palm27x.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. .owner = THIS_MODULE,
  127. .dai_link = palm27x_dai,
  128. .num_links = ARRAY_SIZE(palm27x_dai),
  129. };
  130. static struct platform_device *palm27x_snd_device;
  131. static int palm27x_asoc_probe(struct platform_device *pdev)
  132. {
  133. int ret;
  134. if (!(machine_is_palmtx() || machine_is_palmt5() ||
  135. machine_is_palmld() || machine_is_palmte2()))
  136. return -ENODEV;
  137. if (!pdev->dev.platform_data) {
  138. dev_err(&pdev->dev, "please supply platform_data\n");
  139. return -ENODEV;
  140. }
  141. hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *)
  142. (pdev->dev.platform_data))->jack_gpio;
  143. palm27x_snd_device = platform_device_alloc("soc-audio", -1);
  144. if (!palm27x_snd_device)
  145. return -ENOMEM;
  146. platform_set_drvdata(palm27x_snd_device, &palm27x_asoc);
  147. ret = platform_device_add(palm27x_snd_device);
  148. if (ret != 0)
  149. goto put_device;
  150. return 0;
  151. put_device:
  152. platform_device_put(palm27x_snd_device);
  153. return ret;
  154. }
  155. static int __devexit palm27x_asoc_remove(struct platform_device *pdev)
  156. {
  157. platform_device_unregister(palm27x_snd_device);
  158. return 0;
  159. }
  160. static struct platform_driver palm27x_wm9712_driver = {
  161. .probe = palm27x_asoc_probe,
  162. .remove = __devexit_p(palm27x_asoc_remove),
  163. .driver = {
  164. .name = "palm27x-asoc",
  165. .owner = THIS_MODULE,
  166. },
  167. };
  168. module_platform_driver(palm27x_wm9712_driver);
  169. /* Module information */
  170. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  171. MODULE_DESCRIPTION("ALSA SoC Palm T|X, T5 and LifeDrive");
  172. MODULE_LICENSE("GPL");