linux驱动子系统之输入子系统(2)

linux驱动子系统之输入子系统(2)

2. 输入核心层

2.1 概述

核心层对下提供了设备驱动层的编程接口,对上有提供了事件处理层的编程接口。input.c是核心层实现的文件。

 

2.2 驱动代码分析

l  初始化模块

static int __init input_init(void)

{

         err= class_register(&input_class);

 

         err= input_proc_init();

 

         err= register_chrdev(INPUT_MAJOR, "input", &input_fops);

}

初始化模块完成了三件事情:注册input类,导出设备信息到proc,注册input字符设备

 

l  File_operations

static const struct file_operationsinput_fops = {

         .owner= THIS_MODULE,

         .open= input_open_file,

         .llseek= noop_llseek,

};

很奇怪,怎么就只实现了open。不急,我们先来看下open函数

static int input_open_file(struct inode*inode, struct file *file)

{

         handler= input_table[iminor(inode) >> 5];

         if(handler)

                   new_fops= fops_get(handler->fops);

 

         old_fops= file->f_op;

         file->f_op= new_fops;

 

         err= new_fops->open(inode, file);

         fops_put(old_fops);

}

原来是重定向到了事件处理层实现的fops,因为对不同的事件处理的方法都不同



  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值