forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/intel/boards/bxt_rt298.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Intel Broxton-P I2S Machine Driver
34 *
....@@ -5,15 +6,6 @@
56 *
67 * Modified from:
78 * Intel Skylake I2S Machine driver
8
- *
9
- * This program is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU General Public License version
11
- * 2 as published by the Free Software Foundation.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
179 */
1810
1911 #include <linux/module.h>
....@@ -21,10 +13,12 @@
2113 #include <sound/core.h>
2214 #include <sound/pcm.h>
2315 #include <sound/soc.h>
16
+#include <sound/soc-acpi.h>
2417 #include <sound/jack.h>
2518 #include <sound/pcm_params.h>
2619 #include "../../codecs/hdac_hdmi.h"
2720 #include "../../codecs/rt298.h"
21
+#include "hda_dsp_common.h"
2822
2923 /* Headset jack detection DAPM pins */
3024 static struct snd_soc_jack broxton_headset;
....@@ -38,6 +32,7 @@
3832
3933 struct bxt_rt286_private {
4034 struct list_head hdmi_pcm_list;
35
+ bool common_hdmi_codec_drv;
4136 };
4237
4338 enum {
....@@ -160,7 +155,7 @@
160155 static int broxton_rt298_fe_init(struct snd_soc_pcm_runtime *rtd)
161156 {
162157 struct snd_soc_dapm_context *dapm;
163
- struct snd_soc_component *component = rtd->cpu_dai->component;
158
+ struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
164159
165160 dapm = snd_soc_component_get_dapm(component);
166161 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
....@@ -170,7 +165,7 @@
170165
171166 static int broxton_rt298_codec_init(struct snd_soc_pcm_runtime *rtd)
172167 {
173
- struct snd_soc_component *component = rtd->codec_dai->component;
168
+ struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
174169 int ret = 0;
175170
176171 ret = snd_soc_card_jack_new(rtd->card, "Headset",
....@@ -191,7 +186,7 @@
191186 static int broxton_hdmi_init(struct snd_soc_pcm_runtime *rtd)
192187 {
193188 struct bxt_rt286_private *ctx = snd_soc_card_get_drvdata(rtd->card);
194
- struct snd_soc_dai *dai = rtd->codec_dai;
189
+ struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
195190 struct bxt_hdmi_pcm *pcm;
196191
197192 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
....@@ -211,13 +206,13 @@
211206 {
212207 struct snd_interval *rate = hw_param_interval(params,
213208 SNDRV_PCM_HW_PARAM_RATE);
214
- struct snd_interval *channels = hw_param_interval(params,
209
+ struct snd_interval *chan = hw_param_interval(params,
215210 SNDRV_PCM_HW_PARAM_CHANNELS);
216211 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
217212
218213 /* The ADSP will covert the FE rate to 48k, stereo */
219214 rate->min = rate->max = 48000;
220
- channels->min = channels->max = 2;
215
+ chan->min = chan->max = 2;
221216
222217 /* set SSP5 to 24 bit */
223218 snd_mask_none(fmt);
....@@ -229,8 +224,8 @@
229224 static int broxton_rt298_hw_params(struct snd_pcm_substream *substream,
230225 struct snd_pcm_hw_params *params)
231226 {
232
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
233
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
227
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
228
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
234229 int ret;
235230
236231 ret = snd_soc_dai_set_sysclk(codec_dai, RT298_SCLK_S_PLL,
....@@ -260,9 +255,9 @@
260255 static int broxton_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
261256 struct snd_pcm_hw_params *params)
262257 {
263
- struct snd_interval *channels = hw_param_interval(params,
258
+ struct snd_interval *chan = hw_param_interval(params,
264259 SNDRV_PCM_HW_PARAM_CHANNELS);
265
- channels->min = channels->max = 4;
260
+ chan->min = chan->max = 4;
266261
267262 return 0;
268263 }
....@@ -330,6 +325,64 @@
330325 .startup = bxt_fe_startup,
331326 };
332327
328
+SND_SOC_DAILINK_DEF(dummy,
329
+ DAILINK_COMP_ARRAY(COMP_DUMMY()));
330
+
331
+SND_SOC_DAILINK_DEF(system,
332
+ DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
333
+
334
+SND_SOC_DAILINK_DEF(reference,
335
+ DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
336
+
337
+SND_SOC_DAILINK_DEF(dmic,
338
+ DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
339
+
340
+SND_SOC_DAILINK_DEF(hdmi1,
341
+ DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
342
+
343
+SND_SOC_DAILINK_DEF(hdmi2,
344
+ DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
345
+
346
+SND_SOC_DAILINK_DEF(hdmi3,
347
+ DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
348
+
349
+SND_SOC_DAILINK_DEF(ssp5_pin,
350
+ DAILINK_COMP_ARRAY(COMP_CPU("SSP5 Pin")));
351
+SND_SOC_DAILINK_DEF(ssp5_codec,
352
+ DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT343A:00",
353
+ "rt298-aif1")));
354
+
355
+SND_SOC_DAILINK_DEF(dmic_pin,
356
+ DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
357
+
358
+SND_SOC_DAILINK_DEF(dmic_codec,
359
+ DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec",
360
+ "dmic-hifi")));
361
+
362
+SND_SOC_DAILINK_DEF(dmic16k,
363
+ DAILINK_COMP_ARRAY(COMP_CPU("DMIC16k Pin")));
364
+
365
+SND_SOC_DAILINK_DEF(idisp1_pin,
366
+ DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
367
+SND_SOC_DAILINK_DEF(idisp1_codec,
368
+ DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
369
+ "intel-hdmi-hifi1")));
370
+
371
+SND_SOC_DAILINK_DEF(idisp2_pin,
372
+ DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
373
+SND_SOC_DAILINK_DEF(idisp2_codec,
374
+ DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
375
+ "intel-hdmi-hifi2")));
376
+
377
+SND_SOC_DAILINK_DEF(idisp3_pin,
378
+ DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
379
+SND_SOC_DAILINK_DEF(idisp3_codec,
380
+ DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
381
+ "intel-hdmi-hifi3")));
382
+
383
+SND_SOC_DAILINK_DEF(platform,
384
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:0e.0")));
385
+
333386 /* broxton digital audio interface glue - connects codec <--> CPU */
334387 static struct snd_soc_dai_link broxton_rt298_dais[] = {
335388 /* Front End DAI links */
....@@ -337,107 +390,82 @@
337390 {
338391 .name = "Bxt Audio Port",
339392 .stream_name = "Audio",
340
- .cpu_dai_name = "System Pin",
341
- .platform_name = "0000:00:0e.0",
342393 .nonatomic = 1,
343394 .dynamic = 1,
344
- .codec_name = "snd-soc-dummy",
345
- .codec_dai_name = "snd-soc-dummy-dai",
346395 .init = broxton_rt298_fe_init,
347396 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
348397 .dpcm_playback = 1,
349398 .ops = &broxton_rt286_fe_ops,
399
+ SND_SOC_DAILINK_REG(system, dummy, platform),
350400 },
351401 [BXT_DPCM_AUDIO_CP] =
352402 {
353403 .name = "Bxt Audio Capture Port",
354404 .stream_name = "Audio Record",
355
- .cpu_dai_name = "System Pin",
356
- .platform_name = "0000:00:0e.0",
357405 .nonatomic = 1,
358406 .dynamic = 1,
359
- .codec_name = "snd-soc-dummy",
360
- .codec_dai_name = "snd-soc-dummy-dai",
361407 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
362408 .dpcm_capture = 1,
363409 .ops = &broxton_rt286_fe_ops,
410
+ SND_SOC_DAILINK_REG(system, dummy, platform),
364411 },
365412 [BXT_DPCM_AUDIO_REF_CP] =
366413 {
367414 .name = "Bxt Audio Reference cap",
368415 .stream_name = "refcap",
369
- .cpu_dai_name = "Reference Pin",
370
- .codec_name = "snd-soc-dummy",
371
- .codec_dai_name = "snd-soc-dummy-dai",
372
- .platform_name = "0000:00:0e.0",
373416 .init = NULL,
374417 .dpcm_capture = 1,
375418 .nonatomic = 1,
376419 .dynamic = 1,
420
+ SND_SOC_DAILINK_REG(reference, dummy, platform),
377421 },
378422 [BXT_DPCM_AUDIO_DMIC_CP] =
379423 {
380424 .name = "Bxt Audio DMIC cap",
381425 .stream_name = "dmiccap",
382
- .cpu_dai_name = "DMIC Pin",
383
- .codec_name = "snd-soc-dummy",
384
- .codec_dai_name = "snd-soc-dummy-dai",
385
- .platform_name = "0000:00:0e.0",
386426 .init = NULL,
387427 .dpcm_capture = 1,
388428 .nonatomic = 1,
389429 .dynamic = 1,
390430 .ops = &broxton_dmic_ops,
431
+ SND_SOC_DAILINK_REG(dmic, dummy, platform),
391432 },
392433 [BXT_DPCM_AUDIO_HDMI1_PB] =
393434 {
394435 .name = "Bxt HDMI Port1",
395436 .stream_name = "Hdmi1",
396
- .cpu_dai_name = "HDMI1 Pin",
397
- .codec_name = "snd-soc-dummy",
398
- .codec_dai_name = "snd-soc-dummy-dai",
399
- .platform_name = "0000:00:0e.0",
400437 .dpcm_playback = 1,
401438 .init = NULL,
402439 .nonatomic = 1,
403440 .dynamic = 1,
441
+ SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
404442 },
405443 [BXT_DPCM_AUDIO_HDMI2_PB] =
406444 {
407445 .name = "Bxt HDMI Port2",
408446 .stream_name = "Hdmi2",
409
- .cpu_dai_name = "HDMI2 Pin",
410
- .codec_name = "snd-soc-dummy",
411
- .codec_dai_name = "snd-soc-dummy-dai",
412
- .platform_name = "0000:00:0e.0",
413447 .dpcm_playback = 1,
414448 .init = NULL,
415449 .nonatomic = 1,
416450 .dynamic = 1,
451
+ SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
417452 },
418453 [BXT_DPCM_AUDIO_HDMI3_PB] =
419454 {
420455 .name = "Bxt HDMI Port3",
421456 .stream_name = "Hdmi3",
422
- .cpu_dai_name = "HDMI3 Pin",
423
- .codec_name = "snd-soc-dummy",
424
- .codec_dai_name = "snd-soc-dummy-dai",
425
- .platform_name = "0000:00:0e.0",
426457 .dpcm_playback = 1,
427458 .init = NULL,
428459 .nonatomic = 1,
429460 .dynamic = 1,
461
+ SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
430462 },
431463 /* Back End DAI links */
432464 {
433465 /* SSP5 - Codec */
434466 .name = "SSP5-Codec",
435467 .id = 0,
436
- .cpu_dai_name = "SSP5 Pin",
437
- .platform_name = "0000:00:0e.0",
438468 .no_pcm = 1,
439
- .codec_name = "i2c-INT343A:00",
440
- .codec_dai_name = "rt298-aif1",
441469 .init = broxton_rt298_codec_init,
442470 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF |
443471 SND_SOC_DAIFMT_CBS_CFS,
....@@ -446,63 +474,49 @@
446474 .ops = &broxton_rt298_ops,
447475 .dpcm_playback = 1,
448476 .dpcm_capture = 1,
477
+ SND_SOC_DAILINK_REG(ssp5_pin, ssp5_codec, platform),
449478 },
450479 {
451480 .name = "dmic01",
452481 .id = 1,
453
- .cpu_dai_name = "DMIC01 Pin",
454
- .codec_name = "dmic-codec",
455
- .codec_dai_name = "dmic-hifi",
456
- .platform_name = "0000:00:0e.0",
457482 .be_hw_params_fixup = broxton_dmic_fixup,
458483 .ignore_suspend = 1,
459484 .dpcm_capture = 1,
460485 .no_pcm = 1,
486
+ SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
461487 },
462488 {
463489 .name = "dmic16k",
464490 .id = 2,
465
- .cpu_dai_name = "DMIC16k Pin",
466
- .codec_name = "dmic-codec",
467
- .codec_dai_name = "dmic-hifi",
468
- .platform_name = "0000:00:0e.0",
469491 .be_hw_params_fixup = broxton_dmic_fixup,
470492 .ignore_suspend = 1,
471493 .dpcm_capture = 1,
472494 .no_pcm = 1,
495
+ SND_SOC_DAILINK_REG(dmic16k, dmic_codec, platform),
473496 },
474497 {
475498 .name = "iDisp1",
476499 .id = 3,
477
- .cpu_dai_name = "iDisp1 Pin",
478
- .codec_name = "ehdaudio0D2",
479
- .codec_dai_name = "intel-hdmi-hifi1",
480
- .platform_name = "0000:00:0e.0",
481500 .init = broxton_hdmi_init,
482501 .dpcm_playback = 1,
483502 .no_pcm = 1,
503
+ SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
484504 },
485505 {
486506 .name = "iDisp2",
487507 .id = 4,
488
- .cpu_dai_name = "iDisp2 Pin",
489
- .codec_name = "ehdaudio0D2",
490
- .codec_dai_name = "intel-hdmi-hifi2",
491
- .platform_name = "0000:00:0e.0",
492508 .init = broxton_hdmi_init,
493509 .dpcm_playback = 1,
494510 .no_pcm = 1,
511
+ SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
495512 },
496513 {
497514 .name = "iDisp3",
498515 .id = 5,
499
- .cpu_dai_name = "iDisp3 Pin",
500
- .codec_name = "ehdaudio0D2",
501
- .codec_dai_name = "intel-hdmi-hifi3",
502
- .platform_name = "0000:00:0e.0",
503516 .init = broxton_hdmi_init,
504517 .dpcm_playback = 1,
505518 .no_pcm = 1,
519
+ SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
506520 },
507521 };
508522
....@@ -514,6 +528,16 @@
514528 struct snd_soc_component *component = NULL;
515529 int err, i = 0;
516530 char jack_name[NAME_SIZE];
531
+
532
+ if (list_empty(&ctx->hdmi_pcm_list))
533
+ return -EINVAL;
534
+
535
+ if (ctx->common_hdmi_codec_drv) {
536
+ pcm = list_first_entry(&ctx->hdmi_pcm_list, struct bxt_hdmi_pcm,
537
+ head);
538
+ component = pcm->codec_dai->component;
539
+ return hda_dsp_hdmi_build_controls(card, component);
540
+ }
517541
518542 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
519543 component = pcm->codec_dai->component;
....@@ -533,9 +557,6 @@
533557
534558 i++;
535559 }
536
-
537
- if (!component)
538
- return -EINVAL;
539560
540561 return hdac_hdmi_jack_port_init(component, &card->dapm);
541562 }
....@@ -578,19 +599,22 @@
578599 struct bxt_rt286_private *ctx;
579600 struct snd_soc_card *card =
580601 (struct snd_soc_card *)pdev->id_entry->driver_data;
602
+ struct snd_soc_acpi_mach *mach;
603
+ const char *platform_name;
604
+ int ret;
581605 int i;
582606
583607 for (i = 0; i < ARRAY_SIZE(broxton_rt298_dais); i++) {
584
- if (!strncmp(card->dai_link[i].codec_name, "i2c-INT343A:00",
585
- I2C_NAME_SIZE)) {
608
+ if (!strncmp(card->dai_link[i].codecs->name, "i2c-INT343A:00",
609
+ I2C_NAME_SIZE)) {
586610 if (!strncmp(card->name, "broxton-rt298",
587
- PLATFORM_NAME_SIZE)) {
611
+ PLATFORM_NAME_SIZE)) {
588612 card->dai_link[i].name = "SSP5-Codec";
589
- card->dai_link[i].cpu_dai_name = "SSP5 Pin";
613
+ card->dai_link[i].cpus->dai_name = "SSP5 Pin";
590614 } else if (!strncmp(card->name, "geminilake-rt298",
591
- PLATFORM_NAME_SIZE)) {
615
+ PLATFORM_NAME_SIZE)) {
592616 card->dai_link[i].name = "SSP2-Codec";
593
- card->dai_link[i].cpu_dai_name = "SSP2 Pin";
617
+ card->dai_link[i].cpus->dai_name = "SSP2 Pin";
594618 }
595619 }
596620 }
....@@ -604,6 +628,17 @@
604628 card->dev = &pdev->dev;
605629 snd_soc_card_set_drvdata(card, ctx);
606630
631
+ /* override plaform name, if required */
632
+ mach = pdev->dev.platform_data;
633
+ platform_name = mach->mach_params.platform;
634
+
635
+ ret = snd_soc_fixup_dai_links_platform_name(card,
636
+ platform_name);
637
+ if (ret)
638
+ return ret;
639
+
640
+ ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
641
+
607642 return devm_snd_soc_register_card(&pdev->dev, card);
608643 }
609644