speyside.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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 <sound/jack.h>
  14. #include <linux/gpio.h>
  15. #include "../codecs/wm8915.h"
  16. #include "../codecs/wm9081.h"
  17. #define WM8915_HPSEL_GPIO 214
  18. static int speyside_set_bias_level(struct snd_soc_card *card,
  19. enum snd_soc_bias_level level)
  20. {
  21. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  22. int ret;
  23. switch (level) {
  24. case SND_SOC_BIAS_STANDBY:
  25. ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK1,
  26. 32768, SND_SOC_CLOCK_IN);
  27. if (ret < 0)
  28. return ret;
  29. ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK1,
  30. 0, 0, 0);
  31. if (ret < 0) {
  32. pr_err("Failed to stop FLL\n");
  33. return ret;
  34. }
  35. default:
  36. break;
  37. }
  38. return 0;
  39. }
  40. static int speyside_hw_params(struct snd_pcm_substream *substream,
  41. struct snd_pcm_hw_params *params)
  42. {
  43. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  44. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  45. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  46. int ret;
  47. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  48. | SND_SOC_DAIFMT_NB_NF
  49. | SND_SOC_DAIFMT_CBM_CFM);
  50. if (ret < 0)
  51. return ret;
  52. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  53. | SND_SOC_DAIFMT_NB_NF
  54. | SND_SOC_DAIFMT_CBM_CFM);
  55. if (ret < 0)
  56. return ret;
  57. ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK1,
  58. 32768, 256 * 48000);
  59. if (ret < 0)
  60. return ret;
  61. ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_FLL,
  62. 256 * 48000, SND_SOC_CLOCK_IN);
  63. if (ret < 0)
  64. return ret;
  65. return 0;
  66. }
  67. static struct snd_soc_ops speyside_ops = {
  68. .hw_params = speyside_hw_params,
  69. };
  70. static struct snd_soc_jack speyside_headset;
  71. /* Headset jack detection DAPM pins */
  72. static struct snd_soc_jack_pin speyside_headset_pins[] = {
  73. {
  74. .pin = "Headset Mic",
  75. .mask = SND_JACK_MICROPHONE,
  76. },
  77. {
  78. .pin = "Headphone",
  79. .mask = SND_JACK_HEADPHONE,
  80. },
  81. };
  82. /* Default the headphone selection to active high */
  83. static int speyside_jack_polarity;
  84. static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
  85. struct snd_soc_dapm_widget *sink)
  86. {
  87. if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
  88. return 1;
  89. if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
  90. return 1;
  91. return 0;
  92. }
  93. static void speyside_set_polarity(struct snd_soc_codec *codec,
  94. int polarity)
  95. {
  96. speyside_jack_polarity = !polarity;
  97. gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
  98. /* Re-run DAPM to make sure we're using the correct mic bias */
  99. snd_soc_dapm_sync(&codec->dapm);
  100. }
  101. static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
  102. {
  103. struct snd_soc_dai *dai = rtd->codec_dai;
  104. struct snd_soc_codec *codec = rtd->codec;
  105. int ret;
  106. ret = snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0);
  107. if (ret < 0)
  108. return ret;
  109. ret = gpio_request(WM8915_HPSEL_GPIO, "HP_SEL");
  110. if (ret != 0)
  111. pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
  112. gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
  113. ret = snd_soc_jack_new(codec, "Headset",
  114. SND_JACK_HEADSET | SND_JACK_BTN_0,
  115. &speyside_headset);
  116. if (ret)
  117. return ret;
  118. ret = snd_soc_jack_add_pins(&speyside_headset,
  119. ARRAY_SIZE(speyside_headset_pins),
  120. speyside_headset_pins);
  121. if (ret)
  122. return ret;
  123. wm8915_detect(codec, &speyside_headset, speyside_set_polarity);
  124. return 0;
  125. }
  126. static int speyside_late_probe(struct snd_soc_card *card)
  127. {
  128. snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
  129. snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
  130. snd_soc_dapm_ignore_suspend(&card->dapm, "Main AMIC");
  131. snd_soc_dapm_ignore_suspend(&card->dapm, "Main DMIC");
  132. snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
  133. snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output");
  134. snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input");
  135. return 0;
  136. }
  137. static struct snd_soc_dai_link speyside_dai[] = {
  138. {
  139. .name = "CPU",
  140. .stream_name = "CPU",
  141. .cpu_dai_name = "samsung-i2s.0",
  142. .codec_dai_name = "wm8915-aif1",
  143. .platform_name = "samsung-audio",
  144. .codec_name = "wm8915.1-001a",
  145. .init = speyside_wm8915_init,
  146. .ops = &speyside_ops,
  147. },
  148. {
  149. .name = "Baseband",
  150. .stream_name = "Baseband",
  151. .cpu_dai_name = "wm8915-aif2",
  152. .codec_dai_name = "wm1250-ev1",
  153. .codec_name = "wm1250-ev1.1-0027",
  154. .ops = &speyside_ops,
  155. .ignore_suspend = 1,
  156. },
  157. };
  158. static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
  159. {
  160. snd_soc_dapm_nc_pin(dapm, "LINEOUT");
  161. /* At any time the WM9081 is active it will have this clock */
  162. return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK,
  163. 48000 * 256, 0);
  164. }
  165. static struct snd_soc_aux_dev speyside_aux_dev[] = {
  166. {
  167. .name = "wm9081",
  168. .codec_name = "wm9081.1-006c",
  169. .init = speyside_wm9081_init,
  170. },
  171. };
  172. static struct snd_soc_codec_conf speyside_codec_conf[] = {
  173. {
  174. .dev_name = "wm9081.1-006c",
  175. .name_prefix = "Sub",
  176. },
  177. };
  178. static const struct snd_kcontrol_new controls[] = {
  179. SOC_DAPM_PIN_SWITCH("Main Speaker"),
  180. SOC_DAPM_PIN_SWITCH("Main DMIC"),
  181. SOC_DAPM_PIN_SWITCH("Main AMIC"),
  182. SOC_DAPM_PIN_SWITCH("WM1250 Input"),
  183. SOC_DAPM_PIN_SWITCH("WM1250 Output"),
  184. };
  185. static struct snd_soc_dapm_widget widgets[] = {
  186. SND_SOC_DAPM_HP("Headphone", NULL),
  187. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  188. SND_SOC_DAPM_SPK("Main Speaker", NULL),
  189. SND_SOC_DAPM_MIC("Main AMIC", NULL),
  190. SND_SOC_DAPM_MIC("Main DMIC", NULL),
  191. };
  192. static struct snd_soc_dapm_route audio_paths[] = {
  193. { "IN1RN", NULL, "MICB1" },
  194. { "IN1RP", NULL, "MICB1" },
  195. { "IN1RN", NULL, "MICB2" },
  196. { "IN1RP", NULL, "MICB2" },
  197. { "MICB1", NULL, "Headset Mic", speyside_get_micbias },
  198. { "MICB2", NULL, "Headset Mic", speyside_get_micbias },
  199. { "IN1LP", NULL, "MICB2" },
  200. { "IN1RN", NULL, "MICB1" },
  201. { "MICB2", NULL, "Main AMIC" },
  202. { "DMIC1DAT", NULL, "MICB1" },
  203. { "DMIC2DAT", NULL, "MICB1" },
  204. { "MICB1", NULL, "Main DMIC" },
  205. { "Headphone", NULL, "HPOUT1L" },
  206. { "Headphone", NULL, "HPOUT1R" },
  207. { "Sub IN1", NULL, "HPOUT2L" },
  208. { "Sub IN2", NULL, "HPOUT2R" },
  209. { "Main Speaker", NULL, "Sub SPKN" },
  210. { "Main Speaker", NULL, "Sub SPKP" },
  211. { "Main Speaker", NULL, "SPKDAT" },
  212. };
  213. static struct snd_soc_card speyside = {
  214. .name = "Speyside",
  215. .dai_link = speyside_dai,
  216. .num_links = ARRAY_SIZE(speyside_dai),
  217. .aux_dev = speyside_aux_dev,
  218. .num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
  219. .codec_conf = speyside_codec_conf,
  220. .num_configs = ARRAY_SIZE(speyside_codec_conf),
  221. .set_bias_level = speyside_set_bias_level,
  222. .controls = controls,
  223. .num_controls = ARRAY_SIZE(controls),
  224. .dapm_widgets = widgets,
  225. .num_dapm_widgets = ARRAY_SIZE(widgets),
  226. .dapm_routes = audio_paths,
  227. .num_dapm_routes = ARRAY_SIZE(audio_paths),
  228. .late_probe = speyside_late_probe,
  229. };
  230. static __devinit int speyside_probe(struct platform_device *pdev)
  231. {
  232. struct snd_soc_card *card = &speyside;
  233. int ret;
  234. card->dev = &pdev->dev;
  235. ret = snd_soc_register_card(card);
  236. if (ret) {
  237. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  238. ret);
  239. return ret;
  240. }
  241. return 0;
  242. }
  243. static int __devexit speyside_remove(struct platform_device *pdev)
  244. {
  245. struct snd_soc_card *card = platform_get_drvdata(pdev);
  246. snd_soc_unregister_card(card);
  247. return 0;
  248. }
  249. static struct platform_driver speyside_driver = {
  250. .driver = {
  251. .name = "speyside",
  252. .owner = THIS_MODULE,
  253. .pm = &snd_soc_pm_ops,
  254. },
  255. .probe = speyside_probe,
  256. .remove = __devexit_p(speyside_remove),
  257. };
  258. static int __init speyside_audio_init(void)
  259. {
  260. return platform_driver_register(&speyside_driver);
  261. }
  262. module_init(speyside_audio_init);
  263. static void __exit speyside_audio_exit(void)
  264. {
  265. platform_driver_unregister(&speyside_driver);
  266. }
  267. module_exit(speyside_audio_exit);
  268. MODULE_DESCRIPTION("Speyside audio support");
  269. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  270. MODULE_LICENSE("GPL");
  271. MODULE_ALIAS("platform:speyside");