blob: c5be1bdc2c9abfbeb61082e118fa2971db1258af [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040017#include <linux/module.h>
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000018#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/initval.h>
21#include <sound/soc.h>
22
Florian Vaussard4f2bf0a2016-02-05 16:32:14 +010023#include <linux/of.h>
24
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000025#define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000)
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000026#define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
27
Mark Brown45a14a82013-08-07 18:24:09 +010028static const struct snd_soc_dapm_widget ads117x_dapm_widgets[] = {
29SND_SOC_DAPM_INPUT("Input1"),
30SND_SOC_DAPM_INPUT("Input2"),
31SND_SOC_DAPM_INPUT("Input3"),
32SND_SOC_DAPM_INPUT("Input4"),
33SND_SOC_DAPM_INPUT("Input5"),
34SND_SOC_DAPM_INPUT("Input6"),
35SND_SOC_DAPM_INPUT("Input7"),
36SND_SOC_DAPM_INPUT("Input8"),
37};
38
39static const struct snd_soc_dapm_route ads117x_dapm_routes[] = {
40 { "Capture", NULL, "Input1" },
41 { "Capture", NULL, "Input2" },
42 { "Capture", NULL, "Input3" },
43 { "Capture", NULL, "Input4" },
44 { "Capture", NULL, "Input5" },
45 { "Capture", NULL, "Input6" },
46 { "Capture", NULL, "Input7" },
47 { "Capture", NULL, "Input8" },
48};
49
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000050static struct snd_soc_dai_driver ads117x_dai = {
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000051/* ADC */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000052 .name = "ads117x-hifi",
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000053 .capture = {
54 .stream_name = "Capture",
55 .channels_min = 1,
56 .channels_max = 32,
57 .rates = ADS117X_RATES,
58 .formats = ADS117X_FORMATS,},
59};
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000060
Mark Brown45a14a82013-08-07 18:24:09 +010061static struct snd_soc_codec_driver soc_codec_dev_ads117x = {
62 .dapm_widgets = ads117x_dapm_widgets,
63 .num_dapm_widgets = ARRAY_SIZE(ads117x_dapm_widgets),
64 .dapm_routes = ads117x_dapm_routes,
65 .num_dapm_routes = ARRAY_SIZE(ads117x_dapm_routes),
66};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000067
Bill Pemberton7a79e942012-12-07 09:26:37 -050068static int ads117x_probe(struct platform_device *pdev)
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000069{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000070 return snd_soc_register_codec(&pdev->dev,
71 &soc_codec_dev_ads117x, &ads117x_dai, 1);
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000072}
73
Bill Pemberton7a79e942012-12-07 09:26:37 -050074static int ads117x_remove(struct platform_device *pdev)
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +000075{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000076 snd_soc_unregister_codec(&pdev->dev);
Mark Brownf3d0e822009-11-04 21:43:27 +000077 return 0;
78}
79
Florian Vaussard4f2bf0a2016-02-05 16:32:14 +010080#if defined(CONFIG_OF)
81static const struct of_device_id ads117x_dt_ids[] = {
82 { .compatible = "ti,ads1174" },
83 { .compatible = "ti,ads1178" },
84 { },
85};
86MODULE_DEVICE_TABLE(of, ads117x_dt_ids);
87#endif
88
Mark Brownf3d0e822009-11-04 21:43:27 +000089static struct platform_driver ads117x_codec_driver = {
90 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000091 .name = "ads117x-codec",
Florian Vaussard4f2bf0a2016-02-05 16:32:14 +010092 .of_match_table = of_match_ptr(ads117x_dt_ids),
Mark Brownf3d0e822009-11-04 21:43:27 +000093 },
94
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000095 .probe = ads117x_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -050096 .remove = ads117x_remove,
Mark Brownf3d0e822009-11-04 21:43:27 +000097};
98
Mark Brown5bbcc3c2011-11-23 22:52:08 +000099module_platform_driver(ads117x_codec_driver);
Graeme Gregory2dcf9fb2009-11-04 17:49:22 +0000100
101MODULE_DESCRIPTION("ASoC ads117x driver");
102MODULE_AUTHOR("Graeme Gregory");
103MODULE_LICENSE("GPL");