palm27x.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * linux/sound/soc/pxa/palm27x.c
  3. *
  4. * SoC Audio driver for Palm T|X, T5 and LifeDrive
  5. *
  6. * based on tosa.c
  7. *
  8. * Copyright (C) 2008 Marek Vasut <marek.vasut@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/moduleparam.h>
  17. #include <linux/device.h>
  18. #include <linux/gpio.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/soc.h>
  22. #include <sound/jack.h>
  23. #include <asm/mach-types.h>
  24. #include <mach/audio.h>
  25. #include <linux/platform_data/asoc-palm27x.h>
  26. #include "../codecs/wm9712.h"
  27. #include "pxa2xx-ac97.h"
  28. static struct snd_soc_jack hs_jack;
  29. /* Headphones jack detection DAPM pins */
  30. static struct snd_soc_jack_pin hs_jack_pins[] = {
  31. {
  32. .pin = "Headphone Jack",
  33. .mask = SND_JACK_HEADPHONE,
  34. },
  35. };
  36. /* Headphones jack detection gpios */
  37. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  38. [0] = {
  39. /* gpio is set on per-platform basis */
  40. .name = "hp-gpio",
  41. .report = SND_JACK_HEADPHONE,
  42. .debounce_time = 200,
  43. },
  44. };
  45. /* Palm27x machine dapm widgets */
  46. static const struct snd_soc_dapm_widget palm27x_dapm_widgets[] = {
  47. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  48. SND_SOC_DAPM_SPK("Ext. Speaker", NULL),
  49. SND_SOC_DAPM_MIC("Ext. Microphone", NULL),
  50. };
  51. /* PalmTX audio map */
  52. static const struct snd_soc_dapm_route audio_map[] = {
  53. /* headphone connected to HPOUTL, HPOUTR */
  54. {"Headphone Jack", NULL, "HPOUTL"},
  55. {"Headphone Jack", NULL, "HPOUTR"},
  56. /* ext speaker connected to ROUT2, LOUT2 */
  57. {"Ext. Speaker", NULL, "LOUT2"},
  58. {"Ext. Speaker", NULL, "ROUT2"},
  59. /* mic connected to MIC1 */
  60. {"MIC1", NULL, "Ext. Microphone"},
  61. };
  62. static struct snd_soc_card palm27x_asoc;
  63. static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
  64. {
  65. int err;
  66. /* Jack detection API stuff */
  67. err = snd_soc_card_jack_new(rtd->card, "Headphone Jack",
  68. SND_JACK_HEADPHONE, &hs_jack, hs_jack_pins,
  69. ARRAY_SIZE(hs_jack_pins));
  70. if (err)
  71. return err;
  72. err = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  73. hs_jack_gpios);
  74. return err;
  75. }
  76. static struct snd_soc_dai_link palm27x_dai[] = {
  77. {
  78. .name = "AC97 HiFi",
  79. .stream_name = "AC97 HiFi",
  80. .cpu_dai_name = "pxa2xx-ac97",
  81. .codec_dai_name = "wm9712-hifi",
  82. .codec_name = "wm9712-codec",
  83. .platform_name = "pxa-pcm-audio",
  84. .init = palm27x_ac97_init,
  85. },
  86. {
  87. .name = "AC97 Aux",
  88. .stream_name = "AC97 Aux",
  89. .cpu_dai_name = "pxa2xx-ac97-aux",
  90. .codec_dai_name = "wm9712-aux",
  91. .codec_name = "wm9712-codec",
  92. .platform_name = "pxa-pcm-audio",
  93. },
  94. };
  95. static struct snd_soc_card palm27x_asoc = {
  96. .name = "Palm/PXA27x",
  97. .owner = THIS_MODULE,
  98. .dai_link = palm27x_dai,
  99. .num_links = ARRAY_SIZE(palm27x_dai),
  100. .dapm_widgets = palm27x_dapm_widgets,
  101. .num_dapm_widgets = ARRAY_SIZE(palm27x_dapm_widgets),
  102. .dapm_routes = audio_map,
  103. .num_dapm_routes = ARRAY_SIZE(audio_map),
  104. .fully_routed = true,
  105. };
  106. static int palm27x_asoc_probe(struct platform_device *pdev)
  107. {
  108. int ret;
  109. if (!(machine_is_palmtx() || machine_is_palmt5() ||
  110. machine_is_palmld() || machine_is_palmte2()))
  111. return -ENODEV;
  112. if (!pdev->dev.platform_data) {
  113. dev_err(&pdev->dev, "please supply platform_data\n");
  114. return -ENODEV;
  115. }
  116. hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *)
  117. (pdev->dev.platform_data))->jack_gpio;
  118. palm27x_asoc.dev = &pdev->dev;
  119. ret = devm_snd_soc_register_card(&pdev->dev, &palm27x_asoc);
  120. if (ret)
  121. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  122. ret);
  123. return ret;
  124. }
  125. static struct platform_driver palm27x_wm9712_driver = {
  126. .probe = palm27x_asoc_probe,
  127. .driver = {
  128. .name = "palm27x-asoc",
  129. .pm = &snd_soc_pm_ops,
  130. },
  131. };
  132. module_platform_driver(palm27x_wm9712_driver);
  133. /* Module information */
  134. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  135. MODULE_DESCRIPTION("ALSA SoC Palm T|X, T5 and LifeDrive");
  136. MODULE_LICENSE("GPL");
  137. MODULE_ALIAS("platform:palm27x-asoc");