Chinaunix首页 | 论坛 | 博客
  • 博客访问: 670838
  • 博文数量: 207
  • 博客积分: 1743
  • 博客等级: 上尉
  • 技术积分: 2044
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-20 14:36
文章分类

全部博文(207)

文章存档

2016年(24)

2015年(10)

2014年(50)

2013年(45)

2012年(78)

分类: LINUX

2014-06-23 11:19:51

一、input子系统简介

1.1、input子系统原理

        在Linux中,输 入子系统是由输入子系统设备驱动层、输入子系统核心层(Input Core)和输入子系统事件处理层(Event Handler)组成。其中设备驱动层提供对硬件各寄存器的读写访问和将底层硬件对用户输入访问的响应转换为标准的输入事件,再通过核心层提交给事件处理 层;而核心层对下提供了设备驱动层的编程接口,对上又提供了事件处理层的编程接口;而事件处理层就为我们用户空间的应用程序提供了统一访问设备的接口和驱 动层提交来的事件处理。所以这使得我们输入设备的驱动部分不在用关心对设备文件的操作,而是要关心对各硬件寄存器的操作和提交的输入事件。下面用图形来描述一下这三者的关系!
 
        从上图可以看出,对于设备驱动层,主要涉及结构体input_dev,对于核心层,主要涉及结构体handle,而对于事件层涉及到了结构体handler。接下来会对这三个结构体进行详细的描述。
        现在我们从设备模型来看下input子系统所处的位置: 

        从上图可以看出,input处于kernel层,input向下操作设备寄存器,向上提供了设备驱动程序操作的设备节点。

1.2、注册input核

        这里所说的input核心,就是指input.c文件中提供的函数,包括1.1中涉及三个结构体的操作函数。
        在input.c文件中,有模块初始化和退出函数,如

点击(此处)折叠或打开

  1. struct class input_class = {
  2.     .name        = "input",
  3.     .devnode    = input_devnode,
  4. };
  5. static int __init input_init(void)
  6. {
  7.     int err;

  8.     err = class_register(&input_class);
  9.     if (err) {
  10.         pr_err("unable to register input_dev class\n");
  11.         return err;
  12.     }

  13.     err = input_proc_init();
  14.     if (err)
  15.         goto fail1;

  16.     err = register_chrdev(INPUT_MAJOR, "input", &input_fops);
  17.     if (err) {
  18.         pr_err("unable to register char major %d", INPUT_MAJOR);
  19.         goto fail2;
  20.     }

  21.     return 0;

  22.  fail2:    input_proc_exit();
  23.  fail1:    class_unregister(&input_class);
  24.     return err;
  25. }
  26. static void __exit input_exit(void)
  27. {
  28.     input_proc_exit();
  29.     unregister_chrdev(INPUT_MAJOR, "input");
  30.     class_unregister(&input_class);
  31. }
  32. subsys_initcall(input_init);
  33. module_exit(input_exit);

        说明:

        1) 这里初始化使用的是subsys_initcall,具有较高优先级。

        2) 在初始化中,首先注册了input类,实际就是在/sys/class目录下建立一个input目录。

        3) input的proc文件系统初始化。

        4) 静态注册设备号。

二、input_dev设备相关函数

        在上面“输入子系统图”中,最左边是设备驱动层,其中涉及结构体input_dev,现在就来讲述其中涉及到的结构体和操作函数。

2.1、input_dev结构体简述

点击(此处)折叠或打开

  1. #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  2. #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
  3. struct input_dev {
  4.     const char *name;
  5.     const char *phys;
  6.     const char *uniq;
  7.     struct input_id id;

  8.     unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];

  9.     unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
  10.     unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
  11.     unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
  12.     unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
  13.     unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
  14.     unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
  15.     unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
  16.     unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
  17.     unsigned long swbit[BITS_TO_LONGS(SW_CNT)];

  18.     unsigned int hint_events_per_packet;

  19.     unsigned int keycodemax;
  20.     unsigned int keycodesize;
  21.     void *keycode;

  22.     int (*setkeycode)(struct input_dev *dev,
  23.              const struct input_keymap_entry *ke,
  24.              unsigned int *old_keycode);
  25.     int (*getkeycode)(struct input_dev *dev,
  26.              struct input_keymap_entry *ke);

  27.     struct ff_device *ff;

  28.     unsigned int repeat_key;
  29.     struct timer_list timer;

  30.     int rep[REP_CNT];

  31.     struct input_mt_slot *mt;
  32.     int mtsize;
  33.     int slot;
  34.     int trkid;

  35.     struct input_absinfo *absinfo;

  36.     unsigned long key[BITS_TO_LONGS(KEY_CNT)];
  37.     unsigned long led[BITS_TO_LONGS(LED_CNT)];
  38.     unsigned long snd[BITS_TO_LONGS(SND_CNT)];
  39.     unsigned long sw[BITS_TO_LONGS(SW_CNT)];

  40.     int (*open)(struct input_dev *dev);
  41.     void (*close)(struct input_dev *dev);
  42.     int (*flush)(struct input_dev *dev, struct file *file);
  43.     int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);

  44.     struct input_handle __rcu *grab;

  45.     spinlock_t event_lock;
  46.     struct mutex mutex;

  47.     unsigned int users;
  48.     bool going_away;

  49.     bool sync;

  50.     struct device dev;

  51.     struct list_head    h_list;
  52.     struct list_head    node;
  53. };

        说明:

        1) 结构体中包括名称、id和链表等。

        2) 结构体中有很多数组,数组成员大小使用宏BITS_TO_LONGS计算。

        3) 因为这些数组中,每个成员中的一位代表一种类型,所以此处就是根据其支持最多的类型,计算出数组中需要几个成员。

2.2、分配input_dev设备函数:input_allocate_device()

点击(此处)折叠或打开

  1. struct input_dev *input_allocate_device(void)
  2. {
  3.     struct input_dev *dev;

  4.     dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
  5.     if (dev) {
  6.         dev->dev.type = &input_dev_type;
  7.         dev->dev.class = &input_class;
  8.         device_initialize(&dev->dev);
  9.         mutex_init(&dev->mutex);
  10.         spin_lock_init(&dev->event_lock);
  11.         INIT_LIST_HEAD(&dev->h_list);
  12.         INIT_LIST_HEAD(&dev->node);

  13.         __module_get(THIS_MODULE);
  14.     }

  15.     return dev;
  16. }

        说明:

        1) 首先申请了结构体input_dev内存。

        2) 如果申请成功,对其成员进行初始化,包括对设备的类型和类初始化,设备的类属于input,则其会显示在/sys/class/input目录下。

        3) 对input设备中的设备进行初始化。

        4) 初始化互斥锁和链表。

2.3、注册input_dev设备函数:input_register_device()

点击(此处)折叠或打开

  1. int input_register_device(struct input_dev *dev)
  2. {
  3.     static atomic_t input_no = ATOMIC_INIT(0);
  4.     struct input_handler *handler;
  5.     const char *path;
  6.     int error;

  7.     /* Every input device generates EV_SYN/SYN_REPORT events. */
  8.     __set_bit(EV_SYN, dev->evbit);

  9.     /* KEY_RESERVED is not supposed to be transmitted to userspace. */
  10.     __clear_bit(KEY_RESERVED, dev->keybit);

  11.     /* Make sure that bitmasks not mentioned in dev->evbit are clean. */
  12.     input_cleanse_bitmasks(dev);

  13.     if (!dev->hint_events_per_packet)
  14.         dev->hint_events_per_packet =
  15.                 input_estimate_events_per_packet(dev);

  16.     /*
  17.      * If delay and period are pre-set by the driver, then autorepeating
  18.      * is handled by the driver itself and we don't do it in input.c.
  19.      */
  20.     init_timer(&dev->timer);
  21.     if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
  22.         dev->timer.data = (long) dev;
  23.         dev->timer.function = input_repeat_key;
  24.         dev->rep[REP_DELAY] = 250;
  25.         dev->rep[REP_PERIOD] = 33;
  26.     }

  27.     if (!dev->getkeycode)
  28.         dev->getkeycode = input_default_getkeycode;

  29.     if (!dev->setkeycode)
  30.         dev->setkeycode = input_default_setkeycode;

  31.     dev_set_name(&dev->dev, "input%ld",
  32.          (unsigned long) atomic_inc_return(&input_no) - 1);

  33.     error = device_add(&dev->dev);
  34.     if (error)
  35.         return error;

  36.     path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
  37.     pr_info("%s as %s\n",
  38.         dev->name ? dev->name : "Unspecified device",
  39.         path ? path : "N/A");
  40.     kfree(path);

  41.     error = mutex_lock_interruptible(&input_mutex);
  42.     if (error) {
  43.         device_del(&dev->dev);
  44.         return error;
  45.     }

  46.     list_add_tail(&dev->node, &input_dev_list);

  47.     list_for_each_entry(handler, &input_handler_list, node)
  48.         input_attach_handler(dev, handler);

  49.     input_wakeup_procfs_readers();

  50.     mutex_unlock(&input_mutex);

  51.     return 0;
  52. }

        说明:

        1) 首先设置,支持同步。

        2) 初始化延时定时器,初始化其成员变量。

        3) 初始化设备dev成员。

        4) 将input设备中的链表链入input设备全局链表input_dev_list中。

        5) 遍历链表input_handler_list,由于input设备注册先执行,所以此处input_handler链表为空,不执行input_attach_handler(dev, handler);
        接下来看下定时器到时执行函数input_repeat_key():

点击(此处)折叠或打开

  1. /*
  2.  * Generate software autorepeat event. Note that we take
  3.  * dev->event_lock here to avoid racing with input_event
  4.  * which may cause keys get "stuck".
  5.  */
  6. static void input_repeat_key(unsigned long data)
  7. {
  8.     struct input_dev *dev = (void *) data;
  9.     unsigned long flags;

  10.     spin_lock_irqsave(&dev->event_lock, flags);

  11.     if (test_bit(dev->repeat_key, dev->key) &&
  12.      is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {

  13.         input_pass_event(dev, EV_KEY, dev->repeat_key, 2);

  14.         if (dev->sync) {
  15.             /*
  16.              * Only send SYN_REPORT if we are not in a middle
  17.              * of driver parsing a new hardware packet.
  18.              * Otherwise assume that the driver will send
  19.              * SYN_REPORT once it's done.
  20.              */
  21.             input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
  22.         }

  23.         if (dev->rep[REP_PERIOD])
  24.             mod_timer(&dev->timer, jiffies +
  25.                     msecs_to_jiffies(dev->rep[REP_PERIOD]));
  26.     }

  27.     spin_unlock_irqrestore(&dev->event_lock, flags);
  28. }
        说明:
        1) 在触摸屏中,该函数在持续触摸状态下会被调用。即如果触摸屏一直被按下,那么每隔定时时间到达,此函数即被执行。
        2) 首先上自旋锁,保护临界区。
        3) 判断是否支持按键事件。
        4) 报告按键值,如果此次支持同步,向应用层报告同步事件。
        5) 如果设置了定时器重新启动周期,那么就重新启动定时器。

2.4、注销input设备函数input_unregister_device()

点击(此处)折叠或打开

  1. void input_unregister_device(struct input_dev *dev)
  2. {
  3.     struct input_handle *handle, *next;

  4.     input_disconnect_device(dev);

  5.     mutex_lock(&input_mutex);

  6.     list_for_each_entry_safe(handle, next, &dev->h_list, d_node)
  7.         handle->handler->disconnect(handle);
  8.     WARN_ON(!list_empty(&dev->h_list));

  9.     del_timer_sync(&dev->timer);
  10.     list_del_init(&dev->node);

  11.     input_wakeup_procfs_readers();

  12.     mutex_unlock(&input_mutex);

  13.     device_unregister(&dev->dev);
  14. }

        说明:

        1) 注销函数是注册函数的相反过程。

        2) 主要就是删除注销函数中申请的资源。
        3) 调用handler中注册的断开函数。

三、handler相关函数

3.1、handler结构体简述

        handler结构体内容如下:

点击(此处)折叠或打开

  1. struct input_handler {

  2.     void *private;

  3.     void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
  4.     bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
  5.     bool (*match)(struct input_handler *handler, struct input_dev *dev);
  6.     int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
  7.     void (*disconnect)(struct input_handle *handle);
  8.     void (*start)(struct input_handle *handle);

  9.     const struct file_operations *fops;
  10.     int minor;
  11.     const char *name;

  12.     const struct input_device_id *id_table;

  13.     struct list_head    h_list;
  14.     struct list_head    node;
  15. }
        说明:
        1) handler结构体中定义了input回调函数,包括链接、释放事件函数等。
        2) 定义了应用层操作结构体
        3) 定义了设备的次设备号。
        4) 定义了input设备ID表。
        5) 定义了链表。

3.2、注册handler函数input_register_handler()

        在讨论handler之前,先看一下input.c文件中的全局数组变量:static struct input_handler *input_table[8];。

        从上可以看到,此数组共有8个成员。在Linux中,最多可以支持8个handler,每个handler最多可以支持32个次设备。也即 32*8=256。那么在注册input_handler时,其成员.minor必须是32的倍数,即:0、32、64、96、128、160、192和 224。这些数是一个handler的次设备号的基址。
        handler注册程序如下:

点击(此处)折叠或打开

  1. int input_register_handler(struct input_handler *handler)
  2. {
  3.     struct input_dev *dev;
  4.     int retval;

  5.     retval = mutex_lock_interruptible(&input_mutex);
  6.     if (retval)
  7.         return retval;

  8.     INIT_LIST_HEAD(&handler->h_list);

  9.     if (handler->fops != NULL) {
  10.         if (input_table[handler->minor >> 5]) {
  11.             retval = -EBUSY;
  12.             goto out;
  13.         }
  14.         input_table[handler->minor >> 5] = handler;
  15.     }

  16.     list_add_tail(&handler->node, &input_handler_list);

  17.     list_for_each_entry(dev, &input_dev_list, node)
  18.         input_attach_handler(dev, handler);

  19.     input_wakeup_procfs_readers();

  20.  out:
  21.     mutex_unlock(&input_mutex);
  22.     return retval;
  23. }

        说明:

        1) 首先锁定互斥锁,然后初始化handler中的链表。

        2) 判断handler中是否有fops成员,如果有就按照次设备作为标识保存handler。

        3) 将handler的链表插入handler的全局链表input_handler_list中。

        4) 遍历input_dev_list设备链表,由2.2中知道,此时input设备链表中已经有成员了。

        5) 关联input设备和handler,程序如下:

点击(此处)折叠或打开

  1. static int input_attach_handler(struct input_dev *dev, struct input_handler *handler)
  2. {
  3.     const struct input_device_id *id;
  4.     int error;

  5.     id = input_match_device(handler, dev);
  6.     if (!id)
  7.         return -ENODEV;

  8.     error = handler->connect(handler, dev, id);
  9.     if (error && error != -ENODEV)
  10.         pr_err("failed to attach handler %s to device %s, error: %d\n",
  11.          handler->name, kobject_name(&dev->dev.kobj), error);

  12.     return error;
  13. }

        说明:

        1) 首先查找匹配的设备。

        2) 调用handler的连接函数,也就是《input子系统(一)--GSC3280触摸屏驱动》中的tsdev_connect()函数。

        3) tsdev_connect()函数中使用input_register_handle()注册了handle。

四、handle相关函数

4.1、handle结构体简述

点击(此处)折叠或打开

  1. struct input_handle {

  2.     void *private;

  3.     int open;
  4.     const char *name;

  5.     struct input_dev *dev;
  6.     struct input_handler *handler;

  7.     struct list_head    d_node;
  8.     struct list_head    h_node;
  9. };
        说明:
        1) 结构体中定义私有指针和名称等。
        2) 定义input设备和handler指针。
        3) 定义链表。

4.2、handle注册函数input_register_handle():

点击(此处)折叠或打开

  1. int input_register_handle(struct input_handle *handle)
  2. {
  3.     struct input_handler *handler = handle->handler;
  4.     struct input_dev *dev = handle->dev;
  5.     int error;

  6.     /*
  7.      * We take dev->mutex here to prevent race with
  8.      * input_release_device().
  9.      */
  10.     error = mutex_lock_interruptible(&dev->mutex);
  11.     if (error)
  12.         return error;

  13.     /*
  14.      * Filters go to the head of the list, normal handlers
  15.      * to the tail.
  16.      */
  17.     if (handler->filter)
  18.         list_add_rcu(&handle->d_node, &dev->h_list);
  19.     else
  20.         list_add_tail_rcu(&handle->d_node, &dev->h_list);

  21.     mutex_unlock(&dev->mutex);

  22.     /*
  23.      * Since we are supposed to be called from ->connect()
  24.      * which is mutually exclusive with ->disconnect()
  25.      * we can't be racing with input_unregister_handle()
  26.      * and so separate lock is not needed here.
  27.      */
  28.     list_add_tail_rcu(&handle->h_node, &handler->h_list);

  29.     if (handler->start)
  30.         handler->start(handle);

  31.     return 0;
  32. }

        说明:

        1) 函数分别将handle的链表插入到设备和handler的链表中。

五、input核心中触摸屏相关函数

4.1、input_set_abs_params()

点击(此处)折叠或打开

  1. struct input_absinfo {
  2.     __s32 value;
  3.     __s32 minimum;
  4.     __s32 maximum;
  5.     __s32 fuzz;
  6.     __s32 flat;
  7.     __s32 resolution;
  8. };
  9. void input_alloc_absinfo(struct input_dev *dev)
  10. {
  11.     if (!dev->absinfo)
  12.         dev->absinfo = kcalloc(ABS_CNT, sizeof(struct input_absinfo),
  13.                     GFP_KERNEL);

  14.     WARN(!dev->absinfo, "%s(): kcalloc() failed?\n", __func__);
  15. }
  16. void input_set_abs_params(struct input_dev *dev, unsigned int axis,
  17.              int min, int max, int fuzz, int flat)
  18. {
  19.     struct input_absinfo *absinfo;

  20.     input_alloc_absinfo(dev);
  21.     if (!dev->absinfo)
  22.         return;

  23.     absinfo = &dev->absinfo[axis];
  24.     absinfo->minimum = min;
  25.     absinfo->maximum = max;
  26.     absinfo->fuzz = fuzz;
  27.     absinfo->flat = flat;

  28.     dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
  29. }        

       说明:
        1) 首先查看设备是否有absinfo结构体,如果没有,就申请。

        2) 对absinfo结构体初始化,设置其最大最小值。

        3) 设置input设备结构体中的absbit数组,表示对相应操作类型的支持。

4.2、报告事件函数

        input_report_abs()、input_report_key()和input_sync()等报告事件函数中,查看其函数体,最后都是调用input_event()函数,如下:

点击(此处)折叠或打开

  1. static inline int is_event_supported(unsigned int code,
  2.                  unsigned long *bm, unsigned int max)
  3. {
  4.     return code <= max && test_bit(code, bm);
  5. }
  6. void input_event(struct input_dev *dev,
  7.          unsigned int type, unsigned int code, int value)
  8. {
  9.     unsigned long flags;

  10.     if (is_event_supported(type, dev->evbit, EV_MAX)) {

  11.         spin_lock_irqsave(&dev->event_lock, flags);
  12.         add_input_randomness(type, code, value);
  13.         input_handle_event(dev, type, code, value);
  14.         spin_unlock_irqrestore(&dev->event_lock, flags);
  15.     }
  16. }

        说明:

        1) 首先判断是否支持此类型。

        2) 如果支持,调用input_handle_event(dev, type, code, value);函数。

点击(此处)折叠或打开

  1. static void input_handle_event(struct input_dev *dev,
  2.              unsigned int type, unsigned int code, int value)
  3. {
  4.     int disposition = INPUT_IGNORE_EVENT;

  5.     switch (type) {

  6.     case EV_SYN:
  7.         switch (code) {
  8.         case SYN_CONFIG:
  9.             disposition = INPUT_PASS_TO_ALL;
  10.             break;

  11.         case SYN_REPORT:
  12.             if (!dev->sync) {
  13.                 dev->sync = true;
  14.                 disposition = INPUT_PASS_TO_HANDLERS;
  15.             }
  16.             break;
  17.         case SYN_MT_REPORT:
  18.             dev->sync = false;
  19.             disposition = INPUT_PASS_TO_HANDLERS;
  20.             break;
  21.         }
  22.         break;

  23.     case EV_KEY:
  24.         if (is_event_supported(code, dev->keybit, KEY_MAX) &&
  25.          !!test_bit(code, dev->key) != value) {

  26.             if (value != 2) {
  27.                 __change_bit(code, dev->key);
  28.                 if (value)
  29.                     input_start_autorepeat(dev, code);
  30.                 else
  31.                     input_stop_autorepeat(dev);
  32.             }

  33.             disposition = INPUT_PASS_TO_HANDLERS;
  34.         }
  35.         break;

  36.     case EV_SW:
  37.         if (is_event_supported(code, dev->swbit, SW_MAX) &&
  38.          !!test_bit(code, dev->sw) != value) {

  39.             __change_bit(code, dev->sw);
  40.             disposition = INPUT_PASS_TO_HANDLERS;
  41.         }
  42.         break;

  43.     case EV_ABS:
  44.         if (is_event_supported(code, dev->absbit, ABS_MAX))
  45.             disposition = input_handle_abs_event(dev, code, &value);

  46.         break;

  47.     case EV_REL:
  48.         if (is_event_supported(code, dev->relbit, REL_MAX) && value)
  49.             disposition = INPUT_PASS_TO_HANDLERS;

  50.         break;

  51.     case EV_MSC:
  52.         if (is_event_supported(code, dev->mscbit, MSC_MAX))
  53.             disposition = INPUT_PASS_TO_ALL;

  54.         break;

  55.     case EV_LED:
  56.         if (is_event_supported(code, dev->ledbit, LED_MAX) &&
  57.          !!test_bit(code, dev->led) != value) {

  58.             __change_bit(code, dev->led);
  59.             disposition = INPUT_PASS_TO_ALL;
  60.         }
  61.         break;

  62.     case EV_SND:
  63.         if (is_event_supported(code, dev->sndbit, SND_MAX)) {

  64.             if (!!test_bit(code, dev->snd) != !!value)
  65.                 __change_bit(code, dev->snd);
  66.             disposition = INPUT_PASS_TO_ALL;
  67.         }
  68.         break;

  69.     case EV_REP:
  70.         if (code <= REP_MAX && value >= 0 && dev->rep[code] != value) {
  71.             dev->rep[code] = value;
  72.             disposition = INPUT_PASS_TO_ALL;
  73.         }
  74.         break;

  75.     case EV_FF:
  76.         if (value >= 0)
  77.             disposition = INPUT_PASS_TO_ALL;
  78.         break;

  79.     case EV_PWR:
  80.         disposition = INPUT_PASS_TO_ALL;
  81.         break;
  82.     }

  83.     if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
  84.         dev->sync = false;

  85.     if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
  86.         dev->event(dev, type, code, value);

  87.     if (disposition & INPUT_PASS_TO_HANDLERS)
  88.         input_pass_event(dev, type, code, value);
  89. }

        说明:

        1) 我们拿EV_ABS事件作为例子,最后调用input_handle_abs_event(dev, code, &value);函数。

点击(此处)折叠或打开

  1. static int input_handle_abs_event(struct input_dev *dev,
  2.                  unsigned int code, int *pval)
  3. {
  4.     bool is_mt_event;
  5.     int *pold;

  6.     if (code == ABS_MT_SLOT) {
  7.         /*
  8.          * "Stage" the event; we'll flush it later, when we
  9.          * get actual touch data.
  10.          */
  11.         if (*pval >= 0 && *pval < dev->mtsize)
  12.             dev->slot = *pval;

  13.         return INPUT_IGNORE_EVENT;
  14.     }

  15.     is_mt_event = code >= ABS_MT_FIRST && code <= ABS_MT_LAST;

  16.     if (!is_mt_event) {
  17.         pold = &dev->absinfo[code].value;
  18.     } else if (dev->mt) {
  19.         struct input_mt_slot *mtslot = &dev->mt[dev->slot];
  20.         pold = &mtslot->abs[code - ABS_MT_FIRST];
  21.     } else {
  22.         /*
  23.          * Bypass filtering for multi-touch events when
  24.          * not employing slots.
  25.          */
  26.         pold = NULL;
  27.     }

  28.     if (pold) {
  29.         *pval = input_defuzz_abs_event(*pval, *pold,
  30.                         dev->absinfo[code].fuzz);
  31.         if (*pold == *pval)
  32.             return INPUT_IGNORE_EVENT;

  33.         *pold = *pval;
  34.     }

  35.     /* Flush pending "slot" event */
  36.     if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
  37.         input_abs_set_val(dev, ABS_MT_SLOT, dev->slot);
  38.         input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot);
  39.     }

  40.     return INPUT_PASS_TO_HANDLERS;
  41. }
  42. static void input_pass_event(struct input_dev *dev,
  43.              unsigned int type, unsigned int code, int value)
  44. {
  45.     struct input_handler *handler;
  46.     struct input_handle *handle;

  47.     rcu_read_lock();

  48.     handle = rcu_dereference(dev->grab);
  49.     if (handle)
  50.         handle->handler->event(handle, type, code, value);
  51.     else {
  52.         bool filtered = false;

  53.         list_for_each_entry_rcu(handle, &dev->h_list, d_node) {
  54.             if (!handle->open)
  55.                 continue;

  56.             handler = handle->handler;
  57.             if (!handler->filter) {
  58.                 if (filtered)
  59.                     break;

  60.                 handler->event(handle, type, code, value);

  61.             } else if (handler->filter(handle, type, code, value))
  62.                 filtered = true;
  63.         }
  64.     }

  65.     rcu_read_unlock();
  66. }

        说明:

        1) 在input_handle_abs_event(dev, code, &value);函数中,调用input_pass_event()函数,该函数调用handler中的event函数,即《input子系统(一)--GSC3280触摸屏驱动》3.3中的tsdev_event()函数。


阅读(1099) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~