All of lore.kernel.org
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
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
	<angelogioacchino.delregno@collabora.com>
Subject: [PATCH v4 07/18] ASoC: mediatek: Add common snd_soc_ops .startup() callback
Date: Tue,  9 Apr 2024 13:32:59 +0200	[thread overview]
Message-ID: <20240409113310.303261-8-angelogioacchino.delregno@collabora.com> (raw)
In-Reply-To: <20240409113310.303261-1-angelogioacchino.delregno@collabora.com>

MediaTek platforms are typically setting PCM rate and channels
constraints for playback, capture and HDMI/DisplayPort playback:
commonize the startup callback by adding the PCM constraints data
to the mtk_platform_card_data structure and by reusing the common
mtk_soundcard_startup() function for all of them by getting back
the parameters from the aforementioned struct.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 .../mediatek/common/mtk-soundcard-driver.c    | 51 +++++++++++++++++++
 .../mediatek/common/mtk-soundcard-driver.h    | 24 +++++++++
 2 files changed, 75 insertions(+)

diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.c b/sound/soc/mediatek/common/mtk-soundcard-driver.c
index b1db17e392d5..d344630f7851 100644
--- a/sound/soc/mediatek/common/mtk-soundcard-driver.c
+++ b/sound/soc/mediatek/common/mtk-soundcard-driver.c
@@ -139,6 +139,57 @@ void clean_card_reference(struct snd_soc_card *card)
 }
 EXPORT_SYMBOL_GPL(clean_card_reference);
 
+int mtk_soundcard_startup(struct snd_pcm_substream *substream,
+			  enum mtk_pcm_constraint_type ctype)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct mtk_soc_card_data *soc_card = snd_soc_card_get_drvdata(rtd->card);
+	const struct mtk_pcm_constraints_data *mpc = &soc_card->card_data->pcm_constraints[ctype];
+	int ret;
+
+	if (unlikely(!mpc))
+		return -EINVAL;
+
+	ret = snd_pcm_hw_constraint_list(substream->runtime, 0,
+					 SNDRV_PCM_HW_PARAM_RATE,
+					 &mpc->rates);
+	if (ret < 0) {
+		dev_err(rtd->dev, "hw_constraint_list rate failed\n");
+		return ret;
+	}
+
+	ret = snd_pcm_hw_constraint_list(substream->runtime, 0,
+					 SNDRV_PCM_HW_PARAM_CHANNELS,
+					 &mpc->channels);
+	if (ret < 0) {
+		dev_err(rtd->dev, "hw_constraint_list channel failed\n");
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mtk_soundcard_startup);
+
+static int mtk_soundcard_playback_startup(struct snd_pcm_substream *substream)
+{
+	return mtk_soundcard_startup(substream, MTK_CONSTRAINT_PLAYBACK);
+}
+
+const struct snd_soc_ops mtk_soundcard_common_playback_ops = {
+	.startup = mtk_soundcard_playback_startup,
+};
+EXPORT_SYMBOL_GPL(mtk_soundcard_common_playback_ops);
+
+static int mtk_soundcard_capture_startup(struct snd_pcm_substream *substream)
+{
+	return mtk_soundcard_startup(substream, MTK_CONSTRAINT_CAPTURE);
+}
+
+const struct snd_soc_ops mtk_soundcard_common_capture_ops = {
+	.startup = mtk_soundcard_capture_startup,
+};
+EXPORT_SYMBOL_GPL(mtk_soundcard_common_capture_ops);
+
 int mtk_soundcard_common_probe(struct platform_device *pdev)
 {
 	struct device_node *platform_node, *adsp_node;
diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.h b/sound/soc/mediatek/common/mtk-soundcard-driver.h
index 4fd2ffb7e486..c38e2ac09ad3 100644
--- a/sound/soc/mediatek/common/mtk-soundcard-driver.h
+++ b/sound/soc/mediatek/common/mtk-soundcard-driver.h
@@ -11,11 +11,26 @@
 
 struct mtk_sof_priv;
 struct mtk_soc_card_data;
+struct snd_pcm_hw_constraint_list;
+
+enum mtk_pcm_constraint_type {
+	MTK_CONSTRAINT_PLAYBACK,
+	MTK_CONSTRAINT_CAPTURE,
+	MTK_CONSTRAINT_HDMIDP,
+	MTK_CONSTRAINT_MAX
+};
+
+struct mtk_pcm_constraints_data {
+	const struct snd_pcm_hw_constraint_list channels;
+	const struct snd_pcm_hw_constraint_list rates;
+};
 
 struct mtk_platform_card_data {
 	struct snd_soc_card *card;
 	struct snd_soc_jack *jacks;
+	const struct mtk_pcm_constraints_data *pcm_constraints;
 	u8 num_jacks;
+	u8 num_pcm_constraints;
 	u8 flags;
 };
 
@@ -23,9 +38,18 @@ struct mtk_soundcard_pdata {
 	const char *card_name;
 	struct mtk_platform_card_data *card_data;
 	const struct mtk_sof_priv *sof_priv;
+
 	int (*soc_probe)(struct mtk_soc_card_data *card_data, bool legacy);
 };
 
+/* Common playback/capture card startup ops */
+extern const struct snd_soc_ops mtk_soundcard_common_playback_ops;
+extern const struct snd_soc_ops mtk_soundcard_common_capture_ops;
+
+/* Exported for custom/extended soundcard startup ops */
+int mtk_soundcard_startup(struct snd_pcm_substream *substream,
+			  enum mtk_pcm_constraint_type ctype);
+
 int parse_dai_link_info(struct snd_soc_card *card);
 void clean_card_reference(struct snd_soc_card *card);
 int mtk_soundcard_common_probe(struct platform_device *pdev);
-- 
2.44.0


WARNING: multiple messages have this Message-ID (diff)
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: broonie@kernel.org
Cc: shraash@google.com, alsa-devel@alsa-project.org,
	allen-kh.cheng@mediatek.com, kuninori.morimoto.gx@renesas.com,
	lgirdwood@gmail.com, tiwai@suse.com, shane.chien@mediatek.com,
	krzysztof.kozlowski+dt@linaro.org, claudiu.beznea@tuxon.dev,
	kernel@collabora.com, robh@kernel.org, nfraprado@collabora.com,
	amergnat@baylibre.com, zhourui@huaqin.corp-partner.google.com,
	jiaxin.yu@mediatek.com, trevor.wu@mediatek.com,
	wenst@chromium.org, devicetree@vger.kernel.org,
	conor+dt@kernel.org, ckeepax@opensource.cirrus.com,
	arnd@arndb.de, frank.li@vivo.com, maso.huang@mediatek.com,
	u.kleine-koenig@pengutronix.de, eugen.hristev@collabora.com,
	alpernebiyasak@gmail.com, linux-mediatek@lists.infradead.org,
	linux-sound@vger.kernel.org, matthias.bgg@gmail.com,
	perex@perex.cz, linux-arm-kernel@lists.infradead.org,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	xiazhengqiao@huaqin.corp-partner.google.com,
	dianders@chromium.org, linux-kernel@vger.kernel.org,
	jarkko.nikula@bitmer.com
Subject: [PATCH v4 07/18] ASoC: mediatek: Add common snd_soc_ops .startup() callback
Date: Tue,  9 Apr 2024 13:32:59 +0200	[thread overview]
Message-ID: <20240409113310.303261-8-angelogioacchino.delregno@collabora.com> (raw)
In-Reply-To: <20240409113310.303261-1-angelogioacchino.delregno@collabora.com>

MediaTek platforms are typically setting PCM rate and channels
constraints for playback, capture and HDMI/DisplayPort playback:
commonize the startup callback by adding the PCM constraints data
to the mtk_platform_card_data structure and by reusing the common
mtk_soundcard_startup() function for all of them by getting back
the parameters from the aforementioned struct.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 .../mediatek/common/mtk-soundcard-driver.c    | 51 +++++++++++++++++++
 .../mediatek/common/mtk-soundcard-driver.h    | 24 +++++++++
 2 files changed, 75 insertions(+)

diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.c b/sound/soc/mediatek/common/mtk-soundcard-driver.c
index b1db17e392d5..d344630f7851 100644
--- a/sound/soc/mediatek/common/mtk-soundcard-driver.c
+++ b/sound/soc/mediatek/common/mtk-soundcard-driver.c
@@ -139,6 +139,57 @@ void clean_card_reference(struct snd_soc_card *card)
 }
 EXPORT_SYMBOL_GPL(clean_card_reference);
 
+int mtk_soundcard_startup(struct snd_pcm_substream *substream,
+			  enum mtk_pcm_constraint_type ctype)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct mtk_soc_card_data *soc_card = snd_soc_card_get_drvdata(rtd->card);
+	const struct mtk_pcm_constraints_data *mpc = &soc_card->card_data->pcm_constraints[ctype];
+	int ret;
+
+	if (unlikely(!mpc))
+		return -EINVAL;
+
+	ret = snd_pcm_hw_constraint_list(substream->runtime, 0,
+					 SNDRV_PCM_HW_PARAM_RATE,
+					 &mpc->rates);
+	if (ret < 0) {
+		dev_err(rtd->dev, "hw_constraint_list rate failed\n");
+		return ret;
+	}
+
+	ret = snd_pcm_hw_constraint_list(substream->runtime, 0,
+					 SNDRV_PCM_HW_PARAM_CHANNELS,
+					 &mpc->channels);
+	if (ret < 0) {
+		dev_err(rtd->dev, "hw_constraint_list channel failed\n");
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mtk_soundcard_startup);
+
+static int mtk_soundcard_playback_startup(struct snd_pcm_substream *substream)
+{
+	return mtk_soundcard_startup(substream, MTK_CONSTRAINT_PLAYBACK);
+}
+
+const struct snd_soc_ops mtk_soundcard_common_playback_ops = {
+	.startup = mtk_soundcard_playback_startup,
+};
+EXPORT_SYMBOL_GPL(mtk_soundcard_common_playback_ops);
+
+static int mtk_soundcard_capture_startup(struct snd_pcm_substream *substream)
+{
+	return mtk_soundcard_startup(substream, MTK_CONSTRAINT_CAPTURE);
+}
+
+const struct snd_soc_ops mtk_soundcard_common_capture_ops = {
+	.startup = mtk_soundcard_capture_startup,
+};
+EXPORT_SYMBOL_GPL(mtk_soundcard_common_capture_ops);
+
 int mtk_soundcard_common_probe(struct platform_device *pdev)
 {
 	struct device_node *platform_node, *adsp_node;
diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.h b/sound/soc/mediatek/common/mtk-soundcard-driver.h
index 4fd2ffb7e486..c38e2ac09ad3 100644
--- a/sound/soc/mediatek/common/mtk-soundcard-driver.h
+++ b/sound/soc/mediatek/common/mtk-soundcard-driver.h
@@ -11,11 +11,26 @@
 
 struct mtk_sof_priv;
 struct mtk_soc_card_data;
+struct snd_pcm_hw_constraint_list;
+
+enum mtk_pcm_constraint_type {
+	MTK_CONSTRAINT_PLAYBACK,
+	MTK_CONSTRAINT_CAPTURE,
+	MTK_CONSTRAINT_HDMIDP,
+	MTK_CONSTRAINT_MAX
+};
+
+struct mtk_pcm_constraints_data {
+	const struct snd_pcm_hw_constraint_list channels;
+	const struct snd_pcm_hw_constraint_list rates;
+};
 
 struct mtk_platform_card_data {
 	struct snd_soc_card *card;
 	struct snd_soc_jack *jacks;
+	const struct mtk_pcm_constraints_data *pcm_constraints;
 	u8 num_jacks;
+	u8 num_pcm_constraints;
 	u8 flags;
 };
 
@@ -23,9 +38,18 @@ struct mtk_soundcard_pdata {
 	const char *card_name;
 	struct mtk_platform_card_data *card_data;
 	const struct mtk_sof_priv *sof_priv;
+
 	int (*soc_probe)(struct mtk_soc_card_data *card_data, bool legacy);
 };
 
+/* Common playback/capture card startup ops */
+extern const struct snd_soc_ops mtk_soundcard_common_playback_ops;
+extern const struct snd_soc_ops mtk_soundcard_common_capture_ops;
+
+/* Exported for custom/extended soundcard startup ops */
+int mtk_soundcard_startup(struct snd_pcm_substream *substream,
+			  enum mtk_pcm_constraint_type ctype);
+
 int parse_dai_link_info(struct snd_soc_card *card);
 void clean_card_reference(struct snd_soc_card *card);
 int mtk_soundcard_common_probe(struct platform_device *pdev);
-- 
2.44.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2024-04-09 11:33 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09 11:32 [PATCH v4 00/18] SoC: Cleanup MediaTek soundcard machine drivers AngeloGioacchino Del Regno
2024-04-09 11:32 ` AngeloGioacchino Del Regno
2024-04-09 11:32 ` [PATCH v4 01/18] ASoC: mediatek: Add common machine soundcard driver probe mechanism AngeloGioacchino Del Regno
2024-04-09 11:32   ` AngeloGioacchino Del Regno
2024-04-10 12:42   ` Alexandre Mergnat
2024-04-10 12:42     ` Alexandre Mergnat
2024-04-09 11:32 ` [PATCH v4 02/18] ASoC: mediatek: common: Constify struct mtk_sof_priv AngeloGioacchino Del Regno
2024-04-09 11:32   ` AngeloGioacchino Del Regno
2024-04-10 12:46   ` Alexandre Mergnat
2024-04-10 12:46     ` Alexandre Mergnat
2024-04-09 11:32 ` [PATCH v4 03/18] ASoC: mediatek: mt8188: Migrate to mtk_soundcard_common_probe AngeloGioacchino Del Regno
2024-04-09 11:32   ` AngeloGioacchino Del Regno
2024-04-10 12:58   ` Alexandre Mergnat
2024-04-10 12:58     ` Alexandre Mergnat
2024-04-09 11:32 ` [PATCH v4 04/18] ASoC: mediatek: mt8195: " AngeloGioacchino Del Regno
2024-04-09 11:32   ` AngeloGioacchino Del Regno
2024-04-10 13:46   ` Alexandre Mergnat
2024-04-10 13:46     ` Alexandre Mergnat
2024-04-09 11:32 ` [PATCH v4 05/18] ASoC: mediatek: mt8192: " AngeloGioacchino Del Regno
2024-04-09 11:32   ` AngeloGioacchino Del Regno
2024-04-10 13:59   ` Alexandre Mergnat
2024-04-10 13:59     ` Alexandre Mergnat
2024-04-10 15:28     ` AngeloGioacchino Del Regno
2024-04-10 15:28       ` AngeloGioacchino Del Regno
2024-04-09 11:32 ` [PATCH v4 06/18] ASoC: mediatek: mt8186: " AngeloGioacchino Del Regno
2024-04-09 11:32   ` AngeloGioacchino Del Regno
2024-04-10 14:02   ` Alexandre Mergnat
2024-04-10 14:02     ` Alexandre Mergnat
2024-04-09 11:32 ` AngeloGioacchino Del Regno [this message]
2024-04-09 11:32   ` [PATCH v4 07/18] ASoC: mediatek: Add common snd_soc_ops .startup() callback AngeloGioacchino Del Regno
2024-04-10 14:27   ` Alexandre Mergnat
2024-04-10 14:27     ` Alexandre Mergnat
2024-04-09 11:33 ` [PATCH v4 08/18] ASoC: mediatek: mt8195: Migrate to the common mtk_soundcard_startup AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-10 14:54   ` Alexandre Mergnat
2024-04-10 14:54     ` Alexandre Mergnat
2024-04-15 16:33   ` kernel test robot
2024-04-09 11:33 ` [PATCH v4 09/18] ASoC: mediatek: mt8192: " AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-10 14:55   ` Alexandre Mergnat
2024-04-10 14:55     ` Alexandre Mergnat
2024-04-09 11:33 ` [PATCH v4 10/18] ASoC: mediatek: mt8186-rt1019: " AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-10 15:07   ` Alexandre Mergnat
2024-04-10 15:07     ` Alexandre Mergnat
2024-04-09 11:33 ` [PATCH v4 11/18] ASoC: mediatek: Add common mtk_afe_component_probe callback AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-10 15:13   ` Alexandre Mergnat
2024-04-10 15:13     ` Alexandre Mergnat
2024-04-09 11:33 ` [PATCH v4 12/18] ASoC: mediatek: Use common mtk_afe_pcm_platform with common probe cb AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-10 15:14   ` Alexandre Mergnat
2024-04-10 15:14     ` Alexandre Mergnat
2024-04-09 11:33 ` [PATCH v4 13/18] ASoC: mediatek: mt8186: Unify mt8186-mt6366 machine drivers AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-10 15:38   ` Alexandre Mergnat
2024-04-10 15:38     ` Alexandre Mergnat
2024-04-09 11:33 ` [PATCH v4 14/18] ASoC: dt-bindings: mt8195: Document audio-routing and dai-link subnode AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-09 11:33 ` [PATCH v4 15/18] ASoC: dt-bindings: mt8192: " AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-09 11:33 ` [PATCH v4 16/18] ASoC: dt-bindings: mt8186: " AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-09 11:33 ` [PATCH v4 17/18] arm64: dts: mediatek: mt8195-cherry: Specify sound DAI links and routing AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno
2024-04-09 11:33 ` [PATCH v4 18/18] arm64: dts: mediatek: mt8186-corsola: " AngeloGioacchino Del Regno
2024-04-09 11:33   ` AngeloGioacchino Del Regno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240409113310.303261-8-angelogioacchino.delregno@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=allen-kh.cheng@mediatek.com \
    --cc=alpernebiyasak@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=amergnat@baylibre.com \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@chromium.org \
    --cc=eugen.hristev@collabora.com \
    --cc=frank.li@vivo.com \
    --cc=jarkko.nikula@bitmer.com \
    --cc=jiaxin.yu@mediatek.com \
    --cc=kernel@collabora.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=maso.huang@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=nfraprado@collabora.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=perex@perex.cz \
    --cc=robh@kernel.org \
    --cc=shane.chien@mediatek.com \
    --cc=shraash@google.com \
    --cc=tiwai@suse.com \
    --cc=trevor.wu@mediatek.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wenst@chromium.org \
    --cc=xiazhengqiao@huaqin.corp-partner.google.com \
    --cc=zhourui@huaqin.corp-partner.google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.