linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bus: ti-sysc: Remove open coded "ranges" parsing
@ 2023-02-01 22:00 Rob Herring
  2023-03-27  7:27 ` Tony Lindgren
  0 siblings, 1 reply; 2+ messages in thread
From: Rob Herring @ 2023-02-01 22:00 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: linux-omap, linux-kernel

"ranges" is a standard property and we have common helper functions for
parsing it, so let's use them.

Signed-off-by: Rob Herring <robh@kernel.org>
---
Compile tested only!
---
 drivers/bus/ti-sysc.c | 41 +++++++++--------------------------------
 1 file changed, 9 insertions(+), 32 deletions(-)

diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c
index 6afae9897843..9c8985515376 100644
--- a/drivers/bus/ti-sysc.c
+++ b/drivers/bus/ti-sysc.c
@@ -648,43 +648,20 @@ static int sysc_init_resets(struct sysc *ddata)
 static int sysc_parse_and_check_child_range(struct sysc *ddata)
 {
 	struct device_node *np = ddata->dev->of_node;
-	const __be32 *ranges;
-	u32 nr_addr, nr_size;
-	int len, error;
-
-	ranges = of_get_property(np, "ranges", &len);
-	if (!ranges) {
-		dev_err(ddata->dev, "missing ranges for %pOF\n", np);
-
-		return -ENOENT;
-	}
-
-	len /= sizeof(*ranges);
-
-	if (len < 3) {
-		dev_err(ddata->dev, "incomplete ranges for %pOF\n", np);
-
-		return -EINVAL;
-	}
-
-	error = of_property_read_u32(np, "#address-cells", &nr_addr);
-	if (error)
-		return -ENOENT;
+	struct of_range_parser parser;
+	struct of_range range;
+	int error;
 
-	error = of_property_read_u32(np, "#size-cells", &nr_size);
+	error = of_range_parser_init(&parser, np);
 	if (error)
-		return -ENOENT;
-
-	if (nr_addr != 1 || nr_size != 1) {
-		dev_err(ddata->dev, "invalid ranges for %pOF\n", np);
+		return error;
 
-		return -EINVAL;
+	for_each_of_range(&parser, &range) {
+		ddata->module_pa = range.cpu_addr;
+		ddata->module_size = range.size;
+		break;
 	}
 
-	ranges++;
-	ddata->module_pa = of_translate_address(np, ranges++);
-	ddata->module_size = be32_to_cpup(ranges);
-
 	return 0;
 }
 
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bus: ti-sysc: Remove open coded "ranges" parsing
  2023-02-01 22:00 [PATCH] bus: ti-sysc: Remove open coded "ranges" parsing Rob Herring
@ 2023-03-27  7:27 ` Tony Lindgren
  0 siblings, 0 replies; 2+ messages in thread
From: Tony Lindgren @ 2023-03-27  7:27 UTC (permalink / raw)
  To: Rob Herring; +Cc: linux-omap, linux-kernel

* Rob Herring <robh@kernel.org> [230202 00:00]:
> "ranges" is a standard property and we have common helper functions for
> parsing it, so let's use them.

Nice, applying into omap-for-v6.4/ti-sysc.

Thanks,

Tony

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-27  7:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-01 22:00 [PATCH] bus: ti-sysc: Remove open coded "ranges" parsing Rob Herring
2023-03-27  7:27 ` Tony Lindgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).