mmc: tmio: fix tuning for stubborn cards
Subsystems (2)
RFC 1/1 mmc: tmio: fix tuning for stubborn cards
The commit 43b0b361b0170030 ("mmc: tmio: always get number of taps") changed the behavior of the tuning. Before the commit the SCC was only enabled for the first tuning attempt (host->init_tuning(host)), if that failed the hardware where reset and tuning retried. In the second attempt the SCC where never configured and tuning would succeed for some stubborn cards. This patch restore this behavior which allows a troubled card I have to be used.
Without this patch:sh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) sh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) sh_mobile_sdhi ee100000.sd: Tuning procedure failed
mmc0: tuning execution failed: -110
mmc0: error -110 whilst initialising SD cardsh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) sh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) sh_mobile_sdhi ee100000.sd: Tuning procedure failed
mmc0: tuning execution failed: -110
mmc0: error -110 whilst initialising SD card
With this patch:sh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) sh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) sh_mobile_sdhi ee100000.sd: Tuning procedure with SCC enabled failed, retry with SCC disabled
mmc0: new ultra high speed SDR50 SDHC card at address aaaa
mmcblk0: mmc0:aaaa SU04G 3.69 GiB
mmcblk0: p1 p2
--- drivers/mmc/host/tmio_mmc_core.c | 50 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-)
Hi Wolfram,
I'm pretty sure this is not a proper fix for the underlying problem, but at least it restores the previous behavior and get the card working. I mostly post this RFC to share my findings and so we have some code to try and help us figure out what really is happening here.
// Niklas
drivers/mmc/host/tmio_mmc_core.c +33 -17
@@ -819,10 +819,35 @@ static void tmio_mmc_hw_reset(struct mmc_host *mmc) host->hw_reset (host); } +static int __tmio_mmc_execute_tuning (struct mmc_host *mmc,u32 opcode) +{ +struct tmio_mmc_host *host =mmc_priv (mmc); +unsigned int i; +int ret; + +bitmap_zero (host->taps, host->tap_num *2 ); + +/* Issue CMD19 twice for each tap */ +for (i =0 ; i <2 * host->tap_num; i++) { +if (host->prepare_tuning) + host->prepare_tuning (host, i % host->tap_num); + + ret =mmc_send_tuning (mmc, opcode,NULL ); +if (ret && ret != -EILSEQ ) +return ret; +if (ret ==0 ) +set_bit (i, host->taps); + +mdelay (1 ); + } + +return host->select_tuning (host); +} +static int tmio_mmc_execute_tuning (struct mmc_host *mmc,u32 opcode) {struct tmio_mmc_host *host =mmc_priv (mmc); -int i, ret =0 ; +int ret =0 ;if (!host->init_tuning || !host->select_tuning)/* Tuning is not supported */
@@ -839,24 +864,15 @@ static int tmio_mmc_execute_tuning(struct mmc_host *mmc, u32 opcode) goto out; } -bitmap_zero (host->taps, host->tap_num *2 ); - -/* Issue CMD19 twice for each tap */ -for (i =0 ; i <2 * host->tap_num; i++) { -if (host->prepare_tuning) - host->prepare_tuning (host, i % host->tap_num); - - ret =mmc_send_tuning (mmc, opcode,NULL ); -if (ret && ret != -EILSEQ ) - goto out; -if (ret ==0 ) -set_bit (i, host->taps); - -mdelay (1 ); + ret =__tmio_mmc_execute_tuning (mmc, opcode); +if (ret) { +/* Tuning failed with SCC enabled, reset hardware and retry */ +dev_info (&host->pdev->dev, +"Tuning procedure with SCC enabled failed, retry with SCC disabled\n" ); + host->hw_reset (host); + ret =__tmio_mmc_execute_tuning (mmc, opcode); } - ret = host->select_tuning (host); - out:if (ret <0 ) {dev_warn (&host->pdev->dev,"Tuning procedure failed\n" );
Signature · 1 line
2.14.2
Quoted 7 lines · Niklas Söderlund
The commit
43b0b361b0170030("mmc: tmio: always get number of taps") changed the behavior of the tuning. Before the commit the SCC was only enabled for the first tuning attempt (host->init_tuning(host)), if that failed the hardware where reset and tuning retried. In the second attempt the SCC where never configured and tuning would succeed for some stubborn cards. This patch restore this behavior which allows a troubled card I have to be used.
Hi Wolfram,
Is tuning retried if the card is changed, f.e. ejected and a different card inserted?
Quoted 10 lines · Simon Horman
Quoted 7 lines · Niklas Söderlund
The commit
43b0b361b0170030("mmc: tmio: always get number of taps") changed the behavior of the tuning. Before the commit the SCC was only enabled for the first tuning attempt (host->init_tuning(host)), if that failed the hardware where reset and tuning retried. In the second attempt the SCC where never configured and tuning would succeed for some stubborn cards. This patch restore this behavior which allows a troubled card I have to be used.Hi Wolfram,
Sorry, Hi Niklas!
Quoted 4 lines
Is tuning retried if the card is changed, f.e. ejected and a different card inserted?
Quoted 9 lines · Simon Horman
Quoted 7 lines · Niklas Söderlund
The commit
43b0b361b0170030("mmc: tmio: always get number of taps") changed the behavior of the tuning. Before the commit the SCC was only enabled for the first tuning attempt (host->init_tuning(host)), if that failed the hardware where reset and tuning retried. In the second attempt the SCC where never configured and tuning would succeed for some stubborn cards. This patch restore this behavior which allows a troubled card I have to be used.
Quoted 4 lines
Hi Wolfram,
Is tuning retried if the card is changed, f.e. ejected and a different card inserted?
I haven't tried this patch yet. I work on finalizing the I2C DMA helper patches currently. Let's hope this goes smooth, so I can check Niklas' findings soon.
Hi Simon,
Quoted 9 lines · Simon Horman
Quoted 7 lines · Niklas S�derlund
The commit
43b0b361b0170030("mmc: tmio: always get number of taps") changed the behavior of the tuning. Before the commit the SCC was only enabled for the first tuning attempt (host->init_tuning(host)), if that failed the hardware where reset and tuning retried. In the second attempt the SCC where never configured and tuning would succeed for some stubborn cards. This patch restore this behavior which allows a troubled card I have to be used.
Quoted 4 lines
Hi Wolfram,
Is tuning retried if the card is changed, f.e. ejected and a different card inserted?
I'd say tuning is retried every time a card is inserted, based on my tests bellow. Which would make the change in 43b0b361b0170030 correct as the number of taps should be reread each time but the fallback to try tuning without the SCC clock changed restored (if that is correct behavior?). The register write which breaks my stubborn card tuning is in renesas_sdhi_init_tuning() in drivers/mmc/host/renesas_sdhi_core.c:
# I assume this write is just to unlock writing to # SH_MOBILE_SDHI_SCC_CKSEL ?
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
# This register change starts to produce the timeout for CMD19 with # my stubborn card. In renesas_sdhi_hw_reset() this register is # reset and tuning then works.
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL,
SH_MOBILE_SDHI_SCC_CKSEL_DTSEL | sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL));
# I as above assume this just locks the register write again ? sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
Test procedure as follows:
1. Insert stubborn card
[ 29.048761] sh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) [ 34.168757] sh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) [ 34.228767] sh_mobile_sdhi ee100000.sd: Tuning procedure with SCC enabled failed, retry with SCC disabled [ 34.255636] mmc0: new ultra high speed SDR50 SDHC card at address aaaa [ 34.262440] mmcblk0: mmc0:aaaa SU04G 3.69 GiB [ 34.274980] mmcblk0: p1 p2
2. Eject stubborn card
[ 115.858994] mmc0: card aaaa removed
3. Insert other card
[ 137.195795] mmc0: new SD card at address 9749 [ 137.200434] mmcblk0: mmc0:9749 SD128 120 MiB (ro) [ 137.208510] mmcblk0: p1
4. Eject other card
[ 142.499073] mmc0: card 9749 removed
5. Insert stubborn card
[ 176.248760] sh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) [ 181.368756] sh_mobile_sdhi ee100000.sd: timeout waiting for hardware interrupt (CMD19) [ 181.428768] sh_mobile_sdhi ee100000.sd: Tuning procedure with SCC enabled failed, retry with SCC disabled [ 181.455631] mmc0: new ultra high speed SDR50 SDHC card at address aaaa [ 181.462424] mmcblk0: mmc0:aaaa SU04G 3.69 GiB [ 181.474949] mmcblk0: p1 p2
Signature · 2 lines
Regards, Niklas S�derlund
Simon Horman
Reviewed-byQuoted 14 lines · Niklas Söderlund
Hi Simon,
Quoted 11 lines · Simon Horman
Quoted 7 lines · Niklas Söderlund
The commit
43b0b361b0170030("mmc: tmio: always get number of taps") changed the behavior of the tuning. Before the commit the SCC was only enabled for the first tuning attempt (host->init_tuning(host)), if that failed the hardware where reset and tuning retried. In the second attempt the SCC where never configured and tuning would succeed for some stubborn cards. This patch restore this behavior which allows a troubled card I have to be used.Hi Wolfram,
Quoted 8 lines
Quoted 2 lines
Is tuning retried if the card is changed, f.e. ejected and a different card inserted?
I'd say tuning is retried every time a card is inserted, based on my tests bellow. Which would make the change in
43b0b361b0170030correct as the number of taps should be reread each time but the fallback to try tuning without the SCC clock changed restored (if that is correct behavior?).
Presumably rereading the number of taps each time is the correct behaviour
- though my initial assumption was otherwise when I added the code to mainline.
I think that in theory there is a chance that tuning could fail at some time and succeed later - f.e. if the board warms up. But in I also think your solution makes a lot of sense in practice.
Quoted 15 lines
The register write which breaks my stubborn card tuning is in
renesas_sdhi_init_tuning()indrivers/mmc/host/renesas_sdhi_core.c:# I assume this write is just to unlock writing to #
SH_MOBILE_SDHI_SCC_CKSEL?
sd_ctrl_write16(host,CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));# This register change starts to produce the timeout for CMD19 with # my stubborn card. In
renesas_sdhi_hw_reset()this register is # reset and tuning then works.
sd_scc_write32(host, priv,SH_MOBILE_SDHI_SCC_CKSEL,
SH_MOBILE_SDHI_SCC_CKSEL_DTSEL|sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL));
Quoted 4 lines
# I as above assume this just locks the register write again ? sd_ctrl_write16(host,
CTL_SD_CARD_CLK_CTL,CLK_CTL_SCLKEN|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
Looking at the above I am reminded of a patch I recently came across in the BSP when looking at enabling HS400.
Quoted 1 line
From
313b1462fb380d8c414853e98ab99e42b73668e5Mon Sep 17 00:00:00 2001
From: Masaharu Hayakawa <[email protected]>
Date: Thu, 26 Jan 2017 18:21:12 +0900
Subject: [PATCH] mmc: sh_mobile_sdhi: Fix HS400 mode tuning
The order of register setting was changed according to the tuning flow. Tuning result of 8TAP replace on the position of the 4TAP. Added function sh_mobile_sdhi_reset_hs400_mode() to return to HS200 mode for retuning.
drivers/mmc/host/sh_mobile_sdhi.c +41 -14
@@ -348,33 +348,30 @@ static unsigned int sh_mobile_sdhi_init_tuning(struct tmio_mmc_host *host) priv =host_to_priv (host); -/* set sampling clock selection range */ -sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_DTCNTL , -0x8 <<SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT ); -/* Initialize SCC */ sd_ctrl_write32_as_16_and_16 (host,CTL_STATUS ,0x0 ); -sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_DTCNTL , -SH_MOBILE_SDHI_SCC_DTCNTL_TAPEN | -sd_scc_read32 (host, priv,SH_MOBILE_SDHI_SCC_DTCNTL )); -sd_ctrl_write16 (host,CTL_SD_CARD_CLK_CTL , ~CLK_CTL_SCLKEN &sd_ctrl_read16 (host,CTL_SD_CARD_CLK_CTL )); +/* set sampling clock selection range */ +sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_DTCNTL , +SH_MOBILE_SDHI_SCC_DTCNTL_TAPEN | +0x8 <<SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT ); +sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_CKSEL ,SH_MOBILE_SDHI_SCC_CKSEL_DTSEL |sd_scc_read32 (host, priv,SH_MOBILE_SDHI_SCC_CKSEL )); -sd_ctrl_write16 (host,CTL_SD_CARD_CLK_CTL ,CLK_CTL_SCLKEN | -sd_ctrl_read16 (host,CTL_SD_CARD_CLK_CTL )); -sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_RVSCNTL , ~SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &sd_scc_read32 (host, priv,SH_MOBILE_SDHI_SCC_RVSCNTL ));sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_DT2FF , host->scc_tappos); +sd_ctrl_write16 (host,CTL_SD_CARD_CLK_CTL ,CLK_CTL_SCLKEN | +sd_ctrl_read16 (host,CTL_SD_CARD_CLK_CTL )); +/* Read TAPNUM */ return (sd_scc_read32 (host, priv,SH_MOBILE_SDHI_SCC_DTCNTL ) >> SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) &
@@ -415,17 +412,46 @@ static void sh_mobile_sdhi_prepare_hs400_tuning(struct mmc_host *mmc, SH_MOBILE_SDHI_SCC_TMPPORT2_HS400OSEL) | sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT2)); +sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_TAPSET , host->tap_set/2 ); +sd_ctrl_write16 (host,CTL_SD_CARD_CLK_CTL ,CLK_CTL_SCLKEN |sd_ctrl_read16 (host,CTL_SD_CARD_CLK_CTL )); } +static void sh_mobile_sdhi_reset_hs400_mode (struct mmc_host *mmc) +{ +struct tmio_mmc_host *host =mmc_priv (mmc); +struct sh_mobile_sdhi *priv =host_to_priv (host); + +if (!(host->mmc->caps2 &MMC_CAP2_HS200_1_8V_SDR ) && + !(host->mmc->caps2 & (MMC_CAP2_HS400_1_8V | +MMC_CAP2_HS200_1_8V_SDR ))) +return ; + +if (!priv->scc_ctl) +return ; + +sd_ctrl_write16 (host,CTL_SD_CARD_CLK_CTL , ~CLK_CTL_SCLKEN & +sd_ctrl_read16 (host,CTL_SD_CARD_CLK_CTL )); + +/* Reset HS400 mode */ +sd_ctrl_write16 (host,CTL_SDIF_MODE , ~0x0001 & +sd_ctrl_read16 (host,CTL_SDIF_MODE )); +sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_TMPPORT2 , + ~(SH_MOBILE_SDHI_SCC_TMPPORT2_HS400EN | +SH_MOBILE_SDHI_SCC_TMPPORT2_HS400OSEL ) & +sd_scc_read32 (host, priv,SH_MOBILE_SDHI_SCC_TMPPORT2 )); + +sd_ctrl_write16 (host,CTL_SD_CARD_CLK_CTL ,CLK_CTL_SCLKEN | +sd_ctrl_read16 (host,CTL_SD_CARD_CLK_CTL )); +} +#define SH_MOBILE_SDHI_MAX_TAP 3static int sh_mobile_sdhi_select_tuning (struct tmio_mmc_host *host) {struct sh_mobile_sdhi *priv =host_to_priv (host);unsigned long tap_cnt;/* counter of tuning success */ -unsigned long tap_set;/* tap position */ unsigned long tap_start;/* start position of tuning success */ unsigned long tap_end;/* end position of tuning success */ unsigned long ntap;/* temporary counter of tuning success */
@@ -510,12 +536,12 @@ static int sh_mobile_sdhi_select_tuning(struct tmio_mmc_host *host) select = true;if (select) - tap_set = (tap_start + tap_end) /2 % host->tap_num; + host->tap_set = (tap_start + tap_end) /2 % host->tap_num;else return -EIO ;/* Set SCC */ -sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_TAPSET , tap_set); +sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_TAPSET , host->tap_set);/* Enable auto re-tuning */ sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
@@ -732,6 +758,7 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev) host->hw_reset = sh_mobile_sdhi_hw_reset; host->prepare_hs400_tuning = sh_mobile_sdhi_prepare_hs400_tuning; + host->reset_hs400_mode = sh_mobile_sdhi_reset_hs400_mode; }/* Orginally registers were 16 bit apart, could be 32 or 64 nowadays */
Signature · 1 line
2.11.0