ad73311.c 2.6 KB

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