speyside_wm8962.c 6.2 KB

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