broadwell.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Intel Broadwell Wildcatpoint SST Audio
  3. *
  4. * Copyright (C) 2013, Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/platform_device.h>
  18. #include <sound/core.h>
  19. #include <sound/pcm.h>
  20. #include <sound/soc.h>
  21. #include <sound/jack.h>
  22. #include <sound/pcm_params.h>
  23. #include "../common/sst-dsp.h"
  24. #include "../haswell/sst-haswell-ipc.h"
  25. #include "../../codecs/rt286.h"
  26. static struct snd_soc_jack broadwell_headset;
  27. /* Headset jack detection DAPM pins */
  28. static struct snd_soc_jack_pin broadwell_headset_pins[] = {
  29. {
  30. .pin = "Mic Jack",
  31. .mask = SND_JACK_MICROPHONE,
  32. },
  33. {
  34. .pin = "Headphone Jack",
  35. .mask = SND_JACK_HEADPHONE,
  36. },
  37. };
  38. static const struct snd_kcontrol_new broadwell_controls[] = {
  39. SOC_DAPM_PIN_SWITCH("Speaker"),
  40. SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  41. };
  42. static const struct snd_soc_dapm_widget broadwell_widgets[] = {
  43. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  44. SND_SOC_DAPM_SPK("Speaker", NULL),
  45. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  46. SND_SOC_DAPM_MIC("DMIC1", NULL),
  47. SND_SOC_DAPM_MIC("DMIC2", NULL),
  48. SND_SOC_DAPM_LINE("Line Jack", NULL),
  49. };
  50. static const struct snd_soc_dapm_route broadwell_rt286_map[] = {
  51. /* speaker */
  52. {"Speaker", NULL, "SPOR"},
  53. {"Speaker", NULL, "SPOL"},
  54. /* HP jack connectors - unknown if we have jack deteck */
  55. {"Headphone Jack", NULL, "HPO Pin"},
  56. /* other jacks */
  57. {"MIC1", NULL, "Mic Jack"},
  58. {"LINE1", NULL, "Line Jack"},
  59. /* digital mics */
  60. {"DMIC1 Pin", NULL, "DMIC1"},
  61. {"DMIC2 Pin", NULL, "DMIC2"},
  62. /* CODEC BE connections */
  63. {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
  64. {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
  65. };
  66. static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
  67. {
  68. struct snd_soc_codec *codec = rtd->codec;
  69. int ret = 0;
  70. ret = snd_soc_card_jack_new(rtd->card, "Headset",
  71. SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset,
  72. broadwell_headset_pins, ARRAY_SIZE(broadwell_headset_pins));
  73. if (ret)
  74. return ret;
  75. rt286_mic_detect(codec, &broadwell_headset);
  76. return 0;
  77. }
  78. static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
  79. struct snd_pcm_hw_params *params)
  80. {
  81. struct snd_interval *rate = hw_param_interval(params,
  82. SNDRV_PCM_HW_PARAM_RATE);
  83. struct snd_interval *channels = hw_param_interval(params,
  84. SNDRV_PCM_HW_PARAM_CHANNELS);
  85. /* The ADSP will covert the FE rate to 48k, stereo */
  86. rate->min = rate->max = 48000;
  87. channels->min = channels->max = 2;
  88. /* set SSP0 to 16 bit */
  89. params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
  90. return 0;
  91. }
  92. static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream,
  93. struct snd_pcm_hw_params *params)
  94. {
  95. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  96. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  97. int ret;
  98. ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
  99. SND_SOC_CLOCK_IN);
  100. if (ret < 0) {
  101. dev_err(rtd->dev, "can't set codec sysclk configuration\n");
  102. return ret;
  103. }
  104. return ret;
  105. }
  106. static struct snd_soc_ops broadwell_rt286_ops = {
  107. .hw_params = broadwell_rt286_hw_params,
  108. };
  109. static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
  110. {
  111. struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
  112. struct sst_hsw *broadwell = pdata->dsp;
  113. int ret;
  114. /* Set ADSP SSP port settings */
  115. ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0,
  116. SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
  117. SST_HSW_DEVICE_CLOCK_MASTER, 9);
  118. if (ret < 0) {
  119. dev_err(rtd->dev, "error: failed to set device config\n");
  120. return ret;
  121. }
  122. return 0;
  123. }
  124. /* broadwell digital audio interface glue - connects codec <--> CPU */
  125. static struct snd_soc_dai_link broadwell_rt286_dais[] = {
  126. /* Front End DAI links */
  127. {
  128. .name = "System PCM",
  129. .stream_name = "System Playback/Capture",
  130. .cpu_dai_name = "System Pin",
  131. .platform_name = "haswell-pcm-audio",
  132. .dynamic = 1,
  133. .codec_name = "snd-soc-dummy",
  134. .codec_dai_name = "snd-soc-dummy-dai",
  135. .init = broadwell_rtd_init,
  136. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  137. .dpcm_playback = 1,
  138. .dpcm_capture = 1,
  139. },
  140. {
  141. .name = "Offload0",
  142. .stream_name = "Offload0 Playback",
  143. .cpu_dai_name = "Offload0 Pin",
  144. .platform_name = "haswell-pcm-audio",
  145. .dynamic = 1,
  146. .codec_name = "snd-soc-dummy",
  147. .codec_dai_name = "snd-soc-dummy-dai",
  148. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  149. .dpcm_playback = 1,
  150. },
  151. {
  152. .name = "Offload1",
  153. .stream_name = "Offload1 Playback",
  154. .cpu_dai_name = "Offload1 Pin",
  155. .platform_name = "haswell-pcm-audio",
  156. .dynamic = 1,
  157. .codec_name = "snd-soc-dummy",
  158. .codec_dai_name = "snd-soc-dummy-dai",
  159. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  160. .dpcm_playback = 1,
  161. },
  162. {
  163. .name = "Loopback PCM",
  164. .stream_name = "Loopback",
  165. .cpu_dai_name = "Loopback Pin",
  166. .platform_name = "haswell-pcm-audio",
  167. .dynamic = 1,
  168. .codec_name = "snd-soc-dummy",
  169. .codec_dai_name = "snd-soc-dummy-dai",
  170. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  171. .dpcm_capture = 1,
  172. },
  173. /* Back End DAI links */
  174. {
  175. /* SSP0 - Codec */
  176. .name = "Codec",
  177. .be_id = 0,
  178. .cpu_dai_name = "snd-soc-dummy-dai",
  179. .platform_name = "snd-soc-dummy",
  180. .no_pcm = 1,
  181. .codec_name = "i2c-INT343A:00",
  182. .codec_dai_name = "rt286-aif1",
  183. .init = broadwell_rt286_codec_init,
  184. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  185. SND_SOC_DAIFMT_CBS_CFS,
  186. .ignore_suspend = 1,
  187. .ignore_pmdown_time = 1,
  188. .be_hw_params_fixup = broadwell_ssp0_fixup,
  189. .ops = &broadwell_rt286_ops,
  190. .dpcm_playback = 1,
  191. .dpcm_capture = 1,
  192. },
  193. };
  194. static int broadwell_suspend(struct snd_soc_card *card){
  195. struct snd_soc_codec *codec;
  196. list_for_each_entry(codec, &card->codec_dev_list, card_list) {
  197. if (!strcmp(codec->component.name, "i2c-INT343A:00")) {
  198. dev_dbg(codec->dev, "disabling jack detect before going to suspend.\n");
  199. rt286_mic_detect(codec, NULL);
  200. break;
  201. }
  202. }
  203. return 0;
  204. }
  205. static int broadwell_resume(struct snd_soc_card *card){
  206. struct snd_soc_codec *codec;
  207. list_for_each_entry(codec, &card->codec_dev_list, card_list) {
  208. if (!strcmp(codec->component.name, "i2c-INT343A:00")) {
  209. dev_dbg(codec->dev, "enabling jack detect for resume.\n");
  210. rt286_mic_detect(codec, &broadwell_headset);
  211. break;
  212. }
  213. }
  214. return 0;
  215. }
  216. /* broadwell audio machine driver for WPT + RT286S */
  217. static struct snd_soc_card broadwell_rt286 = {
  218. .name = "broadwell-rt286",
  219. .owner = THIS_MODULE,
  220. .dai_link = broadwell_rt286_dais,
  221. .num_links = ARRAY_SIZE(broadwell_rt286_dais),
  222. .controls = broadwell_controls,
  223. .num_controls = ARRAY_SIZE(broadwell_controls),
  224. .dapm_widgets = broadwell_widgets,
  225. .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets),
  226. .dapm_routes = broadwell_rt286_map,
  227. .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map),
  228. .fully_routed = true,
  229. .suspend_pre = broadwell_suspend,
  230. .resume_post = broadwell_resume,
  231. };
  232. static int broadwell_audio_probe(struct platform_device *pdev)
  233. {
  234. broadwell_rt286.dev = &pdev->dev;
  235. return devm_snd_soc_register_card(&pdev->dev, &broadwell_rt286);
  236. }
  237. static struct platform_driver broadwell_audio = {
  238. .probe = broadwell_audio_probe,
  239. .driver = {
  240. .name = "broadwell-audio",
  241. },
  242. };
  243. module_platform_driver(broadwell_audio)
  244. /* Module information */
  245. MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
  246. MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell");
  247. MODULE_LICENSE("GPL v2");
  248. MODULE_ALIAS("platform:broadwell-audio");