forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/intel/boards/cht_bsw_max98090_ti.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * cht-bsw-max98090.c - ASoc Machine driver for Intel Cherryview-based
34 * platforms Cherrytrail and Braswell, with max98090 & TI codec.
....@@ -7,19 +8,11 @@
78 * This file is modified from cht_bsw_rt5645.c
89 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
910 *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; version 2 of the License.
13
- *
14
- * This program is distributed in the hope that it will be useful, but
15
- * WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- * General Public License for more details.
18
- *
1911 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2012 */
2113
2214 #include <linux/dmi.h>
15
+#include <linux/gpio/consumer.h>
2316 #include <linux/module.h>
2417 #include <linux/platform_device.h>
2518 #include <linux/slab.h>
....@@ -28,6 +21,7 @@
2821 #include <sound/pcm.h>
2922 #include <sound/pcm_params.h>
3023 #include <sound/soc.h>
24
+#include <sound/soc-acpi.h>
3125 #include <sound/jack.h>
3226 #include "../../codecs/max98090.h"
3327 #include "../atom/sst-atom-controls.h"
....@@ -118,8 +112,8 @@
118112 static int cht_aif1_hw_params(struct snd_pcm_substream *substream,
119113 struct snd_pcm_hw_params *params)
120114 {
121
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
122
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
115
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
116
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
123117 int ret;
124118
125119 ret = snd_soc_dai_set_sysclk(codec_dai, M98090_REG_SYSTEM_CLOCK,
....@@ -263,7 +257,7 @@
263257 int ret = 0;
264258 unsigned int fmt = 0;
265259
266
- ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
260
+ ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, 16);
267261 if (ret < 0) {
268262 dev_err(rtd->dev, "can't set cpu_dai slot fmt: %d\n", ret);
269263 return ret;
....@@ -272,7 +266,7 @@
272266 fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
273267 | SND_SOC_DAIFMT_CBS_CFS;
274268
275
- ret = snd_soc_dai_set_fmt(rtd->cpu_dai, fmt);
269
+ ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0), fmt);
276270 if (ret < 0) {
277271 dev_err(rtd->dev, "can't set cpu_dai set fmt: %d\n", ret);
278272 return ret;
....@@ -331,46 +325,52 @@
331325 };
332326
333327 static struct snd_soc_aux_dev cht_max98090_headset_dev = {
334
- .name = "Headset Chip",
328
+ .dlc = COMP_AUX("i2c-104C227E:00"),
335329 .init = cht_max98090_headset_init,
336
- .codec_name = "i2c-104C227E:00",
337330 };
331
+
332
+SND_SOC_DAILINK_DEF(dummy,
333
+ DAILINK_COMP_ARRAY(COMP_DUMMY()));
334
+
335
+SND_SOC_DAILINK_DEF(media,
336
+ DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
337
+
338
+SND_SOC_DAILINK_DEF(deepbuffer,
339
+ DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
340
+
341
+SND_SOC_DAILINK_DEF(ssp2_port,
342
+ DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
343
+SND_SOC_DAILINK_DEF(ssp2_codec,
344
+ DAILINK_COMP_ARRAY(COMP_CODEC("i2c-193C9890:00", "HiFi")));
345
+
346
+SND_SOC_DAILINK_DEF(platform,
347
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
338348
339349 static struct snd_soc_dai_link cht_dailink[] = {
340350 [MERR_DPCM_AUDIO] = {
341351 .name = "Audio Port",
342352 .stream_name = "Audio",
343
- .cpu_dai_name = "media-cpu-dai",
344
- .codec_dai_name = "snd-soc-dummy-dai",
345
- .codec_name = "snd-soc-dummy",
346
- .platform_name = "sst-mfld-platform",
347353 .nonatomic = true,
348354 .dynamic = 1,
349355 .dpcm_playback = 1,
350356 .dpcm_capture = 1,
351357 .ops = &cht_aif1_ops,
358
+ SND_SOC_DAILINK_REG(media, dummy, platform),
352359 },
353360 [MERR_DPCM_DEEP_BUFFER] = {
354361 .name = "Deep-Buffer Audio Port",
355362 .stream_name = "Deep-Buffer Audio",
356
- .cpu_dai_name = "deepbuffer-cpu-dai",
357
- .codec_dai_name = "snd-soc-dummy-dai",
358
- .codec_name = "snd-soc-dummy",
359
- .platform_name = "sst-mfld-platform",
360363 .nonatomic = true,
361364 .dynamic = 1,
362365 .dpcm_playback = 1,
363366 .ops = &cht_aif1_ops,
367
+ SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
364368 },
365369 /* back ends */
366370 {
367371 .name = "SSP2-Codec",
368372 .id = 0,
369
- .cpu_dai_name = "ssp2-port",
370
- .platform_name = "sst-mfld-platform",
371373 .no_pcm = 1,
372
- .codec_dai_name = "HiFi",
373
- .codec_name = "i2c-193C9890:00",
374374 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
375375 | SND_SOC_DAIFMT_CBS_CFS,
376376 .init = cht_codec_init,
....@@ -378,12 +378,23 @@
378378 .dpcm_playback = 1,
379379 .dpcm_capture = 1,
380380 .ops = &cht_be_ssp2_ops,
381
+ SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
381382 },
382383 };
383384
385
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
386
+/* use space before codec name to simplify card ID, and simplify driver name */
387
+#define CARD_NAME "bytcht max98090" /* card name will be 'sof-bytcht max98090 */
388
+#define DRIVER_NAME "SOF"
389
+#else
390
+#define CARD_NAME "chtmax98090"
391
+#define DRIVER_NAME NULL /* card name will be used for driver name */
392
+#endif
393
+
384394 /* SoC card */
385395 static struct snd_soc_card snd_soc_card_cht = {
386
- .name = "chtmax98090",
396
+ .name = CARD_NAME,
397
+ .driver_name = DRIVER_NAME,
387398 .owner = THIS_MODULE,
388399 .dai_link = cht_dailink,
389400 .num_links = ARRAY_SIZE(cht_dailink),
....@@ -399,9 +410,44 @@
399410
400411 static const struct dmi_system_id cht_max98090_quirk_table[] = {
401412 {
413
+ /* Banjo model Chromebook */
414
+ .matches = {
415
+ DMI_MATCH(DMI_PRODUCT_NAME, "Banjo"),
416
+ },
417
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
418
+ },
419
+ {
420
+ /* Candy model Chromebook */
421
+ .matches = {
422
+ DMI_MATCH(DMI_PRODUCT_NAME, "Candy"),
423
+ },
424
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
425
+ },
426
+ {
402427 /* Clapper model Chromebook */
403428 .matches = {
404429 DMI_MATCH(DMI_PRODUCT_NAME, "Clapper"),
430
+ },
431
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
432
+ },
433
+ {
434
+ /* Cyan model Chromebook */
435
+ .matches = {
436
+ DMI_MATCH(DMI_PRODUCT_NAME, "Cyan"),
437
+ },
438
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
439
+ },
440
+ {
441
+ /* Enguarde model Chromebook */
442
+ .matches = {
443
+ DMI_MATCH(DMI_PRODUCT_NAME, "Enguarde"),
444
+ },
445
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
446
+ },
447
+ {
448
+ /* Glimmer model Chromebook */
449
+ .matches = {
450
+ DMI_MATCH(DMI_PRODUCT_NAME, "Glimmer"),
405451 },
406452 .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
407453 },
....@@ -413,9 +459,72 @@
413459 .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
414460 },
415461 {
462
+ /* Heli model Chromebook */
463
+ .matches = {
464
+ DMI_MATCH(DMI_PRODUCT_NAME, "Heli"),
465
+ },
466
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
467
+ },
468
+ {
469
+ /* Kip model Chromebook */
470
+ .matches = {
471
+ DMI_MATCH(DMI_PRODUCT_NAME, "Kip"),
472
+ },
473
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
474
+ },
475
+ {
476
+ /* Ninja model Chromebook */
477
+ .matches = {
478
+ DMI_MATCH(DMI_PRODUCT_NAME, "Ninja"),
479
+ },
480
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
481
+ },
482
+ {
483
+ /* Orco model Chromebook */
484
+ .matches = {
485
+ DMI_MATCH(DMI_PRODUCT_NAME, "Orco"),
486
+ },
487
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
488
+ },
489
+ {
490
+ /* Quawks model Chromebook */
491
+ .matches = {
492
+ DMI_MATCH(DMI_PRODUCT_NAME, "Quawks"),
493
+ },
494
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
495
+ },
496
+ {
497
+ /* Rambi model Chromebook */
498
+ .matches = {
499
+ DMI_MATCH(DMI_PRODUCT_NAME, "Rambi"),
500
+ },
501
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
502
+ },
503
+ {
504
+ /* Squawks model Chromebook */
505
+ .matches = {
506
+ DMI_MATCH(DMI_PRODUCT_NAME, "Squawks"),
507
+ },
508
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
509
+ },
510
+ {
511
+ /* Sumo model Chromebook */
512
+ .matches = {
513
+ DMI_MATCH(DMI_PRODUCT_NAME, "Sumo"),
514
+ },
515
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
516
+ },
517
+ {
416518 /* Swanky model Chromebook (Toshiba Chromebook 2) */
417519 .matches = {
418520 DMI_MATCH(DMI_PRODUCT_NAME, "Swanky"),
521
+ },
522
+ .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
523
+ },
524
+ {
525
+ /* Winky model Chromebook */
526
+ .matches = {
527
+ DMI_MATCH(DMI_PRODUCT_NAME, "Winky"),
419528 },
420529 .driver_data = (void *)QUIRK_PMC_PLT_CLK_0,
421530 },
....@@ -429,6 +538,8 @@
429538 int ret_val = 0;
430539 struct cht_mc_private *drv;
431540 const char *mclk_name;
541
+ struct snd_soc_acpi_mach *mach;
542
+ const char *platform_name;
432543
433544 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
434545 if (!drv)
....@@ -450,8 +561,17 @@
450561 dev_dbg(dev, "Unable to add GPIO mapping table\n");
451562 }
452563
453
- /* register the soc card */
564
+ /* override plaform name, if required */
454565 snd_soc_card_cht.dev = &pdev->dev;
566
+ mach = pdev->dev.platform_data;
567
+ platform_name = mach->mach_params.platform;
568
+
569
+ ret_val = snd_soc_fixup_dai_links_platform_name(&snd_soc_card_cht,
570
+ platform_name);
571
+ if (ret_val)
572
+ return ret_val;
573
+
574
+ /* register the soc card */
455575 snd_soc_card_set_drvdata(&snd_soc_card_cht, drv);
456576
457577 if (drv->quirks & QUIRK_PMC_PLT_CLK_0)
....@@ -506,6 +626,9 @@
506626 static struct platform_driver snd_cht_mc_driver = {
507627 .driver = {
508628 .name = "cht-bsw-max98090",
629
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
630
+ .pm = &snd_soc_pm_ops,
631
+#endif
509632 },
510633 .probe = snd_cht_mc_probe,
511634 .remove = snd_cht_mc_remove,