ac97.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 const struct snd_soc_dapm_widget ac97_widgets[] = {
  25. SND_SOC_DAPM_INPUT("RX"),
  26. SND_SOC_DAPM_OUTPUT("TX"),
  27. };
  28. static const struct snd_soc_dapm_route ac97_routes[] = {
  29. { "AC97 Capture", NULL, "RX" },
  30. { "TX", NULL, "AC97 Playback" },
  31. };
  32. static int ac97_prepare(struct snd_pcm_substream *substream,
  33. struct snd_soc_dai *dai)
  34. {
  35. struct snd_soc_codec *codec = dai->codec;
  36. struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
  37. int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  38. AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
  39. return snd_ac97_set_rate(ac97, reg, substream->runtime->rate);
  40. }
  41. static const struct snd_soc_dai_ops ac97_dai_ops = {
  42. .prepare = ac97_prepare,
  43. };
  44. static struct snd_soc_dai_driver ac97_dai = {
  45. .name = "ac97-hifi",
  46. .playback = {
  47. .stream_name = "AC97 Playback",
  48. .channels_min = 1,
  49. .channels_max = 2,
  50. .rates = SNDRV_PCM_RATE_KNOT,
  51. .formats = SND_SOC_STD_AC97_FMTS,},
  52. .capture = {
  53. .stream_name = "AC97 Capture",
  54. .channels_min = 1,
  55. .channels_max = 2,
  56. .rates = SNDRV_PCM_RATE_KNOT,
  57. .formats = SND_SOC_STD_AC97_FMTS,},
  58. .ops = &ac97_dai_ops,
  59. };
  60. static int ac97_soc_probe(struct snd_soc_codec *codec)
  61. {
  62. struct snd_ac97 *ac97;
  63. struct snd_ac97_bus *ac97_bus;
  64. struct snd_ac97_template ac97_template;
  65. int ret;
  66. /* add codec as bus device for standard ac97 */
  67. ret = snd_ac97_bus(codec->component.card->snd_card, 0, soc_ac97_ops,
  68. NULL, &ac97_bus);
  69. if (ret < 0)
  70. return ret;
  71. memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
  72. ret = snd_ac97_mixer(ac97_bus, &ac97_template, &ac97);
  73. if (ret < 0)
  74. return ret;
  75. snd_soc_codec_set_drvdata(codec, ac97);
  76. return 0;
  77. }
  78. #ifdef CONFIG_PM
  79. static int ac97_soc_suspend(struct snd_soc_codec *codec)
  80. {
  81. struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
  82. snd_ac97_suspend(ac97);
  83. return 0;
  84. }
  85. static int ac97_soc_resume(struct snd_soc_codec *codec)
  86. {
  87. struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
  88. snd_ac97_resume(ac97);
  89. return 0;
  90. }
  91. #else
  92. #define ac97_soc_suspend NULL
  93. #define ac97_soc_resume NULL
  94. #endif
  95. static struct snd_soc_codec_driver soc_codec_dev_ac97 = {
  96. .probe = ac97_soc_probe,
  97. .suspend = ac97_soc_suspend,
  98. .resume = ac97_soc_resume,
  99. .component_driver = {
  100. .dapm_widgets = ac97_widgets,
  101. .num_dapm_widgets = ARRAY_SIZE(ac97_widgets),
  102. .dapm_routes = ac97_routes,
  103. .num_dapm_routes = ARRAY_SIZE(ac97_routes),
  104. },
  105. };
  106. static int ac97_probe(struct platform_device *pdev)
  107. {
  108. return snd_soc_register_codec(&pdev->dev,
  109. &soc_codec_dev_ac97, &ac97_dai, 1);
  110. }
  111. static int ac97_remove(struct platform_device *pdev)
  112. {
  113. snd_soc_unregister_codec(&pdev->dev);
  114. return 0;
  115. }
  116. static struct platform_driver ac97_codec_driver = {
  117. .driver = {
  118. .name = "ac97-codec",
  119. },
  120. .probe = ac97_probe,
  121. .remove = ac97_remove,
  122. };
  123. module_platform_driver(ac97_codec_driver);
  124. MODULE_DESCRIPTION("Soc Generic AC97 driver");
  125. MODULE_AUTHOR("Liam Girdwood");
  126. MODULE_LICENSE("GPL");
  127. MODULE_ALIAS("platform:ac97-codec");