e800_wm9712.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * e800-wm9712.c -- SoC audio for e800
  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 <asm/mach-types.h>
  19. #include <mach/audio.h>
  20. #include <mach/eseries-gpio.h>
  21. #include "../codecs/wm9712.h"
  22. #include "pxa2xx-pcm.h"
  23. #include "pxa2xx-ac97.h"
  24. static int e800_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_E800_SPK_AMP_ON, 1);
  29. else if (event & SND_SOC_DAPM_POST_PMD)
  30. gpio_set_value(GPIO_E800_SPK_AMP_ON, 0);
  31. return 0;
  32. }
  33. static int e800_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_E800_HP_AMP_OFF, 0);
  38. else if (event & SND_SOC_DAPM_POST_PMD)
  39. gpio_set_value(GPIO_E800_HP_AMP_OFF, 1);
  40. return 0;
  41. }
  42. static const struct snd_soc_dapm_widget e800_dapm_widgets[] = {
  43. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  44. SND_SOC_DAPM_MIC("Mic (Internal1)", NULL),
  45. SND_SOC_DAPM_MIC("Mic (Internal2)", NULL),
  46. SND_SOC_DAPM_SPK("Speaker", NULL),
  47. SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  48. e800_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
  49. SND_SOC_DAPM_POST_PMD),
  50. SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  51. e800_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
  52. SND_SOC_DAPM_POST_PMD),
  53. };
  54. static const struct snd_soc_dapm_route audio_map[] = {
  55. {"Headphone Jack", NULL, "HPOUTL"},
  56. {"Headphone Jack", NULL, "HPOUTR"},
  57. {"Headphone Jack", NULL, "Headphone Amp"},
  58. {"Speaker Amp", NULL, "MONOOUT"},
  59. {"Speaker", NULL, "Speaker Amp"},
  60. {"MIC1", NULL, "Mic (Internal1)"},
  61. {"MIC2", NULL, "Mic (Internal2)"},
  62. };
  63. static int e800_ac97_init(struct snd_soc_codec *codec)
  64. {
  65. snd_soc_dapm_new_controls(codec, e800_dapm_widgets,
  66. ARRAY_SIZE(e800_dapm_widgets));
  67. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  68. snd_soc_dapm_sync(codec);
  69. return 0;
  70. }
  71. static struct snd_soc_dai_link e800_dai[] = {
  72. {
  73. .name = "AC97",
  74. .stream_name = "AC97 HiFi",
  75. .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
  76. .codec_dai = &wm9712_dai[WM9712_DAI_AC97_HIFI],
  77. .init = e800_ac97_init,
  78. },
  79. {
  80. .name = "AC97 Aux",
  81. .stream_name = "AC97 Aux",
  82. .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
  83. .codec_dai = &wm9712_dai[WM9712_DAI_AC97_AUX],
  84. },
  85. };
  86. static struct snd_soc_card e800 = {
  87. .name = "Toshiba e800",
  88. .platform = &pxa2xx_soc_platform,
  89. .dai_link = e800_dai,
  90. .num_links = ARRAY_SIZE(e800_dai),
  91. };
  92. static struct snd_soc_device e800_snd_devdata = {
  93. .card = &e800,
  94. .codec_dev = &soc_codec_dev_wm9712,
  95. };
  96. static struct platform_device *e800_snd_device;
  97. static int __init e800_init(void)
  98. {
  99. int ret;
  100. if (!machine_is_e800())
  101. return -ENODEV;
  102. ret = gpio_request(GPIO_E800_HP_AMP_OFF, "Headphone amp");
  103. if (ret)
  104. return ret;
  105. ret = gpio_request(GPIO_E800_SPK_AMP_ON, "Speaker amp");
  106. if (ret)
  107. goto free_hp_amp_gpio;
  108. ret = gpio_direction_output(GPIO_E800_HP_AMP_OFF, 1);
  109. if (ret)
  110. goto free_spk_amp_gpio;
  111. ret = gpio_direction_output(GPIO_E800_SPK_AMP_ON, 1);
  112. if (ret)
  113. goto free_spk_amp_gpio;
  114. e800_snd_device = platform_device_alloc("soc-audio", -1);
  115. if (!e800_snd_device)
  116. return -ENOMEM;
  117. platform_set_drvdata(e800_snd_device, &e800_snd_devdata);
  118. e800_snd_devdata.dev = &e800_snd_device->dev;
  119. ret = platform_device_add(e800_snd_device);
  120. if (!ret)
  121. return 0;
  122. /* Fail gracefully */
  123. platform_device_put(e800_snd_device);
  124. free_spk_amp_gpio:
  125. gpio_free(GPIO_E800_SPK_AMP_ON);
  126. free_hp_amp_gpio:
  127. gpio_free(GPIO_E800_HP_AMP_OFF);
  128. return ret;
  129. }
  130. static void __exit e800_exit(void)
  131. {
  132. platform_device_unregister(e800_snd_device);
  133. gpio_free(GPIO_E800_SPK_AMP_ON);
  134. gpio_free(GPIO_E800_HP_AMP_OFF);
  135. }
  136. module_init(e800_init);
  137. module_exit(e800_exit);
  138. /* Module information */
  139. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  140. MODULE_DESCRIPTION("ALSA SoC driver for e800");
  141. MODULE_LICENSE("GPL v2");