palm27x.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. err = snd_soc_dapm_sync(dapm);
  93. if (err)
  94. return err;
  95. /* Jack detection API stuff */
  96. err = snd_soc_jack_new(codec, "Headphone Jack",
  97. SND_JACK_HEADPHONE, &hs_jack);
  98. if (err)
  99. return err;
  100. err = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  101. hs_jack_pins);
  102. if (err)
  103. return err;
  104. err = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  105. hs_jack_gpios);
  106. return err;
  107. }
  108. static struct snd_soc_dai_link palm27x_dai[] = {
  109. {
  110. .name = "AC97 HiFi",
  111. .stream_name = "AC97 HiFi",
  112. .cpu_dai_name = "pxa2xx-ac97",
  113. .codec_dai_name = "wm9712-hifi",
  114. .codec_name = "wm9712-codec",
  115. .platform_name = "pxa-pcm-audio",
  116. .init = palm27x_ac97_init,
  117. },
  118. {
  119. .name = "AC97 Aux",
  120. .stream_name = "AC97 Aux",
  121. .cpu_dai_name = "pxa2xx-ac97-aux",
  122. .codec_dai_name = "wm9712-aux",
  123. .codec_name = "wm9712-codec",
  124. .platform_name = "pxa-pcm-audio",
  125. },
  126. };
  127. static struct snd_soc_card palm27x_asoc = {
  128. .name = "Palm/PXA27x",
  129. .dai_link = palm27x_dai,
  130. .num_links = ARRAY_SIZE(palm27x_dai),
  131. };
  132. static struct platform_device *palm27x_snd_device;
  133. static int palm27x_asoc_probe(struct platform_device *pdev)
  134. {
  135. int ret;
  136. if (!(machine_is_palmtx() || machine_is_palmt5() ||
  137. machine_is_palmld() || machine_is_palmte2()))
  138. return -ENODEV;
  139. if (!pdev->dev.platform_data) {
  140. dev_err(&pdev->dev, "please supply platform_data\n");
  141. return -ENODEV;
  142. }
  143. hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *)
  144. (pdev->dev.platform_data))->jack_gpio;
  145. palm27x_snd_device = platform_device_alloc("soc-audio", -1);
  146. if (!palm27x_snd_device)
  147. return -ENOMEM;
  148. platform_set_drvdata(palm27x_snd_device, &palm27x_asoc);
  149. ret = platform_device_add(palm27x_snd_device);
  150. if (ret != 0)
  151. goto put_device;
  152. return 0;
  153. put_device:
  154. platform_device_put(palm27x_snd_device);
  155. return ret;
  156. }
  157. static int __devexit palm27x_asoc_remove(struct platform_device *pdev)
  158. {
  159. platform_device_unregister(palm27x_snd_device);
  160. return 0;
  161. }
  162. static struct platform_driver palm27x_wm9712_driver = {
  163. .probe = palm27x_asoc_probe,
  164. .remove = __devexit_p(palm27x_asoc_remove),
  165. .driver = {
  166. .name = "palm27x-asoc",
  167. .owner = THIS_MODULE,
  168. },
  169. };
  170. static int __init palm27x_asoc_init(void)
  171. {
  172. return platform_driver_register(&palm27x_wm9712_driver);
  173. }
  174. static void __exit palm27x_asoc_exit(void)
  175. {
  176. platform_driver_unregister(&palm27x_wm9712_driver);
  177. }
  178. module_init(palm27x_asoc_init);
  179. module_exit(palm27x_asoc_exit);
  180. /* Module information */
  181. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  182. MODULE_DESCRIPTION("ALSA SoC Palm T|X, T5 and LifeDrive");
  183. MODULE_LICENSE("GPL");