e750_wm9705.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 <mach/audio.h>
  18. #include <mach/eseries-gpio.h>
  19. #include <asm/mach-types.h>
  20. static int e750_spk_amp_event(struct snd_soc_dapm_widget *w,
  21. struct snd_kcontrol *kcontrol, int event)
  22. {
  23. if (event & SND_SOC_DAPM_PRE_PMU)
  24. gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0);
  25. else if (event & SND_SOC_DAPM_POST_PMD)
  26. gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1);
  27. return 0;
  28. }
  29. static int e750_hp_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. gpio_set_value(GPIO_E750_HP_AMP_OFF, 0);
  34. else if (event & SND_SOC_DAPM_POST_PMD)
  35. gpio_set_value(GPIO_E750_HP_AMP_OFF, 1);
  36. return 0;
  37. }
  38. static const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
  39. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  40. SND_SOC_DAPM_SPK("Speaker", NULL),
  41. SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
  42. SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  43. e750_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
  44. SND_SOC_DAPM_POST_PMD),
  45. SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
  46. e750_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
  47. SND_SOC_DAPM_POST_PMD),
  48. };
  49. static const struct snd_soc_dapm_route audio_map[] = {
  50. {"Headphone Amp", NULL, "HPOUTL"},
  51. {"Headphone Amp", NULL, "HPOUTR"},
  52. {"Headphone Jack", NULL, "Headphone Amp"},
  53. {"Speaker Amp", NULL, "MONOOUT"},
  54. {"Speaker", NULL, "Speaker Amp"},
  55. {"MIC1", NULL, "Mic (Internal)"},
  56. };
  57. static struct snd_soc_dai_link e750_dai[] = {
  58. {
  59. .name = "AC97",
  60. .stream_name = "AC97 HiFi",
  61. .cpu_dai_name = "pxa2xx-ac97",
  62. .codec_dai_name = "wm9705-hifi",
  63. .platform_name = "pxa-pcm-audio",
  64. .codec_name = "wm9705-codec",
  65. /* use ops to check startup state */
  66. },
  67. {
  68. .name = "AC97 Aux",
  69. .stream_name = "AC97 Aux",
  70. .cpu_dai_name = "pxa2xx-ac97-aux",
  71. .codec_dai_name = "wm9705-aux",
  72. .platform_name = "pxa-pcm-audio",
  73. .codec_name = "wm9705-codec",
  74. },
  75. };
  76. static struct snd_soc_card e750 = {
  77. .name = "Toshiba e750",
  78. .owner = THIS_MODULE,
  79. .dai_link = e750_dai,
  80. .num_links = ARRAY_SIZE(e750_dai),
  81. .dapm_widgets = e750_dapm_widgets,
  82. .num_dapm_widgets = ARRAY_SIZE(e750_dapm_widgets),
  83. .dapm_routes = audio_map,
  84. .num_dapm_routes = ARRAY_SIZE(audio_map),
  85. .fully_routed = true,
  86. };
  87. static struct gpio e750_audio_gpios[] = {
  88. { GPIO_E750_HP_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Headphone amp" },
  89. { GPIO_E750_SPK_AMP_OFF, GPIOF_OUT_INIT_HIGH, "Speaker amp" },
  90. };
  91. static int e750_probe(struct platform_device *pdev)
  92. {
  93. struct snd_soc_card *card = &e750;
  94. int ret;
  95. ret = gpio_request_array(e750_audio_gpios,
  96. ARRAY_SIZE(e750_audio_gpios));
  97. if (ret)
  98. return ret;
  99. card->dev = &pdev->dev;
  100. ret = devm_snd_soc_register_card(&pdev->dev, card);
  101. if (ret) {
  102. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  103. ret);
  104. gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios));
  105. }
  106. return ret;
  107. }
  108. static int e750_remove(struct platform_device *pdev)
  109. {
  110. gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios));
  111. return 0;
  112. }
  113. static struct platform_driver e750_driver = {
  114. .driver = {
  115. .name = "e750-audio",
  116. .pm = &snd_soc_pm_ops,
  117. },
  118. .probe = e750_probe,
  119. .remove = e750_remove,
  120. };
  121. module_platform_driver(e750_driver);
  122. /* Module information */
  123. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  124. MODULE_DESCRIPTION("ALSA SoC driver for e750");
  125. MODULE_LICENSE("GPL v2");
  126. MODULE_ALIAS("platform:e750-audio");