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

authored by

AngeloGioacchino Del Regno and committed by
Mark Brown
94142cc1 386fe4ce

+41 -98
+41 -98
sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
··· 389 389 return 0; 390 390 } 391 391 392 - static int 393 - mt8192_mt6359_cap1_startup(struct snd_pcm_substream *substream) 394 - { 395 - static const unsigned int channels[] = { 396 - 1, 2, 4 397 - }; 398 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 399 - .count = ARRAY_SIZE(channels), 400 - .list = channels, 401 - .mask = 0, 402 - }; 403 - static const unsigned int rates[] = { 404 - 8000, 16000, 32000, 48000, 96000, 192000 405 - }; 406 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 407 - .count = ARRAY_SIZE(rates), 408 - .list = rates, 409 - .mask = 0, 410 - }; 411 - 412 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 413 - struct snd_pcm_runtime *runtime = substream->runtime; 414 - int ret; 415 - 416 - ret = snd_pcm_hw_constraint_list(runtime, 0, 417 - SNDRV_PCM_HW_PARAM_CHANNELS, 418 - &constraints_channels); 419 - if (ret < 0) { 420 - dev_err(rtd->dev, "hw_constraint_list channels failed\n"); 421 - return ret; 422 - } 423 - 424 - ret = snd_pcm_hw_constraint_list(runtime, 0, 425 - SNDRV_PCM_HW_PARAM_RATE, 426 - &constraints_rates); 427 - if (ret < 0) { 428 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 429 - return ret; 430 - } 431 - 432 - return 0; 433 - } 434 - 435 - static const struct snd_soc_ops mt8192_mt6359_capture1_ops = { 436 - .startup = mt8192_mt6359_cap1_startup, 437 - }; 438 - 439 - static int 440 - mt8192_mt6359_rt5682_startup(struct snd_pcm_substream *substream) 441 - { 442 - static const unsigned int channels[] = { 443 - 1, 2 444 - }; 445 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 446 - .count = ARRAY_SIZE(channels), 447 - .list = channels, 448 - .mask = 0, 449 - }; 450 - static const unsigned int rates[] = { 451 - 48000 452 - }; 453 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 454 - .count = ARRAY_SIZE(rates), 455 - .list = rates, 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_CHANNELS, 465 - &constraints_channels); 466 - if (ret < 0) { 467 - dev_err(rtd->dev, "hw_constraint_list channels failed\n"); 468 - return ret; 469 - } 470 - 471 - ret = snd_pcm_hw_constraint_list(runtime, 0, 472 - SNDRV_PCM_HW_PARAM_RATE, 473 - &constraints_rates); 474 - if (ret < 0) { 475 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 476 - return ret; 477 - } 478 - 479 - return 0; 480 - } 481 - 482 - static const struct snd_soc_ops mt8192_mt6359_rt5682_ops = { 483 - .startup = mt8192_mt6359_rt5682_startup, 484 - }; 485 - 486 392 /* FE */ 487 393 SND_SOC_DAILINK_DEFS(playback1, 488 394 DAILINK_COMP_ARRAY(COMP_CPU("DL1")), ··· 626 720 SND_SOC_DPCM_TRIGGER_PRE}, 627 721 .dynamic = 1, 628 722 .dpcm_playback = 1, 629 - .ops = &mt8192_mt6359_rt5682_ops, 723 + .ops = &mtk_soundcard_common_playback_ops, 630 724 SND_SOC_DAILINK_REG(playback3), 631 725 }, 632 726 { ··· 690 784 SND_SOC_DPCM_TRIGGER_PRE}, 691 785 .dynamic = 1, 692 786 .dpcm_capture = 1, 693 - .ops = &mt8192_mt6359_capture1_ops, 787 + .ops = &mtk_soundcard_common_capture_ops, 694 788 SND_SOC_DAILINK_REG(capture1), 695 789 }, 696 790 { ··· 700 794 SND_SOC_DPCM_TRIGGER_PRE}, 701 795 .dynamic = 1, 702 796 .dpcm_capture = 1, 703 - .ops = &mt8192_mt6359_rt5682_ops, 797 + .ops = &mtk_soundcard_common_playback_ops, 704 798 SND_SOC_DAILINK_REG(capture2), 705 799 }, 706 800 { ··· 1052 1146 struct device *dev = card->dev; 1053 1147 struct device_node *hdmi_codec, *headset_codec, *speaker_codec; 1054 1148 struct snd_soc_dai_link *dai_link; 1055 - int ret, i; 1149 + int i, ret = 0; 1056 1150 1057 1151 hdmi_codec = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0); 1058 1152 if (!hdmi_codec) ··· 1141 1235 return 0; 1142 1236 } 1143 1237 1238 + static const unsigned int mt8192_pcm_playback_channels[] = { 1, 2 }; 1239 + static const unsigned int mt8192_pcm_playback_rates[] = { 48000 }; 1240 + 1241 + static const unsigned int mt8192_pcm_capture_channels[] = { 1, 2, 4 }; 1242 + static const unsigned int mt8192_pcm_capture_rates[] = { 1243 + 8000, 16000, 32000, 48000, 96000, 192000 1244 + }; 1245 + 1246 + static const struct mtk_pcm_constraints_data mt8192_pcm_constraints[MTK_CONSTRAINT_CAPTURE + 1] = { 1247 + [MTK_CONSTRAINT_PLAYBACK] = { 1248 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1249 + .list = mt8192_pcm_playback_channels, 1250 + .count = ARRAY_SIZE(mt8192_pcm_playback_channels) 1251 + }, 1252 + .rates = &(const struct snd_pcm_hw_constraint_list) { 1253 + .list = mt8192_pcm_playback_rates, 1254 + .count = ARRAY_SIZE(mt8192_pcm_playback_rates) 1255 + } 1256 + }, 1257 + [MTK_CONSTRAINT_CAPTURE] = { 1258 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1259 + .list = mt8192_pcm_capture_channels, 1260 + .count = ARRAY_SIZE(mt8192_pcm_capture_channels) 1261 + }, 1262 + .rates = &(const struct snd_pcm_hw_constraint_list) { 1263 + .list = mt8192_pcm_capture_rates, 1264 + .count = ARRAY_SIZE(mt8192_pcm_capture_rates) 1265 + } 1266 + } 1267 + }; 1268 + 1144 1269 static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015_rt5682_pdata = { 1145 1270 .card_name = RT1015_RT5682_CARD_NAME, 1146 1271 .card_data = &(struct mtk_platform_card_data) { 1147 1272 .card = &mt8192_mt6359_rt1015_rt5682_card, 1148 1273 .num_jacks = MT8192_JACK_MAX, 1274 + .pcm_constraints = mt8192_pcm_constraints, 1275 + .num_pcm_constraints = ARRAY_SIZE(mt8192_pcm_constraints), 1149 1276 }, 1150 1277 .soc_probe = mt8192_mt6359_soc_card_probe 1151 1278 }; ··· 1188 1249 .card_data = &(struct mtk_platform_card_data) { 1189 1250 .card = &mt8192_mt6359_rt1015p_rt5682x_card, 1190 1251 .num_jacks = MT8192_JACK_MAX, 1252 + .pcm_constraints = mt8192_pcm_constraints, 1253 + .num_pcm_constraints = ARRAY_SIZE(mt8192_pcm_constraints), 1191 1254 }, 1192 1255 .soc_probe = mt8192_mt6359_soc_card_probe 1193 1256 }; ··· 1199 1258 .card_data = &(struct mtk_platform_card_data) { 1200 1259 .card = &mt8192_mt6359_rt1015p_rt5682x_card, 1201 1260 .num_jacks = MT8192_JACK_MAX, 1261 + .pcm_constraints = mt8192_pcm_constraints, 1262 + .num_pcm_constraints = ARRAY_SIZE(mt8192_pcm_constraints), 1202 1263 }, 1203 1264 .soc_probe = mt8192_mt6359_soc_card_probe 1204 1265 };