From 0dc9c65d3c1840cc0d062a07fb873d94c10b829e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Sat, 9 Nov 2024 19:04:02 +0100 Subject: [PATCH] Fall back to max eMMC clock to fix Kingston eMMC compat with ODROID-N2 (#3665) --- ...x-limit-f_max-to-24-MHz-on-the-first.patch | 81 +++++++++++++++++++ ...001-HACK-mmc-meson-gx-limit-to-24MHz.patch | 26 ------ 2 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 buildroot-external/board/hardkernel/patches/uboot/0001-HACK-mmc-meson-gx-limit-f_max-to-24-MHz-on-the-first.patch delete mode 100644 buildroot-external/board/hardkernel/patches/uboot/0001-HACK-mmc-meson-gx-limit-to-24MHz.patch diff --git a/buildroot-external/board/hardkernel/patches/uboot/0001-HACK-mmc-meson-gx-limit-f_max-to-24-MHz-on-the-first.patch b/buildroot-external/board/hardkernel/patches/uboot/0001-HACK-mmc-meson-gx-limit-f_max-to-24-MHz-on-the-first.patch new file mode 100644 index 00000000000..6ea9730ff97 --- /dev/null +++ b/buildroot-external/board/hardkernel/patches/uboot/0001-HACK-mmc-meson-gx-limit-f_max-to-24-MHz-on-the-first.patch @@ -0,0 +1,81 @@ +From 024796cbf752d2e210341ae8609792803641eb92 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= +Date: Thu, 7 Nov 2024 12:39:02 +0100 +Subject: [PATCH] HACK: mmc: meson-gx: limit f_max to 24 MHz on the first try +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +To initialize some eMMCs cards properly, ODROID N2 needed to have +maximum clock rate limited to 24 MHz. This was working good until ODROID +released eMMC modules with Kingson chips which do not initialize at the +limited frequency at all - instead it seems it's best for the if +no limit is set (which would result in using 52 MHz anyway). + +Instead of hard-limiting the frequency, add a boolean flag that caps the +frequency to the proven 24 MHz, and if mmc_select_mode_and_width fails, +remove this cap and use f_max set to 100 MHz, as limited in upstream +U-Boot. + +Signed-off-by: Jan Čermák +--- + drivers/mmc/meson_gx_mmc.c | 2 ++ + drivers/mmc/mmc.c | 11 +++++++++++ + include/mmc.h | 2 ++ + 3 files changed, 15 insertions(+) + +diff --git a/drivers/mmc/meson_gx_mmc.c b/drivers/mmc/meson_gx_mmc.c +index fcf4f03d1e..715dce3522 100644 +--- a/drivers/mmc/meson_gx_mmc.c ++++ b/drivers/mmc/meson_gx_mmc.c +@@ -283,6 +283,8 @@ static int meson_mmc_probe(struct udevice *dev) + cfg->b_max = 511; /* max 512 - 1 blocks */ + cfg->name = dev->name; + ++ mmc->meson_gx_f_max_hack = true; ++ + mmc->priv = pdata; + upriv->mmc = mmc; + +diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c +index d96db7a0f8..c8dc676612 100644 +--- a/drivers/mmc/mmc.c ++++ b/drivers/mmc/mmc.c +@@ -1652,6 +1652,10 @@ int mmc_set_clock(struct mmc *mmc, uint clock, bool disable) + clock = mmc->cfg->f_min; + } + ++ /* Apply 24 MHz limit that fixes issues with some cards on meson. */ ++ if (mmc->meson_gx_f_max_hack && clock > 24000000) ++ clock = 24000000; ++ + mmc->clock = clock; + mmc->clk_disable = disable; + +@@ -2647,6 +2651,13 @@ static int mmc_startup(struct mmc *mmc) + if (err) + return err; + err = mmc_select_mode_and_width(mmc, mmc->card_caps); ++ if (err && mmc->meson_gx_f_max_hack) { ++ /* Some eMMCs (namely Kingston) do not initialize at limited frequency. */ ++ printf("Card failed to initialize at %d Hz, disabling meson_gx hack.\n", ++ mmc->clock); ++ mmc->meson_gx_f_max_hack = false; ++ err = mmc_select_mode_and_width(mmc, mmc->card_caps); ++ } + } + #endif + if (err) +diff --git a/include/mmc.h b/include/mmc.h +index 1022db3ffa..0ea48c6fd9 100644 +--- a/include/mmc.h ++++ b/include/mmc.h +@@ -739,6 +739,8 @@ struct mmc { + u8 hs400_tuning; + + enum bus_mode user_speed_mode; /* input speed mode from user */ ++ ++ bool meson_gx_f_max_hack; + }; + + #if CONFIG_IS_ENABLED(DM_MMC) diff --git a/buildroot-external/board/hardkernel/patches/uboot/0001-HACK-mmc-meson-gx-limit-to-24MHz.patch b/buildroot-external/board/hardkernel/patches/uboot/0001-HACK-mmc-meson-gx-limit-to-24MHz.patch deleted file mode 100644 index c56843027f5..00000000000 --- a/buildroot-external/board/hardkernel/patches/uboot/0001-HACK-mmc-meson-gx-limit-to-24MHz.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 11f015e13ef0442b6d2bb734954291abde415f73 Mon Sep 17 00:00:00 2001 -From: Neil Armstrong -Date: Mon, 2 Sep 2019 15:42:04 +0200 -Subject: [PATCH] HACK: mmc: meson-gx: limit to 24MHz - -Signed-off-by: Neil Armstrong ---- - drivers/mmc/meson_gx_mmc.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/drivers/mmc/meson_gx_mmc.c b/drivers/mmc/meson_gx_mmc.c -index fcf4f03d1e..6ded4b619b 100644 ---- a/drivers/mmc/meson_gx_mmc.c -+++ b/drivers/mmc/meson_gx_mmc.c -@@ -279,7 +279,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 = SD_EMMC_CLKSRC_24M; - cfg->b_max = 511; /* max 512 - 1 blocks */ - cfg->name = dev->name; - --- -2.43.0 -