z2.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 codec DAI configuration */
  52. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  53. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  54. if (ret < 0)
  55. return ret;
  56. /* set cpu DAI configuration */
  57. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  58. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  59. if (ret < 0)
  60. return ret;
  61. /* set the codec system clock for DAC and ADC */
  62. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  63. SND_SOC_CLOCK_IN);
  64. if (ret < 0)
  65. return ret;
  66. /* set the I2S system clock as input (unused) */
  67. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
  68. SND_SOC_CLOCK_IN);
  69. if (ret < 0)
  70. return ret;
  71. return 0;
  72. }
  73. static struct snd_soc_jack hs_jack;
  74. /* Headset jack detection DAPM pins */
  75. static struct snd_soc_jack_pin hs_jack_pins[] = {
  76. {
  77. .pin = "Mic Jack",
  78. .mask = SND_JACK_MICROPHONE,
  79. },
  80. {
  81. .pin = "Headphone Jack",
  82. .mask = SND_JACK_HEADPHONE,
  83. },
  84. };
  85. /* Headset jack detection gpios */
  86. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  87. {
  88. .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT,
  89. .name = "hsdet-gpio",
  90. .report = SND_JACK_HEADSET,
  91. .debounce_time = 200,
  92. .invert = 1,
  93. },
  94. };
  95. /* z2 machine dapm widgets */
  96. static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
  97. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  98. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  99. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  100. /* headset is a mic and mono headphone */
  101. SND_SOC_DAPM_HP("Headset Jack", NULL),
  102. };
  103. /* Z2 machine audio_map */
  104. static const struct snd_soc_dapm_route audio_map[] = {
  105. /* headphone connected to LOUT1, ROUT1 */
  106. {"Headphone Jack", NULL, "LOUT1"},
  107. {"Headphone Jack", NULL, "ROUT1"},
  108. /* ext speaker connected to LOUT2, ROUT2 */
  109. {"Ext Spk", NULL , "ROUT2"},
  110. {"Ext Spk", NULL , "LOUT2"},
  111. /* mic is connected to R input 2 - with bias */
  112. {"RINPUT2", NULL, "Mic Bias"},
  113. {"Mic Bias", NULL, "Mic Jack"},
  114. };
  115. /*
  116. * Logic for a wm8750 as connected on a Z2 Device
  117. */
  118. static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
  119. {
  120. struct snd_soc_codec *codec = rtd->codec;
  121. struct snd_soc_dapm_context *dapm = &codec->dapm;
  122. int ret;
  123. /* NC codec pins */
  124. snd_soc_dapm_disable_pin(dapm, "LINPUT3");
  125. snd_soc_dapm_disable_pin(dapm, "RINPUT3");
  126. snd_soc_dapm_disable_pin(dapm, "OUT3");
  127. snd_soc_dapm_disable_pin(dapm, "MONO");
  128. /* Add z2 specific widgets */
  129. snd_soc_dapm_new_controls(dapm, wm8750_dapm_widgets,
  130. ARRAY_SIZE(wm8750_dapm_widgets));
  131. /* Set up z2 specific audio paths */
  132. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  133. ret = snd_soc_dapm_sync(dapm);
  134. if (ret)
  135. goto err;
  136. /* Jack detection API stuff */
  137. ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
  138. &hs_jack);
  139. if (ret)
  140. goto err;
  141. ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  142. hs_jack_pins);
  143. if (ret)
  144. goto err;
  145. ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  146. hs_jack_gpios);
  147. if (ret)
  148. goto err;
  149. return 0;
  150. err:
  151. return ret;
  152. }
  153. static struct snd_soc_ops z2_ops = {
  154. .hw_params = z2_hw_params,
  155. };
  156. /* z2 digital audio interface glue - connects codec <--> CPU */
  157. static struct snd_soc_dai_link z2_dai = {
  158. .name = "wm8750",
  159. .stream_name = "WM8750",
  160. .cpu_dai_name = "pxa2xx-i2s",
  161. .codec_dai_name = "wm8750-hifi",
  162. .platform_name = "pxa-pcm-audio",
  163. .codec_name = "wm8750-codec.0-001b",
  164. .init = z2_wm8750_init,
  165. .ops = &z2_ops,
  166. };
  167. /* z2 audio machine driver */
  168. static struct snd_soc_card snd_soc_z2 = {
  169. .name = "Z2",
  170. .dai_link = &z2_dai,
  171. .num_links = 1,
  172. };
  173. static struct platform_device *z2_snd_device;
  174. static int __init z2_init(void)
  175. {
  176. int ret;
  177. if (!machine_is_zipit2())
  178. return -ENODEV;
  179. z2_snd_device = platform_device_alloc("soc-audio", -1);
  180. if (!z2_snd_device)
  181. return -ENOMEM;
  182. platform_set_drvdata(z2_snd_device, &snd_soc_z2);
  183. ret = platform_device_add(z2_snd_device);
  184. if (ret)
  185. platform_device_put(z2_snd_device);
  186. return ret;
  187. }
  188. static void __exit z2_exit(void)
  189. {
  190. platform_device_unregister(z2_snd_device);
  191. }
  192. module_init(z2_init);
  193. module_exit(z2_exit);
  194. MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
  195. "Marek Vasut <marek.vasut@gmail.com>");
  196. MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
  197. MODULE_LICENSE("GPL");