]>
Commit | Line | Data |
---|---|---|
2dcf9fb9 GG |
1 | /* |
2 | * ads117x.c -- Driver for ads1174/8 ADC chips | |
3 | * | |
4 | * Copyright 2009 ShotSpotter Inc. | |
5 | * Author: Graeme Gregory <gg@slimlogic.co.uk> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2 of the License, or (at your | |
10 | * option) any later version. | |
11 | */ | |
12 | ||
13 | #include <linux/kernel.h> | |
5a0e3ad6 | 14 | #include <linux/slab.h> |
2dcf9fb9 GG |
15 | #include <linux/init.h> |
16 | #include <linux/device.h> | |
17 | #include <sound/core.h> | |
18 | #include <sound/pcm.h> | |
19 | #include <sound/initval.h> | |
20 | #include <sound/soc.h> | |
21 | ||
22 | #include "ads117x.h" | |
23 | ||
24 | #define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000) | |
25 | ||
26 | #define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) | |
27 | ||
28 | struct snd_soc_dai ads117x_dai = { | |
29 | /* ADC */ | |
30 | .name = "ADS117X ADC", | |
31 | .id = 1, | |
32 | .capture = { | |
33 | .stream_name = "Capture", | |
34 | .channels_min = 1, | |
35 | .channels_max = 32, | |
36 | .rates = ADS117X_RATES, | |
37 | .formats = ADS117X_FORMATS,}, | |
38 | }; | |
39 | EXPORT_SYMBOL_GPL(ads117x_dai); | |
40 | ||
2dcf9fb9 GG |
41 | static int ads117x_probe(struct platform_device *pdev) |
42 | { | |
43 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
44 | struct snd_soc_codec *codec; | |
45 | int ret; | |
46 | ||
2dcf9fb9 GG |
47 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
48 | if (codec == NULL) | |
49 | return -ENOMEM; | |
50 | ||
51 | socdev->card->codec = codec; | |
52 | mutex_init(&codec->mutex); | |
53 | INIT_LIST_HEAD(&codec->dapm_widgets); | |
54 | INIT_LIST_HEAD(&codec->dapm_paths); | |
f3d0e82f MB |
55 | codec->name = "ADS117X"; |
56 | codec->owner = THIS_MODULE; | |
57 | codec->dai = &ads117x_dai; | |
58 | codec->num_dai = 1; | |
2dcf9fb9 | 59 | |
f3d0e82f MB |
60 | /* register pcms */ |
61 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | |
62 | if (ret < 0) { | |
63 | printk(KERN_ERR "ads117x: failed to create pcms\n"); | |
2dcf9fb9 | 64 | kfree(codec); |
f3d0e82f MB |
65 | return ret; |
66 | } | |
2dcf9fb9 | 67 | |
f3d0e82f | 68 | return 0; |
2dcf9fb9 GG |
69 | } |
70 | ||
71 | static int ads117x_remove(struct platform_device *pdev) | |
72 | { | |
73 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | |
74 | struct snd_soc_codec *codec = socdev->card->codec; | |
75 | ||
76 | snd_soc_free_pcms(socdev); | |
77 | kfree(codec); | |
78 | ||
79 | return 0; | |
80 | } | |
81 | ||
82 | struct snd_soc_codec_device soc_codec_dev_ads117x = { | |
83 | .probe = ads117x_probe, | |
84 | .remove = ads117x_remove, | |
85 | }; | |
86 | EXPORT_SYMBOL_GPL(soc_codec_dev_ads117x); | |
87 | ||
f3d0e82f | 88 | static __devinit int ads117x_platform_probe(struct platform_device *pdev) |
2dcf9fb9 | 89 | { |
f3d0e82f | 90 | ads117x_dai.dev = &pdev->dev; |
2dcf9fb9 GG |
91 | return snd_soc_register_dai(&ads117x_dai); |
92 | } | |
2dcf9fb9 | 93 | |
f3d0e82f | 94 | static int __devexit ads117x_platform_remove(struct platform_device *pdev) |
2dcf9fb9 GG |
95 | { |
96 | snd_soc_unregister_dai(&ads117x_dai); | |
f3d0e82f MB |
97 | return 0; |
98 | } | |
99 | ||
100 | static struct platform_driver ads117x_codec_driver = { | |
101 | .driver = { | |
102 | .name = "ads117x", | |
103 | .owner = THIS_MODULE, | |
104 | }, | |
105 | ||
106 | .probe = ads117x_platform_probe, | |
107 | .remove = __devexit_p(ads117x_platform_remove), | |
108 | }; | |
109 | ||
110 | static int __init ads117x_init(void) | |
111 | { | |
112 | return platform_driver_register(&ads117x_codec_driver); | |
113 | } | |
114 | module_init(ads117x_init); | |
115 | ||
116 | static void __exit ads117x_exit(void) | |
117 | { | |
118 | platform_driver_unregister(&ads117x_codec_driver); | |
2dcf9fb9 GG |
119 | } |
120 | module_exit(ads117x_exit); | |
121 | ||
122 | MODULE_DESCRIPTION("ASoC ads117x driver"); | |
123 | MODULE_AUTHOR("Graeme Gregory"); | |
124 | MODULE_LICENSE("GPL"); |