i2c_add_driver
i2c_register_driver
driver->driver.bus = &i2c_bus_type;
driver_register(&driver->driver);
list_for_each_entry(adapter, &adapters, list) {
driver->attach_adapter(adapter);
i2c_probe(adapter, &addr_data, eeprom_detect);
i2c_probe_address // 发出S信号,发出设备地址(来自addr_data)
i2c_smbus_xfer
i2c_smbus_xfer_emulated
i2c_transfer
adap->algo->master_xfer // s3c24xx_i2c_xfer
怎么写I2C设备驱动程序?
-
分配一个i2c_driver结构体
-
设置
attach_adapter // 它直接调用 i2c_probe(adap, 设备地址, 发现这个设备后要调用的函数);
detach_client // 卸载这个驱动后,如果之前发现能够支持的设备,则调用它来清理 -
注册:i2c_add_driver
测试1th:
cp at24cxx.ko /work/nfs_root/first_fs
开发板重启
nfs 30000000 192.168.31.202:/work/nfs_root/uImage_dm9000c
bootm 30000000
使用新内核启动
mount -t nfs -o nolock,vers=2 192.168.31.202:/work/nfs_root/first_fs /mnt
cd /mnt/
- insmod at24cxx.ko
观察输出信息
rmmod at24cxx - 修改normal_addr里的0x50为0x60
编译加载,观察输出信息
ls /dev/at24cxx -l
insmod at24cxx.ko
./i2c_test
./i2c_test r addr
./i2c_test w addr val
./i2c_test r 0
data: , 0, 0x 0
./i2c_test r 1
data: , 1, 0x 1
./i2c_test w 0 0x61
./i2c_test r 0
data: , 0, 0x 0
./i2c_test w 100 55
./i2c_test r 100
data: d, 100, 0x64