forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Intel Kabylake I2S Machine Driver with MAXIM98927
34 * RT5514 and RT5663 Codecs
....@@ -7,15 +8,6 @@
78 * Modified from:
89 * Intel Kabylake I2S Machine driver supporting MAXIM98927 and
910 * RT5663 codecs
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.
1911 */
2012
2113 #include <linux/input.h>
....@@ -26,10 +18,13 @@
2618 #include <sound/pcm.h>
2719 #include <sound/pcm_params.h>
2820 #include <sound/soc.h>
21
+#include <sound/soc-acpi.h>
2922 #include "../../codecs/rt5514.h"
3023 #include "../../codecs/rt5663.h"
3124 #include "../../codecs/hdac_hdmi.h"
32
-#include "../skylake/skl.h"
25
+#include <linux/clk.h>
26
+#include <linux/clk-provider.h>
27
+#include <linux/clkdev.h>
3328
3429 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
3530 #define KBL_REALTEK_DMIC_CODEC_DAI "rt5514-aif1"
....@@ -58,6 +53,8 @@
5853 struct snd_soc_jack kabylake_headset;
5954 struct list_head hdmi_pcm_list;
6055 struct snd_soc_jack kabylake_hdmi[2];
56
+ struct clk *mclk;
57
+ struct clk *sclk;
6158 };
6259
6360 enum {
....@@ -79,6 +76,61 @@
7976 SOC_DAPM_PIN_SWITCH("DMIC"),
8077 };
8178
79
+static int platform_clock_control(struct snd_soc_dapm_widget *w,
80
+ struct snd_kcontrol *k, int event)
81
+{
82
+ struct snd_soc_dapm_context *dapm = w->dapm;
83
+ struct snd_soc_card *card = dapm->card;
84
+ struct kbl_codec_private *priv = snd_soc_card_get_drvdata(card);
85
+ int ret = 0;
86
+
87
+ /*
88
+ * MCLK/SCLK need to be ON early for a successful synchronization of
89
+ * codec internal clock. And the clocks are turned off during
90
+ * POST_PMD after the stream is stopped.
91
+ */
92
+ switch (event) {
93
+ case SND_SOC_DAPM_PRE_PMU:
94
+ /* Enable MCLK */
95
+ ret = clk_set_rate(priv->mclk, 24000000);
96
+ if (ret < 0) {
97
+ dev_err(card->dev, "Can't set rate for mclk, err: %d\n",
98
+ ret);
99
+ return ret;
100
+ }
101
+
102
+ ret = clk_prepare_enable(priv->mclk);
103
+ if (ret < 0) {
104
+ dev_err(card->dev, "Can't enable mclk, err: %d\n", ret);
105
+ return ret;
106
+ }
107
+
108
+ /* Enable SCLK */
109
+ ret = clk_set_rate(priv->sclk, 3072000);
110
+ if (ret < 0) {
111
+ dev_err(card->dev, "Can't set rate for sclk, err: %d\n",
112
+ ret);
113
+ clk_disable_unprepare(priv->mclk);
114
+ return ret;
115
+ }
116
+
117
+ ret = clk_prepare_enable(priv->sclk);
118
+ if (ret < 0) {
119
+ dev_err(card->dev, "Can't enable sclk, err: %d\n", ret);
120
+ clk_disable_unprepare(priv->mclk);
121
+ }
122
+ break;
123
+ case SND_SOC_DAPM_POST_PMD:
124
+ clk_disable_unprepare(priv->mclk);
125
+ clk_disable_unprepare(priv->sclk);
126
+ break;
127
+ default:
128
+ return 0;
129
+ }
130
+
131
+ return 0;
132
+}
133
+
82134 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
83135 SND_SOC_DAPM_HP("Headphone Jack", NULL),
84136 SND_SOC_DAPM_MIC("Headset Mic", NULL),
....@@ -87,11 +139,15 @@
87139 SND_SOC_DAPM_MIC("DMIC", NULL),
88140 SND_SOC_DAPM_SPK("HDMI1", NULL),
89141 SND_SOC_DAPM_SPK("HDMI2", NULL),
142
+ SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
143
+ platform_clock_control, SND_SOC_DAPM_PRE_PMU |
144
+ SND_SOC_DAPM_POST_PMD),
90145
91146 };
92147
93148 static const struct snd_soc_dapm_route kabylake_map[] = {
94149 /* Headphones */
150
+ { "Headphone Jack", NULL, "Platform Clock" },
95151 { "Headphone Jack", NULL, "HPOL" },
96152 { "Headphone Jack", NULL, "HPOR" },
97153
....@@ -100,6 +156,7 @@
100156 { "Right Spk", NULL, "Right BE_OUT" },
101157
102158 /* other jacks */
159
+ { "Headset Mic", NULL, "Platform Clock" },
103160 { "IN1P", NULL, "Headset Mic" },
104161 { "IN1N", NULL, "Headset Mic" },
105162
....@@ -136,34 +193,20 @@
136193
137194 static struct snd_soc_codec_conf max98927_codec_conf[] = {
138195 {
139
- .dev_name = MAXIM_DEV0_NAME,
196
+ .dlc = COMP_CODEC_CONF(MAXIM_DEV0_NAME),
140197 .name_prefix = "Right",
141198 },
142199 {
143
- .dev_name = MAXIM_DEV1_NAME,
200
+ .dlc = COMP_CODEC_CONF(MAXIM_DEV1_NAME),
144201 .name_prefix = "Left",
145202 },
146203 };
147204
148
-static struct snd_soc_dai_link_component ssp0_codec_components[] = {
149
- { /* Left */
150
- .name = MAXIM_DEV0_NAME,
151
- .dai_name = KBL_MAXIM_CODEC_DAI,
152
- },
153
- { /* Right */
154
- .name = MAXIM_DEV1_NAME,
155
- .dai_name = KBL_MAXIM_CODEC_DAI,
156
- },
157
- { /*dmic */
158
- .name = RT5514_DEV_NAME,
159
- .dai_name = KBL_REALTEK_DMIC_CODEC_DAI,
160
- },
161
-};
162205
163206 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
164207 {
165208 struct snd_soc_dapm_context *dapm;
166
- struct snd_soc_component *component = rtd->cpu_dai->component;
209
+ struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
167210 int ret;
168211
169212 dapm = snd_soc_component_get_dapm(component);
....@@ -178,7 +221,7 @@
178221 {
179222 int ret;
180223 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
181
- struct snd_soc_component *component = rtd->codec_dai->component;
224
+ struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
182225 struct snd_soc_jack *jack;
183226
184227 /*
....@@ -212,7 +255,7 @@
212255 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
213256 {
214257 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
215
- struct snd_soc_dai *dai = rtd->codec_dai;
258
+ struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
216259 struct kbl_hdmi_pcm *pcm;
217260
218261 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
....@@ -290,36 +333,59 @@
290333 {
291334 struct snd_interval *rate = hw_param_interval(params,
292335 SNDRV_PCM_HW_PARAM_RATE);
293
- struct snd_interval *channels = hw_param_interval(params,
336
+ struct snd_interval *chan = hw_param_interval(params,
294337 SNDRV_PCM_HW_PARAM_CHANNELS);
295338 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
296
- struct snd_soc_dpcm *dpcm = container_of(
297
- params, struct snd_soc_dpcm, hw_params);
298
- struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
299
- struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
339
+ struct snd_soc_dpcm *dpcm, *rtd_dpcm = NULL;
340
+
341
+ /*
342
+ * The following loop will be called only for playback stream
343
+ * In this platform, there is only one playback device on every SSP
344
+ */
345
+ for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
346
+ rtd_dpcm = dpcm;
347
+ break;
348
+ }
349
+
350
+ /*
351
+ * This following loop will be called only for capture stream
352
+ * In this platform, there is only one capture device on every SSP
353
+ */
354
+ for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
355
+ rtd_dpcm = dpcm;
356
+ break;
357
+ }
358
+
359
+ if (!rtd_dpcm)
360
+ return -EINVAL;
361
+
362
+ /*
363
+ * The above 2 loops are mutually exclusive based on the stream direction,
364
+ * thus rtd_dpcm variable will never be overwritten
365
+ */
300366
301367 /*
302368 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
303369 */
304
- if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
305
- !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
306
- !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
370
+ if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Port") ||
371
+ !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Headset Playback") ||
372
+ !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Capture Port")) {
307373 rate->min = rate->max = 48000;
308
- channels->min = channels->max = 2;
374
+ chan->min = chan->max = 2;
309375 snd_mask_none(fmt);
310376 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
311
- } else if (!strcmp(fe_dai_link->name, "Kbl Audio DMIC cap")) {
377
+ } else if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio DMIC cap")) {
312378 if (params_channels(params) == 2 ||
313379 DMIC_CH(dmic_constraints) == 2)
314
- channels->min = channels->max = 2;
380
+ chan->min = chan->max = 2;
315381 else
316
- channels->min = channels->max = 4;
382
+ chan->min = chan->max = 4;
317383 }
318384 /*
319385 * The speaker on the SSP0 supports S16_LE and not S24_LE.
320386 * thus changing the mask here
321387 */
322
- if (!strcmp(be_dai_link->name, "SSP0-Codec"))
388
+ if (!strcmp(rtd_dpcm->be->dai_link->name, "SSP0-Codec"))
323389 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
324390
325391 return 0;
....@@ -328,8 +394,8 @@
328394 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
329395 struct snd_pcm_hw_params *params)
330396 {
331
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
332
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
397
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
398
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
333399 int ret;
334400
335401 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
....@@ -352,12 +418,11 @@
352418 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
353419 struct snd_pcm_hw_params *params)
354420 {
355
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
421
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
422
+ struct snd_soc_dai *codec_dai;
356423 int ret = 0, j;
357424
358
- for (j = 0; j < rtd->num_codecs; j++) {
359
- struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
360
-
425
+ for_each_rtd_codec_dais(rtd, j, codec_dai) {
361426 if (!strcmp(codec_dai->component->name, RT5514_DEV_NAME)) {
362427 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16);
363428 if (ret < 0) {
....@@ -434,108 +499,136 @@
434499 .startup = kabylake_dmic_startup,
435500 };
436501
502
+SND_SOC_DAILINK_DEF(dummy,
503
+ DAILINK_COMP_ARRAY(COMP_DUMMY()));
504
+
505
+SND_SOC_DAILINK_DEF(system,
506
+ DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
507
+
508
+SND_SOC_DAILINK_DEF(system2,
509
+ DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
510
+
511
+SND_SOC_DAILINK_DEF(echoref,
512
+ DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
513
+
514
+SND_SOC_DAILINK_DEF(spi_cpu,
515
+ DAILINK_COMP_ARRAY(COMP_CPU("spi-PRP0001:00")));
516
+SND_SOC_DAILINK_DEF(spi_platform,
517
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("spi-PRP0001:00")));
518
+
519
+SND_SOC_DAILINK_DEF(dmic,
520
+ DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
521
+
522
+SND_SOC_DAILINK_DEF(hdmi1,
523
+ DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
524
+
525
+SND_SOC_DAILINK_DEF(hdmi2,
526
+ DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
527
+
528
+SND_SOC_DAILINK_DEF(ssp0_pin,
529
+ DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
530
+SND_SOC_DAILINK_DEF(ssp0_codec,
531
+ DAILINK_COMP_ARRAY(
532
+ /* Left */ COMP_CODEC(MAXIM_DEV0_NAME, KBL_MAXIM_CODEC_DAI),
533
+ /* Right */COMP_CODEC(MAXIM_DEV1_NAME, KBL_MAXIM_CODEC_DAI),
534
+ /* dmic */ COMP_CODEC(RT5514_DEV_NAME, KBL_REALTEK_DMIC_CODEC_DAI)));
535
+
536
+SND_SOC_DAILINK_DEF(ssp1_pin,
537
+ DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
538
+SND_SOC_DAILINK_DEF(ssp1_codec,
539
+ DAILINK_COMP_ARRAY(COMP_CODEC(RT5663_DEV_NAME, KBL_REALTEK_CODEC_DAI)));
540
+
541
+SND_SOC_DAILINK_DEF(idisp1_pin,
542
+ DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
543
+SND_SOC_DAILINK_DEF(idisp1_codec,
544
+ DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
545
+
546
+SND_SOC_DAILINK_DEF(idisp2_pin,
547
+ DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
548
+SND_SOC_DAILINK_DEF(idisp2_codec,
549
+ DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
550
+
551
+SND_SOC_DAILINK_DEF(platform,
552
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
553
+
437554 /* kabylake digital audio interface glue - connects codec <--> CPU */
438555 static struct snd_soc_dai_link kabylake_dais[] = {
439556 /* Front End DAI links */
440557 [KBL_DPCM_AUDIO_PB] = {
441558 .name = "Kbl Audio Port",
442559 .stream_name = "Audio",
443
- .cpu_dai_name = "System Pin",
444
- .platform_name = "0000:00:1f.3",
445560 .dynamic = 1,
446
- .codec_name = "snd-soc-dummy",
447
- .codec_dai_name = "snd-soc-dummy-dai",
448561 .nonatomic = 1,
449562 .init = kabylake_rt5663_fe_init,
450563 .trigger = {
451564 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
452565 .dpcm_playback = 1,
453566 .ops = &kabylake_rt5663_fe_ops,
567
+ SND_SOC_DAILINK_REG(system, dummy, platform),
454568 },
455569 [KBL_DPCM_AUDIO_CP] = {
456570 .name = "Kbl Audio Capture Port",
457571 .stream_name = "Audio Record",
458
- .cpu_dai_name = "System Pin",
459
- .platform_name = "0000:00:1f.3",
460572 .dynamic = 1,
461
- .codec_name = "snd-soc-dummy",
462
- .codec_dai_name = "snd-soc-dummy-dai",
463573 .nonatomic = 1,
464574 .trigger = {
465575 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
466576 .dpcm_capture = 1,
467577 .ops = &kabylake_rt5663_fe_ops,
578
+ SND_SOC_DAILINK_REG(system, dummy, platform),
468579 },
469580 [KBL_DPCM_AUDIO_HS_PB] = {
470581 .name = "Kbl Audio Headset Playback",
471582 .stream_name = "Headset Audio",
472
- .cpu_dai_name = "System Pin2",
473
- .codec_name = "snd-soc-dummy",
474
- .codec_dai_name = "snd-soc-dummy-dai",
475
- .platform_name = "0000:00:1f.3",
476583 .dpcm_playback = 1,
477584 .nonatomic = 1,
478585 .dynamic = 1,
586
+ SND_SOC_DAILINK_REG(system2, dummy, platform),
479587 },
480588 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
481589 .name = "Kbl Audio Echo Reference cap",
482590 .stream_name = "Echoreference Capture",
483
- .cpu_dai_name = "Echoref Pin",
484
- .codec_name = "snd-soc-dummy",
485
- .codec_dai_name = "snd-soc-dummy-dai",
486
- .platform_name = "0000:00:1f.3",
487591 .init = NULL,
488
- .capture_only = 1,
592
+ .dpcm_capture = 1,
489593 .nonatomic = 1,
594
+ SND_SOC_DAILINK_REG(echoref, dummy, platform),
490595 },
491596 [KBL_DPCM_AUDIO_RT5514_DSP] = {
492597 .name = "rt5514 dsp",
493598 .stream_name = "Wake on Voice",
494
- .cpu_dai_name = "spi-PRP0001:00",
495
- .platform_name = "spi-PRP0001:00",
496
- .codec_name = "snd-soc-dummy",
497
- .codec_dai_name = "snd-soc-dummy-dai",
599
+ SND_SOC_DAILINK_REG(spi_cpu, dummy, spi_platform),
498600 },
499601 [KBL_DPCM_AUDIO_DMIC_CP] = {
500602 .name = "Kbl Audio DMIC cap",
501603 .stream_name = "dmiccap",
502
- .cpu_dai_name = "DMIC Pin",
503
- .codec_name = "snd-soc-dummy",
504
- .codec_dai_name = "snd-soc-dummy-dai",
505
- .platform_name = "0000:00:1f.3",
506604 .init = NULL,
507605 .dpcm_capture = 1,
508606 .nonatomic = 1,
509607 .dynamic = 1,
510608 .ops = &kabylake_dmic_ops,
609
+ SND_SOC_DAILINK_REG(dmic, dummy, platform),
511610 },
512611 [KBL_DPCM_AUDIO_HDMI1_PB] = {
513612 .name = "Kbl HDMI Port1",
514613 .stream_name = "Hdmi1",
515
- .cpu_dai_name = "HDMI1 Pin",
516
- .codec_name = "snd-soc-dummy",
517
- .codec_dai_name = "snd-soc-dummy-dai",
518
- .platform_name = "0000:00:1f.3",
519614 .dpcm_playback = 1,
520615 .init = NULL,
521616 .trigger = {
522617 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
523618 .nonatomic = 1,
524619 .dynamic = 1,
620
+ SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
525621 },
526622 [KBL_DPCM_AUDIO_HDMI2_PB] = {
527623 .name = "Kbl HDMI Port2",
528624 .stream_name = "Hdmi2",
529
- .cpu_dai_name = "HDMI2 Pin",
530
- .codec_name = "snd-soc-dummy",
531
- .codec_dai_name = "snd-soc-dummy-dai",
532
- .platform_name = "0000:00:1f.3",
533625 .dpcm_playback = 1,
534626 .init = NULL,
535627 .trigger = {
536628 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
537629 .nonatomic = 1,
538630 .dynamic = 1,
631
+ SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
539632 },
540633 /* Back End DAI links */
541634 /* single Back end dai for both max speakers and dmic */
....@@ -543,11 +636,7 @@
543636 /* SSP0 - Codec */
544637 .name = "SSP0-Codec",
545638 .id = 0,
546
- .cpu_dai_name = "SSP0 Pin",
547
- .platform_name = "0000:00:1f.3",
548639 .no_pcm = 1,
549
- .codecs = ssp0_codec_components,
550
- .num_codecs = ARRAY_SIZE(ssp0_codec_components),
551640 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
552641 SND_SOC_DAIFMT_NB_NF |
553642 SND_SOC_DAIFMT_CBS_CFS,
....@@ -556,15 +645,12 @@
556645 .dpcm_playback = 1,
557646 .dpcm_capture = 1,
558647 .ops = &kabylake_ssp0_ops,
648
+ SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
559649 },
560650 {
561651 .name = "SSP1-Codec",
562652 .id = 1,
563
- .cpu_dai_name = "SSP1 Pin",
564
- .platform_name = "0000:00:1f.3",
565653 .no_pcm = 1,
566
- .codec_name = RT5663_DEV_NAME,
567
- .codec_dai_name = KBL_REALTEK_CODEC_DAI,
568654 .init = kabylake_rt5663_codec_init,
569655 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
570656 SND_SOC_DAIFMT_CBS_CFS,
....@@ -573,30 +659,76 @@
573659 .ops = &kabylake_rt5663_ops,
574660 .dpcm_playback = 1,
575661 .dpcm_capture = 1,
662
+ SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
576663 },
577664 {
578665 .name = "iDisp1",
579666 .id = 3,
580
- .cpu_dai_name = "iDisp1 Pin",
581
- .codec_name = "ehdaudio0D2",
582
- .codec_dai_name = "intel-hdmi-hifi1",
583
- .platform_name = "0000:00:1f.3",
584667 .dpcm_playback = 1,
585668 .init = kabylake_hdmi1_init,
586669 .no_pcm = 1,
670
+ SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
587671 },
588672 {
589673 .name = "iDisp2",
590674 .id = 4,
591
- .cpu_dai_name = "iDisp2 Pin",
592
- .codec_name = "ehdaudio0D2",
593
- .codec_dai_name = "intel-hdmi-hifi2",
594
- .platform_name = "0000:00:1f.3",
595675 .init = kabylake_hdmi2_init,
596676 .dpcm_playback = 1,
597677 .no_pcm = 1,
678
+ SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
598679 },
599680 };
681
+
682
+static int kabylake_set_bias_level(struct snd_soc_card *card,
683
+ struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
684
+{
685
+ struct snd_soc_component *component = dapm->component;
686
+ struct kbl_codec_private *priv = snd_soc_card_get_drvdata(card);
687
+ int ret = 0;
688
+
689
+ if (!component || strcmp(component->name, RT5514_DEV_NAME))
690
+ return 0;
691
+
692
+ if (IS_ERR(priv->mclk))
693
+ return 0;
694
+
695
+ /*
696
+ * It's required to control mclk directly in the set_bias_level
697
+ * function for rt5514 codec or the recording function could
698
+ * break.
699
+ */
700
+ switch (level) {
701
+ case SND_SOC_BIAS_PREPARE:
702
+ if (dapm->bias_level == SND_SOC_BIAS_ON) {
703
+ if (!__clk_is_enabled(priv->mclk))
704
+ return 0;
705
+ dev_dbg(card->dev, "Disable mclk");
706
+ clk_disable_unprepare(priv->mclk);
707
+ } else {
708
+ dev_dbg(card->dev, "Enable mclk");
709
+ ret = clk_set_rate(priv->mclk, 24000000);
710
+ if (ret) {
711
+ dev_err(card->dev, "Can't set rate for mclk, err: %d\n",
712
+ ret);
713
+ return ret;
714
+ }
715
+
716
+ ret = clk_prepare_enable(priv->mclk);
717
+ if (ret) {
718
+ dev_err(card->dev, "Can't enable mclk, err: %d\n",
719
+ ret);
720
+
721
+ /* mclk is already enabled in FW */
722
+ ret = 0;
723
+ }
724
+ }
725
+ break;
726
+ default:
727
+ break;
728
+ }
729
+
730
+ return ret;
731
+}
600732
601733 static int kabylake_card_late_probe(struct snd_soc_card *card)
602734 {
....@@ -633,10 +765,11 @@
633765 * kabylake audio machine driver for MAX98927 + RT5514 + RT5663
634766 */
635767 static struct snd_soc_card kabylake_audio_card = {
636
- .name = "kbl_r5514_5663_max",
768
+ .name = "kbl-r5514-5663-max",
637769 .owner = THIS_MODULE,
638770 .dai_link = kabylake_dais,
639771 .num_links = ARRAY_SIZE(kabylake_dais),
772
+ .set_bias_level = kabylake_set_bias_level,
640773 .controls = kabylake_controls,
641774 .num_controls = ARRAY_SIZE(kabylake_controls),
642775 .dapm_widgets = kabylake_widgets,
....@@ -652,7 +785,8 @@
652785 static int kabylake_audio_probe(struct platform_device *pdev)
653786 {
654787 struct kbl_codec_private *ctx;
655
- struct skl_machine_pdata *pdata;
788
+ struct snd_soc_acpi_mach *mach;
789
+ int ret;
656790
657791 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
658792 if (!ctx)
....@@ -663,11 +797,39 @@
663797 kabylake_audio_card.dev = &pdev->dev;
664798 snd_soc_card_set_drvdata(&kabylake_audio_card, ctx);
665799
666
- pdata = dev_get_drvdata(&pdev->dev);
667
- if (pdata)
668
- dmic_constraints = pdata->dmic_num == 2 ?
800
+ mach = pdev->dev.platform_data;
801
+ if (mach)
802
+ dmic_constraints = mach->mach_params.dmic_num == 2 ?
669803 &constraints_dmic_2ch : &constraints_dmic_channels;
670804
805
+ ctx->mclk = devm_clk_get(&pdev->dev, "ssp1_mclk");
806
+ if (IS_ERR(ctx->mclk)) {
807
+ ret = PTR_ERR(ctx->mclk);
808
+ if (ret == -ENOENT) {
809
+ dev_info(&pdev->dev,
810
+ "Failed to get ssp1_mclk, defer probe\n");
811
+ return -EPROBE_DEFER;
812
+ }
813
+
814
+ dev_err(&pdev->dev, "Failed to get ssp1_mclk with err:%d\n",
815
+ ret);
816
+ return ret;
817
+ }
818
+
819
+ ctx->sclk = devm_clk_get(&pdev->dev, "ssp1_sclk");
820
+ if (IS_ERR(ctx->sclk)) {
821
+ ret = PTR_ERR(ctx->sclk);
822
+ if (ret == -ENOENT) {
823
+ dev_info(&pdev->dev,
824
+ "Failed to get ssp1_sclk, defer probe\n");
825
+ return -EPROBE_DEFER;
826
+ }
827
+
828
+ dev_err(&pdev->dev, "Failed to get ssp1_sclk with err:%d\n",
829
+ ret);
830
+ return ret;
831
+ }
832
+
671833 return devm_snd_soc_register_card(&pdev->dev, &kabylake_audio_card);
672834 }
673835