z2.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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/soc-dapm.h>
  23. #include <sound/jack.h>
  24. #include <asm/mach-types.h>
  25. #include <mach/hardware.h>
  26. #include <mach/audio.h>
  27. #include <mach/z2.h>
  28. #include "../codecs/wm8750.h"
  29. #include "pxa2xx-i2s.h"
  30. static struct snd_soc_card snd_soc_z2;
  31. static int z2_hw_params(struct snd_pcm_substream *substream,
  32. struct snd_pcm_hw_params *params)
  33. {
  34. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  35. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  36. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  37. unsigned int clk = 0;
  38. int ret = 0;
  39. switch (params_rate(params)) {
  40. case 8000:
  41. case 16000:
  42. case 48000:
  43. case 96000:
  44. clk = 12288000;
  45. break;
  46. case 11025:
  47. case 22050:
  48. case 44100:
  49. clk = 11289600;
  50. break;
  51. }
  52. /* set codec DAI configuration */
  53. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  54. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  55. if (ret < 0)
  56. return ret;
  57. /* set cpu DAI configuration */
  58. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  59. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  60. if (ret < 0)
  61. return ret;
  62. /* set the codec system clock for DAC and ADC */
  63. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  64. SND_SOC_CLOCK_IN);
  65. if (ret < 0)
  66. return ret;
  67. /* set the I2S system clock as input (unused) */
  68. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
  69. SND_SOC_CLOCK_IN);
  70. if (ret < 0)
  71. return ret;
  72. return 0;
  73. }
  74. static struct snd_soc_jack hs_jack;
  75. /* Headset jack detection DAPM pins */
  76. static struct snd_soc_jack_pin hs_jack_pins[] = {
  77. {
  78. .pin = "Mic Jack",
  79. .mask = SND_JACK_MICROPHONE,
  80. },
  81. {
  82. .pin = "Headphone Jack",
  83. .mask = SND_JACK_HEADPHONE,
  84. },
  85. };
  86. /* Headset jack detection gpios */
  87. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  88. {
  89. .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT,
  90. .name = "hsdet-gpio",
  91. .report = SND_JACK_HEADSET,
  92. .debounce_time = 200,
  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. int ret;
  122. /* NC codec pins */
  123. snd_soc_dapm_disable_pin(codec, "LINPUT3");
  124. snd_soc_dapm_disable_pin(codec, "RINPUT3");
  125. snd_soc_dapm_disable_pin(codec, "OUT3");
  126. snd_soc_dapm_disable_pin(codec, "MONO");
  127. /* Add z2 specific widgets */
  128. snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
  129. ARRAY_SIZE(wm8750_dapm_widgets));
  130. /* Set up z2 specific audio paths */
  131. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  132. ret = snd_soc_dapm_sync(codec);
  133. if (ret)
  134. goto err;
  135. /* Jack detection API stuff */
  136. ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
  137. &hs_jack);
  138. if (ret)
  139. goto err;
  140. ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  141. hs_jack_pins);
  142. if (ret)
  143. goto err;
  144. ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  145. hs_jack_gpios);
  146. if (ret)
  147. goto err;
  148. return 0;
  149. err:
  150. return ret;
  151. }
  152. static struct snd_soc_ops z2_ops = {
  153. .hw_params = z2_hw_params,
  154. };
  155. /* z2 digital audio interface glue - connects codec <--> CPU */
  156. static struct snd_soc_dai_link z2_dai = {
  157. .name = "wm8750",
  158. .stream_name = "WM8750",
  159. .cpu_dai_name = "pxa2xx-i2s",
  160. .codec_dai_name = "wm8750-hifi",
  161. .platform_name = "pxa-pcm-audio",
  162. .codec_name = "wm8750-codec.0-001a",
  163. .init = z2_wm8750_init,
  164. .ops = &z2_ops,
  165. };
  166. /* z2 audio machine driver */
  167. static struct snd_soc_card snd_soc_z2 = {
  168. .name = "Z2",
  169. .dai_link = &z2_dai,
  170. .num_links = 1,
  171. };
  172. static struct platform_device *z2_snd_device;
  173. static int __init z2_init(void)
  174. {
  175. int ret;
  176. if (!machine_is_zipit2())
  177. return -ENODEV;
  178. z2_snd_device = platform_device_alloc("soc-audio", -1);
  179. if (!z2_snd_device)
  180. return -ENOMEM;
  181. platform_set_drvdata(z2_snd_device, &snd_soc_z2);
  182. ret = platform_device_add(z2_snd_device);
  183. if (ret)
  184. platform_device_put(z2_snd_device);
  185. return ret;
  186. }
  187. static void __exit z2_exit(void)
  188. {
  189. platform_device_unregister(z2_snd_device);
  190. }
  191. module_init(z2_init);
  192. module_exit(z2_exit);
  193. MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
  194. "Marek Vasut <marek.vasut@gmail.com>");
  195. MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
  196. MODULE_LICENSE("GPL");