下面说的这种方式其实和前面的很相似
1.在设备树文件中,设备所在的i2c总线下面定义好设备
&i2c0 {
status = "okay";
eeprom@50 {
compatible = "atmel,24c02";
reg = <0x50>;
};
};
驱动只需要增加一个of_match_table就可以了
/*
* i2c驱动是根据下面这个i2c_device_id表中的名字来匹配,client的名字的
*/
static const struct i2c_device_id at24cxx_id_table[] = {
{ "at24cxx", 0 },
{}
};
/*
* 有限使用设备树中的compatible文件来匹配,匹配不上才使用上面的
*/
static const struct of_device_id at24_of_match[] = {
{ .compatible = "atmel,24c02", .data = NULL },
{},
};
static struct i2c_driver at24cxx_driver = {
.driver = {
.name = "at24cxx", /* 这个随便起名字 */
.of_match_table = at24_of_match,
},
.probe = at24cxx_probe,
.remove = at24c