z2.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * linux/sound/soc/pxa/z2.c
  3. *
  4. * SoC Audio driver for Aeronix Zipit Z2
  5. *
  6. * Copyright (C) 2009 Ken McGuire <kenm@desertweyr.com>
  7. * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/timer.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/platform_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/hardware.h>
  25. #include <mach/audio.h>
  26. #include <mach/z2.h>
  27. #include "../codecs/wm8750.h"
  28. #include "pxa2xx-i2s.h"
  29. static struct snd_soc_card snd_soc_z2;
  30. static int z2_hw_params(struct snd_pcm_substream *substream,
  31. struct snd_pcm_hw_params *params)
  32. {
  33. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  34. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  35. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  36. unsigned int clk = 0;
  37. int ret = 0;
  38. switch (params_rate(params)) {
  39. case 8000:
  40. case 16000:
  41. case 48000:
  42. case 96000:
  43. clk = 12288000;
  44. break;
  45. case 11025:
  46. case 22050:
  47. case 44100:
  48. clk = 11289600;
  49. break;
  50. }
  51. /* set the codec system clock for DAC and ADC */
  52. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  53. SND_SOC_CLOCK_IN);
  54. if (ret < 0)
  55. return ret;
  56. /* set the I2S system clock as input (unused) */
  57. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
  58. SND_SOC_CLOCK_IN);
  59. if (ret < 0)
  60. return ret;
  61. return 0;
  62. }
  63. static struct snd_soc_jack hs_jack;
  64. /* Headset jack detection DAPM pins */
  65. static struct snd_soc_jack_pin hs_jack_pins[] = {
  66. {
  67. .pin = "Mic Jack",
  68. .mask = SND_JACK_MICROPHONE,
  69. },
  70. {
  71. .pin = "Headphone Jack",
  72. .mask = SND_JACK_HEADPHONE,
  73. },
  74. {
  75. .pin = "Ext Spk",
  76. .mask = SND_JACK_HEADPHONE,
  77. .invert = 1
  78. },
  79. };
  80. /* Headset jack detection gpios */
  81. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  82. {
  83. .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT,
  84. .name = "hsdet-gpio",
  85. .report = SND_JACK_HEADSET,
  86. .debounce_time = 200,
  87. .invert = 1,
  88. },
  89. };
  90. /* z2 machine dapm widgets */
  91. static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
  92. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  93. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  94. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  95. /* headset is a mic and mono headphone */
  96. SND_SOC_DAPM_HP("Headset Jack", NULL),
  97. };
  98. /* Z2 machine audio_map */
  99. static const struct snd_soc_dapm_route z2_audio_map[] = {
  100. /* headphone connected to LOUT1, ROUT1 */
  101. {"Headphone Jack", NULL, "LOUT1"},
  102. {"Headphone Jack", NULL, "ROUT1"},
  103. /* ext speaker connected to LOUT2, ROUT2 */
  104. {"Ext Spk", NULL , "ROUT2"},
  105. {"Ext Spk", NULL , "LOUT2"},
  106. /* mic is connected to R input 2 - with bias */
  107. {"RINPUT2", NULL, "Mic Bias"},
  108. {"Mic Bias", NULL, "Mic Jack"},
  109. };
  110. /*
  111. * Logic for a wm8750 as connected on a Z2 Device
  112. */
  113. static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
  114. {
  115. struct snd_soc_codec *codec = rtd->codec;
  116. struct snd_soc_dapm_context *dapm = &codec->dapm;
  117. int ret;
  118. /* NC codec pins */
  119. snd_soc_dapm_disable_pin(dapm, "LINPUT3");
  120. snd_soc_dapm_disable_pin(dapm, "RINPUT3");
  121. snd_soc_dapm_disable_pin(dapm, "OUT3");
  122. snd_soc_dapm_disable_pin(dapm, "MONO1");
  123. /* Jack detection API stuff */
  124. ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
  125. &hs_jack);
  126. if (ret)
  127. goto err;
  128. ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  129. hs_jack_pins);
  130. if (ret)
  131. goto err;
  132. ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  133. hs_jack_gpios);
  134. if (ret)
  135. goto err;
  136. return 0;
  137. err:
  138. return ret;
  139. }
  140. static struct snd_soc_ops z2_ops = {
  141. .hw_params = z2_hw_params,
  142. };
  143. /* z2 digital audio interface glue - connects codec <--> CPU */
  144. static struct snd_soc_dai_link z2_dai = {
  145. .name = "wm8750",
  146. .stream_name = "WM8750",
  147. .cpu_dai_name = "pxa2xx-i2s",
  148. .codec_dai_name = "wm8750-hifi",
  149. .platform_name = "pxa-pcm-audio",
  150. .codec_name = "wm8750.0-001b",
  151. .init = z2_wm8750_init,
  152. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  153. SND_SOC_DAIFMT_CBS_CFS,
  154. .ops = &z2_ops,
  155. };
  156. /* z2 audio machine driver */
  157. static struct snd_soc_card snd_soc_z2 = {
  158. .name = "Z2",
  159. .owner = THIS_MODULE,
  160. .dai_link = &z2_dai,
  161. .num_links = 1,
  162. .dapm_widgets = wm8750_dapm_widgets,
  163. .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
  164. .dapm_routes = z2_audio_map,
  165. .num_dapm_routes = ARRAY_SIZE(z2_audio_map),
  166. };
  167. static struct platform_device *z2_snd_device;
  168. static int __init z2_init(void)
  169. {
  170. int ret;
  171. if (!machine_is_zipit2())
  172. return -ENODEV;
  173. z2_snd_device = platform_device_alloc("soc-audio", -1);
  174. if (!z2_snd_device)
  175. return -ENOMEM;
  176. platform_set_drvdata(z2_snd_device, &snd_soc_z2);
  177. ret = platform_device_add(z2_snd_device);
  178. if (ret)
  179. platform_device_put(z2_snd_device);
  180. return ret;
  181. }
  182. static void __exit z2_exit(void)
  183. {
  184. platform_device_unregister(z2_snd_device);
  185. }
  186. module_init(z2_init);
  187. module_exit(z2_exit);
  188. MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
  189. "Marek Vasut <marek.vasut@gmail.com>");
  190. MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
  191. MODULE_LICENSE("GPL");