e800_wm9712.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 <asm/mach-types.h>
  18. #include <mach/audio.h>
  19. #include <mach/eseries-gpio.h>
  20. #include "../codecs/wm9712.h"
  21. #include "pxa2xx-ac97.h"
  22. static int e800_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_E800_SPK_AMP_ON, 1);
  27. else if (event & SND_SOC_DAPM_POST_PMD)
  28. gpio_set_value(GPIO_E800_SPK_AMP_ON, 0);
  29. return 0;
  30. }
  31. static int e800_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_E800_HP_AMP_OFF, 0);
  36. else if (event & SND_SOC_DAPM_POST_PMD)
  37. gpio_set_value(GPIO_E800_HP_AMP_OFF, 1);
  38. return 0;
  39. }
  40. static const struct snd_soc_dapm_widget e800_dapm_widgets[] = {
  41. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  42. SND_SOC_DAPM_MIC("Mic (Internal1)", NULL),
  43. SND_SOC_DAPM_MIC("Mic (Internal2)", NULL),
  44. SND_SOC_DAPM_SPK("Speaker", NULL),
  45. SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  46. e800_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
  47. SND_SOC_DAPM_POST_PMD),
  48. SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  49. e800_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
  50. SND_SOC_DAPM_POST_PMD),
  51. };
  52. static const struct snd_soc_dapm_route audio_map[] = {
  53. {"Headphone Jack", NULL, "HPOUTL"},
  54. {"Headphone Jack", NULL, "HPOUTR"},
  55. {"Headphone Jack", NULL, "Headphone Amp"},
  56. {"Speaker Amp", NULL, "MONOOUT"},
  57. {"Speaker", NULL, "Speaker Amp"},
  58. {"MIC1", NULL, "Mic (Internal1)"},
  59. {"MIC2", NULL, "Mic (Internal2)"},
  60. };
  61. static int e800_ac97_init(struct snd_soc_pcm_runtime *rtd)
  62. {
  63. struct snd_soc_codec *codec = rtd->codec;
  64. struct snd_soc_dapm_context *dapm = &codec->dapm;
  65. snd_soc_dapm_new_controls(dapm, e800_dapm_widgets,
  66. ARRAY_SIZE(e800_dapm_widgets));
  67. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  68. return 0;
  69. }
  70. static struct snd_soc_dai_link e800_dai[] = {
  71. {
  72. .name = "AC97",
  73. .stream_name = "AC97 HiFi",
  74. .cpu_dai_name = "pxa2xx-ac97",
  75. .codec_dai_name = "wm9712-hifi",
  76. .platform_name = "pxa-pcm-audio",
  77. .codec_name = "wm9712-codec",
  78. .init = e800_ac97_init,
  79. },
  80. {
  81. .name = "AC97 Aux",
  82. .stream_name = "AC97 Aux",
  83. .cpu_dai_name = "pxa2xx-ac97-aux",
  84. .codec_dai_name ="wm9712-aux",
  85. .platform_name = "pxa-pcm-audio",
  86. .codec_name = "wm9712-codec",
  87. },
  88. };
  89. static struct snd_soc_card e800 = {
  90. .name = "Toshiba e800",
  91. .owner = THIS_MODULE,
  92. .dai_link = e800_dai,
  93. .num_links = ARRAY_SIZE(e800_dai),
  94. };
  95. static struct gpio e800_audio_gpios[] = {
  96. { GPIO_E800_SPK_AMP_ON, GPIOF_OUT_INIT_HIGH, "Headphone amp" },
  97. { GPIO_E800_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" },
  98. };
  99. static int __devinit e800_probe(struct platform_device *pdev)
  100. {
  101. struct snd_soc_card *card = &e800;
  102. int ret;
  103. ret = gpio_request_array(e800_audio_gpios,
  104. ARRAY_SIZE(e800_audio_gpios));
  105. if (ret)
  106. return ret;
  107. card->dev = &pdev->dev;
  108. ret = snd_soc_register_card(card);
  109. if (ret) {
  110. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  111. ret);
  112. gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios));
  113. }
  114. return ret;
  115. }
  116. static int __devexit e800_remove(struct platform_device *pdev)
  117. {
  118. struct snd_soc_card *card = platform_get_drvdata(pdev);
  119. gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios));
  120. snd_soc_unregister_card(card);
  121. return 0;
  122. }
  123. static struct platform_driver e800_driver = {
  124. .driver = {
  125. .name = "e800-audio",
  126. .owner = THIS_MODULE,
  127. },
  128. .probe = e800_probe,
  129. .remove = __devexit_p(e800_remove),
  130. };
  131. module_platform_driver(e800_driver);
  132. /* Module information */
  133. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  134. MODULE_DESCRIPTION("ALSA SoC driver for e800");
  135. MODULE_LICENSE("GPL v2");
  136. MODULE_ALIAS("platform:e800-audio");