ads117x.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. /*
  35. * initialise the ads117x driver
  36. */
  37. static int ads117x_init(struct snd_soc_device *socdev)
  38. {
  39. struct snd_soc_codec *codec = socdev->card->codec;
  40. int ret = 0;
  41. codec->name = "ADS117X";
  42. codec->owner = THIS_MODULE;
  43. codec->dai = &ads117x_dai;
  44. codec->num_dai = 1;
  45. /* register pcms */
  46. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  47. if (ret < 0) {
  48. printk(KERN_ERR "ads117x: failed to create pcms\n");
  49. return ret;
  50. }
  51. ret = snd_soc_init_card(socdev);
  52. if (ret < 0) {
  53. printk(KERN_ERR "ads117x: failed to register card\n");
  54. goto card_err;
  55. }
  56. return ret;
  57. card_err:
  58. snd_soc_free_pcms(socdev);
  59. return ret;
  60. }
  61. static int ads117x_probe(struct platform_device *pdev)
  62. {
  63. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  64. struct snd_soc_codec *codec;
  65. int ret;
  66. pr_info("ads117x ADC\n");
  67. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  68. if (codec == NULL)
  69. return -ENOMEM;
  70. socdev->card->codec = codec;
  71. mutex_init(&codec->mutex);
  72. INIT_LIST_HEAD(&codec->dapm_widgets);
  73. INIT_LIST_HEAD(&codec->dapm_paths);
  74. ret = ads117x_init(socdev);
  75. if (ret != 0)
  76. kfree(codec);
  77. return ret;
  78. }
  79. static int ads117x_remove(struct platform_device *pdev)
  80. {
  81. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  82. struct snd_soc_codec *codec = socdev->card->codec;
  83. snd_soc_free_pcms(socdev);
  84. kfree(codec);
  85. return 0;
  86. }
  87. struct snd_soc_codec_device soc_codec_dev_ads117x = {
  88. .probe = ads117x_probe,
  89. .remove = ads117x_remove,
  90. };
  91. EXPORT_SYMBOL_GPL(soc_codec_dev_ads117x);
  92. static int __init ads117x_modinit(void)
  93. {
  94. return snd_soc_register_dai(&ads117x_dai);
  95. }
  96. module_init(ads117x_modinit);
  97. static void __exit ads117x_exit(void)
  98. {
  99. snd_soc_unregister_dai(&ads117x_dai);
  100. }
  101. module_exit(ads117x_exit);
  102. MODULE_DESCRIPTION("ASoC ads117x driver");
  103. MODULE_AUTHOR("Graeme Gregory");
  104. MODULE_LICENSE("GPL");