e740_wm9705.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * e740-wm9705.c -- SoC audio for e740
  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. #define E740_AUDIO_OUT 1
  21. #define E740_AUDIO_IN 2
  22. static int e740_audio_power;
  23. static void e740_sync_audio_power(int status)
  24. {
  25. gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status);
  26. gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0);
  27. gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0);
  28. }
  29. static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
  30. struct snd_kcontrol *kcontrol, int event)
  31. {
  32. if (event & SND_SOC_DAPM_PRE_PMU)
  33. e740_audio_power |= E740_AUDIO_IN;
  34. else if (event & SND_SOC_DAPM_POST_PMD)
  35. e740_audio_power &= ~E740_AUDIO_IN;
  36. e740_sync_audio_power(e740_audio_power);
  37. return 0;
  38. }
  39. static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
  40. struct snd_kcontrol *kcontrol, int event)
  41. {
  42. if (event & SND_SOC_DAPM_PRE_PMU)
  43. e740_audio_power |= E740_AUDIO_OUT;
  44. else if (event & SND_SOC_DAPM_POST_PMD)
  45. e740_audio_power &= ~E740_AUDIO_OUT;
  46. e740_sync_audio_power(e740_audio_power);
  47. return 0;
  48. }
  49. static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
  50. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  51. SND_SOC_DAPM_SPK("Speaker", NULL),
  52. SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
  53. SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  54. e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
  55. SND_SOC_DAPM_POST_PMD),
  56. SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  57. e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
  58. SND_SOC_DAPM_POST_PMD),
  59. };
  60. static const struct snd_soc_dapm_route audio_map[] = {
  61. {"Output Amp", NULL, "LOUT"},
  62. {"Output Amp", NULL, "ROUT"},
  63. {"Output Amp", NULL, "MONOOUT"},
  64. {"Speaker", NULL, "Output Amp"},
  65. {"Headphone Jack", NULL, "Output Amp"},
  66. {"MIC1", NULL, "Mic Amp"},
  67. {"Mic Amp", NULL, "Mic (Internal)"},
  68. };
  69. static struct snd_soc_dai_link e740_dai[] = {
  70. {
  71. .name = "AC97",
  72. .stream_name = "AC97 HiFi",
  73. .cpu_dai_name = "pxa2xx-ac97",
  74. .codec_dai_name = "wm9705-hifi",
  75. .platform_name = "pxa-pcm-audio",
  76. .codec_name = "wm9705-codec",
  77. },
  78. {
  79. .name = "AC97 Aux",
  80. .stream_name = "AC97 Aux",
  81. .cpu_dai_name = "pxa2xx-ac97-aux",
  82. .codec_dai_name = "wm9705-aux",
  83. .platform_name = "pxa-pcm-audio",
  84. .codec_name = "wm9705-codec",
  85. },
  86. };
  87. static struct snd_soc_card e740 = {
  88. .name = "Toshiba e740",
  89. .owner = THIS_MODULE,
  90. .dai_link = e740_dai,
  91. .num_links = ARRAY_SIZE(e740_dai),
  92. .dapm_widgets = e740_dapm_widgets,
  93. .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets),
  94. .dapm_routes = audio_map,
  95. .num_dapm_routes = ARRAY_SIZE(audio_map),
  96. .fully_routed = true,
  97. };
  98. static struct gpio e740_audio_gpios[] = {
  99. { GPIO_E740_MIC_ON, GPIOF_OUT_INIT_LOW, "Mic amp" },
  100. { GPIO_E740_AMP_ON, GPIOF_OUT_INIT_LOW, "Output amp" },
  101. { GPIO_E740_WM9705_nAVDD2, GPIOF_OUT_INIT_HIGH, "Audio power" },
  102. };
  103. static int e740_probe(struct platform_device *pdev)
  104. {
  105. struct snd_soc_card *card = &e740;
  106. int ret;
  107. ret = gpio_request_array(e740_audio_gpios,
  108. ARRAY_SIZE(e740_audio_gpios));
  109. if (ret)
  110. return ret;
  111. card->dev = &pdev->dev;
  112. ret = devm_snd_soc_register_card(&pdev->dev, card);
  113. if (ret) {
  114. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  115. ret);
  116. gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
  117. }
  118. return ret;
  119. }
  120. static int e740_remove(struct platform_device *pdev)
  121. {
  122. gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios));
  123. return 0;
  124. }
  125. static struct platform_driver e740_driver = {
  126. .driver = {
  127. .name = "e740-audio",
  128. .pm = &snd_soc_pm_ops,
  129. },
  130. .probe = e740_probe,
  131. .remove = e740_remove,
  132. };
  133. module_platform_driver(e740_driver);
  134. /* Module information */
  135. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  136. MODULE_DESCRIPTION("ALSA SoC driver for e740");
  137. MODULE_LICENSE("GPL v2");
  138. MODULE_ALIAS("platform:e740-audio");