mioa701_wm9713.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 "pxa2xx-ac97.h"
  53. #include "../codecs/wm9713.h"
  54. #define AC97_GPIO_PULL 0x58
  55. /* Use GPIO8 for rear speaker amplifier */
  56. static int rear_amp_power(struct snd_soc_codec *codec, int power)
  57. {
  58. unsigned short reg;
  59. if (power) {
  60. reg = snd_soc_read(codec, AC97_GPIO_CFG);
  61. snd_soc_write(codec, AC97_GPIO_CFG, reg | 0x0100);
  62. reg = snd_soc_read(codec, AC97_GPIO_PULL);
  63. snd_soc_write(codec, AC97_GPIO_PULL, reg | (1<<15));
  64. } else {
  65. reg = snd_soc_read(codec, AC97_GPIO_CFG);
  66. snd_soc_write(codec, AC97_GPIO_CFG, reg & ~0x0100);
  67. reg = snd_soc_read(codec, AC97_GPIO_PULL);
  68. snd_soc_write(codec, AC97_GPIO_PULL, reg & ~(1<<15));
  69. }
  70. return 0;
  71. }
  72. static int rear_amp_event(struct snd_soc_dapm_widget *widget,
  73. struct snd_kcontrol *kctl, int event)
  74. {
  75. struct snd_soc_card *card = widget->dapm->card;
  76. struct snd_soc_pcm_runtime *rtd;
  77. struct snd_soc_codec *codec;
  78. rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
  79. codec = rtd->codec;
  80. return rear_amp_power(codec, SND_SOC_DAPM_EVENT_ON(event));
  81. }
  82. /* mioa701 machine dapm widgets */
  83. static const struct snd_soc_dapm_widget mioa701_dapm_widgets[] = {
  84. SND_SOC_DAPM_SPK("Front Speaker", NULL),
  85. SND_SOC_DAPM_SPK("Rear Speaker", rear_amp_event),
  86. SND_SOC_DAPM_MIC("Headset", NULL),
  87. SND_SOC_DAPM_LINE("GSM Line Out", NULL),
  88. SND_SOC_DAPM_LINE("GSM Line In", NULL),
  89. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  90. SND_SOC_DAPM_MIC("Front Mic", NULL),
  91. };
  92. static const struct snd_soc_dapm_route audio_map[] = {
  93. /* Call Mic */
  94. {"Mic Bias", NULL, "Front Mic"},
  95. {"MIC1", NULL, "Mic Bias"},
  96. /* Headset Mic */
  97. {"LINEL", NULL, "Headset Mic"},
  98. {"LINER", NULL, "Headset Mic"},
  99. /* GSM Module */
  100. {"MONOIN", NULL, "GSM Line Out"},
  101. {"PCBEEP", NULL, "GSM Line Out"},
  102. {"GSM Line In", NULL, "MONO"},
  103. /* headphone connected to HPL, HPR */
  104. {"Headset", NULL, "HPL"},
  105. {"Headset", NULL, "HPR"},
  106. /* front speaker connected to HPL, OUT3 */
  107. {"Front Speaker", NULL, "HPL"},
  108. {"Front Speaker", NULL, "OUT3"},
  109. /* rear speaker connected to SPKL, SPKR */
  110. {"Rear Speaker", NULL, "SPKL"},
  111. {"Rear Speaker", NULL, "SPKR"},
  112. };
  113. static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
  114. {
  115. struct snd_soc_codec *codec = rtd->codec;
  116. /* Prepare GPIO8 for rear speaker amplifier */
  117. snd_soc_update_bits(codec, AC97_GPIO_CFG, 0x100, 0x100);
  118. /* Prepare MIC input */
  119. snd_soc_update_bits(codec, AC97_3D_CONTROL, 0xc000, 0xc000);
  120. return 0;
  121. }
  122. static struct snd_soc_ops mioa701_ops;
  123. static struct snd_soc_dai_link mioa701_dai[] = {
  124. {
  125. .name = "AC97",
  126. .stream_name = "AC97 HiFi",
  127. .cpu_dai_name = "pxa2xx-ac97",
  128. .codec_dai_name = "wm9713-hifi",
  129. .codec_name = "wm9713-codec",
  130. .init = mioa701_wm9713_init,
  131. .platform_name = "pxa-pcm-audio",
  132. .ops = &mioa701_ops,
  133. },
  134. {
  135. .name = "AC97 Aux",
  136. .stream_name = "AC97 Aux",
  137. .cpu_dai_name = "pxa2xx-ac97-aux",
  138. .codec_dai_name ="wm9713-aux",
  139. .codec_name = "wm9713-codec",
  140. .platform_name = "pxa-pcm-audio",
  141. .ops = &mioa701_ops,
  142. },
  143. };
  144. static struct snd_soc_card mioa701 = {
  145. .name = "MioA701",
  146. .owner = THIS_MODULE,
  147. .dai_link = mioa701_dai,
  148. .num_links = ARRAY_SIZE(mioa701_dai),
  149. .dapm_widgets = mioa701_dapm_widgets,
  150. .num_dapm_widgets = ARRAY_SIZE(mioa701_dapm_widgets),
  151. .dapm_routes = audio_map,
  152. .num_dapm_routes = ARRAY_SIZE(audio_map),
  153. };
  154. static int mioa701_wm9713_probe(struct platform_device *pdev)
  155. {
  156. int rc;
  157. if (!machine_is_mioa701())
  158. return -ENODEV;
  159. mioa701.dev = &pdev->dev;
  160. rc = devm_snd_soc_register_card(&pdev->dev, &mioa701);
  161. if (!rc)
  162. dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will"
  163. "lead to overheating and possible destruction of your device."
  164. " Do not use without a good knowledge of mio's board design!\n");
  165. return rc;
  166. }
  167. static struct platform_driver mioa701_wm9713_driver = {
  168. .probe = mioa701_wm9713_probe,
  169. .driver = {
  170. .name = "mioa701-wm9713",
  171. .pm = &snd_soc_pm_ops,
  172. },
  173. };
  174. module_platform_driver(mioa701_wm9713_driver);
  175. /* Module information */
  176. MODULE_AUTHOR("Robert Jarzmik (rjarzmik@free.fr)");
  177. MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701");
  178. MODULE_LICENSE("GPL");
  179. MODULE_ALIAS("platform:mioa701-wm9713");