[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>
This commit is contained in:
GuEe-GUI
2025-12-01 16:46:17 +08:00
committed by R b b666
parent e5db582cfa
commit 798c84647c
3 changed files with 22 additions and 1 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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 */
/**