Skip to content

Commit e3e10fd

Browse files
committed
[drivers] Fix OFW bus conflict and prevent duplicate device creation
Problem: When enumerating device tree nodes, platform bus and native buses (I2C/SPI) may create duplicate devices for the same OFW node, causing cross-bus conflicts. This triggers assertion failure '(dev->bus != new_bus)' in rt_bus_reload_driver_device() during boot on minimal DM-enabled systems. Root Cause: 1. Platform bus tries to reload devices that already belong to other buses by calling rt_bus_reload_driver_device(dev->bus, dev), which violates the API contract (requires dev->bus != new_bus). 2. Native buses (I2C/SPI) do not mark OFW nodes as occupied, so platform bus creates duplicate platform devices for I2C/SPI client nodes. Solution: 1. components/drivers/core/platform_ofw.c: Return RT_EOK when np->dev exists, letting the native bus handle device lifecycle instead of cross-bus reload. 2. components/drivers/i2c/dev_i2c_bus.c: Mark i2c_client_np->dev during scan to prevent platform bus from duplicating I2C client devices. 3. components/drivers/spi/dev_spi_bus.c: Mark spi_dev_np->dev during scan to prevent platform bus from duplicating SPI devices. Tested on Spacemit K1 RISC-V platform with minimal DM configuration. Signed-off-by: lhxj <[email protected]>
1 parent 754d517 commit e3e10fd

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

components/drivers/core/platform_ofw.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,14 @@ rt_err_t rt_platform_ofw_request(struct rt_ofw_node *np)
223223

224224
if (dev)
225225
{
226-
/* Was create */
227-
if (dev->drv)
228-
{
229-
/* Was probe OK */
230-
err = RT_EOK;
231-
}
232-
else
233-
{
234-
err = rt_bus_reload_driver_device(dev->bus, dev);
235-
}
226+
/*
227+
* Device was already created (np->dev != NULL).
228+
* - If it's already probed (dev->drv != NULL), nothing to do.
229+
* - If not yet probed (dev->drv == NULL), it belongs to its native bus
230+
* (e.g. I2C/SPI) which will handle probing; platform bus should not reload
231+
* or transfer it, to avoid cross-bus conflicts.
232+
*/
233+
err = RT_EOK;
236234
}
237235
else
238236
{

components/drivers/i2c/dev_i2c_bus.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ void i2c_bus_scan_clients(struct rt_i2c_bus_device *bus)
6363

6464
rt_dm_dev_set_name(&client->parent, "%s", client->name);
6565

66+
/* Mark this OFW node as taken to prevent platform bus from creating duplicate device */
67+
i2c_client_np->dev = &client->parent;
68+
6669
rt_i2c_device_register(client);
6770

6871
if (i2c_client_np != child_np)

components/drivers/spi/dev_spi_bus.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ void spi_bus_scan_devices(struct rt_spi_bus *bus)
6969
continue;
7070
}
7171

72+
/* Mark this OFW node as taken to prevent platform bus from creating duplicate device */
73+
spi_dev_np->dev = &spi_dev->parent;
74+
7275
rt_spi_device_register(spi_dev);
7376
}
7477
}

0 commit comments

Comments
 (0)