palm27x.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. {"Ext. Microphone", NULL, "MIC1"},
  61. };
  62. static struct snd_soc_card palm27x_asoc;
  63. static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
  64. {
  65. struct snd_soc_codec *codec = rtd->codec;
  66. struct snd_soc_dapm_context *dapm = &codec->dapm;
  67. int err;
  68. /* connected pins */
  69. if (machine_is_palmld())
  70. snd_soc_dapm_enable_pin(dapm, "MIC1");
  71. snd_soc_dapm_enable_pin(dapm, "HPOUTL");
  72. snd_soc_dapm_enable_pin(dapm, "HPOUTR");
  73. snd_soc_dapm_enable_pin(dapm, "LOUT2");
  74. snd_soc_dapm_enable_pin(dapm, "ROUT2");
  75. /* not connected pins */
  76. snd_soc_dapm_nc_pin(dapm, "OUT3");
  77. snd_soc_dapm_nc_pin(dapm, "MONOOUT");
  78. snd_soc_dapm_nc_pin(dapm, "LINEINL");
  79. snd_soc_dapm_nc_pin(dapm, "LINEINR");
  80. snd_soc_dapm_nc_pin(dapm, "PCBEEP");
  81. snd_soc_dapm_nc_pin(dapm, "PHONE");
  82. snd_soc_dapm_nc_pin(dapm, "MIC2");
  83. /* Jack detection API stuff */
  84. err = snd_soc_jack_new(codec, "Headphone Jack",
  85. SND_JACK_HEADPHONE, &hs_jack);
  86. if (err)
  87. return err;
  88. err = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  89. hs_jack_pins);
  90. if (err)
  91. return err;
  92. err = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  93. hs_jack_gpios);
  94. return err;
  95. }
  96. static struct snd_soc_dai_link palm27x_dai[] = {
  97. {
  98. .name = "AC97 HiFi",
  99. .stream_name = "AC97 HiFi",
  100. .cpu_dai_name = "pxa2xx-ac97",
  101. .codec_dai_name = "wm9712-hifi",
  102. .codec_name = "wm9712-codec",
  103. .platform_name = "pxa-pcm-audio",
  104. .init = palm27x_ac97_init,
  105. },
  106. {
  107. .name = "AC97 Aux",
  108. .stream_name = "AC97 Aux",
  109. .cpu_dai_name = "pxa2xx-ac97-aux",
  110. .codec_dai_name = "wm9712-aux",
  111. .codec_name = "wm9712-codec",
  112. .platform_name = "pxa-pcm-audio",
  113. },
  114. };
  115. static struct snd_soc_card palm27x_asoc = {
  116. .name = "Palm/PXA27x",
  117. .owner = THIS_MODULE,
  118. .dai_link = palm27x_dai,
  119. .num_links = ARRAY_SIZE(palm27x_dai),
  120. .dapm_widgets = palm27x_dapm_widgets,
  121. .num_dapm_widgets = ARRAY_SIZE(palm27x_dapm_widgets),
  122. .dapm_routes = audio_map,
  123. .num_dapm_routes = ARRAY_SIZE(audio_map)
  124. };
  125. static int palm27x_asoc_probe(struct platform_device *pdev)
  126. {
  127. int ret;
  128. if (!(machine_is_palmtx() || machine_is_palmt5() ||
  129. machine_is_palmld() || machine_is_palmte2()))
  130. return -ENODEV;
  131. if (!pdev->dev.platform_data) {
  132. dev_err(&pdev->dev, "please supply platform_data\n");
  133. return -ENODEV;
  134. }
  135. hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *)
  136. (pdev->dev.platform_data))->jack_gpio;
  137. palm27x_asoc.dev = &pdev->dev;
  138. ret = snd_soc_register_card(&palm27x_asoc);
  139. if (ret)
  140. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  141. ret);
  142. return ret;
  143. }
  144. static int palm27x_asoc_remove(struct platform_device *pdev)
  145. {
  146. snd_soc_unregister_card(&palm27x_asoc);
  147. return 0;
  148. }
  149. static struct platform_driver palm27x_wm9712_driver = {
  150. .probe = palm27x_asoc_probe,
  151. .remove = palm27x_asoc_remove,
  152. .driver = {
  153. .name = "palm27x-asoc",
  154. .owner = THIS_MODULE,
  155. },
  156. };
  157. module_platform_driver(palm27x_wm9712_driver);
  158. /* Module information */
  159. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  160. MODULE_DESCRIPTION("ALSA SoC Palm T|X, T5 and LifeDrive");
  161. MODULE_LICENSE("GPL");