Skip to contentSkip to conversation

mux: mmio: Do not use syscon helper to build regmap

PATCH Applied Andrew Davis 4 participants 6 messages Jan 23, 2025 – May 1, 2025 Multiplexer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mux: mmio: Do not use syscon helper to build regmap

The syscon helper device_node_to_regmap() is used to fetch a regmap registered to a device node. It also currently creates this regmap if the node did not already have a regmap associated with it. This should only be used on "syscon" nodes. This driver is not such a device and instead uses device_node_to_regmap() on its own node as a hacky way to create a regmap for itself.

This will not work going forward and so we should create our regmap the normal way by defining our regmap_config, fetching our memory resource, then using the normal regmap_init_mmio() function.

---
 drivers/mux/mmio.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/mux/mmio.c +12 -1
index 30a952c34365f..278efdc480777 100644
@@ -33,6 +33,12 @@ static const struct of_device_id mux_mmio_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, mux_mmio_dt_ids);
 
+static const struct regmap_config mux_mmio_regmap_cfg = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+};
+
 static int mux_mmio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -40,6 +46,7 @@ static int mux_mmio_probe(struct platform_device *pdev)
 	struct regmap_field **fields;
 	struct mux_chip *mux_chip;
 	struct regmap *regmap;
+	void __iomem *base;
 	int num_fields;
 	int ret;
 	int i;
@@ -47,7 +54,11 @@ static int mux_mmio_probe(struct platform_device *pdev)
 	if (of_device_is_compatible(np, "mmio-mux")) {
 		regmap = syscon_node_to_regmap(np->parent);
 	} else {
-		regmap = device_node_to_regmap(np);
+		base = devm_platform_ioremap_resource(pdev, 0);
+		if (IS_ERR(base))
+			regmap = ERR_PTR(-ENODEV);
+		else
+			regmap = regmap_init_mmio(dev, base, &mux_mmio_regmap_cfg);
 		/* Fallback to checking the parent node on "real" errors. */
 		if (IS_ERR(regmap) && regmap != ERR_PTR(-EPROBE_DEFER)) {
 			regmap = dev_get_regmap(dev->parent, NULL);
Signature · 1 line
2.39.2
Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Andrew Davis

The syscon helper device_node_to_regmap() is used to fetch a regmap registered to a device node. It also currently creates this regmap if the node did not already have a regmap associated with it. This should only be used on "syscon" nodes. This driver is not such a device and instead uses device_node_to_regmap() on its own node as a hacky way to create a regmap for itself.

Quoted 6 lines

This will not work going forward and so we should create our regmap the normal way by defining our regmap_config, fetching our memory resource, then using the normal regmap_init_mmio() function.

---

Greg, Peter,

This is part of the fixes TI K3 platforms boot issues reported in
https://lore.kernel.org/all/[email protected]/
on the latest linus master v6.13-5001-gd0d106a2bd21 + linux next-20250123

Total set of patches tested with:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]

Could we get this routed to master as fixes asap please to get a sane 6.14?

Cc Rob and Lee

Quoted 44 lines
 drivers/mux/mmio.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/mux/mmio.c +12 -1
index 30a952c34365f..278efdc480777 100644
@@ -33,6 +33,12 @@ static const struct of_device_id mux_mmio_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, mux_mmio_dt_ids);
 
+static const struct regmap_config mux_mmio_regmap_cfg = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+};
+
 static int mux_mmio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -40,6 +46,7 @@ static int mux_mmio_probe(struct platform_device *pdev)
 	struct regmap_field **fields;
 	struct mux_chip *mux_chip;
 	struct regmap *regmap;
+	void __iomem *base;
 	int num_fields;
 	int ret;
 	int i;
@@ -47,7 +54,11 @@ static int mux_mmio_probe(struct platform_device *pdev)
 	if (of_device_is_compatible(np, "mmio-mux")) {
 		regmap = syscon_node_to_regmap(np->parent);
 	} else {
-		regmap = device_node_to_regmap(np);
+		base = devm_platform_ioremap_resource(pdev, 0);
+		if (IS_ERR(base))
+			regmap = ERR_PTR(-ENODEV);
+		else
+			regmap = regmap_init_mmio(dev, base, &mux_mmio_regmap_cfg);
 		/* Fallback to checking the parent node on "real" errors. */
 		if (IS_ERR(regmap) && regmap != ERR_PTR(-EPROBE_DEFER)) {
 			regmap = dev_get_regmap(dev->parent, NULL);
Signature · 1 line
2.39.2
Signature · 3 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
#2 lore raw
Quoted 23 lines · Nishanth Menon
Quoted 7 lines · Andrew Davis

The syscon helper device_node_to_regmap() is used to fetch a regmap registered to a device node. It also currently creates this regmap if the node did not already have a regmap associated with it. This should only be used on "syscon" nodes. This driver is not such a device and instead uses device_node_to_regmap() on its own node as a hacky way to create a regmap for itself.

Quoted 6 lines

This will not work going forward and so we should create our regmap the normal way by defining our regmap_config, fetching our memory resource, then using the normal regmap_init_mmio() function.

---

Greg, Peter,

This is part of the fixes TI K3 platforms boot issues reported in
https://lore.kernel.org/all/[email protected]/
on the latest linus master v6.13-5001-gd0d106a2bd21 + linux next-20250123

Quoted 8 lines

Total set of patches tested with:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]

Could we get this routed to master as fixes asap please to get a sane 6.14?

Our trees are of course closed right now due to the merge window, you know that :)

So we can take things after -rc1 is out, and route bugfixes for 6.14-final and new stuff for 6.15-rc1, like always. It's hard to see that this is just a bugfix, but if it is, it needs a Fixes: tag at the very least, right?

thanks,

greg k-h

#3 lore raw

On 06:26-20250124, Greg Kroah-Hartman wrote:
[...]

Quoted 14 lines
Quoted 14 lines

Greg, Peter,

This is part of the fixes TI K3 platforms boot issues reported in
https://lore.kernel.org/all/[email protected]/
on the latest linus master v6.13-5001-gd0d106a2bd21 + linux next-20250123

Total set of patches tested with:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]

Quoted 4 lines
Quoted 1 line

Could we get this routed to master as fixes asap please to get a sane 6.14?

Our trees are of course closed right now due to the merge window, you know that :)

Yes, of course.

Quoted 5 lines

So we can take things after -rc1 is out, and route bugfixes for 6.14-final and new stuff for 6.15-rc1, like always. It's hard to see that this is just a bugfix, but if it is, it needs a Fixes: tag at the very least, right?

I am not entirely sure which commit to use for fixes.

On one hand, we can use
https://lore.kernel.org/all/[email protected]/
as the cause of the Fixes. Since, the change in behavior of the subsystem late in the merge cycle caused this side effect, but, we could argue that this patch fixes the subsystem for it's intended behavior and unfortunately exposed issues in users of the syscon subsystem depending on the "wrong" behavior.

OR

The code introduced long back which depended on the older syscon behavior. but, then, we can argue that it was working fine at that point.. and if we cherry-pick the fixup for stable, it is probably inaccurate for the syscon behavior in older kernels?

Lee, Rob: Could you chime in with your suggestion?

Signature · 3 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
#4 lore raw
In reply to Greg Kroah-Hartman
Quoted 33 lines · Greg Kroah-Hartman
Quoted 23 lines · Nishanth Menon
Quoted 7 lines · Andrew Davis

The syscon helper device_node_to_regmap() is used to fetch a regmap registered to a device node. It also currently creates this regmap if the node did not already have a regmap associated with it. This should only be used on "syscon" nodes. This driver is not such a device and instead uses device_node_to_regmap() on its own node as a hacky way to create a regmap for itself.

Quoted 6 lines

This will not work going forward and so we should create our regmap the normal way by defining our regmap_config, fetching our memory resource, then using the normal regmap_init_mmio() function.

---

Greg, Peter,

This is part of the fixes TI K3 platforms boot issues reported in
https://lore.kernel.org/all/[email protected]/
on the latest linus master v6.13-5001-gd0d106a2bd21 + linux next-20250123

Quoted 8 lines

Total set of patches tested with:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]

Could we get this routed to master as fixes asap please to get a sane 6.14?

Quoted 7 lines

Our trees are of course closed right now due to the merge window, you know that :)

So we can take things after -rc1 is out, and route bugfixes for 6.14-final and new stuff for 6.15-rc1, like always. It's hard to see that this is just a bugfix, but if it is, it needs a Fixes: tag at the very least, right?

Just following up after a bit of discussion on IRC.. (Thanks Rob)

I think getting this patch in current window is less urgent for given Rob has posted a restoration of behavior[1]. This patch is still good to be merged based on [2], but probably queued as appropriate.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/CAL_JsqKVydDqmr-gyn1wt=1PO_p1NMze+1D+4qXWxGiGVLV9EA@mail.gmail.com/

Signature · 3 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
#5 lore raw
In reply to Andrew Davis
Quoted 8 lines · Andrew Davis

The syscon helper device_node_to_regmap() is used to fetch a regmap registered to a device node. It also currently creates this regmap if the node did not already have a regmap associated with it. This should only be used on "syscon" nodes. This driver is not such a device and instead uses device_node_to_regmap() on its own node as a hacky way to create a regmap for itself.

[...]

Applied, thanks!

[1/1] mux: mmio: Do not use syscon helper to build regmap

      https://git.kernel.org/krzk/linux/c/61de83fd8256e185588670d3cf0bccc3e913819c

Best regards,

Signature · 1 line
Krzysztof Kozlowski <[email protected]>