speyside_wm8962.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Speyside with WM8962 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 <sound/jack.h>
  14. #include <linux/gpio.h>
  15. #include "../codecs/wm8962.h"
  16. static int speyside_wm8962_set_bias_level(struct snd_soc_card *card,
  17. struct snd_soc_dapm_context *dapm,
  18. enum snd_soc_bias_level level)
  19. {
  20. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  21. int ret;
  22. switch (level) {
  23. case SND_SOC_BIAS_PREPARE:
  24. if (dapm->bias_level == SND_SOC_BIAS_STANDBY) {
  25. ret = snd_soc_dai_set_pll(codec_dai, WM8962_FLL,
  26. WM8962_FLL_MCLK, 32768,
  27. 44100 * 512);
  28. if (ret < 0)
  29. pr_err("Failed to start FLL: %d\n", ret);
  30. ret = snd_soc_dai_set_sysclk(codec_dai,
  31. WM8962_SYSCLK_FLL,
  32. 44100 * 512,
  33. SND_SOC_CLOCK_IN);
  34. if (ret < 0) {
  35. pr_err("Failed to set SYSCLK: %d\n", ret);
  36. return ret;
  37. }
  38. }
  39. break;
  40. default:
  41. break;
  42. }
  43. return 0;
  44. }
  45. static int speyside_wm8962_set_bias_level_post(struct snd_soc_card *card,
  46. struct snd_soc_dapm_context *dapm,
  47. enum snd_soc_bias_level level)
  48. {
  49. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  50. int ret;
  51. switch (level) {
  52. case SND_SOC_BIAS_STANDBY:
  53. ret = snd_soc_dai_set_sysclk(codec_dai, WM8962_SYSCLK_MCLK,
  54. 32768, SND_SOC_CLOCK_IN);
  55. if (ret < 0) {
  56. pr_err("Failed to switch away from FLL: %d\n", ret);
  57. return ret;
  58. }
  59. ret = snd_soc_dai_set_pll(codec_dai, WM8962_FLL,
  60. 0, 0, 0);
  61. if (ret < 0) {
  62. pr_err("Failed to stop FLL: %d\n", ret);
  63. return ret;
  64. }
  65. break;
  66. default:
  67. break;
  68. }
  69. dapm->bias_level = level;
  70. return 0;
  71. }
  72. static int speyside_wm8962_hw_params(struct snd_pcm_substream *substream,
  73. struct snd_pcm_hw_params *params)
  74. {
  75. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  76. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  77. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  78. int ret;
  79. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  80. | SND_SOC_DAIFMT_NB_NF
  81. | SND_SOC_DAIFMT_CBM_CFM);
  82. if (ret < 0)
  83. return ret;
  84. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  85. | SND_SOC_DAIFMT_NB_NF
  86. | SND_SOC_DAIFMT_CBM_CFM);
  87. if (ret < 0)
  88. return ret;
  89. return 0;
  90. }
  91. static struct snd_soc_ops speyside_wm8962_ops = {
  92. .hw_params = speyside_wm8962_hw_params,
  93. };
  94. static struct snd_soc_dai_link speyside_wm8962_dai[] = {
  95. {
  96. .name = "CPU",
  97. .stream_name = "CPU",
  98. .cpu_dai_name = "samsung-i2s.0",
  99. .codec_dai_name = "wm8962",
  100. .platform_name = "samsung-audio",
  101. .codec_name = "wm8962.1-001a",
  102. .ops = &speyside_wm8962_ops,
  103. },
  104. };
  105. static const struct snd_kcontrol_new controls[] = {
  106. SOC_DAPM_PIN_SWITCH("Main Speaker"),
  107. };
  108. static struct snd_soc_dapm_widget widgets[] = {
  109. SND_SOC_DAPM_HP("Headphone", NULL),
  110. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  111. SND_SOC_DAPM_MIC("DMIC", NULL),
  112. SND_SOC_DAPM_SPK("Main Speaker", NULL),
  113. };
  114. static struct snd_soc_dapm_route audio_paths[] = {
  115. { "Headphone", NULL, "HPOUTL" },
  116. { "Headphone", NULL, "HPOUTR" },
  117. { "Main Speaker", NULL, "SPKOUTL" },
  118. { "Main Speaker", NULL, "SPKOUTR" },
  119. { "MICBIAS", NULL, "Headset Mic" },
  120. { "IN4L", NULL, "MICBIAS" },
  121. { "IN4R", NULL, "MICBIAS" },
  122. { "MICBIAS", NULL, "DMIC" },
  123. { "DMICDAT", NULL, "MICBIAS" },
  124. };
  125. static struct snd_soc_jack speyside_wm8962_headset;
  126. /* Headset jack detection DAPM pins */
  127. static struct snd_soc_jack_pin speyside_wm8962_headset_pins[] = {
  128. {
  129. .pin = "Headset Mic",
  130. .mask = SND_JACK_MICROPHONE,
  131. },
  132. {
  133. .pin = "Headphone",
  134. .mask = SND_JACK_MICROPHONE,
  135. },
  136. };
  137. static int speyside_wm8962_late_probe(struct snd_soc_card *card)
  138. {
  139. struct snd_soc_codec *codec = card->rtd[0].codec;
  140. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  141. int ret;
  142. ret = snd_soc_dai_set_sysclk(codec_dai, WM8962_SYSCLK_MCLK,
  143. 32768, SND_SOC_CLOCK_IN);
  144. if (ret < 0)
  145. return ret;
  146. ret = snd_soc_jack_new(codec, "Headset",
  147. SND_JACK_HEADSET | SND_JACK_BTN_0,
  148. &speyside_wm8962_headset);
  149. if (ret)
  150. return ret;
  151. ret = snd_soc_jack_add_pins(&speyside_wm8962_headset,
  152. ARRAY_SIZE(speyside_wm8962_headset_pins),
  153. speyside_wm8962_headset_pins);
  154. if (ret)
  155. return ret;
  156. wm8962_mic_detect(codec, &speyside_wm8962_headset);
  157. return 0;
  158. }
  159. static struct snd_soc_card speyside_wm8962 = {
  160. .name = "Speyside WM8962",
  161. .dai_link = speyside_wm8962_dai,
  162. .num_links = ARRAY_SIZE(speyside_wm8962_dai),
  163. .set_bias_level = speyside_wm8962_set_bias_level,
  164. .set_bias_level_post = speyside_wm8962_set_bias_level_post,
  165. .controls = controls,
  166. .num_controls = ARRAY_SIZE(controls),
  167. .dapm_widgets = widgets,
  168. .num_dapm_widgets = ARRAY_SIZE(widgets),
  169. .dapm_routes = audio_paths,
  170. .num_dapm_routes = ARRAY_SIZE(audio_paths),
  171. .late_probe = speyside_wm8962_late_probe,
  172. };
  173. static __devinit int speyside_wm8962_probe(struct platform_device *pdev)
  174. {
  175. struct snd_soc_card *card = &speyside_wm8962;
  176. int ret;
  177. card->dev = &pdev->dev;
  178. ret = snd_soc_register_card(card);
  179. if (ret) {
  180. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  181. ret);
  182. return ret;
  183. }
  184. return 0;
  185. }
  186. static int __devexit speyside_wm8962_remove(struct platform_device *pdev)
  187. {
  188. struct snd_soc_card *card = platform_get_drvdata(pdev);
  189. snd_soc_unregister_card(card);
  190. return 0;
  191. }
  192. static struct platform_driver speyside_wm8962_driver = {
  193. .driver = {
  194. .name = "speyside-wm8962",
  195. .owner = THIS_MODULE,
  196. .pm = &snd_soc_pm_ops,
  197. },
  198. .probe = speyside_wm8962_probe,
  199. .remove = __devexit_p(speyside_wm8962_remove),
  200. };
  201. static int __init speyside_wm8962_audio_init(void)
  202. {
  203. return platform_driver_register(&speyside_wm8962_driver);
  204. }
  205. module_init(speyside_wm8962_audio_init);
  206. static void __exit speyside_wm8962_audio_exit(void)
  207. {
  208. platform_driver_unregister(&speyside_wm8962_driver);
  209. }
  210. module_exit(speyside_wm8962_audio_exit);
  211. MODULE_DESCRIPTION("Speyside WM8962 audio support");
  212. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  213. MODULE_LICENSE("GPL");
  214. MODULE_ALIAS("platform:speyside-wm8962");