ac97.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ac97.c -- ALSA Soc AC97 codec support
  4. *
  5. * Copyright 2005 Wolfson Microelectronics PLC.
  6. * Author: Liam Girdwood <[email protected]>
  7. *
  8. * Generic AC97 support.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. #include <linux/kernel.h>
  13. #include <linux/device.h>
  14. #include <linux/module.h>
  15. #include <sound/core.h>
  16. #include <sound/pcm.h>
  17. #include <sound/ac97_codec.h>
  18. #include <sound/initval.h>
  19. #include <sound/soc.h>
  20. static const struct snd_soc_dapm_widget ac97_widgets[] = {
  21. SND_SOC_DAPM_INPUT("RX"),
  22. SND_SOC_DAPM_OUTPUT("TX"),
  23. };
  24. static const struct snd_soc_dapm_route ac97_routes[] = {
  25. { "AC97 Capture", NULL, "RX" },
  26. { "TX", NULL, "AC97 Playback" },
  27. };
  28. static int ac97_prepare(struct snd_pcm_substream *substream,
  29. struct snd_soc_dai *dai)
  30. {
  31. struct snd_soc_component *component = dai->component;
  32. struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
  33. int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  34. AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
  35. return snd_ac97_set_rate(ac97, reg, substream->runtime->rate);
  36. }
  37. static const struct snd_soc_dai_ops ac97_dai_ops = {
  38. .prepare = ac97_prepare,
  39. };
  40. static struct snd_soc_dai_driver ac97_dai = {
  41. .name = "ac97-hifi",
  42. .playback = {
  43. .stream_name = "AC97 Playback",
  44. .channels_min = 1,
  45. .channels_max = 2,
  46. .rates = SNDRV_PCM_RATE_KNOT,
  47. .formats = SND_SOC_STD_AC97_FMTS,},
  48. .capture = {
  49. .stream_name = "AC97 Capture",
  50. .channels_min = 1,
  51. .channels_max = 2,
  52. .rates = SNDRV_PCM_RATE_KNOT,
  53. .formats = SND_SOC_STD_AC97_FMTS,},
  54. .ops = &ac97_dai_ops,
  55. };
  56. static int ac97_soc_probe(struct snd_soc_component *component)
  57. {
  58. struct snd_ac97 *ac97;
  59. struct snd_ac97_bus *ac97_bus;
  60. struct snd_ac97_template ac97_template;
  61. int ret;
  62. /* add codec as bus device for standard ac97 */
  63. ret = snd_ac97_bus(component->card->snd_card, 0, soc_ac97_ops,
  64. NULL, &ac97_bus);
  65. if (ret < 0)
  66. return ret;
  67. memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
  68. ret = snd_ac97_mixer(ac97_bus, &ac97_template, &ac97);
  69. if (ret < 0)
  70. return ret;
  71. snd_soc_component_set_drvdata(component, ac97);
  72. return 0;
  73. }
  74. #ifdef CONFIG_PM
  75. static int ac97_soc_suspend(struct snd_soc_component *component)
  76. {
  77. struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
  78. snd_ac97_suspend(ac97);
  79. return 0;
  80. }
  81. static int ac97_soc_resume(struct snd_soc_component *component)
  82. {
  83. struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
  84. snd_ac97_resume(ac97);
  85. return 0;
  86. }
  87. #else
  88. #define ac97_soc_suspend NULL
  89. #define ac97_soc_resume NULL
  90. #endif
  91. static const struct snd_soc_component_driver soc_component_dev_ac97 = {
  92. .probe = ac97_soc_probe,
  93. .suspend = ac97_soc_suspend,
  94. .resume = ac97_soc_resume,
  95. .dapm_widgets = ac97_widgets,
  96. .num_dapm_widgets = ARRAY_SIZE(ac97_widgets),
  97. .dapm_routes = ac97_routes,
  98. .num_dapm_routes = ARRAY_SIZE(ac97_routes),
  99. .idle_bias_on = 1,
  100. .use_pmdown_time = 1,
  101. .endianness = 1,
  102. };
  103. static int ac97_probe(struct platform_device *pdev)
  104. {
  105. return devm_snd_soc_register_component(&pdev->dev,
  106. &soc_component_dev_ac97, &ac97_dai, 1);
  107. }
  108. static int ac97_remove(struct platform_device *pdev)
  109. {
  110. return 0;
  111. }
  112. static struct platform_driver ac97_codec_driver = {
  113. .driver = {
  114. .name = "ac97-codec",
  115. },
  116. .probe = ac97_probe,
  117. .remove = ac97_remove,
  118. };
  119. module_platform_driver(ac97_codec_driver);
  120. MODULE_DESCRIPTION("Soc Generic AC97 driver");
  121. MODULE_AUTHOR("Liam Girdwood");
  122. MODULE_LICENSE("GPL");
  123. MODULE_ALIAS("platform:ac97-codec");