palm27x.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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/soc-dapm.h>
  23. #include <sound/jack.h>
  24. #include <asm/mach-types.h>
  25. #include <mach/audio.h>
  26. #include <mach/palmasoc.h>
  27. #include "../codecs/wm9712.h"
  28. #include "pxa2xx-ac97.h"
  29. static struct snd_soc_jack hs_jack;
  30. /* Headphones jack detection DAPM pins */
  31. static struct snd_soc_jack_pin hs_jack_pins[] = {
  32. {
  33. .pin = "Headphone Jack",
  34. .mask = SND_JACK_HEADPHONE,
  35. },
  36. };
  37. /* Headphones jack detection gpios */
  38. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  39. [0] = {
  40. /* gpio is set on per-platform basis */
  41. .name = "hp-gpio",
  42. .report = SND_JACK_HEADPHONE,
  43. .debounce_time = 200,
  44. },
  45. };
  46. /* Palm27x machine dapm widgets */
  47. static const struct snd_soc_dapm_widget palm27x_dapm_widgets[] = {
  48. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  49. SND_SOC_DAPM_SPK("Ext. Speaker", NULL),
  50. SND_SOC_DAPM_MIC("Ext. Microphone", NULL),
  51. };
  52. /* PalmTX audio map */
  53. static const struct snd_soc_dapm_route audio_map[] = {
  54. /* headphone connected to HPOUTL, HPOUTR */
  55. {"Headphone Jack", NULL, "HPOUTL"},
  56. {"Headphone Jack", NULL, "HPOUTR"},
  57. /* ext speaker connected to ROUT2, LOUT2 */
  58. {"Ext. Speaker", NULL, "LOUT2"},
  59. {"Ext. Speaker", NULL, "ROUT2"},
  60. /* mic connected to MIC1 */
  61. {"Ext. Microphone", NULL, "MIC1"},
  62. };
  63. static struct snd_soc_card palm27x_asoc;
  64. static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
  65. {
  66. struct snd_soc_codec *codec = rtd->codec;
  67. struct snd_soc_dapm_context *dapm = &codec->dapm;
  68. int err;
  69. /* add palm27x specific widgets */
  70. err = snd_soc_dapm_new_controls(dapm, palm27x_dapm_widgets,
  71. ARRAY_SIZE(palm27x_dapm_widgets));
  72. if (err)
  73. return err;
  74. /* set up palm27x specific audio path audio_map */
  75. err = snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  76. if (err)
  77. return err;
  78. /* connected pins */
  79. if (machine_is_palmld())
  80. snd_soc_dapm_enable_pin(dapm, "MIC1");
  81. snd_soc_dapm_enable_pin(dapm, "HPOUTL");
  82. snd_soc_dapm_enable_pin(dapm, "HPOUTR");
  83. snd_soc_dapm_enable_pin(dapm, "LOUT2");
  84. snd_soc_dapm_enable_pin(dapm, "ROUT2");
  85. /* not connected pins */
  86. snd_soc_dapm_nc_pin(dapm, "OUT3");
  87. snd_soc_dapm_nc_pin(dapm, "MONOOUT");
  88. snd_soc_dapm_nc_pin(dapm, "LINEINL");
  89. snd_soc_dapm_nc_pin(dapm, "LINEINR");
  90. snd_soc_dapm_nc_pin(dapm, "PCBEEP");
  91. snd_soc_dapm_nc_pin(dapm, "PHONE");
  92. snd_soc_dapm_nc_pin(dapm, "MIC2");
  93. err = snd_soc_dapm_sync(dapm);
  94. if (err)
  95. return err;
  96. /* Jack detection API stuff */
  97. err = snd_soc_jack_new(codec, "Headphone Jack",
  98. SND_JACK_HEADPHONE, &hs_jack);
  99. if (err)
  100. return err;
  101. err = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  102. hs_jack_pins);
  103. if (err)
  104. return err;
  105. err = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  106. hs_jack_gpios);
  107. return err;
  108. }
  109. static struct snd_soc_dai_link palm27x_dai[] = {
  110. {
  111. .name = "AC97 HiFi",
  112. .stream_name = "AC97 HiFi",
  113. .cpu_dai_name = "pxa-ac97.0",
  114. .codec_dai_name = "wm9712-hifi",
  115. .codec_name = "wm9712-codec",
  116. .platform_name = "pxa-pcm-audio",
  117. .init = palm27x_ac97_init,
  118. },
  119. {
  120. .name = "AC97 Aux",
  121. .stream_name = "AC97 Aux",
  122. .cpu_dai_name = "pxa-ac97.1",
  123. .codec_dai_name = "wm9712-aux",
  124. .codec_name = "wm9712-codec",
  125. .platform_name = "pxa-pcm-audio",
  126. },
  127. };
  128. static struct snd_soc_card palm27x_asoc = {
  129. .name = "Palm/PXA27x",
  130. .dai_link = palm27x_dai,
  131. .num_links = ARRAY_SIZE(palm27x_dai),
  132. };
  133. static struct platform_device *palm27x_snd_device;
  134. static int palm27x_asoc_probe(struct platform_device *pdev)
  135. {
  136. int ret;
  137. if (!(machine_is_palmtx() || machine_is_palmt5() ||
  138. machine_is_palmld() || machine_is_palmte2()))
  139. return -ENODEV;
  140. if (!pdev->dev.platform_data) {
  141. dev_err(&pdev->dev, "please supply platform_data\n");
  142. return -ENODEV;
  143. }
  144. hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *)
  145. (pdev->dev.platform_data))->jack_gpio;
  146. palm27x_snd_device = platform_device_alloc("soc-audio", -1);
  147. if (!palm27x_snd_device)
  148. return -ENOMEM;
  149. platform_set_drvdata(palm27x_snd_device, &palm27x_asoc);
  150. ret = platform_device_add(palm27x_snd_device);
  151. if (ret != 0)
  152. goto put_device;
  153. return 0;
  154. put_device:
  155. platform_device_put(palm27x_snd_device);
  156. return ret;
  157. }
  158. static int __devexit palm27x_asoc_remove(struct platform_device *pdev)
  159. {
  160. platform_device_unregister(palm27x_snd_device);
  161. return 0;
  162. }
  163. static struct platform_driver palm27x_wm9712_driver = {
  164. .probe = palm27x_asoc_probe,
  165. .remove = __devexit_p(palm27x_asoc_remove),
  166. .driver = {
  167. .name = "palm27x-asoc",
  168. .owner = THIS_MODULE,
  169. },
  170. };
  171. static int __init palm27x_asoc_init(void)
  172. {
  173. return platform_driver_register(&palm27x_wm9712_driver);
  174. }
  175. static void __exit palm27x_asoc_exit(void)
  176. {
  177. platform_driver_unregister(&palm27x_wm9712_driver);
  178. }
  179. module_init(palm27x_asoc_init);
  180. module_exit(palm27x_asoc_exit);
  181. /* Module information */
  182. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  183. MODULE_DESCRIPTION("ALSA SoC Palm T|X, T5 and LifeDrive");
  184. MODULE_LICENSE("GPL");