zylonite.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * zylonite.c -- SoC audio for Zylonite
  3. *
  4. * Copyright 2008 Wolfson Microelectronics PLC.
  5. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of the
  10. * License, or (at your option) any later version.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/device.h>
  16. #include <linux/clk.h>
  17. #include <linux/i2c.h>
  18. #include <sound/core.h>
  19. #include <sound/pcm.h>
  20. #include <sound/pcm_params.h>
  21. #include <sound/soc.h>
  22. #include "../codecs/wm9713.h"
  23. #include "pxa-ssp.h"
  24. /*
  25. * There is a physical switch SW15 on the board which changes the MCLK
  26. * for the WM9713 between the standard AC97 master clock and the
  27. * output of the CLK_POUT signal from the PXA.
  28. */
  29. static int clk_pout;
  30. module_param(clk_pout, int, 0);
  31. MODULE_PARM_DESC(clk_pout, "Use CLK_POUT as WM9713 MCLK (SW15 on board).");
  32. static struct clk *pout;
  33. static struct snd_soc_card zylonite;
  34. static const struct snd_soc_dapm_widget zylonite_dapm_widgets[] = {
  35. SND_SOC_DAPM_HP("Headphone", NULL),
  36. SND_SOC_DAPM_MIC("Headset Microphone", NULL),
  37. SND_SOC_DAPM_MIC("Handset Microphone", NULL),
  38. SND_SOC_DAPM_SPK("Multiactor", NULL),
  39. SND_SOC_DAPM_SPK("Headset Earpiece", NULL),
  40. };
  41. /* Currently supported audio map */
  42. static const struct snd_soc_dapm_route audio_map[] = {
  43. /* Headphone output connected to HPL/HPR */
  44. { "Headphone", NULL, "HPL" },
  45. { "Headphone", NULL, "HPR" },
  46. /* On-board earpiece */
  47. { "Headset Earpiece", NULL, "OUT3" },
  48. /* Headphone mic */
  49. { "MIC2A", NULL, "Mic Bias" },
  50. { "Mic Bias", NULL, "Headset Microphone" },
  51. /* On-board mic */
  52. { "MIC1", NULL, "Mic Bias" },
  53. { "Mic Bias", NULL, "Handset Microphone" },
  54. /* Multiactor differentially connected over SPKL/SPKR */
  55. { "Multiactor", NULL, "SPKL" },
  56. { "Multiactor", NULL, "SPKR" },
  57. };
  58. static int zylonite_wm9713_init(struct snd_soc_pcm_runtime *rtd)
  59. {
  60. if (clk_pout)
  61. snd_soc_dai_set_pll(rtd->codec_dai, 0, 0,
  62. clk_get_rate(pout), 0);
  63. return 0;
  64. }
  65. static int zylonite_voice_hw_params(struct snd_pcm_substream *substream,
  66. struct snd_pcm_hw_params *params)
  67. {
  68. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  69. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  70. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  71. unsigned int wm9713_div = 0;
  72. int ret = 0;
  73. int rate = params_rate(params);
  74. /* Only support ratios that we can generate neatly from the AC97
  75. * based master clock - in particular, this excludes 44.1kHz.
  76. * In most applications the voice DAC will be used for telephony
  77. * data so multiples of 8kHz will be the common case.
  78. */
  79. switch (rate) {
  80. case 8000:
  81. wm9713_div = 12;
  82. break;
  83. case 16000:
  84. wm9713_div = 6;
  85. break;
  86. case 48000:
  87. wm9713_div = 2;
  88. break;
  89. default:
  90. /* Don't support OSS emulation */
  91. return -EINVAL;
  92. }
  93. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1);
  94. if (ret < 0)
  95. return ret;
  96. if (clk_pout)
  97. ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_PLL_DIV,
  98. WM9713_PCMDIV(wm9713_div));
  99. else
  100. ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV,
  101. WM9713_PCMDIV(wm9713_div));
  102. if (ret < 0)
  103. return ret;
  104. return 0;
  105. }
  106. static const struct snd_soc_ops zylonite_voice_ops = {
  107. .hw_params = zylonite_voice_hw_params,
  108. };
  109. static struct snd_soc_dai_link zylonite_dai[] = {
  110. {
  111. .name = "AC97",
  112. .stream_name = "AC97 HiFi",
  113. .codec_name = "wm9713-codec",
  114. .platform_name = "pxa-pcm-audio",
  115. .cpu_dai_name = "pxa2xx-ac97",
  116. .codec_dai_name = "wm9713-hifi",
  117. .init = zylonite_wm9713_init,
  118. },
  119. {
  120. .name = "AC97 Aux",
  121. .stream_name = "AC97 Aux",
  122. .codec_name = "wm9713-codec",
  123. .platform_name = "pxa-pcm-audio",
  124. .cpu_dai_name = "pxa2xx-ac97-aux",
  125. .codec_dai_name = "wm9713-aux",
  126. },
  127. {
  128. .name = "WM9713 Voice",
  129. .stream_name = "WM9713 Voice",
  130. .codec_name = "wm9713-codec",
  131. .platform_name = "pxa-pcm-audio",
  132. .cpu_dai_name = "pxa-ssp-dai.2",
  133. .codec_dai_name = "wm9713-voice",
  134. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  135. SND_SOC_DAIFMT_CBS_CFS,
  136. .ops = &zylonite_voice_ops,
  137. },
  138. };
  139. static int zylonite_probe(struct snd_soc_card *card)
  140. {
  141. int ret;
  142. if (clk_pout) {
  143. pout = clk_get(NULL, "CLK_POUT");
  144. if (IS_ERR(pout)) {
  145. dev_err(card->dev, "Unable to obtain CLK_POUT: %ld\n",
  146. PTR_ERR(pout));
  147. return PTR_ERR(pout);
  148. }
  149. ret = clk_enable(pout);
  150. if (ret != 0) {
  151. dev_err(card->dev, "Unable to enable CLK_POUT: %d\n",
  152. ret);
  153. clk_put(pout);
  154. return ret;
  155. }
  156. dev_dbg(card->dev, "MCLK enabled at %luHz\n",
  157. clk_get_rate(pout));
  158. }
  159. return 0;
  160. }
  161. static int zylonite_remove(struct snd_soc_card *card)
  162. {
  163. if (clk_pout) {
  164. clk_disable(pout);
  165. clk_put(pout);
  166. }
  167. return 0;
  168. }
  169. static int zylonite_suspend_post(struct snd_soc_card *card)
  170. {
  171. if (clk_pout)
  172. clk_disable(pout);
  173. return 0;
  174. }
  175. static int zylonite_resume_pre(struct snd_soc_card *card)
  176. {
  177. int ret = 0;
  178. if (clk_pout) {
  179. ret = clk_enable(pout);
  180. if (ret != 0)
  181. dev_err(card->dev, "Unable to enable CLK_POUT: %d\n",
  182. ret);
  183. }
  184. return ret;
  185. }
  186. static struct snd_soc_card zylonite = {
  187. .name = "Zylonite",
  188. .owner = THIS_MODULE,
  189. .probe = &zylonite_probe,
  190. .remove = &zylonite_remove,
  191. .suspend_post = &zylonite_suspend_post,
  192. .resume_pre = &zylonite_resume_pre,
  193. .dai_link = zylonite_dai,
  194. .num_links = ARRAY_SIZE(zylonite_dai),
  195. .dapm_widgets = zylonite_dapm_widgets,
  196. .num_dapm_widgets = ARRAY_SIZE(zylonite_dapm_widgets),
  197. .dapm_routes = audio_map,
  198. .num_dapm_routes = ARRAY_SIZE(audio_map),
  199. };
  200. static struct platform_device *zylonite_snd_ac97_device;
  201. static int __init zylonite_init(void)
  202. {
  203. int ret;
  204. zylonite_snd_ac97_device = platform_device_alloc("soc-audio", -1);
  205. if (!zylonite_snd_ac97_device)
  206. return -ENOMEM;
  207. platform_set_drvdata(zylonite_snd_ac97_device, &zylonite);
  208. ret = platform_device_add(zylonite_snd_ac97_device);
  209. if (ret != 0)
  210. platform_device_put(zylonite_snd_ac97_device);
  211. return ret;
  212. }
  213. static void __exit zylonite_exit(void)
  214. {
  215. platform_device_unregister(zylonite_snd_ac97_device);
  216. }
  217. module_init(zylonite_init);
  218. module_exit(zylonite_exit);
  219. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  220. MODULE_DESCRIPTION("ALSA SoC WM9713 Zylonite");
  221. MODULE_LICENSE("GPL");