ads117x.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/init.h>
  14. #include <linux/device.h>
  15. #include <sound/core.h>
  16. #include <sound/pcm.h>
  17. #include <sound/initval.h>
  18. #include <sound/soc.h>
  19. #include "ads117x.h"
  20. #define ADS117X_RATES (SNDRV_PCM_RATE_8000_48000)
  21. #define ADS117X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
  22. struct snd_soc_dai ads117x_dai = {
  23. /* ADC */
  24. .name = "ADS117X ADC",
  25. .id = 1,
  26. .capture = {
  27. .stream_name = "Capture",
  28. .channels_min = 1,
  29. .channels_max = 32,
  30. .rates = ADS117X_RATES,
  31. .formats = ADS117X_FORMATS,},
  32. };
  33. EXPORT_SYMBOL_GPL(ads117x_dai);
  34. static int ads117x_probe(struct platform_device *pdev)
  35. {
  36. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  37. struct snd_soc_codec *codec;
  38. int ret;
  39. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  40. if (codec == NULL)
  41. return -ENOMEM;
  42. socdev->card->codec = codec;
  43. mutex_init(&codec->mutex);
  44. INIT_LIST_HEAD(&codec->dapm_widgets);
  45. INIT_LIST_HEAD(&codec->dapm_paths);
  46. codec->name = "ADS117X";
  47. codec->owner = THIS_MODULE;
  48. codec->dai = &ads117x_dai;
  49. codec->num_dai = 1;
  50. /* register pcms */
  51. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  52. if (ret < 0) {
  53. printk(KERN_ERR "ads117x: failed to create pcms\n");
  54. kfree(codec);
  55. return ret;
  56. }
  57. return 0;
  58. }
  59. static int ads117x_remove(struct platform_device *pdev)
  60. {
  61. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  62. struct snd_soc_codec *codec = socdev->card->codec;
  63. snd_soc_free_pcms(socdev);
  64. kfree(codec);
  65. return 0;
  66. }
  67. struct snd_soc_codec_device soc_codec_dev_ads117x = {
  68. .probe = ads117x_probe,
  69. .remove = ads117x_remove,
  70. };
  71. EXPORT_SYMBOL_GPL(soc_codec_dev_ads117x);
  72. static __devinit int ads117x_platform_probe(struct platform_device *pdev)
  73. {
  74. ads117x_dai.dev = &pdev->dev;
  75. return snd_soc_register_dai(&ads117x_dai);
  76. }
  77. static int __devexit ads117x_platform_remove(struct platform_device *pdev)
  78. {
  79. snd_soc_unregister_dai(&ads117x_dai);
  80. return 0;
  81. }
  82. static struct platform_driver ads117x_codec_driver = {
  83. .driver = {
  84. .name = "ads117x",
  85. .owner = THIS_MODULE,
  86. },
  87. .probe = ads117x_platform_probe,
  88. .remove = __devexit_p(ads117x_platform_remove),
  89. };
  90. static int __init ads117x_init(void)
  91. {
  92. return platform_driver_register(&ads117x_codec_driver);
  93. }
  94. module_init(ads117x_init);
  95. static void __exit ads117x_exit(void)
  96. {
  97. platform_driver_unregister(&ads117x_codec_driver);
  98. }
  99. module_exit(ads117x_exit);
  100. MODULE_DESCRIPTION("ASoC ads117x driver");
  101. MODULE_AUTHOR("Graeme Gregory");
  102. MODULE_LICENSE("GPL");