From c74780ac27267e5baa649f39574c5065f1ca26a8 Mon Sep 17 00:00:00 2001 From: GuEe-GUI <2991707448@qq.com> Date: Mon, 1 Dec 2025 16:46:17 +0800 Subject: [PATCH] [DM/I2C] Update I2C for DM 1. Add get id match data API. 2. Set I2C device name default before adding to bus. 3. Add Kconfig import for DM. Signed-off-by: GuEe-GUI <2991707448@qq.com> --- components/drivers/i2c/Kconfig | 6 +++++- components/drivers/i2c/dev_i2c_bus.c | 2 ++ components/drivers/include/drivers/dev_i2c.h | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/components/drivers/i2c/Kconfig b/components/drivers/i2c/Kconfig index bb4c90dba82..d24d24b9c41 100644 --- a/components/drivers/i2c/Kconfig +++ b/components/drivers/i2c/Kconfig @@ -1,4 +1,4 @@ -config RT_USING_I2C +menuconfig RT_USING_I2C bool "Using I2C device drivers" default n @@ -241,3 +241,7 @@ if RT_USING_I2C endif endif endif + +if RT_USING_DM && RT_USING_I2C + osource "$(SOC_DM_I2C_DIR)/Kconfig" +endif diff --git a/components/drivers/i2c/dev_i2c_bus.c b/components/drivers/i2c/dev_i2c_bus.c index 8a524715043..9e202dbd9a7 100644 --- a/components/drivers/i2c/dev_i2c_bus.c +++ b/components/drivers/i2c/dev_i2c_bus.c @@ -61,6 +61,8 @@ void i2c_bus_scan_clients(struct rt_i2c_bus_device *bus) client->bus = bus; client->client_addr = client_addr; + rt_dm_dev_set_name(&client->parent, "%s", client->name); + rt_i2c_device_register(client); if (i2c_client_np != child_np) diff --git a/components/drivers/include/drivers/dev_i2c.h b/components/drivers/include/drivers/dev_i2c.h index 3f0e5bb41c2..e704d512e0a 100644 --- a/components/drivers/include/drivers/dev_i2c.h +++ b/components/drivers/include/drivers/dev_i2c.h @@ -286,6 +286,21 @@ rt_err_t rt_i2c_driver_register(struct rt_i2c_driver *driver); rt_err_t rt_i2c_device_register(struct rt_i2c_client *client); #define RT_I2C_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, i2c, BUILIN) + +/** + * @brief Get ID match data from I2C client + * + * This function retrieves the driver-specific data associated with the matched + * device ID or OFW node ID for the I2C client. + * + * @param client the I2C client device + * + * @return const void* pointer to the ID match data, or RT_NULL if no match data exists + */ +rt_inline const void *rt_i2c_client_id_data(struct rt_i2c_client *client) +{ + return client->id ? client->id->data : (client->ofw_id ? client->ofw_id->data : RT_NULL); +} #endif /* RT_USING_DM */ /**