speyside.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. static int speyside_set_bias_level(struct snd_soc_card *card,
  15. enum snd_soc_bias_level level)
  16. {
  17. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  18. int ret;
  19. switch (level) {
  20. case SND_SOC_BIAS_STANDBY:
  21. ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK1,
  22. 32768, SND_SOC_CLOCK_IN);
  23. if (ret < 0)
  24. return ret;
  25. ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK1,
  26. 0, 0, 0);
  27. if (ret < 0) {
  28. pr_err("Failed to stop FLL\n");
  29. return ret;
  30. }
  31. default:
  32. break;
  33. }
  34. return 0;
  35. }
  36. static int speyside_hw_params(struct snd_pcm_substream *substream,
  37. struct snd_pcm_hw_params *params)
  38. {
  39. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  40. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  41. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  42. int ret;
  43. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  44. | SND_SOC_DAIFMT_NB_NF
  45. | SND_SOC_DAIFMT_CBM_CFM);
  46. if (ret < 0)
  47. return ret;
  48. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  49. | SND_SOC_DAIFMT_NB_NF
  50. | SND_SOC_DAIFMT_CBM_CFM);
  51. if (ret < 0)
  52. return ret;
  53. ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK1,
  54. 32768, 256 * 48000);
  55. if (ret < 0)
  56. return ret;
  57. ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_FLL,
  58. 256 * 48000, SND_SOC_CLOCK_IN);
  59. if (ret < 0)
  60. return ret;
  61. return 0;
  62. }
  63. static struct snd_soc_ops speyside_ops = {
  64. .hw_params = speyside_hw_params,
  65. };
  66. static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
  67. {
  68. struct snd_soc_dai *dai = rtd->codec_dai;
  69. return snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0);
  70. }
  71. static struct snd_soc_dai_link speyside_dai[] = {
  72. {
  73. .name = "CPU",
  74. .stream_name = "CPU",
  75. .cpu_dai_name = "samsung-i2s.0",
  76. .codec_dai_name = "wm8915-aif1",
  77. .platform_name = "samsung-audio",
  78. .codec_name = "wm8915.1-001a",
  79. .init = speyside_wm8915_init,
  80. .ops = &speyside_ops,
  81. },
  82. };
  83. static struct snd_soc_dapm_widget widgets[] = {
  84. SND_SOC_DAPM_HP("Headphone", NULL),
  85. SND_SOC_DAPM_SPK("Main Speaker", NULL),
  86. SND_SOC_DAPM_MIC("Main AMIC", NULL),
  87. SND_SOC_DAPM_MIC("Main DMIC", NULL),
  88. };
  89. static struct snd_soc_dapm_route audio_paths[] = {
  90. { "IN1LP", NULL, "MICB2" },
  91. { "MICB2", NULL, "Main AMIC" },
  92. { "DMIC1DAT", NULL, "MICB1" },
  93. { "DMIC2DAT", NULL, "MICB1" },
  94. { "MICB1", NULL, "Main DMIC" },
  95. { "Headphone", NULL, "HPOUT1L" },
  96. { "Headphone", NULL, "HPOUT1R" },
  97. { "Main Speaker", NULL, "SPKDAT" },
  98. };
  99. static struct snd_soc_card speyside = {
  100. .name = "Speyside",
  101. .dai_link = speyside_dai,
  102. .num_links = ARRAY_SIZE(speyside_dai),
  103. .set_bias_level = speyside_set_bias_level,
  104. .dapm_widgets = widgets,
  105. .num_dapm_widgets = ARRAY_SIZE(widgets),
  106. .dapm_routes = audio_paths,
  107. .num_dapm_routes = ARRAY_SIZE(audio_paths),
  108. };
  109. static __devinit int speyside_probe(struct platform_device *pdev)
  110. {
  111. struct snd_soc_card *card = &speyside;
  112. int ret;
  113. card->dev = &pdev->dev;
  114. ret = snd_soc_register_card(card);
  115. if (ret) {
  116. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  117. ret);
  118. return ret;
  119. }
  120. return 0;
  121. }
  122. static int __devexit speyside_remove(struct platform_device *pdev)
  123. {
  124. struct snd_soc_card *card = platform_get_drvdata(pdev);
  125. snd_soc_unregister_card(card);
  126. return 0;
  127. }
  128. static struct platform_driver speyside_driver = {
  129. .driver = {
  130. .name = "speyside",
  131. .owner = THIS_MODULE,
  132. .pm = &snd_soc_pm_ops,
  133. },
  134. .probe = speyside_probe,
  135. .remove = __devexit_p(speyside_remove),
  136. };
  137. static int __init speyside_audio_init(void)
  138. {
  139. return platform_driver_register(&speyside_driver);
  140. }
  141. module_init(speyside_audio_init);
  142. static void __exit speyside_audio_exit(void)
  143. {
  144. platform_driver_unregister(&speyside_driver);
  145. }
  146. module_exit(speyside_audio_exit);
  147. MODULE_DESCRIPTION("Speyside audio support");
  148. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  149. MODULE_LICENSE("GPL");
  150. MODULE_ALIAS("platform:speyside");