z2.c 5.5 KB

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