2 * ads117x.c -- Driver for ads1174/8 ADC chips
4 * Copyright 2009 ShotSpotter Inc.
5 * Author: Graeme Gregory <gg@slimlogic.co.uk>
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.
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
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>
24 #define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000)
26 #define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
28 struct snd_soc_dai ads117x_dai
= {
30 .name
= "ADS117X ADC",
33 .stream_name
= "Capture",
36 .rates
= ADS117X_RATES
,
37 .formats
= ADS117X_FORMATS
,},
39 EXPORT_SYMBOL_GPL(ads117x_dai
);
41 static int ads117x_probe(struct platform_device
*pdev
)
43 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
44 struct snd_soc_codec
*codec
;
47 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
51 socdev
->card
->codec
= codec
;
52 mutex_init(&codec
->mutex
);
53 INIT_LIST_HEAD(&codec
->dapm_widgets
);
54 INIT_LIST_HEAD(&codec
->dapm_paths
);
55 codec
->name
= "ADS117X";
56 codec
->owner
= THIS_MODULE
;
57 codec
->dai
= &ads117x_dai
;
61 ret
= snd_soc_new_pcms(socdev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
);
63 printk(KERN_ERR
"ads117x: failed to create pcms\n");
71 static int ads117x_remove(struct platform_device
*pdev
)
73 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
74 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
76 snd_soc_free_pcms(socdev
);
82 struct snd_soc_codec_device soc_codec_dev_ads117x
= {
83 .probe
= ads117x_probe
,
84 .remove
= ads117x_remove
,
86 EXPORT_SYMBOL_GPL(soc_codec_dev_ads117x
);
88 static __devinit
int ads117x_platform_probe(struct platform_device
*pdev
)
90 ads117x_dai
.dev
= &pdev
->dev
;
91 return snd_soc_register_dai(&ads117x_dai
);
94 static int __devexit
ads117x_platform_remove(struct platform_device
*pdev
)
96 snd_soc_unregister_dai(&ads117x_dai
);
100 static struct platform_driver ads117x_codec_driver
= {
103 .owner
= THIS_MODULE
,
106 .probe
= ads117x_platform_probe
,
107 .remove
= __devexit_p(ads117x_platform_remove
),
110 static int __init
ads117x_init(void)
112 return platform_driver_register(&ads117x_codec_driver
);
114 module_init(ads117x_init
);
116 static void __exit
ads117x_exit(void)
118 platform_driver_unregister(&ads117x_codec_driver
);
120 module_exit(ads117x_exit
);
122 MODULE_DESCRIPTION("ASoC ads117x driver");
123 MODULE_AUTHOR("Graeme Gregory");
124 MODULE_LICENSE("GPL");