ads117x.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/init.h>
  15. #include <linux/device.h>
  16. #include <linux/module.h>
  17. #include <sound/core.h>
  18. #include <sound/pcm.h>
  19. #include <sound/initval.h>
  20. #include <sound/soc.h>
  21. #include <linux/of.h>
  22. #define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000)
  23. #define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
  24. static const struct snd_soc_dapm_widget ads117x_dapm_widgets[] = {
  25. SND_SOC_DAPM_INPUT("Input1"),
  26. SND_SOC_DAPM_INPUT("Input2"),
  27. SND_SOC_DAPM_INPUT("Input3"),
  28. SND_SOC_DAPM_INPUT("Input4"),
  29. SND_SOC_DAPM_INPUT("Input5"),
  30. SND_SOC_DAPM_INPUT("Input6"),
  31. SND_SOC_DAPM_INPUT("Input7"),
  32. SND_SOC_DAPM_INPUT("Input8"),
  33. };
  34. static const struct snd_soc_dapm_route ads117x_dapm_routes[] = {
  35. { "Capture", NULL, "Input1" },
  36. { "Capture", NULL, "Input2" },
  37. { "Capture", NULL, "Input3" },
  38. { "Capture", NULL, "Input4" },
  39. { "Capture", NULL, "Input5" },
  40. { "Capture", NULL, "Input6" },
  41. { "Capture", NULL, "Input7" },
  42. { "Capture", NULL, "Input8" },
  43. };
  44. static struct snd_soc_dai_driver ads117x_dai = {
  45. /* ADC */
  46. .name = "ads117x-hifi",
  47. .capture = {
  48. .stream_name = "Capture",
  49. .channels_min = 1,
  50. .channels_max = 32,
  51. .rates = ADS117X_RATES,
  52. .formats = ADS117X_FORMATS,},
  53. };
  54. static struct snd_soc_codec_driver soc_codec_dev_ads117x = {
  55. .component_driver = {
  56. .dapm_widgets = ads117x_dapm_widgets,
  57. .num_dapm_widgets = ARRAY_SIZE(ads117x_dapm_widgets),
  58. .dapm_routes = ads117x_dapm_routes,
  59. .num_dapm_routes = ARRAY_SIZE(ads117x_dapm_routes),
  60. },
  61. };
  62. static int ads117x_probe(struct platform_device *pdev)
  63. {
  64. return snd_soc_register_codec(&pdev->dev,
  65. &soc_codec_dev_ads117x, &ads117x_dai, 1);
  66. }
  67. static int ads117x_remove(struct platform_device *pdev)
  68. {
  69. snd_soc_unregister_codec(&pdev->dev);
  70. return 0;
  71. }
  72. #if defined(CONFIG_OF)
  73. static const struct of_device_id ads117x_dt_ids[] = {
  74. { .compatible = "ti,ads1174" },
  75. { .compatible = "ti,ads1178" },
  76. { },
  77. };
  78. MODULE_DEVICE_TABLE(of, ads117x_dt_ids);
  79. #endif
  80. static struct platform_driver ads117x_codec_driver = {
  81. .driver = {
  82. .name = "ads117x-codec",
  83. .of_match_table = of_match_ptr(ads117x_dt_ids),
  84. },
  85. .probe = ads117x_probe,
  86. .remove = ads117x_remove,
  87. };
  88. module_platform_driver(ads117x_codec_driver);
  89. MODULE_DESCRIPTION("ASoC ads117x driver");
  90. MODULE_AUTHOR("Graeme Gregory");
  91. MODULE_LICENSE("GPL");