blob: f8e75edb27b7ec793f21f32e10200db2d734148c [file] [log] [blame]
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +00001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000015#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
28struct 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};
39EXPORT_SYMBOL_GPL(ads117x_dai);
40
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000041static 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
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000047 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);
Mark Brownf3d0e822009-11-04 21:43:27 +000055 codec->name = "ADS117X";
56 codec->owner = THIS_MODULE;
57 codec->dai = &ads117x_dai;
58 codec->num_dai = 1;
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000059
Mark Brownf3d0e822009-11-04 21:43:27 +000060 /* 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");
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000064 kfree(codec);
Mark Brownf3d0e822009-11-04 21:43:27 +000065 return ret;
66 }
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000067
Mark Brownf3d0e822009-11-04 21:43:27 +000068 return 0;
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000069}
70
71static 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
82struct snd_soc_codec_device soc_codec_dev_ads117x = {
83 .probe = ads117x_probe,
84 .remove = ads117x_remove,
85};
86EXPORT_SYMBOL_GPL(soc_codec_dev_ads117x);
87
Mark Brownf3d0e822009-11-04 21:43:27 +000088static __devinit int ads117x_platform_probe(struct platform_device *pdev)
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000089{
Mark Brownf3d0e822009-11-04 21:43:27 +000090 ads117x_dai.dev = &pdev->dev;
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000091 return snd_soc_register_dai(&ads117x_dai);
92}
Mark Brownf3d0e822009-11-04 21:43:27 +000093
94static int __devexit ads117x_platform_remove(struct platform_device *pdev)
95{
96 snd_soc_unregister_dai(&ads117x_dai);
97 return 0;
98}
99
100static 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
110static int __init ads117x_init(void)
111{
112 return platform_driver_register(&ads117x_codec_driver);
113}
114module_init(ads117x_init);
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +0000115
116static void __exit ads117x_exit(void)
117{
Mark Brownf3d0e822009-11-04 21:43:27 +0000118 platform_driver_unregister(&ads117x_codec_driver);
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +0000119}
120module_exit(ads117x_exit);
121
122MODULE_DESCRIPTION("ASoC ads117x driver");
123MODULE_AUTHOR("Graeme Gregory");
124MODULE_LICENSE("GPL");