IIC驱动程序分析(三)
来源:互联网 发布:c语言编程我爱你 编辑:程序博客网 时间:2024/05/15 02:42
上面两个程序我们主要实现了设备的识别,但是我们发现当卸载驱动的时候并没有相关的打印信息,这时怎么回事儿呢?其实原因我们之前已经提到过了,那是因为我们在i2c_probe(adapter, &addr_data, at24cxx_detect);的功能函数at24cxx_detect里面并没有建立设备、驱动、适配器的联系,因为没有建立联系,所以卸载的时候当然不会解除联系了!那么具体应该怎么做呢?我们来看代码:
#include <linux/kernel.h>#include <linux/init.h>#include <linux/module.h>#include <linux/slab.h>#include <linux/jiffies.h>#include <linux/i2c.h>#include <linux/mutex.h>static unsigned short ignore[] = { I2C_CLIENT_END };static unsigned short normal_addr[] = { 0x50, I2C_CLIENT_END }; static unsigned short force_addr[] = {ANY_I2C_BUS, 0x60, I2C_CLIENT_END};static unsigned short * forces[] = {force_addr, NULL}; static struct i2c_client_address_data addr_data = { .normal_i2c = normal_addr, .probe = ignore, .ignore = ignore,};static struct i2c_driver at24cxx_driver;static int at24cxx_detect(struct i2c_adapter *adapter, int address, int kind){ struct i2c_client *new_client; printk("at24cxx_detect\n"); /* 构构一个i2c_client结构体: 以后收改数据时会用到它 */ new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);//分配 new_client->addr = address;//这是设备地址 new_client->adapter = adapter;这时适配器 new_client->driver = &at24cxx_driver;//这是驱动 strcpy(new_client->name, "at24cxx");//这是名字 i2c_attach_client(new_client);//添加联系 return 0;}static int at24cxx_attach(struct i2c_adapter *adapter){ return i2c_probe(adapter, &addr_data, at24cxx_detect);}static int at24cxx_detach(struct i2c_client *client){ printk("at24cxx_detach\n"); i2c_detach_client(client); kfree(i2c_get_clientdata(client)); return 0;}static struct i2c_driver at24cxx_driver = { .driver = { .name = "at24cxx", }, .attach_adapter = at24cxx_attach, .detach_client = at24cxx_detach,};static int at24cxx_init(void){ i2c_add_driver(&at24cxx_driver); return 0;}static void at24cxx_exit(void){ i2c_del_driver(&at24cxx_driver);}module_init(at24cxx_init);module_exit(at24cxx_exit);MODULE_LICENSE("GPL");
这样的话卸载的时候就会有打印信息了!
- IIC驱动程序分析(三)
- IIC驱动程序分析(三)
- IIC驱动程序分析(一)
- IIC驱动程序分析(二)
- IIC驱动程序分析(一)
- IIC驱动程序分析(二)
- IIC设备驱动程序(三)————IIC设备驱动程序的层次结构
- IIC设备驱动程序(四)————IIC总线驱动程序框架分析
- IIC总线驱动程序框架分析
- IIC总线驱动程序框架分析
- 430模拟IIC(I2C)驱动程序
- IIC设备驱动程序介绍
- IIC设备驱动程序
- IIC设备驱动程序
- IIC设备驱动程序
- iic三
- NAND控制器驱动程序分析(三)
- CC2430应用(一)-- AT24CXX的驱动程序 IIC 调试例程
- 正则表达式语法
- strcpy 困境
- RGB颜色对照表
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- 一些数学题目
- IIC驱动程序分析(三)
- fatal error LNK1295: '/MANIFESTUAC' not compatible with '/DRIVER' specification
- 每个程序员都应该知道的8个Linux命令
- ashx登陆
- 进程隐藏与进程保护(SSDT Hook 实现)(一)
- asp生成pdf格式文件的方法
- Android Makefile 具体是 如何识别 TARGET_PRODUCT 变量
- 在eclipse中调试launcher模块以及已编译launcher源码两份
- MFC进度条编程控制