All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhoujie Wu <zjwu@marvell.com>
To: Adrian Hunter <adrian.hunter@intel.com>,
	Shawn Lin <shawn.lin@rock-chips.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>,
	"linux-mmc@vger.kernel.org" <linux-mmc@vger.kernel.org>
Subject: Re: [EXT] [PATCH RFC] mmc: sd: Fix signal voltage when there is no power cycle
Date: Thu, 21 Sep 2017 14:52:53 -0700	[thread overview]
Message-ID: <59C434B5.5090707@marvell.com> (raw)
In-Reply-To: <a367a679-28f7-898a-c043-27df8c9c9aba@intel.com>

Hi Adrian,
This patch can solve uhs card can only be recognized as hs card on 
armada3700 board after warm reset or suspend/resume sequence(both have 
no power cycle for sd card).
It looks good for me and tested on armada3700 board with following cards:
Two sandisk 8G uhs card DDR50
Apacer 8G uhs card DDR50
Can it be an official patch? Thanks for your help.

Tested-by: Zhoujie Wu <zjwu@marvell.com>

On 09/21/2017 12:44 AM, Adrian Hunter wrote:
> External Email
>
> ----------------------------------------------------------------------
> If the card has not been power cycled, it may still be using 1.8V
> signaling. According to the SD spec., the Bus Speed Mode (function group 1)
> bits 2 to 4 are zero if the card is initialized at 3.3V signal level. Thus
> they can be used to determine if the card has already switched to 1.8V
> signaling. Detect that situation and try to initialize a UHS-I (1.8V)
> transfer mode.
>
> Tested with the following cards:
>    Transcend 4GB High Speed
>    Kingston 64GB SDR104
>    Lexar by Micron HIGH-PERFORMANCE 300x 16GB DDR50
>    SanDisk Ultra 8GB DDR50
>    Transcend Ultimate 600x 16GB SDR104
>    Transcend Premium 300x 64GB SDR104
>    Lexar by Micron Professional 1000x 32GB UHS-II SDR104
>    SanDisk Extreme Pro 16GB SDR104
>
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>
>
> Here is an alternative approach to Shawn's that uses CMD6 to identify the
> card's signal voltage.
>
> It has the advantages that it does not depend on knowing about the regulator,
> and it works even when unbinding / re-binding the host controller.
>
>
>   drivers/mmc/core/core.c | 38 ++++++++++++++++++++++++--------------
>   drivers/mmc/core/core.h |  1 +
>   drivers/mmc/core/sd.c   | 47 +++++++++++++++++++++++++++++++++++++++++++++--
>   3 files changed, 70 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 24a73f387482..161c1d105d91 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -1723,11 +1723,33 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage)
>   
>   }
>   
> +int mmc_host_set_uhs_voltage(struct mmc_host *host)
> +{
> +	u32 clock;
> +
> +	/*
> +	 * During a signal voltage level switch, the clock must be gated
> +	 * for 5 ms according to the SD spec
> +	 */
> +	clock = host->ios.clock;
> +	host->ios.clock = 0;
> +	mmc_set_ios(host);
> +
> +	if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180))
> +		return -EAGAIN;
> +
> +	/* Keep clock gated for at least 10 ms, though spec only says 5 ms */
> +	mmc_delay(10);
> +	host->ios.clock = clock;
> +	mmc_set_ios(host);
> +
> +	return 0;
> +}
> +
>   int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr)
>   {
>   	struct mmc_command cmd = {};
>   	int err = 0;
> -	u32 clock;
>   
>   	/*
>   	 * If we cannot switch voltages, return failure so the caller
> @@ -1759,15 +1781,8 @@ int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr)
>   		err = -EAGAIN;
>   		goto power_cycle;
>   	}
> -	/*
> -	 * During a signal voltage level switch, the clock must be gated
> -	 * for 5 ms according to the SD spec
> -	 */
> -	clock = host->ios.clock;
> -	host->ios.clock = 0;
> -	mmc_set_ios(host);
>   
> -	if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) {
> +	if (mmc_host_set_uhs_voltage(host)) {
>   		/*
>   		 * Voltages may not have been switched, but we've already
>   		 * sent CMD11, so a power cycle is required anyway
> @@ -1776,11 +1791,6 @@ int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr)
>   		goto power_cycle;
>   	}
>   
> -	/* Keep clock gated for at least 10 ms, though spec only says 5 ms */
> -	mmc_delay(10);
> -	host->ios.clock = clock;
> -	mmc_set_ios(host);
> -
>   	/* Wait for at least 1 ms according to spec */
>   	mmc_delay(1);
>   
> diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
> index 03e0f8384b1c..2b2690d0d877 100644
> --- a/drivers/mmc/core/core.h
> +++ b/drivers/mmc/core/core.h
> @@ -51,6 +51,7 @@ struct device_node *mmc_of_find_child_device(struct mmc_host *host,
>   void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
>   u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
>   int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr);
> +int mmc_host_set_uhs_voltage(struct mmc_host *host);
>   int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
>   void mmc_set_timing(struct mmc_host *host, unsigned int timing);
>   void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
> diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
> index 4fd1620b732d..35e1f52cb3f9 100644
> --- a/drivers/mmc/core/sd.c
> +++ b/drivers/mmc/core/sd.c
> @@ -908,6 +908,18 @@ unsigned mmc_sd_get_max_clock(struct mmc_card *card)
>   	return max_dtr;
>   }
>   
> +static bool mmc_sd_card_using_v18(struct mmc_card *card)
> +{
> +	/*
> +	 * According to the SD spec., the Bus Speed Mode (function group 1) bits
> +	 * 2 to 4 are zero if the card is initialized at 3.3V signal level. Thus
> +	 * they can be used to determine if the card has already switched to
> +	 * 1.8V signaling.
> +	 */
> +	return card->sw_caps.sd3_bus_mode &
> +	       (SD_MODE_UHS_SDR50 | SD_MODE_UHS_SDR104 | SD_MODE_UHS_DDR50);
> +}
> +
>   /*
>    * Handle the detection and initialisation of a card.
>    *
> @@ -921,9 +933,10 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
>   	int err;
>   	u32 cid[4];
>   	u32 rocr = 0;
> +	bool v18_fixup_failed = false;
>   
>   	WARN_ON(!host->claimed);
> -
> +retry:
>   	err = mmc_sd_get_cid(host, ocr, cid, &rocr);
>   	if (err)
>   		return err;
> @@ -989,6 +1002,36 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
>   	if (err)
>   		goto free_card;
>   
> +	/*
> +	 * If the card has not been power cycled, it may still be using 1.8V
> +	 * signaling. Detect that situation and try to initialize a UHS-I (1.8V)
> +	 * transfer mode.
> +	 */
> +	if (!v18_fixup_failed && !mmc_host_is_spi(host) && mmc_host_uhs(host) &&
> +	    mmc_sd_card_using_v18(card) &&
> +	    host->ios.signal_voltage != MMC_SIGNAL_VOLTAGE_180) {
> +		/*
> +		 * Re-read switch information in case it has changed since
> +		 * oldcard was initialized.
> +		 */
> +		if (oldcard) {
> +			err = mmc_read_switch(card);
> +			if (err)
> +				goto free_card;
> +		}
> +		if (mmc_sd_card_using_v18(card)) {
> +			if (mmc_host_set_uhs_voltage(host) ||
> +			    mmc_sd_init_uhs_card(card)) {
> +				v18_fixup_failed = true;
> +				mmc_power_cycle(host, ocr);
> +				if (!oldcard)
> +					mmc_remove_card(card);
> +				goto retry;
> +			}
> +			goto done;
> +		}
> +	}
> +
>   	/* Initialization sequence for UHS-I cards */
>   	if (rocr & SD_ROCR_S18A) {
>   		err = mmc_sd_init_uhs_card(card);
> @@ -1021,7 +1064,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
>   			mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
>   		}
>   	}
> -
> +done:
>   	host->card = card;
>   	return 0;
>   


  reply	other threads:[~2017-09-21 21:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29  3:53 [RFT v2 PATCH] mmc: sd: try to enable UHS mode w/o power cycle from S3 Shawn Lin
     [not found] ` <CAAXpJNvfSWHrJiLHoxmm+ENUDsGayQROnRTL=SoHr-7dX7R9+Q@mail.gmail.com>
2017-08-29 22:13   ` [EXT] " Zhoujie Wu
2017-08-30  0:14     ` Shawn Lin
2017-08-30 22:32       ` Zhoujie Wu
2017-09-01 22:57       ` Zhoujie Wu
2017-09-04  1:06         ` Shawn Lin
2017-09-21  7:44           ` [PATCH RFC] mmc: sd: Fix signal voltage when there is no power cycle Adrian Hunter
2017-09-21 21:52             ` Zhoujie Wu [this message]
2017-09-22  0:39             ` Shawn Lin
2017-09-22 10:00             ` 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=59C434B5.5090707@marvell.com \
    --to=zjwu@marvell.com \
    --cc=adrian.hunter@intel.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=shawn.lin@rock-chips.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.