Lines Matching +full:device +full:- +full:handle
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 1999-2002 Vojtech Pavlik
24 #include <linux/device.h>
28 #include "input-compat.h"
29 #include "input-core-private.h"
30 #include "input-poller.h"
73 if (value > old_val - fuzz / 2 && value < old_val + fuzz / 2) in input_defuzz_abs_event()
76 if (value > old_val - fuzz && value < old_val + fuzz) in input_defuzz_abs_event()
79 if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2) in input_defuzz_abs_event()
88 if (test_bit(EV_REP, dev->evbit) && in input_start_autorepeat()
89 dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && in input_start_autorepeat()
90 dev->timer.function) { in input_start_autorepeat()
91 dev->repeat_key = code; in input_start_autorepeat()
92 mod_timer(&dev->timer, in input_start_autorepeat()
93 jiffies + msecs_to_jiffies(dev->rep[REP_DELAY])); in input_start_autorepeat()
99 del_timer(&dev->timer); in input_stop_autorepeat()
105 * filters at the head of the list of handles attached to the device, and
108 * This function is called with dev->event_lock held and interrupts disabled.
113 struct input_handle *handle; in input_pass_values() local
116 lockdep_assert_held(&dev->event_lock); in input_pass_values()
120 handle = rcu_dereference(dev->grab); in input_pass_values()
121 if (handle) { in input_pass_values()
122 count = handle->handle_events(handle, vals, count); in input_pass_values()
124 list_for_each_entry_rcu(handle, &dev->h_list, d_node) in input_pass_values()
125 if (handle->open) { in input_pass_values()
126 count = handle->handle_events(handle, vals, in input_pass_values()
136 if (test_bit(EV_REP, dev->evbit) && test_bit(EV_KEY, dev->evbit)) { in input_pass_values()
138 if (v->type == EV_KEY && v->value != 2) { in input_pass_values()
139 if (v->value) in input_pass_values()
140 input_start_autorepeat(dev, v->code); in input_pass_values()
158 struct input_mt *mt = dev->mt; in input_handle_abs_event()
168 if (mt && *pval >= 0 && *pval < mt->num_slots) in input_handle_abs_event()
169 mt->slot = *pval; in input_handle_abs_event()
177 pold = &dev->absinfo[code].value; in input_handle_abs_event()
179 pold = &mt->slots[mt->slot].abs[code - ABS_MT_FIRST]; in input_handle_abs_event()
180 is_new_slot = mt->slot != dev->absinfo[ABS_MT_SLOT].value; in input_handle_abs_event()
183 * Bypass filtering for multi-touch events when in input_handle_abs_event()
191 dev->absinfo[code].fuzz); in input_handle_abs_event()
200 dev->absinfo[ABS_MT_SLOT].value = mt->slot; in input_handle_abs_event()
213 /* filter-out events from inhibited devices */ in input_get_disposition()
214 if (dev->inhibited) in input_get_disposition()
235 if (is_event_supported(code, dev->keybit, KEY_MAX)) { in input_get_disposition()
237 /* auto-repeat bypasses state updates */ in input_get_disposition()
243 if (!!test_bit(code, dev->key) != !!value) { in input_get_disposition()
245 __change_bit(code, dev->key); in input_get_disposition()
252 if (is_event_supported(code, dev->swbit, SW_MAX) && in input_get_disposition()
253 !!test_bit(code, dev->sw) != !!value) { in input_get_disposition()
255 __change_bit(code, dev->sw); in input_get_disposition()
261 if (is_event_supported(code, dev->absbit, ABS_MAX)) in input_get_disposition()
267 if (is_event_supported(code, dev->relbit, REL_MAX) && value) in input_get_disposition()
273 if (is_event_supported(code, dev->mscbit, MSC_MAX)) in input_get_disposition()
279 if (is_event_supported(code, dev->ledbit, LED_MAX) && in input_get_disposition()
280 !!test_bit(code, dev->led) != !!value) { in input_get_disposition()
282 __change_bit(code, dev->led); in input_get_disposition()
288 if (is_event_supported(code, dev->sndbit, SND_MAX)) { in input_get_disposition()
290 if (!!test_bit(code, dev->snd) != !!value) in input_get_disposition()
291 __change_bit(code, dev->snd); in input_get_disposition()
297 if (code <= REP_MAX && value >= 0 && dev->rep[code] != value) { in input_get_disposition()
298 dev->rep[code] = value; in input_get_disposition()
320 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) in input_event_dispose()
321 dev->event(dev, type, code, value); in input_event_dispose()
327 v = &dev->vals[dev->num_vals++]; in input_event_dispose()
328 v->type = EV_ABS; in input_event_dispose()
329 v->code = ABS_MT_SLOT; in input_event_dispose()
330 v->value = dev->mt->slot; in input_event_dispose()
333 v = &dev->vals[dev->num_vals++]; in input_event_dispose()
334 v->type = type; in input_event_dispose()
335 v->code = code; in input_event_dispose()
336 v->value = value; in input_event_dispose()
340 if (dev->num_vals >= 2) in input_event_dispose()
341 input_pass_values(dev, dev->vals, dev->num_vals); in input_event_dispose()
342 dev->num_vals = 0; in input_event_dispose()
349 dev->timestamp[INPUT_CLK_MONO] = ktime_set(0, 0); in input_event_dispose()
350 } else if (dev->num_vals >= dev->max_vals - 2) { in input_event_dispose()
351 dev->vals[dev->num_vals++] = input_value_sync; in input_event_dispose()
352 input_pass_values(dev, dev->vals, dev->num_vals); in input_event_dispose()
353 dev->num_vals = 0; in input_event_dispose()
362 lockdep_assert_held(&dev->event_lock); in input_handle_event()
374 * input_event() - report new input event
375 * @dev: device that generated the event
383 * NOTE: input_event() may be safely used right after input device was
395 if (is_event_supported(type, dev->evbit, EV_MAX)) { in input_event()
397 spin_lock_irqsave(&dev->event_lock, flags); in input_event()
399 spin_unlock_irqrestore(&dev->event_lock, flags); in input_event()
405 * input_inject_event() - send input event from input handler
406 * @handle: input handle to send event through
411 * Similar to input_event() but will ignore event if device is
412 * "grabbed" and handle injecting event is not the one that owns
413 * the device.
415 void input_inject_event(struct input_handle *handle, in input_inject_event() argument
418 struct input_dev *dev = handle->dev; in input_inject_event()
422 if (is_event_supported(type, dev->evbit, EV_MAX)) { in input_inject_event()
423 spin_lock_irqsave(&dev->event_lock, flags); in input_inject_event()
426 grab = rcu_dereference(dev->grab); in input_inject_event()
427 if (!grab || grab == handle) in input_inject_event()
431 spin_unlock_irqrestore(&dev->event_lock, flags); in input_inject_event()
437 * input_alloc_absinfo - allocates array of input_absinfo structs
438 * @dev: the input device emitting absolute events
445 if (dev->absinfo) in input_alloc_absinfo()
448 dev->absinfo = kcalloc(ABS_CNT, sizeof(*dev->absinfo), GFP_KERNEL); in input_alloc_absinfo()
449 if (!dev->absinfo) { in input_alloc_absinfo()
450 dev_err(dev->dev.parent ?: &dev->dev, in input_alloc_absinfo()
453 * We will handle this allocation failure in in input_alloc_absinfo()
455 * device with ABS bits but without absinfo. in input_alloc_absinfo()
466 __set_bit(EV_ABS, dev->evbit); in input_set_abs_params()
467 __set_bit(axis, dev->absbit); in input_set_abs_params()
470 if (!dev->absinfo) in input_set_abs_params()
473 absinfo = &dev->absinfo[axis]; in input_set_abs_params()
474 absinfo->minimum = min; in input_set_abs_params()
475 absinfo->maximum = max; in input_set_abs_params()
476 absinfo->fuzz = fuzz; in input_set_abs_params()
477 absinfo->flat = flat; in input_set_abs_params()
482 * input_copy_abs - Copy absinfo from one input_dev to another
483 * @dst: Destination input device to copy the abs settings to
485 * @src: Source input device to copy the abs settings from
489 * the specified source input device's source axis.
490 * This is useful to e.g. setup a pen/stylus input-device for combined
498 if (WARN_ON(!(test_bit(EV_ABS, src->evbit) && in input_copy_abs()
499 test_bit(src_axis, src->absbit)))) in input_copy_abs()
507 if (!src->absinfo) in input_copy_abs()
511 if (!dst->absinfo) in input_copy_abs()
514 dst->absinfo[dst_axis] = src->absinfo[src_axis]; in input_copy_abs()
519 * input_grab_device - grabs device for exclusive use
520 * @handle: input handle that wants to own the device
522 * When a device is grabbed by an input handle all events generated by
523 * the device are delivered only to this handle. Also events injected
524 * by other input handles are ignored while device is grabbed.
526 int input_grab_device(struct input_handle *handle) in input_grab_device() argument
528 struct input_dev *dev = handle->dev; in input_grab_device()
531 retval = mutex_lock_interruptible(&dev->mutex); in input_grab_device()
535 if (dev->grab) { in input_grab_device()
536 retval = -EBUSY; in input_grab_device()
540 rcu_assign_pointer(dev->grab, handle); in input_grab_device()
543 mutex_unlock(&dev->mutex); in input_grab_device()
548 static void __input_release_device(struct input_handle *handle) in __input_release_device() argument
550 struct input_dev *dev = handle->dev; in __input_release_device()
553 grabber = rcu_dereference_protected(dev->grab, in __input_release_device()
554 lockdep_is_held(&dev->mutex)); in __input_release_device()
555 if (grabber == handle) { in __input_release_device()
556 rcu_assign_pointer(dev->grab, NULL); in __input_release_device()
560 list_for_each_entry(handle, &dev->h_list, d_node) in __input_release_device()
561 if (handle->open && handle->handler->start) in __input_release_device()
562 handle->handler->start(handle); in __input_release_device()
567 * input_release_device - release previously grabbed device
568 * @handle: input handle that owns the device
570 * Releases previously grabbed device so that other input handles can
572 * to the device have their start() method called so they have a change
573 * to synchronize device state with the rest of the system.
575 void input_release_device(struct input_handle *handle) in input_release_device() argument
577 struct input_dev *dev = handle->dev; in input_release_device()
579 mutex_lock(&dev->mutex); in input_release_device()
580 __input_release_device(handle); in input_release_device()
581 mutex_unlock(&dev->mutex); in input_release_device()
586 * input_open_device - open input device
587 * @handle: handle through which device is being accessed
590 * want to start receive events from given input device.
592 int input_open_device(struct input_handle *handle) in input_open_device() argument
594 struct input_dev *dev = handle->dev; in input_open_device()
597 retval = mutex_lock_interruptible(&dev->mutex); in input_open_device()
601 if (dev->going_away) { in input_open_device()
602 retval = -ENODEV; in input_open_device()
606 handle->open++; in input_open_device()
608 if (dev->users++ || dev->inhibited) { in input_open_device()
610 * Device is already opened and/or inhibited, in input_open_device()
616 if (dev->open) { in input_open_device()
617 retval = dev->open(dev); in input_open_device()
619 dev->users--; in input_open_device()
620 handle->open--; in input_open_device()
623 * through this handle in input_open_device()
630 if (dev->poller) in input_open_device()
631 input_dev_poller_start(dev->poller); in input_open_device()
634 mutex_unlock(&dev->mutex); in input_open_device()
639 int input_flush_device(struct input_handle *handle, struct file *file) in input_flush_device() argument
641 struct input_dev *dev = handle->dev; in input_flush_device()
644 retval = mutex_lock_interruptible(&dev->mutex); in input_flush_device()
648 if (dev->flush) in input_flush_device()
649 retval = dev->flush(dev, file); in input_flush_device()
651 mutex_unlock(&dev->mutex); in input_flush_device()
657 * input_close_device - close input device
658 * @handle: handle through which device is being accessed
661 * want to stop receive events from given input device.
663 void input_close_device(struct input_handle *handle) in input_close_device() argument
665 struct input_dev *dev = handle->dev; in input_close_device()
667 mutex_lock(&dev->mutex); in input_close_device()
669 __input_release_device(handle); in input_close_device()
671 if (!--dev->users && !dev->inhibited) { in input_close_device()
672 if (dev->poller) in input_close_device()
673 input_dev_poller_stop(dev->poller); in input_close_device()
674 if (dev->close) in input_close_device()
675 dev->close(dev); in input_close_device()
678 if (!--handle->open) { in input_close_device()
682 * through this handle in input_close_device()
687 mutex_unlock(&dev->mutex); in input_close_device()
693 * The function must be called with dev->event_lock held.
700 lockdep_assert_held(&dev->event_lock); in input_dev_release_keys()
702 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { in input_dev_release_keys()
703 for_each_set_bit(code, dev->key, KEY_CNT) { in input_dev_release_keys()
713 * Prepare device for unregistering
717 struct input_handle *handle; in input_disconnect_device() local
720 * Mark device as going away. Note that we take dev->mutex here in input_disconnect_device()
721 * not to protect access to dev->going_away but rather to ensure in input_disconnect_device()
724 mutex_lock(&dev->mutex); in input_disconnect_device()
725 dev->going_away = true; in input_disconnect_device()
726 mutex_unlock(&dev->mutex); in input_disconnect_device()
728 spin_lock_irq(&dev->event_lock); in input_disconnect_device()
739 list_for_each_entry(handle, &dev->h_list, d_node) in input_disconnect_device()
740 handle->open = 0; in input_disconnect_device()
742 spin_unlock_irq(&dev->event_lock); in input_disconnect_device()
746 * input_scancode_to_scalar() - converts scancode in &struct input_keymap_entry
758 switch (ke->len) { in input_scancode_to_scalar()
760 *scancode = *((u8 *)ke->scancode); in input_scancode_to_scalar()
764 *scancode = *((u16 *)ke->scancode); in input_scancode_to_scalar()
768 *scancode = *((u32 *)ke->scancode); in input_scancode_to_scalar()
772 return -EINVAL; in input_scancode_to_scalar()
780 * Those routines handle the default case where no [gs]etkeycode() is
787 switch (dev->keycodesize) { in input_fetch_keycode()
789 return ((u8 *)dev->keycode)[index]; in input_fetch_keycode()
792 return ((u16 *)dev->keycode)[index]; in input_fetch_keycode()
795 return ((u32 *)dev->keycode)[index]; in input_fetch_keycode()
805 if (!dev->keycodesize) in input_default_getkeycode()
806 return -EINVAL; in input_default_getkeycode()
808 if (ke->flags & INPUT_KEYMAP_BY_INDEX) in input_default_getkeycode()
809 index = ke->index; in input_default_getkeycode()
816 if (index >= dev->keycodemax) in input_default_getkeycode()
817 return -EINVAL; in input_default_getkeycode()
819 ke->keycode = input_fetch_keycode(dev, index); in input_default_getkeycode()
820 ke->index = index; in input_default_getkeycode()
821 ke->len = sizeof(index); in input_default_getkeycode()
822 memcpy(ke->scancode, &index, sizeof(index)); in input_default_getkeycode()
835 if (!dev->keycodesize) in input_default_setkeycode()
836 return -EINVAL; in input_default_setkeycode()
838 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in input_default_setkeycode()
839 index = ke->index; in input_default_setkeycode()
846 if (index >= dev->keycodemax) in input_default_setkeycode()
847 return -EINVAL; in input_default_setkeycode()
849 if (dev->keycodesize < sizeof(ke->keycode) && in input_default_setkeycode()
850 (ke->keycode >> (dev->keycodesize * 8))) in input_default_setkeycode()
851 return -EINVAL; in input_default_setkeycode()
853 switch (dev->keycodesize) { in input_default_setkeycode()
855 u8 *k = (u8 *)dev->keycode; in input_default_setkeycode()
857 k[index] = ke->keycode; in input_default_setkeycode()
861 u16 *k = (u16 *)dev->keycode; in input_default_setkeycode()
863 k[index] = ke->keycode; in input_default_setkeycode()
867 u32 *k = (u32 *)dev->keycode; in input_default_setkeycode()
869 k[index] = ke->keycode; in input_default_setkeycode()
875 __clear_bit(*old_keycode, dev->keybit); in input_default_setkeycode()
876 for (i = 0; i < dev->keycodemax; i++) { in input_default_setkeycode()
878 __set_bit(*old_keycode, dev->keybit); in input_default_setkeycode()
885 __set_bit(ke->keycode, dev->keybit); in input_default_setkeycode()
890 * input_get_keycode - retrieve keycode currently mapped to a given scancode
891 * @dev: input device which keymap is being queried
902 spin_lock_irqsave(&dev->event_lock, flags); in input_get_keycode()
903 retval = dev->getkeycode(dev, ke); in input_get_keycode()
904 spin_unlock_irqrestore(&dev->event_lock, flags); in input_get_keycode()
911 * input_set_keycode - attribute a keycode to a given scancode
912 * @dev: input device which keymap is being updated
925 if (ke->keycode > KEY_MAX) in input_set_keycode()
926 return -EINVAL; in input_set_keycode()
928 spin_lock_irqsave(&dev->event_lock, flags); in input_set_keycode()
930 retval = dev->setkeycode(dev, ke, &old_keycode); in input_set_keycode()
935 __clear_bit(KEY_RESERVED, dev->keybit); in input_set_keycode()
942 dev_warn(dev->dev.parent ?: &dev->dev, in input_set_keycode()
945 } else if (test_bit(EV_KEY, dev->evbit) && in input_set_keycode()
946 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && in input_set_keycode()
947 __test_and_clear_bit(old_keycode, dev->key)) { in input_set_keycode()
951 * here is considered no longer supported by the device and in input_set_keycode()
961 spin_unlock_irqrestore(&dev->event_lock, flags); in input_set_keycode()
970 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) in input_match_device_id()
971 if (id->bustype != dev->id.bustype) in input_match_device_id()
974 if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR) in input_match_device_id()
975 if (id->vendor != dev->id.vendor) in input_match_device_id()
978 if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT) in input_match_device_id()
979 if (id->product != dev->id.product) in input_match_device_id()
982 if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION) in input_match_device_id()
983 if (id->version != dev->id.version) in input_match_device_id()
986 if (!bitmap_subset(id->evbit, dev->evbit, EV_MAX) || in input_match_device_id()
987 !bitmap_subset(id->keybit, dev->keybit, KEY_MAX) || in input_match_device_id()
988 !bitmap_subset(id->relbit, dev->relbit, REL_MAX) || in input_match_device_id()
989 !bitmap_subset(id->absbit, dev->absbit, ABS_MAX) || in input_match_device_id()
990 !bitmap_subset(id->mscbit, dev->mscbit, MSC_MAX) || in input_match_device_id()
991 !bitmap_subset(id->ledbit, dev->ledbit, LED_MAX) || in input_match_device_id()
992 !bitmap_subset(id->sndbit, dev->sndbit, SND_MAX) || in input_match_device_id()
993 !bitmap_subset(id->ffbit, dev->ffbit, FF_MAX) || in input_match_device_id()
994 !bitmap_subset(id->swbit, dev->swbit, SW_MAX) || in input_match_device_id()
995 !bitmap_subset(id->propbit, dev->propbit, INPUT_PROP_MAX)) { in input_match_device_id()
1008 for (id = handler->id_table; id->flags || id->driver_info; id++) { in input_match_device()
1010 (!handler->match || handler->match(handler, dev))) { in input_match_device()
1025 return -ENODEV; in input_attach_handler()
1027 error = handler->connect(handler, dev, id); in input_attach_handler()
1028 if (error && error != -ENODEV) in input_attach_handler()
1029 pr_err("failed to attach handler %s to device %s, error: %d\n", in input_attach_handler()
1030 handler->name, kobject_name(&dev->dev.kobj), error); in input_attach_handler()
1049 len += snprintf(buf + len, max(buf_size - len, 0), in input_bits_to_string()
1090 struct seq_file *seq = file->private_data; in input_proc_devices_poll()
1091 struct input_seq_state *state = seq->private; in input_proc_devices_poll()
1094 if (state->input_devices_state != input_devices_state) { in input_proc_devices_poll()
1095 state->input_devices_state = input_devices_state; in input_proc_devices_poll()
1104 struct input_seq_state *state = seq->private; in input_devices_seq_start()
1109 state->mutex_acquired = false; in input_devices_seq_start()
1113 state->mutex_acquired = true; in input_devices_seq_start()
1125 struct input_seq_state *state = seq->private; in input_seq_stop()
1127 if (state->mutex_acquired) in input_seq_stop()
1140 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { in input_seq_print_bitmap()
1160 const char *path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); in input_devices_seq_show()
1161 struct input_handle *handle; in input_devices_seq_show() local
1164 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); in input_devices_seq_show()
1166 seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : ""); in input_devices_seq_show()
1167 seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : ""); in input_devices_seq_show()
1169 seq_printf(seq, "U: Uniq=%s\n", dev->uniq ? dev->uniq : ""); in input_devices_seq_show()
1172 list_for_each_entry(handle, &dev->h_list, d_node) in input_devices_seq_show()
1173 seq_printf(seq, "%s ", handle->name); in input_devices_seq_show()
1176 input_seq_print_bitmap(seq, "PROP", dev->propbit, INPUT_PROP_MAX); in input_devices_seq_show()
1178 input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX); in input_devices_seq_show()
1179 if (test_bit(EV_KEY, dev->evbit)) in input_devices_seq_show()
1180 input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX); in input_devices_seq_show()
1181 if (test_bit(EV_REL, dev->evbit)) in input_devices_seq_show()
1182 input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX); in input_devices_seq_show()
1183 if (test_bit(EV_ABS, dev->evbit)) in input_devices_seq_show()
1184 input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX); in input_devices_seq_show()
1185 if (test_bit(EV_MSC, dev->evbit)) in input_devices_seq_show()
1186 input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX); in input_devices_seq_show()
1187 if (test_bit(EV_LED, dev->evbit)) in input_devices_seq_show()
1188 input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX); in input_devices_seq_show()
1189 if (test_bit(EV_SND, dev->evbit)) in input_devices_seq_show()
1190 input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX); in input_devices_seq_show()
1191 if (test_bit(EV_FF, dev->evbit)) in input_devices_seq_show()
1192 input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX); in input_devices_seq_show()
1193 if (test_bit(EV_SW, dev->evbit)) in input_devices_seq_show()
1194 input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX); in input_devices_seq_show()
1225 struct input_seq_state *state = seq->private; in input_handlers_seq_start()
1230 state->mutex_acquired = false; in input_handlers_seq_start()
1234 state->mutex_acquired = true; in input_handlers_seq_start()
1235 state->pos = *pos; in input_handlers_seq_start()
1242 struct input_seq_state *state = seq->private; in input_handlers_seq_next()
1244 state->pos = *pos + 1; in input_handlers_seq_next()
1251 struct input_seq_state *state = seq->private; in input_handlers_seq_show()
1253 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); in input_handlers_seq_show()
1254 if (handler->filter) in input_handlers_seq_show()
1256 if (handler->legacy_minors) in input_handlers_seq_show()
1257 seq_printf(seq, " Minor=%d", handler->minor); in input_handlers_seq_show()
1289 return -ENOMEM; in input_proc_init()
1305 return -ENOMEM; in input_proc_init()
1322 static ssize_t input_dev_show_##name(struct device *dev, \
1329 input_dev->name ? input_dev->name : ""); \
1346 len += snprintf(buf + len, max(size - len, 0), "%X,", bit); in input_print_modalias_bits()
1356 "input:b%04Xv%04Xp%04Xe%04X-", in input_print_modalias_parts()
1357 id->id.bustype, id->id.vendor, in input_print_modalias_parts()
1358 id->id.product, id->id.version); in input_print_modalias_parts()
1360 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1361 'e', id->evbit, 0, EV_MAX); in input_print_modalias_parts()
1367 space = max(size - (len + 1), 0); in input_print_modalias_parts()
1369 klen = input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1370 'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX); in input_print_modalias_parts()
1383 remainder = full_len - len; in input_print_modalias_parts()
1388 if (remainder <= space - 3) { in input_print_modalias_parts()
1394 for (int i = size - 1 - remainder - 3; i >= 0; i--) { in input_print_modalias_parts()
1404 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1405 'r', id->relbit, 0, REL_MAX); in input_print_modalias_parts()
1406 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1407 'a', id->absbit, 0, ABS_MAX); in input_print_modalias_parts()
1408 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1409 'm', id->mscbit, 0, MSC_MAX); in input_print_modalias_parts()
1410 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1411 'l', id->ledbit, 0, LED_MAX); in input_print_modalias_parts()
1412 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1413 's', id->sndbit, 0, SND_MAX); in input_print_modalias_parts()
1414 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1415 'f', id->ffbit, 0, FF_MAX); in input_print_modalias_parts()
1416 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1417 'w', id->swbit, 0, SW_MAX); in input_print_modalias_parts()
1438 static ssize_t input_dev_show_modalias(struct device *dev, in input_dev_show_modalias()
1446 if (len < PAGE_SIZE - 2) in input_dev_show_modalias()
1447 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); in input_dev_show_modalias()
1456 static ssize_t input_dev_show_properties(struct device *dev, in input_dev_show_properties()
1461 int len = input_print_bitmap(buf, PAGE_SIZE, input_dev->propbit, in input_dev_show_properties()
1470 static ssize_t inhibited_show(struct device *dev, in inhibited_show()
1476 return sysfs_emit(buf, "%d\n", input_dev->inhibited); in inhibited_show()
1479 static ssize_t inhibited_store(struct device *dev, in inhibited_store()
1488 return -EINVAL; in inhibited_store()
1518 static ssize_t input_dev_show_id_##name(struct device *dev, \
1523 return sysfs_emit(buf, "%04x\n", input_dev->id.name); \
1552 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { in input_print_bitmap()
1553 len += input_bits_to_string(buf + len, max(buf_size - len, 0), in input_print_bitmap()
1558 len += snprintf(buf + len, max(buf_size - len, 0), " "); in input_print_bitmap()
1569 len += snprintf(buf + len, max(buf_size - len, 0), "\n"); in input_print_bitmap()
1575 static ssize_t input_dev_show_cap_##bm(struct device *dev, \
1581 input_dev->bm##bit, ev##_MAX, \
1623 static void input_dev_release(struct device *device) in input_dev_release() argument
1625 struct input_dev *dev = to_input_dev(device); in input_dev_release()
1629 kfree(dev->poller); in input_dev_release()
1630 kfree(dev->absinfo); in input_dev_release()
1631 kfree(dev->vals); in input_dev_release()
1638 * Input uevent interface - loading event handlers based on
1639 * device bitfields.
1647 return -ENOMEM; in input_add_uevent_bm_var()
1649 len = input_print_bitmap(&env->buf[env->buflen - 1], in input_add_uevent_bm_var()
1650 sizeof(env->buf) - env->buflen, in input_add_uevent_bm_var()
1652 if (len >= (sizeof(env->buf) - env->buflen)) in input_add_uevent_bm_var()
1653 return -ENOMEM; in input_add_uevent_bm_var()
1655 env->buflen += len; in input_add_uevent_bm_var()
1663 * avoid overflows/-ENOMEM elsewhere. To work around this let's artificially
1668 * SEQNUM=18446744073709551615 - (%llu - 28 bytes)
1672 * 68 bytes total. Allow extra buffer - 96 bytes
1682 return -ENOMEM; in input_add_uevent_modalias_var()
1684 len = input_print_modalias(&env->buf[env->buflen - 1], in input_add_uevent_modalias_var()
1685 (int)sizeof(env->buf) - env->buflen - in input_add_uevent_modalias_var()
1688 if (len >= ((int)sizeof(env->buf) - env->buflen - in input_add_uevent_modalias_var()
1690 return -ENOMEM; in input_add_uevent_modalias_var()
1692 env->buflen += len; in input_add_uevent_modalias_var()
1717 static int input_dev_uevent(const struct device *device, struct kobj_uevent_env *env) in input_dev_uevent() argument
1719 const struct input_dev *dev = to_input_dev(device); in input_dev_uevent()
1722 dev->id.bustype, dev->id.vendor, in input_dev_uevent()
1723 dev->id.product, dev->id.version); in input_dev_uevent()
1724 if (dev->name) in input_dev_uevent()
1725 INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name); in input_dev_uevent()
1726 if (dev->phys) in input_dev_uevent()
1727 INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys); in input_dev_uevent()
1728 if (dev->uniq) in input_dev_uevent()
1729 INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq); in input_dev_uevent()
1731 INPUT_ADD_HOTPLUG_BM_VAR("PROP=", dev->propbit, INPUT_PROP_MAX); in input_dev_uevent()
1733 INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX); in input_dev_uevent()
1734 if (test_bit(EV_KEY, dev->evbit)) in input_dev_uevent()
1735 INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX); in input_dev_uevent()
1736 if (test_bit(EV_REL, dev->evbit)) in input_dev_uevent()
1737 INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX); in input_dev_uevent()
1738 if (test_bit(EV_ABS, dev->evbit)) in input_dev_uevent()
1739 INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX); in input_dev_uevent()
1740 if (test_bit(EV_MSC, dev->evbit)) in input_dev_uevent()
1741 INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX); in input_dev_uevent()
1742 if (test_bit(EV_LED, dev->evbit)) in input_dev_uevent()
1743 INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX); in input_dev_uevent()
1744 if (test_bit(EV_SND, dev->evbit)) in input_dev_uevent()
1745 INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX); in input_dev_uevent()
1746 if (test_bit(EV_FF, dev->evbit)) in input_dev_uevent()
1747 INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX); in input_dev_uevent()
1748 if (test_bit(EV_SW, dev->evbit)) in input_dev_uevent()
1749 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX); in input_dev_uevent()
1761 if (!test_bit(EV_##type, dev->evbit)) \
1764 for_each_set_bit(i, dev->bits##bit, type##_CNT) { \
1765 active = test_bit(i, dev->bits); \
1769 dev->event(dev, EV_##type, i, on ? active : 0); \
1775 if (!dev->event) in input_dev_toggle()
1781 if (activate && test_bit(EV_REP, dev->evbit)) { in input_dev_toggle()
1782 dev->event(dev, EV_REP, REP_PERIOD, dev->rep[REP_PERIOD]); in input_dev_toggle()
1783 dev->event(dev, EV_REP, REP_DELAY, dev->rep[REP_DELAY]); in input_dev_toggle()
1788 * input_reset_device() - reset/restore the state of input device
1789 * @dev: input device whose state needs to be reset
1791 * This function tries to reset the state of an opened input device and
1799 mutex_lock(&dev->mutex); in input_reset_device()
1800 spin_lock_irqsave(&dev->event_lock, flags); in input_reset_device()
1806 spin_unlock_irqrestore(&dev->event_lock, flags); in input_reset_device()
1807 mutex_unlock(&dev->mutex); in input_reset_device()
1813 mutex_lock(&dev->mutex); in input_inhibit_device()
1815 if (dev->inhibited) in input_inhibit_device()
1818 if (dev->users) { in input_inhibit_device()
1819 if (dev->close) in input_inhibit_device()
1820 dev->close(dev); in input_inhibit_device()
1821 if (dev->poller) in input_inhibit_device()
1822 input_dev_poller_stop(dev->poller); in input_inhibit_device()
1825 spin_lock_irq(&dev->event_lock); in input_inhibit_device()
1830 spin_unlock_irq(&dev->event_lock); in input_inhibit_device()
1832 dev->inhibited = true; in input_inhibit_device()
1835 mutex_unlock(&dev->mutex); in input_inhibit_device()
1843 mutex_lock(&dev->mutex); in input_uninhibit_device()
1845 if (!dev->inhibited) in input_uninhibit_device()
1848 if (dev->users) { in input_uninhibit_device()
1849 if (dev->open) { in input_uninhibit_device()
1850 ret = dev->open(dev); in input_uninhibit_device()
1854 if (dev->poller) in input_uninhibit_device()
1855 input_dev_poller_start(dev->poller); in input_uninhibit_device()
1858 dev->inhibited = false; in input_uninhibit_device()
1859 spin_lock_irq(&dev->event_lock); in input_uninhibit_device()
1861 spin_unlock_irq(&dev->event_lock); in input_uninhibit_device()
1864 mutex_unlock(&dev->mutex); in input_uninhibit_device()
1868 static int input_dev_suspend(struct device *dev) in input_dev_suspend()
1872 spin_lock_irq(&input_dev->event_lock); in input_dev_suspend()
1884 spin_unlock_irq(&input_dev->event_lock); in input_dev_suspend()
1889 static int input_dev_resume(struct device *dev) in input_dev_resume()
1893 spin_lock_irq(&input_dev->event_lock); in input_dev_resume()
1898 spin_unlock_irq(&input_dev->event_lock); in input_dev_resume()
1903 static int input_dev_freeze(struct device *dev) in input_dev_freeze()
1907 spin_lock_irq(&input_dev->event_lock); in input_dev_freeze()
1916 spin_unlock_irq(&input_dev->event_lock); in input_dev_freeze()
1921 static int input_dev_poweroff(struct device *dev) in input_dev_poweroff()
1925 spin_lock_irq(&input_dev->event_lock); in input_dev_poweroff()
1930 spin_unlock_irq(&input_dev->event_lock); in input_dev_poweroff()
1950 static char *input_devnode(const struct device *dev, umode_t *mode) in input_devnode()
1962 * input_allocate_device - allocate memory for new input device
1972 static atomic_t input_no = ATOMIC_INIT(-1); in input_allocate_device()
1982 * when we register the device. in input_allocate_device()
1984 dev->max_vals = 10; in input_allocate_device()
1985 dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL); in input_allocate_device()
1986 if (!dev->vals) { in input_allocate_device()
1991 mutex_init(&dev->mutex); in input_allocate_device()
1992 spin_lock_init(&dev->event_lock); in input_allocate_device()
1993 timer_setup(&dev->timer, NULL, 0); in input_allocate_device()
1994 INIT_LIST_HEAD(&dev->h_list); in input_allocate_device()
1995 INIT_LIST_HEAD(&dev->node); in input_allocate_device()
1997 dev->dev.type = &input_dev_type; in input_allocate_device()
1998 dev->dev.class = &input_class; in input_allocate_device()
1999 device_initialize(&dev->dev); in input_allocate_device()
2002 * to use input_free_device() so that device core properly frees its in input_allocate_device()
2003 * resources associated with the input device. in input_allocate_device()
2006 dev_set_name(&dev->dev, "input%lu", in input_allocate_device()
2019 static int devm_input_device_match(struct device *dev, void *res, void *data) in devm_input_device_match()
2023 return devres->input == data; in devm_input_device_match()
2026 static void devm_input_device_release(struct device *dev, void *res) in devm_input_device_release()
2029 struct input_dev *input = devres->input; in devm_input_device_release()
2032 __func__, dev_name(&input->dev)); in devm_input_device_release()
2037 * devm_input_allocate_device - allocate managed input device
2038 * @dev: device owning the input device being created
2043 * freed as it will be done automatically when owner device unbinds from
2044 * its driver (or binding fails). Once managed input device is allocated,
2046 * input device. There are no special devm_input_device_[un]register()
2048 * should you need them. In most cases however, managed input device need
2051 * NOTE: the owner device is set up as parent of input device and users
2054 struct input_dev *devm_input_allocate_device(struct device *dev) in devm_input_allocate_device()
2070 input->dev.parent = dev; in devm_input_allocate_device()
2071 input->devres_managed = true; in devm_input_allocate_device()
2073 devres->input = input; in devm_input_allocate_device()
2081 * input_free_device - free memory occupied by input_dev structure
2082 * @dev: input device to free
2085 * was not called yet or if it failed. Once device was registered
2087 * reference to the device is dropped.
2089 * Device should be allocated by input_allocate_device().
2091 * NOTE: If there are references to the input device then memory
2097 if (dev->devres_managed) in input_free_device()
2098 WARN_ON(devres_destroy(dev->dev.parent, in input_free_device()
2108 * input_set_timestamp - set timestamp for input events
2109 * @dev: input device to set timestamp for
2123 dev->timestamp[INPUT_CLK_MONO] = timestamp; in input_set_timestamp()
2124 dev->timestamp[INPUT_CLK_REAL] = ktime_mono_to_real(timestamp); in input_set_timestamp()
2125 dev->timestamp[INPUT_CLK_BOOT] = ktime_mono_to_any(timestamp, in input_set_timestamp()
2131 * input_get_timestamp - get timestamp for input events
2132 * @dev: input device to get timestamp from
2134 * A valid timestamp is a timestamp of non-zero value.
2140 if (!ktime_compare(dev->timestamp[INPUT_CLK_MONO], invalid_timestamp)) in input_get_timestamp()
2143 return dev->timestamp; in input_get_timestamp()
2148 * input_set_capability - mark device as capable of a certain event
2149 * @dev: device that is capable of emitting or accepting event
2154 * bitmap the function also adjusts dev->evbit.
2168 __set_bit(code, dev->keybit); in input_set_capability()
2172 __set_bit(code, dev->relbit); in input_set_capability()
2177 __set_bit(code, dev->absbit); in input_set_capability()
2181 __set_bit(code, dev->mscbit); in input_set_capability()
2185 __set_bit(code, dev->swbit); in input_set_capability()
2189 __set_bit(code, dev->ledbit); in input_set_capability()
2193 __set_bit(code, dev->sndbit); in input_set_capability()
2197 __set_bit(code, dev->ffbit); in input_set_capability()
2210 __set_bit(type, dev->evbit); in input_set_capability()
2220 if (dev->mt) { in input_estimate_events_per_packet()
2221 mt_slots = dev->mt->num_slots; in input_estimate_events_per_packet()
2222 } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) { in input_estimate_events_per_packet()
2223 mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum - in input_estimate_events_per_packet()
2224 dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1; in input_estimate_events_per_packet()
2226 } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { in input_estimate_events_per_packet()
2234 if (test_bit(EV_ABS, dev->evbit)) in input_estimate_events_per_packet()
2235 for_each_set_bit(i, dev->absbit, ABS_CNT) in input_estimate_events_per_packet()
2238 if (test_bit(EV_REL, dev->evbit)) in input_estimate_events_per_packet()
2239 events += bitmap_weight(dev->relbit, REL_CNT); in input_estimate_events_per_packet()
2249 if (!test_bit(EV_##type, dev->evbit)) \
2250 memset(dev->bits##bit, 0, \
2251 sizeof(dev->bits##bit)); \
2268 struct input_handle *handle, *next; in __input_unregister_device() local
2274 list_for_each_entry_safe(handle, next, &dev->h_list, d_node) in __input_unregister_device()
2275 handle->handler->disconnect(handle); in __input_unregister_device()
2276 WARN_ON(!list_empty(&dev->h_list)); in __input_unregister_device()
2278 del_timer_sync(&dev->timer); in __input_unregister_device()
2279 list_del_init(&dev->node); in __input_unregister_device()
2285 device_del(&dev->dev); in __input_unregister_device()
2288 static void devm_input_device_unregister(struct device *dev, void *res) in devm_input_device_unregister()
2291 struct input_dev *input = devres->input; in devm_input_device_unregister()
2293 dev_dbg(dev, "%s: unregistering device %s\n", in devm_input_device_unregister()
2294 __func__, dev_name(&input->dev)); in devm_input_device_unregister()
2300 * dev->event_lock here to avoid racing with input_event
2308 spin_lock_irqsave(&dev->event_lock, flags); in input_repeat_key()
2310 if (!dev->inhibited && in input_repeat_key()
2311 test_bit(dev->repeat_key, dev->key) && in input_repeat_key()
2312 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { in input_repeat_key()
2315 input_handle_event(dev, EV_KEY, dev->repeat_key, 2); in input_repeat_key()
2318 if (dev->rep[REP_PERIOD]) in input_repeat_key()
2319 mod_timer(&dev->timer, jiffies + in input_repeat_key()
2320 msecs_to_jiffies(dev->rep[REP_PERIOD])); in input_repeat_key()
2323 spin_unlock_irqrestore(&dev->event_lock, flags); in input_repeat_key()
2327 * input_enable_softrepeat - enable software autorepeat
2328 * @dev: input device
2332 * Enable software autorepeat on the input device.
2336 dev->timer.function = input_repeat_key; in input_enable_softrepeat()
2337 dev->rep[REP_DELAY] = delay; in input_enable_softrepeat()
2338 dev->rep[REP_PERIOD] = period; in input_enable_softrepeat()
2344 lockdep_assert_held(&dev->mutex); in input_device_enabled()
2346 return !dev->inhibited && dev->users > 0; in input_device_enabled()
2357 if (dev->hint_events_per_packet < packet_size) in input_device_tune_vals()
2358 dev->hint_events_per_packet = packet_size; in input_device_tune_vals()
2360 max_vals = dev->hint_events_per_packet + 2; in input_device_tune_vals()
2361 if (dev->max_vals >= max_vals) in input_device_tune_vals()
2366 return -ENOMEM; in input_device_tune_vals()
2368 spin_lock_irq(&dev->event_lock); in input_device_tune_vals()
2369 dev->max_vals = max_vals; in input_device_tune_vals()
2370 swap(dev->vals, vals); in input_device_tune_vals()
2371 spin_unlock_irq(&dev->event_lock); in input_device_tune_vals()
2380 * input_register_device - register device with input core
2381 * @dev: device to be registered
2383 * This function registers device with input core. The device must be
2386 * If function fails the device must be freed with input_free_device().
2387 * Once device has been successfully registered it can be unregistered
2395 * that tear down of managed input devices is internally a 2-step process:
2396 * registered managed input device is first unregistered, but stays in
2397 * memory and can still handle input_event() calls (although events will
2398 * not be delivered anywhere). The freeing of managed input device will
2399 * happen later, when devres stack is unwound to the point where device
2409 if (test_bit(EV_ABS, dev->evbit) && !dev->absinfo) { in input_register_device()
2410 dev_err(&dev->dev, in input_register_device()
2411 "Absolute device without dev->absinfo, refusing to register\n"); in input_register_device()
2412 return -EINVAL; in input_register_device()
2415 if (dev->devres_managed) { in input_register_device()
2419 return -ENOMEM; in input_register_device()
2421 devres->input = dev; in input_register_device()
2424 /* Every input device generates EV_SYN/SYN_REPORT events. */ in input_register_device()
2425 __set_bit(EV_SYN, dev->evbit); in input_register_device()
2428 __clear_bit(KEY_RESERVED, dev->keybit); in input_register_device()
2430 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ in input_register_device()
2438 * If delay and period are pre-set by the driver, then autorepeating in input_register_device()
2441 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) in input_register_device()
2444 if (!dev->getkeycode) in input_register_device()
2445 dev->getkeycode = input_default_getkeycode; in input_register_device()
2447 if (!dev->setkeycode) in input_register_device()
2448 dev->setkeycode = input_default_setkeycode; in input_register_device()
2450 if (dev->poller) in input_register_device()
2451 input_dev_poller_finalize(dev->poller); in input_register_device()
2453 error = device_add(&dev->dev); in input_register_device()
2457 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); in input_register_device()
2459 dev->name ? dev->name : "Unspecified device", in input_register_device()
2467 list_add_tail(&dev->node, &input_dev_list); in input_register_device()
2476 if (dev->devres_managed) { in input_register_device()
2477 dev_dbg(dev->dev.parent, "%s: registering %s with devres.\n", in input_register_device()
2478 __func__, dev_name(&dev->dev)); in input_register_device()
2479 devres_add(dev->dev.parent, devres); in input_register_device()
2484 device_del(&dev->dev); in input_register_device()
2492 * input_unregister_device - unregister previously registered device
2493 * @dev: device to be unregistered
2495 * This function unregisters an input device. Once device is unregistered
2500 if (dev->devres_managed) { in input_unregister_device()
2501 WARN_ON(devres_destroy(dev->dev.parent, in input_unregister_device()
2521 if (handler->filter) in input_handler_check_methods()
2523 if (handler->events) in input_handler_check_methods()
2525 if (handler->event) in input_handler_check_methods()
2530 __func__, handler->name); in input_handler_check_methods()
2531 return -EINVAL; in input_handler_check_methods()
2538 * input_register_handler - register a new input handler
2554 INIT_LIST_HEAD(&handler->h_list); in input_register_handler()
2560 list_add_tail(&handler->node, &input_handler_list); in input_register_handler()
2573 * input_unregister_handler - unregisters an input handler
2581 struct input_handle *handle, *next; in input_unregister_handler() local
2585 list_for_each_entry_safe(handle, next, &handler->h_list, h_node) in input_unregister_handler()
2586 handler->disconnect(handle); in input_unregister_handler()
2587 WARN_ON(!list_empty(&handler->h_list)); in input_unregister_handler()
2589 list_del_init(&handler->node); in input_unregister_handler()
2598 * input_handler_for_each_handle - handle iterator
2601 * @fn: function to be called for each handle
2604 * it @data and stop when @fn returns a non-zero value. The function is
2612 struct input_handle *handle; in input_handler_for_each_handle() local
2617 list_for_each_entry_rcu(handle, &handler->h_list, h_node) { in input_handler_for_each_handle()
2618 retval = fn(handle, data); in input_handler_for_each_handle()
2631 * invokes handler->event() method for each event one by one.
2633 static unsigned int input_handle_events_default(struct input_handle *handle, in input_handle_events_default() argument
2637 struct input_handler *handler = handle->handler; in input_handle_events_default()
2641 handler->event(handle, v->type, v->code, v->value); in input_handle_events_default()
2648 * handler->filter() method for each event one by one and removes events
2651 static unsigned int input_handle_events_filter(struct input_handle *handle, in input_handle_events_filter() argument
2655 struct input_handler *handler = handle->handler; in input_handle_events_filter()
2660 if (handler->filter(handle, v->type, v->code, v->value)) in input_handle_events_filter()
2667 return end - vals; in input_handle_events_filter()
2673 static unsigned int input_handle_events_null(struct input_handle *handle, in input_handle_events_null() argument
2681 * Sets up appropriate handle->event_handler based on the input_handler
2682 * associated with the handle.
2684 static void input_handle_setup_event_handler(struct input_handle *handle) in input_handle_setup_event_handler() argument
2686 struct input_handler *handler = handle->handler; in input_handle_setup_event_handler()
2688 if (handler->filter) in input_handle_setup_event_handler()
2689 handle->handle_events = input_handle_events_filter; in input_handle_setup_event_handler()
2690 else if (handler->event) in input_handle_setup_event_handler()
2691 handle->handle_events = input_handle_events_default; in input_handle_setup_event_handler()
2692 else if (handler->events) in input_handle_setup_event_handler()
2693 handle->handle_events = handler->events; in input_handle_setup_event_handler()
2695 handle->handle_events = input_handle_events_null; in input_handle_setup_event_handler()
2699 * input_register_handle - register a new input handle
2700 * @handle: handle to register
2702 * This function puts a new input handle onto device's
2709 int input_register_handle(struct input_handle *handle) in input_register_handle() argument
2711 struct input_handler *handler = handle->handler; in input_register_handle()
2712 struct input_dev *dev = handle->dev; in input_register_handle()
2715 input_handle_setup_event_handler(handle); in input_register_handle()
2717 * We take dev->mutex here to prevent race with in input_register_handle()
2720 error = mutex_lock_interruptible(&dev->mutex); in input_register_handle()
2728 if (handler->filter) in input_register_handle()
2729 list_add_rcu(&handle->d_node, &dev->h_list); in input_register_handle()
2731 list_add_tail_rcu(&handle->d_node, &dev->h_list); in input_register_handle()
2733 mutex_unlock(&dev->mutex); in input_register_handle()
2736 * Since we are supposed to be called from ->connect() in input_register_handle()
2737 * which is mutually exclusive with ->disconnect() in input_register_handle()
2741 list_add_tail_rcu(&handle->h_node, &handler->h_list); in input_register_handle()
2743 if (handler->start) in input_register_handle()
2744 handler->start(handle); in input_register_handle()
2751 * input_unregister_handle - unregister an input handle
2752 * @handle: handle to unregister
2754 * This function removes input handle from device's
2760 void input_unregister_handle(struct input_handle *handle) in input_unregister_handle() argument
2762 struct input_dev *dev = handle->dev; in input_unregister_handle()
2764 list_del_rcu(&handle->h_node); in input_unregister_handle()
2767 * Take dev->mutex to prevent race with input_release_device(). in input_unregister_handle()
2769 mutex_lock(&dev->mutex); in input_unregister_handle()
2770 list_del_rcu(&handle->d_node); in input_unregister_handle()
2771 mutex_unlock(&dev->mutex); in input_unregister_handle()
2778 * input_get_new_minor - allocates a new input minor number
2783 * This function allocates a new device minor for from input major namespace.
2792 * This function should be called from input handler's ->connect() in input_get_new_minor()
2798 legacy_base + legacy_num - 1, in input_get_new_minor()
2805 INPUT_MAX_CHAR_DEVICES - 1, GFP_KERNEL); in input_get_new_minor()
2810 * input_free_minor - release previously allocated minor