z2.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. int ret;
  116. /* Jack detection API stuff */
  117. ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", SND_JACK_HEADSET,
  118. &hs_jack, hs_jack_pins,
  119. ARRAY_SIZE(hs_jack_pins));
  120. if (ret)
  121. goto err;
  122. ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  123. hs_jack_gpios);
  124. if (ret)
  125. goto err;
  126. return 0;
  127. err:
  128. return ret;
  129. }
  130. static struct snd_soc_ops z2_ops = {
  131. .hw_params = z2_hw_params,
  132. };
  133. /* z2 digital audio interface glue - connects codec <--> CPU */
  134. static struct snd_soc_dai_link z2_dai = {
  135. .name = "wm8750",
  136. .stream_name = "WM8750",
  137. .cpu_dai_name = "pxa2xx-i2s",
  138. .codec_dai_name = "wm8750-hifi",
  139. .platform_name = "pxa-pcm-audio",
  140. .codec_name = "wm8750.0-001b",
  141. .init = z2_wm8750_init,
  142. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  143. SND_SOC_DAIFMT_CBS_CFS,
  144. .ops = &z2_ops,
  145. };
  146. /* z2 audio machine driver */
  147. static struct snd_soc_card snd_soc_z2 = {
  148. .name = "Z2",
  149. .owner = THIS_MODULE,
  150. .dai_link = &z2_dai,
  151. .num_links = 1,
  152. .dapm_widgets = wm8750_dapm_widgets,
  153. .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
  154. .dapm_routes = z2_audio_map,
  155. .num_dapm_routes = ARRAY_SIZE(z2_audio_map),
  156. .fully_routed = true,
  157. };
  158. static struct platform_device *z2_snd_device;
  159. static int __init z2_init(void)
  160. {
  161. int ret;
  162. if (!machine_is_zipit2())
  163. return -ENODEV;
  164. z2_snd_device = platform_device_alloc("soc-audio", -1);
  165. if (!z2_snd_device)
  166. return -ENOMEM;
  167. platform_set_drvdata(z2_snd_device, &snd_soc_z2);
  168. ret = platform_device_add(z2_snd_device);
  169. if (ret)
  170. platform_device_put(z2_snd_device);
  171. return ret;
  172. }
  173. static void __exit z2_exit(void)
  174. {
  175. platform_device_unregister(z2_snd_device);
  176. }
  177. module_init(z2_init);
  178. module_exit(z2_exit);
  179. MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
  180. "Marek Vasut <marek.vasut@gmail.com>");
  181. MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
  182. MODULE_LICENSE("GPL");