ad73311.c 2.5 KB

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