HdfDriverEntry驱动入口数据结构:
struct HdfDriverEntry {
int moduleVersion;
int32_t (*Bind)(struct HdfDeviceObject *device);
int32_t (*I2cManagerInit)(struct HdfDeviceObject *device);
void (*Release)(struct HdfDeviceObject *device);
char *moduleName;
};
内核层驱动入口:g_i2cManagerEntry:
struct HdfDriverEntry g_i2cManagerEntry = {
.moduleVersion = 1,
.Bind = I2cManagerBind,
.Init = I2cManagerInit,
.Release = I2cManagerRelease,
.moduleName = "HDF_PLATFORM_I2C_MANAGER",
};
内核层驱动入口,会维护一个静态全局的 i2c 管理器 g_i2cManager ,数据结构为 I2cManager:
struct I2cManager {
struct IDeviceIoService service;
struct HdfDeviceObject *device;
struct I2cCntlr *cntlrs[I2C_BUS_MAX];
struct OsalMutex lock;
};
static struct I2cManager *g_i2cManager = NULL;
内核层驱动的 bind 函数,会将输入的 device 指针,绑定到 i2c 管理器 g_i2cManager 上面。
struct i2c_adapter :
根据 struct device dev 地址,加上 offset,可以获取到 struct i2c_adapter 的地址。
struct i2c_adapter {
struct module *owner;
unsigned int class; /* classes to allow probing for */
const struct i2c_algorithm *algo; /* the algorithm to access the bus */
void *algo_data;
/* data fields that are valid for all devices */
const struct i2c_lock_operations *lock_ops;
struct rt_mutex bus_lock;
struct rt_mutex mux_lock;
int timeout; /* in jiffies */
int retries;
struct device dev; /* the adapter device */
unsigned long locked_flags; /* owned by the I2C core */
#define I2C_ALF_IS_SUSPENDED 0
#define I2C_ALF_SUSPEND_REPORTED 1
int nr;
char name[48];
struct completion dev_released;
struct mutex userspace_clients_lock;
struct list_head userspace_clients;
struct i2c_bus_recovery_info *bus_recovery_info;
const struct i2c_adapter_quirks *quirks;
struct irq_domain *host_notify_domain;
};