skl_rt286.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. /*
  2. * Intel Skylake I2S Machine Driver
  3. *
  4. * Copyright (C) 2014-2015, Intel Corporation. All rights reserved.
  5. *
  6. * Modified from:
  7. * Intel Broadwell Wildcatpoint SST Audio
  8. *
  9. * Copyright (C) 2013, Intel Corporation. All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License version
  13. * 2 as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <sound/core.h>
  23. #include <sound/pcm.h>
  24. #include <sound/soc.h>
  25. #include <sound/jack.h>
  26. #include <sound/pcm_params.h>
  27. #include "../../codecs/rt286.h"
  28. #include "../../codecs/hdac_hdmi.h"
  29. static struct snd_soc_jack skylake_headset;
  30. struct skl_hdmi_pcm {
  31. struct list_head head;
  32. struct snd_soc_dai *codec_dai;
  33. int device;
  34. };
  35. struct skl_rt286_private {
  36. struct list_head hdmi_pcm_list;
  37. };
  38. enum {
  39. SKL_DPCM_AUDIO_PB = 0,
  40. SKL_DPCM_AUDIO_CP,
  41. SKL_DPCM_AUDIO_REF_CP,
  42. SKL_DPCM_AUDIO_DMIC_CP,
  43. SKL_DPCM_AUDIO_HDMI1_PB,
  44. SKL_DPCM_AUDIO_HDMI2_PB,
  45. SKL_DPCM_AUDIO_HDMI3_PB,
  46. };
  47. /* Headset jack detection DAPM pins */
  48. static struct snd_soc_jack_pin skylake_headset_pins[] = {
  49. {
  50. .pin = "Mic Jack",
  51. .mask = SND_JACK_MICROPHONE,
  52. },
  53. {
  54. .pin = "Headphone Jack",
  55. .mask = SND_JACK_HEADPHONE,
  56. },
  57. };
  58. static const struct snd_kcontrol_new skylake_controls[] = {
  59. SOC_DAPM_PIN_SWITCH("Speaker"),
  60. SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  61. SOC_DAPM_PIN_SWITCH("Mic Jack"),
  62. };
  63. static const struct snd_soc_dapm_widget skylake_widgets[] = {
  64. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  65. SND_SOC_DAPM_SPK("Speaker", NULL),
  66. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  67. SND_SOC_DAPM_MIC("DMIC2", NULL),
  68. SND_SOC_DAPM_MIC("SoC DMIC", NULL),
  69. SND_SOC_DAPM_SPK("HDMI1", NULL),
  70. SND_SOC_DAPM_SPK("HDMI2", NULL),
  71. SND_SOC_DAPM_SPK("HDMI3", NULL),
  72. };
  73. static const struct snd_soc_dapm_route skylake_rt286_map[] = {
  74. /* speaker */
  75. {"Speaker", NULL, "SPOR"},
  76. {"Speaker", NULL, "SPOL"},
  77. /* HP jack connectors - unknown if we have jack deteck */
  78. {"Headphone Jack", NULL, "HPO Pin"},
  79. /* other jacks */
  80. {"MIC1", NULL, "Mic Jack"},
  81. /* digital mics */
  82. {"DMIC1 Pin", NULL, "DMIC2"},
  83. {"DMic", NULL, "SoC DMIC"},
  84. {"HDMI1", NULL, "hif5 Output"},
  85. {"HDMI2", NULL, "hif6 Output"},
  86. {"HDMI3", NULL, "hif7 Output"},
  87. /* CODEC BE connections */
  88. { "AIF1 Playback", NULL, "ssp0 Tx"},
  89. { "ssp0 Tx", NULL, "codec0_out"},
  90. { "ssp0 Tx", NULL, "codec1_out"},
  91. { "codec0_in", NULL, "ssp0 Rx" },
  92. { "codec1_in", NULL, "ssp0 Rx" },
  93. { "ssp0 Rx", NULL, "AIF1 Capture" },
  94. { "dmic01_hifi", NULL, "DMIC01 Rx" },
  95. { "DMIC01 Rx", NULL, "DMIC AIF" },
  96. { "hifi3", NULL, "iDisp3 Tx"},
  97. { "iDisp3 Tx", NULL, "iDisp3_out"},
  98. { "hifi2", NULL, "iDisp2 Tx"},
  99. { "iDisp2 Tx", NULL, "iDisp2_out"},
  100. { "hifi1", NULL, "iDisp1 Tx"},
  101. { "iDisp1 Tx", NULL, "iDisp1_out"},
  102. };
  103. static int skylake_rt286_fe_init(struct snd_soc_pcm_runtime *rtd)
  104. {
  105. struct snd_soc_dapm_context *dapm;
  106. struct snd_soc_component *component = rtd->cpu_dai->component;
  107. dapm = snd_soc_component_get_dapm(component);
  108. snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
  109. return 0;
  110. }
  111. static int skylake_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
  112. {
  113. struct snd_soc_codec *codec = rtd->codec;
  114. int ret;
  115. ret = snd_soc_card_jack_new(rtd->card, "Headset",
  116. SND_JACK_HEADSET | SND_JACK_BTN_0,
  117. &skylake_headset,
  118. skylake_headset_pins, ARRAY_SIZE(skylake_headset_pins));
  119. if (ret)
  120. return ret;
  121. rt286_mic_detect(codec, &skylake_headset);
  122. snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
  123. return 0;
  124. }
  125. static int skylake_hdmi_init(struct snd_soc_pcm_runtime *rtd)
  126. {
  127. struct skl_rt286_private *ctx = snd_soc_card_get_drvdata(rtd->card);
  128. struct snd_soc_dai *dai = rtd->codec_dai;
  129. struct skl_hdmi_pcm *pcm;
  130. pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
  131. if (!pcm)
  132. return -ENOMEM;
  133. pcm->device = SKL_DPCM_AUDIO_HDMI1_PB + dai->id;
  134. pcm->codec_dai = dai;
  135. list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
  136. return 0;
  137. }
  138. static unsigned int rates[] = {
  139. 48000,
  140. };
  141. static struct snd_pcm_hw_constraint_list constraints_rates = {
  142. .count = ARRAY_SIZE(rates),
  143. .list = rates,
  144. .mask = 0,
  145. };
  146. static unsigned int channels[] = {
  147. 2,
  148. };
  149. static struct snd_pcm_hw_constraint_list constraints_channels = {
  150. .count = ARRAY_SIZE(channels),
  151. .list = channels,
  152. .mask = 0,
  153. };
  154. static int skl_fe_startup(struct snd_pcm_substream *substream)
  155. {
  156. struct snd_pcm_runtime *runtime = substream->runtime;
  157. /*
  158. * on this platform for PCM device we support,
  159. * 48Khz
  160. * stereo
  161. * 16 bit audio
  162. */
  163. runtime->hw.channels_max = 2;
  164. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  165. &constraints_channels);
  166. runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
  167. snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
  168. snd_pcm_hw_constraint_list(runtime, 0,
  169. SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
  170. return 0;
  171. }
  172. static const struct snd_soc_ops skylake_rt286_fe_ops = {
  173. .startup = skl_fe_startup,
  174. };
  175. static int skylake_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
  176. struct snd_pcm_hw_params *params)
  177. {
  178. struct snd_interval *rate = hw_param_interval(params,
  179. SNDRV_PCM_HW_PARAM_RATE);
  180. struct snd_interval *channels = hw_param_interval(params,
  181. SNDRV_PCM_HW_PARAM_CHANNELS);
  182. struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
  183. /* The output is 48KHz, stereo, 16bits */
  184. rate->min = rate->max = 48000;
  185. channels->min = channels->max = 2;
  186. /* set SSP0 to 24 bit */
  187. snd_mask_none(fmt);
  188. snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
  189. return 0;
  190. }
  191. static int skylake_rt286_hw_params(struct snd_pcm_substream *substream,
  192. struct snd_pcm_hw_params *params)
  193. {
  194. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  195. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  196. int ret;
  197. ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
  198. SND_SOC_CLOCK_IN);
  199. if (ret < 0)
  200. dev_err(rtd->dev, "set codec sysclk failed: %d\n", ret);
  201. return ret;
  202. }
  203. static struct snd_soc_ops skylake_rt286_ops = {
  204. .hw_params = skylake_rt286_hw_params,
  205. };
  206. static int skylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
  207. struct snd_pcm_hw_params *params)
  208. {
  209. struct snd_interval *channels = hw_param_interval(params,
  210. SNDRV_PCM_HW_PARAM_CHANNELS);
  211. if (params_channels(params) == 2)
  212. channels->min = channels->max = 2;
  213. else
  214. channels->min = channels->max = 4;
  215. return 0;
  216. }
  217. static unsigned int channels_dmic[] = {
  218. 2, 4,
  219. };
  220. static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
  221. .count = ARRAY_SIZE(channels_dmic),
  222. .list = channels_dmic,
  223. .mask = 0,
  224. };
  225. static int skylake_dmic_startup(struct snd_pcm_substream *substream)
  226. {
  227. struct snd_pcm_runtime *runtime = substream->runtime;
  228. runtime->hw.channels_max = 4;
  229. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  230. &constraints_dmic_channels);
  231. return snd_pcm_hw_constraint_list(substream->runtime, 0,
  232. SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
  233. }
  234. static struct snd_soc_ops skylake_dmic_ops = {
  235. .startup = skylake_dmic_startup,
  236. };
  237. /* skylake digital audio interface glue - connects codec <--> CPU */
  238. static struct snd_soc_dai_link skylake_rt286_dais[] = {
  239. /* Front End DAI links */
  240. [SKL_DPCM_AUDIO_PB] = {
  241. .name = "Skl Audio Port",
  242. .stream_name = "Audio",
  243. .cpu_dai_name = "System Pin",
  244. .platform_name = "0000:00:1f.3",
  245. .nonatomic = 1,
  246. .dynamic = 1,
  247. .codec_name = "snd-soc-dummy",
  248. .codec_dai_name = "snd-soc-dummy-dai",
  249. .init = skylake_rt286_fe_init,
  250. .trigger = {
  251. SND_SOC_DPCM_TRIGGER_POST,
  252. SND_SOC_DPCM_TRIGGER_POST
  253. },
  254. .dpcm_playback = 1,
  255. .ops = &skylake_rt286_fe_ops,
  256. },
  257. [SKL_DPCM_AUDIO_CP] = {
  258. .name = "Skl Audio Capture Port",
  259. .stream_name = "Audio Record",
  260. .cpu_dai_name = "System Pin",
  261. .platform_name = "0000:00:1f.3",
  262. .nonatomic = 1,
  263. .dynamic = 1,
  264. .codec_name = "snd-soc-dummy",
  265. .codec_dai_name = "snd-soc-dummy-dai",
  266. .trigger = {
  267. SND_SOC_DPCM_TRIGGER_POST,
  268. SND_SOC_DPCM_TRIGGER_POST
  269. },
  270. .dpcm_capture = 1,
  271. .ops = &skylake_rt286_fe_ops,
  272. },
  273. [SKL_DPCM_AUDIO_REF_CP] = {
  274. .name = "Skl Audio Reference cap",
  275. .stream_name = "refcap",
  276. .cpu_dai_name = "Reference Pin",
  277. .codec_name = "snd-soc-dummy",
  278. .codec_dai_name = "snd-soc-dummy-dai",
  279. .platform_name = "0000:00:1f.3",
  280. .init = NULL,
  281. .dpcm_capture = 1,
  282. .nonatomic = 1,
  283. .dynamic = 1,
  284. },
  285. [SKL_DPCM_AUDIO_DMIC_CP] = {
  286. .name = "Skl Audio DMIC cap",
  287. .stream_name = "dmiccap",
  288. .cpu_dai_name = "DMIC Pin",
  289. .codec_name = "snd-soc-dummy",
  290. .codec_dai_name = "snd-soc-dummy-dai",
  291. .platform_name = "0000:00:1f.3",
  292. .init = NULL,
  293. .dpcm_capture = 1,
  294. .nonatomic = 1,
  295. .dynamic = 1,
  296. .ops = &skylake_dmic_ops,
  297. },
  298. [SKL_DPCM_AUDIO_HDMI1_PB] = {
  299. .name = "Skl HDMI Port1",
  300. .stream_name = "Hdmi1",
  301. .cpu_dai_name = "HDMI1 Pin",
  302. .codec_name = "snd-soc-dummy",
  303. .codec_dai_name = "snd-soc-dummy-dai",
  304. .platform_name = "0000:00:1f.3",
  305. .dpcm_playback = 1,
  306. .init = NULL,
  307. .nonatomic = 1,
  308. .dynamic = 1,
  309. },
  310. [SKL_DPCM_AUDIO_HDMI2_PB] = {
  311. .name = "Skl HDMI Port2",
  312. .stream_name = "Hdmi2",
  313. .cpu_dai_name = "HDMI2 Pin",
  314. .codec_name = "snd-soc-dummy",
  315. .codec_dai_name = "snd-soc-dummy-dai",
  316. .platform_name = "0000:00:1f.3",
  317. .dpcm_playback = 1,
  318. .init = NULL,
  319. .nonatomic = 1,
  320. .dynamic = 1,
  321. },
  322. [SKL_DPCM_AUDIO_HDMI3_PB] = {
  323. .name = "Skl HDMI Port3",
  324. .stream_name = "Hdmi3",
  325. .cpu_dai_name = "HDMI3 Pin",
  326. .codec_name = "snd-soc-dummy",
  327. .codec_dai_name = "snd-soc-dummy-dai",
  328. .platform_name = "0000:00:1f.3",
  329. .dpcm_playback = 1,
  330. .init = NULL,
  331. .nonatomic = 1,
  332. .dynamic = 1,
  333. },
  334. /* Back End DAI links */
  335. {
  336. /* SSP0 - Codec */
  337. .name = "SSP0-Codec",
  338. .id = 0,
  339. .cpu_dai_name = "SSP0 Pin",
  340. .platform_name = "0000:00:1f.3",
  341. .no_pcm = 1,
  342. .codec_name = "i2c-INT343A:00",
  343. .codec_dai_name = "rt286-aif1",
  344. .init = skylake_rt286_codec_init,
  345. .dai_fmt = SND_SOC_DAIFMT_I2S |
  346. SND_SOC_DAIFMT_NB_NF |
  347. SND_SOC_DAIFMT_CBS_CFS,
  348. .ignore_pmdown_time = 1,
  349. .be_hw_params_fixup = skylake_ssp0_fixup,
  350. .ops = &skylake_rt286_ops,
  351. .dpcm_playback = 1,
  352. .dpcm_capture = 1,
  353. },
  354. {
  355. .name = "dmic01",
  356. .id = 1,
  357. .cpu_dai_name = "DMIC01 Pin",
  358. .codec_name = "dmic-codec",
  359. .codec_dai_name = "dmic-hifi",
  360. .platform_name = "0000:00:1f.3",
  361. .be_hw_params_fixup = skylake_dmic_fixup,
  362. .ignore_suspend = 1,
  363. .dpcm_capture = 1,
  364. .no_pcm = 1,
  365. },
  366. {
  367. .name = "iDisp1",
  368. .id = 2,
  369. .cpu_dai_name = "iDisp1 Pin",
  370. .codec_name = "ehdaudio0D2",
  371. .codec_dai_name = "intel-hdmi-hifi1",
  372. .platform_name = "0000:00:1f.3",
  373. .init = skylake_hdmi_init,
  374. .dpcm_playback = 1,
  375. .no_pcm = 1,
  376. },
  377. {
  378. .name = "iDisp2",
  379. .id = 3,
  380. .cpu_dai_name = "iDisp2 Pin",
  381. .codec_name = "ehdaudio0D2",
  382. .codec_dai_name = "intel-hdmi-hifi2",
  383. .platform_name = "0000:00:1f.3",
  384. .init = skylake_hdmi_init,
  385. .dpcm_playback = 1,
  386. .no_pcm = 1,
  387. },
  388. {
  389. .name = "iDisp3",
  390. .id = 4,
  391. .cpu_dai_name = "iDisp3 Pin",
  392. .codec_name = "ehdaudio0D2",
  393. .codec_dai_name = "intel-hdmi-hifi3",
  394. .platform_name = "0000:00:1f.3",
  395. .init = skylake_hdmi_init,
  396. .dpcm_playback = 1,
  397. .no_pcm = 1,
  398. },
  399. };
  400. static int skylake_card_late_probe(struct snd_soc_card *card)
  401. {
  402. struct skl_rt286_private *ctx = snd_soc_card_get_drvdata(card);
  403. struct skl_hdmi_pcm *pcm;
  404. int err;
  405. list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
  406. err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device);
  407. if (err < 0)
  408. return err;
  409. }
  410. return 0;
  411. }
  412. /* skylake audio machine driver for SPT + RT286S */
  413. static struct snd_soc_card skylake_rt286 = {
  414. .name = "skylake-rt286",
  415. .owner = THIS_MODULE,
  416. .dai_link = skylake_rt286_dais,
  417. .num_links = ARRAY_SIZE(skylake_rt286_dais),
  418. .controls = skylake_controls,
  419. .num_controls = ARRAY_SIZE(skylake_controls),
  420. .dapm_widgets = skylake_widgets,
  421. .num_dapm_widgets = ARRAY_SIZE(skylake_widgets),
  422. .dapm_routes = skylake_rt286_map,
  423. .num_dapm_routes = ARRAY_SIZE(skylake_rt286_map),
  424. .fully_routed = true,
  425. .late_probe = skylake_card_late_probe,
  426. };
  427. static int skylake_audio_probe(struct platform_device *pdev)
  428. {
  429. struct skl_rt286_private *ctx;
  430. ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
  431. if (!ctx)
  432. return -ENOMEM;
  433. INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
  434. skylake_rt286.dev = &pdev->dev;
  435. snd_soc_card_set_drvdata(&skylake_rt286, ctx);
  436. return devm_snd_soc_register_card(&pdev->dev, &skylake_rt286);
  437. }
  438. static const struct platform_device_id skl_board_ids[] = {
  439. { .name = "skl_alc286s_i2s" },
  440. { .name = "kbl_alc286s_i2s" },
  441. { }
  442. };
  443. static struct platform_driver skylake_audio = {
  444. .probe = skylake_audio_probe,
  445. .driver = {
  446. .name = "skl_alc286s_i2s",
  447. .pm = &snd_soc_pm_ops,
  448. },
  449. .id_table = skl_board_ids,
  450. };
  451. module_platform_driver(skylake_audio)
  452. /* Module information */
  453. MODULE_AUTHOR("Omair Mohammed Abdullah <omair.m.abdullah@intel.com>");
  454. MODULE_DESCRIPTION("Intel SST Audio for Skylake");
  455. MODULE_LICENSE("GPL v2");
  456. MODULE_ALIAS("platform:skl_alc286s_i2s");
  457. MODULE_ALIAS("platform:kbl_alc286s_i2s");