palm27x.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 "pxa2xx-ac97.h"
  27. static struct snd_soc_jack hs_jack;
  28. /* Headphones jack detection DAPM pins */
  29. static struct snd_soc_jack_pin hs_jack_pins[] = {
  30. {
  31. .pin = "Headphone Jack",
  32. .mask = SND_JACK_HEADPHONE,
  33. },
  34. };
  35. /* Headphones jack detection gpios */
  36. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  37. [0] = {
  38. /* gpio is set on per-platform basis */
  39. .name = "hp-gpio",
  40. .report = SND_JACK_HEADPHONE,
  41. .debounce_time = 200,
  42. },
  43. };
  44. /* Palm27x machine dapm widgets */
  45. static const struct snd_soc_dapm_widget palm27x_dapm_widgets[] = {
  46. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  47. SND_SOC_DAPM_SPK("Ext. Speaker", NULL),
  48. SND_SOC_DAPM_MIC("Ext. Microphone", NULL),
  49. };
  50. /* PalmTX audio map */
  51. static const struct snd_soc_dapm_route audio_map[] = {
  52. /* headphone connected to HPOUTL, HPOUTR */
  53. {"Headphone Jack", NULL, "HPOUTL"},
  54. {"Headphone Jack", NULL, "HPOUTR"},
  55. /* ext speaker connected to ROUT2, LOUT2 */
  56. {"Ext. Speaker", NULL, "LOUT2"},
  57. {"Ext. Speaker", NULL, "ROUT2"},
  58. /* mic connected to MIC1 */
  59. {"MIC1", NULL, "Ext. Microphone"},
  60. };
  61. static struct snd_soc_card palm27x_asoc;
  62. static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
  63. {
  64. int err;
  65. /* Jack detection API stuff */
  66. err = snd_soc_card_jack_new(rtd->card, "Headphone Jack",
  67. SND_JACK_HEADPHONE, &hs_jack, hs_jack_pins,
  68. ARRAY_SIZE(hs_jack_pins));
  69. if (err)
  70. return err;
  71. err = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  72. hs_jack_gpios);
  73. return err;
  74. }
  75. static struct snd_soc_dai_link palm27x_dai[] = {
  76. {
  77. .name = "AC97 HiFi",
  78. .stream_name = "AC97 HiFi",
  79. .cpu_dai_name = "pxa2xx-ac97",
  80. .codec_dai_name = "wm9712-hifi",
  81. .codec_name = "wm9712-codec",
  82. .platform_name = "pxa-pcm-audio",
  83. .init = palm27x_ac97_init,
  84. },
  85. {
  86. .name = "AC97 Aux",
  87. .stream_name = "AC97 Aux",
  88. .cpu_dai_name = "pxa2xx-ac97-aux",
  89. .codec_dai_name = "wm9712-aux",
  90. .codec_name = "wm9712-codec",
  91. .platform_name = "pxa-pcm-audio",
  92. },
  93. };
  94. static struct snd_soc_card palm27x_asoc = {
  95. .name = "Palm/PXA27x",
  96. .owner = THIS_MODULE,
  97. .dai_link = palm27x_dai,
  98. .num_links = ARRAY_SIZE(palm27x_dai),
  99. .dapm_widgets = palm27x_dapm_widgets,
  100. .num_dapm_widgets = ARRAY_SIZE(palm27x_dapm_widgets),
  101. .dapm_routes = audio_map,
  102. .num_dapm_routes = ARRAY_SIZE(audio_map),
  103. .fully_routed = true,
  104. };
  105. static int palm27x_asoc_probe(struct platform_device *pdev)
  106. {
  107. int ret;
  108. if (!(machine_is_palmtx() || machine_is_palmt5() ||
  109. machine_is_palmld() || machine_is_palmte2()))
  110. return -ENODEV;
  111. if (!pdev->dev.platform_data) {
  112. dev_err(&pdev->dev, "please supply platform_data\n");
  113. return -ENODEV;
  114. }
  115. hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *)
  116. (pdev->dev.platform_data))->jack_gpio;
  117. palm27x_asoc.dev = &pdev->dev;
  118. ret = devm_snd_soc_register_card(&pdev->dev, &palm27x_asoc);
  119. if (ret)
  120. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  121. ret);
  122. return ret;
  123. }
  124. static struct platform_driver palm27x_wm9712_driver = {
  125. .probe = palm27x_asoc_probe,
  126. .driver = {
  127. .name = "palm27x-asoc",
  128. .pm = &snd_soc_pm_ops,
  129. },
  130. };
  131. module_platform_driver(palm27x_wm9712_driver);
  132. /* Module information */
  133. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  134. MODULE_DESCRIPTION("ALSA SoC Palm T|X, T5 and LifeDrive");
  135. MODULE_LICENSE("GPL");
  136. MODULE_ALIAS("platform:palm27x-asoc");