ad73311.c 2.6 KB

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