e740_wm9705.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * e740-wm9705.c -- SoC audio for e740
  3. *
  4. * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; version 2 ONLY.
  9. *
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/gpio.h>
  14. #include <sound/core.h>
  15. #include <sound/pcm.h>
  16. #include <sound/soc.h>
  17. #include <sound/soc-dapm.h>
  18. #include <mach/audio.h>
  19. #include <mach/eseries-gpio.h>
  20. #include <asm/mach-types.h>
  21. #include "../codecs/wm9705.h"
  22. #include "pxa2xx-pcm.h"
  23. #include "pxa2xx-ac97.h"
  24. #define E740_AUDIO_OUT 1
  25. #define E740_AUDIO_IN 2
  26. static int e740_audio_power;
  27. static void e740_sync_audio_power(int status)
  28. {
  29. gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status);
  30. gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0);
  31. gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0);
  32. }
  33. static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
  34. struct snd_kcontrol *kcontrol, int event)
  35. {
  36. if (event & SND_SOC_DAPM_PRE_PMU)
  37. e740_audio_power |= E740_AUDIO_IN;
  38. else if (event & SND_SOC_DAPM_POST_PMD)
  39. e740_audio_power &= ~E740_AUDIO_IN;
  40. e740_sync_audio_power(e740_audio_power);
  41. return 0;
  42. }
  43. static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
  44. struct snd_kcontrol *kcontrol, int event)
  45. {
  46. if (event & SND_SOC_DAPM_PRE_PMU)
  47. e740_audio_power |= E740_AUDIO_OUT;
  48. else if (event & SND_SOC_DAPM_POST_PMD)
  49. e740_audio_power &= ~E740_AUDIO_OUT;
  50. e740_sync_audio_power(e740_audio_power);
  51. return 0;
  52. }
  53. static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
  54. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  55. SND_SOC_DAPM_SPK("Speaker", NULL),
  56. SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
  57. SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  58. e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
  59. SND_SOC_DAPM_POST_PMD),
  60. SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  61. e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
  62. SND_SOC_DAPM_POST_PMD),
  63. };
  64. static const struct snd_soc_dapm_route audio_map[] = {
  65. {"Output Amp", NULL, "LOUT"},
  66. {"Output Amp", NULL, "ROUT"},
  67. {"Output Amp", NULL, "MONOOUT"},
  68. {"Speaker", NULL, "Output Amp"},
  69. {"Headphone Jack", NULL, "Output Amp"},
  70. {"MIC1", NULL, "Mic Amp"},
  71. {"Mic Amp", NULL, "Mic (Internal)"},
  72. };
  73. static int e740_ac97_init(struct snd_soc_codec *codec)
  74. {
  75. snd_soc_dapm_nc_pin(codec, "HPOUTL");
  76. snd_soc_dapm_nc_pin(codec, "HPOUTR");
  77. snd_soc_dapm_nc_pin(codec, "PHONE");
  78. snd_soc_dapm_nc_pin(codec, "LINEINL");
  79. snd_soc_dapm_nc_pin(codec, "LINEINR");
  80. snd_soc_dapm_nc_pin(codec, "CDINL");
  81. snd_soc_dapm_nc_pin(codec, "CDINR");
  82. snd_soc_dapm_nc_pin(codec, "PCBEEP");
  83. snd_soc_dapm_nc_pin(codec, "MIC2");
  84. snd_soc_dapm_new_controls(codec, e740_dapm_widgets,
  85. ARRAY_SIZE(e740_dapm_widgets));
  86. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  87. snd_soc_dapm_sync(codec);
  88. return 0;
  89. }
  90. static struct snd_soc_dai_link e740_dai[] = {
  91. {
  92. .name = "AC97",
  93. .stream_name = "AC97 HiFi",
  94. .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
  95. .codec_dai = &wm9705_dai[WM9705_DAI_AC97_HIFI],
  96. .init = e740_ac97_init,
  97. },
  98. {
  99. .name = "AC97 Aux",
  100. .stream_name = "AC97 Aux",
  101. .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
  102. .codec_dai = &wm9705_dai[WM9705_DAI_AC97_AUX],
  103. },
  104. };
  105. static struct snd_soc_card e740 = {
  106. .name = "Toshiba e740",
  107. .platform = &pxa2xx_soc_platform,
  108. .dai_link = e740_dai,
  109. .num_links = ARRAY_SIZE(e740_dai),
  110. };
  111. static struct snd_soc_device e740_snd_devdata = {
  112. .card = &e740,
  113. .codec_dev = &soc_codec_dev_wm9705,
  114. };
  115. static struct platform_device *e740_snd_device;
  116. static int __init e740_init(void)
  117. {
  118. int ret;
  119. if (!machine_is_e740())
  120. return -ENODEV;
  121. ret = gpio_request(GPIO_E740_MIC_ON, "Mic amp");
  122. if (ret)
  123. return ret;
  124. ret = gpio_request(GPIO_E740_AMP_ON, "Output amp");
  125. if (ret)
  126. goto free_mic_amp_gpio;
  127. ret = gpio_request(GPIO_E740_WM9705_nAVDD2, "Audio power");
  128. if (ret)
  129. goto free_op_amp_gpio;
  130. /* Disable audio */
  131. ret = gpio_direction_output(GPIO_E740_MIC_ON, 0);
  132. if (ret)
  133. goto free_apwr_gpio;
  134. ret = gpio_direction_output(GPIO_E740_AMP_ON, 0);
  135. if (ret)
  136. goto free_apwr_gpio;
  137. ret = gpio_direction_output(GPIO_E740_WM9705_nAVDD2, 1);
  138. if (ret)
  139. goto free_apwr_gpio;
  140. e740_snd_device = platform_device_alloc("soc-audio", -1);
  141. if (!e740_snd_device) {
  142. ret = -ENOMEM;
  143. goto free_apwr_gpio;
  144. }
  145. platform_set_drvdata(e740_snd_device, &e740_snd_devdata);
  146. e740_snd_devdata.dev = &e740_snd_device->dev;
  147. ret = platform_device_add(e740_snd_device);
  148. if (!ret)
  149. return 0;
  150. /* Fail gracefully */
  151. platform_device_put(e740_snd_device);
  152. free_apwr_gpio:
  153. gpio_free(GPIO_E740_WM9705_nAVDD2);
  154. free_op_amp_gpio:
  155. gpio_free(GPIO_E740_AMP_ON);
  156. free_mic_amp_gpio:
  157. gpio_free(GPIO_E740_MIC_ON);
  158. return ret;
  159. }
  160. static void __exit e740_exit(void)
  161. {
  162. platform_device_unregister(e740_snd_device);
  163. }
  164. module_init(e740_init);
  165. module_exit(e740_exit);
  166. /* Module information */
  167. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  168. MODULE_DESCRIPTION("ALSA SoC driver for e740");
  169. MODULE_LICENSE("GPL v2");