From nobody Thu Nov 14 04:48:10 2024 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CCCF12DDAE; Thu, 7 Mar 2024 11:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709811924; cv=none; b=iJwZv0dp6/wy/XdFq4lDPx5HIMIqWAHeKxKVZ38jTwNo3VyRjLfBF5424Dyyyjuoi3+X1U2pfwnQBELFYw5gP2YSRXOr/odK91/jH2MATfp3cHMGsokFc+tCflXPEKNgjVPRikWt4G43ojw+CXua+awhtdazaI1f/fAvcUASjUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709811924; c=relaxed/simple; bh=J1cLn1ZkiMj/nqWHv8FW9Fb4kGxB9xQ83ourhgps8rk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rtz6I73nqQsATknOpZ0b7gadte0n9eh6H+1rC3ZE5IUsj78FBMGh2NJ53F+iki5rcGhiZMUu/nwtoqLbfSmmjwjC9NgRJalEGDFk5eTzSRFADhiChbn4/Sv910xN4nNZUuCaLV6DJ8VfD2raZffVl/MjBR884HRkq61a6EKtGxU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=MAdMVrtc; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="MAdMVrtc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709811921; bh=J1cLn1ZkiMj/nqWHv8FW9Fb4kGxB9xQ83ourhgps8rk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MAdMVrtcTCXx5wsZ1ME4xkowWo4ETERQJsy8xRxSRpuiMrezj8MrLK1G6NQ0PyfZC mHK1M/qy26a+SH1ryw9pV3rv0tFWarzYSwWKYpk/2Injc4Kdwq09rPArxhMjmYuaIO 3JNktiklm+OiNiH9/7TWujHNnWuZp+cadeWcOoEIMS9qzL956bdOw8gYPDaLswVi9G FK5SE0KnOyiCBesxQxmugTjkQR+x//L4q+3I7Vt466RoEicGpbeyiABQ1DL0u8kRf6 B1aauKxUPZDw4tWg12CKakFxyxGECs8un91tqHa/BsCilGHLNqibvRehJpT/wCDdvN 8ly46UEJaYdTg== Received: from IcarusMOD.eternityproject.eu (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 7706D37820BB; Thu, 7 Mar 2024 11:45:19 +0000 (UTC) From: AngeloGioacchino Del Regno To: broonie@kernel.org Cc: wenst@chromium.org, lgirdwood@gmail.com, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, matthias.bgg@gmail.com, perex@perex.cz, tiwai@suse.com, trevor.wu@mediatek.com, maso.huang@mediatek.com, xiazhengqiao@huaqin.corp-partner.google.com, arnd@arndb.de, kuninori.morimoto.gx@renesas.com, shraash@google.com, amergnat@baylibre.com, nicolas.ferre@microchip.com, u.kleine-koenig@pengutronix.de, dianders@chromium.org, frank.li@vivo.com, allen-kh.cheng@mediatek.com, eugen.hristev@collabora.com, claudiu.beznea@tuxon.dev, jarkko.nikula@bitmer.com, jiaxin.yu@mediatek.com, alpernebiyasak@gmail.com, ckeepax@opensource.cirrus.com, zhourui@huaqin.corp-partner.google.com, nfraprado@collabora.com, alsa-devel@alsa-project.org, shane.chien@mediatek.com, linux-sound@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, AngeloGioacchino Del Regno Subject: [PATCH v2 12/22] ASoC: mediatek: mt8195: Migrate to the common mtk_soundcard_startup Date: Thu, 7 Mar 2024 12:44:35 +0100 Message-ID: <20240307114445.196981-13-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240307114445.196981-1-angelogioacchino.delregno@collabora.com> References: <20240307114445.196981-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- sound/soc/mediatek/mt8195/mt8195-mt6359.c | 195 ++++++---------------- 1 file changed, 53 insertions(+), 142 deletions(-) diff --git a/sound/soc/mediatek/mt8195/mt8195-mt6359.c b/sound/soc/mediatek= /mt8195/mt8195-mt6359.c index f694618e7635..d143ce3406fe 100644 --- a/sound/soc/mediatek/mt8195/mt8195-mt6359.c +++ b/sound/soc/mediatek/mt8195/mt8195-mt6359.c @@ -328,44 +328,7 @@ static int mt8195_mt6359_init(struct snd_soc_pcm_runti= me *rtd) =20 static int mt8195_hdmitx_dptx_startup(struct snd_pcm_substream *substream) { - static const unsigned int rates[] =3D { - 48000 - }; - static const unsigned int channels[] =3D { - 2, 4, 6, 8 - }; - static const struct snd_pcm_hw_constraint_list constraints_rates =3D { - .count =3D ARRAY_SIZE(rates), - .list =3D rates, - .mask =3D 0, - }; - static const struct snd_pcm_hw_constraint_list constraints_channels =3D { - .count =3D ARRAY_SIZE(channels), - .list =3D channels, - .mask =3D 0, - }; - - struct snd_soc_pcm_runtime *rtd =3D snd_soc_substream_to_rtd(substream); - struct snd_pcm_runtime *runtime =3D substream->runtime; - int ret; - - ret =3D snd_pcm_hw_constraint_list(runtime, 0, - SNDRV_PCM_HW_PARAM_RATE, - &constraints_rates); - if (ret < 0) { - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); - return ret; - } - - ret =3D snd_pcm_hw_constraint_list(runtime, 0, - SNDRV_PCM_HW_PARAM_CHANNELS, - &constraints_channels); - if (ret < 0) { - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); - return ret; - } - - return 0; + return mtk_soundcard_startup(substream, MTK_CONSTRAINT_HDMIDP); } =20 static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops =3D { @@ -428,98 +391,6 @@ static int mt8195_dptx_hw_params_fixup(struct snd_soc_= pcm_runtime *rtd, return 0; } =20 -static int mt8195_playback_startup(struct snd_pcm_substream *substream) -{ - static const unsigned int rates[] =3D { - 48000 - }; - static const unsigned int channels[] =3D { - 2 - }; - static const struct snd_pcm_hw_constraint_list constraints_rates =3D { - .count =3D ARRAY_SIZE(rates), - .list =3D rates, - .mask =3D 0, - }; - static const struct snd_pcm_hw_constraint_list constraints_channels =3D { - .count =3D ARRAY_SIZE(channels), - .list =3D channels, - .mask =3D 0, - }; - - struct snd_soc_pcm_runtime *rtd =3D snd_soc_substream_to_rtd(substream); - struct snd_pcm_runtime *runtime =3D substream->runtime; - int ret; - - ret =3D snd_pcm_hw_constraint_list(runtime, 0, - SNDRV_PCM_HW_PARAM_RATE, - &constraints_rates); - if (ret < 0) { - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); - return ret; - } - - ret =3D snd_pcm_hw_constraint_list(runtime, 0, - SNDRV_PCM_HW_PARAM_CHANNELS, - &constraints_channels); - if (ret < 0) { - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); - return ret; - } - - return 0; -} - -static const struct snd_soc_ops mt8195_playback_ops =3D { - .startup =3D mt8195_playback_startup, -}; - -static int mt8195_capture_startup(struct snd_pcm_substream *substream) -{ - static const unsigned int rates[] =3D { - 48000 - }; - static const unsigned int channels[] =3D { - 1, 2 - }; - static const struct snd_pcm_hw_constraint_list constraints_rates =3D { - .count =3D ARRAY_SIZE(rates), - .list =3D rates, - .mask =3D 0, - }; - static const struct snd_pcm_hw_constraint_list constraints_channels =3D { - .count =3D ARRAY_SIZE(channels), - .list =3D channels, - .mask =3D 0, - }; - - struct snd_soc_pcm_runtime *rtd =3D snd_soc_substream_to_rtd(substream); - struct snd_pcm_runtime *runtime =3D substream->runtime; - int ret; - - ret =3D snd_pcm_hw_constraint_list(runtime, 0, - SNDRV_PCM_HW_PARAM_RATE, - &constraints_rates); - if (ret < 0) { - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); - return ret; - } - - ret =3D snd_pcm_hw_constraint_list(runtime, 0, - SNDRV_PCM_HW_PARAM_CHANNELS, - &constraints_channels); - if (ret < 0) { - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); - return ret; - } - - return 0; -} - -static const struct snd_soc_ops mt8195_capture_ops =3D { - .startup =3D mt8195_capture_startup, -}; - static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream *substrea= m, struct snd_pcm_hw_params *params) { @@ -1042,7 +913,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_links= [] =3D { }, .dynamic =3D 1, .dpcm_playback =3D 1, - .ops =3D &mt8195_playback_ops, + .ops =3D &mtk_soundcard_common_playback_ops, SND_SOC_DAILINK_REG(DL2_FE), }, [DAI_LINK_DL3_FE] =3D { @@ -1054,7 +925,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_links= [] =3D { }, .dynamic =3D 1, .dpcm_playback =3D 1, - .ops =3D &mt8195_playback_ops, + .ops =3D &mtk_soundcard_common_playback_ops, SND_SOC_DAILINK_REG(DL3_FE), }, [DAI_LINK_DL6_FE] =3D { @@ -1066,7 +937,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_links= [] =3D { }, .dynamic =3D 1, .dpcm_playback =3D 1, - .ops =3D &mt8195_playback_ops, + .ops =3D &mtk_soundcard_common_playback_ops, SND_SOC_DAILINK_REG(DL6_FE), }, [DAI_LINK_DL7_FE] =3D { @@ -1089,7 +960,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_links= [] =3D { }, .dynamic =3D 1, .dpcm_playback =3D 1, - .ops =3D &mt8195_playback_ops, + .ops =3D &mtk_soundcard_common_playback_ops, SND_SOC_DAILINK_REG(DL8_FE), }, [DAI_LINK_DL10_FE] =3D { @@ -1113,7 +984,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_links= [] =3D { }, .dynamic =3D 1, .dpcm_playback =3D 1, - .ops =3D &mt8195_playback_ops, + .ops =3D &mtk_soundcard_common_playback_ops, SND_SOC_DAILINK_REG(DL11_FE), }, [DAI_LINK_UL1_FE] =3D { @@ -1136,7 +1007,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_link= s[] =3D { }, .dynamic =3D 1, .dpcm_capture =3D 1, - .ops =3D &mt8195_capture_ops, + .ops =3D &mtk_soundcard_common_capture_ops, SND_SOC_DAILINK_REG(UL2_FE), }, [DAI_LINK_UL3_FE] =3D { @@ -1148,7 +1019,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_link= s[] =3D { }, .dynamic =3D 1, .dpcm_capture =3D 1, - .ops =3D &mt8195_capture_ops, + .ops =3D &mtk_soundcard_common_capture_ops, SND_SOC_DAILINK_REG(UL3_FE), }, [DAI_LINK_UL4_FE] =3D { @@ -1160,7 +1031,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_link= s[] =3D { }, .dynamic =3D 1, .dpcm_capture =3D 1, - .ops =3D &mt8195_capture_ops, + .ops =3D &mtk_soundcard_common_capture_ops, SND_SOC_DAILINK_REG(UL4_FE), }, [DAI_LINK_UL5_FE] =3D { @@ -1172,7 +1043,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_link= s[] =3D { }, .dynamic =3D 1, .dpcm_capture =3D 1, - .ops =3D &mt8195_capture_ops, + .ops =3D &mtk_soundcard_common_capture_ops, SND_SOC_DAILINK_REG(UL5_FE), }, [DAI_LINK_UL6_FE] =3D { @@ -1195,7 +1066,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_link= s[] =3D { }, .dynamic =3D 1, .dpcm_capture =3D 1, - .ops =3D &mt8195_capture_ops, + .ops =3D &mtk_soundcard_common_capture_ops, SND_SOC_DAILINK_REG(UL8_FE), }, [DAI_LINK_UL9_FE] =3D { @@ -1207,7 +1078,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_link= s[] =3D { }, .dynamic =3D 1, .dpcm_capture =3D 1, - .ops =3D &mt8195_capture_ops, + .ops =3D &mtk_soundcard_common_capture_ops, SND_SOC_DAILINK_REG(UL9_FE), }, [DAI_LINK_UL10_FE] =3D { @@ -1219,7 +1090,7 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_link= s[] =3D { }, .dynamic =3D 1, .dpcm_capture =3D 1, - .ops =3D &mt8195_capture_ops, + .ops =3D &mtk_soundcard_common_capture_ops, SND_SOC_DAILINK_REG(UL10_FE), }, /* BE */ @@ -1561,6 +1432,40 @@ static int mt8195_mt6359_soc_card_probe(struct mtk_s= oc_card_data *soc_card_data, return 0; } =20 +static const unsigned int mt8195_pcm_playback_channels[] =3D { 2 }; +static const unsigned int mt8195_pcm_capture_channels[] =3D { 1, 2 }; +static const unsigned int mt8195_pcm_hdmidp_channels[] =3D { 2, 4, 6, 8 }; +static const unsigned int mt8195_pcm_rates[] =3D { 48000 }; + +static const struct snd_pcm_hw_constraint_list mt8195_rate_constraint =3D { + .list =3D mt8195_pcm_rates, + .count =3D ARRAY_SIZE(mt8195_pcm_rates) +}; + +static const struct mtk_pcm_constraints_data mt8195_pcm_constraints[MTK_CO= NSTRAINT_HDMIDP + 1] =3D { + [MTK_CONSTRAINT_PLAYBACK] =3D { + .channels =3D { + .list =3D mt8195_pcm_playback_channels, + .count =3D ARRAY_SIZE(mt8195_pcm_playback_channels) + }, + .rates =3D mt8195_rate_constraint, + }, + [MTK_CONSTRAINT_CAPTURE] =3D { + .channels =3D { + .list =3D mt8195_pcm_capture_channels, + .count =3D ARRAY_SIZE(mt8195_pcm_capture_channels) + }, + .rates =3D mt8195_rate_constraint, + }, + [MTK_CONSTRAINT_HDMIDP] =3D { + .channels =3D { + .list =3D mt8195_pcm_hdmidp_channels, + .count =3D ARRAY_SIZE(mt8195_pcm_hdmidp_channels) + }, + .rates =3D mt8195_rate_constraint, + }, +}; + static const struct mtk_sof_priv mt8195_sof_priv =3D { .conn_streams =3D g_sof_conn_streams, .num_streams =3D ARRAY_SIZE(g_sof_conn_streams), @@ -1572,6 +1477,8 @@ static const struct mtk_soundcard_pdata mt8195_mt6359= _rt1019_rt5682_card =3D { .card_data =3D &(struct mtk_platform_card_data) { .card =3D &mt8195_mt6359_soc_card, .num_jacks =3D MT8195_JACK_MAX, + .pcm_constraints =3D mt8195_pcm_constraints, + .num_pcm_constraints =3D ARRAY_SIZE(mt8195_pcm_constraints), .flags =3D RT1019_SPEAKER_AMP_PRESENT }, .sof_priv =3D &mt8195_sof_priv, @@ -1583,6 +1490,8 @@ static const struct mtk_soundcard_pdata mt8195_mt6359= _rt1011_rt5682_card =3D { .card_data =3D &(struct mtk_platform_card_data) { .card =3D &mt8195_mt6359_soc_card, .num_jacks =3D MT8195_JACK_MAX, + .pcm_constraints =3D mt8195_pcm_constraints, + .num_pcm_constraints =3D ARRAY_SIZE(mt8195_pcm_constraints), .flags =3D RT1011_SPEAKER_AMP_PRESENT }, .sof_priv =3D &mt8195_sof_priv, @@ -1594,6 +1503,8 @@ static const struct mtk_soundcard_pdata mt8195_mt6359= _max98390_rt5682_card =3D { .card_data =3D &(struct mtk_platform_card_data) { .card =3D &mt8195_mt6359_soc_card, .num_jacks =3D MT8195_JACK_MAX, + .pcm_constraints =3D mt8195_pcm_constraints, + .num_pcm_constraints =3D ARRAY_SIZE(mt8195_pcm_constraints), .flags =3D MAX98390_SPEAKER_AMP_PRESENT }, .sof_priv =3D &mt8195_sof_priv, --=20 2.44.0