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: mt8186-rt1019: 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.

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

authored by

AngeloGioacchino Del Regno and committed by
Mark Brown
f103ce4f 94142cc1

+36 -96
+36 -96
sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c
··· 332 332 return ret; 333 333 } 334 334 335 - static int mt8186_mt6366_rt1019_rt5682s_playback_startup(struct snd_pcm_substream *substream) 336 - { 337 - static const unsigned int rates[] = { 338 - 48000 339 - }; 340 - static const unsigned int channels[] = { 341 - 2 342 - }; 343 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 344 - .count = ARRAY_SIZE(rates), 345 - .list = rates, 346 - .mask = 0, 347 - }; 348 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 349 - .count = ARRAY_SIZE(channels), 350 - .list = channels, 351 - .mask = 0, 352 - }; 353 - 354 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 355 - struct snd_pcm_runtime *runtime = substream->runtime; 356 - int ret; 357 - 358 - ret = snd_pcm_hw_constraint_list(runtime, 0, 359 - SNDRV_PCM_HW_PARAM_RATE, 360 - &constraints_rates); 361 - if (ret < 0) { 362 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 363 - return ret; 364 - } 365 - 366 - ret = snd_pcm_hw_constraint_list(runtime, 0, 367 - SNDRV_PCM_HW_PARAM_CHANNELS, 368 - &constraints_channels); 369 - if (ret < 0) { 370 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 371 - return ret; 372 - } 373 - 374 - return 0; 375 - } 376 - 377 - static const struct snd_soc_ops mt8186_mt6366_rt1019_rt5682s_playback_ops = { 378 - .startup = mt8186_mt6366_rt1019_rt5682s_playback_startup, 379 - }; 380 - 381 - static int mt8186_mt6366_rt1019_rt5682s_capture_startup(struct snd_pcm_substream *substream) 382 - { 383 - static const unsigned int rates[] = { 384 - 48000 385 - }; 386 - static const unsigned int channels[] = { 387 - 1, 2 388 - }; 389 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 390 - .count = ARRAY_SIZE(rates), 391 - .list = rates, 392 - .mask = 0, 393 - }; 394 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 395 - .count = ARRAY_SIZE(channels), 396 - .list = channels, 397 - .mask = 0, 398 - }; 399 - 400 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 401 - struct snd_pcm_runtime *runtime = substream->runtime; 402 - int ret; 403 - 404 - ret = snd_pcm_hw_constraint_list(runtime, 0, 405 - SNDRV_PCM_HW_PARAM_RATE, 406 - &constraints_rates); 407 - if (ret < 0) { 408 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 409 - return ret; 410 - } 411 - 412 - ret = snd_pcm_hw_constraint_list(runtime, 0, 413 - SNDRV_PCM_HW_PARAM_CHANNELS, 414 - &constraints_channels); 415 - if (ret < 0) { 416 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 417 - return ret; 418 - } 419 - 420 - return 0; 421 - } 422 - 423 - static const struct snd_soc_ops mt8186_mt6366_rt1019_rt5682s_capture_ops = { 424 - .startup = mt8186_mt6366_rt1019_rt5682s_capture_startup, 425 - }; 426 - 427 335 /* FE */ 428 336 SND_SOC_DAILINK_DEFS(playback1, 429 337 DAILINK_COMP_ARRAY(COMP_CPU("DL1")), ··· 552 644 .dpcm_merged_format = 1, 553 645 .dpcm_merged_chan = 1, 554 646 .dpcm_merged_rate = 1, 555 - .ops = &mt8186_mt6366_rt1019_rt5682s_playback_ops, 647 + .ops = &mtk_soundcard_common_playback_ops, 556 648 SND_SOC_DAILINK_REG(playback1), 557 649 }, 558 650 { ··· 586 678 .dpcm_merged_format = 1, 587 679 .dpcm_merged_chan = 1, 588 680 .dpcm_merged_rate = 1, 589 - .ops = &mt8186_mt6366_rt1019_rt5682s_playback_ops, 681 + .ops = &mtk_soundcard_common_playback_ops, 590 682 SND_SOC_DAILINK_REG(playback3), 591 683 }, 592 684 { ··· 653 745 .dpcm_merged_format = 1, 654 746 .dpcm_merged_chan = 1, 655 747 .dpcm_merged_rate = 1, 656 - .ops = &mt8186_mt6366_rt1019_rt5682s_capture_ops, 748 + .ops = &mtk_soundcard_common_capture_ops, 657 749 SND_SOC_DAILINK_REG(capture2), 658 750 }, 659 751 { ··· 675 767 .dpcm_merged_format = 1, 676 768 .dpcm_merged_chan = 1, 677 769 .dpcm_merged_rate = 1, 678 - .ops = &mt8186_mt6366_rt1019_rt5682s_capture_ops, 770 + .ops = &mtk_soundcard_common_capture_ops, 679 771 SND_SOC_DAILINK_REG(capture4), 680 772 }, 681 773 { ··· 1128 1220 return 0; 1129 1221 } 1130 1222 1223 + static const unsigned int mt8186_pcm_playback_channels[] = { 2 }; 1224 + static const unsigned int mt8186_pcm_capture_channels[] = { 1, 2 }; 1225 + static const unsigned int mt8186_pcm_rates[] = { 48000 }; 1226 + 1227 + static const struct snd_pcm_hw_constraint_list mt8186_rate_constraint = { 1228 + .list = mt8186_pcm_rates, 1229 + .count = ARRAY_SIZE(mt8186_pcm_rates) 1230 + }; 1231 + 1232 + static const struct mtk_pcm_constraints_data mt8186_pcm_constraints[MTK_CONSTRAINT_CAPTURE + 1] = { 1233 + [MTK_CONSTRAINT_PLAYBACK] = { 1234 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1235 + .list = mt8186_pcm_playback_channels, 1236 + .count = ARRAY_SIZE(mt8186_pcm_playback_channels) 1237 + }, 1238 + .rates = &mt8186_rate_constraint, 1239 + }, 1240 + [MTK_CONSTRAINT_CAPTURE] = { 1241 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1242 + .list = mt8186_pcm_capture_channels, 1243 + .count = ARRAY_SIZE(mt8186_pcm_capture_channels) 1244 + }, 1245 + .rates = &mt8186_rate_constraint, 1246 + } 1247 + }; 1248 + 1131 1249 static const struct mtk_sof_priv mt8186_sof_priv = { 1132 1250 .conn_streams = g_sof_conn_streams, 1133 1251 .num_streams = ARRAY_SIZE(g_sof_conn_streams), ··· 1164 1230 .card_data = &(struct mtk_platform_card_data) { 1165 1231 .card = &mt8186_mt6366_rt1019_rt5682s_soc_card, 1166 1232 .num_jacks = MT8186_JACK_MAX, 1233 + .pcm_constraints = mt8186_pcm_constraints, 1234 + .num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints), 1167 1235 }, 1168 1236 .sof_priv = &mt8186_sof_priv, 1169 1237 .soc_probe = mt8186_mt6366_soc_card_probe ··· 1175 1239 .card_data = &(struct mtk_platform_card_data) { 1176 1240 .card = &mt8186_mt6366_rt5682s_max98360_soc_card, 1177 1241 .num_jacks = MT8186_JACK_MAX, 1242 + .pcm_constraints = mt8186_pcm_constraints, 1243 + .num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints), 1178 1244 }, 1179 1245 .sof_priv = &mt8186_sof_priv, 1180 1246 .soc_probe = mt8186_mt6366_soc_card_probe ··· 1186 1248 .card_data = &(struct mtk_platform_card_data) { 1187 1249 .card = &mt8186_mt6366_rt5650_soc_card, 1188 1250 .num_jacks = MT8186_JACK_MAX, 1251 + .pcm_constraints = mt8186_pcm_constraints, 1252 + .num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints), 1189 1253 }, 1190 1254 .sof_priv = &mt8186_sof_priv, 1191 1255 .soc_probe = mt8186_mt6366_soc_card_probe