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/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-pcm.h"
  30. #include "pxa2xx-i2s.h"
  31. static struct snd_soc_card snd_soc_z2;
  32. static int z2_hw_params(struct snd_pcm_substream *substream,
  33. struct snd_pcm_hw_params *params)
  34. {
  35. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  36. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  37. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  38. unsigned int clk = 0;
  39. int ret = 0;
  40. switch (params_rate(params)) {
  41. case 8000:
  42. case 16000:
  43. case 48000:
  44. case 96000:
  45. clk = 12288000;
  46. break;
  47. case 11025:
  48. case 22050:
  49. case 44100:
  50. clk = 11289600;
  51. break;
  52. }
  53. /* set codec DAI configuration */
  54. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  55. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  56. if (ret < 0)
  57. return ret;
  58. /* set cpu DAI configuration */
  59. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  60. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  61. if (ret < 0)
  62. return ret;
  63. /* set the codec system clock for DAC and ADC */
  64. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  65. SND_SOC_CLOCK_IN);
  66. if (ret < 0)
  67. return ret;
  68. /* set the I2S system clock as input (unused) */
  69. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
  70. SND_SOC_CLOCK_IN);
  71. if (ret < 0)
  72. return ret;
  73. return 0;
  74. }
  75. static struct snd_soc_jack hs_jack;
  76. /* Headset jack detection DAPM pins */
  77. static struct snd_soc_jack_pin hs_jack_pins[] = {
  78. {
  79. .pin = "Mic Jack",
  80. .mask = SND_JACK_MICROPHONE,
  81. },
  82. {
  83. .pin = "Headphone Jack",
  84. .mask = SND_JACK_HEADPHONE,
  85. },
  86. };
  87. /* Headset jack detection gpios */
  88. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  89. {
  90. .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT,
  91. .name = "hsdet-gpio",
  92. .report = SND_JACK_HEADSET,
  93. .debounce_time = 200,
  94. },
  95. };
  96. /* z2 machine dapm widgets */
  97. static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
  98. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  99. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  100. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  101. /* headset is a mic and mono headphone */
  102. SND_SOC_DAPM_HP("Headset Jack", NULL),
  103. };
  104. /* Z2 machine audio_map */
  105. static const struct snd_soc_dapm_route audio_map[] = {
  106. /* headphone connected to LOUT1, ROUT1 */
  107. {"Headphone Jack", NULL, "LOUT1"},
  108. {"Headphone Jack", NULL, "ROUT1"},
  109. /* ext speaker connected to LOUT2, ROUT2 */
  110. {"Ext Spk", NULL , "ROUT2"},
  111. {"Ext Spk", NULL , "LOUT2"},
  112. /* mic is connected to R input 2 - with bias */
  113. {"RINPUT2", NULL, "Mic Bias"},
  114. {"Mic Bias", NULL, "Mic Jack"},
  115. };
  116. /*
  117. * Logic for a wm8750 as connected on a Z2 Device
  118. */
  119. static int z2_wm8750_init(struct snd_soc_codec *codec)
  120. {
  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(&snd_soc_z2, "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 = &pxa_i2s_dai,
  160. .codec_dai = &wm8750_dai,
  161. .init = z2_wm8750_init,
  162. .ops = &z2_ops,
  163. };
  164. /* z2 audio machine driver */
  165. static struct snd_soc_card snd_soc_z2 = {
  166. .name = "Z2",
  167. .platform = &pxa2xx_soc_platform,
  168. .dai_link = &z2_dai,
  169. .num_links = 1,
  170. };
  171. /* z2 audio subsystem */
  172. static struct snd_soc_device z2_snd_devdata = {
  173. .card = &snd_soc_z2,
  174. .codec_dev = &soc_codec_dev_wm8750,
  175. };
  176. static struct platform_device *z2_snd_device;
  177. static int __init z2_init(void)
  178. {
  179. int ret;
  180. if (!machine_is_zipit2())
  181. return -ENODEV;
  182. z2_snd_device = platform_device_alloc("soc-audio", -1);
  183. if (!z2_snd_device)
  184. return -ENOMEM;
  185. platform_set_drvdata(z2_snd_device, &z2_snd_devdata);
  186. z2_snd_devdata.dev = &z2_snd_device->dev;
  187. ret = platform_device_add(z2_snd_device);
  188. if (ret)
  189. platform_device_put(z2_snd_device);
  190. return ret;
  191. }
  192. static void __exit z2_exit(void)
  193. {
  194. platform_device_unregister(z2_snd_device);
  195. }
  196. module_init(z2_init);
  197. module_exit(z2_exit);
  198. MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
  199. "Marek Vasut <marek.vasut@gmail.com>");
  200. MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
  201. MODULE_LICENSE("GPL");