kbl_rt5663_max98927.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. /*
  2. * Intel Kabylake I2S Machine Driver with MAXIM98927
  3. * and RT5663 Codecs
  4. *
  5. * Copyright (C) 2017, Intel Corporation. All rights reserved.
  6. *
  7. * Modified from:
  8. * Intel Skylake I2S Machine driver
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License version
  12. * 2 as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/input.h>
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <sound/core.h>
  23. #include <sound/jack.h>
  24. #include <sound/pcm.h>
  25. #include <sound/pcm_params.h>
  26. #include <sound/soc.h>
  27. #include "../../codecs/rt5663.h"
  28. #include "../../codecs/hdac_hdmi.h"
  29. #include "../skylake/skl.h"
  30. #include <linux/clk.h>
  31. #include <linux/clk-provider.h>
  32. #include <linux/clkdev.h>
  33. #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
  34. #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
  35. #define DMIC_CH(p) p->list[p->count-1]
  36. #define MAXIM_DEV0_NAME "i2c-MX98927:00"
  37. #define MAXIM_DEV1_NAME "i2c-MX98927:01"
  38. static struct snd_soc_card *kabylake_audio_card;
  39. static const struct snd_pcm_hw_constraint_list *dmic_constraints;
  40. static struct snd_soc_jack skylake_hdmi[3];
  41. struct kbl_hdmi_pcm {
  42. struct list_head head;
  43. struct snd_soc_dai *codec_dai;
  44. int device;
  45. };
  46. struct kbl_rt5663_private {
  47. struct snd_soc_jack kabylake_headset;
  48. struct list_head hdmi_pcm_list;
  49. struct clk *mclk;
  50. struct clk *sclk;
  51. };
  52. enum {
  53. KBL_DPCM_AUDIO_PB = 0,
  54. KBL_DPCM_AUDIO_CP,
  55. KBL_DPCM_AUDIO_HS_PB,
  56. KBL_DPCM_AUDIO_ECHO_REF_CP,
  57. KBL_DPCM_AUDIO_REF_CP,
  58. KBL_DPCM_AUDIO_DMIC_CP,
  59. KBL_DPCM_AUDIO_HDMI1_PB,
  60. KBL_DPCM_AUDIO_HDMI2_PB,
  61. KBL_DPCM_AUDIO_HDMI3_PB,
  62. };
  63. static const struct snd_kcontrol_new kabylake_controls[] = {
  64. SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  65. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  66. SOC_DAPM_PIN_SWITCH("Left Spk"),
  67. SOC_DAPM_PIN_SWITCH("Right Spk"),
  68. };
  69. static int platform_clock_control(struct snd_soc_dapm_widget *w,
  70. struct snd_kcontrol *k, int event)
  71. {
  72. struct snd_soc_dapm_context *dapm = w->dapm;
  73. struct snd_soc_card *card = dapm->card;
  74. struct kbl_rt5663_private *priv = snd_soc_card_get_drvdata(card);
  75. int ret = 0;
  76. /*
  77. * MCLK/SCLK need to be ON early for a successful synchronization of
  78. * codec internal clock. And the clocks are turned off during
  79. * POST_PMD after the stream is stopped.
  80. */
  81. switch (event) {
  82. case SND_SOC_DAPM_PRE_PMU:
  83. /* Enable MCLK */
  84. ret = clk_set_rate(priv->mclk, 24000000);
  85. if (ret < 0) {
  86. dev_err(card->dev, "Can't set rate for mclk, err: %d\n",
  87. ret);
  88. return ret;
  89. }
  90. ret = clk_prepare_enable(priv->mclk);
  91. if (ret < 0) {
  92. dev_err(card->dev, "Can't enable mclk, err: %d\n", ret);
  93. return ret;
  94. }
  95. /* Enable SCLK */
  96. ret = clk_set_rate(priv->sclk, 3072000);
  97. if (ret < 0) {
  98. dev_err(card->dev, "Can't set rate for sclk, err: %d\n",
  99. ret);
  100. clk_disable_unprepare(priv->mclk);
  101. return ret;
  102. }
  103. ret = clk_prepare_enable(priv->sclk);
  104. if (ret < 0) {
  105. dev_err(card->dev, "Can't enable sclk, err: %d\n", ret);
  106. clk_disable_unprepare(priv->mclk);
  107. }
  108. break;
  109. case SND_SOC_DAPM_POST_PMD:
  110. clk_disable_unprepare(priv->mclk);
  111. clk_disable_unprepare(priv->sclk);
  112. break;
  113. default:
  114. return 0;
  115. }
  116. return 0;
  117. }
  118. static const struct snd_soc_dapm_widget kabylake_widgets[] = {
  119. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  120. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  121. SND_SOC_DAPM_SPK("Left Spk", NULL),
  122. SND_SOC_DAPM_SPK("Right Spk", NULL),
  123. SND_SOC_DAPM_MIC("SoC DMIC", NULL),
  124. SND_SOC_DAPM_SPK("HDMI1", NULL),
  125. SND_SOC_DAPM_SPK("HDMI2", NULL),
  126. SND_SOC_DAPM_SPK("HDMI3", NULL),
  127. SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
  128. platform_clock_control, SND_SOC_DAPM_PRE_PMU |
  129. SND_SOC_DAPM_POST_PMD),
  130. };
  131. static const struct snd_soc_dapm_route kabylake_map[] = {
  132. /* HP jack connectors - unknown if we have jack detection */
  133. { "Headphone Jack", NULL, "Platform Clock" },
  134. { "Headphone Jack", NULL, "HPOL" },
  135. { "Headphone Jack", NULL, "HPOR" },
  136. /* speaker */
  137. { "Left Spk", NULL, "Left BE_OUT" },
  138. { "Right Spk", NULL, "Right BE_OUT" },
  139. /* other jacks */
  140. { "Headset Mic", NULL, "Platform Clock" },
  141. { "IN1P", NULL, "Headset Mic" },
  142. { "IN1N", NULL, "Headset Mic" },
  143. { "DMic", NULL, "SoC DMIC" },
  144. /* CODEC BE connections */
  145. { "Left HiFi Playback", NULL, "ssp0 Tx" },
  146. { "Right HiFi Playback", NULL, "ssp0 Tx" },
  147. { "ssp0 Tx", NULL, "spk_out" },
  148. { "AIF Playback", NULL, "ssp1 Tx" },
  149. { "ssp1 Tx", NULL, "codec1_out" },
  150. { "hs_in", NULL, "ssp1 Rx" },
  151. { "ssp1 Rx", NULL, "AIF Capture" },
  152. /* IV feedback path */
  153. { "codec0_fb_in", NULL, "ssp0 Rx"},
  154. { "ssp0 Rx", NULL, "Left HiFi Capture" },
  155. { "ssp0 Rx", NULL, "Right HiFi Capture" },
  156. /* DMIC */
  157. { "dmic01_hifi", NULL, "DMIC01 Rx" },
  158. { "DMIC01 Rx", NULL, "DMIC AIF" },
  159. { "hifi3", NULL, "iDisp3 Tx"},
  160. { "iDisp3 Tx", NULL, "iDisp3_out"},
  161. { "hifi2", NULL, "iDisp2 Tx"},
  162. { "iDisp2 Tx", NULL, "iDisp2_out"},
  163. { "hifi1", NULL, "iDisp1 Tx"},
  164. { "iDisp1 Tx", NULL, "iDisp1_out"},
  165. };
  166. enum {
  167. KBL_DPCM_AUDIO_5663_PB = 0,
  168. KBL_DPCM_AUDIO_5663_CP,
  169. KBL_DPCM_AUDIO_5663_HDMI1_PB,
  170. KBL_DPCM_AUDIO_5663_HDMI2_PB,
  171. };
  172. static const struct snd_kcontrol_new kabylake_5663_controls[] = {
  173. SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  174. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  175. };
  176. static const struct snd_soc_dapm_widget kabylake_5663_widgets[] = {
  177. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  178. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  179. SND_SOC_DAPM_SPK("DP", NULL),
  180. SND_SOC_DAPM_SPK("HDMI", NULL),
  181. SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
  182. platform_clock_control, SND_SOC_DAPM_PRE_PMU |
  183. SND_SOC_DAPM_POST_PMD),
  184. };
  185. static const struct snd_soc_dapm_route kabylake_5663_map[] = {
  186. { "Headphone Jack", NULL, "Platform Clock" },
  187. { "Headphone Jack", NULL, "HPOL" },
  188. { "Headphone Jack", NULL, "HPOR" },
  189. /* other jacks */
  190. { "Headset Mic", NULL, "Platform Clock" },
  191. { "IN1P", NULL, "Headset Mic" },
  192. { "IN1N", NULL, "Headset Mic" },
  193. { "HDMI", NULL, "hif5 Output" },
  194. { "DP", NULL, "hif6 Output" },
  195. /* CODEC BE connections */
  196. { "AIF Playback", NULL, "ssp1 Tx" },
  197. { "ssp1 Tx", NULL, "codec1_out" },
  198. { "codec0_in", NULL, "ssp1 Rx" },
  199. { "ssp1 Rx", NULL, "AIF Capture" },
  200. { "hifi2", NULL, "iDisp2 Tx"},
  201. { "iDisp2 Tx", NULL, "iDisp2_out"},
  202. { "hifi1", NULL, "iDisp1 Tx"},
  203. { "iDisp1 Tx", NULL, "iDisp1_out"},
  204. };
  205. static struct snd_soc_codec_conf max98927_codec_conf[] = {
  206. {
  207. .dev_name = MAXIM_DEV0_NAME,
  208. .name_prefix = "Right",
  209. },
  210. {
  211. .dev_name = MAXIM_DEV1_NAME,
  212. .name_prefix = "Left",
  213. },
  214. };
  215. static struct snd_soc_dai_link_component max98927_codec_components[] = {
  216. { /* Left */
  217. .name = MAXIM_DEV0_NAME,
  218. .dai_name = KBL_MAXIM_CODEC_DAI,
  219. },
  220. { /* Right */
  221. .name = MAXIM_DEV1_NAME,
  222. .dai_name = KBL_MAXIM_CODEC_DAI,
  223. },
  224. };
  225. static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
  226. {
  227. int ret;
  228. struct snd_soc_dapm_context *dapm;
  229. struct snd_soc_component *component = rtd->cpu_dai->component;
  230. dapm = snd_soc_component_get_dapm(component);
  231. ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
  232. if (ret) {
  233. dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
  234. return ret;
  235. }
  236. return ret;
  237. }
  238. static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
  239. {
  240. int ret;
  241. struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
  242. struct snd_soc_component *component = rtd->codec_dai->component;
  243. struct snd_soc_jack *jack;
  244. /*
  245. * Headset buttons map to the google Reference headset.
  246. * These can be configured by userspace.
  247. */
  248. ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
  249. SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  250. SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset,
  251. NULL, 0);
  252. if (ret) {
  253. dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
  254. return ret;
  255. }
  256. jack = &ctx->kabylake_headset;
  257. snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
  258. snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
  259. snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
  260. snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
  261. snd_soc_component_set_jack(component, &ctx->kabylake_headset, NULL);
  262. return ret;
  263. }
  264. static int kabylake_rt5663_max98927_codec_init(struct snd_soc_pcm_runtime *rtd)
  265. {
  266. int ret;
  267. ret = kabylake_rt5663_codec_init(rtd);
  268. if (ret)
  269. return ret;
  270. ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
  271. if (ret) {
  272. dev_err(rtd->dev, "SoC DMIC ignore suspend failed %d\n", ret);
  273. return ret;
  274. }
  275. return ret;
  276. }
  277. static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
  278. {
  279. struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
  280. struct snd_soc_dai *dai = rtd->codec_dai;
  281. struct kbl_hdmi_pcm *pcm;
  282. pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
  283. if (!pcm)
  284. return -ENOMEM;
  285. pcm->device = device;
  286. pcm->codec_dai = dai;
  287. list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
  288. return 0;
  289. }
  290. static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
  291. {
  292. return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
  293. }
  294. static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
  295. {
  296. return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
  297. }
  298. static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
  299. {
  300. return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
  301. }
  302. static int kabylake_5663_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
  303. {
  304. return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI1_PB);
  305. }
  306. static int kabylake_5663_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
  307. {
  308. return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI2_PB);
  309. }
  310. static unsigned int rates[] = {
  311. 48000,
  312. };
  313. static const struct snd_pcm_hw_constraint_list constraints_rates = {
  314. .count = ARRAY_SIZE(rates),
  315. .list = rates,
  316. .mask = 0,
  317. };
  318. static unsigned int channels[] = {
  319. 2,
  320. };
  321. static const struct snd_pcm_hw_constraint_list constraints_channels = {
  322. .count = ARRAY_SIZE(channels),
  323. .list = channels,
  324. .mask = 0,
  325. };
  326. static int kbl_fe_startup(struct snd_pcm_substream *substream)
  327. {
  328. struct snd_pcm_runtime *runtime = substream->runtime;
  329. /*
  330. * On this platform for PCM device we support,
  331. * 48Khz
  332. * stereo
  333. * 16 bit audio
  334. */
  335. runtime->hw.channels_max = 2;
  336. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  337. &constraints_channels);
  338. runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
  339. snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
  340. snd_pcm_hw_constraint_list(runtime, 0,
  341. SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
  342. return 0;
  343. }
  344. static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
  345. .startup = kbl_fe_startup,
  346. };
  347. static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
  348. struct snd_pcm_hw_params *params)
  349. {
  350. struct snd_interval *rate = hw_param_interval(params,
  351. SNDRV_PCM_HW_PARAM_RATE);
  352. struct snd_interval *channels = hw_param_interval(params,
  353. SNDRV_PCM_HW_PARAM_CHANNELS);
  354. struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
  355. struct snd_soc_dpcm *dpcm = container_of(
  356. params, struct snd_soc_dpcm, hw_params);
  357. struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
  358. struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
  359. /*
  360. * The ADSP will convert the FE rate to 48k, stereo, 24 bit
  361. */
  362. if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
  363. !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
  364. !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
  365. rate->min = rate->max = 48000;
  366. channels->min = channels->max = 2;
  367. snd_mask_none(fmt);
  368. snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
  369. }
  370. /*
  371. * The speaker on the SSP0 supports S16_LE and not S24_LE.
  372. * thus changing the mask here
  373. */
  374. if (!strcmp(be_dai_link->name, "SSP0-Codec"))
  375. snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
  376. return 0;
  377. }
  378. static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
  379. struct snd_pcm_hw_params *params)
  380. {
  381. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  382. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  383. int ret;
  384. /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
  385. rt5663_sel_asrc_clk_src(codec_dai->component,
  386. RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
  387. RT5663_CLK_SEL_I2S1_ASRC);
  388. ret = snd_soc_dai_set_sysclk(codec_dai,
  389. RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
  390. if (ret < 0)
  391. dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
  392. return ret;
  393. }
  394. static struct snd_soc_ops kabylake_rt5663_ops = {
  395. .hw_params = kabylake_rt5663_hw_params,
  396. };
  397. static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
  398. struct snd_pcm_hw_params *params)
  399. {
  400. struct snd_interval *channels = hw_param_interval(params,
  401. SNDRV_PCM_HW_PARAM_CHANNELS);
  402. if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
  403. channels->min = channels->max = 2;
  404. else
  405. channels->min = channels->max = 4;
  406. return 0;
  407. }
  408. static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
  409. struct snd_pcm_hw_params *params)
  410. {
  411. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  412. int ret = 0, j;
  413. for (j = 0; j < rtd->num_codecs; j++) {
  414. struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
  415. if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
  416. /*
  417. * Use channel 4 and 5 for the first amp
  418. */
  419. ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
  420. if (ret < 0) {
  421. dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
  422. return ret;
  423. }
  424. }
  425. if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
  426. /*
  427. * Use channel 6 and 7 for the second amp
  428. */
  429. ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
  430. if (ret < 0) {
  431. dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
  432. return ret;
  433. }
  434. }
  435. }
  436. return ret;
  437. }
  438. static struct snd_soc_ops kabylake_ssp0_ops = {
  439. .hw_params = kabylake_ssp0_hw_params,
  440. };
  441. static unsigned int channels_dmic[] = {
  442. 2, 4,
  443. };
  444. static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
  445. .count = ARRAY_SIZE(channels_dmic),
  446. .list = channels_dmic,
  447. .mask = 0,
  448. };
  449. static const unsigned int dmic_2ch[] = {
  450. 2,
  451. };
  452. static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
  453. .count = ARRAY_SIZE(dmic_2ch),
  454. .list = dmic_2ch,
  455. .mask = 0,
  456. };
  457. static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
  458. {
  459. struct snd_pcm_runtime *runtime = substream->runtime;
  460. runtime->hw.channels_max = DMIC_CH(dmic_constraints);
  461. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  462. dmic_constraints);
  463. return snd_pcm_hw_constraint_list(substream->runtime, 0,
  464. SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
  465. }
  466. static struct snd_soc_ops kabylake_dmic_ops = {
  467. .startup = kabylake_dmic_startup,
  468. };
  469. static unsigned int rates_16000[] = {
  470. 16000,
  471. };
  472. static const struct snd_pcm_hw_constraint_list constraints_16000 = {
  473. .count = ARRAY_SIZE(rates_16000),
  474. .list = rates_16000,
  475. };
  476. static const unsigned int ch_mono[] = {
  477. 1,
  478. };
  479. static const struct snd_pcm_hw_constraint_list constraints_refcap = {
  480. .count = ARRAY_SIZE(ch_mono),
  481. .list = ch_mono,
  482. };
  483. static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
  484. {
  485. substream->runtime->hw.channels_max = 1;
  486. snd_pcm_hw_constraint_list(substream->runtime, 0,
  487. SNDRV_PCM_HW_PARAM_CHANNELS,
  488. &constraints_refcap);
  489. return snd_pcm_hw_constraint_list(substream->runtime, 0,
  490. SNDRV_PCM_HW_PARAM_RATE,
  491. &constraints_16000);
  492. }
  493. static struct snd_soc_ops skylaye_refcap_ops = {
  494. .startup = kabylake_refcap_startup,
  495. };
  496. /* kabylake digital audio interface glue - connects codec <--> CPU */
  497. static struct snd_soc_dai_link kabylake_dais[] = {
  498. /* Front End DAI links */
  499. [KBL_DPCM_AUDIO_PB] = {
  500. .name = "Kbl Audio Port",
  501. .stream_name = "Audio",
  502. .cpu_dai_name = "System Pin",
  503. .platform_name = "0000:00:1f.3",
  504. .dynamic = 1,
  505. .codec_name = "snd-soc-dummy",
  506. .codec_dai_name = "snd-soc-dummy-dai",
  507. .nonatomic = 1,
  508. .init = kabylake_rt5663_fe_init,
  509. .trigger = {
  510. SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  511. .dpcm_playback = 1,
  512. .ops = &kabylake_rt5663_fe_ops,
  513. },
  514. [KBL_DPCM_AUDIO_CP] = {
  515. .name = "Kbl Audio Capture Port",
  516. .stream_name = "Audio Record",
  517. .cpu_dai_name = "System Pin",
  518. .platform_name = "0000:00:1f.3",
  519. .dynamic = 1,
  520. .codec_name = "snd-soc-dummy",
  521. .codec_dai_name = "snd-soc-dummy-dai",
  522. .nonatomic = 1,
  523. .trigger = {
  524. SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  525. .dpcm_capture = 1,
  526. .ops = &kabylake_rt5663_fe_ops,
  527. },
  528. [KBL_DPCM_AUDIO_HS_PB] = {
  529. .name = "Kbl Audio Headset Playback",
  530. .stream_name = "Headset Audio",
  531. .cpu_dai_name = "System Pin2",
  532. .codec_name = "snd-soc-dummy",
  533. .codec_dai_name = "snd-soc-dummy-dai",
  534. .platform_name = "0000:00:1f.3",
  535. .dpcm_playback = 1,
  536. .nonatomic = 1,
  537. .dynamic = 1,
  538. },
  539. [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
  540. .name = "Kbl Audio Echo Reference cap",
  541. .stream_name = "Echoreference Capture",
  542. .cpu_dai_name = "Echoref Pin",
  543. .codec_name = "snd-soc-dummy",
  544. .codec_dai_name = "snd-soc-dummy-dai",
  545. .platform_name = "0000:00:1f.3",
  546. .init = NULL,
  547. .capture_only = 1,
  548. .nonatomic = 1,
  549. },
  550. [KBL_DPCM_AUDIO_REF_CP] = {
  551. .name = "Kbl Audio Reference cap",
  552. .stream_name = "Wake on Voice",
  553. .cpu_dai_name = "Reference Pin",
  554. .codec_name = "snd-soc-dummy",
  555. .codec_dai_name = "snd-soc-dummy-dai",
  556. .platform_name = "0000:00:1f.3",
  557. .init = NULL,
  558. .dpcm_capture = 1,
  559. .nonatomic = 1,
  560. .dynamic = 1,
  561. .ops = &skylaye_refcap_ops,
  562. },
  563. [KBL_DPCM_AUDIO_DMIC_CP] = {
  564. .name = "Kbl Audio DMIC cap",
  565. .stream_name = "dmiccap",
  566. .cpu_dai_name = "DMIC Pin",
  567. .codec_name = "snd-soc-dummy",
  568. .codec_dai_name = "snd-soc-dummy-dai",
  569. .platform_name = "0000:00:1f.3",
  570. .init = NULL,
  571. .dpcm_capture = 1,
  572. .nonatomic = 1,
  573. .dynamic = 1,
  574. .ops = &kabylake_dmic_ops,
  575. },
  576. [KBL_DPCM_AUDIO_HDMI1_PB] = {
  577. .name = "Kbl HDMI Port1",
  578. .stream_name = "Hdmi1",
  579. .cpu_dai_name = "HDMI1 Pin",
  580. .codec_name = "snd-soc-dummy",
  581. .codec_dai_name = "snd-soc-dummy-dai",
  582. .platform_name = "0000:00:1f.3",
  583. .dpcm_playback = 1,
  584. .init = NULL,
  585. .trigger = {
  586. SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  587. .nonatomic = 1,
  588. .dynamic = 1,
  589. },
  590. [KBL_DPCM_AUDIO_HDMI2_PB] = {
  591. .name = "Kbl HDMI Port2",
  592. .stream_name = "Hdmi2",
  593. .cpu_dai_name = "HDMI2 Pin",
  594. .codec_name = "snd-soc-dummy",
  595. .codec_dai_name = "snd-soc-dummy-dai",
  596. .platform_name = "0000:00:1f.3",
  597. .dpcm_playback = 1,
  598. .init = NULL,
  599. .trigger = {
  600. SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  601. .nonatomic = 1,
  602. .dynamic = 1,
  603. },
  604. [KBL_DPCM_AUDIO_HDMI3_PB] = {
  605. .name = "Kbl HDMI Port3",
  606. .stream_name = "Hdmi3",
  607. .cpu_dai_name = "HDMI3 Pin",
  608. .codec_name = "snd-soc-dummy",
  609. .codec_dai_name = "snd-soc-dummy-dai",
  610. .platform_name = "0000:00:1f.3",
  611. .trigger = {
  612. SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  613. .dpcm_playback = 1,
  614. .init = NULL,
  615. .nonatomic = 1,
  616. .dynamic = 1,
  617. },
  618. /* Back End DAI links */
  619. {
  620. /* SSP0 - Codec */
  621. .name = "SSP0-Codec",
  622. .id = 0,
  623. .cpu_dai_name = "SSP0 Pin",
  624. .platform_name = "0000:00:1f.3",
  625. .no_pcm = 1,
  626. .codecs = max98927_codec_components,
  627. .num_codecs = ARRAY_SIZE(max98927_codec_components),
  628. .dai_fmt = SND_SOC_DAIFMT_DSP_B |
  629. SND_SOC_DAIFMT_NB_NF |
  630. SND_SOC_DAIFMT_CBS_CFS,
  631. .ignore_pmdown_time = 1,
  632. .be_hw_params_fixup = kabylake_ssp_fixup,
  633. .dpcm_playback = 1,
  634. .ops = &kabylake_ssp0_ops,
  635. },
  636. {
  637. /* SSP1 - Codec */
  638. .name = "SSP1-Codec",
  639. .id = 1,
  640. .cpu_dai_name = "SSP1 Pin",
  641. .platform_name = "0000:00:1f.3",
  642. .no_pcm = 1,
  643. .codec_name = "i2c-10EC5663:00",
  644. .codec_dai_name = KBL_REALTEK_CODEC_DAI,
  645. .init = kabylake_rt5663_max98927_codec_init,
  646. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  647. SND_SOC_DAIFMT_CBS_CFS,
  648. .ignore_pmdown_time = 1,
  649. .be_hw_params_fixup = kabylake_ssp_fixup,
  650. .ops = &kabylake_rt5663_ops,
  651. .dpcm_playback = 1,
  652. .dpcm_capture = 1,
  653. },
  654. {
  655. .name = "dmic01",
  656. .id = 2,
  657. .cpu_dai_name = "DMIC01 Pin",
  658. .codec_name = "dmic-codec",
  659. .codec_dai_name = "dmic-hifi",
  660. .platform_name = "0000:00:1f.3",
  661. .be_hw_params_fixup = kabylake_dmic_fixup,
  662. .ignore_suspend = 1,
  663. .dpcm_capture = 1,
  664. .no_pcm = 1,
  665. },
  666. {
  667. .name = "iDisp1",
  668. .id = 3,
  669. .cpu_dai_name = "iDisp1 Pin",
  670. .codec_name = "ehdaudio0D2",
  671. .codec_dai_name = "intel-hdmi-hifi1",
  672. .platform_name = "0000:00:1f.3",
  673. .dpcm_playback = 1,
  674. .init = kabylake_hdmi1_init,
  675. .no_pcm = 1,
  676. },
  677. {
  678. .name = "iDisp2",
  679. .id = 4,
  680. .cpu_dai_name = "iDisp2 Pin",
  681. .codec_name = "ehdaudio0D2",
  682. .codec_dai_name = "intel-hdmi-hifi2",
  683. .platform_name = "0000:00:1f.3",
  684. .init = kabylake_hdmi2_init,
  685. .dpcm_playback = 1,
  686. .no_pcm = 1,
  687. },
  688. {
  689. .name = "iDisp3",
  690. .id = 5,
  691. .cpu_dai_name = "iDisp3 Pin",
  692. .codec_name = "ehdaudio0D2",
  693. .codec_dai_name = "intel-hdmi-hifi3",
  694. .platform_name = "0000:00:1f.3",
  695. .init = kabylake_hdmi3_init,
  696. .dpcm_playback = 1,
  697. .no_pcm = 1,
  698. },
  699. };
  700. static struct snd_soc_dai_link kabylake_5663_dais[] = {
  701. /* Front End DAI links */
  702. [KBL_DPCM_AUDIO_5663_PB] = {
  703. .name = "Kbl Audio Port",
  704. .stream_name = "Audio",
  705. .cpu_dai_name = "System Pin",
  706. .platform_name = "0000:00:1f.3",
  707. .dynamic = 1,
  708. .codec_name = "snd-soc-dummy",
  709. .codec_dai_name = "snd-soc-dummy-dai",
  710. .nonatomic = 1,
  711. .trigger = {
  712. SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  713. .dpcm_playback = 1,
  714. .ops = &kabylake_rt5663_fe_ops,
  715. },
  716. [KBL_DPCM_AUDIO_5663_CP] = {
  717. .name = "Kbl Audio Capture Port",
  718. .stream_name = "Audio Record",
  719. .cpu_dai_name = "System Pin",
  720. .platform_name = "0000:00:1f.3",
  721. .dynamic = 1,
  722. .codec_name = "snd-soc-dummy",
  723. .codec_dai_name = "snd-soc-dummy-dai",
  724. .nonatomic = 1,
  725. .trigger = {
  726. SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  727. .dpcm_capture = 1,
  728. .ops = &kabylake_rt5663_fe_ops,
  729. },
  730. [KBL_DPCM_AUDIO_5663_HDMI1_PB] = {
  731. .name = "Kbl HDMI Port1",
  732. .stream_name = "Hdmi1",
  733. .cpu_dai_name = "HDMI1 Pin",
  734. .codec_name = "snd-soc-dummy",
  735. .codec_dai_name = "snd-soc-dummy-dai",
  736. .platform_name = "0000:00:1f.3",
  737. .dpcm_playback = 1,
  738. .init = NULL,
  739. .trigger = {
  740. SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  741. .nonatomic = 1,
  742. .dynamic = 1,
  743. },
  744. [KBL_DPCM_AUDIO_5663_HDMI2_PB] = {
  745. .name = "Kbl HDMI Port2",
  746. .stream_name = "Hdmi2",
  747. .cpu_dai_name = "HDMI2 Pin",
  748. .codec_name = "snd-soc-dummy",
  749. .codec_dai_name = "snd-soc-dummy-dai",
  750. .platform_name = "0000:00:1f.3",
  751. .dpcm_playback = 1,
  752. .init = NULL,
  753. .trigger = {
  754. SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  755. .nonatomic = 1,
  756. .dynamic = 1,
  757. },
  758. /* Back End DAI links */
  759. {
  760. /* SSP1 - Codec */
  761. .name = "SSP1-Codec",
  762. .id = 0,
  763. .cpu_dai_name = "SSP1 Pin",
  764. .platform_name = "0000:00:1f.3",
  765. .no_pcm = 1,
  766. .codec_name = "i2c-10EC5663:00",
  767. .codec_dai_name = KBL_REALTEK_CODEC_DAI,
  768. .init = kabylake_rt5663_codec_init,
  769. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  770. SND_SOC_DAIFMT_CBS_CFS,
  771. .ignore_pmdown_time = 1,
  772. .be_hw_params_fixup = kabylake_ssp_fixup,
  773. .ops = &kabylake_rt5663_ops,
  774. .dpcm_playback = 1,
  775. .dpcm_capture = 1,
  776. },
  777. {
  778. .name = "iDisp1",
  779. .id = 1,
  780. .cpu_dai_name = "iDisp1 Pin",
  781. .codec_name = "ehdaudio0D2",
  782. .codec_dai_name = "intel-hdmi-hifi1",
  783. .platform_name = "0000:00:1f.3",
  784. .dpcm_playback = 1,
  785. .init = kabylake_5663_hdmi1_init,
  786. .no_pcm = 1,
  787. },
  788. {
  789. .name = "iDisp2",
  790. .id = 2,
  791. .cpu_dai_name = "iDisp2 Pin",
  792. .codec_name = "ehdaudio0D2",
  793. .codec_dai_name = "intel-hdmi-hifi2",
  794. .platform_name = "0000:00:1f.3",
  795. .init = kabylake_5663_hdmi2_init,
  796. .dpcm_playback = 1,
  797. .no_pcm = 1,
  798. },
  799. };
  800. #define NAME_SIZE 32
  801. static int kabylake_card_late_probe(struct snd_soc_card *card)
  802. {
  803. struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
  804. struct kbl_hdmi_pcm *pcm;
  805. struct snd_soc_component *component = NULL;
  806. int err, i = 0;
  807. char jack_name[NAME_SIZE];
  808. list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
  809. component = pcm->codec_dai->component;
  810. snprintf(jack_name, sizeof(jack_name),
  811. "HDMI/DP, pcm=%d Jack", pcm->device);
  812. err = snd_soc_card_jack_new(card, jack_name,
  813. SND_JACK_AVOUT, &skylake_hdmi[i],
  814. NULL, 0);
  815. if (err)
  816. return err;
  817. err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
  818. &skylake_hdmi[i]);
  819. if (err < 0)
  820. return err;
  821. i++;
  822. }
  823. if (!component)
  824. return -EINVAL;
  825. return hdac_hdmi_jack_port_init(component, &card->dapm);
  826. }
  827. /* kabylake audio machine driver for SPT + RT5663 */
  828. static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = {
  829. .name = "kblrt5663max",
  830. .owner = THIS_MODULE,
  831. .dai_link = kabylake_dais,
  832. .num_links = ARRAY_SIZE(kabylake_dais),
  833. .controls = kabylake_controls,
  834. .num_controls = ARRAY_SIZE(kabylake_controls),
  835. .dapm_widgets = kabylake_widgets,
  836. .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
  837. .dapm_routes = kabylake_map,
  838. .num_dapm_routes = ARRAY_SIZE(kabylake_map),
  839. .codec_conf = max98927_codec_conf,
  840. .num_configs = ARRAY_SIZE(max98927_codec_conf),
  841. .fully_routed = true,
  842. .late_probe = kabylake_card_late_probe,
  843. };
  844. /* kabylake audio machine driver for RT5663 */
  845. static struct snd_soc_card kabylake_audio_card_rt5663 = {
  846. .name = "kblrt5663",
  847. .owner = THIS_MODULE,
  848. .dai_link = kabylake_5663_dais,
  849. .num_links = ARRAY_SIZE(kabylake_5663_dais),
  850. .controls = kabylake_5663_controls,
  851. .num_controls = ARRAY_SIZE(kabylake_5663_controls),
  852. .dapm_widgets = kabylake_5663_widgets,
  853. .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets),
  854. .dapm_routes = kabylake_5663_map,
  855. .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map),
  856. .fully_routed = true,
  857. .late_probe = kabylake_card_late_probe,
  858. };
  859. static int kabylake_audio_probe(struct platform_device *pdev)
  860. {
  861. struct kbl_rt5663_private *ctx;
  862. struct skl_machine_pdata *pdata;
  863. int ret;
  864. ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
  865. if (!ctx)
  866. return -ENOMEM;
  867. INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
  868. kabylake_audio_card =
  869. (struct snd_soc_card *)pdev->id_entry->driver_data;
  870. kabylake_audio_card->dev = &pdev->dev;
  871. snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
  872. pdata = dev_get_drvdata(&pdev->dev);
  873. if (pdata)
  874. dmic_constraints = pdata->dmic_num == 2 ?
  875. &constraints_dmic_2ch : &constraints_dmic_channels;
  876. ctx->mclk = devm_clk_get(&pdev->dev, "ssp1_mclk");
  877. if (IS_ERR(ctx->mclk)) {
  878. ret = PTR_ERR(ctx->mclk);
  879. if (ret == -ENOENT) {
  880. dev_info(&pdev->dev,
  881. "Failed to get ssp1_sclk, defer probe\n");
  882. return -EPROBE_DEFER;
  883. }
  884. dev_err(&pdev->dev, "Failed to get ssp1_mclk with err:%d\n",
  885. ret);
  886. return ret;
  887. }
  888. ctx->sclk = devm_clk_get(&pdev->dev, "ssp1_sclk");
  889. if (IS_ERR(ctx->sclk)) {
  890. ret = PTR_ERR(ctx->sclk);
  891. if (ret == -ENOENT) {
  892. dev_info(&pdev->dev,
  893. "Failed to get ssp1_sclk, defer probe\n");
  894. return -EPROBE_DEFER;
  895. }
  896. dev_err(&pdev->dev, "Failed to get ssp1_sclk with err:%d\n",
  897. ret);
  898. return ret;
  899. }
  900. return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
  901. }
  902. static const struct platform_device_id kbl_board_ids[] = {
  903. {
  904. .name = "kbl_rt5663",
  905. .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663,
  906. },
  907. {
  908. .name = "kbl_rt5663_m98927",
  909. .driver_data =
  910. (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927,
  911. },
  912. { }
  913. };
  914. static struct platform_driver kabylake_audio = {
  915. .probe = kabylake_audio_probe,
  916. .driver = {
  917. .name = "kbl_rt5663_m98927",
  918. .pm = &snd_soc_pm_ops,
  919. },
  920. .id_table = kbl_board_ids,
  921. };
  922. module_platform_driver(kabylake_audio)
  923. /* Module information */
  924. MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
  925. MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
  926. MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
  927. MODULE_LICENSE("GPL v2");
  928. MODULE_ALIAS("platform:kbl_rt5663");
  929. MODULE_ALIAS("platform:kbl_rt5663_m98927");