mioa701_wm9713.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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/soc-dapm.h>
  51. #include <sound/initval.h>
  52. #include <sound/ac97_codec.h>
  53. #include "pxa2xx-ac97.h"
  54. #include "../codecs/wm9713.h"
  55. #define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x)
  56. #define AC97_GPIO_PULL 0x58
  57. /* Use GPIO8 for rear speaker amplifier */
  58. static int rear_amp_power(struct snd_soc_codec *codec, int power)
  59. {
  60. unsigned short reg;
  61. if (power) {
  62. reg = snd_soc_read(codec, AC97_GPIO_CFG);
  63. snd_soc_write(codec, AC97_GPIO_CFG, reg | 0x0100);
  64. reg = snd_soc_read(codec, AC97_GPIO_PULL);
  65. snd_soc_write(codec, AC97_GPIO_PULL, reg | (1<<15));
  66. } else {
  67. reg = snd_soc_read(codec, AC97_GPIO_CFG);
  68. snd_soc_write(codec, AC97_GPIO_CFG, reg & ~0x0100);
  69. reg = snd_soc_read(codec, AC97_GPIO_PULL);
  70. snd_soc_write(codec, AC97_GPIO_PULL, reg & ~(1<<15));
  71. }
  72. return 0;
  73. }
  74. static int rear_amp_event(struct snd_soc_dapm_widget *widget,
  75. struct snd_kcontrol *kctl, int event)
  76. {
  77. struct snd_soc_codec *codec = widget->codec;
  78. return rear_amp_power(codec, SND_SOC_DAPM_EVENT_ON(event));
  79. }
  80. /* mioa701 machine dapm widgets */
  81. static const struct snd_soc_dapm_widget mioa701_dapm_widgets[] = {
  82. SND_SOC_DAPM_SPK("Front Speaker", NULL),
  83. SND_SOC_DAPM_SPK("Rear Speaker", rear_amp_event),
  84. SND_SOC_DAPM_MIC("Headset", NULL),
  85. SND_SOC_DAPM_LINE("GSM Line Out", NULL),
  86. SND_SOC_DAPM_LINE("GSM Line In", NULL),
  87. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  88. SND_SOC_DAPM_MIC("Front Mic", NULL),
  89. };
  90. static const struct snd_soc_dapm_route audio_map[] = {
  91. /* Call Mic */
  92. {"Mic Bias", NULL, "Front Mic"},
  93. {"MIC1", NULL, "Mic Bias"},
  94. /* Headset Mic */
  95. {"LINEL", NULL, "Headset Mic"},
  96. {"LINER", NULL, "Headset Mic"},
  97. /* GSM Module */
  98. {"MONOIN", NULL, "GSM Line Out"},
  99. {"PCBEEP", NULL, "GSM Line Out"},
  100. {"GSM Line In", NULL, "MONO"},
  101. /* headphone connected to HPL, HPR */
  102. {"Headset", NULL, "HPL"},
  103. {"Headset", NULL, "HPR"},
  104. /* front speaker connected to HPL, OUT3 */
  105. {"Front Speaker", NULL, "HPL"},
  106. {"Front Speaker", NULL, "OUT3"},
  107. /* rear speaker connected to SPKL, SPKR */
  108. {"Rear Speaker", NULL, "SPKL"},
  109. {"Rear Speaker", NULL, "SPKR"},
  110. };
  111. static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
  112. {
  113. struct snd_soc_codec *codec = rtd->codec;
  114. struct snd_soc_dapm_context *dapm = &codec->dapm;
  115. unsigned short reg;
  116. /* Add mioa701 specific widgets */
  117. snd_soc_dapm_new_controls(dapm, ARRAY_AND_SIZE(mioa701_dapm_widgets));
  118. /* Set up mioa701 specific audio path audio_mapnects */
  119. snd_soc_dapm_add_routes(dapm, ARRAY_AND_SIZE(audio_map));
  120. /* Prepare GPIO8 for rear speaker amplifier */
  121. reg = codec->driver->read(codec, AC97_GPIO_CFG);
  122. codec->driver->write(codec, AC97_GPIO_CFG, reg | 0x0100);
  123. /* Prepare MIC input */
  124. reg = codec->driver->read(codec, AC97_3D_CONTROL);
  125. codec->driver->write(codec, AC97_3D_CONTROL, reg | 0xc000);
  126. snd_soc_dapm_enable_pin(dapm, "Front Speaker");
  127. snd_soc_dapm_enable_pin(dapm, "Rear Speaker");
  128. snd_soc_dapm_enable_pin(dapm, "Front Mic");
  129. snd_soc_dapm_enable_pin(dapm, "GSM Line In");
  130. snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
  131. snd_soc_dapm_sync(dapm);
  132. return 0;
  133. }
  134. static struct snd_soc_ops mioa701_ops;
  135. static struct snd_soc_dai_link mioa701_dai[] = {
  136. {
  137. .name = "AC97",
  138. .stream_name = "AC97 HiFi",
  139. .cpu_dai_name = "pxa-ac97.0",
  140. .codec_dai_name = "wm9713-hifi",
  141. .codec_name = "wm9713-codec",
  142. .init = mioa701_wm9713_init,
  143. .platform_name = "pxa-pcm-audio",
  144. .ops = &mioa701_ops,
  145. },
  146. {
  147. .name = "AC97 Aux",
  148. .stream_name = "AC97 Aux",
  149. .cpu_dai_name = "pxa-ac97.1",
  150. .codec_dai_name ="wm9713-aux",
  151. .codec_name = "wm9713-codec",
  152. .platform_name = "pxa-pcm-audio",
  153. .ops = &mioa701_ops,
  154. },
  155. };
  156. static struct snd_soc_card mioa701 = {
  157. .name = "MioA701",
  158. .dai_link = mioa701_dai,
  159. .num_links = ARRAY_SIZE(mioa701_dai),
  160. };
  161. static struct platform_device *mioa701_snd_device;
  162. static int mioa701_wm9713_probe(struct platform_device *pdev)
  163. {
  164. int ret;
  165. if (!machine_is_mioa701())
  166. return -ENODEV;
  167. dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will"
  168. "lead to overheating and possible destruction of your device."
  169. "Do not use without a good knowledge of mio's board design!\n");
  170. mioa701_snd_device = platform_device_alloc("soc-audio", -1);
  171. if (!mioa701_snd_device)
  172. return -ENOMEM;
  173. platform_set_drvdata(mioa701_snd_device, &mioa701);
  174. ret = platform_device_add(mioa701_snd_device);
  175. if (!ret)
  176. return 0;
  177. platform_device_put(mioa701_snd_device);
  178. return ret;
  179. }
  180. static int __devexit mioa701_wm9713_remove(struct platform_device *pdev)
  181. {
  182. platform_device_unregister(mioa701_snd_device);
  183. return 0;
  184. }
  185. static struct platform_driver mioa701_wm9713_driver = {
  186. .probe = mioa701_wm9713_probe,
  187. .remove = __devexit_p(mioa701_wm9713_remove),
  188. .driver = {
  189. .name = "mioa701-wm9713",
  190. .owner = THIS_MODULE,
  191. },
  192. };
  193. static int __init mioa701_asoc_init(void)
  194. {
  195. return platform_driver_register(&mioa701_wm9713_driver);
  196. }
  197. static void __exit mioa701_asoc_exit(void)
  198. {
  199. platform_driver_unregister(&mioa701_wm9713_driver);
  200. }
  201. module_init(mioa701_asoc_init);
  202. module_exit(mioa701_asoc_exit);
  203. /* Module information */
  204. MODULE_AUTHOR("Robert Jarzmik (rjarzmik@free.fr)");
  205. MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701");
  206. MODULE_LICENSE("GPL");