e750_wm9705.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * e750-wm9705.c -- SoC audio for e750
  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 <mach/audio.h>
  18. #include <mach/eseries-gpio.h>
  19. #include <asm/mach-types.h>
  20. #include "../codecs/wm9705.h"
  21. #include "pxa2xx-ac97.h"
  22. static int e750_spk_amp_event(struct snd_soc_dapm_widget *w,
  23. struct snd_kcontrol *kcontrol, int event)
  24. {
  25. if (event & SND_SOC_DAPM_PRE_PMU)
  26. gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0);
  27. else if (event & SND_SOC_DAPM_POST_PMD)
  28. gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1);
  29. return 0;
  30. }
  31. static int e750_hp_amp_event(struct snd_soc_dapm_widget *w,
  32. struct snd_kcontrol *kcontrol, int event)
  33. {
  34. if (event & SND_SOC_DAPM_PRE_PMU)
  35. gpio_set_value(GPIO_E750_HP_AMP_OFF, 0);
  36. else if (event & SND_SOC_DAPM_POST_PMD)
  37. gpio_set_value(GPIO_E750_HP_AMP_OFF, 1);
  38. return 0;
  39. }
  40. static const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
  41. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  42. SND_SOC_DAPM_SPK("Speaker", NULL),
  43. SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
  44. SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  45. e750_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
  46. SND_SOC_DAPM_POST_PMD),
  47. SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  48. e750_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
  49. SND_SOC_DAPM_POST_PMD),
  50. };
  51. static const struct snd_soc_dapm_route audio_map[] = {
  52. {"Headphone Amp", NULL, "HPOUTL"},
  53. {"Headphone Amp", NULL, "HPOUTR"},
  54. {"Headphone Jack", NULL, "Headphone Amp"},
  55. {"Speaker Amp", NULL, "MONOOUT"},
  56. {"Speaker", NULL, "Speaker Amp"},
  57. {"MIC1", NULL, "Mic (Internal)"},
  58. };
  59. static int e750_ac97_init(struct snd_soc_pcm_runtime *rtd)
  60. {
  61. struct snd_soc_codec *codec = rtd->codec;
  62. struct snd_soc_dapm_context *dapm = &codec->dapm;
  63. snd_soc_dapm_nc_pin(dapm, "LOUT");
  64. snd_soc_dapm_nc_pin(dapm, "ROUT");
  65. snd_soc_dapm_nc_pin(dapm, "PHONE");
  66. snd_soc_dapm_nc_pin(dapm, "LINEINL");
  67. snd_soc_dapm_nc_pin(dapm, "LINEINR");
  68. snd_soc_dapm_nc_pin(dapm, "CDINL");
  69. snd_soc_dapm_nc_pin(dapm, "CDINR");
  70. snd_soc_dapm_nc_pin(dapm, "PCBEEP");
  71. snd_soc_dapm_nc_pin(dapm, "MIC2");
  72. snd_soc_dapm_new_controls(dapm, e750_dapm_widgets,
  73. ARRAY_SIZE(e750_dapm_widgets));
  74. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  75. snd_soc_dapm_sync(dapm);
  76. return 0;
  77. }
  78. static struct snd_soc_dai_link e750_dai[] = {
  79. {
  80. .name = "AC97",
  81. .stream_name = "AC97 HiFi",
  82. .cpu_dai_name = "pxa2xx-ac97",
  83. .codec_dai_name = "wm9705-hifi",
  84. .platform_name = "pxa-pcm-audio",
  85. .codec_name = "wm9705-codec",
  86. .init = e750_ac97_init,
  87. /* use ops to check startup state */
  88. },
  89. {
  90. .name = "AC97 Aux",
  91. .stream_name = "AC97 Aux",
  92. .cpu_dai_name = "pxa2xx-ac97-aux",
  93. .codec_dai_name ="wm9705-aux",
  94. .platform_name = "pxa-pcm-audio",
  95. .codec_name = "wm9705-codec",
  96. },
  97. };
  98. static struct snd_soc_card e750 = {
  99. .name = "Toshiba e750",
  100. .dai_link = e750_dai,
  101. .num_links = ARRAY_SIZE(e750_dai),
  102. };
  103. static struct platform_device *e750_snd_device;
  104. static int __init e750_init(void)
  105. {
  106. int ret;
  107. if (!machine_is_e750())
  108. return -ENODEV;
  109. ret = gpio_request(GPIO_E750_HP_AMP_OFF, "Headphone amp");
  110. if (ret)
  111. return ret;
  112. ret = gpio_request(GPIO_E750_SPK_AMP_OFF, "Speaker amp");
  113. if (ret)
  114. goto free_hp_amp_gpio;
  115. ret = gpio_direction_output(GPIO_E750_HP_AMP_OFF, 1);
  116. if (ret)
  117. goto free_spk_amp_gpio;
  118. ret = gpio_direction_output(GPIO_E750_SPK_AMP_OFF, 1);
  119. if (ret)
  120. goto free_spk_amp_gpio;
  121. e750_snd_device = platform_device_alloc("soc-audio", -1);
  122. if (!e750_snd_device) {
  123. ret = -ENOMEM;
  124. goto free_spk_amp_gpio;
  125. }
  126. platform_set_drvdata(e750_snd_device, &e750);
  127. ret = platform_device_add(e750_snd_device);
  128. if (!ret)
  129. return 0;
  130. /* Fail gracefully */
  131. platform_device_put(e750_snd_device);
  132. free_spk_amp_gpio:
  133. gpio_free(GPIO_E750_SPK_AMP_OFF);
  134. free_hp_amp_gpio:
  135. gpio_free(GPIO_E750_HP_AMP_OFF);
  136. return ret;
  137. }
  138. static void __exit e750_exit(void)
  139. {
  140. platform_device_unregister(e750_snd_device);
  141. gpio_free(GPIO_E750_SPK_AMP_OFF);
  142. gpio_free(GPIO_E750_HP_AMP_OFF);
  143. }
  144. module_init(e750_init);
  145. module_exit(e750_exit);
  146. /* Module information */
  147. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  148. MODULE_DESCRIPTION("ALSA SoC driver for e750");
  149. MODULE_LICENSE("GPL v2");