[PATCH 2/6] driver: pass the requested node to the rescan hook
Ahmad Fatoum
a.fatoum at barebox.org
Thu Nov 19 10:58:12 PST 2026
of_device_create_on_demand() rescans the parent device, so a bus like
I2C or SPI registers the device for the requested node. The hooks
register every child that has no device yet though, not only the one
asked for.
Let's pass the node along, so the hooks can restrict themselves to it.
NULL still means all children. The I2C and SPI hooks ignore the node
for now, so there is no functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
drivers/i2c/i2c.c | 2 +-
drivers/of/platform.c | 4 ++--
drivers/spi/spi.c | 2 +-
include/device.h | 5 +++--
include/driver.h | 4 ++--
5 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 407c4db8a76a..cfc340736309 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -485,7 +485,7 @@ int of_i2c_register_devices_by_node(struct device_node *node)
return 0;
}
-static void i2c_hw_rescan(struct device *dev)
+static void i2c_hw_rescan(struct device *dev, struct device_node *np)
{
struct i2c_adapter *adap;
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 0346d87a2b61..12a1b759fc07 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -138,7 +138,7 @@ struct device *of_platform_device_create(struct device_node *np,
* devices.
*/
if (np->dev) {
- device_rescan(np->dev);
+ device_rescan(np->dev, NULL);
return np->dev;
}
@@ -450,7 +450,7 @@ static struct device *of_device_create_on_demand(struct device_node *np)
return NULL;
if (!np->dev && parent->dev)
- device_rescan(parent->dev);
+ device_rescan(parent->dev, np);
/* Create all parent devices needed for the requested device */
parent_dev = parent->dev ? : of_device_create_on_demand(parent);
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 53bcd22b8c56..b1806a2ea445 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -199,7 +199,7 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
}
}
-static void spi_controller_rescan(struct device *dev)
+static void spi_controller_rescan(struct device *dev, struct device_node *np)
{
struct spi_controller *ctrl;
diff --git a/include/device.h b/include/device.h
index 7abeed9c460f..34b45a9bb014 100644
--- a/include/device.h
+++ b/include/device.h
@@ -59,7 +59,8 @@ struct of_device_id;
* @dma_offset: DMA offset.
* @detect: For devices which take longer to probe, this is called when the driver
* should actually detect client devices.
- * @rescan: Callback to rescan the device.
+ * @rescan: Callback to rescan the device. If @np is not NULL, only the
+ * device for that child node needs to be created.
* @deferred_probe_reason: If a driver probe is deferred, this stores the last error.
*/
struct device {
@@ -119,7 +120,7 @@ struct device {
#endif
int (*detect)(struct device *);
- void (*rescan)(struct device *);
+ void (*rescan)(struct device *dev, struct device_node *np);
char *deferred_probe_reason;
};
diff --git a/include/driver.h b/include/driver.h
index a93da2e06f62..ec1f1ccfb85e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -98,10 +98,10 @@ static inline void put_device(struct device *dev) {}
void free_device_res(struct device *dev);
void free_device(struct device *dev);
-static inline void device_rescan(struct device *dev)
+static inline void device_rescan(struct device *dev, struct device_node *np)
{
if (dev->rescan)
- dev->rescan(dev);
+ dev->rescan(dev, np);
}
/* Iterate over a devices children
--
2.47.3
More information about the barebox
mailing list