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()
119 handle = rcu_dereference(dev->grab); in input_pass_values()
120 if (handle) { in input_pass_values()
121 count = handle->handle_events(handle, vals, count); in input_pass_values()
125 list_for_each_entry_rcu(handle, &dev->h_list, d_node) { in input_pass_values()
126 if (handle->open) { in input_pass_values()
127 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
393 if (is_event_supported(type, dev->evbit, EV_MAX)) { in input_event()
394 guard(spinlock_irqsave)(&dev->event_lock); in input_event()
401 * input_inject_event() - send input event from input handler
402 * @handle: input handle to send event through
407 * Similar to input_event() but will ignore event if device is
408 * "grabbed" and handle injecting event is not the one that owns
409 * the device.
411 void input_inject_event(struct input_handle *handle, in input_inject_event() argument
414 struct input_dev *dev = handle->dev; in input_inject_event()
417 if (is_event_supported(type, dev->evbit, EV_MAX)) { in input_inject_event()
418 guard(spinlock_irqsave)(&dev->event_lock); in input_inject_event()
421 grab = rcu_dereference(dev->grab); in input_inject_event()
422 if (!grab || grab == handle) in input_inject_event()
430 * input_alloc_absinfo - allocates array of input_absinfo structs
431 * @dev: the input device emitting absolute events
438 if (dev->absinfo) in input_alloc_absinfo()
441 dev->absinfo = kcalloc(ABS_CNT, sizeof(*dev->absinfo), GFP_KERNEL); in input_alloc_absinfo()
442 if (!dev->absinfo) { in input_alloc_absinfo()
443 dev_err(dev->dev.parent ?: &dev->dev, in input_alloc_absinfo()
446 * We will handle this allocation failure in in input_alloc_absinfo()
448 * device with ABS bits but without absinfo. in input_alloc_absinfo()
459 __set_bit(EV_ABS, dev->evbit); in input_set_abs_params()
460 __set_bit(axis, dev->absbit); in input_set_abs_params()
463 if (!dev->absinfo) in input_set_abs_params()
466 absinfo = &dev->absinfo[axis]; in input_set_abs_params()
467 absinfo->minimum = min; in input_set_abs_params()
468 absinfo->maximum = max; in input_set_abs_params()
469 absinfo->fuzz = fuzz; in input_set_abs_params()
470 absinfo->flat = flat; in input_set_abs_params()
475 * input_copy_abs - Copy absinfo from one input_dev to another
476 * @dst: Destination input device to copy the abs settings to
478 * @src: Source input device to copy the abs settings from
482 * the specified source input device's source axis.
483 * This is useful to e.g. setup a pen/stylus input-device for combined
491 if (WARN_ON(!(test_bit(EV_ABS, src->evbit) && in input_copy_abs()
492 test_bit(src_axis, src->absbit)))) in input_copy_abs()
500 if (!src->absinfo) in input_copy_abs()
504 if (!dst->absinfo) in input_copy_abs()
507 dst->absinfo[dst_axis] = src->absinfo[src_axis]; in input_copy_abs()
512 * input_grab_device - grabs device for exclusive use
513 * @handle: input handle that wants to own the device
515 * When a device is grabbed by an input handle all events generated by
516 * the device are delivered only to this handle. Also events injected
517 * by other input handles are ignored while device is grabbed.
519 int input_grab_device(struct input_handle *handle) in input_grab_device() argument
521 struct input_dev *dev = handle->dev; in input_grab_device()
523 scoped_cond_guard(mutex_intr, return -EINTR, &dev->mutex) { in input_grab_device()
524 if (dev->grab) in input_grab_device()
525 return -EBUSY; in input_grab_device()
527 rcu_assign_pointer(dev->grab, handle); in input_grab_device()
534 static void __input_release_device(struct input_handle *handle) in __input_release_device() argument
536 struct input_dev *dev = handle->dev; in __input_release_device()
539 grabber = rcu_dereference_protected(dev->grab, in __input_release_device()
540 lockdep_is_held(&dev->mutex)); in __input_release_device()
541 if (grabber == handle) { in __input_release_device()
542 rcu_assign_pointer(dev->grab, NULL); in __input_release_device()
546 list_for_each_entry(handle, &dev->h_list, d_node) in __input_release_device()
547 if (handle->open && handle->handler->start) in __input_release_device()
548 handle->handler->start(handle); in __input_release_device()
553 * input_release_device - release previously grabbed device
554 * @handle: input handle that owns the device
556 * Releases previously grabbed device so that other input handles can
558 * to the device have their start() method called so they have a change
559 * to synchronize device state with the rest of the system.
561 void input_release_device(struct input_handle *handle) in input_release_device() argument
563 struct input_dev *dev = handle->dev; in input_release_device()
565 guard(mutex)(&dev->mutex); in input_release_device()
566 __input_release_device(handle); in input_release_device()
571 * input_open_device - open input device
572 * @handle: handle through which device is being accessed
575 * want to start receive events from given input device.
577 int input_open_device(struct input_handle *handle) in input_open_device() argument
579 struct input_dev *dev = handle->dev; in input_open_device()
582 scoped_cond_guard(mutex_intr, return -EINTR, &dev->mutex) { in input_open_device()
583 if (dev->going_away) in input_open_device()
584 return -ENODEV; in input_open_device()
586 handle->open++; in input_open_device()
588 if (handle->handler->passive_observer) in input_open_device()
591 if (dev->users++ || dev->inhibited) { in input_open_device()
593 * Device is already opened and/or inhibited, in input_open_device()
599 if (dev->open) { in input_open_device()
600 error = dev->open(dev); in input_open_device()
602 dev->users--; in input_open_device()
603 handle->open--; in input_open_device()
606 * events through this handle. in input_open_device()
613 if (dev->poller) in input_open_device()
614 input_dev_poller_start(dev->poller); in input_open_device()
621 int input_flush_device(struct input_handle *handle, struct file *file) in input_flush_device() argument
623 struct input_dev *dev = handle->dev; in input_flush_device()
625 scoped_cond_guard(mutex_intr, return -EINTR, &dev->mutex) { in input_flush_device()
626 if (dev->flush) in input_flush_device()
627 return dev->flush(dev, file); in input_flush_device()
635 * input_close_device - close input device
636 * @handle: handle through which device is being accessed
639 * want to stop receive events from given input device.
641 void input_close_device(struct input_handle *handle) in input_close_device() argument
643 struct input_dev *dev = handle->dev; in input_close_device()
645 guard(mutex)(&dev->mutex); in input_close_device()
647 __input_release_device(handle); in input_close_device()
649 if (!handle->handler->passive_observer) { in input_close_device()
650 if (!--dev->users && !dev->inhibited) { in input_close_device()
651 if (dev->poller) in input_close_device()
652 input_dev_poller_stop(dev->poller); in input_close_device()
653 if (dev->close) in input_close_device()
654 dev->close(dev); in input_close_device()
658 if (!--handle->open) { in input_close_device()
662 * through this handle in input_close_device()
671 * The function must be called with dev->event_lock held.
678 lockdep_assert_held(&dev->event_lock); in input_dev_release_keys()
680 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { in input_dev_release_keys()
681 for_each_set_bit(code, dev->key, KEY_CNT) { in input_dev_release_keys()
691 * Prepare device for unregistering
695 struct input_handle *handle; in input_disconnect_device() local
698 * Mark device as going away. Note that we take dev->mutex here in input_disconnect_device()
699 * not to protect access to dev->going_away but rather to ensure in input_disconnect_device()
702 scoped_guard(mutex, &dev->mutex) in input_disconnect_device()
703 dev->going_away = true; in input_disconnect_device()
705 guard(spinlock_irq)(&dev->event_lock); in input_disconnect_device()
716 list_for_each_entry(handle, &dev->h_list, d_node) in input_disconnect_device()
717 handle->open = 0; in input_disconnect_device()
721 * input_scancode_to_scalar() - converts scancode in &struct input_keymap_entry
733 switch (ke->len) { in input_scancode_to_scalar()
735 *scancode = *((u8 *)ke->scancode); in input_scancode_to_scalar()
739 *scancode = *((u16 *)ke->scancode); in input_scancode_to_scalar()
743 *scancode = *((u32 *)ke->scancode); in input_scancode_to_scalar()
747 return -EINVAL; in input_scancode_to_scalar()
755 * Those routines handle the default case where no [gs]etkeycode() is
762 switch (dev->keycodesize) { in input_fetch_keycode()
764 return ((u8 *)dev->keycode)[index]; in input_fetch_keycode()
767 return ((u16 *)dev->keycode)[index]; in input_fetch_keycode()
770 return ((u32 *)dev->keycode)[index]; in input_fetch_keycode()
780 if (!dev->keycodesize) in input_default_getkeycode()
781 return -EINVAL; in input_default_getkeycode()
783 if (ke->flags & INPUT_KEYMAP_BY_INDEX) in input_default_getkeycode()
784 index = ke->index; in input_default_getkeycode()
791 if (index >= dev->keycodemax) in input_default_getkeycode()
792 return -EINVAL; in input_default_getkeycode()
794 ke->keycode = input_fetch_keycode(dev, index); in input_default_getkeycode()
795 ke->index = index; in input_default_getkeycode()
796 ke->len = sizeof(index); in input_default_getkeycode()
797 memcpy(ke->scancode, &index, sizeof(index)); in input_default_getkeycode()
810 if (!dev->keycodesize) in input_default_setkeycode()
811 return -EINVAL; in input_default_setkeycode()
813 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in input_default_setkeycode()
814 index = ke->index; in input_default_setkeycode()
821 if (index >= dev->keycodemax) in input_default_setkeycode()
822 return -EINVAL; in input_default_setkeycode()
824 if (dev->keycodesize < sizeof(ke->keycode) && in input_default_setkeycode()
825 (ke->keycode >> (dev->keycodesize * 8))) in input_default_setkeycode()
826 return -EINVAL; in input_default_setkeycode()
828 switch (dev->keycodesize) { in input_default_setkeycode()
830 u8 *k = (u8 *)dev->keycode; in input_default_setkeycode()
832 k[index] = ke->keycode; in input_default_setkeycode()
836 u16 *k = (u16 *)dev->keycode; in input_default_setkeycode()
838 k[index] = ke->keycode; in input_default_setkeycode()
842 u32 *k = (u32 *)dev->keycode; in input_default_setkeycode()
844 k[index] = ke->keycode; in input_default_setkeycode()
850 __clear_bit(*old_keycode, dev->keybit); in input_default_setkeycode()
851 for (i = 0; i < dev->keycodemax; i++) { in input_default_setkeycode()
853 __set_bit(*old_keycode, dev->keybit); in input_default_setkeycode()
860 __set_bit(ke->keycode, dev->keybit); in input_default_setkeycode()
865 * input_get_keycode - retrieve keycode currently mapped to a given scancode
866 * @dev: input device which keymap is being queried
874 guard(spinlock_irqsave)(&dev->event_lock); in input_get_keycode()
876 return dev->getkeycode(dev, ke); in input_get_keycode()
881 * input_set_keycode - attribute a keycode to a given scancode
882 * @dev: input device which keymap is being updated
894 if (ke->keycode > KEY_MAX) in input_set_keycode()
895 return -EINVAL; in input_set_keycode()
897 guard(spinlock_irqsave)(&dev->event_lock); in input_set_keycode()
899 error = dev->setkeycode(dev, ke, &old_keycode); in input_set_keycode()
904 __clear_bit(KEY_RESERVED, dev->keybit); in input_set_keycode()
911 dev_warn(dev->dev.parent ?: &dev->dev, in input_set_keycode()
914 } else if (test_bit(EV_KEY, dev->evbit) && in input_set_keycode()
915 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && in input_set_keycode()
916 __test_and_clear_bit(old_keycode, dev->key)) { in input_set_keycode()
920 * here is considered no longer supported by the device and in input_set_keycode()
936 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) in input_match_device_id()
937 if (id->bustype != dev->id.bustype) in input_match_device_id()
940 if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR) in input_match_device_id()
941 if (id->vendor != dev->id.vendor) in input_match_device_id()
944 if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT) in input_match_device_id()
945 if (id->product != dev->id.product) in input_match_device_id()
948 if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION) in input_match_device_id()
949 if (id->version != dev->id.version) in input_match_device_id()
952 if (!bitmap_subset(id->evbit, dev->evbit, EV_MAX) || in input_match_device_id()
953 !bitmap_subset(id->keybit, dev->keybit, KEY_MAX) || in input_match_device_id()
954 !bitmap_subset(id->relbit, dev->relbit, REL_MAX) || in input_match_device_id()
955 !bitmap_subset(id->absbit, dev->absbit, ABS_MAX) || in input_match_device_id()
956 !bitmap_subset(id->mscbit, dev->mscbit, MSC_MAX) || in input_match_device_id()
957 !bitmap_subset(id->ledbit, dev->ledbit, LED_MAX) || in input_match_device_id()
958 !bitmap_subset(id->sndbit, dev->sndbit, SND_MAX) || in input_match_device_id()
959 !bitmap_subset(id->ffbit, dev->ffbit, FF_MAX) || in input_match_device_id()
960 !bitmap_subset(id->swbit, dev->swbit, SW_MAX) || in input_match_device_id()
961 !bitmap_subset(id->propbit, dev->propbit, INPUT_PROP_MAX)) { in input_match_device_id()
974 for (id = handler->id_table; id->flags || id->driver_info; id++) { in input_match_device()
976 (!handler->match || handler->match(handler, dev))) { in input_match_device()
991 return -ENODEV; in input_attach_handler()
993 error = handler->connect(handler, dev, id); in input_attach_handler()
994 if (error && error != -ENODEV) in input_attach_handler()
995 pr_err("failed to attach handler %s to device %s, error: %d\n", in input_attach_handler()
996 handler->name, kobject_name(&dev->dev.kobj), error); in input_attach_handler()
1015 len += snprintf(buf + len, max(buf_size - len, 0), in input_bits_to_string()
1056 struct seq_file *seq = file->private_data; in input_proc_devices_poll()
1057 struct input_seq_state *state = seq->private; in input_proc_devices_poll()
1060 if (state->input_devices_state != input_devices_state) { in input_proc_devices_poll()
1061 state->input_devices_state = input_devices_state; in input_proc_devices_poll()
1070 struct input_seq_state *state = seq->private; in input_devices_seq_start()
1075 state->mutex_acquired = false; in input_devices_seq_start()
1079 state->mutex_acquired = true; in input_devices_seq_start()
1091 struct input_seq_state *state = seq->private; in input_seq_stop()
1093 if (state->mutex_acquired) in input_seq_stop()
1106 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { in input_seq_print_bitmap()
1126 const char *path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); in input_devices_seq_show()
1127 struct input_handle *handle; in input_devices_seq_show() local
1130 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); in input_devices_seq_show()
1132 seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : ""); in input_devices_seq_show()
1133 seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : ""); in input_devices_seq_show()
1135 seq_printf(seq, "U: Uniq=%s\n", dev->uniq ? dev->uniq : ""); in input_devices_seq_show()
1138 list_for_each_entry(handle, &dev->h_list, d_node) in input_devices_seq_show()
1139 seq_printf(seq, "%s ", handle->name); in input_devices_seq_show()
1142 input_seq_print_bitmap(seq, "PROP", dev->propbit, INPUT_PROP_MAX); in input_devices_seq_show()
1144 input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX); in input_devices_seq_show()
1145 if (test_bit(EV_KEY, dev->evbit)) in input_devices_seq_show()
1146 input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX); in input_devices_seq_show()
1147 if (test_bit(EV_REL, dev->evbit)) in input_devices_seq_show()
1148 input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX); in input_devices_seq_show()
1149 if (test_bit(EV_ABS, dev->evbit)) in input_devices_seq_show()
1150 input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX); in input_devices_seq_show()
1151 if (test_bit(EV_MSC, dev->evbit)) in input_devices_seq_show()
1152 input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX); in input_devices_seq_show()
1153 if (test_bit(EV_LED, dev->evbit)) in input_devices_seq_show()
1154 input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX); in input_devices_seq_show()
1155 if (test_bit(EV_SND, dev->evbit)) in input_devices_seq_show()
1156 input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX); in input_devices_seq_show()
1157 if (test_bit(EV_FF, dev->evbit)) in input_devices_seq_show()
1158 input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX); in input_devices_seq_show()
1159 if (test_bit(EV_SW, dev->evbit)) in input_devices_seq_show()
1160 input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX); in input_devices_seq_show()
1191 struct input_seq_state *state = seq->private; in input_handlers_seq_start()
1196 state->mutex_acquired = false; in input_handlers_seq_start()
1200 state->mutex_acquired = true; in input_handlers_seq_start()
1201 state->pos = *pos; in input_handlers_seq_start()
1208 struct input_seq_state *state = seq->private; in input_handlers_seq_next()
1210 state->pos = *pos + 1; in input_handlers_seq_next()
1217 struct input_seq_state *state = seq->private; in input_handlers_seq_show()
1219 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); in input_handlers_seq_show()
1220 if (handler->filter) in input_handlers_seq_show()
1222 if (handler->legacy_minors) in input_handlers_seq_show()
1223 seq_printf(seq, " Minor=%d", handler->minor); in input_handlers_seq_show()
1255 return -ENOMEM; in input_proc_init()
1271 return -ENOMEM; in input_proc_init()
1288 static ssize_t input_dev_show_##name(struct device *dev, \
1295 input_dev->name ? input_dev->name : ""); \
1312 len += snprintf(buf + len, max(size - len, 0), "%X,", bit); in input_print_modalias_bits()
1322 "input:b%04Xv%04Xp%04Xe%04X-", in input_print_modalias_parts()
1323 id->id.bustype, id->id.vendor, in input_print_modalias_parts()
1324 id->id.product, id->id.version); in input_print_modalias_parts()
1326 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1327 'e', id->evbit, 0, EV_MAX); in input_print_modalias_parts()
1333 space = max(size - (len + 1), 0); in input_print_modalias_parts()
1335 klen = input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1336 'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX); in input_print_modalias_parts()
1349 remainder = full_len - len; in input_print_modalias_parts()
1354 if (remainder <= space - 3) { in input_print_modalias_parts()
1360 for (int i = size - 1 - remainder - 3; i >= 0; i--) { in input_print_modalias_parts()
1370 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1371 'r', id->relbit, 0, REL_MAX); in input_print_modalias_parts()
1372 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1373 'a', id->absbit, 0, ABS_MAX); in input_print_modalias_parts()
1374 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1375 'm', id->mscbit, 0, MSC_MAX); in input_print_modalias_parts()
1376 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1377 'l', id->ledbit, 0, LED_MAX); in input_print_modalias_parts()
1378 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1379 's', id->sndbit, 0, SND_MAX); in input_print_modalias_parts()
1380 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1381 'f', id->ffbit, 0, FF_MAX); in input_print_modalias_parts()
1382 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1383 'w', id->swbit, 0, SW_MAX); in input_print_modalias_parts()
1404 static ssize_t input_dev_show_modalias(struct device *dev, in input_dev_show_modalias()
1412 if (len < PAGE_SIZE - 2) in input_dev_show_modalias()
1413 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); in input_dev_show_modalias()
1422 static ssize_t input_dev_show_properties(struct device *dev, in input_dev_show_properties()
1427 int len = input_print_bitmap(buf, PAGE_SIZE, input_dev->propbit, in input_dev_show_properties()
1436 static ssize_t inhibited_show(struct device *dev, in inhibited_show()
1442 return sysfs_emit(buf, "%d\n", input_dev->inhibited); in inhibited_show()
1445 static ssize_t inhibited_store(struct device *dev, in inhibited_store()
1454 return -EINVAL; in inhibited_store()
1484 static ssize_t input_dev_show_id_##name(struct device *dev, \
1489 return sysfs_emit(buf, "%04x\n", input_dev->id.name); \
1518 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { in input_print_bitmap()
1519 len += input_bits_to_string(buf + len, max(buf_size - len, 0), in input_print_bitmap()
1524 len += snprintf(buf + len, max(buf_size - len, 0), " "); in input_print_bitmap()
1535 len += snprintf(buf + len, max(buf_size - len, 0), "\n"); in input_print_bitmap()
1541 static ssize_t input_dev_show_cap_##bm(struct device *dev, \
1547 input_dev->bm##bit, ev##_MAX, \
1589 static void input_dev_release(struct device *device) in input_dev_release() argument
1591 struct input_dev *dev = to_input_dev(device); in input_dev_release()
1595 kfree(dev->poller); in input_dev_release()
1596 kfree(dev->absinfo); in input_dev_release()
1597 kfree(dev->vals); in input_dev_release()
1604 * Input uevent interface - loading event handlers based on
1605 * device bitfields.
1613 return -ENOMEM; in input_add_uevent_bm_var()
1615 len = input_print_bitmap(&env->buf[env->buflen - 1], in input_add_uevent_bm_var()
1616 sizeof(env->buf) - env->buflen, in input_add_uevent_bm_var()
1618 if (len >= (sizeof(env->buf) - env->buflen)) in input_add_uevent_bm_var()
1619 return -ENOMEM; in input_add_uevent_bm_var()
1621 env->buflen += len; in input_add_uevent_bm_var()
1629 * avoid overflows/-ENOMEM elsewhere. To work around this let's artificially
1634 * SEQNUM=18446744073709551615 - (%llu - 28 bytes)
1638 * 68 bytes total. Allow extra buffer - 96 bytes
1648 return -ENOMEM; in input_add_uevent_modalias_var()
1650 len = input_print_modalias(&env->buf[env->buflen - 1], in input_add_uevent_modalias_var()
1651 (int)sizeof(env->buf) - env->buflen - in input_add_uevent_modalias_var()
1654 if (len >= ((int)sizeof(env->buf) - env->buflen - in input_add_uevent_modalias_var()
1656 return -ENOMEM; in input_add_uevent_modalias_var()
1658 env->buflen += len; in input_add_uevent_modalias_var()
1683 static int input_dev_uevent(const struct device *device, struct kobj_uevent_env *env) in input_dev_uevent() argument
1685 const struct input_dev *dev = to_input_dev(device); in input_dev_uevent()
1688 dev->id.bustype, dev->id.vendor, in input_dev_uevent()
1689 dev->id.product, dev->id.version); in input_dev_uevent()
1690 if (dev->name) in input_dev_uevent()
1691 INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name); in input_dev_uevent()
1692 if (dev->phys) in input_dev_uevent()
1693 INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys); in input_dev_uevent()
1694 if (dev->uniq) in input_dev_uevent()
1695 INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq); in input_dev_uevent()
1697 INPUT_ADD_HOTPLUG_BM_VAR("PROP=", dev->propbit, INPUT_PROP_MAX); in input_dev_uevent()
1699 INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX); in input_dev_uevent()
1700 if (test_bit(EV_KEY, dev->evbit)) in input_dev_uevent()
1701 INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX); in input_dev_uevent()
1702 if (test_bit(EV_REL, dev->evbit)) in input_dev_uevent()
1703 INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX); in input_dev_uevent()
1704 if (test_bit(EV_ABS, dev->evbit)) in input_dev_uevent()
1705 INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX); in input_dev_uevent()
1706 if (test_bit(EV_MSC, dev->evbit)) in input_dev_uevent()
1707 INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX); in input_dev_uevent()
1708 if (test_bit(EV_LED, dev->evbit)) in input_dev_uevent()
1709 INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX); in input_dev_uevent()
1710 if (test_bit(EV_SND, dev->evbit)) in input_dev_uevent()
1711 INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX); in input_dev_uevent()
1712 if (test_bit(EV_FF, dev->evbit)) in input_dev_uevent()
1713 INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX); in input_dev_uevent()
1714 if (test_bit(EV_SW, dev->evbit)) in input_dev_uevent()
1715 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX); in input_dev_uevent()
1727 if (!test_bit(EV_##type, dev->evbit)) \
1730 for_each_set_bit(i, dev->bits##bit, type##_CNT) { \
1731 active = test_bit(i, dev->bits); \
1735 dev->event(dev, EV_##type, i, on ? active : 0); \
1741 if (!dev->event) in input_dev_toggle()
1747 if (activate && test_bit(EV_REP, dev->evbit)) { in input_dev_toggle()
1748 dev->event(dev, EV_REP, REP_PERIOD, dev->rep[REP_PERIOD]); in input_dev_toggle()
1749 dev->event(dev, EV_REP, REP_DELAY, dev->rep[REP_DELAY]); in input_dev_toggle()
1754 * input_reset_device() - reset/restore the state of input device
1755 * @dev: input device whose state needs to be reset
1757 * This function tries to reset the state of an opened input device and
1763 guard(mutex)(&dev->mutex); in input_reset_device()
1764 guard(spinlock_irqsave)(&dev->event_lock); in input_reset_device()
1774 guard(mutex)(&dev->mutex); in input_inhibit_device()
1776 if (dev->inhibited) in input_inhibit_device()
1779 if (dev->users) { in input_inhibit_device()
1780 if (dev->close) in input_inhibit_device()
1781 dev->close(dev); in input_inhibit_device()
1782 if (dev->poller) in input_inhibit_device()
1783 input_dev_poller_stop(dev->poller); in input_inhibit_device()
1786 scoped_guard(spinlock_irq, &dev->event_lock) { in input_inhibit_device()
1793 dev->inhibited = true; in input_inhibit_device()
1802 guard(mutex)(&dev->mutex); in input_uninhibit_device()
1804 if (!dev->inhibited) in input_uninhibit_device()
1807 if (dev->users) { in input_uninhibit_device()
1808 if (dev->open) { in input_uninhibit_device()
1809 error = dev->open(dev); in input_uninhibit_device()
1813 if (dev->poller) in input_uninhibit_device()
1814 input_dev_poller_start(dev->poller); in input_uninhibit_device()
1817 dev->inhibited = false; in input_uninhibit_device()
1819 scoped_guard(spinlock_irq, &dev->event_lock) in input_uninhibit_device()
1825 static int input_dev_suspend(struct device *dev) in input_dev_suspend()
1829 guard(spinlock_irq)(&input_dev->event_lock); in input_dev_suspend()
1844 static int input_dev_resume(struct device *dev) in input_dev_resume()
1848 guard(spinlock_irq)(&input_dev->event_lock); in input_dev_resume()
1856 static int input_dev_freeze(struct device *dev) in input_dev_freeze()
1860 guard(spinlock_irq)(&input_dev->event_lock); in input_dev_freeze()
1872 static int input_dev_poweroff(struct device *dev) in input_dev_poweroff()
1876 guard(spinlock_irq)(&input_dev->event_lock); in input_dev_poweroff()
1899 static char *input_devnode(const struct device *dev, umode_t *mode) in input_devnode()
1911 * input_allocate_device - allocate memory for new input device
1921 static atomic_t input_no = ATOMIC_INIT(-1); in input_allocate_device()
1931 * when we register the device. in input_allocate_device()
1933 dev->max_vals = 10; in input_allocate_device()
1934 dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL); in input_allocate_device()
1935 if (!dev->vals) { in input_allocate_device()
1940 mutex_init(&dev->mutex); in input_allocate_device()
1941 spin_lock_init(&dev->event_lock); in input_allocate_device()
1942 timer_setup(&dev->timer, NULL, 0); in input_allocate_device()
1943 INIT_LIST_HEAD(&dev->h_list); in input_allocate_device()
1944 INIT_LIST_HEAD(&dev->node); in input_allocate_device()
1946 dev->dev.type = &input_dev_type; in input_allocate_device()
1947 dev->dev.class = &input_class; in input_allocate_device()
1948 device_initialize(&dev->dev); in input_allocate_device()
1951 * to use input_free_device() so that device core properly frees its in input_allocate_device()
1952 * resources associated with the input device. in input_allocate_device()
1955 dev_set_name(&dev->dev, "input%lu", in input_allocate_device()
1968 static int devm_input_device_match(struct device *dev, void *res, void *data) in devm_input_device_match()
1972 return devres->input == data; in devm_input_device_match()
1975 static void devm_input_device_release(struct device *dev, void *res) in devm_input_device_release()
1978 struct input_dev *input = devres->input; in devm_input_device_release()
1981 __func__, dev_name(&input->dev)); in devm_input_device_release()
1986 * devm_input_allocate_device - allocate managed input device
1987 * @dev: device owning the input device being created
1992 * freed as it will be done automatically when owner device unbinds from
1993 * its driver (or binding fails). Once managed input device is allocated,
1995 * input device. There are no special devm_input_device_[un]register()
1997 * should you need them. In most cases however, managed input device need
2000 * NOTE: the owner device is set up as parent of input device and users
2003 struct input_dev *devm_input_allocate_device(struct device *dev) in devm_input_allocate_device()
2019 input->dev.parent = dev; in devm_input_allocate_device()
2020 input->devres_managed = true; in devm_input_allocate_device()
2022 devres->input = input; in devm_input_allocate_device()
2030 * input_free_device - free memory occupied by input_dev structure
2031 * @dev: input device to free
2034 * was not called yet or if it failed. Once device was registered
2036 * reference to the device is dropped.
2038 * Device should be allocated by input_allocate_device().
2040 * NOTE: If there are references to the input device then memory
2046 if (dev->devres_managed) in input_free_device()
2047 WARN_ON(devres_destroy(dev->dev.parent, in input_free_device()
2057 * input_set_timestamp - set timestamp for input events
2058 * @dev: input device to set timestamp for
2072 dev->timestamp[INPUT_CLK_MONO] = timestamp; in input_set_timestamp()
2073 dev->timestamp[INPUT_CLK_REAL] = ktime_mono_to_real(timestamp); in input_set_timestamp()
2074 dev->timestamp[INPUT_CLK_BOOT] = ktime_mono_to_any(timestamp, in input_set_timestamp()
2080 * input_get_timestamp - get timestamp for input events
2081 * @dev: input device to get timestamp from
2083 * A valid timestamp is a timestamp of non-zero value.
2089 if (!ktime_compare(dev->timestamp[INPUT_CLK_MONO], invalid_timestamp)) in input_get_timestamp()
2092 return dev->timestamp; in input_get_timestamp()
2097 * input_set_capability - mark device as capable of a certain event
2098 * @dev: device that is capable of emitting or accepting event
2103 * bitmap the function also adjusts dev->evbit.
2117 __set_bit(code, dev->keybit); in input_set_capability()
2121 __set_bit(code, dev->relbit); in input_set_capability()
2126 __set_bit(code, dev->absbit); in input_set_capability()
2130 __set_bit(code, dev->mscbit); in input_set_capability()
2134 __set_bit(code, dev->swbit); in input_set_capability()
2138 __set_bit(code, dev->ledbit); in input_set_capability()
2142 __set_bit(code, dev->sndbit); in input_set_capability()
2146 __set_bit(code, dev->ffbit); in input_set_capability()
2159 __set_bit(type, dev->evbit); in input_set_capability()
2169 if (dev->mt) { in input_estimate_events_per_packet()
2170 mt_slots = dev->mt->num_slots; in input_estimate_events_per_packet()
2171 } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) { in input_estimate_events_per_packet()
2172 mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum - in input_estimate_events_per_packet()
2173 dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1; in input_estimate_events_per_packet()
2175 } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { in input_estimate_events_per_packet()
2183 if (test_bit(EV_ABS, dev->evbit)) in input_estimate_events_per_packet()
2184 for_each_set_bit(i, dev->absbit, ABS_CNT) in input_estimate_events_per_packet()
2187 if (test_bit(EV_REL, dev->evbit)) in input_estimate_events_per_packet()
2188 events += bitmap_weight(dev->relbit, REL_CNT); in input_estimate_events_per_packet()
2198 if (!test_bit(EV_##type, dev->evbit)) \
2199 memset(dev->bits##bit, 0, \
2200 sizeof(dev->bits##bit)); \
2217 struct input_handle *handle, *next; in __input_unregister_device() local
2222 list_for_each_entry_safe(handle, next, &dev->h_list, d_node) in __input_unregister_device()
2223 handle->handler->disconnect(handle); in __input_unregister_device()
2224 WARN_ON(!list_empty(&dev->h_list)); in __input_unregister_device()
2226 del_timer_sync(&dev->timer); in __input_unregister_device()
2227 list_del_init(&dev->node); in __input_unregister_device()
2232 device_del(&dev->dev); in __input_unregister_device()
2235 static void devm_input_device_unregister(struct device *dev, void *res) in devm_input_device_unregister()
2238 struct input_dev *input = devres->input; in devm_input_device_unregister()
2240 dev_dbg(dev, "%s: unregistering device %s\n", in devm_input_device_unregister()
2241 __func__, dev_name(&input->dev)); in devm_input_device_unregister()
2247 * dev->event_lock here to avoid racing with input_event
2254 guard(spinlock_irqsave)(&dev->event_lock); in input_repeat_key()
2256 if (!dev->inhibited && in input_repeat_key()
2257 test_bit(dev->repeat_key, dev->key) && in input_repeat_key()
2258 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { in input_repeat_key()
2261 input_handle_event(dev, EV_KEY, dev->repeat_key, 2); in input_repeat_key()
2264 if (dev->rep[REP_PERIOD]) in input_repeat_key()
2265 mod_timer(&dev->timer, jiffies + in input_repeat_key()
2266 msecs_to_jiffies(dev->rep[REP_PERIOD])); in input_repeat_key()
2271 * input_enable_softrepeat - enable software autorepeat
2272 * @dev: input device
2276 * Enable software autorepeat on the input device.
2280 dev->timer.function = input_repeat_key; in input_enable_softrepeat()
2281 dev->rep[REP_DELAY] = delay; in input_enable_softrepeat()
2282 dev->rep[REP_PERIOD] = period; in input_enable_softrepeat()
2288 lockdep_assert_held(&dev->mutex); in input_device_enabled()
2290 return !dev->inhibited && dev->users > 0; in input_device_enabled()
2301 if (dev->hint_events_per_packet < packet_size) in input_device_tune_vals()
2302 dev->hint_events_per_packet = packet_size; in input_device_tune_vals()
2304 max_vals = dev->hint_events_per_packet + 2; in input_device_tune_vals()
2305 if (dev->max_vals >= max_vals) in input_device_tune_vals()
2310 return -ENOMEM; in input_device_tune_vals()
2312 scoped_guard(spinlock_irq, &dev->event_lock) { in input_device_tune_vals()
2313 dev->max_vals = max_vals; in input_device_tune_vals()
2314 swap(dev->vals, vals); in input_device_tune_vals()
2324 * input_register_device - register device with input core
2325 * @dev: device to be registered
2327 * This function registers device with input core. The device must be
2330 * If function fails the device must be freed with input_free_device().
2331 * Once device has been successfully registered it can be unregistered
2339 * that tear down of managed input devices is internally a 2-step process:
2340 * registered managed input device is first unregistered, but stays in
2341 * memory and can still handle input_event() calls (although events will
2342 * not be delivered anywhere). The freeing of managed input device will
2343 * happen later, when devres stack is unwound to the point where device
2353 if (test_bit(EV_ABS, dev->evbit) && !dev->absinfo) { in input_register_device()
2354 dev_err(&dev->dev, in input_register_device()
2355 "Absolute device without dev->absinfo, refusing to register\n"); in input_register_device()
2356 return -EINVAL; in input_register_device()
2359 if (dev->devres_managed) { in input_register_device()
2363 return -ENOMEM; in input_register_device()
2365 devres->input = dev; in input_register_device()
2368 /* Every input device generates EV_SYN/SYN_REPORT events. */ in input_register_device()
2369 __set_bit(EV_SYN, dev->evbit); in input_register_device()
2372 __clear_bit(KEY_RESERVED, dev->keybit); in input_register_device()
2374 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ in input_register_device()
2382 * If delay and period are pre-set by the driver, then autorepeating in input_register_device()
2385 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) in input_register_device()
2388 if (!dev->getkeycode) in input_register_device()
2389 dev->getkeycode = input_default_getkeycode; in input_register_device()
2391 if (!dev->setkeycode) in input_register_device()
2392 dev->setkeycode = input_default_setkeycode; in input_register_device()
2394 if (dev->poller) in input_register_device()
2395 input_dev_poller_finalize(dev->poller); in input_register_device()
2397 error = device_add(&dev->dev); in input_register_device()
2401 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); in input_register_device()
2403 dev->name ? dev->name : "Unspecified device", in input_register_device()
2407 error = -EINTR; in input_register_device()
2409 list_add_tail(&dev->node, &input_dev_list); in input_register_device()
2417 if (dev->devres_managed) { in input_register_device()
2418 dev_dbg(dev->dev.parent, "%s: registering %s with devres.\n", in input_register_device()
2419 __func__, dev_name(&dev->dev)); in input_register_device()
2420 devres_add(dev->dev.parent, devres); in input_register_device()
2425 device_del(&dev->dev); in input_register_device()
2433 * input_unregister_device - unregister previously registered device
2434 * @dev: device to be unregistered
2436 * This function unregisters an input device. Once device is unregistered
2441 if (dev->devres_managed) { in input_unregister_device()
2442 WARN_ON(devres_destroy(dev->dev.parent, in input_unregister_device()
2462 if (handler->filter) in input_handler_check_methods()
2464 if (handler->events) in input_handler_check_methods()
2466 if (handler->event) in input_handler_check_methods()
2471 __func__, handler->name); in input_handler_check_methods()
2472 return -EINVAL; in input_handler_check_methods()
2479 * input_register_handler - register a new input handler
2495 scoped_cond_guard(mutex_intr, return -EINTR, &input_mutex) { in input_register_handler()
2496 INIT_LIST_HEAD(&handler->h_list); in input_register_handler()
2498 list_add_tail(&handler->node, &input_handler_list); in input_register_handler()
2511 * input_unregister_handler - unregisters an input handler
2519 struct input_handle *handle, *next; in input_unregister_handler() local
2523 list_for_each_entry_safe(handle, next, &handler->h_list, h_node) in input_unregister_handler()
2524 handler->disconnect(handle); in input_unregister_handler()
2525 WARN_ON(!list_empty(&handler->h_list)); in input_unregister_handler()
2527 list_del_init(&handler->node); in input_unregister_handler()
2534 * input_handler_for_each_handle - handle iterator
2537 * @fn: function to be called for each handle
2540 * it @data and stop when @fn returns a non-zero value. The function is
2548 struct input_handle *handle; in input_handler_for_each_handle() local
2553 list_for_each_entry_rcu(handle, &handler->h_list, h_node) { in input_handler_for_each_handle()
2554 retval = fn(handle, data); in input_handler_for_each_handle()
2565 * invokes handler->event() method for each event one by one.
2567 static unsigned int input_handle_events_default(struct input_handle *handle, in input_handle_events_default() argument
2571 struct input_handler *handler = handle->handler; in input_handle_events_default()
2575 handler->event(handle, v->type, v->code, v->value); in input_handle_events_default()
2582 * handler->filter() method for each event one by one and removes events
2585 static unsigned int input_handle_events_filter(struct input_handle *handle, in input_handle_events_filter() argument
2589 struct input_handler *handler = handle->handler; in input_handle_events_filter()
2594 if (handler->filter(handle, v->type, v->code, v->value)) in input_handle_events_filter()
2601 return end - vals; in input_handle_events_filter()
2607 static unsigned int input_handle_events_null(struct input_handle *handle, in input_handle_events_null() argument
2615 * Sets up appropriate handle->event_handler based on the input_handler
2616 * associated with the handle.
2618 static void input_handle_setup_event_handler(struct input_handle *handle) in input_handle_setup_event_handler() argument
2620 struct input_handler *handler = handle->handler; in input_handle_setup_event_handler()
2622 if (handler->filter) in input_handle_setup_event_handler()
2623 handle->handle_events = input_handle_events_filter; in input_handle_setup_event_handler()
2624 else if (handler->event) in input_handle_setup_event_handler()
2625 handle->handle_events = input_handle_events_default; in input_handle_setup_event_handler()
2626 else if (handler->events) in input_handle_setup_event_handler()
2627 handle->handle_events = handler->events; in input_handle_setup_event_handler()
2629 handle->handle_events = input_handle_events_null; in input_handle_setup_event_handler()
2633 * input_register_handle - register a new input handle
2634 * @handle: handle to register
2636 * This function puts a new input handle onto device's
2643 int input_register_handle(struct input_handle *handle) in input_register_handle() argument
2645 struct input_handler *handler = handle->handler; in input_register_handle()
2646 struct input_dev *dev = handle->dev; in input_register_handle()
2648 input_handle_setup_event_handler(handle); in input_register_handle()
2650 * We take dev->mutex here to prevent race with in input_register_handle()
2653 scoped_cond_guard(mutex_intr, return -EINTR, &dev->mutex) { in input_register_handle()
2658 if (handler->filter) in input_register_handle()
2659 list_add_rcu(&handle->d_node, &dev->h_list); in input_register_handle()
2661 list_add_tail_rcu(&handle->d_node, &dev->h_list); in input_register_handle()
2665 * Since we are supposed to be called from ->connect() in input_register_handle()
2666 * which is mutually exclusive with ->disconnect() in input_register_handle()
2670 list_add_tail_rcu(&handle->h_node, &handler->h_list); in input_register_handle()
2672 if (handler->start) in input_register_handle()
2673 handler->start(handle); in input_register_handle()
2680 * input_unregister_handle - unregister an input handle
2681 * @handle: handle to unregister
2683 * This function removes input handle from device's
2689 void input_unregister_handle(struct input_handle *handle) in input_unregister_handle() argument
2691 struct input_dev *dev = handle->dev; in input_unregister_handle()
2693 list_del_rcu(&handle->h_node); in input_unregister_handle()
2696 * Take dev->mutex to prevent race with input_release_device(). in input_unregister_handle()
2698 scoped_guard(mutex, &dev->mutex) in input_unregister_handle()
2699 list_del_rcu(&handle->d_node); in input_unregister_handle()
2706 * input_get_new_minor - allocates a new input minor number
2711 * This function allocates a new device minor for from input major namespace.
2720 * This function should be called from input handler's ->connect() in input_get_new_minor()
2726 legacy_base + legacy_num - 1, in input_get_new_minor()
2733 INPUT_MAX_CHAR_DEVICES - 1, GFP_KERNEL); in input_get_new_minor()
2738 * input_free_minor - release previously allocated minor