ad73311.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * ad73311.c -- ALSA Soc AD73311 codec support
  3. *
  4. * Copyright: Analog Device Inc.
  5. * Author: Cliff Cai <cliff.cai@analog.com>
  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/init.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/device.h>
  16. #include <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/ac97_codec.h>
  19. #include <sound/initval.h>
  20. #include <sound/soc.h>
  21. #include "ad73311.h"
  22. struct snd_soc_dai ad73311_dai = {
  23. .name = "AD73311",
  24. .playback = {
  25. .stream_name = "Playback",
  26. .channels_min = 1,
  27. .channels_max = 1,
  28. .rates = SNDRV_PCM_RATE_8000,
  29. .formats = SNDRV_PCM_FMTBIT_S16_LE, },
  30. .capture = {
  31. .stream_name = "Capture",
  32. .channels_min = 1,
  33. .channels_max = 1,
  34. .rates = SNDRV_PCM_RATE_8000,
  35. .formats = SNDRV_PCM_FMTBIT_S16_LE, },
  36. };
  37. EXPORT_SYMBOL_GPL(ad73311_dai);
  38. static int ad73311_soc_probe(struct platform_device *pdev)
  39. {
  40. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  41. struct snd_soc_codec *codec;
  42. int ret = 0;
  43. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  44. if (codec == NULL)
  45. return -ENOMEM;
  46. mutex_init(&codec->mutex);
  47. codec->name = "AD73311";
  48. codec->owner = THIS_MODULE;
  49. codec->dai = &ad73311_dai;
  50. codec->num_dai = 1;
  51. socdev->card->codec = codec;
  52. INIT_LIST_HEAD(&codec->dapm_widgets);
  53. INIT_LIST_HEAD(&codec->dapm_paths);
  54. /* register pcms */
  55. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  56. if (ret < 0) {
  57. printk(KERN_ERR "ad73311: failed to create pcms\n");
  58. goto pcm_err;
  59. }
  60. ret = snd_soc_init_card(socdev);
  61. if (ret < 0) {
  62. printk(KERN_ERR "ad73311: failed to register card\n");
  63. goto register_err;
  64. }
  65. return ret;
  66. register_err:
  67. snd_soc_free_pcms(socdev);
  68. pcm_err:
  69. kfree(socdev->card->codec);
  70. socdev->card->codec = NULL;
  71. return ret;
  72. }
  73. static int ad73311_soc_remove(struct platform_device *pdev)
  74. {
  75. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  76. struct snd_soc_codec *codec = socdev->card->codec;
  77. if (codec == NULL)
  78. return 0;
  79. snd_soc_free_pcms(socdev);
  80. kfree(codec);
  81. return 0;
  82. }
  83. struct snd_soc_codec_device soc_codec_dev_ad73311 = {
  84. .probe = ad73311_soc_probe,
  85. .remove = ad73311_soc_remove,
  86. };
  87. EXPORT_SYMBOL_GPL(soc_codec_dev_ad73311);
  88. static int __init ad73311_init(void)
  89. {
  90. return snd_soc_register_dai(&ad73311_dai);
  91. }
  92. module_init(ad73311_init);
  93. static void __exit ad73311_exit(void)
  94. {
  95. snd_soc_unregister_dai(&ad73311_dai);
  96. }
  97. module_exit(ad73311_exit);
  98. MODULE_DESCRIPTION("ASoC ad73311 driver");
  99. MODULE_AUTHOR("Cliff Cai ");
  100. MODULE_LICENSE("GPL");