Linux输入子系统分析 (1) -- 输入子系统初始化

[linux-3.0 http://lxr.linux.no/#linux+v3.0]

<drivers/input/input.c>

2414 static int __init input_init(void)
2415 {
2416         int err;
2417                    
2418         err = class_register(&input_class);
2419         if (err) {
2420                 pr_err("unable to register input_dev class\n");
2421                 return err;
2422         }
2423 
2424         err = input_proc_init();
2425         if (err)
2426                 goto fail1;
2427 
2428         err = register_chrdev_region(MKDEV(INPUT_MAJOR, 0),
2429                                      INPUT_MAX_CHAR_DEVICES, "input");
2430         if (err) {
2431                 pr_err("unable to register char major %d", INPUT_MAJOR);
2432                 goto fail2;
2433         }
2434 
2435         return 0;
2436 
2437  fail2: input_proc_exit();
2438  fail1: class_unregister(&input_class);
2439         return err;
2440 }
2441 
2442 static void __exit input_exit(void)
2443 {
2444         input_proc_exit();
2445         unregister_chrdev_region(MKDEV(INPUT_MAJOR, 0),
2446                                  INPUT_MAX_CHAR_DEVICES);
2447         class_unregister(&input_class);
2448 }
2449 
2450 subsys_initcall(input_init);
2451 module_exit(input_exit);


input_init的主要作用:

2143行,创建“input"类,即在/sys/classs/下面建一个input的子目录。

    input_class的定义如下:

1632struct class input_class = {
1633 .name = "input",
1634 .devnode = input_devnode,
1635};
1636EXPORT_SYMBOL_GPL(input_class);

2149行,创建proc文件系统中创建input目录,存放于/proc/bus/下面(/proc/bus/input),而后在此目录下创建devices和handlers文件

    通过读取devices,可以知道系统中的输入设备。

-------------------------------------------------------------------------------------------

# cat /proc/bus/input/devices

I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="AT42QT1070 QTouch Sensor"
P: Phys=
S: Sysfs=/devices/platform/i2c-gpio.0/i2c-0/0-001b/input/input0
U: Uniq=
H: Handlers=kbd event0
B: PROP=0
B: EV=3
B: KEY=8fc

I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="Atmel maXTouch Touchscreen"
P: Phys=
S: Sysfs=/devices/platform/i2c-gpio.0/i2c-0/0-004a/input/input1
U: Uniq=
H: Handlers=mouse0 event1
B: PROP=0
B: EV=b
B: KEY=400 0 0 0 0 0 0 0 0 0 0
B: ABS=610000 1000003

-------------------------------------------------------------------------------------------

    通过读取handlers,可以知道系统中注册了那些处理函数。

-------------------------------------------------------------------------------------------

# cat /proc/bus/input/handlers

N: Number=0 Name=kbd
N: Number=1 Name=mousedev Minor=32
N: Number=2 Name=evdev Minor=64

-------------------------------------------------------------------------------------------

2153行,注册一个字符类型设备及其操作函数。

2159行,如果上面操作没有错误,完美退出。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值