Skip to contentSkip to conversation

mmc: k1: do not require max-frequency in the device tree

RFC PATCH In review Hung-Chun Tseng 3 participants 5 messages Oct 13 – Oct 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover mmc: k1: do not require max-frequency in the device tree

The K1 SDHCI driver sets the io clock to cfg.f_max, which is only filled in from a "max-frequency" property, so each K1 board carries max-frequency = <204800000> for the SD and eMMC nodes in its -u-boot.dtsi. E Shattow pointed out that this property is unlikely to be accepted in the upstream device tree and looks like a driver issue [1]. The Linux driver indeed does not need it: it reports the current io clock rate as the maximum.

Patch 1 makes the U-Boot driver do the same when max-frequency is absent. Patch 2 drops the property from the BPI-F3 and MusePi Pro overlays.

This is an RFC because I could only build-test it: spacemit_k1_defconfig builds (SPL and u-boot.itb), and the resulting BPI-F3 and MusePi Pro DTBs no longer carry max-frequency on the MMC nodes. I have not run it on hardware. The open question is what rate the io clock runs at when SPL and U-Boot probe the controllers: if the BootROM or SPL leaves it well below 204.8 MHz, SD and eMMC will still work but run slower, and the driver may need a default rate instead of the current one. A test on a BPI-F3 or MusePi Pro, or a pointer to the expected clock setup, would be very welcome.

[1] https://lore.kernel.org/u-boot/[email protected]/

Hung-Chun Tseng (2):
mmc: k1: use the io clock rate when max-frequency is absent
riscv: dts: k1: drop max-frequency from the SD and eMMC nodes

 arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi |  2 --
 arch/riscv/dts/k1-musepi-pro-u-boot.dtsi  |  2 --
 drivers/mmc/spacemit_sdhci.c              | 24 +++++++++++++++++++----
 3 files changed, 20 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/2 mmc: k1: use the io clock rate when max-frequency is absent

The driver sets the io clock to cfg.f_max, which mmc_of_parse() only fills in from the "max-frequency" property. The compatible has no driver data, so without that property f_max is 0 and probe asks the clock framework for a rate of 0. Every K1 board therefore needs a max-frequency override in its -u-boot.dtsi, and the property cannot go into the upstream device tree because the Linux driver does not need
it: sdhci-of-k1.c reports clk_get_rate() of the io clock as the maximum.

Do the same here. Keep setting the rate when max-frequency is present, and otherwise use the rate the io clock already runs at.

---
 drivers/mmc/spacemit_sdhci.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/mmc/spacemit_sdhci.c +20 -4
index f5578f38b..9b22ae48a 100644
@@ -606,10 +606,26 @@ static int spacemit_sdhci_probe(struct udevice *dev)
 		goto err_reset;
 	}
 
-	ret = clk_set_rate(&clk, plat->cfg.f_max);
-	if (ret) {
-		log_err("Failed to set io clk: %d\n", ret);
-		goto err_reset;
+	/*
+	 * Without a "max-frequency" property, use the io clock at the rate
+	 * it already runs at, as the Linux driver does, rather than asking
+	 * for a rate of 0.
+	 */
+	if (plat->cfg.f_max) {
+		ret = clk_set_rate(&clk, plat->cfg.f_max);
+		if (ret) {
+			log_err("Failed to set io clk: %d\n", ret);
+			goto err_reset;
+		}
+	} else {
+		ulong rate = clk_get_rate(&clk);
+
+		if (!rate || IS_ERR_VALUE(rate)) {
+			log_err("Failed to get io clk rate: %ld\n", (long)rate);
+			ret = rate ? (int)rate : -EINVAL;
+			goto err_reset;
+		}
+		plat->cfg.f_max = rate;
 	}
 
 	/* Set quirks */
Signature · 1 line
2.43.0
#2 lore raw

Re: [RFC PATCH 1/2] mmc: k1: use the io clock rate when max-frequency is absent

Quoted 9 lines · Hung-Chun Tseng

The driver sets the io clock to cfg.f_max, which mmc_of_parse() only fills in from the "max-frequency" property. The compatible has no driver data, so without that property f_max is 0 and probe asks the clock framework for a rate of 0. Every K1 board therefore needs a max-frequency override in its -u-boot.dtsi, and the property cannot go into the upstream device tree because the Linux driver does not need
it: sdhci-of-k1.c reports clk_get_rate() of the io clock as the maximum.

Quoted 4 lines

Do the same here. Keep setting the rate when max-frequency is present, and otherwise use the rate the io clock already runs at.

Similar changes are already under review in Dave's patch. I'd suggest taking a look at it before proceeding:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

#3 lore raw

RFC PATCH 2/2 riscv: dts: k1: drop max-frequency from the SD and eMMC nodes

In reply to Hung-Chun Tseng

The K1 SDHCI driver now falls back to the io clock rate when max-frequency is absent, so the BPI-F3 and MusePi Pro overlays no longer need to carry it.

---
 arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi | 2 --
 arch/riscv/dts/k1-musepi-pro-u-boot.dtsi  | 2 --
 2 files changed, 4 deletions(-)
arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi +0 -2
index 3077cdee5..fbbf1fb81 100644
@@ -89,12 +89,10 @@
 
 &emmc {
 	bootph-pre-ram;
-	max-frequency = <204800000>;
 };
 
 &sdhci0 {
 	bootph-pre-ram;
-	max-frequency = <204800000>;
 };
 
 &binman {
arch/riscv/dts/k1-musepi-pro-u-boot.dtsi +0 -2
index d6299c969..cb0560c14 100644
@@ -126,13 +126,11 @@
 
 &emmc {
 	bootph-pre-ram;
-	max-frequency = <204800000>;
 };
 
 &sdhci0 {
 	bootph-pre-ram;
 	cd-gpios = <&gpio K1_GPIO(80) (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
-	max-frequency = <204800000>;
 };
 
 &binman {
Signature · 1 line
2.43.0
maintainer
#4 lore raw
In reply to Hung-Chun Tseng

Hi Hung-Chun,

Quoted 22 lines · Hung-Chun Tseng

The K1 SDHCI driver sets the io clock to cfg.f_max, which is only filled in from a "max-frequency" property, so each K1 board carries max-frequency = <204800000> for the SD and eMMC nodes in its -u-boot.dtsi. E Shattow pointed out that this property is unlikely to be accepted in the upstream device tree and looks like a driver issue [1]. The Linux driver indeed does not need it: it reports the current io clock rate as the maximum.

Patch 1 makes the U-Boot driver do the same when max-frequency is absent. Patch 2 drops the property from the BPI-F3 and MusePi Pro overlays.

This is an RFC because I could only build-test it: spacemit_k1_defconfig builds (SPL and u-boot.itb), and the resulting BPI-F3 and MusePi Pro DTBs no longer carry max-frequency on the MMC nodes. I have not run it on hardware. The open question is what rate the io clock runs at when SPL and U-Boot probe the controllers: if the BootROM or SPL leaves it well below 204.8 MHz, SD and eMMC will still work but run slower, and the driver may need a default rate instead of the current one. A test on a BPI-F3 or MusePi Pro, or a pointer to the expected clock setup, would be very welcome.

Quoted 2 lines

[1] https://lore.kernel.org/u-boot/[email protected]/

Please do not start a new thread, as there is already one discussion, see
https://lore.kernel.org/all/[email protected]/

Quoted 12 lines

Hung-Chun Tseng (2):
mmc: k1: use the io clock rate when max-frequency is absent
riscv: dts: k1: drop max-frequency from the SD and eMMC nodes

 arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi |  2 --
 arch/riscv/dts/k1-musepi-pro-u-boot.dtsi  |  2 --
 drivers/mmc/spacemit_sdhci.c              | 24 +++++++++++++++++++----
 3 files changed, 20 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.0
Signature · 1 line
Yixun Lan (dlan)