From: Trevor Wu <trevor.wu@mediatek.com>
To: <broonie@kernel.org>, <lgirdwood@gmail.com>, <tiwai@suse.com>,
<perex@perex.cz>, <matthias.bgg@gmail.com>,
<angelogioacchino.delregno@collabora.com>
Cc: <trevor.wu@mediatek.com>, <alsa-devel@alsa-project.org>,
<linux-mediatek@lists.infradead.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH] ASoC: mediatek: mt8188: add constraints for PCM
Date: Thu, 29 Jun 2023 15:59:10 +0800 [thread overview]
Message-ID: <20230629075910.21982-1-trevor.wu@mediatek.com> (raw)
For certain projects, only a limited number of parameters are necessary.
Therefore, it may be beneficial to add constraints that restrict the
capacity of the PCM.
Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
---
sound/soc/mediatek/mt8188/mt8188-mt6359.c | 145 +++++++++++++++++++++-
1 file changed, 144 insertions(+), 1 deletion(-)
diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
index ac69c23e0da1..0e4e1b8c99e2 100644
--- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c
+++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
@@ -30,6 +30,7 @@
#define TEST_MISO_DONE_2 BIT(29)
#define NAU8825_HS_PRESENT BIT(0)
+#define DPCM_FE_CONSTRAINT BIT(16)
/*
* Maxim MAX98390
@@ -452,6 +453,143 @@ enum {
DAI_LINK_UL_SRC_BE,
};
+static int mt8188_playback_startup(struct snd_pcm_substream *substream)
+{
+ static const unsigned int rates[] = {
+ 48000
+ };
+ static const unsigned int channels[] = {
+ 2
+ };
+ static const struct snd_pcm_hw_constraint_list constraints_rates = {
+ .count = ARRAY_SIZE(rates),
+ .list = rates,
+ .mask = 0,
+ };
+ static const struct snd_pcm_hw_constraint_list constraints_channels = {
+ .count = ARRAY_SIZE(channels),
+ .list = channels,
+ .mask = 0,
+ };
+
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ struct mt8188_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
+ struct mt8188_card_data *data = (struct mt8188_card_data *)priv->private_data;
+ int ret;
+
+ if (!(data->quirk & DPCM_FE_CONSTRAINT))
+ return 0;
+
+ ret = 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 = 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 mt8188_playback_ops = {
+ .startup = mt8188_playback_startup,
+};
+
+static int mt8188_capture_startup(struct snd_pcm_substream *substream)
+{
+ static const unsigned int rates[] = {
+ 48000
+ };
+ static const struct snd_pcm_hw_constraint_list constraints_rates = {
+ .count = ARRAY_SIZE(rates),
+ .list = rates,
+ .mask = 0,
+ };
+
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ struct mt8188_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
+ struct mt8188_card_data *data = (struct mt8188_card_data *)priv->private_data;
+ int ret;
+
+ if (!(data->quirk & DPCM_FE_CONSTRAINT))
+ return 0;
+
+ ret = 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;
+ }
+
+ return 0;
+}
+
+static const struct snd_soc_ops mt8188_capture_ops = {
+ .startup = mt8188_capture_startup,
+};
+
+static int mt8188_hdmi_dptx_startup(struct snd_pcm_substream *substream)
+{
+ static const unsigned int rates[] = {
+ 48000
+ };
+ static const unsigned int channels[] = {
+ 2, 4, 6, 8
+ };
+ static const struct snd_pcm_hw_constraint_list constraints_rates = {
+ .count = ARRAY_SIZE(rates),
+ .list = rates,
+ .mask = 0,
+ };
+ static const struct snd_pcm_hw_constraint_list constraints_channels = {
+ .count = ARRAY_SIZE(channels),
+ .list = channels,
+ .mask = 0,
+ };
+
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ struct mt8188_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
+ struct mt8188_card_data *data = (struct mt8188_card_data *)priv->private_data;
+ int ret;
+
+ if (!(data->quirk & DPCM_FE_CONSTRAINT))
+ return 0;
+
+ ret = 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 = 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 mt8188_hdmi_dptx_playback_ops = {
+ .startup = mt8188_hdmi_dptx_startup,
+};
+
static int mt8188_dptx_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
@@ -723,6 +861,7 @@ static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
},
.dynamic = 1,
.dpcm_playback = 1,
+ .ops = &mt8188_playback_ops,
SND_SOC_DAILINK_REG(playback2),
},
[DAI_LINK_DL3_FE] = {
@@ -734,6 +873,7 @@ static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
},
.dynamic = 1,
.dpcm_playback = 1,
+ .ops = &mt8188_playback_ops,
SND_SOC_DAILINK_REG(playback3),
},
[DAI_LINK_DL6_FE] = {
@@ -778,6 +918,7 @@ static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
},
.dynamic = 1,
.dpcm_playback = 1,
+ .ops = &mt8188_hdmi_dptx_playback_ops,
SND_SOC_DAILINK_REG(playback10),
},
[DAI_LINK_DL11_FE] = {
@@ -833,6 +974,7 @@ static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
},
.dynamic = 1,
.dpcm_capture = 1,
+ .ops = &mt8188_capture_ops,
SND_SOC_DAILINK_REG(capture4),
},
[DAI_LINK_UL5_FE] = {
@@ -844,6 +986,7 @@ static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
},
.dynamic = 1,
.dpcm_capture = 1,
+ .ops = &mt8188_capture_ops,
SND_SOC_DAILINK_REG(capture5),
},
[DAI_LINK_UL6_FE] = {
@@ -1122,7 +1265,7 @@ static struct mt8188_card_data mt8188_evb_card = {
static struct mt8188_card_data mt8188_nau8825_card = {
.name = "mt8188_nau8825",
- .quirk = NAU8825_HS_PRESENT,
+ .quirk = NAU8825_HS_PRESENT | DPCM_FE_CONSTRAINT,
};
static const struct of_device_id mt8188_mt6359_dt_match[] = {
--
2.18.0
next reply other threads:[~2023-06-29 8:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-29 7:59 Trevor Wu [this message]
2023-06-29 15:06 ` Mark Brown
2023-06-30 5:29 ` Trevor Wu (吳文良)
2023-06-30 11:00 ` Mark Brown
2023-07-03 12:27 ` AngeloGioacchino Del Regno
2023-07-04 2:01 ` Trevor Wu (吳文良)
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=20230629075910.21982-1-trevor.wu@mediatek.com \
--to=trevor.wu@mediatek.com \
--cc=alsa-devel@alsa-project.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=perex@perex.cz \
--cc=tiwai@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®