blob: cc96411ca3e6ec0547202f06a0db55dab6e885a0 [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>
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
27struct 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};
38EXPORT_SYMBOL_GPL(ads117x_dai);
39
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000040static 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
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000046 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);
Mark Brownf3d0e822009-11-04 21:43:27 +000054 codec->name = "ADS117X";
55 codec->owner = THIS_MODULE;
56 codec->dai = &ads117x_dai;
57 codec->num_dai = 1;
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000058
Mark Brownf3d0e822009-11-04 21:43:27 +000059 /* 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");
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000063 kfree(codec);
Mark Brownf3d0e822009-11-04 21:43:27 +000064 return ret;
65 }
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000066
Mark Brownf3d0e822009-11-04 21:43:27 +000067 return 0;
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000068}
69
70static 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
81struct snd_soc_codec_device soc_codec_dev_ads117x = {
82 .probe = ads117x_probe,
83 .remove = ads117x_remove,
84};
85EXPORT_SYMBOL_GPL(soc_codec_dev_ads117x);
86
Mark Brownf3d0e822009-11-04 21:43:27 +000087static __devinit int ads117x_platform_probe(struct platform_device *pdev)
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000088{
Mark Brownf3d0e822009-11-04 21:43:27 +000089 ads117x_dai.dev = &pdev->dev;
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000090 return snd_soc_register_dai(&ads117x_dai);
91}
Mark Brownf3d0e822009-11-04 21:43:27 +000092
93static int __devexit ads117x_platform_remove(struct platform_device *pdev)
94{
95 snd_soc_unregister_dai(&ads117x_dai);
96 return 0;
97}
98
99static 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
109static int __init ads117x_init(void)
110{
111 return platform_driver_register(&ads117x_codec_driver);
112}
113module_init(ads117x_init);
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +0000114
115static void __exit ads117x_exit(void)
116{
Mark Brownf3d0e822009-11-04 21:43:27 +0000117 platform_driver_unregister(&ads117x_codec_driver);
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +0000118}
119module_exit(ads117x_exit);
120
121MODULE_DESCRIPTION("ASoC ads117x driver");
122MODULE_AUTHOR("Graeme Gregory");
123MODULE_LICENSE("GPL");