Skip to contentSkip to conversation

mmc: meson-gx: fix mmc & sdcard failur on SM1 SoCs

PATCH New Jaehoon Chung 3 participants 6 messages Nov 10, 2020 – Nov 12, 2020 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20201110232156epcas1p11a12c40acfb7f04ad864f001c0e4ea77@epcas1p1.samsung.com

#1 lore raw

v2 cover mmc: meson-gx: fix mmc & sdcard failur on SM1 SoCs

Amlogic SM1 SoCs doesn't work over 50MHz. When phase sets to 270', it's working fine over 50MHz on Amlogic SM1 SoCs.

To use a proper phase value adds an u-boot only sm1 compatible.

In future, it needs to find what value is a proper about each SoCs.

According to Neil's suggestion, applied code based on below patch.
https://patchwork.ozlabs.org/project/uboot/patch/20201109031233.25320-1-jh80.chung at samsung.com

Tested on Odroid-C4/N2, VIM3.

Changelog v2:
- Rewrote "[2/3] mmc: meson-gx: limit max frequency on SM1 SoCs"
- Applied "mmc: meson_gx_mmc: change a clock phase to stable value"
- Add Jaehoon's Signed-off tag

Neil Armstrong (3):
mmc: meson-gx: move arch header to local header
mmc: meson-gx: change clock phase value 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                    | 29 +++++++++++++++----
 .../sd_emmc.h => drivers/mmc/meson_gx_mmc.h   | 10 ++++---
 8 files changed, 54 insertions(+), 13 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.29.0
#2 lore raw

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

From: Neil Armstrong <[email protected]>

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                                 | 2 +-
 .../asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h | 7 ++-----
 2 files changed, 3 insertions(+), 6 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 719dd1e5e570..eedebb317b5f 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.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 1e9f8cf498b4..b4544b55628f 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.29.0
#3 lore raw

PATCH v2 2/3 mmc: meson-gx: change clock phase value on SM1 SoCs

In reply to Jaehoon Chung

From: Neil Armstrong <[email protected]>

Amlogic SM1 SoCs doesn't work over 50MHz. When phase sets to 270', it's working fine over 50MHz on Amlogic SM1 SoCs.
Since Other Amlogic SoCs doens't report an issue, phase value is using to 180' by default.

To distinguish which value is used adds an u-boot only sm1 compatible.

In future, it needs to find what value is a proper about each SoCs.

---
 drivers/mmc/meson_gx_mmc.c | 27 +++++++++++++++++++++++----
 drivers/mmc/meson_gx_mmc.h |  5 +++++
 2 files changed, 28 insertions(+), 4 deletions(-)
drivers/mmc/meson_gx_mmc.c +23 -4
index eedebb317b5f..a5e9ac5637b9 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;
@@ -52,8 +62,16 @@ static void meson_mmc_config_clock(struct mmc *mmc)
 	}
 	clk_div = DIV_ROUND_UP(clk, mmc->clock);
 
-	/* 180 phase core clock */
-	meson_mmc_clk |= CLK_CO_PHASE_180;
+	/*
+	 * SM1 SoCs doesn't work fine over 50MHz with CLK_CO_PHASE_180
+	 * If CLK_CO_PHASE_270 is used, it's more stable than other.
+	 * Other SoCs use CLK_CO_PHASE_180 by default.
+	 * It needs to find what is a proper value about each SoCs.
+	 */
+	if (meson_gx_mmc_is_compatible(mmc->dev, MMC_COMPATIBLE_SM1))
+		meson_mmc_clk |= CLK_CO_PHASE_270;
+	else
+		meson_mmc_clk |= CLK_CO_PHASE_180;
 
 	/* 180 phase tx clock */
 	meson_mmc_clk |= CLK_TX_PHASE_000;
@@ -308,8 +326,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 b4544b55628f..92aec5329f6e 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.29.0
#4 lore raw

PATCH v2 2/3 mmc: meson-gx: change clock phase value on SM1 SoCs

Hi Jaehoon,

Quoted 8 lines · Jaehoon Chung

From: Neil Armstrong <[email protected]>

Amlogic SM1 SoCs doesn't work over 50MHz. When phase sets to 270', it's working fine over 50MHz on Amlogic SM1 SoCs.
Since Other Amlogic SoCs doens't report an issue, phase value is using to 180' by default.

Quoted 7 lines

To distinguish which value is used adds an u-boot only sm1 compatible.

In future, it needs to find what value is a proper about each SoCs.

---

Thanks for this patch series.
I have tested this on Odroid N2 and c4 eMMC module so Please add my for this series,

Quoted 82 lines
 drivers/mmc/meson_gx_mmc.c | 27 +++++++++++++++++++++++----
 drivers/mmc/meson_gx_mmc.h |  5 +++++
 2 files changed, 28 insertions(+), 4 deletions(-)
drivers/mmc/meson_gx_mmc.c +23 -4
index eedebb317b5f..a5e9ac5637b9 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;
@@ -52,8 +62,16 @@ static void meson_mmc_config_clock(struct mmc *mmc)
        }
        clk_div = DIV_ROUND_UP(clk, mmc->clock);
 
-       /* 180 phase core clock */
-       meson_mmc_clk |= CLK_CO_PHASE_180;
+       /*
+        * SM1 SoCs doesn't work fine over 50MHz with CLK_CO_PHASE_180
+        * If CLK_CO_PHASE_270 is used, it's more stable than other.
+        * Other SoCs use CLK_CO_PHASE_180 by default.
+        * It needs to find what is a proper value about each SoCs.
+        */
+       if (meson_gx_mmc_is_compatible(mmc->dev, MMC_COMPATIBLE_SM1))
+               meson_mmc_clk |= CLK_CO_PHASE_270;
+       else
+               meson_mmc_clk |= CLK_CO_PHASE_180;
 
        /* 180 phase tx clock */
        meson_mmc_clk |= CLK_TX_PHASE_000;
@@ -308,8 +326,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 -1
index b4544b55628f..92aec5329f6e 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
--

2.29.0

#5 lore raw

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

In reply to Jaehoon Chung

From: Neil Armstrong <[email protected]>

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 f66eca14b12c..489efa150a6e 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 b5da4fdfc3ee..81fd5be3783b 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 f66eca14b12c..a591c0c9f230 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 2a8f0545b1a3..c4319880759f 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 236f2468dc20..8ebc1caa4a79 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 000000000000..e05d4c369adc
@@ -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.29.0
#6 lore raw

v2 cover mmc: meson-gx: fix mmc & sdcard failur on SM1 SoCs

In reply to Jaehoon Chung
Quoted 22 lines · Jaehoon Chung

Amlogic SM1 SoCs doesn't work over 50MHz. When phase sets to 270', it's working fine over 50MHz on Amlogic SM1 SoCs.

To use a proper phase value adds an u-boot only sm1 compatible.

In future, it needs to find what value is a proper about each SoCs.

According to Neil's suggestion, applied code based on below patch.
https://patchwork.ozlabs.org/project/uboot/patch/20201109031233.25320-1-jh80.chung at samsung.com

Tested on Odroid-C4/N2, VIM3.

Changelog v2:
- Rewrote "[2/3] mmc: meson-gx: limit max frequency on SM1 SoCs"
- Applied "mmc: meson_gx_mmc: change a clock phase to stable value"
- Add Jaehoon's Signed-off tag

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

Quoted 12 lines
 .../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                    | 29 +++++++++++++++----
 .../sd_emmc.h => drivers/mmc/meson_gx_mmc.h   | 10 ++++---
 8 files changed, 54 insertions(+), 13 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%)

Thanks !

Applying to u-boot-amlogic