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: mt8188: 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.

Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20240416071410.75620-4-angelogioacchino.delregno@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

AngeloGioacchino Del Regno and committed by
Mark Brown
aad45b8a f8782f77

+64 -139
+64 -139
sound/soc/mediatek/mt8188/mt8188-mt6359.c
··· 236 236 }, 237 237 }; 238 238 239 - struct mt8188_mt6359_priv { 240 - struct snd_soc_jack dp_jack; 241 - struct snd_soc_jack hdmi_jack; 242 - struct snd_soc_jack headset_jack; 243 - void *private_data; 239 + enum mt8188_jacks { 240 + MT8188_JACK_HEADSET, 241 + MT8188_JACK_DP, 242 + MT8188_JACK_HDMI, 243 + MT8188_JACK_MAX, 244 244 }; 245 245 246 246 static struct snd_soc_jack_pin mt8188_hdmi_jack_pins[] = { ··· 266 266 .pin = "Headset Mic", 267 267 .mask = SND_JACK_MICROPHONE, 268 268 }, 269 - }; 270 - 271 - struct mt8188_card_data { 272 - const char *name; 273 - unsigned long quirk; 274 269 }; 275 270 276 271 static const struct snd_kcontrol_new mt8188_dumb_spk_controls[] = { ··· 585 590 static int mt8188_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) 586 591 { 587 592 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 588 - struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv; 593 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HDMI]; 589 594 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; 590 595 int ret = 0; 591 596 592 597 ret = snd_soc_card_jack_new_pins(rtd->card, "HDMI Jack", 593 - SND_JACK_LINEOUT, &priv->hdmi_jack, 598 + SND_JACK_LINEOUT, jack, 594 599 mt8188_hdmi_jack_pins, 595 600 ARRAY_SIZE(mt8188_hdmi_jack_pins)); 596 601 if (ret) { ··· 598 603 return ret; 599 604 } 600 605 601 - ret = snd_soc_component_set_jack(component, &priv->hdmi_jack, NULL); 606 + ret = snd_soc_component_set_jack(component, jack, NULL); 602 607 if (ret) { 603 608 dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n", 604 609 __func__, component->name, ret); ··· 611 616 static int mt8188_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) 612 617 { 613 618 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 614 - struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv; 619 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_DP]; 615 620 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; 616 621 int ret = 0; 617 622 618 623 ret = snd_soc_card_jack_new_pins(rtd->card, "DP Jack", SND_JACK_LINEOUT, 619 - &priv->dp_jack, mt8188_dp_jack_pins, 624 + jack, mt8188_dp_jack_pins, 620 625 ARRAY_SIZE(mt8188_dp_jack_pins)); 621 626 if (ret) { 622 627 dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret); 623 628 return ret; 624 629 } 625 630 626 - ret = snd_soc_component_set_jack(component, &priv->dp_jack, NULL); 631 + ret = snd_soc_component_set_jack(component, jack, NULL); 627 632 if (ret) { 628 633 dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n", 629 634 __func__, component->name, ret); ··· 731 736 static int mt8188_headset_codec_init(struct snd_soc_pcm_runtime *rtd) 732 737 { 733 738 struct snd_soc_card *card = rtd->card; 734 - struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 735 - struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv; 739 + struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 740 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HEADSET]; 736 741 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; 737 - struct snd_soc_jack *jack = &priv->headset_jack; 738 742 int ret; 739 743 740 744 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_nau8825_widgets, ··· 1218 1224 static void mt8188_fixup_controls(struct snd_soc_card *card) 1219 1225 { 1220 1226 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 1221 - struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv; 1222 - struct mt8188_card_data *card_data = (struct mt8188_card_data *)priv->private_data; 1227 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1223 1228 struct snd_kcontrol *kctl; 1224 1229 1225 - if (card_data->quirk & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) { 1230 + if (card_data->flags & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) { 1226 1231 struct snd_soc_dapm_widget *w, *next_w; 1227 1232 1228 1233 for_each_card_widgets_safe(card, w, next_w) { ··· 1252 1259 .fixup_controls = mt8188_fixup_controls, 1253 1260 }; 1254 1261 1255 - static int mt8188_mt6359_dev_probe(struct platform_device *pdev) 1262 + static int mt8188_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) 1256 1263 { 1257 - struct snd_soc_card *card = &mt8188_mt6359_soc_card; 1258 - struct device_node *platform_node; 1259 - struct device_node *adsp_node; 1260 - struct mtk_soc_card_data *soc_card_data; 1261 - struct mt8188_mt6359_priv *priv; 1262 - struct mt8188_card_data *card_data; 1264 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1265 + struct snd_soc_card *card = soc_card_data->card_data->card; 1263 1266 struct snd_soc_dai_link *dai_link; 1264 1267 bool init_mt6359 = false; 1265 1268 bool init_es8326 = false; ··· 1263 1274 bool init_rt5682s = false; 1264 1275 bool init_max98390 = false; 1265 1276 bool init_dumb = false; 1266 - int ret, i; 1277 + int i; 1267 1278 1268 - card_data = (struct mt8188_card_data *)of_device_get_match_data(&pdev->dev); 1269 - card->dev = &pdev->dev; 1270 - 1271 - ret = snd_soc_of_parse_card_name(card, "model"); 1272 - if (ret) 1273 - return dev_err_probe(&pdev->dev, ret, "%s new card name parsing error\n", 1274 - __func__); 1275 - 1276 - if (!card->name) 1277 - card->name = card_data->name; 1278 - 1279 - if (of_property_read_bool(pdev->dev.of_node, "audio-routing")) { 1280 - ret = snd_soc_of_parse_audio_routing(card, "audio-routing"); 1281 - if (ret) 1282 - return ret; 1283 - } 1284 - 1285 - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 1286 - if (!priv) 1287 - return -ENOMEM; 1288 - 1289 - soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*card_data), GFP_KERNEL); 1290 - if (!soc_card_data) 1291 - return -ENOMEM; 1292 - 1293 - soc_card_data->mach_priv = priv; 1294 - 1295 - adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); 1296 - if (adsp_node) { 1297 - struct mtk_sof_priv *sof_priv; 1298 - 1299 - sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); 1300 - if (!sof_priv) { 1301 - ret = -ENOMEM; 1302 - goto err_adsp_node; 1303 - } 1304 - sof_priv->conn_streams = g_sof_conn_streams; 1305 - sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams); 1306 - soc_card_data->sof_priv = sof_priv; 1307 - card->probe = mtk_sof_card_probe; 1308 - card->late_probe = mtk_sof_card_late_probe; 1309 - if (!card->topology_shortname_created) { 1310 - snprintf(card->topology_shortname, 32, "sof-%s", card->name); 1311 - card->topology_shortname_created = true; 1312 - } 1313 - card->name = card->topology_shortname; 1314 - } 1315 - 1316 - if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { 1317 - ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, 1318 - "mediatek,dai-link", 1319 - mt8188_mt6359_dai_links, 1320 - ARRAY_SIZE(mt8188_mt6359_dai_links)); 1321 - if (ret) { 1322 - dev_err_probe(&pdev->dev, ret, "Parse dai-link fail\n"); 1323 - goto err_adsp_node; 1324 - } 1325 - } else { 1326 - if (!adsp_node) 1327 - card->num_links = DAI_LINK_REGULAR_NUM; 1328 - } 1329 - 1330 - platform_node = of_parse_phandle(pdev->dev.of_node, 1331 - "mediatek,platform", 0); 1332 - if (!platform_node) { 1333 - ret = dev_err_probe(&pdev->dev, -EINVAL, 1334 - "Property 'platform' missing or invalid\n"); 1335 - goto err_adsp_node; 1336 - 1337 - } 1338 - 1339 - ret = parse_dai_link_info(card); 1340 - if (ret) 1341 - goto err; 1279 + if (legacy) 1280 + return -EINVAL; 1342 1281 1343 1282 for_each_card_prelinks(card, i, dai_link) { 1344 - if (!dai_link->platforms->name) { 1345 - if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && adsp_node) 1346 - dai_link->platforms->of_node = adsp_node; 1347 - else 1348 - dai_link->platforms->of_node = platform_node; 1349 - } 1350 - 1351 1283 if (strcmp(dai_link->name, "DPTX_BE") == 0) { 1352 1284 if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) 1353 1285 dai_link->init = mt8188_dptx_codec_init; ··· 1291 1381 * mt8188_max98390_ops. Two amps is I2S mode, 1292 1382 * SOC and codec don't require TDM settings. 1293 1383 */ 1294 - if (!(card_data->quirk & MAX98390_TWO_AMP)) { 1384 + if (!(card_data->flags & MAX98390_TWO_AMP)) { 1295 1385 dai_link->ops = &mt8188_max98390_ops; 1296 1386 } 1297 1387 if (!init_max98390) { ··· 1330 1420 } 1331 1421 } 1332 1422 1333 - priv->private_data = card_data; 1334 - snd_soc_card_set_drvdata(card, soc_card_data); 1335 - 1336 - ret = devm_snd_soc_register_card(&pdev->dev, card); 1337 - if (ret) 1338 - dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", 1339 - __func__); 1340 - err: 1341 - of_node_put(platform_node); 1342 - clean_card_reference(card); 1343 - 1344 - err_adsp_node: 1345 - of_node_put(adsp_node); 1346 - 1347 - return ret; 1423 + return 0; 1348 1424 } 1349 1425 1350 - static struct mt8188_card_data mt8188_evb_card = { 1351 - .name = "mt8188_mt6359", 1426 + static const struct mtk_sof_priv mt8188_sof_priv = { 1427 + .conn_streams = g_sof_conn_streams, 1428 + .num_streams = ARRAY_SIZE(g_sof_conn_streams), 1352 1429 }; 1353 1430 1354 - static struct mt8188_card_data mt8188_nau8825_card = { 1355 - .name = "mt8188_nau8825", 1356 - .quirk = NAU8825_HS_PRESENT, 1431 + static const struct mtk_soundcard_pdata mt8188_evb_card = { 1432 + .card_name = "mt8188_mt6359", 1433 + .card_data = &(struct mtk_platform_card_data) { 1434 + .card = &mt8188_mt6359_soc_card, 1435 + .num_jacks = MT8188_JACK_MAX, 1436 + }, 1437 + .sof_priv = &mt8188_sof_priv, 1438 + .soc_probe = mt8188_mt6359_soc_card_probe, 1357 1439 }; 1358 1440 1359 - static struct mt8188_card_data mt8188_rt5682s_card = { 1360 - .name = "mt8188_rt5682s", 1361 - .quirk = RT5682S_HS_PRESENT | MAX98390_TWO_AMP, 1441 + static const struct mtk_soundcard_pdata mt8188_nau8825_card = { 1442 + .card_name = "mt8188_nau8825", 1443 + .card_data = &(struct mtk_platform_card_data) { 1444 + .card = &mt8188_mt6359_soc_card, 1445 + .num_jacks = MT8188_JACK_MAX, 1446 + .flags = NAU8825_HS_PRESENT 1447 + }, 1448 + .sof_priv = &mt8188_sof_priv, 1449 + .soc_probe = mt8188_mt6359_soc_card_probe, 1362 1450 }; 1363 1451 1364 - static struct mt8188_card_data mt8188_es8326_card = { 1365 - .name = "mt8188_es8326", 1366 - .quirk = ES8326_HS_PRESENT | MAX98390_TWO_AMP, 1452 + static const struct mtk_soundcard_pdata mt8188_rt5682s_card = { 1453 + .card_name = "mt8188_rt5682s", 1454 + .card_data = &(struct mtk_platform_card_data) { 1455 + .card = &mt8188_mt6359_soc_card, 1456 + .num_jacks = MT8188_JACK_MAX, 1457 + .flags = RT5682S_HS_PRESENT | MAX98390_TWO_AMP 1458 + }, 1459 + .sof_priv = &mt8188_sof_priv, 1460 + .soc_probe = mt8188_mt6359_soc_card_probe, 1461 + }; 1462 + 1463 + static const struct mtk_soundcard_pdata mt8188_es8326_card = { 1464 + .card_name = "mt8188_es8326", 1465 + .card_data = &(struct mtk_platform_card_data) { 1466 + .card = &mt8188_mt6359_soc_card, 1467 + .num_jacks = MT8188_JACK_MAX, 1468 + .flags = ES8326_HS_PRESENT | MAX98390_TWO_AMP 1469 + }, 1470 + .sof_priv = &mt8188_sof_priv, 1471 + .soc_probe = mt8188_mt6359_soc_card_probe, 1367 1472 }; 1368 1473 1369 1474 static const struct of_device_id mt8188_mt6359_dt_match[] = { ··· 1396 1471 .of_match_table = mt8188_mt6359_dt_match, 1397 1472 .pm = &snd_soc_pm_ops, 1398 1473 }, 1399 - .probe = mt8188_mt6359_dev_probe, 1474 + .probe = mtk_soundcard_common_probe, 1400 1475 }; 1401 1476 1402 1477 module_platform_driver(mt8188_mt6359_driver);