z2.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/sound/soc/pxa/z2.c
  4. *
  5. * SoC Audio driver for Aeronix Zipit Z2
  6. *
  7. * Copyright (C) 2009 Ken McGuire <[email protected]>
  8. * Copyright (C) 2010 Marek Vasut <[email protected]>
  9. */
  10. #include <linux/module.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/timer.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/gpio/consumer.h>
  16. #include <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/soc.h>
  19. #include <sound/jack.h>
  20. #include <asm/mach-types.h>
  21. #include <linux/platform_data/asoc-pxa.h>
  22. #include "../codecs/wm8750.h"
  23. #include "pxa2xx-i2s.h"
  24. static struct snd_soc_card snd_soc_z2;
  25. static int z2_hw_params(struct snd_pcm_substream *substream,
  26. struct snd_pcm_hw_params *params)
  27. {
  28. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  29. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  30. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  31. unsigned int clk = 0;
  32. int ret = 0;
  33. switch (params_rate(params)) {
  34. case 8000:
  35. case 16000:
  36. case 48000:
  37. case 96000:
  38. clk = 12288000;
  39. break;
  40. case 11025:
  41. case 22050:
  42. case 44100:
  43. clk = 11289600;
  44. break;
  45. }
  46. /* set the codec system clock for DAC and ADC */
  47. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  48. SND_SOC_CLOCK_IN);
  49. if (ret < 0)
  50. return ret;
  51. /* set the I2S system clock as input (unused) */
  52. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
  53. SND_SOC_CLOCK_IN);
  54. if (ret < 0)
  55. return ret;
  56. return 0;
  57. }
  58. static struct snd_soc_jack hs_jack;
  59. /* Headset jack detection DAPM pins */
  60. static struct snd_soc_jack_pin hs_jack_pins[] = {
  61. {
  62. .pin = "Mic Jack",
  63. .mask = SND_JACK_MICROPHONE,
  64. },
  65. {
  66. .pin = "Headphone Jack",
  67. .mask = SND_JACK_HEADPHONE,
  68. },
  69. {
  70. .pin = "Ext Spk",
  71. .mask = SND_JACK_HEADPHONE,
  72. .invert = 1
  73. },
  74. };
  75. /* Headset jack detection gpios */
  76. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  77. {
  78. .name = "hsdet-gpio",
  79. .report = SND_JACK_HEADSET,
  80. .debounce_time = 200,
  81. .invert = 1,
  82. },
  83. };
  84. /* z2 machine dapm widgets */
  85. static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
  86. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  87. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  88. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  89. /* headset is a mic and mono headphone */
  90. SND_SOC_DAPM_HP("Headset Jack", NULL),
  91. };
  92. /* Z2 machine audio_map */
  93. static const struct snd_soc_dapm_route z2_audio_map[] = {
  94. /* headphone connected to LOUT1, ROUT1 */
  95. {"Headphone Jack", NULL, "LOUT1"},
  96. {"Headphone Jack", NULL, "ROUT1"},
  97. /* ext speaker connected to LOUT2, ROUT2 */
  98. {"Ext Spk", NULL, "ROUT2"},
  99. {"Ext Spk", NULL, "LOUT2"},
  100. /* mic is connected to R input 2 - with bias */
  101. {"RINPUT2", NULL, "Mic Bias"},
  102. {"Mic Bias", NULL, "Mic Jack"},
  103. };
  104. /*
  105. * Logic for a wm8750 as connected on a Z2 Device
  106. */
  107. static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
  108. {
  109. int ret;
  110. /* Jack detection API stuff */
  111. ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
  112. SND_JACK_HEADSET, &hs_jack,
  113. hs_jack_pins,
  114. ARRAY_SIZE(hs_jack_pins));
  115. if (ret)
  116. goto err;
  117. ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  118. hs_jack_gpios);
  119. if (ret)
  120. goto err;
  121. return 0;
  122. err:
  123. return ret;
  124. }
  125. static const struct snd_soc_ops z2_ops = {
  126. .hw_params = z2_hw_params,
  127. };
  128. /* z2 digital audio interface glue - connects codec <--> CPU */
  129. SND_SOC_DAILINK_DEFS(wm8750,
  130. DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-i2s")),
  131. DAILINK_COMP_ARRAY(COMP_CODEC("wm8750.0-001b", "wm8750-hifi")),
  132. DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
  133. static struct snd_soc_dai_link z2_dai = {
  134. .name = "wm8750",
  135. .stream_name = "WM8750",
  136. .init = z2_wm8750_init,
  137. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  138. SND_SOC_DAIFMT_CBS_CFS,
  139. .ops = &z2_ops,
  140. SND_SOC_DAILINK_REG(wm8750),
  141. };
  142. /* z2 audio machine driver */
  143. static struct snd_soc_card snd_soc_z2 = {
  144. .name = "Z2",
  145. .owner = THIS_MODULE,
  146. .dai_link = &z2_dai,
  147. .num_links = 1,
  148. .dapm_widgets = wm8750_dapm_widgets,
  149. .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
  150. .dapm_routes = z2_audio_map,
  151. .num_dapm_routes = ARRAY_SIZE(z2_audio_map),
  152. .fully_routed = true,
  153. };
  154. static struct platform_device *z2_snd_device;
  155. static int __init z2_init(void)
  156. {
  157. int ret;
  158. if (!machine_is_zipit2())
  159. return -ENODEV;
  160. z2_snd_device = platform_device_alloc("soc-audio", -1);
  161. if (!z2_snd_device)
  162. return -ENOMEM;
  163. hs_jack_gpios[0].gpiod_dev = &z2_snd_device->dev;
  164. platform_set_drvdata(z2_snd_device, &snd_soc_z2);
  165. ret = platform_device_add(z2_snd_device);
  166. if (ret)
  167. platform_device_put(z2_snd_device);
  168. return ret;
  169. }
  170. static void __exit z2_exit(void)
  171. {
  172. platform_device_unregister(z2_snd_device);
  173. }
  174. module_init(z2_init);
  175. module_exit(z2_exit);
  176. MODULE_AUTHOR("Ken McGuire <[email protected]>, "
  177. "Marek Vasut <[email protected]>");
  178. MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
  179. MODULE_LICENSE("GPL");