[objc]
1. /**
2. * input_register_device - register device with input core
3. * @dev: device to be registered
4. *
5. * This function registers device with input core. The device must be
6. * allocated with input_allocate_device() and all it's capabilities
7. * set up before registering.
8. * If function fails the device must be freed with input_free_device().
9. * Once device has been successfully registered it can be unregistered
10. * with input_unregister_device(); input_free_device() should not be
11. * called in this case.
12. */
13.
14. int input_register_device(struct input_dev *dev)
15. {
16. static atomic_t input_no = ATOMIC_INIT(0);
17. //这个原子变量,代表总共注册的input设备,每注册一个加1,因为是静态变量,所以每次调用都不会清零的
18. struct input_handler *handler;
19. const charchar *path;
20. int error;
21.
22. __set_bit(EV_SYN, dev->evbit); //EN_SYN 这个是设备都要支持的事件类型,所以要设置
23.
24. /*
25. * If delay and period are pre-set by the driver, then autorepeating
26. * is handled by the driver itself and we don't do it in input.c.
27. */
28. // 这个内核定时器是为了重复按键而设置的
29. init_timer(&dev->timer);
30. if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
31. dev->timer.data = (long) dev;
32. dev->timer.function = input_repeat_key;
33. dev->rep[REP_DELAY] = 250;
34. dev->rep[REP_PERIOD] = 33;
35. //如果没有定义有关重复按键的相关值,就用内核默认的
36. }
37.
38. if (!dev->getkeycode)
39. dev->getkeycode = input_default_getkeycode;
40. if (!dev->setkeycode)
41. dev->setkeycode = input_default_setkeycode;
42. //以上设置的默认函数由input核心提供
43. dev_set_name(&dev->dev, "input%ld",
44. (unsigned long) atomic_inc_return(&input_no) - 1);
45. //设置input_dev中device的名字,这个名字会在/class/input中出现
46. error = device_add(&dev->dev);
47. //将device加入到linux设备模型中去
48. if (error)
49. return error;
50.
51. path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
52. printk(KERN_INFO "input: %s as %s\n",
53. dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
54. kfree(path);
评论0
最新资源