zylonite.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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/i2c.h>
  17. #include <sound/core.h>
  18. #include <sound/pcm.h>
  19. #include <sound/pcm_params.h>
  20. #include <sound/soc.h>
  21. #include <sound/soc-dapm.h>
  22. #include "../codecs/wm9713.h"
  23. #include "pxa2xx-pcm.h"
  24. #include "pxa2xx-ac97.h"
  25. #include "pxa-ssp.h"
  26. static struct snd_soc_card zylonite;
  27. static const struct snd_soc_dapm_widget zylonite_dapm_widgets[] = {
  28. SND_SOC_DAPM_HP("Headphone", NULL),
  29. SND_SOC_DAPM_MIC("Headset Microphone", NULL),
  30. SND_SOC_DAPM_MIC("Handset Microphone", NULL),
  31. SND_SOC_DAPM_SPK("Multiactor", NULL),
  32. SND_SOC_DAPM_SPK("Headset Earpiece", NULL),
  33. };
  34. /* Currently supported audio map */
  35. static const struct snd_soc_dapm_route audio_map[] = {
  36. /* Headphone output connected to HPL/HPR */
  37. { "Headphone", NULL, "HPL" },
  38. { "Headphone", NULL, "HPR" },
  39. /* On-board earpiece */
  40. { "Headset Earpiece", NULL, "OUT3" },
  41. /* Headphone mic */
  42. { "MIC2A", NULL, "Mic Bias" },
  43. { "Mic Bias", NULL, "Headset Microphone" },
  44. /* On-board mic */
  45. { "MIC1", NULL, "Mic Bias" },
  46. { "Mic Bias", NULL, "Handset Microphone" },
  47. /* Multiactor differentially connected over SPKL/SPKR */
  48. { "Multiactor", NULL, "SPKL" },
  49. { "Multiactor", NULL, "SPKR" },
  50. };
  51. static int zylonite_wm9713_init(struct snd_soc_codec *codec)
  52. {
  53. /* Currently we only support use of the AC97 clock here. If
  54. * CLK_POUT is selected by SW15 then the clock API will need
  55. * to be used to request and enable it here.
  56. */
  57. snd_soc_dapm_new_controls(codec, zylonite_dapm_widgets,
  58. ARRAY_SIZE(zylonite_dapm_widgets));
  59. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  60. /* Static setup for now */
  61. snd_soc_dapm_enable_pin(codec, "Headphone");
  62. snd_soc_dapm_enable_pin(codec, "Headset Earpiece");
  63. snd_soc_dapm_sync(codec);
  64. return 0;
  65. }
  66. static int zylonite_voice_hw_params(struct snd_pcm_substream *substream,
  67. struct snd_pcm_hw_params *params)
  68. {
  69. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  70. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  71. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  72. unsigned int pll_out = 0;
  73. unsigned int acds = 0;
  74. unsigned int wm9713_div = 0;
  75. int ret = 0;
  76. switch (params_rate(params)) {
  77. case 8000:
  78. wm9713_div = 12;
  79. pll_out = 2048000;
  80. break;
  81. case 16000:
  82. wm9713_div = 6;
  83. pll_out = 4096000;
  84. break;
  85. case 48000:
  86. default:
  87. wm9713_div = 2;
  88. pll_out = 12288000;
  89. acds = 1;
  90. break;
  91. }
  92. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  93. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  94. if (ret < 0)
  95. return ret;
  96. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  97. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  98. if (ret < 0)
  99. return ret;
  100. ret = snd_soc_dai_set_tdm_slot(cpu_dai,
  101. params_channels(params),
  102. params_channels(params));
  103. if (ret < 0)
  104. return ret;
  105. ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, pll_out);
  106. if (ret < 0)
  107. return ret;
  108. ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_AUDIO_DIV_ACDS, acds);
  109. if (ret < 0)
  110. return ret;
  111. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1);
  112. if (ret < 0)
  113. return ret;
  114. /* Note that if the PLL is in use the WM9713_PCMCLK_PLL_DIV needs
  115. * to be set instead.
  116. */
  117. ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV,
  118. WM9713_PCMDIV(wm9713_div));
  119. if (ret < 0)
  120. return ret;
  121. return 0;
  122. }
  123. static struct snd_soc_ops zylonite_voice_ops = {
  124. .hw_params = zylonite_voice_hw_params,
  125. };
  126. static struct snd_soc_dai_link zylonite_dai[] = {
  127. {
  128. .name = "AC97",
  129. .stream_name = "AC97 HiFi",
  130. .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
  131. .codec_dai = &wm9713_dai[WM9713_DAI_AC97_HIFI],
  132. .init = zylonite_wm9713_init,
  133. },
  134. {
  135. .name = "AC97 Aux",
  136. .stream_name = "AC97 Aux",
  137. .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
  138. .codec_dai = &wm9713_dai[WM9713_DAI_AC97_AUX],
  139. },
  140. {
  141. .name = "WM9713 Voice",
  142. .stream_name = "WM9713 Voice",
  143. .cpu_dai = &pxa_ssp_dai[PXA_DAI_SSP3],
  144. .codec_dai = &wm9713_dai[WM9713_DAI_PCM_VOICE],
  145. .ops = &zylonite_voice_ops,
  146. },
  147. };
  148. static struct snd_soc_card zylonite = {
  149. .name = "Zylonite",
  150. .platform = &pxa2xx_soc_platform,
  151. .dai_link = zylonite_dai,
  152. .num_links = ARRAY_SIZE(zylonite_dai),
  153. };
  154. static struct snd_soc_device zylonite_snd_ac97_devdata = {
  155. .card = &zylonite,
  156. .codec_dev = &soc_codec_dev_wm9713,
  157. };
  158. static struct platform_device *zylonite_snd_ac97_device;
  159. static int __init zylonite_init(void)
  160. {
  161. int ret;
  162. zylonite_snd_ac97_device = platform_device_alloc("soc-audio", -1);
  163. if (!zylonite_snd_ac97_device)
  164. return -ENOMEM;
  165. platform_set_drvdata(zylonite_snd_ac97_device,
  166. &zylonite_snd_ac97_devdata);
  167. zylonite_snd_ac97_devdata.dev = &zylonite_snd_ac97_device->dev;
  168. ret = platform_device_add(zylonite_snd_ac97_device);
  169. if (ret != 0)
  170. platform_device_put(zylonite_snd_ac97_device);
  171. return ret;
  172. }
  173. static void __exit zylonite_exit(void)
  174. {
  175. platform_device_unregister(zylonite_snd_ac97_device);
  176. }
  177. module_init(zylonite_init);
  178. module_exit(zylonite_exit);
  179. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  180. MODULE_DESCRIPTION("ALSA SoC WM9713 Zylonite");
  181. MODULE_LICENSE("GPL");