xref: /linux/sound/soc/codecs/ads117x.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
22dcf9fb9SGraeme Gregory /*
32dcf9fb9SGraeme Gregory  * ads117x.c  --  Driver for ads1174/8 ADC chips
42dcf9fb9SGraeme Gregory  *
52dcf9fb9SGraeme Gregory  * Copyright 2009 ShotSpotter Inc.
62dcf9fb9SGraeme Gregory  * Author: Graeme Gregory <gg@slimlogic.co.uk>
72dcf9fb9SGraeme Gregory  */
82dcf9fb9SGraeme Gregory 
92dcf9fb9SGraeme Gregory #include <linux/kernel.h>
105a0e3ad6STejun Heo #include <linux/slab.h>
112dcf9fb9SGraeme Gregory #include <linux/init.h>
122dcf9fb9SGraeme Gregory #include <linux/device.h>
13da155d5bSPaul Gortmaker #include <linux/module.h>
142dcf9fb9SGraeme Gregory #include <sound/core.h>
152dcf9fb9SGraeme Gregory #include <sound/pcm.h>
162dcf9fb9SGraeme Gregory #include <sound/initval.h>
172dcf9fb9SGraeme Gregory #include <sound/soc.h>
182dcf9fb9SGraeme Gregory 
194f2bf0acSFlorian Vaussard #include <linux/of.h>
204f2bf0acSFlorian Vaussard 
212dcf9fb9SGraeme Gregory #define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000)
222dcf9fb9SGraeme Gregory #define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
232dcf9fb9SGraeme Gregory 
2445a14a8bSMark Brown static const struct snd_soc_dapm_widget ads117x_dapm_widgets[] = {
2545a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input1"),
2645a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input2"),
2745a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input3"),
2845a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input4"),
2945a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input5"),
3045a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input6"),
3145a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input7"),
3245a14a8bSMark Brown SND_SOC_DAPM_INPUT("Input8"),
3345a14a8bSMark Brown };
3445a14a8bSMark Brown 
3545a14a8bSMark Brown static const struct snd_soc_dapm_route ads117x_dapm_routes[] = {
3645a14a8bSMark Brown 	{ "Capture", NULL, "Input1" },
3745a14a8bSMark Brown 	{ "Capture", NULL, "Input2" },
3845a14a8bSMark Brown 	{ "Capture", NULL, "Input3" },
3945a14a8bSMark Brown 	{ "Capture", NULL, "Input4" },
4045a14a8bSMark Brown 	{ "Capture", NULL, "Input5" },
4145a14a8bSMark Brown 	{ "Capture", NULL, "Input6" },
4245a14a8bSMark Brown 	{ "Capture", NULL, "Input7" },
4345a14a8bSMark Brown 	{ "Capture", NULL, "Input8" },
4445a14a8bSMark Brown };
4545a14a8bSMark Brown 
46f0fba2adSLiam Girdwood static struct snd_soc_dai_driver ads117x_dai = {
472dcf9fb9SGraeme Gregory /* ADC */
48f0fba2adSLiam Girdwood 	.name = "ads117x-hifi",
492dcf9fb9SGraeme Gregory 	.capture = {
502dcf9fb9SGraeme Gregory 		.stream_name = "Capture",
512dcf9fb9SGraeme Gregory 		.channels_min = 1,
522dcf9fb9SGraeme Gregory 		.channels_max = 32,
532dcf9fb9SGraeme Gregory 		.rates = ADS117X_RATES,
542dcf9fb9SGraeme Gregory 		.formats = ADS117X_FORMATS,},
552dcf9fb9SGraeme Gregory };
562dcf9fb9SGraeme Gregory 
5793101617SKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_ads117x = {
5845a14a8bSMark Brown 	.dapm_widgets		= ads117x_dapm_widgets,
5945a14a8bSMark Brown 	.num_dapm_widgets	= ARRAY_SIZE(ads117x_dapm_widgets),
6045a14a8bSMark Brown 	.dapm_routes		= ads117x_dapm_routes,
6145a14a8bSMark Brown 	.num_dapm_routes	= ARRAY_SIZE(ads117x_dapm_routes),
6293101617SKuninori Morimoto 	.idle_bias_on		= 1,
6393101617SKuninori Morimoto 	.use_pmdown_time	= 1,
6493101617SKuninori Morimoto 	.endianness		= 1,
6545a14a8bSMark Brown };
66f0fba2adSLiam Girdwood 
ads117x_probe(struct platform_device * pdev)677a79e94eSBill Pemberton static int ads117x_probe(struct platform_device *pdev)
682dcf9fb9SGraeme Gregory {
6993101617SKuninori Morimoto 	return devm_snd_soc_register_component(&pdev->dev,
7093101617SKuninori Morimoto 			&soc_component_dev_ads117x, &ads117x_dai, 1);
71f3d0e82fSMark Brown }
72f3d0e82fSMark Brown 
734f2bf0acSFlorian Vaussard #if defined(CONFIG_OF)
744f2bf0acSFlorian Vaussard static const struct of_device_id ads117x_dt_ids[] = {
754f2bf0acSFlorian Vaussard 	{ .compatible = "ti,ads1174" },
764f2bf0acSFlorian Vaussard 	{ .compatible = "ti,ads1178" },
774f2bf0acSFlorian Vaussard 	{ },
784f2bf0acSFlorian Vaussard };
794f2bf0acSFlorian Vaussard MODULE_DEVICE_TABLE(of, ads117x_dt_ids);
804f2bf0acSFlorian Vaussard #endif
814f2bf0acSFlorian Vaussard 
82f3d0e82fSMark Brown static struct platform_driver ads117x_codec_driver = {
83f3d0e82fSMark Brown 	.driver = {
84f0fba2adSLiam Girdwood 			.name = "ads117x-codec",
854f2bf0acSFlorian Vaussard 			.of_match_table = of_match_ptr(ads117x_dt_ids),
86f3d0e82fSMark Brown 	},
87f3d0e82fSMark Brown 
88f0fba2adSLiam Girdwood 	.probe = ads117x_probe,
89f3d0e82fSMark Brown };
90f3d0e82fSMark Brown 
915bbcc3c0SMark Brown module_platform_driver(ads117x_codec_driver);
922dcf9fb9SGraeme Gregory 
932dcf9fb9SGraeme Gregory MODULE_DESCRIPTION("ASoC ads117x driver");
942dcf9fb9SGraeme Gregory MODULE_AUTHOR("Graeme Gregory");
952dcf9fb9SGraeme Gregory MODULE_LICENSE("GPL");
96