fix the sdio device DATA/CMD CRC and Timeout issue after tuning
Subsystems (4)
[email protected]
maintainerv3 cover fix the sdio device DATA/CMD CRC and Timeout issue after tuning
From: Haibo Chen <[email protected]>
V3:
- involve init_card() callback instead of change the common code.
V2:
- drop the dts/dt-binding change, since this is one IC limitation, so handle this directlly in driver.
- simply the auto tuning code logic.
- To detect the SDIO device in host driver side, add some change
in common code, move host->card = card a bit upper.
Haibo Chen (2):
mmc: sdhci-esdhc-imx: simplify the auto tuning logic
mmc: sdhci-esdhc-imx: only enable DAT[0] and CMD line auto tuning for
SDIO device
drivers/mmc/host/sdhci-esdhc-imx.c | 66 ++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
[email protected]
maintainerPATCH v3 1/2 mmc: sdhci-esdhc-imx: simplify the auto tuning logic
From: Haibo Chen <[email protected]>
Clear auto tuning bit when reset tuning, and enable auto tuning only after tuning done successfully for both standard tuning and manual tuning.
--- drivers/mmc/host/sdhci-esdhc-imx.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
drivers/mmc/host/sdhci-esdhc-imx.c +16 -9
@@ -429,9 +429,10 @@ static inline void esdhc_wait_for_card_clock_gate_off(struct sdhci_host *host) }/* Enable the auto tuning circuit to check the CMD line and BUS line */ -static inline void usdhc_auto_tuning_mode_sel (struct sdhci_host *host) +static inline void usdhc_auto_tuning_mode_sel_and_en (struct sdhci_host *host) {u32 buswidth, auto_tune_buswidth; +u32 reg; buswidth =USDHC_GET_BUSWIDTH (readl (host->ioaddr +SDHCI_HOST_CONTROL ));
@@ -450,6 +451,10 @@ static inline void usdhc_auto_tuning_mode_sel(struct sdhci_host *host)esdhc_clrset_le (host,ESDHC_VEND_SPEC2_AUTO_TUNE_MODE_MASK , auto_tune_buswidth |ESDHC_VEND_SPEC2_AUTO_TUNE_CMD_EN ,ESDHC_VEND_SPEC2 ); + + reg =readl (host->ioaddr +ESDHC_MIX_CTRL ); + reg |=ESDHC_MIX_CTRL_AUTO_TUNE_EN ; +writel (reg, host->ioaddr +ESDHC_MIX_CTRL ); }static u32 esdhc_readl_le (struct sdhci_host *host,int reg)
@@ -681,14 +686,11 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg) }else { v &= ~ESDHC_MIX_CTRL_SMPCLK_SEL ; m &= ~ESDHC_MIX_CTRL_FBCLK_SEL ; - m &= ~ESDHC_MIX_CTRL_AUTO_TUNE_EN ; }if (val &SDHCI_CTRL_EXEC_TUNING ) { v |=ESDHC_MIX_CTRL_EXE_TUNE ; m |=ESDHC_MIX_CTRL_FBCLK_SEL ; - m |=ESDHC_MIX_CTRL_AUTO_TUNE_EN ; -usdhc_auto_tuning_mode_sel (host); }else { v &= ~ESDHC_MIX_CTRL_EXE_TUNE ; }
@@ -1022,13 +1024,15 @@ static void esdhc_reset_tuning(struct sdhci_host *host)/* Reset the tuning circuit */ if (esdhc_is_usdhc (imx_data)) { + ctrl =readl (host->ioaddr +ESDHC_MIX_CTRL ); + ctrl &= ~ESDHC_MIX_CTRL_AUTO_TUNE_EN ;if (imx_data->socdata->flags &ESDHC_FLAG_MAN_TUNING ) { - ctrl =readl (host->ioaddr +ESDHC_MIX_CTRL ); ctrl &= ~ESDHC_MIX_CTRL_SMPCLK_SEL ; ctrl &= ~ESDHC_MIX_CTRL_FBCLK_SEL ;writel (ctrl, host->ioaddr +ESDHC_MIX_CTRL );writel (0 , host->ioaddr +ESDHC_TUNE_CTRL_STATUS ); }else if (imx_data->socdata->flags &ESDHC_FLAG_STD_TUNING ) { +writel (ctrl, host->ioaddr +ESDHC_MIX_CTRL ); ctrl =readl (host->ioaddr +SDHCI_AUTO_CMD_STATUS ); ctrl &= ~ESDHC_MIX_CTRL_SMPCLK_SEL ; ctrl &= ~ESDHC_MIX_CTRL_EXE_TUNE ;
@@ -1054,6 +1058,7 @@ static void esdhc_reset_tuning(struct sdhci_host *host)static int usdhc_execute_tuning (struct mmc_host *mmc,u32 opcode) {struct sdhci_host *host =mmc_priv (mmc); +int err;/* * i.MX uSDHC internally already uses a fixed optimized timing for
@@ -1068,7 +1073,12 @@ static int usdhc_execute_tuning(struct mmc_host *mmc, u32 opcode)* correct delay cell. */ esdhc_reset_tuning (host); -return sdhci_execute_tuning (mmc, opcode); + err =sdhci_execute_tuning (mmc, opcode); +/* If tuning done, enable auto tuning */ +if (!err && !host->tuning_err) +usdhc_auto_tuning_mode_sel_and_en (host); + +return err; }static void esdhc_prepare_tuning (struct sdhci_host *host,u32 val)
@@ -1102,11 +1112,8 @@ static void esdhc_post_tuning(struct sdhci_host *host) {u32 reg; -usdhc_auto_tuning_mode_sel (host); - reg =readl (host->ioaddr +ESDHC_MIX_CTRL ); reg &= ~ESDHC_MIX_CTRL_EXE_TUNE ; - reg |=ESDHC_MIX_CTRL_AUTO_TUNE_EN ;writel (reg, host->ioaddr +ESDHC_MIX_CTRL ); }
Signature · 1 line
2.34.1
Re: [PATCH v3 1/2] mmc: sdhci-esdhc-imx: simplify the auto tuning logic
Quoted 7 lines · On 23/12/22 04:50, [email protected] wrote:
From: Haibo Chen <[email protected]>
Clear auto tuning bit when reset tuning, and enable auto tuning only after tuning done successfully for both standard tuning and manual tuning.
Signed-off-by Haibo Chen <[email protected]>
Quoted 97 lines
--- drivers/mmc/host/sdhci-esdhc-imx.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)drivers/mmc/host/sdhci-esdhc-imx.c +16
-9@@ -429,9 +429,10 @@ static inline void esdhc_wait_for_card_clock_gate_off(struct sdhci_host *host) }/* Enable the auto tuning circuit to check the CMD line and BUS line */ -static inline void usdhc_auto_tuning_mode_sel (struct sdhci_host *host) +static inline void usdhc_auto_tuning_mode_sel_and_en (struct sdhci_host *host) {u32 buswidth, auto_tune_buswidth; +u32 reg; buswidth =USDHC_GET_BUSWIDTH (readl (host->ioaddr +SDHCI_HOST_CONTROL ));@@ -450,6 +451,10 @@ static inline void usdhc_auto_tuning_mode_sel(struct sdhci_host *host)esdhc_clrset_le (host,ESDHC_VEND_SPEC2_AUTO_TUNE_MODE_MASK , auto_tune_buswidth |ESDHC_VEND_SPEC2_AUTO_TUNE_CMD_EN ,ESDHC_VEND_SPEC2 ); + + reg =readl (host->ioaddr +ESDHC_MIX_CTRL ); + reg |=ESDHC_MIX_CTRL_AUTO_TUNE_EN ; +writel (reg, host->ioaddr +ESDHC_MIX_CTRL ); }static u32 esdhc_readl_le (struct sdhci_host *host,int reg)@@ -681,14 +686,11 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg) }else { v &= ~ESDHC_MIX_CTRL_SMPCLK_SEL ; m &= ~ESDHC_MIX_CTRL_FBCLK_SEL ; - m &= ~ESDHC_MIX_CTRL_AUTO_TUNE_EN ; }if (val &SDHCI_CTRL_EXEC_TUNING ) { v |=ESDHC_MIX_CTRL_EXE_TUNE ; m |=ESDHC_MIX_CTRL_FBCLK_SEL ; - m |=ESDHC_MIX_CTRL_AUTO_TUNE_EN ; -usdhc_auto_tuning_mode_sel (host); }else { v &= ~ESDHC_MIX_CTRL_EXE_TUNE ; }@@ -1022,13 +1024,15 @@ static void esdhc_reset_tuning(struct sdhci_host *host)/* Reset the tuning circuit */ if (esdhc_is_usdhc (imx_data)) { + ctrl =readl (host->ioaddr +ESDHC_MIX_CTRL ); + ctrl &= ~ESDHC_MIX_CTRL_AUTO_TUNE_EN ;if (imx_data->socdata->flags &ESDHC_FLAG_MAN_TUNING ) { - ctrl =readl (host->ioaddr +ESDHC_MIX_CTRL ); ctrl &= ~ESDHC_MIX_CTRL_SMPCLK_SEL ; ctrl &= ~ESDHC_MIX_CTRL_FBCLK_SEL ;writel (ctrl, host->ioaddr +ESDHC_MIX_CTRL );writel (0 , host->ioaddr +ESDHC_TUNE_CTRL_STATUS ); }else if (imx_data->socdata->flags &ESDHC_FLAG_STD_TUNING ) { +writel (ctrl, host->ioaddr +ESDHC_MIX_CTRL ); ctrl =readl (host->ioaddr +SDHCI_AUTO_CMD_STATUS ); ctrl &= ~ESDHC_MIX_CTRL_SMPCLK_SEL ; ctrl &= ~ESDHC_MIX_CTRL_EXE_TUNE ;@@ -1054,6 +1058,7 @@ static void esdhc_reset_tuning(struct sdhci_host *host)static int usdhc_execute_tuning (struct mmc_host *mmc,u32 opcode) {struct sdhci_host *host =mmc_priv (mmc); +int err;/* * i.MX uSDHC internally already uses a fixed optimized timing for @@ -1068,7 +1073,12 @@ static int usdhc_execute_tuning(struct mmc_host *mmc, u32 opcode)* correct delay cell. */ esdhc_reset_tuning (host); -return sdhci_execute_tuning (mmc, opcode); + err =sdhci_execute_tuning (mmc, opcode); +/* If tuning done, enable auto tuning */ +if (!err && !host->tuning_err) +usdhc_auto_tuning_mode_sel_and_en (host); + +return err; }static void esdhc_prepare_tuning (struct sdhci_host *host,u32 val)@@ -1102,11 +1112,8 @@ static void esdhc_post_tuning(struct sdhci_host *host) {u32 reg; -usdhc_auto_tuning_mode_sel (host); - reg =readl (host->ioaddr +ESDHC_MIX_CTRL ); reg &= ~ESDHC_MIX_CTRL_EXE_TUNE ; - reg |=ESDHC_MIX_CTRL_AUTO_TUNE_EN ;writel (reg, host->ioaddr +ESDHC_MIX_CTRL ); }
[email protected]
maintainerPATCH v3 2/2 mmc: sdhci-esdhc-imx: only enable DAT[0] and CMD line auto tuning for SDIO device
In reply to [email protected]From: Haibo Chen <[email protected]>
USDHC IP has one limitation: the tuning circuit can't handle the async sdio device interrupt correctly. When sdio device use 4 data lines, async sdio interrupt will use the shared DAT[1], if enable auto tuning circuit to check these 4 data lines, include the DAT[1], this circuit will detect this interrupt, take this as data on DAT[1], and adjust the delay cell wrongly, finally will cause the DATA/CMD CRC error. So for SDIO device, only enable DAT[0] and CMD line for auto tuning. To distinguish the card type during card init, involve init_card().
--- drivers/mmc/host/sdhci-esdhc-imx.c | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/mmc/host/sdhci-esdhc-imx.c +41 -0
@@ -337,6 +337,16 @@ struct pltfm_imx_data {struct clk *clk_ahb;struct clk *clk_per;unsigned int actual_clock; + +/* +* USDHC has one limition, require the SDIO device a different +* register setting. Driver has to recognize card type during +* the card init, but at this stage, mmc_host->card is not +* available. So involve this field to save the card type +* during card init through usdhc_init_card(). +*/ +unsigned int init_card_type; +enum {NO_CMD_PENDING ,/* no multiblock command pending */ MULTIBLK_IN_PROCESS ,/* exact multiblock cmd in process */
@@ -431,6 +441,8 @@ static inline void esdhc_wait_for_card_clock_gate_off(struct sdhci_host *host)/* Enable the auto tuning circuit to check the CMD line and BUS line */ static inline void usdhc_auto_tuning_mode_sel_and_en (struct sdhci_host *host) { +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct pltfm_imx_data *imx_data =sdhci_pltfm_priv (pltfm_host);u32 buswidth, auto_tune_buswidth;u32 reg;
@@ -448,6 +460,20 @@ static inline void usdhc_auto_tuning_mode_sel_and_en(struct sdhci_host *host)break ; } +/* +* For USDHC, auto tuning circuit can not handle the async sdio +* device interrupt correctly. When sdio device use 4 data lines, +* async sdio interrupt will use the shared DAT[1], if enable auto +* tuning circuit check these 4 data lines, include the DAT[1], +* this circuit will detect this interrupt, take this as a data on +* DAT[1], and adjust the delay cell wrongly. +* This is the hardware design limitation, to avoid this, for sdio +* device, config the auto tuning circuit only check DAT[0] and CMD +* line. +*/ +if (imx_data->init_card_type ==MMC_TYPE_SDIO ) + auto_tune_buswidth =ESDHC_VEND_SPEC2_AUTO_TUNE_1BIT_EN ; +esdhc_clrset_le (host,ESDHC_VEND_SPEC2_AUTO_TUNE_MODE_MASK , auto_tune_buswidth |ESDHC_VEND_SPEC2_AUTO_TUNE_CMD_EN ,ESDHC_VEND_SPEC2 );
@@ -1055,6 +1081,15 @@ static void esdhc_reset_tuning(struct sdhci_host *host) } } +static void usdhc_init_card (struct mmc_host *mmc,struct mmc_card *card) +{ +struct sdhci_host *host =mmc_priv (mmc); +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct pltfm_imx_data *imx_data =sdhci_pltfm_priv (pltfm_host); + + imx_data->init_card_type = card->type; +} +static int usdhc_execute_tuning (struct mmc_host *mmc,u32 opcode) {struct sdhci_host *host =mmc_priv (mmc);
@@ -1673,6 +1708,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)* to replace the standard one in sdhci_ops. */ host->mmc_host_ops.execute_tuning = usdhc_execute_tuning; + +/* +* Link usdhc specific mmc_host_ops init card function, +* to distinguish the card type. +*/ + host->mmc_host_ops.init_card = usdhc_init_card; } err =sdhci_esdhc_imx_probe_dt (pdev, host, imx_data);
Signature · 1 line
2.34.1
Re: [PATCH v3 2/2] mmc: sdhci-esdhc-imx: only enable DAT[0] and CMD line auto tuning for SDIO device
Quoted 11 lines · On 23/12/22 04:50, [email protected] wrote:
From: Haibo Chen <[email protected]>
USDHC IP has one limitation: the tuning circuit can't handle the async sdio device interrupt correctly. When sdio device use 4 data lines, async sdio interrupt will use the shared DAT[1], if enable auto tuning circuit to check these 4 data lines, include the DAT[1], this circuit will detect this interrupt, take this as data on DAT[1], and adjust the delay cell wrongly, finally will cause the DATA/CMD CRC error. So for SDIO device, only enable DAT[0] and CMD line for auto tuning. To distinguish the card type during card init, involve
init_card().
Quoted 1 line
Signed-off-by Haibo Chen <[email protected]>
Quoted 84 lines
--- drivers/mmc/host/sdhci-esdhc-imx.c | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)drivers/mmc/host/sdhci-esdhc-imx.c +41
-0@@ -337,6 +337,16 @@ struct pltfm_imx_data {struct clk *clk_ahb;struct clk *clk_per;unsigned int actual_clock; + +/* +* USDHC has one limition, require the SDIO device a different +* register setting. Driver has to recognize card type during +* the card init, but at this stage, mmc_host->card is not +* available. So involve this field to save the card type +* during card init through usdhc_init_card(). +*/ +unsigned int init_card_type; +enum {NO_CMD_PENDING ,/* no multiblock command pending */ MULTIBLK_IN_PROCESS ,/* exact multiblock cmd in process */ @@ -431,6 +441,8 @@ static inline void esdhc_wait_for_card_clock_gate_off(struct sdhci_host *host)/* Enable the auto tuning circuit to check the CMD line and BUS line */ static inline void usdhc_auto_tuning_mode_sel_and_en (struct sdhci_host *host) { +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct pltfm_imx_data *imx_data =sdhci_pltfm_priv (pltfm_host);u32 buswidth, auto_tune_buswidth;u32 reg;@@ -448,6 +460,20 @@ static inline void usdhc_auto_tuning_mode_sel_and_en(struct sdhci_host *host)break ; } +/* +* For USDHC, auto tuning circuit can not handle the async sdio +* device interrupt correctly. When sdio device use 4 data lines, +* async sdio interrupt will use the shared DAT[1], if enable auto +* tuning circuit check these 4 data lines, include the DAT[1], +* this circuit will detect this interrupt, take this as a data on +* DAT[1], and adjust the delay cell wrongly. +* This is the hardware design limitation, to avoid this, for sdio +* device, config the auto tuning circuit only check DAT[0] and CMD +* line. +*/ +if (imx_data->init_card_type ==MMC_TYPE_SDIO ) + auto_tune_buswidth =ESDHC_VEND_SPEC2_AUTO_TUNE_1BIT_EN ; +esdhc_clrset_le (host,ESDHC_VEND_SPEC2_AUTO_TUNE_MODE_MASK , auto_tune_buswidth |ESDHC_VEND_SPEC2_AUTO_TUNE_CMD_EN ,ESDHC_VEND_SPEC2 );@@ -1055,6 +1081,15 @@ static void esdhc_reset_tuning(struct sdhci_host *host) } } +static void usdhc_init_card (struct mmc_host *mmc,struct mmc_card *card) +{ +struct sdhci_host *host =mmc_priv (mmc); +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct pltfm_imx_data *imx_data =sdhci_pltfm_priv (pltfm_host); + + imx_data->init_card_type = card->type; +} +static int usdhc_execute_tuning (struct mmc_host *mmc,u32 opcode) {struct sdhci_host *host =mmc_priv (mmc);@@ -1673,6 +1708,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)* to replace the standard one in sdhci_ops. */ host->mmc_host_ops.execute_tuning = usdhc_execute_tuning; + +/* +* Link usdhc specific mmc_host_ops init card function, +* to distinguish the card type. +*/ + host->mmc_host_ops.init_card = usdhc_init_card; } err =sdhci_esdhc_imx_probe_dt (pdev, host, imx_data);
Quoted 13 lines · On Fri, 23 Dec 2022 at 03:50, <[email protected]> wrote:
From: Haibo Chen <[email protected]>
V3:
- involveinit_card()callback instead of change the common code.V2:
- drop the dts/dt-binding change, since this is one IC limitation, so handle this directlly in driver.
- simply the auto tuning code logic.
- To detect the SDIO device in host driver side, add some changein common code, move host->card = card a bit upper.
Quoted 8 lines
Haibo Chen (2):
mmc: sdhci-esdhc-imx: simplify the auto tuning logic
mmc: sdhci-esdhc-imx: only enable DAT[0] and CMD line auto tuning for
SDIO devicedrivers/mmc/host/sdhci-esdhc-imx.c | 66 ++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 9 deletions(-)
Applied for next, thanks!
Kind regards
Uffe