ac97.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * ac97.c -- ALSA Soc AC97 codec support
  3. *
  4. * Copyright 2005 Wolfson Microelectronics PLC.
  5. * Author: Liam Girdwood <lrg@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. * Generic AC97 support.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/slab.h>
  16. #include <linux/kernel.h>
  17. #include <linux/device.h>
  18. #include <linux/module.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. static int ac97_prepare(struct snd_pcm_substream *substream,
  25. struct snd_soc_dai *dai)
  26. {
  27. struct snd_soc_codec *codec = dai->codec;
  28. int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  29. AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
  30. return snd_ac97_set_rate(codec->ac97, reg, substream->runtime->rate);
  31. }
  32. #define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  33. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
  34. SNDRV_PCM_RATE_48000)
  35. static const struct snd_soc_dai_ops ac97_dai_ops = {
  36. .prepare = ac97_prepare,
  37. };
  38. static struct snd_soc_dai_driver ac97_dai = {
  39. .name = "ac97-hifi",
  40. .ac97_control = 1,
  41. .playback = {
  42. .stream_name = "AC97 Playback",
  43. .channels_min = 1,
  44. .channels_max = 2,
  45. .rates = STD_AC97_RATES,
  46. .formats = SND_SOC_STD_AC97_FMTS,},
  47. .capture = {
  48. .stream_name = "AC97 Capture",
  49. .channels_min = 1,
  50. .channels_max = 2,
  51. .rates = STD_AC97_RATES,
  52. .formats = SND_SOC_STD_AC97_FMTS,},
  53. .ops = &ac97_dai_ops,
  54. };
  55. static unsigned int ac97_read(struct snd_soc_codec *codec,
  56. unsigned int reg)
  57. {
  58. return soc_ac97_ops.read(codec->ac97, reg);
  59. }
  60. static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
  61. unsigned int val)
  62. {
  63. soc_ac97_ops.write(codec->ac97, reg, val);
  64. return 0;
  65. }
  66. static int ac97_soc_probe(struct snd_soc_codec *codec)
  67. {
  68. struct snd_ac97_bus *ac97_bus;
  69. struct snd_ac97_template ac97_template;
  70. int ret;
  71. /* add codec as bus device for standard ac97 */
  72. ret = snd_ac97_bus(codec->card->snd_card, 0, &soc_ac97_ops, NULL, &ac97_bus);
  73. if (ret < 0)
  74. return ret;
  75. memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
  76. ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97);
  77. if (ret < 0)
  78. return ret;
  79. return 0;
  80. }
  81. #ifdef CONFIG_PM
  82. static int ac97_soc_suspend(struct snd_soc_codec *codec)
  83. {
  84. snd_ac97_suspend(codec->ac97);
  85. return 0;
  86. }
  87. static int ac97_soc_resume(struct snd_soc_codec *codec)
  88. {
  89. snd_ac97_resume(codec->ac97);
  90. return 0;
  91. }
  92. #else
  93. #define ac97_soc_suspend NULL
  94. #define ac97_soc_resume NULL
  95. #endif
  96. static struct snd_soc_codec_driver soc_codec_dev_ac97 = {
  97. .write = ac97_write,
  98. .read = ac97_read,
  99. .probe = ac97_soc_probe,
  100. .suspend = ac97_soc_suspend,
  101. .resume = ac97_soc_resume,
  102. };
  103. static __devinit int ac97_probe(struct platform_device *pdev)
  104. {
  105. return snd_soc_register_codec(&pdev->dev,
  106. &soc_codec_dev_ac97, &ac97_dai, 1);
  107. }
  108. static int __devexit ac97_remove(struct platform_device *pdev)
  109. {
  110. snd_soc_unregister_codec(&pdev->dev);
  111. return 0;
  112. }
  113. static struct platform_driver ac97_codec_driver = {
  114. .driver = {
  115. .name = "ac97-codec",
  116. .owner = THIS_MODULE,
  117. },
  118. .probe = ac97_probe,
  119. .remove = __devexit_p(ac97_remove),
  120. };
  121. module_platform_driver(ac97_codec_driver);
  122. MODULE_DESCRIPTION("Soc Generic AC97 driver");
  123. MODULE_AUTHOR("Liam Girdwood");
  124. MODULE_LICENSE("GPL");
  125. MODULE_ALIAS("platform:ac97-codec");