devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Brugger <matthias.bgg@gmail.com>
To: Chaotian Jing <chaotian.jing@mediatek.com>,
	Ulf Hansson <ulf.hansson@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Ryder Lee <ryder.lee@mediatek.com>,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	Sean Wang <sean.wang@mediatek.com>,
	linux-mmc@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	srv_heupstream@mediatek.com, jjian.zhou@mediatek.com,
	wenbin.mei@mediatek.com
Subject: Re: [PATCH 4/6] mmc: mediatek: tune CMD/DATA together
Date: Fri, 19 Oct 2018 10:46:38 +0200	[thread overview]
Message-ID: <51d95ab5-896e-c386-7a3e-362e8a3c2960@gmail.com> (raw)
In-Reply-To: <1539415250-32337-5-git-send-email-chaotian.jing@mediatek.com>



On 13/10/2018 09:20, Chaotian Jing wrote:
> for MSDC IP which supports both data tune and async fifo, it can
> tune cmd/data together. which can save the time and make the tune
> result of CMD more stable as data line are 4bit or 8bit.
> 
> Signed-off-by: Chaotian Jing <chaotian.jing@mediatek.com>
> ---
>  drivers/mmc/host/mtk-sd.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 87 insertions(+)
> 
> diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
> index fe80a1d..09d7e44 100644
> --- a/drivers/mmc/host/mtk-sd.c
> +++ b/drivers/mmc/host/mtk-sd.c
> @@ -1773,12 +1773,98 @@ static int msdc_tune_data(struct mmc_host *mmc, u32 opcode)
>  	return final_delay == 0xff ? -EIO : 0;
>  }
>  
> +/*
> + * MSDC IP which supports data tune + async fifo can do CMD/DAT tune
> + * together, which can save the tuning time.
> + */
> +static int msdc_tune_together(struct mmc_host *mmc, u32 opcode)
> +{
> +	struct msdc_host *host = mmc_priv(mmc);
> +	u32 rise_delay = 0, fall_delay = 0;
> +	struct msdc_delay_phase final_rise_delay, final_fall_delay = { 0,};
> +	u8 final_delay, final_maxlen;
> +	u32 tune_reg = host->dev_comp->pad_tune_reg;
> +	int i, ret;
> +
> +	sdr_set_field(host->base + MSDC_PATCH_BIT, MSDC_INT_DAT_LATCH_CK_SEL,
> +		      host->latch_ck);
> +
> +	sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL);
> +	sdr_clr_bits(host->base + MSDC_IOCON,
> +		     MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL);
> +	for (i = 0 ; i < PAD_DELAY_MAX; i++) {
> +		sdr_set_field(host->base + tune_reg,
> +			      MSDC_PAD_TUNE_CMDRDLY, i);
> +		sdr_set_field(host->base + tune_reg,
> +			      MSDC_PAD_TUNE_DATRRDLY, i);
> +		ret = mmc_send_tuning(mmc, opcode, NULL);
> +		if (!ret)
> +			rise_delay |= (1 << i);
> +	}
> +	final_rise_delay = get_best_delay(host, rise_delay);
> +	/* if rising edge has enough margin, then do not scan falling edge */
> +	if (final_rise_delay.maxlen >= 12 ||
> +	    (final_rise_delay.start == 0 && final_rise_delay.maxlen >= 4))
> +		goto skip_fall;
> +
> +	sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL);
> +	sdr_set_bits(host->base + MSDC_IOCON,
> +		     MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL);
> +	for (i = 0; i < PAD_DELAY_MAX; i++) {
> +		sdr_set_field(host->base + tune_reg,
> +			      MSDC_PAD_TUNE_CMDRDLY, i);
> +		sdr_set_field(host->base + tune_reg,
> +			      MSDC_PAD_TUNE_DATRRDLY, i);
> +		ret = mmc_send_tuning(mmc, opcode, NULL);
> +		if (!ret)
> +			fall_delay |= (1 << i);
> +	}
> +	final_fall_delay = get_best_delay(host, fall_delay);
> +
> +skip_fall:
> +	final_maxlen = max(final_rise_delay.maxlen, final_fall_delay.maxlen);
> +	if (final_maxlen == final_rise_delay.maxlen) {
> +		sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL);
> +		sdr_clr_bits(host->base + MSDC_IOCON,
> +			     MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL);
> +		sdr_set_field(host->base + tune_reg, MSDC_PAD_TUNE_CMDRDLY,
> +			      final_rise_delay.final_phase);
> +		sdr_set_field(host->base + tune_reg,
> +			      MSDC_PAD_TUNE_DATRRDLY,
> +			      final_rise_delay.final_phase);
> +		final_delay = final_rise_delay.final_phase;
> +	} else {
> +		sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL);
> +		sdr_set_bits(host->base + MSDC_IOCON,
> +			     MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL);
> +		sdr_set_field(host->base + tune_reg, MSDC_PAD_TUNE_CMDRDLY,
> +			      final_fall_delay.final_phase);
> +		sdr_set_field(host->base + tune_reg,
> +			      MSDC_PAD_TUNE_DATRRDLY,
> +			      final_fall_delay.final_phase);
> +		final_delay = final_fall_delay.final_phase;
> +	}
> +
> +	dev_dbg(host->dev, "Final pad delay: %x\n", final_delay);
> +	return final_delay == 0xff ? -EIO : 0;
> +}
> +
>  static int msdc_execute_tuning(struct mmc_host *mmc, u32 opcode)
>  {
>  	struct msdc_host *host = mmc_priv(mmc);
>  	int ret;
>  	u32 tune_reg = host->dev_comp->pad_tune_reg;
>  
> +	if (host->dev_comp->data_tune && host->dev_comp->async_fifo) {
> +		ret = msdc_tune_together(mmc, opcode);
> +		if (host->hs400_mode) {
> +			sdr_clr_bits(host->base + MSDC_IOCON,
> +				     MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL);
> +			sdr_set_field(host->base + tune_reg,
> +				      MSDC_PAD_TUNE_DATRRDLY, 0);
> +		}
> +		goto tune_done;
> +	}
>  	if (host->hs400_mode &&

Couldn't we put a else if here instead of using a goto?

Regards,
Matthias

>  	    host->dev_comp->hs400_tune)
>  		ret = hs400_tune_response(mmc, opcode);
> @@ -1794,6 +1880,7 @@ static int msdc_execute_tuning(struct mmc_host *mmc, u32 opcode)
>  			dev_err(host->dev, "Tune data fail!\n");
>  	}
>  
> +tune_done:
>  	host->saved_tune_para.iocon = readl(host->base + MSDC_IOCON);
>  	host->saved_tune_para.pad_tune = readl(host->base + tune_reg);
>  	host->saved_tune_para.pad_cmd_tune = readl(host->base + PAD_CMD_TUNE);
> 

  reply	other threads:[~2018-10-19  8:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-13  7:20 mmc: mediatek: add MT8183 MMC driver support Chaotian Jing
2018-10-13  7:20 ` [PATCH 1/6] mmc: dt-bindings: add support for MT8183 SoC Chaotian Jing
2018-10-13  7:20 ` [PATCH 2/6] mmc: mediatek: fill the actual clock for mmc debugfs Chaotian Jing
2018-10-13  7:20 ` [PATCH 3/6] mmc: mediatek: fix cannot receive new request when msdc_cmd_is_ready fail Chaotian Jing
2018-10-13  7:20 ` [PATCH 4/6] mmc: mediatek: tune CMD/DATA together Chaotian Jing
2018-10-19  8:46   ` Matthias Brugger [this message]
2018-10-13  7:20 ` [PATCH 5/6] mmc: mediatek: add MT8183 MMC driver support Chaotian Jing
2018-10-19  9:04   ` Matthias Brugger
2018-10-13  7:20 ` [PATCH 6/6] mmc: mediatek: drop too much code of tuning method Chaotian Jing
2018-10-19  8:54   ` Matthias Brugger
2018-10-15 13:15 ` mmc: mediatek: add MT8183 MMC driver support Ulf Hansson

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=51d95ab5-896e-c386-7a3e-362e8a3c2960@gmail.com \
    --to=matthias.bgg@gmail.com \
    --cc=chaotian.jing@mediatek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jjian.zhou@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=ryder.lee@mediatek.com \
    --cc=sean.wang@mediatek.com \
    --cc=srv_heupstream@mediatek.com \
    --cc=ulf.hansson@linaro.org \
    --cc=wenbin.mei@mediatek.com \
    --cc=wsa+renesas@sang-engineering.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;
as well as URLs for NNTP newsgroup(s).