已aw9523b 為例
模組初始化,解除安裝入口
module_init(aw9523b_init);
module_exit(aw9523b_exit);
static int __init aw9523b_init(void)
else
}static void __exit aw9523b_exit(void)
呼叫i2c_driver 的結構體,填寫name,match_table,相關prob函式
static struct i2c_driver aw9523b_driver=,
.probe=aw9523b_driver_probe, //匹配成功後會呼叫probe函式
.id_table=aw9523b_i2c_id, //id匹配
};
宣告 i2c相關結構體 的名字
static struct i2c_client *new_client; //i2c_master_send 中作為引數使用
static const struct i2c_device_id aw9523b_i2c_id=,{}}; //i2c_driver 用
#ifdef config_of //和dtb匹配時
static const struct of_device_id aw9523b_of_match=,
{},};#endif
prob中寫位址等
static int aw9523b_driver_probe(struct i2c_client *client, const struct i2c_device_id *id)
讀寫函式
int aw9523b_read_byte(unsigned char cmd, unsigned char *returndata)
; char readdata = 0;
int ret = 0;
//mutex_lock(&aw9523b_i2c_access);
new_client->ext_flag =
((new_client->ext_flag) & i2c_mask_flag) | i2c_wr_flag | i2c_direction_flag;
cmd_buf[0] = cmd;
ret = i2c_master_send(new_client, &cmd_buf[0], (1 << 8 | 1));
if (ret < 0)
readdata = cmd_buf[0];
*returndata = readdata;
new_client->ext_flag = 0;
//mutex_unlock(&aw9523b_i2c_access);
return 1;
}int aw9523b_write_byte(unsigned char cmd, unsigned char writedata)
; int ret = 0;
//mutex_lock(&aw9523b_i2c_access);
write_data[0] = cmd;
write_data[1] = writedata;
new_client->ext_flag = ((new_client->ext_flag) & i2c_mask_flag) | i2c_direction_flag;
ret = i2c_master_send(new_client, write_data, 2);
if (ret < 0)
new_client->ext_flag = 0;
//mutex_unlock(&aw9523b_i2c_access);
return 1;
}
I2C匯流排架構 之 裝置驅動
i2c裝置驅動是i2c框架中最接近應用層的,其上接應用層,下接i2c核心。也是驅動開發人員需要實現的 在此驅動中我們只需負責以下步驟 以ap3216c為例 a.新增硬體資訊 裝置樹 b.搭建驅動框架 c.構建i2c driver,並註冊到linux d.註冊字元裝置 e.向應用層提供i2c裝置操作介...
i2c裝置驅動
1,i2c 裝置註冊 static struct i2c board info i2c2 devices i2c裝置一般在板級 中註冊 static void msm8916 add i2c deivces void 2,i2c驅動註冊 include static const struct i2c...
I2C裝置驅動流程
一 i2c裝置 驅動流程 1 i2c register board info 定義i2c 器件資訊 name,address,etc.static struct i2c board info initdata pi2c board info i2c register board info 1,arr...