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 the common mtk_soundcard_startup

Add a const mtk_pcm_constraints_data struct array with all of the
(again, constant) constraints for all of the supported usecases,
remove the duplicated functions and call mtk_soundcard_startup()
instead in all of the .startup() callbacks.

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-9-angelogioacchino.delregno@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

AngeloGioacchino Del Regno and committed by
Mark Brown
386fe4ce fe071237

+53 -142
+53 -142
sound/soc/mediatek/mt8195/mt8195-mt6359.c
··· 328 328 329 329 static int mt8195_hdmitx_dptx_startup(struct snd_pcm_substream *substream) 330 330 { 331 - static const unsigned int rates[] = { 332 - 48000 333 - }; 334 - static const unsigned int channels[] = { 335 - 2, 4, 6, 8 336 - }; 337 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 338 - .count = ARRAY_SIZE(rates), 339 - .list = rates, 340 - .mask = 0, 341 - }; 342 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 343 - .count = ARRAY_SIZE(channels), 344 - .list = channels, 345 - .mask = 0, 346 - }; 347 - 348 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 349 - struct snd_pcm_runtime *runtime = substream->runtime; 350 - int ret; 351 - 352 - ret = snd_pcm_hw_constraint_list(runtime, 0, 353 - SNDRV_PCM_HW_PARAM_RATE, 354 - &constraints_rates); 355 - if (ret < 0) { 356 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 357 - return ret; 358 - } 359 - 360 - ret = snd_pcm_hw_constraint_list(runtime, 0, 361 - SNDRV_PCM_HW_PARAM_CHANNELS, 362 - &constraints_channels); 363 - if (ret < 0) { 364 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 365 - return ret; 366 - } 367 - 368 - return 0; 331 + return mtk_soundcard_startup(substream, MTK_CONSTRAINT_HDMIDP); 369 332 } 370 333 371 334 static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops = { ··· 390 427 391 428 return 0; 392 429 } 393 - 394 - static int mt8195_playback_startup(struct snd_pcm_substream *substream) 395 - { 396 - static const unsigned int rates[] = { 397 - 48000 398 - }; 399 - static const unsigned int channels[] = { 400 - 2 401 - }; 402 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 403 - .count = ARRAY_SIZE(rates), 404 - .list = rates, 405 - .mask = 0, 406 - }; 407 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 408 - .count = ARRAY_SIZE(channels), 409 - .list = channels, 410 - .mask = 0, 411 - }; 412 - 413 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 414 - struct snd_pcm_runtime *runtime = substream->runtime; 415 - int ret; 416 - 417 - ret = snd_pcm_hw_constraint_list(runtime, 0, 418 - SNDRV_PCM_HW_PARAM_RATE, 419 - &constraints_rates); 420 - if (ret < 0) { 421 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 422 - return ret; 423 - } 424 - 425 - ret = snd_pcm_hw_constraint_list(runtime, 0, 426 - SNDRV_PCM_HW_PARAM_CHANNELS, 427 - &constraints_channels); 428 - if (ret < 0) { 429 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 430 - return ret; 431 - } 432 - 433 - return 0; 434 - } 435 - 436 - static const struct snd_soc_ops mt8195_playback_ops = { 437 - .startup = mt8195_playback_startup, 438 - }; 439 - 440 - static int mt8195_capture_startup(struct snd_pcm_substream *substream) 441 - { 442 - static const unsigned int rates[] = { 443 - 48000 444 - }; 445 - static const unsigned int channels[] = { 446 - 1, 2 447 - }; 448 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 449 - .count = ARRAY_SIZE(rates), 450 - .list = rates, 451 - .mask = 0, 452 - }; 453 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 454 - .count = ARRAY_SIZE(channels), 455 - .list = channels, 456 - .mask = 0, 457 - }; 458 - 459 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 460 - struct snd_pcm_runtime *runtime = substream->runtime; 461 - int ret; 462 - 463 - ret = snd_pcm_hw_constraint_list(runtime, 0, 464 - SNDRV_PCM_HW_PARAM_RATE, 465 - &constraints_rates); 466 - if (ret < 0) { 467 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 468 - return ret; 469 - } 470 - 471 - ret = snd_pcm_hw_constraint_list(runtime, 0, 472 - SNDRV_PCM_HW_PARAM_CHANNELS, 473 - &constraints_channels); 474 - if (ret < 0) { 475 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 476 - return ret; 477 - } 478 - 479 - return 0; 480 - } 481 - 482 - static const struct snd_soc_ops mt8195_capture_ops = { 483 - .startup = mt8195_capture_startup, 484 - }; 485 430 486 431 static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream *substream, 487 432 struct snd_pcm_hw_params *params) ··· 913 1042 }, 914 1043 .dynamic = 1, 915 1044 .dpcm_playback = 1, 916 - .ops = &mt8195_playback_ops, 1045 + .ops = &mtk_soundcard_common_playback_ops, 917 1046 SND_SOC_DAILINK_REG(DL2_FE), 918 1047 }, 919 1048 [DAI_LINK_DL3_FE] = { ··· 925 1054 }, 926 1055 .dynamic = 1, 927 1056 .dpcm_playback = 1, 928 - .ops = &mt8195_playback_ops, 1057 + .ops = &mtk_soundcard_common_playback_ops, 929 1058 SND_SOC_DAILINK_REG(DL3_FE), 930 1059 }, 931 1060 [DAI_LINK_DL6_FE] = { ··· 937 1066 }, 938 1067 .dynamic = 1, 939 1068 .dpcm_playback = 1, 940 - .ops = &mt8195_playback_ops, 1069 + .ops = &mtk_soundcard_common_playback_ops, 941 1070 SND_SOC_DAILINK_REG(DL6_FE), 942 1071 }, 943 1072 [DAI_LINK_DL7_FE] = { ··· 960 1089 }, 961 1090 .dynamic = 1, 962 1091 .dpcm_playback = 1, 963 - .ops = &mt8195_playback_ops, 1092 + .ops = &mtk_soundcard_common_playback_ops, 964 1093 SND_SOC_DAILINK_REG(DL8_FE), 965 1094 }, 966 1095 [DAI_LINK_DL10_FE] = { ··· 984 1113 }, 985 1114 .dynamic = 1, 986 1115 .dpcm_playback = 1, 987 - .ops = &mt8195_playback_ops, 1116 + .ops = &mtk_soundcard_common_playback_ops, 988 1117 SND_SOC_DAILINK_REG(DL11_FE), 989 1118 }, 990 1119 [DAI_LINK_UL1_FE] = { ··· 1007 1136 }, 1008 1137 .dynamic = 1, 1009 1138 .dpcm_capture = 1, 1010 - .ops = &mt8195_capture_ops, 1139 + .ops = &mtk_soundcard_common_capture_ops, 1011 1140 SND_SOC_DAILINK_REG(UL2_FE), 1012 1141 }, 1013 1142 [DAI_LINK_UL3_FE] = { ··· 1019 1148 }, 1020 1149 .dynamic = 1, 1021 1150 .dpcm_capture = 1, 1022 - .ops = &mt8195_capture_ops, 1151 + .ops = &mtk_soundcard_common_capture_ops, 1023 1152 SND_SOC_DAILINK_REG(UL3_FE), 1024 1153 }, 1025 1154 [DAI_LINK_UL4_FE] = { ··· 1031 1160 }, 1032 1161 .dynamic = 1, 1033 1162 .dpcm_capture = 1, 1034 - .ops = &mt8195_capture_ops, 1163 + .ops = &mtk_soundcard_common_capture_ops, 1035 1164 SND_SOC_DAILINK_REG(UL4_FE), 1036 1165 }, 1037 1166 [DAI_LINK_UL5_FE] = { ··· 1043 1172 }, 1044 1173 .dynamic = 1, 1045 1174 .dpcm_capture = 1, 1046 - .ops = &mt8195_capture_ops, 1175 + .ops = &mtk_soundcard_common_capture_ops, 1047 1176 SND_SOC_DAILINK_REG(UL5_FE), 1048 1177 }, 1049 1178 [DAI_LINK_UL6_FE] = { ··· 1066 1195 }, 1067 1196 .dynamic = 1, 1068 1197 .dpcm_capture = 1, 1069 - .ops = &mt8195_capture_ops, 1198 + .ops = &mtk_soundcard_common_capture_ops, 1070 1199 SND_SOC_DAILINK_REG(UL8_FE), 1071 1200 }, 1072 1201 [DAI_LINK_UL9_FE] = { ··· 1078 1207 }, 1079 1208 .dynamic = 1, 1080 1209 .dpcm_capture = 1, 1081 - .ops = &mt8195_capture_ops, 1210 + .ops = &mtk_soundcard_common_capture_ops, 1082 1211 SND_SOC_DAILINK_REG(UL9_FE), 1083 1212 }, 1084 1213 [DAI_LINK_UL10_FE] = { ··· 1090 1219 }, 1091 1220 .dynamic = 1, 1092 1221 .dpcm_capture = 1, 1093 - .ops = &mt8195_capture_ops, 1222 + .ops = &mtk_soundcard_common_capture_ops, 1094 1223 SND_SOC_DAILINK_REG(UL10_FE), 1095 1224 }, 1096 1225 /* BE */ ··· 1432 1561 return 0; 1433 1562 } 1434 1563 1564 + static const unsigned int mt8195_pcm_playback_channels[] = { 2 }; 1565 + static const unsigned int mt8195_pcm_capture_channels[] = { 1, 2 }; 1566 + static const unsigned int mt8195_pcm_hdmidp_channels[] = { 2, 4, 6, 8 }; 1567 + static const unsigned int mt8195_pcm_rates[] = { 48000 }; 1568 + 1569 + static const struct snd_pcm_hw_constraint_list mt8195_rate_constraint = { 1570 + .list = mt8195_pcm_rates, 1571 + .count = ARRAY_SIZE(mt8195_pcm_rates) 1572 + }; 1573 + 1574 + static const struct mtk_pcm_constraints_data mt8195_pcm_constraints[MTK_CONSTRAINT_HDMIDP + 1] = { 1575 + [MTK_CONSTRAINT_PLAYBACK] = { 1576 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1577 + .list = mt8195_pcm_playback_channels, 1578 + .count = ARRAY_SIZE(mt8195_pcm_playback_channels) 1579 + }, 1580 + .rates = &mt8195_rate_constraint, 1581 + }, 1582 + [MTK_CONSTRAINT_CAPTURE] = { 1583 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1584 + .list = mt8195_pcm_capture_channels, 1585 + .count = ARRAY_SIZE(mt8195_pcm_capture_channels) 1586 + }, 1587 + .rates = &mt8195_rate_constraint, 1588 + }, 1589 + [MTK_CONSTRAINT_HDMIDP] = { 1590 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1591 + .list = mt8195_pcm_hdmidp_channels, 1592 + .count = ARRAY_SIZE(mt8195_pcm_hdmidp_channels) 1593 + }, 1594 + .rates = &mt8195_rate_constraint, 1595 + }, 1596 + }; 1597 + 1435 1598 static const struct mtk_sof_priv mt8195_sof_priv = { 1436 1599 .conn_streams = g_sof_conn_streams, 1437 1600 .num_streams = ARRAY_SIZE(g_sof_conn_streams), ··· 1477 1572 .card_data = &(struct mtk_platform_card_data) { 1478 1573 .card = &mt8195_mt6359_soc_card, 1479 1574 .num_jacks = MT8195_JACK_MAX, 1575 + .pcm_constraints = mt8195_pcm_constraints, 1576 + .num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints), 1480 1577 .flags = RT1019_SPEAKER_AMP_PRESENT 1481 1578 }, 1482 1579 .sof_priv = &mt8195_sof_priv, ··· 1490 1583 .card_data = &(struct mtk_platform_card_data) { 1491 1584 .card = &mt8195_mt6359_soc_card, 1492 1585 .num_jacks = MT8195_JACK_MAX, 1586 + .pcm_constraints = mt8195_pcm_constraints, 1587 + .num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints), 1493 1588 .flags = RT1011_SPEAKER_AMP_PRESENT 1494 1589 }, 1495 1590 .sof_priv = &mt8195_sof_priv, ··· 1503 1594 .card_data = &(struct mtk_platform_card_data) { 1504 1595 .card = &mt8195_mt6359_soc_card, 1505 1596 .num_jacks = MT8195_JACK_MAX, 1597 + .pcm_constraints = mt8195_pcm_constraints, 1598 + .num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints), 1506 1599 .flags = MAX98390_SPEAKER_AMP_PRESENT 1507 1600 }, 1508 1601 .sof_priv = &mt8195_sof_priv,