linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Sowjanya Komatineni <skomatineni@nvidia.com>
Cc: robh+dt@kernel.org, mark.rutland@arm.com, mperttunen@nvidia.com,
	jonathanh@nvidia.com, adrian.hunter@intel.com,
	ulf.hansson@linaro.org, devicetree@vger.kernel.org,
	linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mmc@vger.kernel.org
Subject: Re: [PATCH V3 3/3] mmc: tegra: SDMMC pads auto-calibration
Date: Thu, 10 Jan 2019 16:06:02 +0100	[thread overview]
Message-ID: <20190110150602.GC25353@ulmo> (raw)
In-Reply-To: <1546462674-22856-3-git-send-email-skomatineni@nvidia.com>

[-- Attachment #1: Type: text/plain, Size: 9045 bytes --]

On Wed, Jan 02, 2019 at 12:57:54PM -0800, Sowjanya Komatineni wrote:
> Programs initial drive code offsets which will be used by auto
> calibration process.
> 
> Programs fixed drive strengths for SDMMC pads when auto cal
> timeouts. Fixed settings are based on Pre-SI analysis of the
> pad design.
> 
> Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
> ---
>  drivers/mmc/host/sdhci-tegra.c | 107 +++++++++++++++++++++++++++++++----------
>  1 file changed, 81 insertions(+), 26 deletions(-)

Hi Sowjanya,

this looks really good. Some minor comments below.

> diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
> index 7b95d088fdef..f8361249cf57 100644
> --- a/drivers/mmc/host/sdhci-tegra.c
> +++ b/drivers/mmc/host/sdhci-tegra.c
> @@ -75,6 +75,7 @@
>  #define SDHCI_TEGRA_SDMEM_COMP_PADCTRL_VREF_SEL_MASK	0x0000000f
>  #define SDHCI_TEGRA_SDMEM_COMP_PADCTRL_VREF_SEL_VAL	0x7
>  #define SDHCI_TEGRA_SDMEM_COMP_PADCTRL_E_INPUT_E_PWRD	BIT(31)
> +#define SDHCI_COMP_PADCTRL_DRVUPDN_OFFSET_MASK		0x07FFF000
>  
>  #define SDHCI_TEGRA_AUTO_CAL_STATUS			0x1ec
>  #define SDHCI_TEGRA_AUTO_CAL_ACTIVE			BIT(31)
> @@ -121,6 +122,8 @@ struct sdhci_tegra {
>  	struct pinctrl *pinctrl_sdmmc;
>  	struct pinctrl_state *pinctrl_state_3v3;
>  	struct pinctrl_state *pinctrl_state_1v8;
> +	struct pinctrl_state *pinctrl_state_3v3_drv;
> +	struct pinctrl_state *pinctrl_state_1v8_drv;
>  
>  	struct sdhci_tegra_autocal_offsets autocal_offsets;
>  	ktime_t last_calib;
> @@ -130,6 +133,9 @@ struct sdhci_tegra {
>  	u32 dqs_trim;
>  };
>  
> +static int tegra_sdhci_set_padctrl(struct sdhci_host *host, int voltage,
> +							bool state_drvupdn);
> +

You're rewriting most of that function anyway, so might as well move it
up here. The diff should be about the same in terms of readability, so
you don't need the forward declaration.

>  static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
>  {
>  	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> @@ -437,6 +443,7 @@ static void tegra_sdhci_pad_autocalib(struct sdhci_host *host)
>  			pdpu = offsets.pull_down_3v3 << 8 | offsets.pull_up_3v3;
>  	}
>  
> +	/* Set initial offset before auto-calibration */
>  	tegra_sdhci_set_pad_autocal_offset(host, pdpu);
>  
>  	card_clk_enabled = tegra_sdhci_configure_card_clk(host, false);
> @@ -460,19 +467,15 @@ static void tegra_sdhci_pad_autocalib(struct sdhci_host *host)
>  	if (ret) {
>  		dev_err(mmc_dev(host->mmc), "Pad autocal timed out\n");
>  
> -		if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180)
> -			pdpu = offsets.pull_down_1v8_timeout << 8 |
> -			       offsets.pull_up_1v8_timeout;
> -		else
> -			pdpu = offsets.pull_down_3v3_timeout << 8 |
> -			       offsets.pull_up_3v3_timeout;
> -
> -		/* Disable automatic calibration and use fixed offsets */
> +		/* Disable automatic cal and use fixed Drive Strengths */
>  		reg = sdhci_readl(host, SDHCI_TEGRA_AUTO_CAL_CONFIG);
>  		reg &= ~SDHCI_AUTO_CAL_ENABLE;
>  		sdhci_writel(host, reg, SDHCI_TEGRA_AUTO_CAL_CONFIG);
>  
> -		tegra_sdhci_set_pad_autocal_offset(host, pdpu);
> +		ret = tegra_sdhci_set_padctrl(host, ios->signal_voltage, false);
> +		if (ret < 0)
> +			dev_err(mmc_dev(host->mmc),
> +			"Setting drive strengths failed %d\n", PTR_ERR(ret));

It's customary to align the first argument on subsequent lines with the
first argument on the first line. Also, I find it more readable to have
a ':' separating the error code:

			dev_err(mmc_dev(host->mmc),
				"Setting drive strengths failed: %d\n", ret);

Also note how you don't need to cast the ret value because it is already
an integer.

>  	}
>  }
>  
> @@ -743,27 +746,73 @@ static int tegra_sdhci_execute_tuning(struct sdhci_host *host, u32 opcode)
>  	return mmc_send_tuning(host->mmc, opcode, NULL);
>  }
>  
> -static int tegra_sdhci_set_padctrl(struct sdhci_host *host, int voltage)
> +static int tegra_sdhci_set_padctrl(struct sdhci_host *host, int voltage,
> +							bool state_drvupdn)

Same as above, make sure the bool state_drvupdn argument aligns with
struct sdhc_host *host.

>  {
>  	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
>  	struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
> -	int ret;
> +	struct sdhci_tegra_autocal_offsets offsets =
> +					tegra_host->autocal_offsets;

Perhaps make this a pointer to avoid copying the whole structure? You
could even make it const if you want to be very explicit that you're
only referencing the autocalibration offsets.

> +	struct pinctrl_state *pinctrl_drvupdn = NULL;
> +	int ret = 0;
> +	u8 drvup = 0, drvdn = 0;
> +	u32 reg;
>  
> -	if (!tegra_host->pad_control_available)
> -		return 0;
> +	if (!state_drvupdn) {
> +		/* PADS Drive Strength */
> +		if (voltage == MMC_SIGNAL_VOLTAGE_180) {
> +			if (!IS_ERR(tegra_host->pinctrl_state_1v8_drv) &&
> +				(tegra_host->pinctrl_state_1v8_drv != NULL)) {

Perhaps:

	IS_ERR_OR_NULL(tegra_host->pinctrl_state_1v8_drv)?

but then, do we actually need this? It looks like pinctrl_lookup_state()
will always return either an ERR_PTR() encoded error code or a valid
pointer. Under what circumstances would pinctrl_state_1v8_drv be NULL?

> +				pinctrl_drvupdn =
> +					tegra_host->pinctrl_state_1v8_drv;
> +			} else {
> +				drvup = offsets.pull_up_1v8_timeout;
> +				drvdn = offsets.pull_down_1v8_timeout;
> +			}
> +		} else {
> +			if (!IS_ERR(tegra_host->pinctrl_state_3v3_drv) &&
> +				(tegra_host->pinctrl_state_3v3_drv != NULL)) {
> +				pinctrl_drvupdn =
> +					tegra_host->pinctrl_state_3v3_drv;
> +			} else {
> +				drvup = offsets.pull_up_3v3_timeout;
> +				drvdn = offsets.pull_down_3v3_timeout;
> +			}
> +		}
> +
> +		if (pinctrl_drvupdn != NULL) {
> +			ret = pinctrl_select_state(tegra_host->pinctrl_sdmmc,
> +							pinctrl_drvupdn);
> +			if (ret < 0)
> +				dev_err(mmc_dev(host->mmc),
> +					"failed pads drvupdn, ret: %d\n", ret);
> +		} else if ((drvup) || (drvdn)) {
> +			reg = sdhci_readl(host,
> +					SDHCI_TEGRA_SDMEM_COMP_PADCTRL);
> +			reg &= ~SDHCI_COMP_PADCTRL_DRVUPDN_OFFSET_MASK;
> +			reg |= (drvup << 20) | (drvdn << 12);
> +			sdhci_writel(host, reg,
> +					SDHCI_TEGRA_SDMEM_COMP_PADCTRL);
> +		}
>  
> -	if (voltage == MMC_SIGNAL_VOLTAGE_180) {
> -		ret = pinctrl_select_state(tegra_host->pinctrl_sdmmc,
> -					   tegra_host->pinctrl_state_1v8);
> -		if (ret < 0)
> -			dev_err(mmc_dev(host->mmc),
> -				"setting 1.8V failed, ret: %d\n", ret);
>  	} else {
> -		ret = pinctrl_select_state(tegra_host->pinctrl_sdmmc,
> -					   tegra_host->pinctrl_state_3v3);
> -		if (ret < 0)
> -			dev_err(mmc_dev(host->mmc),
> -				"setting 3.3V failed, ret: %d\n", ret);
> +		/* Dual Voltage PADS Voltage selection */
> +		if (!tegra_host->pad_control_available)
> +			return 0;
> +
> +		if (voltage == MMC_SIGNAL_VOLTAGE_180) {
> +			ret = pinctrl_select_state(tegra_host->pinctrl_sdmmc,
> +						tegra_host->pinctrl_state_1v8);
> +			if (ret < 0)
> +				dev_err(mmc_dev(host->mmc),
> +					"setting 1.8V failed, ret: %d\n", ret);
> +		} else {
> +			ret = pinctrl_select_state(tegra_host->pinctrl_sdmmc,
> +						tegra_host->pinctrl_state_3v3);
> +			if (ret < 0)
> +				dev_err(mmc_dev(host->mmc),
> +					"setting 3.3V failed, ret: %d\n", ret);
> +		}
>  	}
>  
>  	return ret;
> @@ -778,7 +827,7 @@ static int sdhci_tegra_start_signal_voltage_switch(struct mmc_host *mmc,
>  	int ret = 0;
>  
>  	if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) {
> -		ret = tegra_sdhci_set_padctrl(host, ios->signal_voltage);
> +		ret = tegra_sdhci_set_padctrl(host, ios->signal_voltage, true);
>  		if (ret < 0)
>  			return ret;
>  		ret = sdhci_start_signal_voltage_switch(mmc, ios);
> @@ -786,7 +835,7 @@ static int sdhci_tegra_start_signal_voltage_switch(struct mmc_host *mmc,
>  		ret = sdhci_start_signal_voltage_switch(mmc, ios);
>  		if (ret < 0)
>  			return ret;
> -		ret = tegra_sdhci_set_padctrl(host, ios->signal_voltage);
> +		ret = tegra_sdhci_set_padctrl(host, ios->signal_voltage, true);
>  	}
>  
>  	if (tegra_host->pad_calib_required)
> @@ -805,6 +854,12 @@ static int tegra_sdhci_init_pinctrl_info(struct device *dev,
>  		return -1;
>  	}
>  
> +	tegra_host->pinctrl_state_1v8_drv = pinctrl_lookup_state(
> +				tegra_host->pinctrl_sdmmc, "sdmmc-1v8-drv");
> +
> +	tegra_host->pinctrl_state_3v3_drv = pinctrl_lookup_state(
> +				tegra_host->pinctrl_sdmmc, "sdmmc-3v3-drv");

If this truly is optional, then I suggest we do something like this
instead:

	tegra_host->pinctrl_state_1v8_drv = pinctrl_lookup_state(...);
	if (IS_ERR(tegra_host->pinctrl_state_1v8_drv)) {
		err = PTR_ERR(tegra_host->pinctrl_state_1v8_drv);

		if (err == -ENODEV)
			tegra_host->pinctrl_state_1v8_drv = NULL;
		else
			return err;
	}

With that we can use the much simpler condition everywhere:

	if (tegra_host->pinctrl_state_1v8_drv)
		...

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-01-10 15:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-02 20:57 [PATCH V3 1/3] dt-bindings: mmc: tegra: Add pinctrl for pad drive strength config Sowjanya Komatineni
2019-01-02 20:57 ` [PATCH V3 2/3] arm64: dts: tegra: Add SDMMC Auto-cal settings Sowjanya Komatineni
2019-01-02 20:57 ` [PATCH V3 3/3] mmc: tegra: SDMMC pads auto-calibration Sowjanya Komatineni
2019-01-10 15:06   ` Thierry Reding [this message]
2019-01-10 19:19     ` Sowjanya Komatineni
2019-01-10 14:48 ` [PATCH V3 1/3] dt-bindings: mmc: tegra: Add pinctrl for pad drive strength config Thierry Reding
2019-01-11 16:11 ` Rob Herring

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=20190110150602.GC25353@ulmo \
    --to=thierry.reding@gmail.com \
    --cc=adrian.hunter@intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mperttunen@nvidia.com \
    --cc=robh+dt@kernel.org \
    --cc=skomatineni@nvidia.com \
    --cc=ulf.hansson@linaro.org \
    /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).