Skip to contentSkip to conversation

mmc: meson-gx: fix mmc & scard failure on SM1 SoCs

PATCH Superseded Neil Armstrong 3 participants 11 messages Nov 6, 2020 – Nov 9, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover mmc: meson-gx: fix mmc & scard failure on SM1 SoCs

Amlogic SM1 SoCs doesn't handle very well high clocks from the DIV2 input Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher frequencies via the first input from a composite clock.

Here 26MHz corresponds to MMC_HS clock speed.

We also add a u-boot only sm1 compatible to distinguish the controller in a new meson-sm1-u-boot.dtsi and reworks the other -u-boot.dtsi to use this for SM1 based boards.

Finally a TOFIX is added to precise the clock management should use the clock controller instead of local management with fixed clock rates.

Neil Armstrong (3):
mmc: meson-gx: move arch header to local header
mmc: meson-gx: limit max frequency on SM1 SoCs
ARM: dts: meson-sm1: add u-boot specific MMC controller compatible

 .../meson-g12b-a311d-khadas-vim3-u-boot.dtsi  |  1 +
 arch/arm/dts/meson-khadas-vim3-u-boot.dtsi    |  2 --
 .../dts/meson-sm1-khadas-vim3l-u-boot.dtsi    |  1 +
 arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi  |  2 +-
 arch/arm/dts/meson-sm1-sei610-u-boot.dtsi     |  2 +-
 arch/arm/dts/meson-sm1-u-boot.dtsi            | 20 +++++++++++++
 drivers/mmc/meson_gx_mmc.c                    | 28 ++++++++++++++++---
 .../sd_emmc.h => drivers/mmc/meson_gx_mmc.h   | 10 ++++---
 8 files changed, 54 insertions(+), 12 deletions(-)
 create mode 100644 arch/arm/dts/meson-sm1-u-boot.dtsi
 rename arch/arm/include/asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h (95%)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/3 mmc: meson-gx: move arch header to local header

Move the asm/arch-meson/sd_emmc.h to a local meson_gx_mmc.h, remove the useless if/then and fix the meson_gx_mmc.c include.

---
 drivers/mmc/meson_gx_mmc.c                                 | 4 ++--
 .../asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h | 7 ++-----
 2 files changed, 4 insertions(+), 7 deletions(-)
 rename arch/arm/include/asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h (97%)
drivers/mmc/meson_gx_mmc.c +2 -2
index 719dd1e5e5..9350edf3fa 100644
@@ -13,9 +13,9 @@
 #include <mmc.h>
 #include <asm/io.h>
 #include <asm/gpio.h>
-#include <asm/arch/sd_emmc.h>
 #include <linux/delay.h>
 #include <linux/log2.h>
+#include "meson_gx_mmc.h"
 
 static inline void *get_regbase(const struct mmc *mmc)
 {
@@ -265,7 +265,7 @@ static int meson_mmc_probe(struct udevice *dev)
 	cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |
 			MMC_MODE_HS_52MHz | MMC_MODE_HS;
 	cfg->f_min = DIV_ROUND_UP(SD_EMMC_CLKSRC_24M, CLK_MAX_DIV);
-	cfg->f_max = 100000000; /* 100 MHz */
+	cfg->f_max = 100000000; /* 100 MHz */;
 	cfg->b_max = 511; /* max 512 - 1 blocks */
 	cfg->name = dev->name;
 
drivers/mmc/meson_gx_mmc.h renamed from arch/arm/include/asm/arch-meson/sd_emmc.h +2 -5
similarity index 97%
rename from arch/arm/include/asm/arch-meson/sd_emmc.h
rename to drivers/mmc/meson_gx_mmc.h
index 1e9f8cf498..b4544b5562 100644
@@ -3,14 +3,11 @@
  * (C) Copyright 2016 Carlo Caione <[email protected]>
  */
 
-#ifndef __SD_EMMC_H__
-#define __SD_EMMC_H__
+#ifndef __MESON_GX_MMC_H__
+#define __MESON_GX_MMC_H__
 
 #include <mmc.h>
-#ifndef __ASSEMBLY__
 #include <linux/bitops.h>
-#endif
-
 
 #define SDIO_PORT_A			0
 #define SDIO_PORT_B			1
Signature · 1 line
2.25.1
#2 lore raw

PATCH 1/3 mmc: meson-gx: move arch header to local header

Quoted 26 lines · Neil Armstrong

Move the asm/arch-meson/sd_emmc.h to a local meson_gx_mmc.h, remove the useless if/then and fix the meson_gx_mmc.c include.

---
 drivers/mmc/meson_gx_mmc.c                                 | 4 ++--
 .../asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h | 7 ++-----
 2 files changed, 4 insertions(+), 7 deletions(-)
 rename arch/arm/include/asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h (97%)
drivers/mmc/meson_gx_mmc.c +1 -1
index 719dd1e5e5..9350edf3fa 100644
@@ -13,9 +13,9 @@
 #include <mmc.h>
 #include <asm/io.h>
 #include <asm/gpio.h>
-#include <asm/arch/sd_emmc.h>
 #include <linux/delay.h>
 #include <linux/log2.h>
+#include "meson_gx_mmc.h"
 
 static inline void *get_regbase(const struct mmc *mmc)
 {

drivers/mmc/meson_gx_mmc.c static int meson_mmc_probe(struct udevice *dev) · line 268

Quoted 5 lines
drivers/mmc/meson_gx_mmc.c +1 -1
@@ -265,7 +265,7 @@ static int meson_mmc_probe(struct udevice *dev)
 	cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |
 			MMC_MODE_HS_52MHz | MMC_MODE_HS;
 	cfg->f_min = DIV_ROUND_UP(SD_EMMC_CLKSRC_24M, CLK_MAX_DIV);
-	cfg->f_max = 100000000; /* 100 MHz */
+	cfg->f_max = 100000000; /* 100 MHz */;

Don't need to touch. Remove ";"

Quoted 28 lines
drivers/mmc/meson_gx_mmc.c +0 -0
 	cfg->b_max = 511; /* max 512 - 1 blocks */
 	cfg->name = dev->name;
 
drivers/mmc/meson_gx_mmc.h renamed from arch/arm/include/asm/arch-meson/sd_emmc.h +2 -5
similarity index 97%
rename from arch/arm/include/asm/arch-meson/sd_emmc.h
rename to drivers/mmc/meson_gx_mmc.h
index 1e9f8cf498..b4544b5562 100644
@@ -3,14 +3,11 @@
  * (C) Copyright 2016 Carlo Caione <[email protected]>
  */
 
-#ifndef __SD_EMMC_H__
-#define __SD_EMMC_H__
+#ifndef __MESON_GX_MMC_H__
+#define __MESON_GX_MMC_H__
 
 #include <mmc.h>
-#ifndef __ASSEMBLY__
 #include <linux/bitops.h>
-#endif
-
 
 #define SDIO_PORT_A			0
 #define SDIO_PORT_B			1
#3 lore raw

PATCH 1/3 mmc: meson-gx: move arch header to local header

Quoted 24 lines · Jaehoon Chung
Quoted 23 lines · Neil Armstrong

Move the asm/arch-meson/sd_emmc.h to a local meson_gx_mmc.h, remove the useless if/then and fix the meson_gx_mmc.c include.

---
 drivers/mmc/meson_gx_mmc.c                                 | 4 ++--
 .../asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h | 7 ++-----
 2 files changed, 4 insertions(+), 7 deletions(-)
 rename arch/arm/include/asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h (97%)
drivers/mmc/meson_gx_mmc.c +1 -1
index 719dd1e5e5..9350edf3fa 100644
@@ -13,9 +13,9 @@
 #include <mmc.h>
 #include <asm/io.h>
 #include <asm/gpio.h>
-#include <asm/arch/sd_emmc.h>
 #include <linux/delay.h>
 #include <linux/log2.h>
+#include "meson_gx_mmc.h"
 
Quoted 10 lines

drivers/mmc/meson_gx_mmc.c static int meson_mmc_probe(struct udevice *dev) · line 268

Quoted 8 lines
drivers/mmc/meson_gx_mmc.c +1 -1
 static inline void *get_regbase(const struct mmc *mmc)
 {
@@ -265,7 +265,7 @@ static int meson_mmc_probe(struct udevice *dev)
 	cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |
 			MMC_MODE_HS_52MHz | MMC_MODE_HS;
 	cfg->f_min = DIV_ROUND_UP(SD_EMMC_CLKSRC_24M, CLK_MAX_DIV);
-	cfg->f_max = 100000000; /* 100 MHz */
+	cfg->f_max = 100000000; /* 100 MHz */;

Don't need to touch. Remove ";"

Oops it's a spurious change, thanks for noticing.

Neil

Quoted 30 lines
Quoted 29 lines
drivers/mmc/meson_gx_mmc.c +0 -0
 	cfg->b_max = 511; /* max 512 - 1 blocks */
 	cfg->name = dev->name;
 
drivers/mmc/meson_gx_mmc.h renamed from arch/arm/include/asm/arch-meson/sd_emmc.h +2 -5
similarity index 97%
rename from arch/arm/include/asm/arch-meson/sd_emmc.h
rename to drivers/mmc/meson_gx_mmc.h
index 1e9f8cf498..b4544b5562 100644
@@ -3,14 +3,11 @@
  * (C) Copyright 2016 Carlo Caione <[email protected]>
  */
 
-#ifndef __SD_EMMC_H__
-#define __SD_EMMC_H__
+#ifndef __MESON_GX_MMC_H__
+#define __MESON_GX_MMC_H__
 
 #include <mmc.h>
-#ifndef __ASSEMBLY__
 #include <linux/bitops.h>
-#endif
-
 
 #define SDIO_PORT_A			0
 #define SDIO_PORT_B			1
#4 lore raw

PATCH 2/3 mmc: meson-gx: limit max frequency on SM1 SoCs

In reply to Neil Armstrong

Amlogic SM1 SoCs doesn't handle very well high clocks from the DIV2 input Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher frequencies via the first input from a composite clock.

Here 26MHz corresponds to MMC_HS clock speed.

We also add a u-boot only sm1 compatible to distinguish the controller.

Finally a TOFIX is added to precise the clock management should use the clock controller instead of local management with fixed clock rates.

---
 drivers/mmc/meson_gx_mmc.c | 26 +++++++++++++++++++++++---
 drivers/mmc/meson_gx_mmc.h |  5 +++++
 2 files changed, 28 insertions(+), 3 deletions(-)
drivers/mmc/meson_gx_mmc.c +23 -3
index 9350edf3fa..2c6b6cd15b 100644
@@ -17,6 +17,14 @@
 #include <linux/log2.h>
 #include "meson_gx_mmc.h"
 
+bool meson_gx_mmc_is_compatible(struct udevice *dev,
+				enum meson_gx_mmc_compatible family)
+{
+	enum meson_gx_mmc_compatible compat = dev_get_driver_data(dev);
+
+	return compat == family;
+}
+
 static inline void *get_regbase(const struct mmc *mmc)
 {
 	struct meson_mmc_platdata *pdata = mmc->priv;
@@ -42,6 +50,8 @@ static void meson_mmc_config_clock(struct mmc *mmc)
 	if (!mmc->clock)
 		return;
 
+	/* TOFIX This should use the proper clock taken from DT */
+
 	/* 1GHz / CLK_MAX_DIV = 15,9 MHz */
 	if (mmc->clock > 16000000) {
 		clk = SD_EMMC_CLKSRC_DIV2;
@@ -265,7 +275,16 @@ static int meson_mmc_probe(struct udevice *dev)
 	cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |
 			MMC_MODE_HS_52MHz | MMC_MODE_HS;
 	cfg->f_min = DIV_ROUND_UP(SD_EMMC_CLKSRC_24M, CLK_MAX_DIV);
-	cfg->f_max = 100000000; /* 100 MHz */;
+	/*
+	 * TOFIX SM1 SoCs doesn't handle very well high clocks from the DIV2 input
+	 * Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher
+	 * frequencies via the first input from a composite clock
+	 * 26MHz corresponds to MMC_HS clock speed
+	 */
+	if (meson_gx_mmc_is_compatible(dev, MMC_COMPATIBLE_SM1))
+		cfg->f_max = 26000000; /* 26 MHz */
+	else
+		cfg->f_max = 100000000; /* 100 MHz */
 	cfg->b_max = 511; /* max 512 - 1 blocks */
 	cfg->name = dev->name;
 
@@ -308,8 +327,9 @@ int meson_mmc_bind(struct udevice *dev)
 }
 
 static const struct udevice_id meson_mmc_match[] = {
-	{ .compatible = "amlogic,meson-gx-mmc" },
-	{ .compatible = "amlogic,meson-axg-mmc" },
+	{ .compatible = "amlogic,meson-gx-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-axg-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-sm1-mmc", .data = MMC_COMPATIBLE_SM1 },
 	{ /* sentinel */ }
 };
 
drivers/mmc/meson_gx_mmc.h +5 -0
index b4544b5562..92aec5329f 100644
@@ -9,6 +9,11 @@
 #include <mmc.h>
 #include <linux/bitops.h>
 
+enum meson_gx_mmc_compatible {
+	MMC_COMPATIBLE_GX,
+	MMC_COMPATIBLE_SM1,
+};
+
 #define SDIO_PORT_A			0
 #define SDIO_PORT_B			1
 #define SDIO_PORT_C			2
Signature · 1 line
2.25.1
#5 lore raw

PATCH 2/3 mmc: meson-gx: limit max frequency on SM1 SoCs

Quoted 7 lines · Neil Armstrong

Amlogic SM1 SoCs doesn't handle very well high clocks from the DIV2 input Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher frequencies via the first input from a composite clock.

Here 26MHz corresponds to MMC_HS clock speed.

We also add a u-boot only sm1 compatible to distinguish the controller.

Well, it's workaround for using eMMC.
I didn't check all SM1 SoCs..but odroid-c4 is supported hs200 mode (200MHz) on Kernel side. It means that bootloader can also support its mode.

I'm checking this problem with odroid-c4 target. If i find how to fix, i will share.

Best Regards,
Jaehoon Chung

Quoted 85 lines

Finally a TOFIX is added to precise the clock management should use the clock controller instead of local management with fixed clock rates.

---
 drivers/mmc/meson_gx_mmc.c | 26 +++++++++++++++++++++++---
 drivers/mmc/meson_gx_mmc.h |  5 +++++
 2 files changed, 28 insertions(+), 3 deletions(-)
drivers/mmc/meson_gx_mmc.c +23 -3
index 9350edf3fa..2c6b6cd15b 100644
@@ -17,6 +17,14 @@
 #include <linux/log2.h>
 #include "meson_gx_mmc.h"
 
+bool meson_gx_mmc_is_compatible(struct udevice *dev,
+				enum meson_gx_mmc_compatible family)
+{
+	enum meson_gx_mmc_compatible compat = dev_get_driver_data(dev);
+
+	return compat == family;
+}
+
 static inline void *get_regbase(const struct mmc *mmc)
 {
 	struct meson_mmc_platdata *pdata = mmc->priv;
@@ -42,6 +50,8 @@ static void meson_mmc_config_clock(struct mmc *mmc)
 	if (!mmc->clock)
 		return;
 
+	/* TOFIX This should use the proper clock taken from DT */
+
 	/* 1GHz / CLK_MAX_DIV = 15,9 MHz */
 	if (mmc->clock > 16000000) {
 		clk = SD_EMMC_CLKSRC_DIV2;
@@ -265,7 +275,16 @@ static int meson_mmc_probe(struct udevice *dev)
 	cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |
 			MMC_MODE_HS_52MHz | MMC_MODE_HS;
 	cfg->f_min = DIV_ROUND_UP(SD_EMMC_CLKSRC_24M, CLK_MAX_DIV);
-	cfg->f_max = 100000000; /* 100 MHz */;
+	/*
+	 * TOFIX SM1 SoCs doesn't handle very well high clocks from the DIV2 input
+	 * Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher
+	 * frequencies via the first input from a composite clock
+	 * 26MHz corresponds to MMC_HS clock speed
+	 */
+	if (meson_gx_mmc_is_compatible(dev, MMC_COMPATIBLE_SM1))
+		cfg->f_max = 26000000; /* 26 MHz */
+	else
+		cfg->f_max = 100000000; /* 100 MHz */
 	cfg->b_max = 511; /* max 512 - 1 blocks */
 	cfg->name = dev->name;
 
@@ -308,8 +327,9 @@ int meson_mmc_bind(struct udevice *dev)
 }
 
 static const struct udevice_id meson_mmc_match[] = {
-	{ .compatible = "amlogic,meson-gx-mmc" },
-	{ .compatible = "amlogic,meson-axg-mmc" },
+	{ .compatible = "amlogic,meson-gx-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-axg-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-sm1-mmc", .data = MMC_COMPATIBLE_SM1 },
 	{ /* sentinel */ }
 };
 
drivers/mmc/meson_gx_mmc.h +5 -0
index b4544b5562..92aec5329f 100644
@@ -9,6 +9,11 @@
 #include <mmc.h>
 #include <linux/bitops.h>
 
+enum meson_gx_mmc_compatible {
+	MMC_COMPATIBLE_GX,
+	MMC_COMPATIBLE_SM1,
+};
+
 #define SDIO_PORT_A			0
 #define SDIO_PORT_B			1
 #define SDIO_PORT_C			2
#6 lore raw

PATCH 2/3 mmc: meson-gx: limit max frequency on SM1 SoCs

Quoted 10 lines · Jaehoon Chung
Quoted 7 lines · Neil Armstrong

Amlogic SM1 SoCs doesn't handle very well high clocks from the DIV2 input Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher frequencies via the first input from a composite clock.

Here 26MHz corresponds to MMC_HS clock speed.

We also add a u-boot only sm1 compatible to distinguish the controller.

Well, it's workaround for using eMMC.

It's for the next release, to have a temporary fix. The goal is to not have such workaround....

Quoted 4 lines

I didn't check all SM1 SoCs..but odroid-c4 is supported hs200 mode (200MHz) on Kernel side. It means that bootloader can also support its mode.

I'm checking this problem with odroid-c4 target. If i find how to fix, i will share.

H200 will need a big work including tuning and proper clock management.

If you manage to got that far, I'll be great !

Neil

Quoted 91 lines

Best Regards,
Jaehoon Chung

Quoted 85 lines

Finally a TOFIX is added to precise the clock management should use the clock controller instead of local management with fixed clock rates.

---
 drivers/mmc/meson_gx_mmc.c | 26 +++++++++++++++++++++++---
 drivers/mmc/meson_gx_mmc.h |  5 +++++
 2 files changed, 28 insertions(+), 3 deletions(-)
drivers/mmc/meson_gx_mmc.c +23 -3
index 9350edf3fa..2c6b6cd15b 100644
@@ -17,6 +17,14 @@
 #include <linux/log2.h>
 #include "meson_gx_mmc.h"
 
+bool meson_gx_mmc_is_compatible(struct udevice *dev,
+				enum meson_gx_mmc_compatible family)
+{
+	enum meson_gx_mmc_compatible compat = dev_get_driver_data(dev);
+
+	return compat == family;
+}
+
 static inline void *get_regbase(const struct mmc *mmc)
 {
 	struct meson_mmc_platdata *pdata = mmc->priv;
@@ -42,6 +50,8 @@ static void meson_mmc_config_clock(struct mmc *mmc)
 	if (!mmc->clock)
 		return;
 
+	/* TOFIX This should use the proper clock taken from DT */
+
 	/* 1GHz / CLK_MAX_DIV = 15,9 MHz */
 	if (mmc->clock > 16000000) {
 		clk = SD_EMMC_CLKSRC_DIV2;
@@ -265,7 +275,16 @@ static int meson_mmc_probe(struct udevice *dev)
 	cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |
 			MMC_MODE_HS_52MHz | MMC_MODE_HS;
 	cfg->f_min = DIV_ROUND_UP(SD_EMMC_CLKSRC_24M, CLK_MAX_DIV);
-	cfg->f_max = 100000000; /* 100 MHz */;
+	/*
+	 * TOFIX SM1 SoCs doesn't handle very well high clocks from the DIV2 input
+	 * Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher
+	 * frequencies via the first input from a composite clock
+	 * 26MHz corresponds to MMC_HS clock speed
+	 */
+	if (meson_gx_mmc_is_compatible(dev, MMC_COMPATIBLE_SM1))
+		cfg->f_max = 26000000; /* 26 MHz */
+	else
+		cfg->f_max = 100000000; /* 100 MHz */
 	cfg->b_max = 511; /* max 512 - 1 blocks */
 	cfg->name = dev->name;
 
@@ -308,8 +327,9 @@ int meson_mmc_bind(struct udevice *dev)
 }
 
 static const struct udevice_id meson_mmc_match[] = {
-	{ .compatible = "amlogic,meson-gx-mmc" },
-	{ .compatible = "amlogic,meson-axg-mmc" },
+	{ .compatible = "amlogic,meson-gx-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-axg-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-sm1-mmc", .data = MMC_COMPATIBLE_SM1 },
 	{ /* sentinel */ }
 };
 
drivers/mmc/meson_gx_mmc.h +5 -0
index b4544b5562..92aec5329f 100644
@@ -9,6 +9,11 @@
 #include <mmc.h>
 #include <linux/bitops.h>
 
+enum meson_gx_mmc_compatible {
+	MMC_COMPATIBLE_GX,
+	MMC_COMPATIBLE_SM1,
+};
+
 #define SDIO_PORT_A			0
 #define SDIO_PORT_B			1
 #define SDIO_PORT_C			2
#7 lore raw

PATCH 2/3 mmc: meson-gx: limit max frequency on SM1 SoCs

Quoted 18 lines

From: Neil Armstrong <[email protected]>
Date: Fri, 6 Nov 2020 11:35:30 +0100

Quoted 10 lines · Jaehoon Chung
Quoted 7 lines · Neil Armstrong

Amlogic SM1 SoCs doesn't handle very well high clocks from the DIV2 input Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher frequencies via the first input from a composite clock.

Here 26MHz corresponds to MMC_HS clock speed.

We also add a u-boot only sm1 compatible to distinguish the controller.

Well, it's workaround for using eMMC.

It's for the next release, to have a temporary fix. The goal is to not have such workaround....

Quoted 6 lines
Quoted 4 lines

I didn't check all SM1 SoCs..but odroid-c4 is supported hs200 mode (200MHz) on Kernel side. It means that bootloader can also support its mode.

I'm checking this problem with odroid-c4 target. If i find how to fix, i will share.

H200 will need a big work including tuning and proper clock management.

I worry a bit that this would make things more fragile. I have some trouble getting HS200 to work properly on the Odroid-N2 in OpenBSD (might be a clock management issue). And the fact that on both the Odroid-N2 and Odroid-C4 the eMMC isn't soldered on means that it has to work reliably on a wider variety of eMMC modules.

I believe Linux automatically switches back to a lowe-speed mode if HS200 doesn't work isn't it? Should U-Boot do something similar?

Quoted 97 lines

If you manage to got that far, I'll be great !

Neil

Quoted 91 lines

Best Regards,
Jaehoon Chung

Quoted 85 lines

Finally a TOFIX is added to precise the clock management should use the clock controller instead of local management with fixed clock rates.

---
 drivers/mmc/meson_gx_mmc.c | 26 +++++++++++++++++++++++---
 drivers/mmc/meson_gx_mmc.h |  5 +++++
 2 files changed, 28 insertions(+), 3 deletions(-)
drivers/mmc/meson_gx_mmc.c +23 -3
index 9350edf3fa..2c6b6cd15b 100644
@@ -17,6 +17,14 @@
 #include <linux/log2.h>
 #include "meson_gx_mmc.h"
 
+bool meson_gx_mmc_is_compatible(struct udevice *dev,
+				enum meson_gx_mmc_compatible family)
+{
+	enum meson_gx_mmc_compatible compat = dev_get_driver_data(dev);
+
+	return compat == family;
+}
+
 static inline void *get_regbase(const struct mmc *mmc)
 {
 	struct meson_mmc_platdata *pdata = mmc->priv;
@@ -42,6 +50,8 @@ static void meson_mmc_config_clock(struct mmc *mmc)
 	if (!mmc->clock)
 		return;
 
+	/* TOFIX This should use the proper clock taken from DT */
+
 	/* 1GHz / CLK_MAX_DIV = 15,9 MHz */
 	if (mmc->clock > 16000000) {
 		clk = SD_EMMC_CLKSRC_DIV2;
@@ -265,7 +275,16 @@ static int meson_mmc_probe(struct udevice *dev)
 	cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |
 			MMC_MODE_HS_52MHz | MMC_MODE_HS;
 	cfg->f_min = DIV_ROUND_UP(SD_EMMC_CLKSRC_24M, CLK_MAX_DIV);
-	cfg->f_max = 100000000; /* 100 MHz */;
+	/*
+	 * TOFIX SM1 SoCs doesn't handle very well high clocks from the DIV2 input
+	 * Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher
+	 * frequencies via the first input from a composite clock
+	 * 26MHz corresponds to MMC_HS clock speed
+	 */
+	if (meson_gx_mmc_is_compatible(dev, MMC_COMPATIBLE_SM1))
+		cfg->f_max = 26000000; /* 26 MHz */
+	else
+		cfg->f_max = 100000000; /* 100 MHz */
 	cfg->b_max = 511; /* max 512 - 1 blocks */
 	cfg->name = dev->name;
 
@@ -308,8 +327,9 @@ int meson_mmc_bind(struct udevice *dev)
 }
 
 static const struct udevice_id meson_mmc_match[] = {
-	{ .compatible = "amlogic,meson-gx-mmc" },
-	{ .compatible = "amlogic,meson-axg-mmc" },
+	{ .compatible = "amlogic,meson-gx-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-axg-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-sm1-mmc", .data = MMC_COMPATIBLE_SM1 },
 	{ /* sentinel */ }
 };
 
drivers/mmc/meson_gx_mmc.h +5 -0
index b4544b5562..92aec5329f 100644
@@ -9,6 +9,11 @@
 #include <mmc.h>
 #include <linux/bitops.h>
 
+enum meson_gx_mmc_compatible {
+	MMC_COMPATIBLE_GX,
+	MMC_COMPATIBLE_SM1,
+};
+
 #define SDIO_PORT_A			0
 #define SDIO_PORT_B			1
 #define SDIO_PORT_C			2
#8 lore raw

PATCH 2/3 mmc: meson-gx: limit max frequency on SM1 SoCs

Hi Mark,

Quoted 25 lines · Mark Kettenis
Quoted 18 lines

From: Neil Armstrong <[email protected]>
Date: Fri, 6 Nov 2020 11:35:30 +0100

Quoted 10 lines · Jaehoon Chung
Quoted 7 lines · Neil Armstrong

Amlogic SM1 SoCs doesn't handle very well high clocks from the DIV2 input Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher frequencies via the first input from a composite clock.

Here 26MHz corresponds to MMC_HS clock speed.

We also add a u-boot only sm1 compatible to distinguish the controller.

Well, it's workaround for using eMMC.

It's for the next release, to have a temporary fix. The goal is to not have such workaround....

Quoted 6 lines
Quoted 4 lines

I didn't check all SM1 SoCs..but odroid-c4 is supported hs200 mode (200MHz) on Kernel side. It means that bootloader can also support its mode.

I'm checking this problem with odroid-c4 target. If i find how to fix, i will share.

H200 will need a big work including tuning and proper clock management.

Quoted 8 lines

I worry a bit that this would make things more fragile. I have some trouble getting HS200 to work properly on the Odroid-N2 in OpenBSD (might be a clock management issue). And the fact that on both the Odroid-N2 and Odroid-C4 the eMMC isn't soldered on means that it has to work reliably on a wider variety of eMMC modules.

I believe Linux automatically switches back to a lowe-speed mode if HS200 doesn't work isn't it? Should U-Boot do something similar?

As i know, It's provided on U-boot side, likes Linux.
If HS200 or other modes are failed, then it's trying to set lower mode. But I don't know why SM1 SoC doesn't set to it.
It seems that doesn't recovery to previous clock or some configs.

Best Regards,
Jaehoon Chung

Quoted 99 lines
Quoted 98 lines

If you manage to got that far, I'll be great !

Neil

Quoted 91 lines

Best Regards,
Jaehoon Chung

Quoted 85 lines

Finally a TOFIX is added to precise the clock management should use the clock controller instead of local management with fixed clock rates.

---
 drivers/mmc/meson_gx_mmc.c | 26 +++++++++++++++++++++++---
 drivers/mmc/meson_gx_mmc.h |  5 +++++
 2 files changed, 28 insertions(+), 3 deletions(-)
drivers/mmc/meson_gx_mmc.c +23 -3
index 9350edf3fa..2c6b6cd15b 100644
@@ -17,6 +17,14 @@
 #include <linux/log2.h>
 #include "meson_gx_mmc.h"
 
+bool meson_gx_mmc_is_compatible(struct udevice *dev,
+				enum meson_gx_mmc_compatible family)
+{
+	enum meson_gx_mmc_compatible compat = dev_get_driver_data(dev);
+
+	return compat == family;
+}
+
 static inline void *get_regbase(const struct mmc *mmc)
 {
 	struct meson_mmc_platdata *pdata = mmc->priv;
@@ -42,6 +50,8 @@ static void meson_mmc_config_clock(struct mmc *mmc)
 	if (!mmc->clock)
 		return;
 
+	/* TOFIX This should use the proper clock taken from DT */
+
 	/* 1GHz / CLK_MAX_DIV = 15,9 MHz */
 	if (mmc->clock > 16000000) {
 		clk = SD_EMMC_CLKSRC_DIV2;
@@ -265,7 +275,16 @@ static int meson_mmc_probe(struct udevice *dev)
 	cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |
 			MMC_MODE_HS_52MHz | MMC_MODE_HS;
 	cfg->f_min = DIV_ROUND_UP(SD_EMMC_CLKSRC_24M, CLK_MAX_DIV);
-	cfg->f_max = 100000000; /* 100 MHz */;
+	/*
+	 * TOFIX SM1 SoCs doesn't handle very well high clocks from the DIV2 input
+	 * Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher
+	 * frequencies via the first input from a composite clock
+	 * 26MHz corresponds to MMC_HS clock speed
+	 */
+	if (meson_gx_mmc_is_compatible(dev, MMC_COMPATIBLE_SM1))
+		cfg->f_max = 26000000; /* 26 MHz */
+	else
+		cfg->f_max = 100000000; /* 100 MHz */
 	cfg->b_max = 511; /* max 512 - 1 blocks */
 	cfg->name = dev->name;
 
@@ -308,8 +327,9 @@ int meson_mmc_bind(struct udevice *dev)
 }
 
 static const struct udevice_id meson_mmc_match[] = {
-	{ .compatible = "amlogic,meson-gx-mmc" },
-	{ .compatible = "amlogic,meson-axg-mmc" },
+	{ .compatible = "amlogic,meson-gx-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-axg-mmc", .data = MMC_COMPATIBLE_GX },
+	{ .compatible = "amlogic,meson-sm1-mmc", .data = MMC_COMPATIBLE_SM1 },
 	{ /* sentinel */ }
 };
 
drivers/mmc/meson_gx_mmc.h +5 -0
index b4544b5562..92aec5329f 100644
@@ -9,6 +9,11 @@
 #include <mmc.h>
 #include <linux/bitops.h>
 
+enum meson_gx_mmc_compatible {
+	MMC_COMPATIBLE_GX,
+	MMC_COMPATIBLE_SM1,
+};
+
 #define SDIO_PORT_A			0
 #define SDIO_PORT_B			1
 #define SDIO_PORT_C			2
#9 lore raw

PATCH 3/3 ARM: dts: meson-sm1: add u-boot specific MMC controller compatible

In reply to Neil Armstrong

In order to enable the Amlogic SM1 MMC controller fix, we need to add a u-boot specific MMC controller compatible.

This adds a new meson-sm1-u-boot.dtsi and reworks the other -u-boot.dtsi to use this for SM1 based boards.

---
 .../meson-g12b-a311d-khadas-vim3-u-boot.dtsi  |  1 +
 arch/arm/dts/meson-khadas-vim3-u-boot.dtsi    |  2 --
 .../dts/meson-sm1-khadas-vim3l-u-boot.dtsi    |  1 +
 arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi  |  2 +-
 arch/arm/dts/meson-sm1-sei610-u-boot.dtsi     |  2 +-
 arch/arm/dts/meson-sm1-u-boot.dtsi            | 20 +++++++++++++++++++
 6 files changed, 24 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/dts/meson-sm1-u-boot.dtsi
arch/arm/dts/meson-g12b-a311d-khadas-vim3-u-boot.dtsi +1 -0
index f66eca14b1..489efa150a 100644
@@ -4,4 +4,5 @@
  * Author: Neil Armstrong <[email protected]>
  */
 
+#include "meson-g12-common-u-boot.dtsi"
 #include "meson-khadas-vim3-u-boot.dtsi"
arch/arm/dts/meson-khadas-vim3-u-boot.dtsi +0 -2
index b5da4fdfc3..81fd5be378 100644
@@ -4,8 +4,6 @@
  * Author: Neil Armstrong <[email protected]>
  */
 
-#include "meson-g12-common-u-boot.dtsi"
-
 / {
 	aliases {
 		spi0 = &spifc;
arch/arm/dts/meson-sm1-khadas-vim3l-u-boot.dtsi +1 -0
index f66eca14b1..a591c0c9f2 100644
@@ -4,4 +4,5 @@
  * Author: Neil Armstrong <[email protected]>
  */
 
+#include "meson-sm1-u-boot.dtsi"
 #include "meson-khadas-vim3-u-boot.dtsi"
arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi +1 -1
index 2a8f0545b1..c431988075 100644
@@ -4,7 +4,7 @@
  * Author: Neil Armstrong <[email protected]>
  */
 
-#include "meson-g12-common-u-boot.dtsi"
+#include "meson-sm1-u-boot.dtsi"
 
 &ethmac {
 	snps,reset-gpio = <&gpio GPIOZ_15 (GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN)>;
arch/arm/dts/meson-sm1-sei610-u-boot.dtsi +1 -1
index 236f2468dc..8ebc1caa4a 100644
@@ -4,4 +4,4 @@
  * Author: Neil Armstrong <[email protected]>
  */
 
-#include "meson-g12-common-u-boot.dtsi"
+#include "meson-sm1-u-boot.dtsi"
arch/arm/dts/meson-sm1-u-boot.dtsi new file +20 -0
new file mode 100644
index 0000000000..e05d4c369a
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2020 BayLibre, SAS.
+ * Author: Neil Armstrong <[email protected]>
+ */
+
+#include "meson-g12-common-u-boot.dtsi"
+
+&sd_emmc_a {
+	compatible = "amlogic,meson-sm1-mmc";
+};
+
+&sd_emmc_b {
+	compatible = "amlogic,meson-sm1-mmc";
+};
+
+&sd_emmc_c {
+	compatible = "amlogic,meson-sm1-mmc";
+};
+
Signature · 1 line
2.25.1
#10 lore raw

cover mmc: meson-gx: fix mmc & scard failure on SM1 SoCs

In reply to Neil Armstrong

Dear Neil,

Quoted 5 lines · Neil Armstrong

Amlogic SM1 SoCs doesn't handle very well high clocks from the DIV2 input Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher frequencies via the first input from a composite clock.

Here 26MHz corresponds to MMC_HS clock speed.

When i have checked, it's working with 52MHz.

mmc1(part 0) is current device
Odroid N2> mmcinfo
Device: mmc@ffe07000
Manufacturer ID: 15
OEM: 100
Name: BJTD4
Bus Speed: 52000000
Mode: MMC High Speed (52MHz)
Rd Block Len: 512
MMC version 5.1
High Capacity: Yes
Capacity: 29.1 GiB
Bus Width: 8-bit
Erase Group Size: 512 KiB
HC WP Group Size: 8 MiB
User Capacity: 29.1 GiB WRREL
Boot Capacity: 4 MiB ENH
RPMB Capacity: 4 MiB ENH

Device: sd@ffe05000
Manufacturer ID: 3
OEM: 5344
Name: SB16G
Bus Speed: 50000000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 14.8 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
Odroid N2> ums 0 mmc 0

If you can wait for more time, i can fix it.
I think that it's better than applying this patch.
But i don't know which boards are SM1 SoC..(Odroid-c4 and VIM3L?)

Best Regards,
Jaehoon Chung

Quoted 24 lines

We also add a u-boot only sm1 compatible to distinguish the controller in a new meson-sm1-u-boot.dtsi and reworks the other -u-boot.dtsi to use this for SM1 based boards.

Finally a TOFIX is added to precise the clock management should use the clock controller instead of local management with fixed clock rates.

Neil Armstrong (3):
mmc: meson-gx: move arch header to local header
mmc: meson-gx: limit max frequency on SM1 SoCs
ARM: dts: meson-sm1: add u-boot specific MMC controller compatible

 .../meson-g12b-a311d-khadas-vim3-u-boot.dtsi  |  1 +
 arch/arm/dts/meson-khadas-vim3-u-boot.dtsi    |  2 --
 .../dts/meson-sm1-khadas-vim3l-u-boot.dtsi    |  1 +
 arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi  |  2 +-
 arch/arm/dts/meson-sm1-sei610-u-boot.dtsi     |  2 +-
 arch/arm/dts/meson-sm1-u-boot.dtsi            | 20 +++++++++++++
 drivers/mmc/meson_gx_mmc.c                    | 28 ++++++++++++++++---
 .../sd_emmc.h => drivers/mmc/meson_gx_mmc.h   | 10 ++++---
 8 files changed, 54 insertions(+), 12 deletions(-)
 create mode 100644 arch/arm/dts/meson-sm1-u-boot.dtsi
 rename arch/arm/include/asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h (95%)