palm27x.c 3.9 KB

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