Skip to contentSkip to conversation

mfd: syscon: Restore device_node_to_regmap() for non-syscon nodes

PATCH Applied Rob Herring (Arm) 9 participants 10 messages Jan 24, 2025 – Feb 11, 2025

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

PATCH 1/1 mfd: syscon: Restore device_node_to_regmap() for non-syscon nodes

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

Fixes ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Cc Will McVicker <[email protected]>
Cc John Madieu <[email protected]>
Cc Nishanth Menon <[email protected]>
---
 drivers/mfd/syscon.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
drivers/mfd/syscon.c +26 -3
index 226915ca3c93..aa4a9940b569 100644
@@ -159,6 +159,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
 }
 
 static struct regmap *device_node_get_regmap(struct device_node *np,
+					     bool create_regmap,
 					     bool check_res)
 {
 	struct syscon *entry, *syscon = NULL;
@@ -172,7 +173,7 @@ static struct regmap *device_node_get_regmap(struct device_node *np,
 		}
 
 	if (!syscon) {
-		if (of_device_is_compatible(np, "syscon"))
+		if (create_regmap)
 			syscon = of_syscon_register(np, check_res);
 		else
 			syscon = ERR_PTR(-EINVAL);
@@ -233,15 +234,37 @@ int of_syscon_register_regmap(struct device_node *np, struct regmap *regmap)
 }
 EXPORT_SYMBOL_GPL(of_syscon_register_regmap);
 
+/**
+ * device_node_to_regmap() - Get or create a regmap for specified device node
+ * @np: Device tree node
+ *
+ * Get a regmap for the specified device node. If there's not an existing
+ * regmap, then one is instantiated. This function should not be used if the
+ * device node has a custom regmap driver or has resources (clocks, resets) to
+ * be managed. Use syscon_node_to_regmap() instead for those cases.
+ *
+ * Return: regmap ptr on success, negative error code on failure.
+ */
 struct regmap *device_node_to_regmap(struct device_node *np)
 {
-	return device_node_get_regmap(np, false);
+	return device_node_get_regmap(np, true, false);
 }
 EXPORT_SYMBOL_GPL(device_node_to_regmap);
 
+/**
+ * syscon_node_to_regmap() - Get or create a regmap for specified syscon device node
+ * @np: Device tree node
+ *
+ * Get a regmap for the specified device node. If there's not an existing
+ * regmap, then one is instantiated if the node is a generic "syscon". This
+ * function is safe to use for a syscon registered with
+ * of_syscon_register_regmap().
+ *
+ * Return: regmap ptr on success, negative error code on failure.
+ */
 struct regmap *syscon_node_to_regmap(struct device_node *np)
 {
-	return device_node_get_regmap(np, true);
+	return device_node_get_regmap(np, of_device_is_compatible(np, "syscon"), true);
 }
 EXPORT_SYMBOL_GPL(syscon_node_to_regmap);
 
Signature · 1 line
2.45.2
Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Rob Herring

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

Quoted 6 lines
Fixes ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Cc Will McVicker <[email protected]>
Cc John Madieu <[email protected]>
Cc Nishanth Menon <[email protected]>

Thanks Rob.

Tested with next-20250124 on TI K3 platforms

Signature · 3 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
Tested-by on v1 1/1
#2 lore raw
In reply to Rob Herring (Arm)
Quoted 10 lines · Rob Herring (Arm)

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

Quoted 6 lines
Fixes ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Cc Will McVicker <[email protected]>
Cc John Madieu <[email protected]>
Cc Nishanth Menon <[email protected]>

Still hitting this as of next-20250128. This patch fixed the issue which otherwise prevents boot on the Genio 700 EVK and Genio 1200 EVK boards.

Thanks,
Nícolas

Reviewed-by on v1 1/1
#3 lore raw
In reply to Rob Herring (Arm)
Quoted 10 lines · Rob Herring (Arm)

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

Quoted 7 lines
Fixes ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Cc Will McVicker <[email protected]>
Cc John Madieu <[email protected]>
Cc Nishanth Menon <[email protected]>

---

This fix is required to un-break various Mediatek clock drivers as device_node_to_regmap() is used all over the place there (in reset.c, clk-gate.c, clk-cpumux.c, clk-mux.c) and commit 3ba5a6159434 ("arm64: dts: mediatek: mt7622: fix clock controllers") has droped all those unneeded "syscon"s.

Quoted 67 lines
 drivers/mfd/syscon.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
drivers/mfd/syscon.c +26 -3
index 226915ca3c93..aa4a9940b569 100644
@@ -159,6 +159,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
 }
 
 static struct regmap *device_node_get_regmap(struct device_node *np,
+					     bool create_regmap,
 					     bool check_res)
 {
 	struct syscon *entry, *syscon = NULL;
@@ -172,7 +173,7 @@ static struct regmap *device_node_get_regmap(struct device_node *np,
 		}
 
 	if (!syscon) {
-		if (of_device_is_compatible(np, "syscon"))
+		if (create_regmap)
 			syscon = of_syscon_register(np, check_res);
 		else
 			syscon = ERR_PTR(-EINVAL);
@@ -233,15 +234,37 @@ int of_syscon_register_regmap(struct device_node *np, struct regmap *regmap)
 }
 EXPORT_SYMBOL_GPL(of_syscon_register_regmap);
 
+/**
+ * device_node_to_regmap() - Get or create a regmap for specified device node
+ * @np: Device tree node
+ *
+ * Get a regmap for the specified device node. If there's not an existing
+ * regmap, then one is instantiated. This function should not be used if the
+ * device node has a custom regmap driver or has resources (clocks, resets) to
+ * be managed. Use syscon_node_to_regmap() instead for those cases.
+ *
+ * Return: regmap ptr on success, negative error code on failure.
+ */
 struct regmap *device_node_to_regmap(struct device_node *np)
 {
-	return device_node_get_regmap(np, false);
+	return device_node_get_regmap(np, true, false);
 }
 EXPORT_SYMBOL_GPL(device_node_to_regmap);
 
+/**
+ * syscon_node_to_regmap() - Get or create a regmap for specified syscon device node
+ * @np: Device tree node
+ *
+ * Get a regmap for the specified device node. If there's not an existing
+ * regmap, then one is instantiated if the node is a generic "syscon". This
+ * function is safe to use for a syscon registered with
+ * of_syscon_register_regmap().
+ *
+ * Return: regmap ptr on success, negative error code on failure.
+ */
 struct regmap *syscon_node_to_regmap(struct device_node *np)
 {
-	return device_node_get_regmap(np, true);
+	return device_node_get_regmap(np, of_device_is_compatible(np, "syscon"), true);
 }
 EXPORT_SYMBOL_GPL(syscon_node_to_regmap);
 
Signature · 1 line
2.45.2
Tested-by Daniel Golle Tested-by
#4 lore raw

regards Frank

Quoted 23 lines

Gesendet: Sonntag, 2. Februar 2025 um 23:57
Von: "Daniel Golle" <[email protected]>
Betreff: Re: [PATCH] mfd: syscon: Restore device_node_to_regmap() for non-syscon nodes

Quoted 10 lines · Rob Herring (Arm)

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

Quoted 7 lines
Fixes ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Cc Will McVicker <[email protected]>
Cc John Madieu <[email protected]>
Cc Nishanth Menon <[email protected]>

---

Quoted 2 lines

fixing Daniels Tested-by-tag :)

and confirming the patch fixes the clock-syscon-issue (on mt7988)

Quoted 5 lines

This fix is required to un-break various Mediatek clock drivers as device_node_to_regmap() is used all over the place there (in reset.c, clk-gate.c, clk-cpumux.c, clk-mux.c) and commit 3ba5a6159434 ("arm64: dts: mediatek: mt7622: fix clock controllers") has droped all those unneeded "syscon"s.

Tested-by on v1 1/1
#5 lore raw
In reply to Rob Herring (Arm)
Quoted 16 lines · Rob Herring (Arm)

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

Fixes ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Cc Will McVicker <[email protected]>
Cc John Madieu <[email protected]>
Cc Nishanth Menon <[email protected]>
Quoted 3 lines
---
 drivers/mfd/syscon.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

Tested this for basic boot on TI K3 AM625-SK with next-20250204.

Signature · 3 lines
Best regards,
Dhruva Gole
Texas Instruments Incorporated
maintainer
#6 lore raw
In reply to Rob Herring (Arm)
Quoted 16 lines · Rob Herring (Arm)

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

Fixes ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Cc Will McVicker <[email protected]>
Cc John Madieu <[email protected]>
Cc Nishanth Menon <[email protected]>
Quoted 3 lines
---
 drivers/mfd/syscon.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

NOTE TO SELF: -rcs

Signature · 1 line
Lee Jones [李琼斯]
Tested-by on v1 1/1
#7 lore raw
In reply to Rob Herring (Arm)
Quoted 10 lines · Rob Herring (Arm)

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

Quoted 6 lines
Fixes ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Cc Will McVicker <[email protected]>
Cc John Madieu <[email protected]>
Cc Nishanth Menon <[email protected]>

This restored the power controller and everything depending on it on the MT8183 Chromebooks.

Reviewed-by Tested-by on v1 1/1
#8 lore raw
In reply to Rob Herring (Arm)

Il 24/01/25 20:16, Rob Herring (Arm) ha scritto:

Quoted 10 lines

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

Quoted 6 lines
Fixes ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible")
Cc Will McVicker <[email protected]>
Cc John Madieu <[email protected]>
Cc Nishanth Menon <[email protected]>

...and tested on

Radxa NIO 12L (MT8395/8195), MediaTek Genio 700 EVK (MT8390/MT8188), and on MT8195 Tomato Chromebook

Quoted 65 lines
---
  drivers/mfd/syscon.c | 29 ++++++++++++++++++++++++++---
  1 file changed, 26 insertions(+), 3 deletions(-)
drivers/mfd/syscon.c +26 -3
index 226915ca3c93..aa4a9940b569 100644
@@ -159,6 +159,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
  }
 
  static struct regmap *device_node_get_regmap(struct device_node *np,
+					     bool create_regmap,
  					     bool check_res)
  {
  	struct syscon *entry, *syscon = NULL;
@@ -172,7 +173,7 @@ static struct regmap *device_node_get_regmap(struct device_node *np,
  		}
 
  	if (!syscon) {
-		if (of_device_is_compatible(np, "syscon"))
+		if (create_regmap)
  			syscon = of_syscon_register(np, check_res);
  		else
  			syscon = ERR_PTR(-EINVAL);
@@ -233,15 +234,37 @@ int of_syscon_register_regmap(struct device_node *np, struct regmap *regmap)
  }
  EXPORT_SYMBOL_GPL(of_syscon_register_regmap);
 
+/**
+ * device_node_to_regmap() - Get or create a regmap for specified device node
+ * @np: Device tree node
+ *
+ * Get a regmap for the specified device node. If there's not an existing
+ * regmap, then one is instantiated. This function should not be used if the
+ * device node has a custom regmap driver or has resources (clocks, resets) to
+ * be managed. Use syscon_node_to_regmap() instead for those cases.
+ *
+ * Return: regmap ptr on success, negative error code on failure.
+ */
  struct regmap *device_node_to_regmap(struct device_node *np)
  {
-	return device_node_get_regmap(np, false);
+	return device_node_get_regmap(np, true, false);
  }
  EXPORT_SYMBOL_GPL(device_node_to_regmap);
 
+/**
+ * syscon_node_to_regmap() - Get or create a regmap for specified syscon device node
+ * @np: Device tree node
+ *
+ * Get a regmap for the specified device node. If there's not an existing
+ * regmap, then one is instantiated if the node is a generic "syscon". This
+ * function is safe to use for a syscon registered with
+ * of_syscon_register_regmap().
+ *
+ * Return: regmap ptr on success, negative error code on failure.
+ */
  struct regmap *syscon_node_to_regmap(struct device_node *np)
  {
-	return device_node_get_regmap(np, true);
+	return device_node_get_regmap(np, of_device_is_compatible(np, "syscon"), true);
  }
  EXPORT_SYMBOL_GPL(syscon_node_to_regmap);
 
maintainer Applied
#9 lore raw

Re: (subset) [PATCH] mfd: syscon: Restore device_node_to_regmap() for non-syscon nodes

In reply to Rob Herring (Arm)
Quoted 11 lines · Rob Herring (Arm)

Commit ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") broke drivers which call device_node_to_regmap() on nodes without a "syscon" compatible. Restore the prior behavior for device_node_to_regmap().

This also makes using device_node_to_regmap() incompatible with of_syscon_register_regmap() again, so add kerneldoc for device_node_to_regmap() and syscon_node_to_regmap() to make it clear how and when each one should be used.

[...]

Applied, thanks!

[1/1] mfd: syscon: Restore device_node_to_regmap() for non-syscon nodes

      commit: 5728c92ae112301936006c5e305677beb1a7f578

--
Lee Jones [李琼斯]