Skip to contentSkip to conversation

Fix sd card support for RK3576

PATCH Superseded Shawn Lin 3 participants 8 messages Jan 13 – Jan 14

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Shawn Lin

author
#0 lore raw

v2 cover Fix sd card support for RK3576

SD card hot-plug support for RK3576 is totally broken. This is because sd slot should try to use slot-gpio(cd-gpios) instead of function IO for supporting runtime PM. In order to support slot-gpio method, we should disable jtag switching for RK3576.

But the rockchip_grf_init fails to handle this because it couldn't handle multiple grf nodes. In this case, iocgrf is in behind of sysgrf, so only sysgrf is handled. We should scan all possible nodes.

Moreover, the offset is wrong as well. Per the TRM, the address of TOP_IOC_IOC_MISC_CON is 0x260440F0, which means the offset if 0x40F0 instead of 0x040F

This series fixes this mess but only adds slot-gpio support for RK3576-EVB1. Other boards are also missing slot-gpio support, but folks are all cced for checking the boards they are using.

Please review and test

Changes in v2:
- use for_each_matching_node_and_match(Heiko)
- add fixes tag

Shawn Lin (3):
soc: rockchip: grf: Fix wrong RK3576_IOCGRF_MISC_CON definition
soc: rockchip: grf: Support multiple grf to be handled
arm64: dts: rockchip: Add cd-gpios for sdmmc of RK3576 EVB1

 arch/arm64/boot/dts/rockchip/rk3576-evb1-v10.dts |  1 +
 drivers/soc/rockchip/grf.c                       | 54 ++++++++++++------------
 2 files changed, 28 insertions(+), 27 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 1/3 soc: rockchip: grf: Fix wrong RK3576_IOCGRF_MISC_CON definition

RK3576_IOCGRF_MISC_CON is IOC_GRF + 0x40F0, fix it.

Fixes e1aaecacfa13 ("soc: rockchip: grf: Add rk3576 default GRF values")
Cc Detlev Casanova <[email protected]>

---

Changes in v2: None

 drivers/soc/rockchip/grf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/rockchip/grf.c +1 -1
index 27bfa09..8974d1c 100644
@@ -146,7 +146,7 @@ static const struct rockchip_grf_info rk3576_sysgrf __initconst = {
 	.num_values = ARRAY_SIZE(rk3576_defaults_sys_grf),
 };
 
-#define RK3576_IOCGRF_MISC_CON		0x04F0
+#define RK3576_IOCGRF_MISC_CON		0x40F0
 
 static const struct rockchip_grf_value rk3576_defaults_ioc_grf[] __initconst = {
 	{ "jtag switching", RK3576_IOCGRF_MISC_CON, FIELD_PREP_WM16_CONST(BIT(1), 0) },
Signature · 7 lines
2.7.4


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author
#2 lore raw

PATCH v2 2/3 soc: rockchip: grf: Support multiple grf to be handled

In reply to Shawn Lin

Currently, only the first matched node will be handled. This leads to jtag switching broken for RK3576, as rk3576-sys-grf is found before rk3576-ioc-grf. Change the code to scan all the possible nodes to fix the problem.

Fixes e1aaecacfa13 ("soc: rockchip: grf: Add rk3576 default GRF values")
Cc Detlev Casanova <[email protected]>

---

Changes in v2:
- use for_each_matching_node_and_match(Heiko)

 drivers/soc/rockchip/grf.c | 54 +++++++++++++++++++++++-----------------------
 1 file changed, 27 insertions(+), 27 deletions(-)
drivers/soc/rockchip/grf.c +27 -27
index 8974d1c..9b36390 100644
@@ -217,34 +217,34 @@ static int __init rockchip_grf_init(void)
 	struct regmap *grf;
 	int ret, i;
 
-	np = of_find_matching_node_and_match(NULL, rockchip_grf_dt_match,
-					     &match);
-	if (!np)
-		return -ENODEV;
-	if (!match || !match->data) {
-		pr_err("%s: missing grf data\n", __func__);
+	for_each_matching_node_and_match(np, rockchip_grf_dt_match, &match) {
+		if (!of_device_is_available(np))
+			continue;
+		if (!match || !match->data) {
+			pr_err("%s: missing grf data\n", __func__);
+			of_node_put(np);
+			return -EINVAL;
+		}
+
+		grf_info = match->data;
+
+		grf = syscon_node_to_regmap(np);
 		of_node_put(np);
-		return -EINVAL;
-	}
-
-	grf_info = match->data;
-
-	grf = syscon_node_to_regmap(np);
-	of_node_put(np);
-	if (IS_ERR(grf)) {
-		pr_err("%s: could not get grf syscon\n", __func__);
-		return PTR_ERR(grf);
-	}
-
-	for (i = 0; i < grf_info->num_values; i++) {
-		const struct rockchip_grf_value *val = &grf_info->values[i];
-
-		pr_debug("%s: adjusting %s in %#6x to %#10x\n", __func__,
-			val->desc, val->reg, val->val);
-		ret = regmap_write(grf, val->reg, val->val);
-		if (ret < 0)
-			pr_err("%s: write to %#6x failed with %d\n",
-			       __func__, val->reg, ret);
+		if (IS_ERR(grf)) {
+			pr_err("%s: could not get grf syscon\n", __func__);
+			return PTR_ERR(grf);
+		}
+
+		for (i = 0; i < grf_info->num_values; i++) {
+			const struct rockchip_grf_value *val = &grf_info->values[i];
+
+			pr_debug("%s: adjusting %s in %#6x to %#10x\n", __func__,
+				val->desc, val->reg, val->val);
+			ret = regmap_write(grf, val->reg, val->val);
+			if (ret < 0)
+				pr_err("%s: write to %#6x failed with %d\n",
+					__func__, val->reg, ret);
+		}
 	}
 
 	return 0;
Signature · 1 line
2.7.4
maintainer
#3 lore raw

Re: [PATCH v2 2/3] soc: rockchip: grf: Support multiple grf to be handled

Hi Shawn,

Am Dienstag, 13. Januar 2026, 02:18:24 Mitteleuropäische Normalzeit schrieb Shawn Lin:

Quoted 33 lines

Currently, only the first matched node will be handled. This leads to jtag switching broken for RK3576, as rk3576-sys-grf is found before rk3576-ioc-grf. Change the code to scan all the possible nodes to fix the problem.

Fixes e1aaecacfa13 ("soc: rockchip: grf: Add rk3576 default GRF values")
Cc Detlev Casanova <[email protected]>

---

Changes in v2:
- use for_each_matching_node_and_match(Heiko)

 drivers/soc/rockchip/grf.c | 54 +++++++++++++++++++++++-----------------------
 1 file changed, 27 insertions(+), 27 deletions(-)
drivers/soc/rockchip/grf.c +3 -6
index 8974d1c..9b36390 100644
@@ -217,34 +217,34 @@ static int __init rockchip_grf_init(void)
 	struct regmap *grf;
 	int ret, i;
 
-	np = of_find_matching_node_and_match(NULL, rockchip_grf_dt_match,
-					     &match);
-	if (!np)
-		return -ENODEV;
-	if (!match || !match->data) {
-		pr_err("%s: missing grf data\n", __func__);
+	for_each_matching_node_and_match(np, rockchip_grf_dt_match, &match) {
+		if (!of_device_is_available(np))
+			continue;

drivers/soc/rockchip/grf.c static int __init rockchip_grf_init(void) · line 232

Quoted 10 lines
drivers/soc/rockchip/grf.c +9 -0
+		if (!match || !match->data) {
+			pr_err("%s: missing grf data\n", __func__);
+			of_node_put(np);
+			return -EINVAL;
+		}
+
+		grf_info = match->data;
+
+		grf = syscon_node_to_regmap(np);
 		of_node_put(np);

This of_node_put can go away I think.

for_each_matching_node_and_match iterates over the nodes via
of_find_matching_node_and_match(dn, matches, match) [0]

and of_find_matching_node_and_match() will of_node_put() the from node [1]

Heiko

[0] https://elixir.bootlin.com/linux/v6.18.4/source/include/linux/of.h#L1469
[1] https://elixir.bootlin.com/linux/v6.18.4/source/drivers/of/base.c#L1147

Quoted 40 lines
drivers/soc/rockchip/grf.c +15 -21
-		return -EINVAL;
-	}
-
-	grf_info = match->data;
-
-	grf = syscon_node_to_regmap(np);
-	of_node_put(np);
-	if (IS_ERR(grf)) {
-		pr_err("%s: could not get grf syscon\n", __func__);
-		return PTR_ERR(grf);
-	}
-
-	for (i = 0; i < grf_info->num_values; i++) {
-		const struct rockchip_grf_value *val = &grf_info->values[i];
-
-		pr_debug("%s: adjusting %s in %#6x to %#10x\n", __func__,
-			val->desc, val->reg, val->val);
-		ret = regmap_write(grf, val->reg, val->val);
-		if (ret < 0)
-			pr_err("%s: write to %#6x failed with %d\n",
-			       __func__, val->reg, ret);
+		if (IS_ERR(grf)) {
+			pr_err("%s: could not get grf syscon\n", __func__);
+			return PTR_ERR(grf);
+		}
+
+		for (i = 0; i < grf_info->num_values; i++) {
+			const struct rockchip_grf_value *val = &grf_info->values[i];
+
+			pr_debug("%s: adjusting %s in %#6x to %#10x\n", __func__,
+				val->desc, val->reg, val->val);
+			ret = regmap_write(grf, val->reg, val->val);
+			if (ret < 0)
+				pr_err("%s: write to %#6x failed with %d\n",
+					__func__, val->reg, ret);
+		}
 	}
 
 	return 0;
author
#4 lore raw

Re: [PATCH v2 2/3] soc: rockchip: grf: Support multiple grf to be handled

Quoted 49 lines · Heiko Stübner

Hi Shawn,

Am Dienstag, 13. Januar 2026, 02:18:24 Mitteleuropäische Normalzeit schrieb Shawn Lin:

Quoted 33 lines

Currently, only the first matched node will be handled. This leads to jtag switching broken for RK3576, as rk3576-sys-grf is found before rk3576-ioc-grf. Change the code to scan all the possible nodes to fix the problem.

Fixes e1aaecacfa13 ("soc: rockchip: grf: Add rk3576 default GRF values")
Cc Detlev Casanova <[email protected]>

---

Changes in v2:
- use for_each_matching_node_and_match(Heiko)

  drivers/soc/rockchip/grf.c | 54 +++++++++++++++++++++++-----------------------
  1 file changed, 27 insertions(+), 27 deletions(-)
drivers/soc/rockchip/grf.c +3 -6
index 8974d1c..9b36390 100644
@@ -217,34 +217,34 @@ static int __init rockchip_grf_init(void)
  	struct regmap *grf;
  	int ret, i;
 
-	np = of_find_matching_node_and_match(NULL, rockchip_grf_dt_match,
-					     &match);
-	if (!np)
-		return -ENODEV;
-	if (!match || !match->data) {
-		pr_err("%s: missing grf data\n", __func__);
+	for_each_matching_node_and_match(np, rockchip_grf_dt_match, &match) {
+		if (!of_device_is_available(np))
+			continue;

drivers/soc/rockchip/grf.c static int __init rockchip_grf_init(void) · line 232

Quoted 10 lines
drivers/soc/rockchip/grf.c +9 -0
+		if (!match || !match->data) {
+			pr_err("%s: missing grf data\n", __func__);
+			of_node_put(np);
+			return -EINVAL;
+		}
+
+		grf_info = match->data;
+
+		grf = syscon_node_to_regmap(np);
  		of_node_put(np);

This of_node_put can go away I think.

Quoted 6 lines

for_each_matching_node_and_match iterates over the nodes via
of_find_matching_node_and_match(dn, matches, match) [0]

and of_find_matching_node_and_match() will of_node_put() the from node [1]

Oops, will fix.

Thanks.

Quoted 43 lines

Heiko

[0] https://elixir.bootlin.com/linux/v6.18.4/source/include/linux/of.h#L1469
[1] https://elixir.bootlin.com/linux/v6.18.4/source/drivers/of/base.c#L1147

Quoted 38 lines
drivers/soc/rockchip/grf.c +15 -21
-		return -EINVAL;
-	}
-
-	grf_info = match->data;
-
-	grf = syscon_node_to_regmap(np);
-	of_node_put(np);
-	if (IS_ERR(grf)) {
-		pr_err("%s: could not get grf syscon\n", __func__);
-		return PTR_ERR(grf);
-	}
-
-	for (i = 0; i < grf_info->num_values; i++) {
-		const struct rockchip_grf_value *val = &grf_info->values[i];
-
-		pr_debug("%s: adjusting %s in %#6x to %#10x\n", __func__,
-			val->desc, val->reg, val->val);
-		ret = regmap_write(grf, val->reg, val->val);
-		if (ret < 0)
-			pr_err("%s: write to %#6x failed with %d\n",
-			       __func__, val->reg, ret);
+		if (IS_ERR(grf)) {
+			pr_err("%s: could not get grf syscon\n", __func__);
+			return PTR_ERR(grf);
+		}
+
+		for (i = 0; i < grf_info->num_values; i++) {
+			const struct rockchip_grf_value *val = &grf_info->values[i];
+
+			pr_debug("%s: adjusting %s in %#6x to %#10x\n", __func__,
+				val->desc, val->reg, val->val);
+			ret = regmap_write(grf, val->reg, val->val);
+			if (ret < 0)
+				pr_err("%s: write to %#6x failed with %d\n",
+					__func__, val->reg, ret);
+		}
  	}
 
Quoted 11 lines

drivers/soc/rockchip/grf.c static int __init rockchip_grf_init(void) · line 250

Quoted 2 lines
drivers/soc/rockchip/grf.c +0 -0
  	return 0;

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author
#5 lore raw

PATCH v2 3/3 arm64: dts: rockchip: Add cd-gpios for sdmmc of RK3576 EVB1

In reply to Shawn Lin

Without cd-gpios, the sdmmc would not be detected, because during runtime PM, the clock is gated which prevents the irq from issuing.

Fixes f135a1a07352 ("arm64: dts: rockchip: Add rk3576 evb1 board")

---

Changes in v2:
- add fixes tag

 arch/arm64/boot/dts/rockchip/rk3576-evb1-v10.dts | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/rockchip/rk3576-evb1-v10.dts +1 -0
index 0789733..b583cec 100644
@@ -958,6 +958,7 @@
 	bus-width = <4>;
 	cap-mmc-highspeed;
 	cap-sd-highspeed;
+	cd-gpios = <&gpio0 RK_PA7 GPIO_ACTIVE_LOW>;
 	disable-wp;
 	max-frequency = <200000000>;
 	no-sdio;
Signature · 1 line
2.7.4
Tested-by on the v2 series
#6 lore raw
In reply to Shawn Lin

Hi Shawn,

Quoted 6 lines · Shawn Lin

This series fixes this mess but only adds slot-gpio support for RK3576-EVB1. Other boards are also missing slot-gpio support, but folks are all cced for checking the boards they are using.

Please review and test

I tested this series on the FriendlyElec NanoPi R76S. With the addition of 'cd-gpios = <&gpio0 RK_PA7 GPIO_ACTIVE_LOW>;' in the board DTS, the µSD hot-plug now works correctly.

However, even with this fix, the NanoPi R76S still suffers from the constant 400kHz retuning loop when runtime PM is enabled. I will send a v2 of my driver quirk to address this board-specific instability.

Link to v1: https://lore.kernel.org/all/[email protected]/T/#t

author
#7 lore raw
Quoted 8 lines · Marco Schirrmeister

Hi Shawn,

Quoted 5 lines · Shawn Lin

This series fixes this mess but only adds slot-gpio support for RK3576-EVB1. Other boards are also missing slot-gpio support, but folks are all cced for checking the boards they are using.

Quoted 6 lines
Quoted 1 line

Please review and test

I tested this series on the FriendlyElec NanoPi R76S. With the addition of 'cd-gpios = <&gpio0 RK_PA7 GPIO_ACTIVE_LOW>;' in the board DTS, the µSD hot-plug now works correctly.

Thanks for testing.

Quoted 4 lines

However, even with this fix, the NanoPi R76S still suffers from the constant 400kHz retuning loop when runtime PM is enabled. I will send a v2 of my driver quirk to address this board-specific instability.

When talking about board-specific instability of SD support, the intuitive reaction is bus more or frequency related. I never came across this kind of problem which caused by runtime PM support. That being said, there is potential unveiled problems for your boards. I will comment your v2 to see if we could sort them out.

Quoted 4 lines

Link to v1: https://lore.kernel.org/all/[email protected]/T/#t

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip