speyside.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * Speyside audio support
  3. *
  4. * Copyright 2011 Wolfson Microelectronics
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <sound/soc.h>
  12. #include <sound/soc-dapm.h>
  13. #include "../codecs/wm8915.h"
  14. #include "../codecs/wm9081.h"
  15. static int speyside_set_bias_level(struct snd_soc_card *card,
  16. enum snd_soc_bias_level level)
  17. {
  18. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  19. int ret;
  20. switch (level) {
  21. case SND_SOC_BIAS_STANDBY:
  22. ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK1,
  23. 32768, SND_SOC_CLOCK_IN);
  24. if (ret < 0)
  25. return ret;
  26. ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK1,
  27. 0, 0, 0);
  28. if (ret < 0) {
  29. pr_err("Failed to stop FLL\n");
  30. return ret;
  31. }
  32. default:
  33. break;
  34. }
  35. return 0;
  36. }
  37. static int speyside_hw_params(struct snd_pcm_substream *substream,
  38. struct snd_pcm_hw_params *params)
  39. {
  40. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  41. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  42. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  43. int ret;
  44. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  45. | SND_SOC_DAIFMT_NB_NF
  46. | SND_SOC_DAIFMT_CBM_CFM);
  47. if (ret < 0)
  48. return ret;
  49. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  50. | SND_SOC_DAIFMT_NB_NF
  51. | SND_SOC_DAIFMT_CBM_CFM);
  52. if (ret < 0)
  53. return ret;
  54. ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK1,
  55. 32768, 256 * 48000);
  56. if (ret < 0)
  57. return ret;
  58. ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_FLL,
  59. 256 * 48000, SND_SOC_CLOCK_IN);
  60. if (ret < 0)
  61. return ret;
  62. return 0;
  63. }
  64. static struct snd_soc_ops speyside_ops = {
  65. .hw_params = speyside_hw_params,
  66. };
  67. static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
  68. {
  69. struct snd_soc_dai *dai = rtd->codec_dai;
  70. return snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0);
  71. }
  72. static struct snd_soc_dai_link speyside_dai[] = {
  73. {
  74. .name = "CPU",
  75. .stream_name = "CPU",
  76. .cpu_dai_name = "samsung-i2s.0",
  77. .codec_dai_name = "wm8915-aif1",
  78. .platform_name = "samsung-audio",
  79. .codec_name = "wm8915.1-001a",
  80. .init = speyside_wm8915_init,
  81. .ops = &speyside_ops,
  82. },
  83. };
  84. static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
  85. {
  86. snd_soc_dapm_nc_pin(dapm, "LINEOUT");
  87. /* At any time the WM9081 is active it will have this clock */
  88. return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK,
  89. 48000 * 256, 0);
  90. }
  91. static struct snd_soc_aux_dev speyside_aux_dev[] = {
  92. {
  93. .name = "wm9081",
  94. .codec_name = "wm9081.1-006c",
  95. .init = speyside_wm9081_init,
  96. },
  97. };
  98. static struct snd_soc_codec_conf speyside_codec_conf[] = {
  99. {
  100. .dev_name = "wm9081.1-006c",
  101. .name_prefix = "Sub",
  102. },
  103. };
  104. static struct snd_soc_dapm_widget widgets[] = {
  105. SND_SOC_DAPM_HP("Headphone", NULL),
  106. SND_SOC_DAPM_SPK("Main Speaker", NULL),
  107. SND_SOC_DAPM_MIC("Main AMIC", NULL),
  108. SND_SOC_DAPM_MIC("Main DMIC", NULL),
  109. };
  110. static struct snd_soc_dapm_route audio_paths[] = {
  111. { "IN1LP", NULL, "MICB2" },
  112. { "MICB2", NULL, "Main AMIC" },
  113. { "DMIC1DAT", NULL, "MICB1" },
  114. { "DMIC2DAT", NULL, "MICB1" },
  115. { "MICB1", NULL, "Main DMIC" },
  116. { "Headphone", NULL, "HPOUT1L" },
  117. { "Headphone", NULL, "HPOUT1R" },
  118. { "Sub IN1", NULL, "HPOUT2L" },
  119. { "Sub IN2", NULL, "HPOUT2R" },
  120. { "Main Speaker", NULL, "Sub SPKN" },
  121. { "Main Speaker", NULL, "Sub SPKP" },
  122. { "Main Speaker", NULL, "SPKDAT" },
  123. };
  124. static struct snd_soc_card speyside = {
  125. .name = "Speyside",
  126. .dai_link = speyside_dai,
  127. .num_links = ARRAY_SIZE(speyside_dai),
  128. .aux_dev = speyside_aux_dev,
  129. .num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
  130. .codec_conf = speyside_codec_conf,
  131. .num_configs = ARRAY_SIZE(speyside_codec_conf),
  132. .set_bias_level = speyside_set_bias_level,
  133. .dapm_widgets = widgets,
  134. .num_dapm_widgets = ARRAY_SIZE(widgets),
  135. .dapm_routes = audio_paths,
  136. .num_dapm_routes = ARRAY_SIZE(audio_paths),
  137. };
  138. static __devinit int speyside_probe(struct platform_device *pdev)
  139. {
  140. struct snd_soc_card *card = &speyside;
  141. int ret;
  142. card->dev = &pdev->dev;
  143. ret = snd_soc_register_card(card);
  144. if (ret) {
  145. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  146. ret);
  147. return ret;
  148. }
  149. return 0;
  150. }
  151. static int __devexit speyside_remove(struct platform_device *pdev)
  152. {
  153. struct snd_soc_card *card = platform_get_drvdata(pdev);
  154. snd_soc_unregister_card(card);
  155. return 0;
  156. }
  157. static struct platform_driver speyside_driver = {
  158. .driver = {
  159. .name = "speyside",
  160. .owner = THIS_MODULE,
  161. .pm = &snd_soc_pm_ops,
  162. },
  163. .probe = speyside_probe,
  164. .remove = __devexit_p(speyside_remove),
  165. };
  166. static int __init speyside_audio_init(void)
  167. {
  168. return platform_driver_register(&speyside_driver);
  169. }
  170. module_init(speyside_audio_init);
  171. static void __exit speyside_audio_exit(void)
  172. {
  173. platform_driver_unregister(&speyside_driver);
  174. }
  175. module_exit(speyside_audio_exit);
  176. MODULE_DESCRIPTION("Speyside audio support");
  177. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  178. MODULE_LICENSE("GPL");
  179. MODULE_ALIAS("platform:speyside");