e800_wm9712.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 "pxa2xx-ac97.h"
  21. static int e800_spk_amp_event(struct snd_soc_dapm_widget *w,
  22. struct snd_kcontrol *kcontrol, int event)
  23. {
  24. if (event & SND_SOC_DAPM_PRE_PMU)
  25. gpio_set_value(GPIO_E800_SPK_AMP_ON, 1);
  26. else if (event & SND_SOC_DAPM_POST_PMD)
  27. gpio_set_value(GPIO_E800_SPK_AMP_ON, 0);
  28. return 0;
  29. }
  30. static int e800_hp_amp_event(struct snd_soc_dapm_widget *w,
  31. struct snd_kcontrol *kcontrol, int event)
  32. {
  33. if (event & SND_SOC_DAPM_PRE_PMU)
  34. gpio_set_value(GPIO_E800_HP_AMP_OFF, 0);
  35. else if (event & SND_SOC_DAPM_POST_PMD)
  36. gpio_set_value(GPIO_E800_HP_AMP_OFF, 1);
  37. return 0;
  38. }
  39. static const struct snd_soc_dapm_widget e800_dapm_widgets[] = {
  40. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  41. SND_SOC_DAPM_MIC("Mic (Internal1)", NULL),
  42. SND_SOC_DAPM_MIC("Mic (Internal2)", NULL),
  43. SND_SOC_DAPM_SPK("Speaker", NULL),
  44. SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  45. e800_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. e800_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 Jack", NULL, "HPOUTL"},
  53. {"Headphone Jack", NULL, "HPOUTR"},
  54. {"Headphone Jack", NULL, "Headphone Amp"},
  55. {"Speaker Amp", NULL, "MONOOUT"},
  56. {"Speaker", NULL, "Speaker Amp"},
  57. {"MIC1", NULL, "Mic (Internal1)"},
  58. {"MIC2", NULL, "Mic (Internal2)"},
  59. };
  60. static struct snd_soc_dai_link e800_dai[] = {
  61. {
  62. .name = "AC97",
  63. .stream_name = "AC97 HiFi",
  64. .cpu_dai_name = "pxa2xx-ac97",
  65. .codec_dai_name = "wm9712-hifi",
  66. .platform_name = "pxa-pcm-audio",
  67. .codec_name = "wm9712-codec",
  68. },
  69. {
  70. .name = "AC97 Aux",
  71. .stream_name = "AC97 Aux",
  72. .cpu_dai_name = "pxa2xx-ac97-aux",
  73. .codec_dai_name ="wm9712-aux",
  74. .platform_name = "pxa-pcm-audio",
  75. .codec_name = "wm9712-codec",
  76. },
  77. };
  78. static struct snd_soc_card e800 = {
  79. .name = "Toshiba e800",
  80. .owner = THIS_MODULE,
  81. .dai_link = e800_dai,
  82. .num_links = ARRAY_SIZE(e800_dai),
  83. .dapm_widgets = e800_dapm_widgets,
  84. .num_dapm_widgets = ARRAY_SIZE(e800_dapm_widgets),
  85. .dapm_routes = audio_map,
  86. .num_dapm_routes = ARRAY_SIZE(audio_map),
  87. };
  88. static struct gpio e800_audio_gpios[] = {
  89. { GPIO_E800_SPK_AMP_ON, GPIOF_OUT_INIT_HIGH, "Headphone amp" },
  90. { GPIO_E800_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" },
  91. };
  92. static int e800_probe(struct platform_device *pdev)
  93. {
  94. struct snd_soc_card *card = &e800;
  95. int ret;
  96. ret = gpio_request_array(e800_audio_gpios,
  97. ARRAY_SIZE(e800_audio_gpios));
  98. if (ret)
  99. return ret;
  100. card->dev = &pdev->dev;
  101. ret = devm_snd_soc_register_card(&pdev->dev, card);
  102. if (ret) {
  103. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  104. ret);
  105. gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios));
  106. }
  107. return ret;
  108. }
  109. static int e800_remove(struct platform_device *pdev)
  110. {
  111. gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios));
  112. return 0;
  113. }
  114. static struct platform_driver e800_driver = {
  115. .driver = {
  116. .name = "e800-audio",
  117. .pm = &snd_soc_pm_ops,
  118. },
  119. .probe = e800_probe,
  120. .remove = e800_remove,
  121. };
  122. module_platform_driver(e800_driver);
  123. /* Module information */
  124. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  125. MODULE_DESCRIPTION("ALSA SoC driver for e800");
  126. MODULE_LICENSE("GPL v2");
  127. MODULE_ALIAS("platform:e800-audio");