palm27x.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 <mach/palmasoc.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. /* add palm27x specific widgets */
  69. err = snd_soc_dapm_new_controls(dapm, palm27x_dapm_widgets,
  70. ARRAY_SIZE(palm27x_dapm_widgets));
  71. if (err)
  72. return err;
  73. /* set up palm27x specific audio path audio_map */
  74. err = snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  75. if (err)
  76. return err;
  77. /* connected pins */
  78. if (machine_is_palmld())
  79. snd_soc_dapm_enable_pin(dapm, "MIC1");
  80. snd_soc_dapm_enable_pin(dapm, "HPOUTL");
  81. snd_soc_dapm_enable_pin(dapm, "HPOUTR");
  82. snd_soc_dapm_enable_pin(dapm, "LOUT2");
  83. snd_soc_dapm_enable_pin(dapm, "ROUT2");
  84. /* not connected pins */
  85. snd_soc_dapm_nc_pin(dapm, "OUT3");
  86. snd_soc_dapm_nc_pin(dapm, "MONOOUT");
  87. snd_soc_dapm_nc_pin(dapm, "LINEINL");
  88. snd_soc_dapm_nc_pin(dapm, "LINEINR");
  89. snd_soc_dapm_nc_pin(dapm, "PCBEEP");
  90. snd_soc_dapm_nc_pin(dapm, "PHONE");
  91. snd_soc_dapm_nc_pin(dapm, "MIC2");
  92. /* Jack detection API stuff */
  93. err = snd_soc_jack_new(codec, "Headphone Jack",
  94. SND_JACK_HEADPHONE, &hs_jack);
  95. if (err)
  96. return err;
  97. err = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  98. hs_jack_pins);
  99. if (err)
  100. return err;
  101. err = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  102. hs_jack_gpios);
  103. return err;
  104. }
  105. static struct snd_soc_dai_link palm27x_dai[] = {
  106. {
  107. .name = "AC97 HiFi",
  108. .stream_name = "AC97 HiFi",
  109. .cpu_dai_name = "pxa2xx-ac97",
  110. .codec_dai_name = "wm9712-hifi",
  111. .codec_name = "wm9712-codec",
  112. .platform_name = "pxa-pcm-audio",
  113. .init = palm27x_ac97_init,
  114. },
  115. {
  116. .name = "AC97 Aux",
  117. .stream_name = "AC97 Aux",
  118. .cpu_dai_name = "pxa2xx-ac97-aux",
  119. .codec_dai_name = "wm9712-aux",
  120. .codec_name = "wm9712-codec",
  121. .platform_name = "pxa-pcm-audio",
  122. },
  123. };
  124. static struct snd_soc_card palm27x_asoc = {
  125. .name = "Palm/PXA27x",
  126. .dai_link = palm27x_dai,
  127. .num_links = ARRAY_SIZE(palm27x_dai),
  128. };
  129. static struct platform_device *palm27x_snd_device;
  130. static int palm27x_asoc_probe(struct platform_device *pdev)
  131. {
  132. int ret;
  133. if (!(machine_is_palmtx() || machine_is_palmt5() ||
  134. machine_is_palmld() || machine_is_palmte2()))
  135. return -ENODEV;
  136. if (!pdev->dev.platform_data) {
  137. dev_err(&pdev->dev, "please supply platform_data\n");
  138. return -ENODEV;
  139. }
  140. hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *)
  141. (pdev->dev.platform_data))->jack_gpio;
  142. palm27x_snd_device = platform_device_alloc("soc-audio", -1);
  143. if (!palm27x_snd_device)
  144. return -ENOMEM;
  145. platform_set_drvdata(palm27x_snd_device, &palm27x_asoc);
  146. ret = platform_device_add(palm27x_snd_device);
  147. if (ret != 0)
  148. goto put_device;
  149. return 0;
  150. put_device:
  151. platform_device_put(palm27x_snd_device);
  152. return ret;
  153. }
  154. static int __devexit palm27x_asoc_remove(struct platform_device *pdev)
  155. {
  156. platform_device_unregister(palm27x_snd_device);
  157. return 0;
  158. }
  159. static struct platform_driver palm27x_wm9712_driver = {
  160. .probe = palm27x_asoc_probe,
  161. .remove = __devexit_p(palm27x_asoc_remove),
  162. .driver = {
  163. .name = "palm27x-asoc",
  164. .owner = THIS_MODULE,
  165. },
  166. };
  167. static int __init palm27x_asoc_init(void)
  168. {
  169. return platform_driver_register(&palm27x_wm9712_driver);
  170. }
  171. static void __exit palm27x_asoc_exit(void)
  172. {
  173. platform_driver_unregister(&palm27x_wm9712_driver);
  174. }
  175. module_init(palm27x_asoc_init);
  176. module_exit(palm27x_asoc_exit);
  177. /* Module information */
  178. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  179. MODULE_DESCRIPTION("ALSA SoC Palm T|X, T5 and LifeDrive");
  180. MODULE_LICENSE("GPL");