/kernel-5.10/drivers/i2c/i2c-core-base.c 是 I2C 的核心部分,I2C 核心提供了一些與具體硬件無關的 API 函數
1、i2c_adapter 注冊/注銷函數
int i2c_add_adapter(struct i2c_adapter *adapter)//自動分配 adapter ID
int i2c_add_numbered_adapter(struct i2c_adapter *adap)//指定 ID
void i2c_del_adapter(struct i2c_adapter * adap)
2、i2c_driver 注冊/注銷函數
int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
int i2c_add_driver(struct i2c_driver *driver)
void i2c_del_driver(struct i2c_driver *driver)
上述 API 一般需要在 init/exit 或者 probe/remove 函數中成對使用。
設備和驅動的匹配過程也是由 I2C 總線完成的,I2C 總線的數據結構為 i2c_bus_type,定義在 /kernel-5.10/drivers/i2c/i2c-core-base.c 文件,i2c_bus_type 內容如下:
struct bus_type i2c_bus_type = {
.name = "i2c",
.match = i2c_device_match,
.probe = i2c_device_probe,
.remove = i2c_device_remove,
.shutdown = i2c_device_shutdown,
};
.match 就是 I2C 總線的設備和驅動匹配函數,在這里就是 i2c_device_match 這個函數,此函數內容如下:
static int i2c_device_match(struct device *dev, struct device_driver *drv)
{
struct i2c_client *client = i2c_verify_client(dev);
struct i2c_driver *driver;
if (!client)
return 0;
/* Attempt an OF style match */
if (of_driver_match_device(dev, drv))
return 1;
/* Then ACPI style match */
if (acpi_driver_match_device(dev, drv))
return 1;
driver = to_i2c_driver(drv);
/* match on an id table if there is one */
if (driver- >id_table)
return i2c_match_id(driver- >id_table, client) != NULL;
return 0;
}
of_driver_match_device 函數用于完成設備樹設備和驅動匹配。比較 I2C 設備節點的 compatible 屬性和 of_device_id 中的 compatible 屬性是否相等,如果相當的話就表示 I2C 設備和驅動匹配。
acpi_driver_match_device 函數用于 ACPI 形式的匹配。
i2c_match_id 函數用于傳統的、無設備樹的 I2C 設備和驅動匹配過程。比較 I2C 設備名字和 i2c_device_id 的 name 字段是否相等,相等的話就說明 I2C 設備和驅動匹配。
-
I2C
+關注
關注
28文章
1513瀏覽量
126458 -
函數
+關注
關注
3文章
4364瀏覽量
63809
發布評論請先 登錄
相關推薦
I2C總線驅動和設備驅動
i2c總線ppt(I2C總線器件應用)
I2C Guid I2C指南
詳細講解RT-Thread I2C設備驅動框架及相關函數

Linux的I2C驅動架構
I2C系列的合集,可以系統學習I2C協議
嵌入式linux應用讀寫i2c示例

MSP430F5529 DriverLib 庫函數學習筆記(十一)I2C / IIC

硬件I2C與模擬I2C

評論