Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: mediatek: mt8195: Migrate to mtk_soundcard_common_probe

Add mtk_soundcard_pdata platform data for the MediaTek common sound card
probe mechanism, including a driver/soc-specific probe extension (used
for bits that cannot be commonized hence specific to this driver), and
change the probe function to mtk_soundcard_common_probe.

This is also adding the possibility of specifying the links and routing
with the audio-routing property and (x)-dai-link nodes in device trees
to stop hardcoding machine specific links in the card driver assupported
by the common probe function, but support for legacy device trees is
retained with a legacy_probe function, which is used only in case the
new properties are not found.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20240416071410.75620-5-angelogioacchino.delregno@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

AngeloGioacchino Del Regno and committed by
Mark Brown
6718e1ed aad45b8a

+161 -135
+161 -135
sound/soc/mediatek/mt8195/mt8195-mt6359.c
··· 22 22 #include "../common/mtk-afe-platform-driver.h" 23 23 #include "../common/mtk-dsp-sof-common.h" 24 24 #include "../common/mtk-soc-card.h" 25 + #include "../common/mtk-soundcard-driver.h" 25 26 #include "mt8195-afe-clk.h" 26 27 #include "mt8195-afe-common.h" 27 28 28 29 #define RT1011_SPEAKER_AMP_PRESENT BIT(0) 29 30 #define RT1019_SPEAKER_AMP_PRESENT BIT(1) 30 31 #define MAX98390_SPEAKER_AMP_PRESENT BIT(2) 32 + 33 + #define DUMB_CODEC_INIT BIT(0) 34 + #define MT6359_CODEC_INIT BIT(1) 35 + #define RT1011_CODEC_INIT BIT(2) 36 + #define RT1019_CODEC_INIT BIT(3) 37 + #define MAX98390_CODEC_INIT BIT(4) 38 + #define RT5682_CODEC_INIT BIT(5) 31 39 32 40 #define RT1011_CODEC_DAI "rt1011-aif" 33 41 #define RT1011_DEV0_NAME "rt1011.2-0038" ··· 59 51 #define SOF_DMA_UL4 "SOF_DMA_UL4" 60 52 #define SOF_DMA_UL5 "SOF_DMA_UL5" 61 53 62 - struct mt8195_card_data { 63 - const char *name; 64 - unsigned long quirk; 54 + struct mt8195_mt6359_priv { 55 + struct clk *i2so1_mclk; 65 56 }; 66 57 67 - struct mt8195_mt6359_priv { 68 - struct snd_soc_jack headset_jack; 69 - struct snd_soc_jack dp_jack; 70 - struct snd_soc_jack hdmi_jack; 71 - struct clk *i2so1_mclk; 58 + enum mt8195_jacks { 59 + MT8195_JACK_HEADSET, 60 + MT8195_JACK_DP, 61 + MT8195_JACK_HDMI, 62 + MT8195_JACK_MAX, 72 63 }; 73 64 74 65 /* Headset jack detection DAPM pins */ ··· 389 382 static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) 390 383 { 391 384 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 392 - struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 385 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_DP]; 393 386 struct snd_soc_component *cmpnt_codec = 394 387 snd_soc_rtd_to_codec(rtd, 0)->component; 395 388 int ret; 396 389 397 - ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, 398 - &priv->dp_jack); 390 + ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, jack); 399 391 if (ret) 400 392 return ret; 401 393 402 - return snd_soc_component_set_jack(cmpnt_codec, &priv->dp_jack, NULL); 394 + return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 403 395 } 404 396 405 397 static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) 406 398 { 407 399 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 408 - struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 400 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HDMI]; 409 401 struct snd_soc_component *cmpnt_codec = 410 402 snd_soc_rtd_to_codec(rtd, 0)->component; 411 403 int ret; 412 404 413 - ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, 414 - &priv->hdmi_jack); 405 + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack); 415 406 if (ret) 416 407 return ret; 417 408 418 - return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); 409 + return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 419 410 } 420 411 421 412 static int mt8195_dptx_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, ··· 571 566 snd_soc_rtd_to_codec(rtd, 0)->component; 572 567 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 573 568 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 574 - struct snd_soc_jack *jack = &priv->headset_jack; 569 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HEADSET]; 575 570 struct snd_soc_component *cmpnt_afe = 576 571 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 577 572 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); ··· 692 687 return ret; 693 688 } 694 689 695 - static int mt8195_rt1019_init(struct snd_soc_pcm_runtime *rtd) 690 + static int mt8195_dumb_amp_init(struct snd_soc_pcm_runtime *rtd) 696 691 { 697 692 struct snd_soc_card *card = rtd->card; 698 693 int ret; ··· 711 706 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); 712 707 return ret; 713 708 } 709 + 710 + return 0; 711 + } 712 + 713 + static int mt8195_rt1019_init(struct snd_soc_pcm_runtime *rtd) 714 + { 715 + struct snd_soc_card *card = rtd->card; 716 + int ret; 717 + 718 + ret = mt8195_dumb_amp_init(rtd); 719 + if (ret) 720 + return ret; 714 721 715 722 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes, 716 723 ARRAY_SIZE(mt8195_rt1019_routes)); ··· 1388 1371 return ret; 1389 1372 } 1390 1373 1391 - static int mt8195_mt6359_dev_probe(struct platform_device *pdev) 1374 + static int mt8195_mt6359_legacy_probe(struct mtk_soc_card_data *soc_card_data) 1392 1375 { 1393 - struct snd_soc_card *card = &mt8195_mt6359_soc_card; 1376 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1377 + struct snd_soc_card *card = card_data->card; 1378 + struct device_node *codec_node, *dp_node, *hdmi_node; 1394 1379 struct snd_soc_dai_link *dai_link; 1395 - struct mtk_soc_card_data *soc_card_data; 1396 - struct mt8195_mt6359_priv *mach_priv; 1397 - struct device_node *platform_node, *adsp_node, *codec_node, *dp_node, *hdmi_node; 1398 - struct mt8195_card_data *card_data; 1399 - int is5682s = 0; 1400 - int init6359 = 0; 1401 - int sof_on = 0; 1402 - int ret, i; 1403 - 1404 - card_data = (struct mt8195_card_data *)of_device_get_match_data(&pdev->dev); 1405 - card->dev = &pdev->dev; 1406 - 1407 - ret = snd_soc_of_parse_card_name(card, "model"); 1408 - if (ret) { 1409 - dev_err(&pdev->dev, "%s new card name parsing error %d\n", 1410 - __func__, ret); 1411 - return ret; 1412 - } 1413 - 1414 - if (!card->name) 1415 - card->name = card_data->name; 1380 + struct device *dev = card->dev; 1381 + bool is5682s, init6359 = false; 1382 + int i; 1416 1383 1417 1384 if (strstr(card->name, "_5682s")) { 1418 1385 codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682s"); 1419 - is5682s = 1; 1420 - } else 1421 - codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682i"); 1422 - 1423 - soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*card_data), GFP_KERNEL); 1424 - if (!soc_card_data) 1425 - return -ENOMEM; 1426 - 1427 - mach_priv = devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL); 1428 - if (!mach_priv) 1429 - return -ENOMEM; 1430 - 1431 - soc_card_data->mach_priv = mach_priv; 1432 - 1433 - adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); 1434 - if (adsp_node) { 1435 - struct mtk_sof_priv *sof_priv; 1436 - 1437 - sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); 1438 - if (!sof_priv) { 1439 - ret = -ENOMEM; 1440 - goto err_kzalloc; 1441 - } 1442 - sof_priv->conn_streams = g_sof_conn_streams; 1443 - sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams); 1444 - sof_priv->sof_dai_link_fixup = mt8195_dai_link_fixup; 1445 - soc_card_data->sof_priv = sof_priv; 1446 - card->probe = mtk_sof_card_probe; 1447 - card->late_probe = mtk_sof_card_late_probe; 1448 - if (!card->topology_shortname_created) { 1449 - snprintf(card->topology_shortname, 32, "sof-%s", card->name); 1450 - card->topology_shortname_created = true; 1451 - } 1452 - card->name = card->topology_shortname; 1453 - sof_on = 1; 1454 - } 1455 - 1456 - if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { 1457 - ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, 1458 - "mediatek,dai-link", 1459 - mt8195_mt6359_dai_links, 1460 - ARRAY_SIZE(mt8195_mt6359_dai_links)); 1461 - if (ret) { 1462 - dev_dbg(&pdev->dev, "Parse dai-link fail\n"); 1463 - goto err_parse_of; 1464 - } 1386 + is5682s = true; 1465 1387 } else { 1466 - if (!sof_on) 1467 - card->num_links = DAI_LINK_REGULAR_NUM; 1388 + codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682i"); 1389 + is5682s = false; 1468 1390 } 1469 1391 1470 - platform_node = of_parse_phandle(pdev->dev.of_node, 1471 - "mediatek,platform", 0); 1472 - if (!platform_node) { 1473 - dev_dbg(&pdev->dev, "Property 'platform' missing or invalid\n"); 1474 - ret = -EINVAL; 1475 - goto err_platform_node; 1476 - } 1477 - 1478 - dp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,dptx-codec", 0); 1479 - hdmi_node = of_parse_phandle(pdev->dev.of_node, 1480 - "mediatek,hdmi-codec", 0); 1392 + dp_node = of_parse_phandle(dev->of_node, "mediatek,dptx-codec", 0); 1393 + hdmi_node = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0); 1481 1394 1482 1395 for_each_card_prelinks(card, i, dai_link) { 1483 - if (!dai_link->platforms->name) { 1484 - if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on) 1485 - dai_link->platforms->of_node = adsp_node; 1486 - else 1487 - dai_link->platforms->of_node = platform_node; 1488 - } 1489 - 1490 1396 if (strcmp(dai_link->name, "DPTX_BE") == 0) { 1491 1397 if (!dp_node) { 1492 - dev_dbg(&pdev->dev, "No property 'dptx-codec'\n"); 1398 + dev_dbg(dev, "No property 'dptx-codec'\n"); 1493 1399 } else { 1494 1400 dai_link->codecs->of_node = dp_node; 1495 1401 dai_link->codecs->name = NULL; ··· 1421 1481 } 1422 1482 } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { 1423 1483 if (!hdmi_node) { 1424 - dev_dbg(&pdev->dev, "No property 'hdmi-codec'\n"); 1484 + dev_dbg(dev, "No property 'hdmi-codec'\n"); 1425 1485 } else { 1426 1486 dai_link->codecs->of_node = hdmi_node; 1427 1487 dai_link->codecs->name = NULL; ··· 1430 1490 } 1431 1491 } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0) { 1432 1492 if (!codec_node) { 1433 - dev_err(&pdev->dev, "Codec not found!\n"); 1493 + dev_err(dev, "Codec not found!\n"); 1434 1494 } else { 1435 1495 dai_link->codecs->of_node = codec_node; 1436 1496 dai_link->codecs->name = NULL; ··· 1441 1501 } 1442 1502 } else if (strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { 1443 1503 if (!codec_node) { 1444 - dev_err(&pdev->dev, "Codec not found!\n"); 1504 + dev_err(dev, "Codec not found!\n"); 1445 1505 } else { 1446 1506 dai_link->codecs->of_node = codec_node; 1447 1507 dai_link->codecs->name = NULL; ··· 1454 1514 strcmp(dai_link->name, "UL_SRC2_BE") == 0) { 1455 1515 if (!init6359) { 1456 1516 dai_link->init = mt8195_mt6359_init; 1457 - init6359 = 1; 1517 + init6359 = true; 1458 1518 } 1459 1519 } else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) { 1460 - switch (card_data->quirk) { 1520 + switch (card_data->flags) { 1461 1521 case RT1011_SPEAKER_AMP_PRESENT: 1462 1522 dai_link->codecs = rt1011_comps; 1463 1523 dai_link->num_codecs = ARRAY_SIZE(rt1011_comps); ··· 1485 1545 } 1486 1546 } 1487 1547 1488 - snd_soc_card_set_drvdata(card, soc_card_data); 1489 - 1490 - ret = devm_snd_soc_register_card(&pdev->dev, card); 1491 - 1492 - of_node_put(platform_node); 1493 - of_node_put(dp_node); 1494 - of_node_put(hdmi_node); 1495 - err_kzalloc: 1496 - err_parse_of: 1497 - err_platform_node: 1498 - of_node_put(adsp_node); 1499 - return ret; 1548 + return 0; 1500 1549 } 1501 1550 1502 - static struct mt8195_card_data mt8195_mt6359_rt1019_rt5682_card = { 1503 - .name = "mt8195_r1019_5682", 1504 - .quirk = RT1019_SPEAKER_AMP_PRESENT, 1551 + static int mt8195_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) 1552 + { 1553 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1554 + struct snd_soc_card *card = card_data->card; 1555 + struct mt8195_mt6359_priv *mach_priv; 1556 + struct snd_soc_dai_link *dai_link; 1557 + u8 codec_init = 0; 1558 + int i; 1559 + 1560 + mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL); 1561 + if (!mach_priv) 1562 + return -ENOMEM; 1563 + 1564 + soc_card_data->mach_priv = mach_priv; 1565 + 1566 + if (legacy) 1567 + return mt8195_mt6359_legacy_probe(soc_card_data); 1568 + 1569 + for_each_card_prelinks(card, i, dai_link) { 1570 + if (strcmp(dai_link->name, "DPTX_BE") == 0) { 1571 + if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) 1572 + dai_link->init = mt8195_dptx_codec_init; 1573 + } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { 1574 + if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) 1575 + dai_link->init = mt8195_hdmi_codec_init; 1576 + } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || 1577 + strcmp(dai_link->name, "UL_SRC1_BE") == 0 || 1578 + strcmp(dai_link->name, "UL_SRC2_BE") == 0) { 1579 + if (!(codec_init & MT6359_CODEC_INIT)) { 1580 + dai_link->init = mt8195_mt6359_init; 1581 + codec_init |= MT6359_CODEC_INIT; 1582 + } 1583 + } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 || 1584 + strcmp(dai_link->name, "ETDM2_OUT_BE") == 0 || 1585 + strcmp(dai_link->name, "ETDM1_IN_BE") == 0 || 1586 + strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { 1587 + if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) { 1588 + if (!(codec_init & MAX98390_CODEC_INIT)) { 1589 + dai_link->init = mt8195_max98390_init; 1590 + codec_init |= MAX98390_CODEC_INIT; 1591 + } 1592 + } else if (!strcmp(dai_link->codecs->dai_name, RT1011_CODEC_DAI)) { 1593 + dai_link->ops = &mt8195_rt1011_etdm_ops; 1594 + if (!(codec_init & RT1011_CODEC_INIT)) { 1595 + dai_link->init = mt8195_rt1011_init; 1596 + codec_init |= RT1011_CODEC_INIT; 1597 + } 1598 + } else if (!strcmp(dai_link->codecs->dai_name, RT1019_CODEC_DAI)) { 1599 + if (!(codec_init & RT1019_CODEC_INIT)) { 1600 + dai_link->init = mt8195_rt1019_init; 1601 + codec_init |= RT1019_CODEC_INIT; 1602 + } 1603 + } else if (!strcmp(dai_link->codecs->dai_name, RT5682_CODEC_DAI) || 1604 + !strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) { 1605 + dai_link->ops = &mt8195_rt5682_etdm_ops; 1606 + if (!(codec_init & RT5682_CODEC_INIT)) { 1607 + dai_link->init = mt8195_rt5682_init; 1608 + codec_init |= RT5682_CODEC_INIT; 1609 + } 1610 + } else { 1611 + if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) { 1612 + if (!(codec_init & DUMB_CODEC_INIT)) { 1613 + dai_link->init = mt8195_dumb_amp_init; 1614 + codec_init |= DUMB_CODEC_INIT; 1615 + } 1616 + } 1617 + } 1618 + } 1619 + } 1620 + 1621 + return 0; 1622 + } 1623 + 1624 + static const struct mtk_sof_priv mt8195_sof_priv = { 1625 + .conn_streams = g_sof_conn_streams, 1626 + .num_streams = ARRAY_SIZE(g_sof_conn_streams), 1627 + .sof_dai_link_fixup = mt8195_dai_link_fixup 1505 1628 }; 1506 1629 1507 - static struct mt8195_card_data mt8195_mt6359_rt1011_rt5682_card = { 1508 - .name = "mt8195_r1011_5682", 1509 - .quirk = RT1011_SPEAKER_AMP_PRESENT, 1630 + static const struct mtk_soundcard_pdata mt8195_mt6359_rt1019_rt5682_card = { 1631 + .card_name = "mt8195_r1019_5682", 1632 + .card_data = &(struct mtk_platform_card_data) { 1633 + .card = &mt8195_mt6359_soc_card, 1634 + .num_jacks = MT8195_JACK_MAX, 1635 + .flags = RT1019_SPEAKER_AMP_PRESENT 1636 + }, 1637 + .sof_priv = &mt8195_sof_priv, 1638 + .soc_probe = mt8195_mt6359_soc_card_probe 1510 1639 }; 1511 1640 1512 - static struct mt8195_card_data mt8195_mt6359_max98390_rt5682_card = { 1513 - .name = "mt8195_m98390_r5682", 1514 - .quirk = MAX98390_SPEAKER_AMP_PRESENT, 1641 + static const struct mtk_soundcard_pdata mt8195_mt6359_rt1011_rt5682_card = { 1642 + .card_name = "mt8195_r1011_5682", 1643 + .card_data = &(struct mtk_platform_card_data) { 1644 + .card = &mt8195_mt6359_soc_card, 1645 + .num_jacks = MT8195_JACK_MAX, 1646 + .flags = RT1011_SPEAKER_AMP_PRESENT 1647 + }, 1648 + .sof_priv = &mt8195_sof_priv, 1649 + .soc_probe = mt8195_mt6359_soc_card_probe 1650 + }; 1651 + 1652 + static const struct mtk_soundcard_pdata mt8195_mt6359_max98390_rt5682_card = { 1653 + .card_name = "mt8195_m98390_r5682", 1654 + .card_data = &(struct mtk_platform_card_data) { 1655 + .card = &mt8195_mt6359_soc_card, 1656 + .num_jacks = MT8195_JACK_MAX, 1657 + .flags = MAX98390_SPEAKER_AMP_PRESENT 1658 + }, 1659 + .sof_priv = &mt8195_sof_priv, 1660 + .soc_probe = mt8195_mt6359_soc_card_probe 1515 1661 }; 1516 1662 1517 1663 static const struct of_device_id mt8195_mt6359_dt_match[] = { ··· 1623 1597 .of_match_table = mt8195_mt6359_dt_match, 1624 1598 .pm = &snd_soc_pm_ops, 1625 1599 }, 1626 - .probe = mt8195_mt6359_dev_probe, 1600 + .probe = mtk_soundcard_common_probe, 1627 1601 }; 1628 1602 1629 1603 module_platform_driver(mt8195_mt6359_driver);