mmc: sunxi: mask DATA0 during H6-family clock updates
Subsystems (2)
PATCH 1/1 mmc: sunxi: mask DATA0 during H6-family clock updates
Linux marks the H6/A100-style controllers with mask_data0 and sets the CLKCR MASK_DATA0 bit while issuing update-clock commands. Without this, the controller can sample DAT0 as busy around clock updates before the first card command, so card detection may fail with -ETIMEDOUT.
Mirror the Linux behavior for H6-family and NCAT2-family controllers while updating the card clock.
--- drivers/mmc/sunxi_mmc.c | 30 +++++++++++++++++++++++++++--- drivers/mmc/sunxi_mmc.h | 1 + 2 files changed, 28 insertions(+), 3 deletions(-)
drivers/mmc/sunxi_mmc.c +27 -3
@@ -64,6 +64,12 @@ static bool sunxi_mmc_can_calibrate(void)IS_ENABLED (CONFIG_MACH_SUN8I_R40 ); } +static bool sunxi_mmc_needs_data0_mask (void ) +{ +return IS_ENABLED (CONFIG_SUN50I_GEN_H6 ) || +IS_ENABLED (CONFIG_SUNXI_GEN_NCAT2 ); +} +static int mmc_set_mod_clk (struct sunxi_mmc_priv *priv,unsigned int hz) {unsigned int pll, pll_hz, div, n, oclk_dly, sclk_dly;
@@ -201,14 +207,31 @@ static int mmc_update_clk(struct sunxi_mmc_priv *priv)return 0 ; } +static int mmc_update_clk_with_data0_mask (struct sunxi_mmc_priv *priv) +{ +bool mask_data0 =sunxi_mmc_needs_data0_mask (); +int ret; + +if (mask_data0) +setbits_le32 (&priv->reg->clkcr,SUNXI_MMC_CLK_MASK_DATA0 ); + + ret =mmc_update_clk (priv); + +if (mask_data0) +clrbits_le32 (&priv->reg->clkcr,SUNXI_MMC_CLK_MASK_DATA0 ); + +return ret; +} +static int mmc_config_clock (struct sunxi_mmc_priv *priv,struct mmc *mmc) {unsigned rval =readl (&priv->reg->clkcr);/* Disable Clock */ - rval &= ~SUNXI_MMC_CLK_ENABLE ; + rval &= ~(SUNXI_MMC_CLK_ENABLE |SUNXI_MMC_CLK_POWERSAVE | +SUNXI_MMC_CLK_MASK_DATA0 );writel (rval, &priv->reg->clkcr); -if (mmc_update_clk (priv)) +if (mmc_update_clk_with_data0_mask (priv))return -1 ;/* Set mod_clk to new rate */
@@ -231,9 +254,10 @@ static int mmc_config_clock(struct sunxi_mmc_priv *priv, struct mmc *mmc)#endif /* Re-enable Clock */ + rval &= ~(SUNXI_MMC_CLK_POWERSAVE |SUNXI_MMC_CLK_MASK_DATA0 ); rval |=SUNXI_MMC_CLK_ENABLE ;writel (rval, &priv->reg->clkcr); -if (mmc_update_clk (priv)) +if (mmc_update_clk_with_data0_mask (priv))return -1 ;return 0 ;
drivers/mmc/sunxi_mmc.h +1 -0
@@ -58,6 +58,7 @@ struct sunxi_mmc {#define SUNXI_MMC_CLK_POWERSAVE (0x1 << 17)#define SUNXI_MMC_CLK_ENABLE (0x1 << 16) +#define SUNXI_MMC_CLK_MASK_DATA0 (0x1U << 31)#define SUNXI_MMC_CLK_DIVIDER_MASK (0xff)#define SUNXI_MMC_GCTRL 0x000
Signature · 1 line
2.53.0
Hi James,
Quoted 4 lines · James Hilliard
Linux marks the H6/A100-style controllers with
mask_data0and sets the CLKCRMASK_DATA0bit while issuing update-clock commands. Without this, the controller can sample DAT0 as busy around clock updates before the first card command, so card detection may fail with-ETIMEDOUT.
Can you please say *WHY* this change is needed? Is this "card detection may fail" a theoretical assumption, or did this happen to you in practice? I wouldn't be aware of any reports about issues with MMC in U-Boot, so I'd be curious to hear about that, with a concrete example, and how often this happens, if you experienced this. Also if that applies to the SPL or to U-Boot proper only.
Quoted 14 lines
Mirror the Linux behavior for H6-family and NCAT2-family controllers while updating the card clock.
Signed-off-by James Hilliard <[email protected]>--- drivers/mmc/sunxi_mmc.c | 30 +++++++++++++++++++++++++++--- drivers/mmc/sunxi_mmc.h | 1 + 2 files changed, 28 insertions(+), 3 deletions(-)drivers/mmc/sunxi_mmc.c +0
-0
drivers/mmc/sunxi_mmc.c static bool sunxi_mmc_can_calibrate(void) · line 70
Quoted 7 lines
drivers/mmc/sunxi_mmc.c +4
-0@@ -64,6 +64,12 @@ static bool sunxi_mmc_can_calibrate(void)IS_ENABLED (CONFIG_MACH_SUN8I_R40 ); } +static bool sunxi_mmc_needs_data0_mask (void ) +{ +return IS_ENABLED (CONFIG_SUN50I_GEN_H6 ) || +IS_ENABLED (CONFIG_SUNXI_GEN_NCAT2 );
Meh, I see that this is a pragmatic approach, but I wonder if this should come from the DT when in U-Boot proper (or when using DM_MMC in general).
drivers/mmc/sunxi_mmc.c static int mmc_update_clk(struct sunxi_mmc_priv *priv) · line 210
Quoted 10 lines
drivers/mmc/sunxi_mmc.c +3
-0+} +static int mmc_set_mod_clk (struct sunxi_mmc_priv *priv,unsigned int hz) {unsigned int pll, pll_hz, div, n, oclk_dly, sclk_dly;@@ -201,14 +207,31 @@ static int mmc_update_clk(struct sunxi_mmc_priv *priv)return 0 ; } +static int mmc_update_clk_with_data0_mask (struct sunxi_mmc_priv *priv)
If I see this correctly, then this function is only called (twice) from mmc_config_clock() below, but you don't change the other user in the error path of sunxi_mmc_send_cmd_common(), right? It's probably worth mentioning this in the commit message.
And if that's true, please fold the functionality into mmc_config_clock(). This one knows the value of clkcr already, so no need for two read/modify/write operations, and no need for a function with a lengthy name.
Quoted 12 lines
drivers/mmc/sunxi_mmc.c +12
-0+{ +bool mask_data0 =sunxi_mmc_needs_data0_mask (); +int ret; + +if (mask_data0) +setbits_le32 (&priv->reg->clkcr,SUNXI_MMC_CLK_MASK_DATA0 ); + + ret =mmc_update_clk (priv); + +if (mask_data0) +clrbits_le32 (&priv->reg->clkcr,SUNXI_MMC_CLK_MASK_DATA0 ); +
drivers/mmc/sunxi_mmc.c static int mmc_update_clk(struct sunxi_mmc_priv *priv) · line 231
Quoted 10 lines
drivers/mmc/sunxi_mmc.c +4
-1+return ret; +} +static int mmc_config_clock (struct sunxi_mmc_priv *priv,struct mmc *mmc) {unsigned rval =readl (&priv->reg->clkcr);/* Disable Clock */ - rval &= ~SUNXI_MMC_CLK_ENABLE ; + rval &= ~(SUNXI_MMC_CLK_ENABLE | SUNXI_MMC_CLK_POWERSAVE |
What about this POWERSAVE bit? If you change this as well, please mention this in the commit message, and say why this is needed (as it wasn't used before in the driver).
Cheers,
Andre
Quoted 31 lines
drivers/mmc/sunxi_mmc.c +4
-2+ SUNXI_MMC_CLK_MASK_DATA0);writel (rval, &priv->reg->clkcr); -if (mmc_update_clk (priv)) +if (mmc_update_clk_with_data0_mask (priv))return -1 ;/* Set mod_clk to new rate */ @@ -231,9 +254,10 @@ static int mmc_config_clock(struct sunxi_mmc_priv *priv, struct mmc *mmc)#endif /* Re-enable Clock */ + rval &= ~(SUNXI_MMC_CLK_POWERSAVE |SUNXI_MMC_CLK_MASK_DATA0 ); rval |=SUNXI_MMC_CLK_ENABLE ;writel (rval, &priv->reg->clkcr); -if (mmc_update_clk (priv)) +if (mmc_update_clk_with_data0_mask (priv))return -1 ;return 0 ;drivers/mmc/sunxi_mmc.h +1
-0@@ -58,6 +58,7 @@ struct sunxi_mmc {#define SUNXI_MMC_CLK_POWERSAVE (0x1 << 17)#define SUNXI_MMC_CLK_ENABLE (0x1 << 16) +#define SUNXI_MMC_CLK_MASK_DATA0 (0x1U << 31)#define SUNXI_MMC_CLK_DIVIDER_MASK (0xff)#define SUNXI_MMC_GCTRL 0x000