forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/intel/boards/cht_bsw_rt5645.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * cht-bsw-rt5645.c - ASoc Machine driver for Intel Cherryview-based platforms
34 * Cherrytrail and Braswell, with RT5645 codec.
....@@ -8,15 +9,6 @@
89 * This file is modified from cht_bsw_rt5672.c
910 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1011 *
11
- * This program is free software; you can redistribute it and/or modify
12
- * it under the terms of the GNU General Public License as published by
13
- * the Free Software Foundation; version 2 of the License.
14
- *
15
- * This program is distributed in the hope that it will be useful, but
16
- * WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
- * General Public License for more details.
19
- *
2012 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2113 */
2214
....@@ -26,8 +18,6 @@
2618 #include <linux/clk.h>
2719 #include <linux/dmi.h>
2820 #include <linux/slab.h>
29
-#include <asm/cpu_device_id.h>
30
-#include <asm/platform_sst_audio.h>
3121 #include <sound/pcm.h>
3222 #include <sound/pcm_params.h>
3323 #include <sound/soc.h>
....@@ -35,6 +25,7 @@
3525 #include <sound/soc-acpi.h>
3626 #include "../../codecs/rt5645.h"
3727 #include "../atom/sst-atom-controls.h"
28
+#include "../common/soc-intel-quirks.h"
3829
3930 #define CHT_PLAT_CLK_3_HZ 19200000
4031 #define CHT_CODEC_DAI1 "rt5645-aif1"
....@@ -57,6 +48,7 @@
5748 #define CHT_RT5645_SSP2_AIF2 BIT(16) /* default is using AIF1 */
5849 #define CHT_RT5645_SSP0_AIF1 BIT(17)
5950 #define CHT_RT5645_SSP0_AIF2 BIT(18)
51
+#define CHT_RT5645_PMC_PLT_CLK_0 BIT(19)
6052
6153 static unsigned long cht_rt5645_quirk = 0;
6254
....@@ -68,6 +60,8 @@
6860 dev_info(dev, "quirk SSP0_AIF1 enabled");
6961 if (cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2)
7062 dev_info(dev, "quirk SSP0_AIF2 enabled");
63
+ if (cht_rt5645_quirk & CHT_RT5645_PMC_PLT_CLK_0)
64
+ dev_info(dev, "quirk PMC_PLT_CLK_0 enabled");
7165 }
7266
7367 static int platform_clock_control(struct snd_soc_dapm_widget *w,
....@@ -213,8 +207,8 @@
213207 static int cht_aif1_hw_params(struct snd_pcm_substream *substream,
214208 struct snd_pcm_hw_params *params)
215209 {
216
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
217
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
210
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
211
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
218212 int ret;
219213
220214 /* set codec PLL source to the 19.2MHz platform clock (MCLK) */
....@@ -235,15 +229,21 @@
235229 return 0;
236230 }
237231
238
-/* uncomment when we have a real quirk
239232 static int cht_rt5645_quirk_cb(const struct dmi_system_id *id)
240233 {
241234 cht_rt5645_quirk = (unsigned long)id->driver_data;
242235 return 1;
243236 }
244
-*/
245237
246238 static const struct dmi_system_id cht_rt5645_quirk_table[] = {
239
+ {
240
+ /* Strago family Chromebooks */
241
+ .callback = cht_rt5645_quirk_cb,
242
+ .matches = {
243
+ DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_Strago"),
244
+ },
245
+ .driver_data = (void *)CHT_RT5645_PMC_PLT_CLK_0,
246
+ },
247247 {
248248 },
249249 };
....@@ -252,7 +252,7 @@
252252 {
253253 struct snd_soc_card *card = runtime->card;
254254 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card);
255
- struct snd_soc_component *component = runtime->codec_dai->component;
255
+ struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
256256 int jack_type;
257257 int ret;
258258
....@@ -359,7 +359,7 @@
359359 * with explicit setting to I2S 2ch 16-bit. The word length is set with
360360 * dai_set_tdm_slot() since there is no other API exposed
361361 */
362
- ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
362
+ ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
363363 SND_SOC_DAIFMT_I2S |
364364 SND_SOC_DAIFMT_NB_NF |
365365 SND_SOC_DAIFMT_CBS_CFS
....@@ -369,7 +369,7 @@
369369 return ret;
370370 }
371371
372
- ret = snd_soc_dai_set_fmt(rtd->codec_dai,
372
+ ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
373373 SND_SOC_DAIFMT_I2S |
374374 SND_SOC_DAIFMT_NB_NF |
375375 SND_SOC_DAIFMT_CBS_CFS
....@@ -379,7 +379,7 @@
379379 return ret;
380380 }
381381
382
- ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
382
+ ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, 16);
383383 if (ret < 0) {
384384 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
385385 return ret;
....@@ -393,7 +393,7 @@
393393 /*
394394 * Default mode for SSP configuration is TDM 4 slot
395395 */
396
- ret = snd_soc_dai_set_fmt(rtd->codec_dai,
396
+ ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0),
397397 SND_SOC_DAIFMT_DSP_B |
398398 SND_SOC_DAIFMT_IB_NF |
399399 SND_SOC_DAIFMT_CBS_CFS);
....@@ -403,7 +403,7 @@
403403 }
404404
405405 /* TDM 4 slots 24 bit, set Rx & Tx bitmask to 4 active slots */
406
- ret = snd_soc_dai_set_tdm_slot(rtd->codec_dai, 0xF, 0xF, 4, 24);
406
+ ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_codec(rtd, 0), 0xF, 0xF, 4, 24);
407407 if (ret < 0) {
408408 dev_err(rtd->dev, "can't set codec TDM slot %d\n", ret);
409409 return ret;
....@@ -426,54 +426,74 @@
426426 .hw_params = cht_aif1_hw_params,
427427 };
428428
429
+SND_SOC_DAILINK_DEF(dummy,
430
+ DAILINK_COMP_ARRAY(COMP_DUMMY()));
431
+
432
+SND_SOC_DAILINK_DEF(media,
433
+ DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
434
+
435
+SND_SOC_DAILINK_DEF(deepbuffer,
436
+ DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
437
+
438
+SND_SOC_DAILINK_DEF(ssp2_port,
439
+ DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
440
+SND_SOC_DAILINK_DEF(ssp2_codec,
441
+ DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5645:00", "rt5645-aif1")));
442
+
443
+SND_SOC_DAILINK_DEF(platform,
444
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
445
+
429446 static struct snd_soc_dai_link cht_dailink[] = {
430447 [MERR_DPCM_AUDIO] = {
431448 .name = "Audio Port",
432449 .stream_name = "Audio",
433
- .cpu_dai_name = "media-cpu-dai",
434
- .codec_dai_name = "snd-soc-dummy-dai",
435
- .codec_name = "snd-soc-dummy",
436
- .platform_name = "sst-mfld-platform",
437450 .nonatomic = true,
438451 .dynamic = 1,
439452 .dpcm_playback = 1,
440453 .dpcm_capture = 1,
441454 .ops = &cht_aif1_ops,
455
+ SND_SOC_DAILINK_REG(media, dummy, platform),
442456 },
443457 [MERR_DPCM_DEEP_BUFFER] = {
444458 .name = "Deep-Buffer Audio Port",
445459 .stream_name = "Deep-Buffer Audio",
446
- .cpu_dai_name = "deepbuffer-cpu-dai",
447
- .codec_dai_name = "snd-soc-dummy-dai",
448
- .codec_name = "snd-soc-dummy",
449
- .platform_name = "sst-mfld-platform",
450460 .nonatomic = true,
451461 .dynamic = 1,
452462 .dpcm_playback = 1,
453463 .ops = &cht_aif1_ops,
464
+ SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
454465 },
455466 /* CODEC<->CODEC link */
456467 /* back ends */
457468 {
458469 .name = "SSP2-Codec",
459470 .id = 0,
460
- .cpu_dai_name = "ssp2-port",
461
- .platform_name = "sst-mfld-platform",
462471 .no_pcm = 1,
463
- .codec_dai_name = "rt5645-aif1",
464
- .codec_name = "i2c-10EC5645:00",
465472 .init = cht_codec_init,
466473 .be_hw_params_fixup = cht_codec_fixup,
467474 .nonatomic = true,
468475 .dpcm_playback = 1,
469476 .dpcm_capture = 1,
470477 .ops = &cht_be_ssp2_ops,
478
+ SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
471479 },
472480 };
473481
482
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
483
+/* use space before codec name to simplify card ID, and simplify driver name */
484
+#define CARD_RT5645_NAME "bytcht rt5645" /* card name 'sof-bytcht rt5645' */
485
+#define CARD_RT5650_NAME "bytcht rt5650" /* card name 'sof-bytcht rt5650' */
486
+#define DRIVER_NAME "SOF"
487
+#else
488
+#define CARD_RT5645_NAME "chtrt5645"
489
+#define CARD_RT5650_NAME "chtrt5650"
490
+#define DRIVER_NAME NULL /* card name will be used for driver name */
491
+#endif
492
+
474493 /* SoC card */
475494 static struct snd_soc_card snd_soc_card_chtrt5645 = {
476
- .name = "chtrt5645",
495
+ .name = CARD_RT5645_NAME,
496
+ .driver_name = DRIVER_NAME,
477497 .owner = THIS_MODULE,
478498 .dai_link = cht_dailink,
479499 .num_links = ARRAY_SIZE(cht_dailink),
....@@ -486,7 +506,8 @@
486506 };
487507
488508 static struct snd_soc_card snd_soc_card_chtrt5650 = {
489
- .name = "chtrt5650",
509
+ .name = CARD_RT5650_NAME,
510
+ .driver_name = DRIVER_NAME,
490511 .owner = THIS_MODULE,
491512 .dai_link = cht_dailink,
492513 .num_links = ARRAY_SIZE(cht_dailink),
....@@ -507,20 +528,6 @@
507528 };
508529
509530 static char cht_rt5645_codec_name[SND_ACPI_I2C_ID_LEN];
510
-static char cht_rt5645_codec_aif_name[12]; /* = "rt5645-aif[1|2]" */
511
-static char cht_rt5645_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
512
-
513
-static bool is_valleyview(void)
514
-{
515
- static const struct x86_cpu_id cpu_ids[] = {
516
- { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
517
- {}
518
- };
519
-
520
- if (!x86_match_cpu(cpu_ids))
521
- return false;
522
- return true;
523
-}
524531
525532 struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
526533 u64 aif_value; /* 1: AIF1, 2: AIF2 */
....@@ -531,19 +538,21 @@
531538 {
532539 struct snd_soc_card *card = snd_soc_cards[0].soc_card;
533540 struct snd_soc_acpi_mach *mach;
541
+ const char *platform_name;
534542 struct cht_mc_private *drv;
535
- const char *i2c_name = NULL;
543
+ struct acpi_device *adev;
536544 bool found = false;
537545 bool is_bytcr = false;
538546 int dai_index = 0;
539547 int ret_val = 0;
540548 int i;
549
+ const char *mclk_name;
541550
542551 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
543552 if (!drv)
544553 return -ENOMEM;
545554
546
- mach = (&pdev->dev)->platform_data;
555
+ mach = pdev->dev.platform_data;
547556
548557 for (i = 0; i < ARRAY_SIZE(snd_soc_cards); i++) {
549558 if (acpi_dev_found(snd_soc_cards[i].codec_id) &&
....@@ -567,28 +576,27 @@
567576
568577 /* set correct codec name */
569578 for (i = 0; i < ARRAY_SIZE(cht_dailink); i++)
570
- if (!strcmp(card->dai_link[i].codec_name, "i2c-10EC5645:00")) {
571
- card->dai_link[i].codec_name = drv->codec_name;
579
+ if (!strcmp(card->dai_link[i].codecs->name,
580
+ "i2c-10EC5645:00")) {
581
+ card->dai_link[i].codecs->name = drv->codec_name;
572582 dai_index = i;
573583 }
574584
575585 /* fixup codec name based on HID */
576
- i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1);
577
- if (i2c_name) {
586
+ adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
587
+ if (adev) {
578588 snprintf(cht_rt5645_codec_name, sizeof(cht_rt5645_codec_name),
579
- "%s%s", "i2c-", i2c_name);
580
- cht_dailink[dai_index].codec_name = cht_rt5645_codec_name;
589
+ "i2c-%s", acpi_dev_name(adev));
590
+ put_device(&adev->dev);
591
+ cht_dailink[dai_index].codecs->name = cht_rt5645_codec_name;
581592 }
582593
583594 /*
584595 * swap SSP0 if bytcr is detected
585596 * (will be overridden if DMI quirk is detected)
586597 */
587
- if (is_valleyview()) {
588
- struct sst_platform_info *p_info = mach->pdata;
589
- const struct sst_res_info *res_info = p_info->res_info;
590
-
591
- if (res_info->acpi_ipc_irq_index == 0)
598
+ if (soc_intel_is_byt()) {
599
+ if (mach->mach_params.acpi_ipc_irq_index == 0)
592600 is_bytcr = true;
593601 }
594602
....@@ -644,34 +652,30 @@
644652 log_quirks(&pdev->dev);
645653
646654 if ((cht_rt5645_quirk & CHT_RT5645_SSP2_AIF2) ||
647
- (cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2)) {
648
-
649
- /* fixup codec aif name */
650
- snprintf(cht_rt5645_codec_aif_name,
651
- sizeof(cht_rt5645_codec_aif_name),
652
- "%s", "rt5645-aif2");
653
-
654
- cht_dailink[dai_index].codec_dai_name =
655
- cht_rt5645_codec_aif_name;
656
- }
655
+ (cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2))
656
+ cht_dailink[dai_index].codecs->dai_name = "rt5645-aif2";
657657
658658 if ((cht_rt5645_quirk & CHT_RT5645_SSP0_AIF1) ||
659
- (cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2)) {
659
+ (cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2))
660
+ cht_dailink[dai_index].cpus->dai_name = "ssp0-port";
660661
661
- /* fixup cpu dai name name */
662
- snprintf(cht_rt5645_cpu_dai_name,
663
- sizeof(cht_rt5645_cpu_dai_name),
664
- "%s", "ssp0-port");
662
+ /* override plaform name, if required */
663
+ platform_name = mach->mach_params.platform;
665664
666
- cht_dailink[dai_index].cpu_dai_name =
667
- cht_rt5645_cpu_dai_name;
668
- }
665
+ ret_val = snd_soc_fixup_dai_links_platform_name(card,
666
+ platform_name);
667
+ if (ret_val)
668
+ return ret_val;
669669
670
- drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
670
+ if (cht_rt5645_quirk & CHT_RT5645_PMC_PLT_CLK_0)
671
+ mclk_name = "pmc_plt_clk_0";
672
+ else
673
+ mclk_name = "pmc_plt_clk_3";
674
+
675
+ drv->mclk = devm_clk_get(&pdev->dev, mclk_name);
671676 if (IS_ERR(drv->mclk)) {
672
- dev_err(&pdev->dev,
673
- "Failed to get MCLK from pmc_plt_clk_3: %ld\n",
674
- PTR_ERR(drv->mclk));
677
+ dev_err(&pdev->dev, "Failed to get MCLK from %s: %ld\n",
678
+ mclk_name, PTR_ERR(drv->mclk));
675679 return PTR_ERR(drv->mclk);
676680 }
677681
....@@ -689,6 +693,9 @@
689693 static struct platform_driver snd_cht_mc_driver = {
690694 .driver = {
691695 .name = "cht-bsw-rt5645",
696
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
697
+ .pm = &snd_soc_pm_ops,
698
+#endif
692699 },
693700 .probe = snd_cht_mc_probe,
694701 };