public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: Trevor Wu <trevor.wu@mediatek.com>,
	broonie@kernel.org, lgirdwood@gmail.com, tiwai@suse.com,
	perex@perex.cz, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, matthias.bgg@gmail.com
Cc: alsa-devel@alsa-project.org, linux-mediatek@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 3/7] ASoC: mediatek: mt8188: revise ETDM control flow
Date: Thu, 13 Apr 2023 15:17:41 +0200	[thread overview]
Message-ID: <e36598dd-4f83-90b4-1744-61d18744b02d@collabora.com> (raw)
In-Reply-To: <20230413104713.7174-4-trevor.wu@mediatek.com>

Il 13/04/23 12:47, Trevor Wu ha scritto:
> Replace register controls in snd_soc_dai_ops with snd_soc_dapm_widgets.
> startup, shutdown and trigger ops are removed, and create DAPM_SUPPLY
> to handle mclk, clock gating and etdm enabling. Additionally, mclk setup
> sequence is also updated because of new supply enabling sequence.
> 
> Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
> ---
>   sound/soc/mediatek/mt8188/mt8188-dai-etdm.c | 790 ++++++++++----------
>   sound/soc/mediatek/mt8188/mt8188-reg.h      |   2 +
>   2 files changed, 406 insertions(+), 386 deletions(-)
> 
> diff --git a/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c b/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c
> index fddecf5bf7c6..c276687630ee 100644
> --- a/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c
> +++ b/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c
> @@ -21,6 +21,13 @@
>   #define ETDM_TO_DAI_ID(x) ((x) + MT8188_AFE_IO_ETDM_START)
>   #define ENUM_TO_STR(x)	#x
>   
> +enum {
> +	SUPPLY_SEQ_ETDM_MCLK,
> +	SUPPLY_SEQ_ETDM_CG,
> +	SUPPLY_SEQ_DPTX_EN,
> +	SUPPLY_SEQ_ETDM_EN,
> +};
> +
>   enum {
>   	MTK_DAI_ETDM_FORMAT_I2S = 0,
>   	MTK_DAI_ETDM_FORMAT_LJ,
> @@ -84,7 +91,6 @@ struct mtk_dai_etdm_rate {
>   };
>   
>   struct mtk_dai_etdm_priv {
> -	unsigned int clock_mode;
>   	unsigned int data_mode;
>   	bool slave_mode;
>   	bool lrck_inv;
> @@ -100,8 +106,6 @@ struct mtk_dai_etdm_priv {
>   	unsigned int cowork_slv_count;
>   	int cowork_slv_id[MT8188_AFE_IO_ETDM_NUM - 1]; //dai_id
>   	bool in_disable_ch[MT8188_ETDM_MAX_CHANNELS];
> -	unsigned int en_ref_cnt;
> -	bool is_prepared;
>   };
>   
>   static const struct mtk_dai_etdm_rate mt8188_etdm_rates[] = {
> @@ -345,14 +349,82 @@ static int mtk_dai_etdm_get_clkdiv_id_by_dai_id(int dai_id)
>   	}
>   }
>   
> +static int get_etdm_id_by_name(struct mtk_base_afe *afe,
> +			       const char *name)
> +{
> +	if (!strncmp(name, "ETDM1_IN", strlen("ETDM1_IN")))
> +		return MT8188_AFE_IO_ETDM1_IN;
> +	else if (!strncmp(name, "ETDM2_IN", strlen("ETDM2_IN")))
> +		return MT8188_AFE_IO_ETDM2_IN;
> +	else if (!strncmp(name, "ETDM1_OUT", strlen("ETDM1_OUT")))
> +		return MT8188_AFE_IO_ETDM1_OUT;
> +	else if (!strncmp(name, "ETDM2_OUT", strlen("ETDM2_OUT")))
> +		return MT8188_AFE_IO_ETDM2_OUT;
> +	else
> +		return -EINVAL;
> +}
> +
> +static struct mtk_dai_etdm_priv *get_etdm_priv_by_name(struct mtk_base_afe *afe,
> +						       const char *name)
> +{
> +	struct mt8188_afe_private *afe_priv = afe->platform_priv;
> +	int dai_id = get_etdm_id_by_name(afe, name);
> +
> +	if (dai_id < MT8188_AFE_IO_ETDM_START ||
> +	    dai_id >= MT8188_AFE_IO_ETDM_END)
> +		return NULL;
> +
> +	return afe_priv->dai_priv[dai_id];
> +}
> +
>   static int mtk_dai_etdm_enable_mclk(struct mtk_base_afe *afe, int dai_id)
>   {
>   	struct mt8188_afe_private *afe_priv = afe->platform_priv;
> +	struct mtk_dai_etdm_priv *etdm_data;
> +	struct etdm_con_reg etdm_reg;
> +	unsigned int val = 0;
> +	unsigned int mask;
> +	int clkmux_id = mtk_dai_etdm_get_clk_id_by_dai_id(dai_id);
>   	int clkdiv_id = mtk_dai_etdm_get_clkdiv_id_by_dai_id(dai_id);
> +	int apll_clk_id;
> +	int apll;
> +	int ret;
> +
> +	if (!is_valid_etdm_dai(dai_id))
> +		return -EINVAL;
> +	etdm_data = afe_priv->dai_priv[dai_id];
>   
> -	if (clkdiv_id < 0)
> +	apll = etdm_data->mclk_apll;
> +	apll_clk_id = mt8188_afe_get_mclk_source_clk_id(apll);
> +
> +	if (clkmux_id < 0 || clkdiv_id < 0)
>   		return -EINVAL;
>   
> +	if (apll_clk_id < 0)
> +		return apll_clk_id;
> +
> +	ret = get_etdm_reg(dai_id, &etdm_reg);
> +	if (ret < 0)
> +		return ret;
> +
> +	mask = ETDM_CON1_MCLK_OUTPUT;
> +	if (etdm_data->mclk_dir == SND_SOC_CLOCK_OUT)
> +		val = ETDM_CON1_MCLK_OUTPUT;
> +	regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val);
> +
> +	/* enable parent clock before select apll*/
> +	mt8188_afe_enable_clk(afe, afe_priv->clk[clkmux_id]);
> +
> +	/* select apll */
> +	ret = mt8188_afe_set_clk_parent(afe, afe_priv->clk[clkmux_id],
> +					afe_priv->clk[apll_clk_id]);
> +	if (ret)
> +		return ret;
> +
> +	/* set rate */
> +	ret = mt8188_afe_set_clk_rate(afe, afe_priv->clk[clkdiv_id],
> +				      etdm_data->mclk_freq);
> +
>   	mt8188_afe_enable_clk(afe, afe_priv->clk[clkdiv_id]);
>   
>   	return 0;
> @@ -361,12 +433,207 @@ static int mtk_dai_etdm_enable_mclk(struct mtk_base_afe *afe, int dai_id)
>   static int mtk_dai_etdm_disable_mclk(struct mtk_base_afe *afe, int dai_id)
>   {
>   	struct mt8188_afe_private *afe_priv = afe->platform_priv;
> +	int clkmux_id = mtk_dai_etdm_get_clk_id_by_dai_id(dai_id);
>   	int clkdiv_id = mtk_dai_etdm_get_clkdiv_id_by_dai_id(dai_id);
>   
> -	if (clkdiv_id < 0)
> +	if (clkmux_id < 0 || clkdiv_id < 0)
>   		return -EINVAL;
>   
>   	mt8188_afe_disable_clk(afe, afe_priv->clk[clkdiv_id]);
> +	mt8188_afe_disable_clk(afe, afe_priv->clk[clkmux_id]);
> +
> +	return 0;
> +}
> +
> +static int mtk_etdm_mclk_connect(struct snd_soc_dapm_widget *source,
> +				 struct snd_soc_dapm_widget *sink)
> +{
> +	struct snd_soc_dapm_widget *w = sink;
> +	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_etdm_priv *etdm_priv;
> +	int mclk_id;
> +
> +	mclk_id = get_etdm_id_by_name(afe, source->name);
> +	if (mclk_id < 0) {
> +		dev_info(afe->dev, "mclk_id < 0");

Since you're returning 0, this doesn't appear to be an error and this print is
useless unless it is used for debugging purposes.

Please change it to dev_dbg().

> +		return 0;
> +	}
> +
> +	etdm_priv = get_etdm_priv_by_name(afe, w->name);
> +	if (!etdm_priv) {
> +		dev_info(afe->dev, "etdm_priv == NULL");

dev_dbg()

> +		return 0;
> +	}
> +
> +	if (get_etdm_id_by_name(afe, sink->name) == mclk_id)
> +		return !!(etdm_priv->mclk_freq > 0);
> +
> +	if (etdm_priv->cowork_source_id == mclk_id) {
> +		etdm_priv = afe_priv->dai_priv[mclk_id];
> +		return !!(etdm_priv->mclk_freq > 0);
> +	}
> +
> +	return 0;
> +}
> +
> +static int mtk_etdm_cowork_connect(struct snd_soc_dapm_widget *source,
> +				   struct snd_soc_dapm_widget *sink)
> +{
> +	struct snd_soc_dapm_widget *w = sink;
> +	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_etdm_priv *etdm_priv;
> +	int source_id;
> +	int i;
> +
> +	source_id = get_etdm_id_by_name(afe, source->name);
> +	if (source_id < 0) {
> +		dev_info(afe->dev, "%s() source_id < 0\n", __func__);

dev_dbg() please

> +		return 0;
> +	}
> +
> +	etdm_priv = get_etdm_priv_by_name(afe, w->name);
> +	if (!etdm_priv) {
> +		dev_info(afe->dev, "%s() etdm_priv == NULL\n", __func__);

...again... and everywhere else.

> +		return 0;
> +	}
> +

Regards,
Angelo



  reply	other threads:[~2023-04-13 13:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 10:47 [PATCH 0/7] ASoC: mediatek: mt8188: revise AFE driver Trevor Wu
2023-04-13 10:47 ` [PATCH 1/7] ASoC: mediatek: mt8188: remove supply AUDIO_HIRES Trevor Wu
2023-04-13 13:17   ` AngeloGioacchino Del Regno
2023-04-13 10:47 ` [PATCH 2/7] ASoC: mediatek: mt8188: complete set_tdm_slot function Trevor Wu
2023-04-13 10:47 ` [PATCH 3/7] ASoC: mediatek: mt8188: revise ETDM control flow Trevor Wu
2023-04-13 13:17   ` AngeloGioacchino Del Regno [this message]
2023-04-17  2:52     ` Trevor Wu (吳文良)
2023-04-13 10:47 ` [PATCH 4/7] ASoC: mediatek: mt8188: refine APLL control Trevor Wu
2023-04-13 10:47 ` [PATCH 5/7] ASoC: mediatek: mt8188: combine afe component registration Trevor Wu
2023-04-13 10:47 ` [PATCH 6/7] ASoC: mediatek: mt8188: add bus protection Trevor Wu
2023-04-13 13:19   ` AngeloGioacchino Del Regno
2023-04-20  6:44     ` Trevor Wu (吳文良)
2023-04-13 10:47 ` [PATCH 7/7] ASoC: dt-bindings: mediatek,mt8188-afe: add audio properties Trevor Wu
2023-04-15  9:00   ` Krzysztof Kozlowski
2023-04-17  2:44     ` Trevor Wu (吳文良)
2023-04-17  7:55       ` AngeloGioacchino Del Regno
2023-04-18 10:23         ` Trevor Wu (吳文良)
2023-04-18 12:25           ` Krzysztof Kozlowski
2023-04-20  6:25             ` 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=e36598dd-4f83-90b4-1744-61d18744b02d@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.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=robh+dt@kernel.org \
    --cc=tiwai@suse.com \
    --cc=trevor.wu@mediatek.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