diff mbox series

[v6] arm64: dts: rockchip: Fix SD card init on rk3399-nanopi4

Message ID E5A1A1E7-449F-4161-87B9-7A6CA0CAA42C@kohlschutter.com (mailing list archive)
State New, archived
Headers show
Series [v6] arm64: dts: rockchip: Fix SD card init on rk3399-nanopi4 | expand

Commit Message

Christian Kohlschütter July 18, 2022, 12:04 p.m. UTC
mmc/SD-card initialization may fail on NanoPi R4S with
"mmc1: problem reading SD Status register" /
"mmc1: error -110 whilst initialising SD card"
either on cold boot or after a reboot.

Moreover, the system would also sometimes hang upon reboot.

This is caused by vcc3v0-sd's "regulator-always-on", which triggers
an erroneous double-initialization of the regulator. This causes
voltage fluctuations that can, depending on timing, prevent the
SD card from initializing correctly.

Adding some liberal delay via "off-on-delay-us" is ineffective since
that codepath is skipped as long "regulator-always-on" is set.

Removing "regulator-always-on" alone is not sufficient because that
would allow the system to set GPIO0_A1 to LOW upon reboot, which may
cause the system to hang.

In order to allow the system to set GPIO0_A1 to HIGH upon initialization
but prevent it from changing it back to LOW, this patch increases the
usage count of vcc3v0-sd from 1 to 2, whereas the additional reference,
"vcc1v8_s3", is marked as "always-on", causing permanent retention.

Signed-off-by: Christian Kohlschütter <christian@kohlschutter.com>
---
arch/arm64/boot/dts/rockchip/rk3399-nanopi4.dtsi | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Christian Kohlschütter July 18, 2022, 12:05 p.m. UTC | #1
> Am 18.07.2022 um 14:04 schrieb Christian Kohlschütter <christian@kohlschutter.com>:
> 
> mmc/SD-card initialization may fail on NanoPi R4S with
> "mmc1: problem reading SD Status register" /
> "mmc1: error -110 whilst initialising SD card"
> either on cold boot or after a reboot.
...
Walking back on my claim in the commit message that no further patches are needed for the u-boot integration to work.
Other than that, the actual patch is unchanged.
Christian Kohlschütter July 18, 2022, 9:04 p.m. UTC | #2
Am 18.07.2022 um 14:05 schrieb Christian Kohlschütter <christian@kohlschutter.com>:
> 
>> Am 18.07.2022 um 14:04 schrieb Christian Kohlschütter <christian@kohlschutter.com>:
>> 
>> mmc/SD-card initialization may fail on NanoPi R4S with
>> "mmc1: problem reading SD Status register" /
>> "mmc1: error -110 whilst initialising SD card"
>> either on cold boot or after a reboot.
> ...
> Walking back on my claim in the commit message that no further patches are needed for the u-boot integration to work.
> Other than that, the actual patch is unchanged.

I can no longer verify that the v6 patch actually increases use_count to 2.

At this point, I don't have a purely device tree-based fix that works reliably, therefore necessitating the code changes in regulator/core.c.
If anyone of you knows a way to reliably increase vcc3v0_sd's use_count ("cat /sys/kernel/debug/regulator/vcc3v0_sd/use_count") to at least 2, then we can remove the regulator-always-on statement.
diff mbox series

Patch

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-nanopi4.dtsi b/arch/arm64/boot/dts/rockchip/rk3399-nanopi4.dtsi
index 8c0ff6c96e03..38507a6e3046 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-nanopi4.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399-nanopi4.dtsi
@@ -61,7 +61,17 @@  vcc1v8_s3: vcc1v8-s3 {
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-name = "vcc1v8_s3";
-		vin-supply = <&vcc_1v8>;
+
+		/*
+		 * Workaround to skip setting gpio0 RK_PA1 to LOW upon reboot,
+		 * which may freeze the system.
+		 *
+		 * Adding a reference to vcc3v0_sd increases its num_users
+		 * count to 2, preventing deactivation since this regulator is
+		 * marked "always-on".
+		 */
+		// vin-supply = <&vcc_1v8>; // actual supply
+		vin-supply = <&vcc3v0_sd>;
	};

	vcc3v0_sd: vcc3v0-sd {
@@ -70,7 +80,6 @@  vcc3v0_sd: vcc3v0-sd {
		gpio = <&gpio0 RK_PA1 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&sdmmc0_pwr_h>;
-		regulator-always-on;
		regulator-min-microvolt = <3000000>;
		regulator-max-microvolt = <3000000>;
		regulator-name = "vcc3v0_sd";