xref: /linux/sound/soc/codecs/ads117x.c (revision 45a14a8b50465a6ce61005f7fe9f3fd5c06823d5)
12dcf9fb9SGraeme Gregory /*
22dcf9fb9SGraeme Gregory  * ads117x.c  --  Driver for ads1174/8 ADC chips
32dcf9fb9SGraeme Gregory  *
42dcf9fb9SGraeme Gregory  * Copyright 2009 ShotSpotter Inc.
52dcf9fb9SGraeme Gregory  * Author: Graeme Gregory <gg@slimlogic.co.uk>
62dcf9fb9SGraeme Gregory  *
72dcf9fb9SGraeme Gregory  *  This program is free software; you can redistribute  it and/or modify it
82dcf9fb9SGraeme Gregory  *  under  the terms of  the GNU General  Public License as published by the
92dcf9fb9SGraeme Gregory  *  Free Software Foundation;  either version 2 of the  License, or (at your
102dcf9fb9SGraeme Gregory  *  option) any later version.
112dcf9fb9SGraeme Gregory  */
122dcf9fb9SGraeme Gregory 
132dcf9fb9SGraeme Gregory #include <linux/kernel.h>
145a0e3ad6STejun Heo #include <linux/slab.h>
152dcf9fb9SGraeme Gregory #include <linux/init.h>
162dcf9fb9SGraeme Gregory #include <linux/device.h>
17da155d5bSPaul Gortmaker #include <linux/module.h>
182dcf9fb9SGraeme Gregory #include <sound/core.h>
192dcf9fb9SGraeme Gregory #include <sound/pcm.h>
202dcf9fb9SGraeme Gregory #include <sound/initval.h>
212dcf9fb9SGraeme Gregory #include <sound/soc.h>
222dcf9fb9SGraeme Gregory 
232dcf9fb9SGraeme Gregory #define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000)
242dcf9fb9SGraeme Gregory #define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
252dcf9fb9SGraeme Gregory 
26*45a14a8bSMark Brown static const struct snd_soc_dapm_widget ads117x_dapm_widgets[] = {
27*45a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input1"),
28*45a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input2"),
29*45a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input3"),
30*45a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input4"),
31*45a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input5"),
32*45a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input6"),
33*45a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input7"),
34*45a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input8"),
35*45a14a8bSMark Brown };
36*45a14a8bSMark Brown 
37*45a14a8bSMark Brown static const struct snd_soc_dapm_route ads117x_dapm_routes[] = {
38*45a14a8bSMark Brown 	{ "Capture", NULL, "Input1" },
39*45a14a8bSMark Brown 	{ "Capture", NULL, "Input2" },
40*45a14a8bSMark Brown 	{ "Capture", NULL, "Input3" },
41*45a14a8bSMark Brown 	{ "Capture", NULL, "Input4" },
42*45a14a8bSMark Brown 	{ "Capture", NULL, "Input5" },
43*45a14a8bSMark Brown 	{ "Capture", NULL, "Input6" },
44*45a14a8bSMark Brown 	{ "Capture", NULL, "Input7" },
45*45a14a8bSMark Brown 	{ "Capture", NULL, "Input8" },
46*45a14a8bSMark Brown };
47*45a14a8bSMark Brown 
48f0fba2adSLiam Girdwood static struct snd_soc_dai_driver ads117x_dai = {
492dcf9fb9SGraeme Gregory /* ADC */
50f0fba2adSLiam Girdwood 	.name = "ads117x-hifi",
512dcf9fb9SGraeme Gregory 	.capture = {
522dcf9fb9SGraeme Gregory 		.stream_name = "Capture",
532dcf9fb9SGraeme Gregory 		.channels_min = 1,
542dcf9fb9SGraeme Gregory 		.channels_max = 32,
552dcf9fb9SGraeme Gregory 		.rates = ADS117X_RATES,
562dcf9fb9SGraeme Gregory 		.formats = ADS117X_FORMATS,},
572dcf9fb9SGraeme Gregory };
582dcf9fb9SGraeme Gregory 
59*45a14a8bSMark Brown static struct snd_soc_codec_driver soc_codec_dev_ads117x = {
60*45a14a8bSMark Brown 	.dapm_widgets = ads117x_dapm_widgets,
61*45a14a8bSMark Brown 	.num_dapm_widgets = ARRAY_SIZE(ads117x_dapm_widgets),
62*45a14a8bSMark Brown 	.dapm_routes = ads117x_dapm_routes,
63*45a14a8bSMark Brown 	.num_dapm_routes = ARRAY_SIZE(ads117x_dapm_routes),
64*45a14a8bSMark Brown };
65f0fba2adSLiam Girdwood 
667a79e94eSBill Pemberton static int ads117x_probe(struct platform_device *pdev)
672dcf9fb9SGraeme Gregory {
68f0fba2adSLiam Girdwood 	return snd_soc_register_codec(&pdev->dev,
69f0fba2adSLiam Girdwood 			&soc_codec_dev_ads117x, &ads117x_dai, 1);
702dcf9fb9SGraeme Gregory }
712dcf9fb9SGraeme Gregory 
727a79e94eSBill Pemberton static int ads117x_remove(struct platform_device *pdev)
732dcf9fb9SGraeme Gregory {
74f0fba2adSLiam Girdwood 	snd_soc_unregister_codec(&pdev->dev);
75f3d0e82fSMark Brown 	return 0;
76f3d0e82fSMark Brown }
77f3d0e82fSMark Brown 
78f3d0e82fSMark Brown static struct platform_driver ads117x_codec_driver = {
79f3d0e82fSMark Brown 	.driver = {
80f0fba2adSLiam Girdwood 			.name = "ads117x-codec",
81f3d0e82fSMark Brown 			.owner = THIS_MODULE,
82f3d0e82fSMark Brown 	},
83f3d0e82fSMark Brown 
84f0fba2adSLiam Girdwood 	.probe = ads117x_probe,
857a79e94eSBill Pemberton 	.remove = ads117x_remove,
86f3d0e82fSMark Brown };
87f3d0e82fSMark Brown 
885bbcc3c0SMark Brown module_platform_driver(ads117x_codec_driver);
892dcf9fb9SGraeme Gregory 
902dcf9fb9SGraeme Gregory MODULE_DESCRIPTION("ASoC ads117x driver");
912dcf9fb9SGraeme Gregory MODULE_AUTHOR("Graeme Gregory");
922dcf9fb9SGraeme Gregory MODULE_LICENSE("GPL");
93