speyside.c 8.6 KB

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