diff mbox series

[1/5] ASoC: mediatek: mt8188: separate ADDA playback dai from capture dai

Message ID 20230517111534.32630-2-trevor.wu@mediatek.com (mailing list archive)
State New, archived
Headers show
Series ASoC: mt8188: add new board support | expand

Commit Message

Trevor Wu (吳文良) May 17, 2023, 11:15 a.m. UTC
MT8188 will support SOF. In SOF, be_hw_params_fixup callback are used to
configure BE hardware parameters. However, playback and capture stream
share the same callback function in which it can't know the stream type.

It's possible to require different paremters for playback and capture
stream, so separate them into two dais for SOF usage.

Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
---
 sound/soc/mediatek/mt8188/mt8188-afe-common.h |  3 +-
 sound/soc/mediatek/mt8188/mt8188-dai-adda.c   | 76 ++++++++++---------
 sound/soc/mediatek/mt8188/mt8188-mt6359.c     | 34 +++++++--
 3 files changed, 68 insertions(+), 45 deletions(-)

Comments

AngeloGioacchino Del Regno May 17, 2023, 11:40 a.m. UTC | #1
Il 17/05/23 13:15, Trevor Wu ha scritto:
> MT8188 will support SOF. In SOF, be_hw_params_fixup callback are used to
> configure BE hardware parameters. However, playback and capture stream
> share the same callback function in which it can't know the stream type.
> 
> It's possible to require different paremters for playback and capture
> stream, so separate them into two dais for SOF usage.
> 
> Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
> ---
>   sound/soc/mediatek/mt8188/mt8188-afe-common.h |  3 +-
>   sound/soc/mediatek/mt8188/mt8188-dai-adda.c   | 76 ++++++++++---------
>   sound/soc/mediatek/mt8188/mt8188-mt6359.c     | 34 +++++++--
>   3 files changed, 68 insertions(+), 45 deletions(-)
> 
> diff --git a/sound/soc/mediatek/mt8188/mt8188-afe-common.h b/sound/soc/mediatek/mt8188/mt8188-afe-common.h
> index eb7e57c239bd..1304d685a306 100644
> --- a/sound/soc/mediatek/mt8188/mt8188-afe-common.h
> +++ b/sound/soc/mediatek/mt8188/mt8188-afe-common.h
> @@ -39,7 +39,7 @@ enum {
>   	MT8188_AFE_MEMIF_END,
>   	MT8188_AFE_MEMIF_NUM = (MT8188_AFE_MEMIF_END - MT8188_AFE_MEMIF_START),
>   	MT8188_AFE_IO_START = MT8188_AFE_MEMIF_END,
> -	MT8188_AFE_IO_ADDA = MT8188_AFE_IO_START,
> +	MT8188_AFE_IO_DL_SRC = MT8188_AFE_IO_START,
>   	MT8188_AFE_IO_DMIC_IN,
>   	MT8188_AFE_IO_DPTX,
>   	MT8188_AFE_IO_ETDM_START,
> @@ -52,6 +52,7 @@ enum {
>   	MT8188_AFE_IO_ETDM_NUM =
>   		(MT8188_AFE_IO_ETDM_END - MT8188_AFE_IO_ETDM_START),
>   	MT8188_AFE_IO_PCM = MT8188_AFE_IO_ETDM_END,
> +	MT8188_AFE_IO_UL_SRC,
>   	MT8188_AFE_IO_END,
>   	MT8188_AFE_IO_NUM = (MT8188_AFE_IO_END - MT8188_AFE_IO_START),
>   	MT8188_DAI_END = MT8188_AFE_IO_END,
> diff --git a/sound/soc/mediatek/mt8188/mt8188-dai-adda.c b/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
> index fed9f927e623..9a6673a6f28a 100644
> --- a/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
> +++ b/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
> @@ -53,8 +53,7 @@ enum {
>   };
>   
>   struct mtk_dai_adda_priv {
> -	unsigned int dl_rate;
> -	unsigned int ul_rate;
> +	bool hires_required;
>   };
>   
>   static unsigned int afe_adda_dl_rate_transform(struct mtk_base_afe *afe,

..snip..

> @@ -503,13 +495,15 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream,
>   	dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %u\n",
>   		__func__, id, substream->stream, rate);
>   
> -	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
> -		adda_priv->dl_rate = rate;
> +	if (rate > ADDA_HIRES_THRES)
> +		adda_priv->hires_required = 1;
> +	else
> +		adda_priv->hires_required = 0;
> +

hires_required is a boolean, so assigning 1 or 0 should be replaced with
assigning true or false; regardless of that, what about...

	adda_priv->hires_required = (rate > ADDA_HIRES_THRES);

> +	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
>   		ret = mtk_dai_da_configure(afe, rate, id);
> -	} else {
> -		adda_priv->ul_rate = rate;
> +	else
>   		ret = mtk_dai_ad_configure(afe, rate, id);
> -	}
>   
>   	return ret;
>   }

Regards,
Angelo
Trevor Wu (吳文良) May 17, 2023, 12:13 p.m. UTC | #2
On Wed, 2023-05-17 at 13:40 +0200, AngeloGioacchino Del Regno wrote:
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> 
> 
> Il 17/05/23 13:15, Trevor Wu ha scritto:
> > MT8188 will support SOF. In SOF, be_hw_params_fixup callback are
> > used to
> > configure BE hardware parameters. However, playback and capture
> > stream
> > share the same callback function in which it can't know the stream
> > type.
> > 
> > It's possible to require different paremters for playback and
> > capture
> > stream, so separate them into two dais for SOF usage.
> > 
> > Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
> > ---
> >   sound/soc/mediatek/mt8188/mt8188-afe-common.h |  3 +-
> >   sound/soc/mediatek/mt8188/mt8188-dai-adda.c   | 76 ++++++++++--
> > -------
> >   sound/soc/mediatek/mt8188/mt8188-mt6359.c     | 34 +++++++--
> >   3 files changed, 68 insertions(+), 45 deletions(-)
> > 
> > diff --git a/sound/soc/mediatek/mt8188/mt8188-afe-common.h
> > b/sound/soc/mediatek/mt8188/mt8188-afe-common.h
> > index eb7e57c239bd..1304d685a306 100644
> > --- a/sound/soc/mediatek/mt8188/mt8188-afe-common.h
> > +++ b/sound/soc/mediatek/mt8188/mt8188-afe-common.h
> > @@ -39,7 +39,7 @@ enum {
> >       MT8188_AFE_MEMIF_END,
> >       MT8188_AFE_MEMIF_NUM = (MT8188_AFE_MEMIF_END -
> > MT8188_AFE_MEMIF_START),
> >       MT8188_AFE_IO_START = MT8188_AFE_MEMIF_END,
> > -     MT8188_AFE_IO_ADDA = MT8188_AFE_IO_START,
> > +     MT8188_AFE_IO_DL_SRC = MT8188_AFE_IO_START,
> >       MT8188_AFE_IO_DMIC_IN,
> >       MT8188_AFE_IO_DPTX,
> >       MT8188_AFE_IO_ETDM_START,
> > @@ -52,6 +52,7 @@ enum {
> >       MT8188_AFE_IO_ETDM_NUM =
> >               (MT8188_AFE_IO_ETDM_END - MT8188_AFE_IO_ETDM_START),
> >       MT8188_AFE_IO_PCM = MT8188_AFE_IO_ETDM_END,
> > +     MT8188_AFE_IO_UL_SRC,
> >       MT8188_AFE_IO_END,
> >       MT8188_AFE_IO_NUM = (MT8188_AFE_IO_END -
> > MT8188_AFE_IO_START),
> >       MT8188_DAI_END = MT8188_AFE_IO_END,
> > diff --git a/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
> > b/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
> > index fed9f927e623..9a6673a6f28a 100644
> > --- a/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
> > +++ b/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
> > @@ -53,8 +53,7 @@ enum {
> >   };
> > 
> >   struct mtk_dai_adda_priv {
> > -     unsigned int dl_rate;
> > -     unsigned int ul_rate;
> > +     bool hires_required;
> >   };
> > 
> >   static unsigned int afe_adda_dl_rate_transform(struct
> > mtk_base_afe *afe,
> 
> ..snip..
> 
> > @@ -503,13 +495,15 @@ static int mtk_dai_adda_hw_params(struct
> > snd_pcm_substream *substream,
> >       dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %u\n",
> >               __func__, id, substream->stream, rate);
> > 
> > -     if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
> > -             adda_priv->dl_rate = rate;
> > +     if (rate > ADDA_HIRES_THRES)
> > +             adda_priv->hires_required = 1;
> > +     else
> > +             adda_priv->hires_required = 0;
> > +
> 
> hires_required is a boolean, so assigning 1 or 0 should be replaced
> with
> assigning true or false; regardless of that, what about...
> 
>         adda_priv->hires_required = (rate > ADDA_HIRES_THRES);
> 

It's great!! I will adopt it in V2.

Thanks,
Trevor

> > +     if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
> >               ret = mtk_dai_da_configure(afe, rate, id);
> > -     } else {
> > -             adda_priv->ul_rate = rate;
> > +     else
> >               ret = mtk_dai_ad_configure(afe, rate, id);
> > -     }
> > 
> >       return ret;
> >   }
> 
> Regards,
> Angelo
diff mbox series

Patch

diff --git a/sound/soc/mediatek/mt8188/mt8188-afe-common.h b/sound/soc/mediatek/mt8188/mt8188-afe-common.h
index eb7e57c239bd..1304d685a306 100644
--- a/sound/soc/mediatek/mt8188/mt8188-afe-common.h
+++ b/sound/soc/mediatek/mt8188/mt8188-afe-common.h
@@ -39,7 +39,7 @@  enum {
 	MT8188_AFE_MEMIF_END,
 	MT8188_AFE_MEMIF_NUM = (MT8188_AFE_MEMIF_END - MT8188_AFE_MEMIF_START),
 	MT8188_AFE_IO_START = MT8188_AFE_MEMIF_END,
-	MT8188_AFE_IO_ADDA = MT8188_AFE_IO_START,
+	MT8188_AFE_IO_DL_SRC = MT8188_AFE_IO_START,
 	MT8188_AFE_IO_DMIC_IN,
 	MT8188_AFE_IO_DPTX,
 	MT8188_AFE_IO_ETDM_START,
@@ -52,6 +52,7 @@  enum {
 	MT8188_AFE_IO_ETDM_NUM =
 		(MT8188_AFE_IO_ETDM_END - MT8188_AFE_IO_ETDM_START),
 	MT8188_AFE_IO_PCM = MT8188_AFE_IO_ETDM_END,
+	MT8188_AFE_IO_UL_SRC,
 	MT8188_AFE_IO_END,
 	MT8188_AFE_IO_NUM = (MT8188_AFE_IO_END - MT8188_AFE_IO_START),
 	MT8188_DAI_END = MT8188_AFE_IO_END,
diff --git a/sound/soc/mediatek/mt8188/mt8188-dai-adda.c b/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
index fed9f927e623..9a6673a6f28a 100644
--- a/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
+++ b/sound/soc/mediatek/mt8188/mt8188-dai-adda.c
@@ -53,8 +53,7 @@  enum {
 };
 
 struct mtk_dai_adda_priv {
-	unsigned int dl_rate;
-	unsigned int ul_rate;
+	bool hires_required;
 };
 
 static unsigned int afe_adda_dl_rate_transform(struct mtk_base_afe *afe,
@@ -241,42 +240,35 @@  static int mtk_adda_ul_event(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
-static int mtk_afe_adc_hires_connect(struct snd_soc_dapm_widget *source,
-				     struct snd_soc_dapm_widget *sink)
+static struct mtk_dai_adda_priv *get_adda_priv_by_name(struct mtk_base_afe *afe,
+						       const char *name)
 {
-	struct snd_soc_dapm_widget *w = source;
-	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
-	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
 	struct mt8188_afe_private *afe_priv = afe->platform_priv;
-	struct mtk_dai_adda_priv *adda_priv;
-
-	adda_priv = afe_priv->dai_priv[MT8188_AFE_IO_ADDA];
 
-	if (!adda_priv) {
-		dev_err(afe->dev, "%s adda_priv == NULL", __func__);
-		return 0;
-	}
-
-	return !!(adda_priv->ul_rate > ADDA_HIRES_THRES);
+	if (strstr(name, "aud_adc_hires"))
+		return afe_priv->dai_priv[MT8188_AFE_IO_UL_SRC];
+	else if (strstr(name, "aud_dac_hires"))
+		return afe_priv->dai_priv[MT8188_AFE_IO_DL_SRC];
+	else
+		return NULL;
 }
 
-static int mtk_afe_dac_hires_connect(struct snd_soc_dapm_widget *source,
-				     struct snd_soc_dapm_widget *sink)
+static int mtk_afe_adda_hires_connect(struct snd_soc_dapm_widget *source,
+				      struct snd_soc_dapm_widget *sink)
 {
 	struct snd_soc_dapm_widget *w = source;
 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
-	struct mt8188_afe_private *afe_priv = afe->platform_priv;
 	struct mtk_dai_adda_priv *adda_priv;
 
-	adda_priv = afe_priv->dai_priv[MT8188_AFE_IO_ADDA];
+	adda_priv = get_adda_priv_by_name(afe, w->name);
 
 	if (!adda_priv) {
-		dev_err(afe->dev, "%s adda_priv == NULL", __func__);
+		dev_dbg(afe->dev, "adda_priv == NULL");
 		return 0;
 	}
 
-	return !!(adda_priv->dl_rate > ADDA_HIRES_THRES);
+	return (adda_priv->hires_required) ? 1 : 0;
 }
 
 static const struct snd_kcontrol_new mtk_dai_adda_o176_mix[] = {
@@ -361,7 +353,7 @@  static const struct snd_soc_dapm_route mtk_dai_adda_routes[] = {
 	{"ADDA Capture", NULL, "ADDA Capture Enable"},
 	{"ADDA Capture", NULL, "ADDA_MTKAIF_CFG"},
 	{"ADDA Capture", NULL, "aud_adc"},
-	{"ADDA Capture", NULL, "aud_adc_hires", mtk_afe_adc_hires_connect},
+	{"ADDA Capture", NULL, "aud_adc_hires", mtk_afe_adda_hires_connect},
 
 	{"I168", NULL, "ADDA Capture"},
 	{"I169", NULL, "ADDA Capture"},
@@ -369,7 +361,7 @@  static const struct snd_soc_dapm_route mtk_dai_adda_routes[] = {
 	{"ADDA Playback", NULL, "ADDA Enable"},
 	{"ADDA Playback", NULL, "ADDA Playback Enable"},
 	{"ADDA Playback", NULL, "aud_dac"},
-	{"ADDA Playback", NULL, "aud_dac_hires", mtk_afe_dac_hires_connect},
+	{"ADDA Playback", NULL, "aud_dac_hires", mtk_afe_adda_hires_connect},
 
 	{"DL_GAIN", NULL, "O176"},
 	{"DL_GAIN", NULL, "O177"},
@@ -503,13 +495,15 @@  static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream,
 	dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %u\n",
 		__func__, id, substream->stream, rate);
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-		adda_priv->dl_rate = rate;
+	if (rate > ADDA_HIRES_THRES)
+		adda_priv->hires_required = 1;
+	else
+		adda_priv->hires_required = 0;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		ret = mtk_dai_da_configure(afe, rate, id);
-	} else {
-		adda_priv->ul_rate = rate;
+	else
 		ret = mtk_dai_ad_configure(afe, rate, id);
-	}
 
 	return ret;
 }
@@ -536,8 +530,8 @@  static const struct snd_soc_dai_ops mtk_dai_adda_ops = {
 
 static struct snd_soc_dai_driver mtk_dai_adda_driver[] = {
 	{
-		.name = "ADDA",
-		.id = MT8188_AFE_IO_ADDA,
+		.name = "DL_SRC",
+		.id = MT8188_AFE_IO_DL_SRC,
 		.playback = {
 			.stream_name = "ADDA Playback",
 			.channels_min = 1,
@@ -545,6 +539,11 @@  static struct snd_soc_dai_driver mtk_dai_adda_driver[] = {
 			.rates = MTK_ADDA_PLAYBACK_RATES,
 			.formats = MTK_ADDA_FORMATS,
 		},
+		.ops = &mtk_dai_adda_ops,
+	},
+	{
+		.name = "UL_SRC",
+		.id = MT8188_AFE_IO_UL_SRC,
 		.capture = {
 			.stream_name = "ADDA Capture",
 			.channels_min = 1,
@@ -560,13 +559,18 @@  static int init_adda_priv_data(struct mtk_base_afe *afe)
 {
 	struct mt8188_afe_private *afe_priv = afe->platform_priv;
 	struct mtk_dai_adda_priv *adda_priv;
+	int adda_dai_list[] = {MT8188_AFE_IO_DL_SRC, MT8188_AFE_IO_UL_SRC};
+	int i;
 
-	adda_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_dai_adda_priv),
-				 GFP_KERNEL);
-	if (!adda_priv)
-		return -ENOMEM;
+	for (i = 0; i < ARRAY_SIZE(adda_dai_list); i++) {
+		adda_priv = devm_kzalloc(afe->dev,
+					 sizeof(struct mtk_dai_adda_priv),
+					 GFP_KERNEL);
+		if (!adda_priv)
+			return -ENOMEM;
 
-	afe_priv->dai_priv[MT8188_AFE_IO_ADDA] = adda_priv;
+		afe_priv->dai_priv[adda_dai_list[i]] = adda_priv;
+	}
 
 	return 0;
 }
diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
index 919d74ea1934..833bc362dad2 100644
--- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c
+++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
@@ -99,8 +99,8 @@  SND_SOC_DAILINK_DEFS(capture10,
 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
 
 /* BE */
-SND_SOC_DAILINK_DEFS(adda,
-		     DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
+SND_SOC_DAILINK_DEFS(dl_src,
+		     DAILINK_COMP_ARRAY(COMP_CPU("DL_SRC")),
 		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
 						   "mt6359-snd-codec-aif1")),
 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
@@ -140,6 +140,12 @@  SND_SOC_DAILINK_DEFS(pcm1,
 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
 
+SND_SOC_DAILINK_DEFS(ul_src,
+		     DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC")),
+		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
+						   "mt6359-snd-codec-aif1")),
+		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
 struct mt8188_mt6359_priv {
 	struct snd_soc_jack dp_jack;
 	struct snd_soc_jack hdmi_jack;
@@ -345,7 +351,7 @@  enum {
 	DAI_LINK_UL8_FE,
 	DAI_LINK_UL9_FE,
 	DAI_LINK_UL10_FE,
-	DAI_LINK_ADDA_BE,
+	DAI_LINK_DL_SRC_BE,
 	DAI_LINK_DPTX_BE,
 	DAI_LINK_ETDM1_IN_BE,
 	DAI_LINK_ETDM2_IN_BE,
@@ -353,6 +359,7 @@  enum {
 	DAI_LINK_ETDM2_OUT_BE,
 	DAI_LINK_ETDM3_OUT_BE,
 	DAI_LINK_PCM1_BE,
+	DAI_LINK_UL_SRC_BE,
 };
 
 static int mt8188_dptx_hw_params(struct snd_pcm_substream *substream,
@@ -604,13 +611,11 @@  static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
 		SND_SOC_DAILINK_REG(capture10),
 	},
 	/* BE */
-	[DAI_LINK_ADDA_BE] = {
-		.name = "ADDA_BE",
+	[DAI_LINK_DL_SRC_BE] = {
+		.name = "DL_SRC_BE",
 		.no_pcm = 1,
 		.dpcm_playback = 1,
-		.dpcm_capture = 1,
-		.init = mt8188_mt6359_init,
-		SND_SOC_DAILINK_REG(adda),
+		SND_SOC_DAILINK_REG(dl_src),
 	},
 	[DAI_LINK_DPTX_BE] = {
 		.name = "DPTX_BE",
@@ -676,6 +681,12 @@  static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
 		.dpcm_capture = 1,
 		SND_SOC_DAILINK_REG(pcm1),
 	},
+	[DAI_LINK_UL_SRC_BE] = {
+		.name = "UL_SRC_BE",
+		.no_pcm = 1,
+		.dpcm_capture = 1,
+		SND_SOC_DAILINK_REG(ul_src),
+	},
 };
 
 static struct snd_soc_card mt8188_mt6359_soc_card = {
@@ -695,6 +706,7 @@  static int mt8188_mt6359_dev_probe(struct platform_device *pdev)
 	struct mt8188_mt6359_priv *priv;
 	struct mt8188_card_data *card_data;
 	struct snd_soc_dai_link *dai_link;
+	bool init_mt6359 = false;
 	int ret, i;
 
 	card_data = (struct mt8188_card_data *)of_device_get_match_data(&pdev->dev);
@@ -739,6 +751,12 @@  static int mt8188_mt6359_dev_probe(struct platform_device *pdev)
 		} else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
 			if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai"))
 				dai_link->init = mt8188_hdmi_codec_init;
+		} else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 ||
+			   strcmp(dai_link->name, "UL_SRC_BE") == 0) {
+			if (!init_mt6359) {
+				dai_link->init = mt8188_mt6359_init;
+				init_mt6359 = true;
+			}
 		}
 	}