mioa701_wm9713.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Handles the Mitac mioa701 SoC system
  4. *
  5. * Copyright (C) 2008 Robert Jarzmik
  6. *
  7. * This is a little schema of the sound interconnections :
  8. *
  9. * Sagem X200 Wolfson WM9713
  10. * +--------+ +-------------------+ Rear Speaker
  11. * | | | | /-+
  12. * | +--->----->---+MONOIN SPKL+--->----+-+ |
  13. * | GSM | | | | | |
  14. * | +--->----->---+PCBEEP SPKR+--->----+-+ |
  15. * | CHIP | | | \-+
  16. * | +---<-----<---+MONO |
  17. * | | | | Front Speaker
  18. * +--------+ | | /-+
  19. * | HPL+--->----+-+ |
  20. * | | | | |
  21. * | OUT3+--->----+-+ |
  22. * | | \-+
  23. * | |
  24. * | | Front Micro
  25. * | | +
  26. * | MIC1+-----<--+o+
  27. * | | +
  28. * +-------------------+ ---
  29. */
  30. #include <linux/module.h>
  31. #include <linux/moduleparam.h>
  32. #include <linux/platform_device.h>
  33. #include <asm/mach-types.h>
  34. #include <linux/platform_data/asoc-pxa.h>
  35. #include <sound/core.h>
  36. #include <sound/pcm.h>
  37. #include <sound/soc.h>
  38. #include <sound/initval.h>
  39. #include <sound/ac97_codec.h>
  40. #include "../codecs/wm9713.h"
  41. #define AC97_GPIO_PULL 0x58
  42. /* Use GPIO8 for rear speaker amplifier */
  43. static int rear_amp_power(struct snd_soc_component *component, int power)
  44. {
  45. unsigned short reg;
  46. if (power) {
  47. reg = snd_soc_component_read(component, AC97_GPIO_CFG);
  48. snd_soc_component_write(component, AC97_GPIO_CFG, reg | 0x0100);
  49. reg = snd_soc_component_read(component, AC97_GPIO_PULL);
  50. snd_soc_component_write(component, AC97_GPIO_PULL, reg | (1<<15));
  51. } else {
  52. reg = snd_soc_component_read(component, AC97_GPIO_CFG);
  53. snd_soc_component_write(component, AC97_GPIO_CFG, reg & ~0x0100);
  54. reg = snd_soc_component_read(component, AC97_GPIO_PULL);
  55. snd_soc_component_write(component, AC97_GPIO_PULL, reg & ~(1<<15));
  56. }
  57. return 0;
  58. }
  59. static int rear_amp_event(struct snd_soc_dapm_widget *widget,
  60. struct snd_kcontrol *kctl, int event)
  61. {
  62. struct snd_soc_card *card = widget->dapm->card;
  63. struct snd_soc_pcm_runtime *rtd;
  64. struct snd_soc_component *component;
  65. rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  66. component = asoc_rtd_to_codec(rtd, 0)->component;
  67. return rear_amp_power(component, SND_SOC_DAPM_EVENT_ON(event));
  68. }
  69. /* mioa701 machine dapm widgets */
  70. static const struct snd_soc_dapm_widget mioa701_dapm_widgets[] = {
  71. SND_SOC_DAPM_SPK("Front Speaker", NULL),
  72. SND_SOC_DAPM_SPK("Rear Speaker", rear_amp_event),
  73. SND_SOC_DAPM_MIC("Headset", NULL),
  74. SND_SOC_DAPM_LINE("GSM Line Out", NULL),
  75. SND_SOC_DAPM_LINE("GSM Line In", NULL),
  76. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  77. SND_SOC_DAPM_MIC("Front Mic", NULL),
  78. };
  79. static const struct snd_soc_dapm_route audio_map[] = {
  80. /* Call Mic */
  81. {"Mic Bias", NULL, "Front Mic"},
  82. {"MIC1", NULL, "Mic Bias"},
  83. /* Headset Mic */
  84. {"LINEL", NULL, "Headset Mic"},
  85. {"LINER", NULL, "Headset Mic"},
  86. /* GSM Module */
  87. {"MONOIN", NULL, "GSM Line Out"},
  88. {"PCBEEP", NULL, "GSM Line Out"},
  89. {"GSM Line In", NULL, "MONO"},
  90. /* headphone connected to HPL, HPR */
  91. {"Headset", NULL, "HPL"},
  92. {"Headset", NULL, "HPR"},
  93. /* front speaker connected to HPL, OUT3 */
  94. {"Front Speaker", NULL, "HPL"},
  95. {"Front Speaker", NULL, "OUT3"},
  96. /* rear speaker connected to SPKL, SPKR */
  97. {"Rear Speaker", NULL, "SPKL"},
  98. {"Rear Speaker", NULL, "SPKR"},
  99. };
  100. static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
  101. {
  102. struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
  103. /* Prepare GPIO8 for rear speaker amplifier */
  104. snd_soc_component_update_bits(component, AC97_GPIO_CFG, 0x100, 0x100);
  105. /* Prepare MIC input */
  106. snd_soc_component_update_bits(component, AC97_3D_CONTROL, 0xc000, 0xc000);
  107. return 0;
  108. }
  109. static struct snd_soc_ops mioa701_ops;
  110. SND_SOC_DAILINK_DEFS(ac97,
  111. DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97")),
  112. DAILINK_COMP_ARRAY(COMP_CODEC("wm9713-codec", "wm9713-hifi")),
  113. DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
  114. SND_SOC_DAILINK_DEFS(ac97_aux,
  115. DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-ac97-aux")),
  116. DAILINK_COMP_ARRAY(COMP_CODEC("wm9713-codec", "wm9713-aux")),
  117. DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
  118. static struct snd_soc_dai_link mioa701_dai[] = {
  119. {
  120. .name = "AC97",
  121. .stream_name = "AC97 HiFi",
  122. .init = mioa701_wm9713_init,
  123. .ops = &mioa701_ops,
  124. SND_SOC_DAILINK_REG(ac97),
  125. },
  126. {
  127. .name = "AC97 Aux",
  128. .stream_name = "AC97 Aux",
  129. .ops = &mioa701_ops,
  130. SND_SOC_DAILINK_REG(ac97_aux),
  131. },
  132. };
  133. static struct snd_soc_card mioa701 = {
  134. .name = "MioA701",
  135. .owner = THIS_MODULE,
  136. .dai_link = mioa701_dai,
  137. .num_links = ARRAY_SIZE(mioa701_dai),
  138. .dapm_widgets = mioa701_dapm_widgets,
  139. .num_dapm_widgets = ARRAY_SIZE(mioa701_dapm_widgets),
  140. .dapm_routes = audio_map,
  141. .num_dapm_routes = ARRAY_SIZE(audio_map),
  142. };
  143. static int mioa701_wm9713_probe(struct platform_device *pdev)
  144. {
  145. int rc;
  146. if (!machine_is_mioa701())
  147. return -ENODEV;
  148. mioa701.dev = &pdev->dev;
  149. rc = devm_snd_soc_register_card(&pdev->dev, &mioa701);
  150. if (!rc)
  151. dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will "
  152. "lead to overheating and possible destruction of your device."
  153. " Do not use without a good knowledge of mio's board design!\n");
  154. return rc;
  155. }
  156. static struct platform_driver mioa701_wm9713_driver = {
  157. .probe = mioa701_wm9713_probe,
  158. .driver = {
  159. .name = "mioa701-wm9713",
  160. .pm = &snd_soc_pm_ops,
  161. },
  162. };
  163. module_platform_driver(mioa701_wm9713_driver);
  164. /* Module information */
  165. MODULE_AUTHOR("Robert Jarzmik ([email protected])");
  166. MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701");
  167. MODULE_LICENSE("GPL");
  168. MODULE_ALIAS("platform:mioa701-wm9713");