mioa701_wm9713.c 7.0 KB

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