mioa701_wm9713.c 6.5 KB

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