palm27x.c 3.9 KB

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