ads117x.c 2.8 KB

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