Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 1 | /* |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/device.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 18 | #include <sound/core.h> |
| 19 | #include <sound/pcm.h> |
| 20 | #include <sound/initval.h> |
| 21 | #include <sound/soc.h> |
| 22 | |
Florian Vaussard | 4f2bf0a | 2016-02-05 16:32:14 +0100 | [diff] [blame] | 23 | #include <linux/of.h> |
| 24 | |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 25 | #define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000) |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 26 | #define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 27 | |
Mark Brown | 45a14a8 | 2013-08-07 18:24:09 +0100 | [diff] [blame] | 28 | static const struct snd_soc_dapm_widget ads117x_dapm_widgets[] = { |
| 29 | SND_SOC_DAPM_INPUT("Input1"), |
| 30 | SND_SOC_DAPM_INPUT("Input2"), |
| 31 | SND_SOC_DAPM_INPUT("Input3"), |
| 32 | SND_SOC_DAPM_INPUT("Input4"), |
| 33 | SND_SOC_DAPM_INPUT("Input5"), |
| 34 | SND_SOC_DAPM_INPUT("Input6"), |
| 35 | SND_SOC_DAPM_INPUT("Input7"), |
| 36 | SND_SOC_DAPM_INPUT("Input8"), |
| 37 | }; |
| 38 | |
| 39 | static 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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 50 | static struct snd_soc_dai_driver ads117x_dai = { |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 51 | /* ADC */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 52 | .name = "ads117x-hifi", |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 53 | .capture = { |
| 54 | .stream_name = "Capture", |
| 55 | .channels_min = 1, |
| 56 | .channels_max = 32, |
| 57 | .rates = ADS117X_RATES, |
| 58 | .formats = ADS117X_FORMATS,}, |
| 59 | }; |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 60 | |
Bhumika Goyal | a180ba4 | 2017-08-03 21:30:19 +0530 | [diff] [blame] | 61 | static const struct snd_soc_codec_driver soc_codec_dev_ads117x = { |
Kuninori Morimoto | 940b816 | 2016-08-08 09:12:30 +0000 | [diff] [blame] | 62 | .component_driver = { |
| 63 | .dapm_widgets = ads117x_dapm_widgets, |
| 64 | .num_dapm_widgets = ARRAY_SIZE(ads117x_dapm_widgets), |
| 65 | .dapm_routes = ads117x_dapm_routes, |
| 66 | .num_dapm_routes = ARRAY_SIZE(ads117x_dapm_routes), |
| 67 | }, |
Mark Brown | 45a14a8 | 2013-08-07 18:24:09 +0100 | [diff] [blame] | 68 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 69 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 70 | static int ads117x_probe(struct platform_device *pdev) |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 71 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 72 | return snd_soc_register_codec(&pdev->dev, |
| 73 | &soc_codec_dev_ads117x, &ads117x_dai, 1); |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 76 | static int ads117x_remove(struct platform_device *pdev) |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 77 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 78 | snd_soc_unregister_codec(&pdev->dev); |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
Florian Vaussard | 4f2bf0a | 2016-02-05 16:32:14 +0100 | [diff] [blame] | 82 | #if defined(CONFIG_OF) |
| 83 | static const struct of_device_id ads117x_dt_ids[] = { |
| 84 | { .compatible = "ti,ads1174" }, |
| 85 | { .compatible = "ti,ads1178" }, |
| 86 | { }, |
| 87 | }; |
| 88 | MODULE_DEVICE_TABLE(of, ads117x_dt_ids); |
| 89 | #endif |
| 90 | |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 91 | static struct platform_driver ads117x_codec_driver = { |
| 92 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 93 | .name = "ads117x-codec", |
Florian Vaussard | 4f2bf0a | 2016-02-05 16:32:14 +0100 | [diff] [blame] | 94 | .of_match_table = of_match_ptr(ads117x_dt_ids), |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 95 | }, |
| 96 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 97 | .probe = ads117x_probe, |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 98 | .remove = ads117x_remove, |
Mark Brown | f3d0e82 | 2009-11-04 21:43:27 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 101 | module_platform_driver(ads117x_codec_driver); |
Graeme Gregory | 2dcf9fb | 2009-11-04 17:49:22 +0000 | [diff] [blame] | 102 | |
| 103 | MODULE_DESCRIPTION("ASoC ads117x driver"); |
| 104 | MODULE_AUTHOR("Graeme Gregory"); |
| 105 | MODULE_LICENSE("GPL"); |