skl_rt286.c 14 KB

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