]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - sound/soc/codecs/ads117x.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
[mirror_ubuntu-artful-kernel.git] / sound / soc / codecs / ads117x.c
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>
14 #include <linux/init.h>
15 #include <linux/device.h>
16 #include <sound/core.h>
17 #include <sound/pcm.h>
18 #include <sound/initval.h>
19 #include <sound/soc.h>
20
21 #include "ads117x.h"
22
23 #define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000)
24
25 #define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
26
27 struct snd_soc_dai ads117x_dai = {
28 /* ADC */
29 .name = "ADS117X ADC",
30 .id = 1,
31 .capture = {
32 .stream_name = "Capture",
33 .channels_min = 1,
34 .channels_max = 32,
35 .rates = ADS117X_RATES,
36 .formats = ADS117X_FORMATS,},
37 };
38 EXPORT_SYMBOL_GPL(ads117x_dai);
39
40 static int ads117x_probe(struct platform_device *pdev)
41 {
42 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
43 struct snd_soc_codec *codec;
44 int ret;
45
46 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
47 if (codec == NULL)
48 return -ENOMEM;
49
50 socdev->card->codec = codec;
51 mutex_init(&codec->mutex);
52 INIT_LIST_HEAD(&codec->dapm_widgets);
53 INIT_LIST_HEAD(&codec->dapm_paths);
54 codec->name = "ADS117X";
55 codec->owner = THIS_MODULE;
56 codec->dai = &ads117x_dai;
57 codec->num_dai = 1;
58
59 /* register pcms */
60 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
61 if (ret < 0) {
62 printk(KERN_ERR "ads117x: failed to create pcms\n");
63 kfree(codec);
64 return ret;
65 }
66
67 return 0;
68 }
69
70 static int ads117x_remove(struct platform_device *pdev)
71 {
72 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
73 struct snd_soc_codec *codec = socdev->card->codec;
74
75 snd_soc_free_pcms(socdev);
76 kfree(codec);
77
78 return 0;
79 }
80
81 struct snd_soc_codec_device soc_codec_dev_ads117x = {
82 .probe = ads117x_probe,
83 .remove = ads117x_remove,
84 };
85 EXPORT_SYMBOL_GPL(soc_codec_dev_ads117x);
86
87 static __devinit int ads117x_platform_probe(struct platform_device *pdev)
88 {
89 ads117x_dai.dev = &pdev->dev;
90 return snd_soc_register_dai(&ads117x_dai);
91 }
92
93 static int __devexit ads117x_platform_remove(struct platform_device *pdev)
94 {
95 snd_soc_unregister_dai(&ads117x_dai);
96 return 0;
97 }
98
99 static struct platform_driver ads117x_codec_driver = {
100 .driver = {
101 .name = "ads117x",
102 .owner = THIS_MODULE,
103 },
104
105 .probe = ads117x_platform_probe,
106 .remove = __devexit_p(ads117x_platform_remove),
107 };
108
109 static int __init ads117x_init(void)
110 {
111 return platform_driver_register(&ads117x_codec_driver);
112 }
113 module_init(ads117x_init);
114
115 static void __exit ads117x_exit(void)
116 {
117 platform_driver_unregister(&ads117x_codec_driver);
118 }
119 module_exit(ads117x_exit);
120
121 MODULE_DESCRIPTION("ASoC ads117x driver");
122 MODULE_AUTHOR("Graeme Gregory");
123 MODULE_LICENSE("GPL");