mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/5] of: platform: deep probe updates
@ 2022-03-08 11:50 Sascha Hauer
  2022-03-08 11:50 ` [PATCH 1/5] of: platform: return early when deep probe is not supported Sascha Hauer
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Sascha Hauer @ 2022-03-08 11:50 UTC (permalink / raw)
  To: Barebox List

It turned out that timers may be initialized very late during
initialization when deep probe is used. The final goal of this series
is to fix that, but there are some preparations necessary.

Sascha Hauer (5):
  of: platform: return early when deep probe is not supported
  of: rename of_find_node_by_name() to of_find_node_by_name_address()
  of: Add of_find_node_by_name() with Linux semantics
  of: platform: Change of_devices_ensure_probed_by_property() return
    value
  of: platform: Ensure timers are probed early

 arch/arm/boards/ccxmx51/ccxmx51.c         |  2 +-
 arch/arm/boards/gateworks-ventana/board.c |  4 +--
 arch/arm/boards/phytec-som-imx6/board.c   |  2 +-
 arch/arm/boards/protonic-imx6/board.c     |  2 +-
 arch/arm/boards/skov-imx6/board.c         |  2 +-
 arch/arm/boards/zii-common/pn-fixup.c     |  2 +-
 arch/arm/boards/zii-imx51-rdu1/board.c    |  2 +-
 arch/arm/boards/zii-imx6q-rdu2/board.c    | 12 +++----
 arch/arm/boards/zii-imx8mq-dev/board.c    |  2 +-
 arch/arm/mach-imx/imx6.c                  |  2 +-
 arch/arm/mach-stm32mp/init.c              |  2 +-
 arch/riscv/cpu/core.c                     |  2 +-
 commands/of_display_timings.c             |  4 +--
 common/oftree.c                           |  4 +--
 drivers/aiodev/qoriq_thermal.c            |  2 +-
 drivers/net/cpsw.c                        |  2 +-
 drivers/net/phy/mv88e6xxx/port.c          |  2 +-
 drivers/of/base.c                         | 40 ++++++++++++++++++++-
 drivers/of/fdt.c                          |  2 +-
 drivers/of/platform.c                     | 44 ++++++++++++++++++++---
 drivers/of/resolver.c                     |  4 +--
 include/of.h                              | 21 +++++++++++
 22 files changed, 127 insertions(+), 34 deletions(-)

-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* [PATCH 1/5] of: platform: return early when deep probe is not supported
  2022-03-08 11:50 [PATCH 0/5] of: platform: deep probe updates Sascha Hauer
@ 2022-03-08 11:50 ` Sascha Hauer
  2022-03-08 11:51 ` [PATCH 2/5] of: rename of_find_node_by_name() to of_find_node_by_name_address() Sascha Hauer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2022-03-08 11:50 UTC (permalink / raw)
  To: Barebox List

When deep probe is not supported we can bail out early from the
of_devices_ensure_probed_by_* functions. This saves us from iterating
over the whole device tree and then doing nothing on the found nodes.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/platform.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 0e718469db..5a05001213 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -455,6 +455,9 @@ int of_device_ensure_probed_by_alias(const char *alias)
 {
 	struct device_node *dev_node;
 
+	if (!deep_probe_is_supported())
+		return 0;
+
 	dev_node = of_find_node_by_alias(NULL, alias);
 	if (!dev_node)
 		return -EINVAL;
@@ -480,6 +483,9 @@ int of_devices_ensure_probed_by_dev_id(const struct of_device_id *ids)
 	struct device_node *np;
 	int err, ret = 0;
 
+	if (!deep_probe_is_supported())
+		return 0;
+
 	for_each_matching_node(np, ids) {
 		if (!of_device_is_available(np))
 			continue;
@@ -509,6 +515,9 @@ int of_devices_ensure_probed_by_property(const char *property_name)
 {
 	struct device_node *node;
 
+	if (!deep_probe_is_supported())
+		return 0;
+
 	for_each_node_with_property(node, property_name) {
 		int ret;
 
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* [PATCH 2/5] of: rename of_find_node_by_name() to of_find_node_by_name_address()
  2022-03-08 11:50 [PATCH 0/5] of: platform: deep probe updates Sascha Hauer
  2022-03-08 11:50 ` [PATCH 1/5] of: platform: return early when deep probe is not supported Sascha Hauer
@ 2022-03-08 11:51 ` Sascha Hauer
  2022-03-08 11:51 ` [PATCH 3/5] of: Add of_find_node_by_name() with Linux semantics Sascha Hauer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2022-03-08 11:51 UTC (permalink / raw)
  To: Barebox List

of_find_node_by_name() has the same name as the corresponding kernel
function but a different semantics. A node name is comprised of the
nodes name and a unit address, separated with '@'. Linux
of_find_node_by_name() matches only the name before the '@' whereas the
barebox function compares the full name.
As several callers depend on the barebox semantics we can't just change
the semantics, so rename the barebox function to
of_find_node_by_name_address().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/ccxmx51/ccxmx51.c         |  2 +-
 arch/arm/boards/gateworks-ventana/board.c |  4 ++--
 arch/arm/boards/phytec-som-imx6/board.c   |  2 +-
 arch/arm/boards/protonic-imx6/board.c     |  2 +-
 arch/arm/boards/skov-imx6/board.c         |  2 +-
 arch/arm/boards/zii-common/pn-fixup.c     |  2 +-
 arch/arm/boards/zii-imx51-rdu1/board.c    |  2 +-
 arch/arm/boards/zii-imx6q-rdu2/board.c    | 12 ++++++------
 arch/arm/boards/zii-imx8mq-dev/board.c    |  2 +-
 arch/arm/mach-imx/imx6.c                  |  2 +-
 arch/arm/mach-stm32mp/init.c              |  2 +-
 arch/riscv/cpu/core.c                     |  2 +-
 commands/of_display_timings.c             |  4 ++--
 common/oftree.c                           |  4 ++--
 drivers/aiodev/qoriq_thermal.c            |  2 +-
 drivers/net/cpsw.c                        |  2 +-
 drivers/net/phy/mv88e6xxx/port.c          |  2 +-
 drivers/of/base.c                         |  6 +++---
 drivers/of/fdt.c                          |  2 +-
 drivers/of/platform.c                     |  2 +-
 drivers/of/resolver.c                     |  4 ++--
 include/of.h                              | 16 ++++++++--------
 22 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/arch/arm/boards/ccxmx51/ccxmx51.c b/arch/arm/boards/ccxmx51/ccxmx51.c
index 09437b047f..dfc26cd835 100644
--- a/arch/arm/boards/ccxmx51/ccxmx51.c
+++ b/arch/arm/boards/ccxmx51/ccxmx51.c
@@ -174,7 +174,7 @@ static void ccxmx51_power_init(struct mc13xxx *mc13xxx)
 
 static void ccxmx51_disable_device(struct device_node *root, const char *label)
 {
-	struct device_node *np = of_find_node_by_name(root, label);
+	struct device_node *np = of_find_node_by_name_address(root, label);
 	if (np)
 		of_device_disable(np);
 }
diff --git a/arch/arm/boards/gateworks-ventana/board.c b/arch/arm/boards/gateworks-ventana/board.c
index 163f8338c6..c4c6960192 100644
--- a/arch/arm/boards/gateworks-ventana/board.c
+++ b/arch/arm/boards/gateworks-ventana/board.c
@@ -19,9 +19,9 @@ static int gw54xx_wdog_of_fixup(struct device_node *root, void *context)
 	struct device_node *np;
 
 	/* switch to the watchdog with internal reset capabilities */
-	np = of_find_node_by_name(root, "wdog@020c0000");
+	np = of_find_node_by_name_address(root, "wdog@020c0000");
 	of_device_disable(np);
-	np = of_find_node_by_name(root, "wdog@020bc000");
+	np = of_find_node_by_name_address(root, "wdog@020bc000");
 	of_device_enable(np);
 
 	return 0;
diff --git a/arch/arm/boards/phytec-som-imx6/board.c b/arch/arm/boards/phytec-som-imx6/board.c
index 1e515a093a..c540aaeb3f 100644
--- a/arch/arm/boards/phytec-som-imx6/board.c
+++ b/arch/arm/boards/phytec-som-imx6/board.c
@@ -107,7 +107,7 @@ static int phycore_da9062_setup_buck_mode(void)
 	unsigned char value;
 	int ret;
 
-	pmic_np = of_find_node_by_name(NULL, "pmic@58");
+	pmic_np = of_find_node_by_name_address(NULL, "pmic@58");
 	if (!pmic_np)
 		return -ENODEV;
 
diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 9b2a00c6c3..adde1be8d9 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -736,7 +736,7 @@ static int prt_imx6_get_id(struct prt_imx6_priv *priv)
 	struct device_node *gpio_np = NULL;
 	int ret;
 
-	gpio_np = of_find_node_by_name(NULL, "gpio@20a0000");
+	gpio_np = of_find_node_by_name_address(NULL, "gpio@20a0000");
 	if (!gpio_np)
 		return -ENODEV;
 
diff --git a/arch/arm/boards/skov-imx6/board.c b/arch/arm/boards/skov-imx6/board.c
index cd7b8e208d..7ceb3590c6 100644
--- a/arch/arm/boards/skov-imx6/board.c
+++ b/arch/arm/boards/skov-imx6/board.c
@@ -568,7 +568,7 @@ static void skov_init_board(const struct board_description *variant)
 			pr_err("Cannot find \"fsl,imx6q-ldb\" node\n");
 
 		/* ... as well as its channel 0 */
-		np = of_find_node_by_name(np, "lvds-channel@0");
+		np = of_find_node_by_name_address(np, "lvds-channel@0");
 		if (np)
 			of_device_enable(np);
 		else
diff --git a/arch/arm/boards/zii-common/pn-fixup.c b/arch/arm/boards/zii-common/pn-fixup.c
index 80785285b7..3c69f1a022 100644
--- a/arch/arm/boards/zii-common/pn-fixup.c
+++ b/arch/arm/boards/zii-common/pn-fixup.c
@@ -11,7 +11,7 @@ char *zii_read_part_number(const char *cell_name, size_t cell_size)
 {
 	struct device_node *np;
 
-	np = of_find_node_by_name(NULL, "device-info");
+	np = of_find_node_by_name_address(NULL, "device-info");
 	if (!np) {
 		pr_warn("No device information found\n");
 		return ERR_PTR(-ENOENT);
diff --git a/arch/arm/boards/zii-imx51-rdu1/board.c b/arch/arm/boards/zii-imx51-rdu1/board.c
index 8fdcb76260..42c99ecc1e 100644
--- a/arch/arm/boards/zii-imx51-rdu1/board.c
+++ b/arch/arm/boards/zii-imx51-rdu1/board.c
@@ -99,7 +99,7 @@ static int zii_rdu1_load_config(void)
 			file = "shadow copy in RAVE SP EEPROM";
 
 			root = of_get_root_node();
-			np   = of_find_node_by_name(root, "eeprom@a4");
+			np   = of_find_node_by_name_address(root, "eeprom@a4");
 			if (!np)
 				return -ENODEV;
 
diff --git a/arch/arm/boards/zii-imx6q-rdu2/board.c b/arch/arm/boards/zii-imx6q-rdu2/board.c
index b915a05dd2..f57827cd13 100644
--- a/arch/arm/boards/zii-imx6q-rdu2/board.c
+++ b/arch/arm/boards/zii-imx6q-rdu2/board.c
@@ -199,19 +199,19 @@ static int rdu2_fixup_dsa(struct device_node *root, void *context)
 	if (!switch_np)
 		return -ENODEV;
 
-	np = of_find_node_by_name(switch_np, "port@2");
+	np = of_find_node_by_name_address(switch_np, "port@2");
 	if (!np)
 		return -ENODEV;
 
 	of_delete_node(np);
 
-	np = of_find_node_by_name(root, "i210@0");
+	np = of_find_node_by_name_address(root, "i210@0");
 	if (!np)
 		return -ENODEV;
 
 	i210_handle = of_node_create_phandle(np);
 
-	np = of_find_node_by_name(switch_np, "port@0");
+	np = of_find_node_by_name_address(switch_np, "port@0");
 	if (!np)
 		return -ENODEV;
 
@@ -265,7 +265,7 @@ static int rdu2_fixup_lvds(struct device_node *root,
 	/*
 	 * LVDS panels need the correct timings
 	 */
-	np = of_find_node_by_name(root, "panel");
+	np = of_find_node_by_name_address(root, "panel");
 	if (!np)
 		return -ENODEV;
 
@@ -280,7 +280,7 @@ static int rdu2_fixup_lvds(struct device_node *root,
 		 * Delete all mode entries, which aren't suited for the
 		 * current display
 		 */
-		np = of_find_node_by_name(np, "display-timings");
+		np = of_find_node_by_name_address(np, "display-timings");
 		if (!np)
 			return -ENODEV;
 
@@ -305,7 +305,7 @@ static int rdu2_fixup_lvds(struct device_node *root,
 	if (fixup->type == IT_DUAL_LVDS)
 		of_set_property(np, "fsl,dual-channel", NULL, 0, 1);
 
-	np = of_find_node_by_name(np, "lvds-channel@0");
+	np = of_find_node_by_name_address(np, "lvds-channel@0");
 	if (!np)
 		return -ENODEV;
 
diff --git a/arch/arm/boards/zii-imx8mq-dev/board.c b/arch/arm/boards/zii-imx8mq-dev/board.c
index 4ad09663ac..02e257f35f 100644
--- a/arch/arm/boards/zii-imx8mq-dev/board.c
+++ b/arch/arm/boards/zii-imx8mq-dev/board.c
@@ -106,7 +106,7 @@ static int zii_imx8mq_dev_fixup_deb_internal(void)
 
 	unregister_device(dev);
 
-	np = of_find_node_by_name(NULL, "i210@0");
+	np = of_find_node_by_name_address(NULL, "i210@0");
 	if (!np)
 		return -ENODEV;
 
diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
index 3ee42fd966..92d3e14ba1 100644
--- a/arch/arm/mach-imx/imx6.c
+++ b/arch/arm/mach-imx/imx6.c
@@ -363,7 +363,7 @@ static int imx6_fixup_cpus(struct device_node *root, void *context)
 	unsigned long scu_phys_base;
 	unsigned int max_core_index;
 
-	cpus_node = of_find_node_by_name(root, "cpus");
+	cpus_node = of_find_node_by_name_address(root, "cpus");
 	if (!cpus_node)
 		return 0;
 
diff --git a/arch/arm/mach-stm32mp/init.c b/arch/arm/mach-stm32mp/init.c
index 01961ae456..bcd04b210a 100644
--- a/arch/arm/mach-stm32mp/init.c
+++ b/arch/arm/mach-stm32mp/init.c
@@ -140,7 +140,7 @@ static int stm32mp15_fixup_cpus(struct device_node *root, void *_ctx)
 	unsigned long ctx = (unsigned long)_ctx;
 	struct device_node *cpus_node, *np, *tmp;
 
-	cpus_node = of_find_node_by_name(root, "cpus");
+	cpus_node = of_find_node_by_name_address(root, "cpus");
 	if (!cpus_node)
 		return 0;
 
diff --git a/arch/riscv/cpu/core.c b/arch/riscv/cpu/core.c
index 1d5902a51f..c075301b1b 100644
--- a/arch/riscv/cpu/core.c
+++ b/arch/riscv/cpu/core.c
@@ -43,7 +43,7 @@ static int riscv_fixup_cpus(struct device_node *root, void *context)
 {
 	struct device_node *cpus_node, *np, *tmp;
 
-	cpus_node = of_find_node_by_name(root, "cpus");
+	cpus_node = of_find_node_by_name_address(root, "cpus");
 	if (!cpus_node)
 		return 0;
 
diff --git a/commands/of_display_timings.c b/commands/of_display_timings.c
index 4e5ec223b7..aab57b17d6 100644
--- a/commands/of_display_timings.c
+++ b/commands/of_display_timings.c
@@ -98,7 +98,7 @@ static int do_of_display_timings(int argc, char *argv[])
 		int found = 0;
 		const char *node = "display-timings";
 
-		for_each_node_by_name_from(display, root, node) {
+		for_each_node_by_name_address_from(display, root, node) {
 			for_each_child_of_node(display, timings) {
 				printf("%s\n", timings->full_name);
 				found = 1;
@@ -113,7 +113,7 @@ static int do_of_display_timings(int argc, char *argv[])
 		int found = 0;
 		const char *node = "display-timings";
 
-		for_each_node_by_name_from(display, root, node) {
+		for_each_node_by_name_address_from(display, root, node) {
 			timings = of_parse_phandle_from(display, root,
 							"native-mode", 0);
 			if (!timings)
diff --git a/common/oftree.c b/common/oftree.c
index 0738ab6e9e..bce0ff09d6 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -405,7 +405,7 @@ int of_autoenable_device_by_path(char *path)
 	struct device_node *node;
 	int ret;
 
-	node = of_find_node_by_name(NULL, path);
+	node = of_find_node_by_name_address(NULL, path);
 	if (!node)
 		node = of_find_node_by_path(path);
 
@@ -442,7 +442,7 @@ int of_autoenable_i2c_by_component(char *path)
 	if (!IS_ENABLED(CONFIG_I2C))
 		return -ENODEV;
 
-	node = of_find_node_by_name(NULL, path);
+	node = of_find_node_by_name_address(NULL, path);
 	if (!node)
 		node = of_find_node_by_path(path);
 	if (!node)
diff --git a/drivers/aiodev/qoriq_thermal.c b/drivers/aiodev/qoriq_thermal.c
index d62048ef13..1acb06a9de 100644
--- a/drivers/aiodev/qoriq_thermal.c
+++ b/drivers/aiodev/qoriq_thermal.c
@@ -118,7 +118,7 @@ static int qoriq_tmu_get_sensor_id(void)
 	struct of_phandle_args sensor_specs;
 	struct device_node *np, *sensor_np;
 
-	np = of_find_node_by_name(NULL, "thermal-zones");
+	np = of_find_node_by_name_address(NULL, "thermal-zones");
 	if (!np)
 		return -ENODEV;
 
diff --git a/drivers/net/cpsw.c b/drivers/net/cpsw.c
index 6725c7b9bd..748aa861f1 100644
--- a/drivers/net/cpsw.c
+++ b/drivers/net/cpsw.c
@@ -1224,7 +1224,7 @@ static void cpsw_add_slave(struct cpsw_slave *slave, struct device_node *child,
 	uint32_t phy_id[2] = {-1, -1};
 	int ret;
 
-	if (!of_find_node_by_name(child, "fixed-link")) {
+	if (!of_find_node_by_name_address(child, "fixed-link")) {
 		ret = of_property_read_u32_array(child, "phy_id", phy_id, 2);
 		if (!ret)
 			dev_warn(slave->cpsw->dev, "phy_id is deprecated, use phy-handle\n");
diff --git a/drivers/net/phy/mv88e6xxx/port.c b/drivers/net/phy/mv88e6xxx/port.c
index ba2b03e18d..79694e5237 100644
--- a/drivers/net/phy/mv88e6xxx/port.c
+++ b/drivers/net/phy/mv88e6xxx/port.c
@@ -558,7 +558,7 @@ int mv88e6xxx_port_probe(struct mv88e6xxx_chip *chip)
 	struct device_node *port_nodes[DSA_MAX_PORTS] = { NULL };
 	int err, i;
 
-	switch_node = of_find_node_by_name(np, "ports");
+	switch_node = of_find_node_by_name_address(np, "ports");
 	if (!switch_node)
 		return -EINVAL;
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 723bf2132d..d5cbb12a29 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -538,7 +538,7 @@ int of_device_is_compatible(const struct device_node *device,
 EXPORT_SYMBOL(of_device_is_compatible);
 
 /**
- *	of_find_node_by_name - Find a node by its "name" property
+ *	of_find_node_by_name_address - Find a node by its full name
  *	@from:	The node to start searching from or NULL, the node
  *		you pass will not be searched, only the next one
  *		will; typically, you pass what the previous call
@@ -547,7 +547,7 @@ EXPORT_SYMBOL(of_device_is_compatible);
  *
  *	Returns a pointer to the node found or NULL.
  */
-struct device_node *of_find_node_by_name(struct device_node *from,
+struct device_node *of_find_node_by_name_address(struct device_node *from,
 	const char *name)
 {
 	struct device_node *np;
@@ -558,7 +558,7 @@ struct device_node *of_find_node_by_name(struct device_node *from,
 
 	return NULL;
 }
-EXPORT_SYMBOL(of_find_node_by_name);
+EXPORT_SYMBOL(of_find_node_by_name_address);
 
 /**
  *	of_find_node_by_type - Find a node by its "device_type" property
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 770126c78e..5ccbd1bb69 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -486,7 +486,7 @@ void *of_flatten_dtb(struct device_node *node)
 	if (ret)
 		goto out_free;
 
-	memreserve = of_find_node_by_name(node, "memreserve");
+	memreserve = of_find_node_by_name_address(node, "memreserve");
 	if (memreserve) {
 		const void *entries = of_get_property(memreserve, "reg", &len);
 
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 5a05001213..f22c5f2e76 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -202,7 +202,7 @@ struct device_d *of_device_enable_and_register_by_name(const char *name)
 {
 	struct device_node *node;
 
-	node = of_find_node_by_name(NULL, name);
+	node = of_find_node_by_name_address(NULL, name);
 	if (!node)
 		node = of_find_node_by_path(name);
 
diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c
index 242775099e..2457ae96a4 100644
--- a/drivers/of/resolver.c
+++ b/drivers/of/resolver.c
@@ -214,7 +214,7 @@ struct device_node *of_resolve_phandles(struct device_node *root,
 	 * to a phandle defined in the overlay. We must update the references,
 	 * because we just adjusted the definitions.
 	 */
-	local_fixups = of_find_node_by_name(result, "__local_fixups__");
+	local_fixups = of_find_node_by_name_address(result, "__local_fixups__");
 	err = adjust_local_phandle_references(local_fixups, result, delta);
 	if (err) {
 		pr_err("failed to fix phandles in overlay\n");
@@ -227,7 +227,7 @@ struct device_node *of_resolve_phandles(struct device_node *root,
 	 * the base device tree. We must update the references, because they
 	 * are otherwise undefined.
 	 */
-	overlay_fixups = of_find_node_by_name(result, "__fixups__");
+	overlay_fixups = of_find_node_by_name_address(result, "__fixups__");
 	if (!overlay_fixups) {
 		pr_debug("overlay does not contain phandles to base devicetree\n");
 		goto out;
diff --git a/include/of.h b/include/of.h
index b449d10ec7..2c1a3f5510 100644
--- a/include/of.h
+++ b/include/of.h
@@ -136,7 +136,7 @@ extern struct property *of_new_property_const(struct device_node *node,
 					      const void *data, int len);
 extern void of_delete_property(struct property *pp);
 
-extern struct device_node *of_find_node_by_name(struct device_node *from,
+extern struct device_node *of_find_node_by_name_address(struct device_node *from,
 	const char *name);
 extern struct device_node *of_find_node_by_path_from(struct device_node *from,
 						const char *path);
@@ -653,7 +653,7 @@ static inline struct device_node *of_find_node_by_path(const char *path)
 	return NULL;
 }
 
-static inline struct device_node *of_find_node_by_name(struct device_node *from,
+static inline struct device_node *of_find_node_by_name_address(struct device_node *from,
 	const char *name)
 {
 	return NULL;
@@ -824,15 +824,15 @@ static inline int of_autoenable_i2c_by_component(char *path)
 
 #define for_each_property_of_node(dn, pp) \
 	list_for_each_entry(pp, &dn->properties, list)
-#define for_each_node_by_name(dn, name) \
-	for (dn = of_find_node_by_name(NULL, name); dn; \
-	     dn = of_find_node_by_name(dn, name))
+#define for_each_node_by_name_address(dn, name) \
+	for (dn = of_find_node_by_name_address(NULL, name); dn; \
+	     dn = of_find_node_by_name_address(dn, name))
 #define for_each_node_by_type(dn, type) \
 	for (dn = of_find_node_by_type(NULL, type); dn; \
 	     dn = of_find_node_by_type(dn, type))
-#define for_each_node_by_name_from(dn, root, name) \
-	for (dn = of_find_node_by_name(root, name); dn; \
-	     dn = of_find_node_by_name(dn, name))
+#define for_each_node_by_name_address_from(dn, root, name) \
+	for (dn = of_find_node_by_name_address(root, name); dn; \
+	     dn = of_find_node_by_name_address(dn, name))
 /* Iterate over compatible nodes starting from given root */
 #define for_each_compatible_node_from(dn, root, type, compatible) \
 	for (dn = of_find_compatible_node(root, type, compatible); dn; \
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* [PATCH 3/5] of: Add of_find_node_by_name() with Linux semantics
  2022-03-08 11:50 [PATCH 0/5] of: platform: deep probe updates Sascha Hauer
  2022-03-08 11:50 ` [PATCH 1/5] of: platform: return early when deep probe is not supported Sascha Hauer
  2022-03-08 11:51 ` [PATCH 2/5] of: rename of_find_node_by_name() to of_find_node_by_name_address() Sascha Hauer
@ 2022-03-08 11:51 ` Sascha Hauer
  2022-03-08 11:51 ` [PATCH 4/5] of: platform: Change of_devices_ensure_probed_by_property() return value Sascha Hauer
  2022-03-08 11:51 ` [PATCH 5/5] of: platform: Ensure timers are probed early Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2022-03-08 11:51 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/of.h      | 20 ++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index d5cbb12a29..83291c4785 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -23,6 +23,21 @@
 
 static struct device_node *root_node;
 
+bool of_node_name_eq(const struct device_node *np, const char *name)
+{
+	const char *node_name;
+	size_t len;
+
+	if (!np)
+		return false;
+
+	node_name = kbasename(np->full_name);
+		len = strchrnul(node_name, '@') - node_name;
+
+	return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);
+}
+EXPORT_SYMBOL(of_node_name_eq);
+
 /*
  * Iterate over all nodes of a tree. As a devicetree does not
  * have a dedicated list head, the start node (usually the root
@@ -560,6 +575,29 @@ struct device_node *of_find_node_by_name_address(struct device_node *from,
 }
 EXPORT_SYMBOL(of_find_node_by_name_address);
 
+/**
+ *	of_find_node_by_name - Find a node by its "name" property
+ *	@from:	The node to start searching from or NULL, the node
+ *		you pass will not be searched, only the next one
+ *		will; typically, you pass what the previous call
+ *		returned.
+ *	@name:	The name string to match against
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_by_name(struct device_node *from,
+	const char *name)
+{
+	struct device_node *np;
+
+	of_tree_for_each_node_from(np, from)
+		if (np->name && of_node_name_eq(np, name))
+			return np;
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_node_by_name);
+
 /**
  *	of_find_node_by_type - Find a node by its "device_type" property
  *	@from:  The node to start searching from, or NULL to start searching
diff --git a/include/of.h b/include/of.h
index 2c1a3f5510..9089409f9f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -120,6 +120,7 @@ extern int of_bus_n_addr_cells(struct device_node *np);
 extern int of_n_addr_cells(struct device_node *np);
 extern int of_bus_n_size_cells(struct device_node *np);
 extern int of_n_size_cells(struct device_node *np);
+extern bool of_node_name_eq(const struct device_node *np, const char *name);
 
 extern struct property *of_find_property(const struct device_node *np,
 					const char *name, int *lenp);
@@ -136,6 +137,8 @@ extern struct property *of_new_property_const(struct device_node *node,
 					      const void *data, int len);
 extern void of_delete_property(struct property *pp);
 
+extern struct device_node *of_find_node_by_name(struct device_node *from,
+	const char *name);
 extern struct device_node *of_find_node_by_name_address(struct device_node *from,
 	const char *name);
 extern struct device_node *of_find_node_by_path_from(struct device_node *from,
@@ -313,6 +316,11 @@ struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 int of_autoenable_device_by_path(char *path);
 int of_autoenable_i2c_by_component(char *path);
 #else
+static inline bool of_node_name_eq(const struct device_node *np, const char *name)
+{
+	return false;
+}
+
 static inline int of_parse_partitions(struct cdev *cdev,
 					  struct device_node *node)
 {
@@ -653,6 +661,12 @@ static inline struct device_node *of_find_node_by_path(const char *path)
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_by_name(struct device_node *from,
+	const char *name)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_find_node_by_name_address(struct device_node *from,
 	const char *name)
 {
@@ -824,12 +838,18 @@ static inline int of_autoenable_i2c_by_component(char *path)
 
 #define for_each_property_of_node(dn, pp) \
 	list_for_each_entry(pp, &dn->properties, list)
+#define for_each_node_by_name(dn, name) \
+	for (dn = of_find_node_by_name(NULL, name); dn; \
+	     dn = of_find_node_by_name(dn, name))
 #define for_each_node_by_name_address(dn, name) \
 	for (dn = of_find_node_by_name_address(NULL, name); dn; \
 	     dn = of_find_node_by_name_address(dn, name))
 #define for_each_node_by_type(dn, type) \
 	for (dn = of_find_node_by_type(NULL, type); dn; \
 	     dn = of_find_node_by_type(dn, type))
+#define for_each_node_by_name_from(dn, root, name) \
+	for (dn = of_find_node_by_name(root, name); dn; \
+	     dn = of_find_node_by_name(dn, name))
 #define for_each_node_by_name_address_from(dn, root, name) \
 	for (dn = of_find_node_by_name_address(root, name); dn; \
 	     dn = of_find_node_by_name_address(dn, name))
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* [PATCH 4/5] of: platform: Change of_devices_ensure_probed_by_property() return value
  2022-03-08 11:50 [PATCH 0/5] of: platform: deep probe updates Sascha Hauer
                   ` (2 preceding siblings ...)
  2022-03-08 11:51 ` [PATCH 3/5] of: Add of_find_node_by_name() with Linux semantics Sascha Hauer
@ 2022-03-08 11:51 ` Sascha Hauer
  2022-03-08 11:51 ` [PATCH 5/5] of: platform: Ensure timers are probed early Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2022-03-08 11:51 UTC (permalink / raw)
  To: Barebox List

of_devices_ensure_probed_by_property() returns with an error immediately
when one the calls to of_device_ensure_probed() fails. This is not the
desired behaviour. Instead, always call of_device_ensure_probed() on all
found nodes and return unsuccessfully when at least one of the nodes
failed.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/platform.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index f22c5f2e76..4e96350ae2 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -514,16 +514,15 @@ EXPORT_SYMBOL_GPL(of_devices_ensure_probed_by_dev_id);
 int of_devices_ensure_probed_by_property(const char *property_name)
 {
 	struct device_node *node;
+	int err, ret = 0;
 
 	if (!deep_probe_is_supported())
 		return 0;
 
 	for_each_node_with_property(node, property_name) {
-		int ret;
-
 		ret = of_device_ensure_probed(node);
-		if (ret)
-			return ret;
+		if (err)
+			ret = err;
 	}
 
 	return 0;
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* [PATCH 5/5] of: platform: Ensure timers are probed early
  2022-03-08 11:50 [PATCH 0/5] of: platform: deep probe updates Sascha Hauer
                   ` (3 preceding siblings ...)
  2022-03-08 11:51 ` [PATCH 4/5] of: platform: Change of_devices_ensure_probed_by_property() return value Sascha Hauer
@ 2022-03-08 11:51 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2022-03-08 11:51 UTC (permalink / raw)
  To: Barebox List

Timers are a very crucial resource and are needed early. Without them
no delay function can work properly. With deep probe enabled they may
be initialized very late in the initialization order. Make sure they
are probed early. We do not know which device node provides the timer,
so probe all nodes named "timer".

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/platform.c | 26 ++++++++++++++++++++++++++
 include/of.h          |  1 +
 2 files changed, 27 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 4e96350ae2..e4e0b5dc40 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -529,6 +529,24 @@ int of_devices_ensure_probed_by_property(const char *property_name)
 }
 EXPORT_SYMBOL_GPL(of_devices_ensure_probed_by_property);
 
+int of_devices_ensure_probed_by_name(const char *name)
+{
+	struct device_node *node;
+	int err, ret = 0;
+
+	if (!deep_probe_is_supported())
+		return 0;
+
+	for_each_node_by_name(node, name) {
+		ret = of_device_ensure_probed(node);
+		if (err)
+			ret = err;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_devices_ensure_probed_by_name);
+
 static int of_stdoutpath_init(void)
 {
 	struct device_node *np;
@@ -545,3 +563,11 @@ static int of_stdoutpath_init(void)
 	return of_device_ensure_probed(np);
 }
 postconsole_initcall(of_stdoutpath_init);
+
+static int of_timer_init(void)
+{
+	of_devices_ensure_probed_by_name("timer");
+
+	return 0;
+}
+postcore_initcall(of_timer_init);
diff --git a/include/of.h b/include/of.h
index 9089409f9f..cf9950e9b3 100644
--- a/include/of.h
+++ b/include/of.h
@@ -287,6 +287,7 @@ extern struct device_d *of_device_enable_and_register_by_alias(
 extern int of_device_ensure_probed(struct device_node *np);
 extern int of_device_ensure_probed_by_alias(const char *alias);
 extern int of_devices_ensure_probed_by_property(const char *property_name);
+extern int of_devices_ensure_probed_by_name(const char *name);
 extern int of_devices_ensure_probed_by_dev_id(const struct of_device_id *ids);
 extern int of_partition_ensure_probed(struct device_node *np);
 
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

end of thread, other threads:[~2022-03-08 11:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 11:50 [PATCH 0/5] of: platform: deep probe updates Sascha Hauer
2022-03-08 11:50 ` [PATCH 1/5] of: platform: return early when deep probe is not supported Sascha Hauer
2022-03-08 11:51 ` [PATCH 2/5] of: rename of_find_node_by_name() to of_find_node_by_name_address() Sascha Hauer
2022-03-08 11:51 ` [PATCH 3/5] of: Add of_find_node_by_name() with Linux semantics Sascha Hauer
2022-03-08 11:51 ` [PATCH 4/5] of: platform: Change of_devices_ensure_probed_by_property() return value Sascha Hauer
2022-03-08 11:51 ` [PATCH 5/5] of: platform: Ensure timers are probed early Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox