e750_wm9705.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 <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. static int e750_spk_amp_event(struct snd_soc_dapm_widget *w,
  25. struct snd_kcontrol *kcontrol, int event)
  26. {
  27. if (event & SND_SOC_DAPM_PRE_PMU)
  28. gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0);
  29. else if (event & SND_SOC_DAPM_POST_PMD)
  30. gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1);
  31. return 0;
  32. }
  33. static int e750_hp_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. gpio_set_value(GPIO_E750_HP_AMP_OFF, 0);
  38. else if (event & SND_SOC_DAPM_POST_PMD)
  39. gpio_set_value(GPIO_E750_HP_AMP_OFF, 1);
  40. return 0;
  41. }
  42. static const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
  43. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  44. SND_SOC_DAPM_SPK("Speaker", NULL),
  45. SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
  46. SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  47. e750_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
  48. SND_SOC_DAPM_POST_PMD),
  49. SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  50. e750_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
  51. SND_SOC_DAPM_POST_PMD),
  52. };
  53. static const struct snd_soc_dapm_route audio_map[] = {
  54. {"Headphone Amp", NULL, "HPOUTL"},
  55. {"Headphone Amp", NULL, "HPOUTR"},
  56. {"Headphone Jack", NULL, "Headphone Amp"},
  57. {"Speaker Amp", NULL, "MONOOUT"},
  58. {"Speaker", NULL, "Speaker Amp"},
  59. {"MIC1", NULL, "Mic (Internal)"},
  60. };
  61. static int e750_ac97_init(struct snd_soc_codec *codec)
  62. {
  63. snd_soc_dapm_nc_pin(codec, "LOUT");
  64. snd_soc_dapm_nc_pin(codec, "ROUT");
  65. snd_soc_dapm_nc_pin(codec, "PHONE");
  66. snd_soc_dapm_nc_pin(codec, "LINEINL");
  67. snd_soc_dapm_nc_pin(codec, "LINEINR");
  68. snd_soc_dapm_nc_pin(codec, "CDINL");
  69. snd_soc_dapm_nc_pin(codec, "CDINR");
  70. snd_soc_dapm_nc_pin(codec, "PCBEEP");
  71. snd_soc_dapm_nc_pin(codec, "MIC2");
  72. snd_soc_dapm_new_controls(codec, e750_dapm_widgets,
  73. ARRAY_SIZE(e750_dapm_widgets));
  74. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  75. snd_soc_dapm_sync(codec);
  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 = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
  83. .codec_dai = &wm9705_dai[WM9705_DAI_AC97_HIFI],
  84. .init = e750_ac97_init,
  85. /* use ops to check startup state */
  86. },
  87. {
  88. .name = "AC97 Aux",
  89. .stream_name = "AC97 Aux",
  90. .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
  91. .codec_dai = &wm9705_dai[WM9705_DAI_AC97_AUX],
  92. },
  93. };
  94. static struct snd_soc_card e750 = {
  95. .name = "Toshiba e750",
  96. .platform = &pxa2xx_soc_platform,
  97. .dai_link = e750_dai,
  98. .num_links = ARRAY_SIZE(e750_dai),
  99. };
  100. static struct snd_soc_device e750_snd_devdata = {
  101. .card = &e750,
  102. .codec_dev = &soc_codec_dev_wm9705,
  103. };
  104. static struct platform_device *e750_snd_device;
  105. static int __init e750_init(void)
  106. {
  107. int ret;
  108. if (!machine_is_e750())
  109. return -ENODEV;
  110. ret = gpio_request(GPIO_E750_HP_AMP_OFF, "Headphone amp");
  111. if (ret)
  112. return ret;
  113. ret = gpio_request(GPIO_E750_SPK_AMP_OFF, "Speaker amp");
  114. if (ret)
  115. goto free_hp_amp_gpio;
  116. ret = gpio_direction_output(GPIO_E750_HP_AMP_OFF, 1);
  117. if (ret)
  118. goto free_spk_amp_gpio;
  119. ret = gpio_direction_output(GPIO_E750_SPK_AMP_OFF, 1);
  120. if (ret)
  121. goto free_spk_amp_gpio;
  122. e750_snd_device = platform_device_alloc("soc-audio", -1);
  123. if (!e750_snd_device) {
  124. ret = -ENOMEM;
  125. goto free_spk_amp_gpio;
  126. }
  127. platform_set_drvdata(e750_snd_device, &e750_snd_devdata);
  128. e750_snd_devdata.dev = &e750_snd_device->dev;
  129. ret = platform_device_add(e750_snd_device);
  130. if (!ret)
  131. return 0;
  132. /* Fail gracefully */
  133. platform_device_put(e750_snd_device);
  134. free_spk_amp_gpio:
  135. gpio_free(GPIO_E750_SPK_AMP_OFF);
  136. free_hp_amp_gpio:
  137. gpio_free(GPIO_E750_HP_AMP_OFF);
  138. return ret;
  139. }
  140. static void __exit e750_exit(void)
  141. {
  142. platform_device_unregister(e750_snd_device);
  143. gpio_free(GPIO_E750_SPK_AMP_OFF);
  144. gpio_free(GPIO_E750_HP_AMP_OFF);
  145. }
  146. module_init(e750_init);
  147. module_exit(e750_exit);
  148. /* Module information */
  149. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  150. MODULE_DESCRIPTION("ALSA SoC driver for e750");
  151. MODULE_LICENSE("GPL v2");