All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/3] sunxi-mmc: enable new clock mode on A64
@ 2018-11-07  3:57 Vasily Khoruzhick
  2018-11-07  3:57 ` [U-Boot] [PATCH 1/3] sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option Vasily Khoruzhick
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Vasily Khoruzhick @ 2018-11-07  3:57 UTC (permalink / raw)
  To: u-boot

A64 requires new clock mode on SD and eMMC controllers. Not using
new clock mode causes stability issues of the driver - SPL may
occasionally fail to load u-boot from SD for some particular SD card
on some particular devices.

This series depends on "sunxi: add support for automatic delay calibration"
from my Pinebook series.

Tested on Pinebook and Pine64-LTS.

Vasily Khoruzhick (3):
  sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option
  sunxi-mmc: don't double clock for new mode unconditionally
  sunxi-mmc: use new mode on both controllers on A64

 arch/arm/mach-sunxi/Kconfig |  2 ++
 drivers/mmc/Kconfig         |  4 ++++
 drivers/mmc/sunxi_mmc.c     | 19 +++++++++----------
 3 files changed, 15 insertions(+), 10 deletions(-)

-- 
2.19.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 1/3] sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option
  2018-11-07  3:57 [U-Boot] [PATCH 0/3] sunxi-mmc: enable new clock mode on A64 Vasily Khoruzhick
@ 2018-11-07  3:57 ` Vasily Khoruzhick
  2018-11-07  4:13   ` Chen-Yu Tsai
  2018-11-07  3:57 ` [U-Boot] [PATCH 2/3] sunxi-mmc: don't double clock for new mode unconditionally Vasily Khoruzhick
  2018-11-07  3:57 ` [U-Boot] [PATCH 3/3] sunxi-mmc: use new mode on both controllers on A64 Vasily Khoruzhick
  2 siblings, 1 reply; 9+ messages in thread
From: Vasily Khoruzhick @ 2018-11-07  3:57 UTC (permalink / raw)
  To: u-boot

A64 doesn't have a mode switch in CCM, so introduce new
MMC_SUNXI_HAS_NEW_MODE_SWITCH option to support new clock mode on A64

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Tested-by: Zhaofeng Li <hello@zhaofeng.li>
---
 arch/arm/mach-sunxi/Kconfig | 1 +
 drivers/mmc/Kconfig         | 4 ++++
 drivers/mmc/sunxi_mmc.c     | 2 ++
 3 files changed, 7 insertions(+)

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 560dc9b25d..66fff6c6d3 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -230,6 +230,7 @@ config MACH_SUN8I_A83T
 	select PHY_SUN4I_USB
 	select SUNXI_GEN_SUN6I
 	select MMC_SUNXI_HAS_NEW_MODE
+	select MMC_SUNXI_HAS_MODE_SWITCH
 	select SUPPORT_SPL
 
 config MACH_SUN8I_H3
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 27246ee465..3f7458d409 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -569,6 +569,10 @@ config MMC_SUNXI_HAS_NEW_MODE
 	bool
 	depends on MMC_SUNXI
 
+config MMC_SUNXI_HAS_MODE_SWITCH
+	bool
+	depends on MMC_SUNXI
+
 config GENERIC_ATMEL_MCI
 	bool "Atmel Multimedia Card Interface support"
 	depends on DM_MMC && BLK && ARCH_AT91
diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
index 147eb9b4d5..b3526f5e3f 100644
--- a/drivers/mmc/sunxi_mmc.c
+++ b/drivers/mmc/sunxi_mmc.c
@@ -176,7 +176,9 @@ static int mmc_set_mod_clk(struct sunxi_mmc_priv *priv, unsigned int hz)
 
 	if (new_mode) {
 #ifdef CONFIG_MMC_SUNXI_HAS_NEW_MODE
+#ifdef CONFIG_MMC_SUNXI_HAS_MODE_SWITCH
 		val = CCM_MMC_CTRL_MODE_SEL_NEW;
+#endif
 		setbits_le32(&priv->reg->ntsr, SUNXI_MMC_NTSR_MODE_SEL_NEW);
 #endif
 	} else if (!calibrate) {
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/3] sunxi-mmc: don't double clock for new mode unconditionally
  2018-11-07  3:57 [U-Boot] [PATCH 0/3] sunxi-mmc: enable new clock mode on A64 Vasily Khoruzhick
  2018-11-07  3:57 ` [U-Boot] [PATCH 1/3] sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option Vasily Khoruzhick
@ 2018-11-07  3:57 ` Vasily Khoruzhick
  2018-11-07  4:15   ` Chen-Yu Tsai
  2018-11-07  3:57 ` [U-Boot] [PATCH 3/3] sunxi-mmc: use new mode on both controllers on A64 Vasily Khoruzhick
  2 siblings, 1 reply; 9+ messages in thread
From: Vasily Khoruzhick @ 2018-11-07  3:57 UTC (permalink / raw)
  To: u-boot

Comment in Linux driver says that clock needs to be doubled only
if we use DDR modes, moreover divider has to be set accordingly.

U-boot driver doesn't declare support for any DDR modes and doesn't
set divider, so it doubles clock unconditionally when new mode
is used.

Some cards can't handle that and as result SPL fails to load u-boot.

Fixes: de9b1771c3b ("mmc: sunxi: Support new mode")
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Tested-by: Zhaofeng Li <hello@zhaofeng.li>
---
 drivers/mmc/sunxi_mmc.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
index b3526f5e3f..e50b2c3343 100644
--- a/drivers/mmc/sunxi_mmc.c
+++ b/drivers/mmc/sunxi_mmc.c
@@ -109,13 +109,6 @@ static int mmc_set_mod_clk(struct sunxi_mmc_priv *priv, unsigned int hz)
 	calibrate = true;
 #endif
 
-	/*
-	 * The MMC clock has an extra /2 post-divider when operating in the new
-	 * mode.
-	 */
-	if (new_mode)
-		hz = hz * 2;
-
 	if (hz <= 24000000) {
 		pll = CCM_MMC_CTRL_OSCM24;
 		pll_hz = 24000000;
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 3/3] sunxi-mmc: use new mode on both controllers on A64
  2018-11-07  3:57 [U-Boot] [PATCH 0/3] sunxi-mmc: enable new clock mode on A64 Vasily Khoruzhick
  2018-11-07  3:57 ` [U-Boot] [PATCH 1/3] sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option Vasily Khoruzhick
  2018-11-07  3:57 ` [U-Boot] [PATCH 2/3] sunxi-mmc: don't double clock for new mode unconditionally Vasily Khoruzhick
@ 2018-11-07  3:57 ` Vasily Khoruzhick
  2018-11-07  4:16   ` Chen-Yu Tsai
  2 siblings, 1 reply; 9+ messages in thread
From: Vasily Khoruzhick @ 2018-11-07  3:57 UTC (permalink / raw)
  To: u-boot

Using new mode improves stability of eMMC and SD cards. Without
it SPl fails to load u-boot from SD on Pinebook.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Tested-by: Zhaofeng Li <hello@zhaofeng.li>
---
 arch/arm/mach-sunxi/Kconfig |  1 +
 drivers/mmc/sunxi_mmc.c     | 10 +++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 66fff6c6d3..3c54f5106d 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -282,6 +282,7 @@ config MACH_SUN50I
 	select SUN6I_PRCM
 	select SUNXI_DE2
 	select SUNXI_GEN_SUN6I
+	select MMC_SUNXI_HAS_NEW_MODE
 	select SUPPORT_SPL
 	select SUNXI_DRAM_DW
 	select SUNXI_DRAM_DW_32BIT
diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
index e50b2c3343..2b6f3c2234 100644
--- a/drivers/mmc/sunxi_mmc.c
+++ b/drivers/mmc/sunxi_mmc.c
@@ -98,12 +98,16 @@ static int mmc_resource_init(int sdc_no)
 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;
-	bool new_mode = false;
+	bool new_mode = true;
 	bool calibrate = false;
 	u32 val = 0;
 
-	if (IS_ENABLED(CONFIG_MMC_SUNXI_HAS_NEW_MODE) && (priv->mmc_no == 2))
-		new_mode = true;
+	if (!IS_ENABLED(CONFIG_MMC_SUNXI_HAS_NEW_MODE))
+		new_mode = false;
+
+	/* A83 support new mode only on eMMC */
+	if (IS_ENABLED(CONFIG_MACH_SUN8I_A83T) && priv->mmc_no != 2)
+		new_mode = false;
 
 #if defined(CONFIG_MACH_SUN50I) || defined(CONFIG_MACH_SUN50I_H6)
 	calibrate = true;
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 1/3] sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option
  2018-11-07  3:57 ` [U-Boot] [PATCH 1/3] sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option Vasily Khoruzhick
@ 2018-11-07  4:13   ` Chen-Yu Tsai
  2018-11-07  4:20     ` Vasily Khoruzhick
  0 siblings, 1 reply; 9+ messages in thread
From: Chen-Yu Tsai @ 2018-11-07  4:13 UTC (permalink / raw)
  To: u-boot

On Wed, Nov 7, 2018 at 11:59 AM Vasily Khoruzhick <anarsoul@gmail.com> wrote:
>
> A64 doesn't have a mode switch in CCM, so introduce new
> MMC_SUNXI_HAS_NEW_MODE_SWITCH option to support new clock mode on A64
>
> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> Tested-by: Zhaofeng Li <hello@zhaofeng.li>

This patch isn't strictly necessary. See

    https://elixir.bootlin.com/linux/v4.20-rc1/source/drivers/mmc/host/sunxi-mmc.c#L831

If the switch doesn't exist, changes to that bit are ignored.

ChenYu

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/3] sunxi-mmc: don't double clock for new mode unconditionally
  2018-11-07  3:57 ` [U-Boot] [PATCH 2/3] sunxi-mmc: don't double clock for new mode unconditionally Vasily Khoruzhick
@ 2018-11-07  4:15   ` Chen-Yu Tsai
  0 siblings, 0 replies; 9+ messages in thread
From: Chen-Yu Tsai @ 2018-11-07  4:15 UTC (permalink / raw)
  To: u-boot

On Wed, Nov 7, 2018 at 11:59 AM Vasily Khoruzhick <anarsoul@gmail.com> wrote:
>
> Comment in Linux driver says that clock needs to be doubled only
> if we use DDR modes, moreover divider has to be set accordingly.
>
> U-boot driver doesn't declare support for any DDR modes and doesn't
> set divider, so it doubles clock unconditionally when new mode

doesn't set the card clock divider, so the card is running at the module
clock's rate. This would be a bit clearer.

ChenYu

> is used.
>
> Some cards can't handle that and as result SPL fails to load u-boot.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 3/3] sunxi-mmc: use new mode on both controllers on A64
  2018-11-07  3:57 ` [U-Boot] [PATCH 3/3] sunxi-mmc: use new mode on both controllers on A64 Vasily Khoruzhick
@ 2018-11-07  4:16   ` Chen-Yu Tsai
  0 siblings, 0 replies; 9+ messages in thread
From: Chen-Yu Tsai @ 2018-11-07  4:16 UTC (permalink / raw)
  To: u-boot

On Wed, Nov 7, 2018 at 11:59 AM Vasily Khoruzhick <anarsoul@gmail.com> wrote:
>
> Using new mode improves stability of eMMC and SD cards. Without
> it SPl fails to load u-boot from SD on Pinebook.
>
> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> Tested-by: Zhaofeng Li <hello@zhaofeng.li>

Reviewed-by: Chen-Yu Tsai <wens@csie.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 1/3] sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option
  2018-11-07  4:13   ` Chen-Yu Tsai
@ 2018-11-07  4:20     ` Vasily Khoruzhick
  2018-11-07  4:27       ` Chen-Yu Tsai
  0 siblings, 1 reply; 9+ messages in thread
From: Vasily Khoruzhick @ 2018-11-07  4:20 UTC (permalink / raw)
  To: u-boot

On Tue, Nov 6, 2018 at 8:13 PM Chen-Yu Tsai <wens@csie.org> wrote:
>
> On Wed, Nov 7, 2018 at 11:59 AM Vasily Khoruzhick <anarsoul@gmail.com> wrote:
> >
> > A64 doesn't have a mode switch in CCM, so introduce new
> > MMC_SUNXI_HAS_NEW_MODE_SWITCH option to support new clock mode on A64
> >
> > Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> > Tested-by: Zhaofeng Li <hello@zhaofeng.li>
>
> This patch isn't strictly necessary. See
>
>     https://elixir.bootlin.com/linux/v4.20-rc1/source/drivers/mmc/host/sunxi-mmc.c#L831
>
> If the switch doesn't exist, changes to that bit are ignored.

CCM_MMC_CTRL_MODE_SEL_NEW is not defined on A64, so it won't compile
unless we define it on A64 which seems to be redundant.

>
> ChenYu

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 1/3] sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option
  2018-11-07  4:20     ` Vasily Khoruzhick
@ 2018-11-07  4:27       ` Chen-Yu Tsai
  0 siblings, 0 replies; 9+ messages in thread
From: Chen-Yu Tsai @ 2018-11-07  4:27 UTC (permalink / raw)
  To: u-boot

On Wed, Nov 7, 2018 at 12:21 PM Vasily Khoruzhick <anarsoul@gmail.com> wrote:
>
> On Tue, Nov 6, 2018 at 8:13 PM Chen-Yu Tsai <wens@csie.org> wrote:
> >
> > On Wed, Nov 7, 2018 at 11:59 AM Vasily Khoruzhick <anarsoul@gmail.com> wrote:
> > >
> > > A64 doesn't have a mode switch in CCM, so introduce new
> > > MMC_SUNXI_HAS_NEW_MODE_SWITCH option to support new clock mode on A64
> > >
> > > Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> > > Tested-by: Zhaofeng Li <hello@zhaofeng.li>
> >
> > This patch isn't strictly necessary. See
> >
> >     https://elixir.bootlin.com/linux/v4.20-rc1/source/drivers/mmc/host/sunxi-mmc.c#L831
> >
> > If the switch doesn't exist, changes to that bit are ignored.
>
> CCM_MMC_CTRL_MODE_SEL_NEW is not defined on A64, so it won't compile
> unless we define it on A64 which seems to be redundant.

OK. That makes sense then. You should mention that in the commit message,
as that is exactly the reason why this patch is needed.

On the other hand, having hardware device registers defined at the arch level
is kind of hard to keep track of.

ChenYu

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-11-07  4:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-07  3:57 [U-Boot] [PATCH 0/3] sunxi-mmc: enable new clock mode on A64 Vasily Khoruzhick
2018-11-07  3:57 ` [U-Boot] [PATCH 1/3] sunxi-mmc: introduce new MMC_SUNXI_HAS_NEW_MODE_SWITCH option Vasily Khoruzhick
2018-11-07  4:13   ` Chen-Yu Tsai
2018-11-07  4:20     ` Vasily Khoruzhick
2018-11-07  4:27       ` Chen-Yu Tsai
2018-11-07  3:57 ` [U-Boot] [PATCH 2/3] sunxi-mmc: don't double clock for new mode unconditionally Vasily Khoruzhick
2018-11-07  4:15   ` Chen-Yu Tsai
2018-11-07  3:57 ` [U-Boot] [PATCH 3/3] sunxi-mmc: use new mode on both controllers on A64 Vasily Khoruzhick
2018-11-07  4:16   ` Chen-Yu Tsai

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.