Lines Matching +full:sw +full:- +full:managed
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 1999-2002 Vojtech Pavlik
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()
108 * This function is called with dev->event_lock held and interrupts disabled.
116 lockdep_assert_held(&dev->event_lock); in input_pass_values()
120 handle = rcu_dereference(dev->grab); 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
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
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()
431 spin_unlock_irqrestore(&dev->event_lock, flags); in input_inject_event()
437 * input_alloc_absinfo - allocates array of input_absinfo structs
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()
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
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
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()
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()
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
577 struct input_dev *dev = handle->dev; in input_release_device()
579 mutex_lock(&dev->mutex); in input_release_device()
581 mutex_unlock(&dev->mutex); in input_release_device()
586 * input_open_device - open input device
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 (handle->handler->passive_observer) in input_open_device()
611 if (dev->users++ || dev->inhibited) { in input_open_device()
619 if (dev->open) { in input_open_device()
620 retval = dev->open(dev); in input_open_device()
622 dev->users--; in input_open_device()
623 handle->open--; in input_open_device()
633 if (dev->poller) in input_open_device()
634 input_dev_poller_start(dev->poller); in input_open_device()
637 mutex_unlock(&dev->mutex); in input_open_device()
644 struct input_dev *dev = handle->dev; in input_flush_device()
647 retval = mutex_lock_interruptible(&dev->mutex); in input_flush_device()
651 if (dev->flush) in input_flush_device()
652 retval = dev->flush(dev, file); in input_flush_device()
654 mutex_unlock(&dev->mutex); in input_flush_device()
660 * input_close_device - close input device
668 struct input_dev *dev = handle->dev; in input_close_device()
670 mutex_lock(&dev->mutex); in input_close_device()
674 if (!handle->handler->passive_observer) { in input_close_device()
675 if (!--dev->users && !dev->inhibited) { in input_close_device()
676 if (dev->poller) in input_close_device()
677 input_dev_poller_stop(dev->poller); in input_close_device()
678 if (dev->close) in input_close_device()
679 dev->close(dev); in input_close_device()
683 if (!--handle->open) { in input_close_device()
692 mutex_unlock(&dev->mutex); in input_close_device()
698 * The function must be called with dev->event_lock held.
705 lockdep_assert_held(&dev->event_lock); in input_dev_release_keys()
707 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { in input_dev_release_keys()
708 for_each_set_bit(code, dev->key, KEY_CNT) { in input_dev_release_keys()
725 * Mark device as going away. Note that we take dev->mutex here in input_disconnect_device()
726 * not to protect access to dev->going_away but rather to ensure in input_disconnect_device()
729 mutex_lock(&dev->mutex); in input_disconnect_device()
730 dev->going_away = true; in input_disconnect_device()
731 mutex_unlock(&dev->mutex); in input_disconnect_device()
733 spin_lock_irq(&dev->event_lock); in input_disconnect_device()
744 list_for_each_entry(handle, &dev->h_list, d_node) in input_disconnect_device()
745 handle->open = 0; in input_disconnect_device()
747 spin_unlock_irq(&dev->event_lock); in input_disconnect_device()
751 * input_scancode_to_scalar() - converts scancode in &struct input_keymap_entry
763 switch (ke->len) { in input_scancode_to_scalar()
765 *scancode = *((u8 *)ke->scancode); in input_scancode_to_scalar()
769 *scancode = *((u16 *)ke->scancode); in input_scancode_to_scalar()
773 *scancode = *((u32 *)ke->scancode); in input_scancode_to_scalar()
777 return -EINVAL; in input_scancode_to_scalar()
792 switch (dev->keycodesize) { in input_fetch_keycode()
794 return ((u8 *)dev->keycode)[index]; in input_fetch_keycode()
797 return ((u16 *)dev->keycode)[index]; in input_fetch_keycode()
800 return ((u32 *)dev->keycode)[index]; in input_fetch_keycode()
810 if (!dev->keycodesize) in input_default_getkeycode()
811 return -EINVAL; in input_default_getkeycode()
813 if (ke->flags & INPUT_KEYMAP_BY_INDEX) in input_default_getkeycode()
814 index = ke->index; in input_default_getkeycode()
821 if (index >= dev->keycodemax) in input_default_getkeycode()
822 return -EINVAL; in input_default_getkeycode()
824 ke->keycode = input_fetch_keycode(dev, index); in input_default_getkeycode()
825 ke->index = index; in input_default_getkeycode()
826 ke->len = sizeof(index); in input_default_getkeycode()
827 memcpy(ke->scancode, &index, sizeof(index)); in input_default_getkeycode()
840 if (!dev->keycodesize) in input_default_setkeycode()
841 return -EINVAL; in input_default_setkeycode()
843 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in input_default_setkeycode()
844 index = ke->index; in input_default_setkeycode()
851 if (index >= dev->keycodemax) in input_default_setkeycode()
852 return -EINVAL; in input_default_setkeycode()
854 if (dev->keycodesize < sizeof(ke->keycode) && in input_default_setkeycode()
855 (ke->keycode >> (dev->keycodesize * 8))) in input_default_setkeycode()
856 return -EINVAL; in input_default_setkeycode()
858 switch (dev->keycodesize) { in input_default_setkeycode()
860 u8 *k = (u8 *)dev->keycode; in input_default_setkeycode()
862 k[index] = ke->keycode; in input_default_setkeycode()
866 u16 *k = (u16 *)dev->keycode; in input_default_setkeycode()
868 k[index] = ke->keycode; in input_default_setkeycode()
872 u32 *k = (u32 *)dev->keycode; in input_default_setkeycode()
874 k[index] = ke->keycode; in input_default_setkeycode()
880 __clear_bit(*old_keycode, dev->keybit); in input_default_setkeycode()
881 for (i = 0; i < dev->keycodemax; i++) { in input_default_setkeycode()
883 __set_bit(*old_keycode, dev->keybit); in input_default_setkeycode()
890 __set_bit(ke->keycode, dev->keybit); in input_default_setkeycode()
895 * input_get_keycode - retrieve keycode currently mapped to a given scancode
907 spin_lock_irqsave(&dev->event_lock, flags); in input_get_keycode()
908 retval = dev->getkeycode(dev, ke); in input_get_keycode()
909 spin_unlock_irqrestore(&dev->event_lock, flags); in input_get_keycode()
916 * input_set_keycode - attribute a keycode to a given scancode
930 if (ke->keycode > KEY_MAX) in input_set_keycode()
931 return -EINVAL; in input_set_keycode()
933 spin_lock_irqsave(&dev->event_lock, flags); in input_set_keycode()
935 retval = dev->setkeycode(dev, ke, &old_keycode); in input_set_keycode()
940 __clear_bit(KEY_RESERVED, dev->keybit); in input_set_keycode()
947 dev_warn(dev->dev.parent ?: &dev->dev, in input_set_keycode()
950 } else if (test_bit(EV_KEY, dev->evbit) && in input_set_keycode()
951 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && in input_set_keycode()
952 __test_and_clear_bit(old_keycode, dev->key)) { in input_set_keycode()
966 spin_unlock_irqrestore(&dev->event_lock, flags); in input_set_keycode()
975 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) in input_match_device_id()
976 if (id->bustype != dev->id.bustype) in input_match_device_id()
979 if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR) in input_match_device_id()
980 if (id->vendor != dev->id.vendor) in input_match_device_id()
983 if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT) in input_match_device_id()
984 if (id->product != dev->id.product) in input_match_device_id()
987 if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION) in input_match_device_id()
988 if (id->version != dev->id.version) in input_match_device_id()
991 if (!bitmap_subset(id->evbit, dev->evbit, EV_MAX) || in input_match_device_id()
992 !bitmap_subset(id->keybit, dev->keybit, KEY_MAX) || in input_match_device_id()
993 !bitmap_subset(id->relbit, dev->relbit, REL_MAX) || in input_match_device_id()
994 !bitmap_subset(id->absbit, dev->absbit, ABS_MAX) || in input_match_device_id()
995 !bitmap_subset(id->mscbit, dev->mscbit, MSC_MAX) || in input_match_device_id()
996 !bitmap_subset(id->ledbit, dev->ledbit, LED_MAX) || in input_match_device_id()
997 !bitmap_subset(id->sndbit, dev->sndbit, SND_MAX) || in input_match_device_id()
998 !bitmap_subset(id->ffbit, dev->ffbit, FF_MAX) || in input_match_device_id()
999 !bitmap_subset(id->swbit, dev->swbit, SW_MAX) || in input_match_device_id()
1000 !bitmap_subset(id->propbit, dev->propbit, INPUT_PROP_MAX)) { in input_match_device_id()
1013 for (id = handler->id_table; id->flags || id->driver_info; id++) { in input_match_device()
1015 (!handler->match || handler->match(handler, dev))) { in input_match_device()
1030 return -ENODEV; in input_attach_handler()
1032 error = handler->connect(handler, dev, id); in input_attach_handler()
1033 if (error && error != -ENODEV) in input_attach_handler()
1035 handler->name, kobject_name(&dev->dev.kobj), error); in input_attach_handler()
1054 len += snprintf(buf + len, max(buf_size - len, 0), in input_bits_to_string()
1095 struct seq_file *seq = file->private_data; in input_proc_devices_poll()
1096 struct input_seq_state *state = seq->private; in input_proc_devices_poll()
1099 if (state->input_devices_state != input_devices_state) { in input_proc_devices_poll()
1100 state->input_devices_state = input_devices_state; in input_proc_devices_poll()
1109 struct input_seq_state *state = seq->private; in input_devices_seq_start()
1114 state->mutex_acquired = false; in input_devices_seq_start()
1118 state->mutex_acquired = true; in input_devices_seq_start()
1130 struct input_seq_state *state = seq->private; in input_seq_stop()
1132 if (state->mutex_acquired) in input_seq_stop()
1145 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { in input_seq_print_bitmap()
1165 const char *path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); in input_devices_seq_show()
1169 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); in input_devices_seq_show()
1171 seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : ""); in input_devices_seq_show()
1172 seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : ""); in input_devices_seq_show()
1174 seq_printf(seq, "U: Uniq=%s\n", dev->uniq ? dev->uniq : ""); in input_devices_seq_show()
1177 list_for_each_entry(handle, &dev->h_list, d_node) in input_devices_seq_show()
1178 seq_printf(seq, "%s ", handle->name); in input_devices_seq_show()
1181 input_seq_print_bitmap(seq, "PROP", dev->propbit, INPUT_PROP_MAX); in input_devices_seq_show()
1183 input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX); in input_devices_seq_show()
1184 if (test_bit(EV_KEY, dev->evbit)) in input_devices_seq_show()
1185 input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX); in input_devices_seq_show()
1186 if (test_bit(EV_REL, dev->evbit)) in input_devices_seq_show()
1187 input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX); in input_devices_seq_show()
1188 if (test_bit(EV_ABS, dev->evbit)) in input_devices_seq_show()
1189 input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX); in input_devices_seq_show()
1190 if (test_bit(EV_MSC, dev->evbit)) in input_devices_seq_show()
1191 input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX); in input_devices_seq_show()
1192 if (test_bit(EV_LED, dev->evbit)) in input_devices_seq_show()
1193 input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX); in input_devices_seq_show()
1194 if (test_bit(EV_SND, dev->evbit)) in input_devices_seq_show()
1195 input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX); in input_devices_seq_show()
1196 if (test_bit(EV_FF, dev->evbit)) in input_devices_seq_show()
1197 input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX); in input_devices_seq_show()
1198 if (test_bit(EV_SW, dev->evbit)) in input_devices_seq_show()
1199 input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX); in input_devices_seq_show()
1230 struct input_seq_state *state = seq->private; in input_handlers_seq_start()
1235 state->mutex_acquired = false; in input_handlers_seq_start()
1239 state->mutex_acquired = true; in input_handlers_seq_start()
1240 state->pos = *pos; in input_handlers_seq_start()
1247 struct input_seq_state *state = seq->private; in input_handlers_seq_next()
1249 state->pos = *pos + 1; in input_handlers_seq_next()
1256 struct input_seq_state *state = seq->private; in input_handlers_seq_show()
1258 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); in input_handlers_seq_show()
1259 if (handler->filter) in input_handlers_seq_show()
1261 if (handler->legacy_minors) in input_handlers_seq_show()
1262 seq_printf(seq, " Minor=%d", handler->minor); in input_handlers_seq_show()
1294 return -ENOMEM; in input_proc_init()
1310 return -ENOMEM; in input_proc_init()
1334 input_dev->name ? input_dev->name : ""); \
1351 len += snprintf(buf + len, max(size - len, 0), "%X,", bit); in input_print_modalias_bits()
1361 "input:b%04Xv%04Xp%04Xe%04X-", in input_print_modalias_parts()
1362 id->id.bustype, id->id.vendor, in input_print_modalias_parts()
1363 id->id.product, id->id.version); in input_print_modalias_parts()
1365 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1366 'e', id->evbit, 0, EV_MAX); in input_print_modalias_parts()
1372 space = max(size - (len + 1), 0); in input_print_modalias_parts()
1374 klen = input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1375 'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX); in input_print_modalias_parts()
1388 remainder = full_len - len; in input_print_modalias_parts()
1393 if (remainder <= space - 3) { in input_print_modalias_parts()
1399 for (int i = size - 1 - remainder - 3; i >= 0; i--) { in input_print_modalias_parts()
1409 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1410 'r', id->relbit, 0, REL_MAX); in input_print_modalias_parts()
1411 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1412 'a', id->absbit, 0, ABS_MAX); in input_print_modalias_parts()
1413 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1414 'm', id->mscbit, 0, MSC_MAX); in input_print_modalias_parts()
1415 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1416 'l', id->ledbit, 0, LED_MAX); in input_print_modalias_parts()
1417 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1418 's', id->sndbit, 0, SND_MAX); in input_print_modalias_parts()
1419 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1420 'f', id->ffbit, 0, FF_MAX); in input_print_modalias_parts()
1421 len += input_print_modalias_bits(buf + len, size - len, in input_print_modalias_parts()
1422 'w', id->swbit, 0, SW_MAX); in input_print_modalias_parts()
1451 if (len < PAGE_SIZE - 2) in input_dev_show_modalias()
1452 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); in input_dev_show_modalias()
1466 int len = input_print_bitmap(buf, PAGE_SIZE, input_dev->propbit, in input_dev_show_properties()
1481 return sysfs_emit(buf, "%d\n", input_dev->inhibited); in inhibited_show()
1493 return -EINVAL; in inhibited_store()
1528 return sysfs_emit(buf, "%04x\n", input_dev->id.name); \
1557 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { in input_print_bitmap()
1558 len += input_bits_to_string(buf + len, max(buf_size - len, 0), in input_print_bitmap()
1563 len += snprintf(buf + len, max(buf_size - len, 0), " "); in input_print_bitmap()
1574 len += snprintf(buf + len, max(buf_size - len, 0), "\n"); in input_print_bitmap()
1586 input_dev->bm##bit, ev##_MAX, \
1600 INPUT_DEV_CAP_ATTR(SW, sw);
1634 kfree(dev->poller); in input_dev_release()
1635 kfree(dev->absinfo); in input_dev_release()
1636 kfree(dev->vals); in input_dev_release()
1643 * Input uevent interface - loading event handlers based on
1652 return -ENOMEM; in input_add_uevent_bm_var()
1654 len = input_print_bitmap(&env->buf[env->buflen - 1], in input_add_uevent_bm_var()
1655 sizeof(env->buf) - env->buflen, in input_add_uevent_bm_var()
1657 if (len >= (sizeof(env->buf) - env->buflen)) in input_add_uevent_bm_var()
1658 return -ENOMEM; in input_add_uevent_bm_var()
1660 env->buflen += len; in input_add_uevent_bm_var()
1668 * avoid overflows/-ENOMEM elsewhere. To work around this let's artificially
1673 * SEQNUM=18446744073709551615 - (%llu - 28 bytes)
1677 * 68 bytes total. Allow extra buffer - 96 bytes
1687 return -ENOMEM; in input_add_uevent_modalias_var()
1689 len = input_print_modalias(&env->buf[env->buflen - 1], in input_add_uevent_modalias_var()
1690 (int)sizeof(env->buf) - env->buflen - in input_add_uevent_modalias_var()
1693 if (len >= ((int)sizeof(env->buf) - env->buflen - in input_add_uevent_modalias_var()
1695 return -ENOMEM; in input_add_uevent_modalias_var()
1697 env->buflen += len; in input_add_uevent_modalias_var()
1727 dev->id.bustype, dev->id.vendor, in input_dev_uevent()
1728 dev->id.product, dev->id.version); in input_dev_uevent()
1729 if (dev->name) in input_dev_uevent()
1730 INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name); in input_dev_uevent()
1731 if (dev->phys) in input_dev_uevent()
1732 INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys); in input_dev_uevent()
1733 if (dev->uniq) in input_dev_uevent()
1734 INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq); in input_dev_uevent()
1736 INPUT_ADD_HOTPLUG_BM_VAR("PROP=", dev->propbit, INPUT_PROP_MAX); in input_dev_uevent()
1738 INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX); in input_dev_uevent()
1739 if (test_bit(EV_KEY, dev->evbit)) in input_dev_uevent()
1740 INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX); in input_dev_uevent()
1741 if (test_bit(EV_REL, dev->evbit)) in input_dev_uevent()
1742 INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX); in input_dev_uevent()
1743 if (test_bit(EV_ABS, dev->evbit)) in input_dev_uevent()
1744 INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX); in input_dev_uevent()
1745 if (test_bit(EV_MSC, dev->evbit)) in input_dev_uevent()
1746 INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX); in input_dev_uevent()
1747 if (test_bit(EV_LED, dev->evbit)) in input_dev_uevent()
1748 INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX); in input_dev_uevent()
1749 if (test_bit(EV_SND, dev->evbit)) in input_dev_uevent()
1750 INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX); in input_dev_uevent()
1751 if (test_bit(EV_FF, dev->evbit)) in input_dev_uevent()
1752 INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX); in input_dev_uevent()
1753 if (test_bit(EV_SW, dev->evbit)) in input_dev_uevent()
1754 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX); in input_dev_uevent()
1766 if (!test_bit(EV_##type, dev->evbit)) \
1769 for_each_set_bit(i, dev->bits##bit, type##_CNT) { \
1770 active = test_bit(i, dev->bits); \
1774 dev->event(dev, EV_##type, i, on ? active : 0); \
1780 if (!dev->event) in input_dev_toggle()
1786 if (activate && test_bit(EV_REP, dev->evbit)) { in input_dev_toggle()
1787 dev->event(dev, EV_REP, REP_PERIOD, dev->rep[REP_PERIOD]); in input_dev_toggle()
1788 dev->event(dev, EV_REP, REP_DELAY, dev->rep[REP_DELAY]); in input_dev_toggle()
1793 * input_reset_device() - reset/restore the state of input device
1804 mutex_lock(&dev->mutex); in input_reset_device()
1805 spin_lock_irqsave(&dev->event_lock, flags); in input_reset_device()
1811 spin_unlock_irqrestore(&dev->event_lock, flags); in input_reset_device()
1812 mutex_unlock(&dev->mutex); in input_reset_device()
1818 mutex_lock(&dev->mutex); in input_inhibit_device()
1820 if (dev->inhibited) in input_inhibit_device()
1823 if (dev->users) { in input_inhibit_device()
1824 if (dev->close) in input_inhibit_device()
1825 dev->close(dev); in input_inhibit_device()
1826 if (dev->poller) in input_inhibit_device()
1827 input_dev_poller_stop(dev->poller); in input_inhibit_device()
1830 spin_lock_irq(&dev->event_lock); in input_inhibit_device()
1835 spin_unlock_irq(&dev->event_lock); in input_inhibit_device()
1837 dev->inhibited = true; in input_inhibit_device()
1840 mutex_unlock(&dev->mutex); in input_inhibit_device()
1848 mutex_lock(&dev->mutex); in input_uninhibit_device()
1850 if (!dev->inhibited) in input_uninhibit_device()
1853 if (dev->users) { in input_uninhibit_device()
1854 if (dev->open) { in input_uninhibit_device()
1855 ret = dev->open(dev); in input_uninhibit_device()
1859 if (dev->poller) in input_uninhibit_device()
1860 input_dev_poller_start(dev->poller); in input_uninhibit_device()
1863 dev->inhibited = false; in input_uninhibit_device()
1864 spin_lock_irq(&dev->event_lock); in input_uninhibit_device()
1866 spin_unlock_irq(&dev->event_lock); in input_uninhibit_device()
1869 mutex_unlock(&dev->mutex); in input_uninhibit_device()
1877 spin_lock_irq(&input_dev->event_lock); in input_dev_suspend()
1889 spin_unlock_irq(&input_dev->event_lock); in input_dev_suspend()
1898 spin_lock_irq(&input_dev->event_lock); in input_dev_resume()
1903 spin_unlock_irq(&input_dev->event_lock); in input_dev_resume()
1912 spin_lock_irq(&input_dev->event_lock); in input_dev_freeze()
1921 spin_unlock_irq(&input_dev->event_lock); in input_dev_freeze()
1930 spin_lock_irq(&input_dev->event_lock); in input_dev_poweroff()
1935 spin_unlock_irq(&input_dev->event_lock); in input_dev_poweroff()
1967 * input_allocate_device - allocate memory for new input device
1977 static atomic_t input_no = ATOMIC_INIT(-1); in input_allocate_device()
1989 dev->max_vals = 10; in input_allocate_device()
1990 dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL); in input_allocate_device()
1991 if (!dev->vals) { in input_allocate_device()
1996 mutex_init(&dev->mutex); in input_allocate_device()
1997 spin_lock_init(&dev->event_lock); in input_allocate_device()
1998 timer_setup(&dev->timer, NULL, 0); in input_allocate_device()
1999 INIT_LIST_HEAD(&dev->h_list); in input_allocate_device()
2000 INIT_LIST_HEAD(&dev->node); in input_allocate_device()
2002 dev->dev.type = &input_dev_type; in input_allocate_device()
2003 dev->dev.class = &input_class; in input_allocate_device()
2004 device_initialize(&dev->dev); in input_allocate_device()
2011 dev_set_name(&dev->dev, "input%lu", in input_allocate_device()
2028 return devres->input == data; in devm_input_device_match()
2034 struct input_dev *input = devres->input; in devm_input_device_release()
2037 __func__, dev_name(&input->dev)); in devm_input_device_release()
2042 * devm_input_allocate_device - allocate managed input device
2047 * Managed input devices do not need to be explicitly unregistered or
2049 * its driver (or binding fails). Once managed input device is allocated,
2052 * variants, regular ones work with both managed and unmanaged devices,
2053 * should you need them. In most cases however, managed input device need
2075 input->dev.parent = dev; in devm_input_allocate_device()
2076 input->devres_managed = true; in devm_input_allocate_device()
2078 devres->input = input; in devm_input_allocate_device()
2086 * input_free_device - free memory occupied by input_dev structure
2102 if (dev->devres_managed) in input_free_device()
2103 WARN_ON(devres_destroy(dev->dev.parent, in input_free_device()
2113 * input_set_timestamp - set timestamp for input events
2128 dev->timestamp[INPUT_CLK_MONO] = timestamp; in input_set_timestamp()
2129 dev->timestamp[INPUT_CLK_REAL] = ktime_mono_to_real(timestamp); in input_set_timestamp()
2130 dev->timestamp[INPUT_CLK_BOOT] = ktime_mono_to_any(timestamp, in input_set_timestamp()
2136 * input_get_timestamp - get timestamp for input events
2139 * A valid timestamp is a timestamp of non-zero value.
2145 if (!ktime_compare(dev->timestamp[INPUT_CLK_MONO], invalid_timestamp)) in input_get_timestamp()
2148 return dev->timestamp; in input_get_timestamp()
2153 * input_set_capability - mark device as capable of a certain event
2159 * bitmap the function also adjusts dev->evbit.
2173 __set_bit(code, dev->keybit); in input_set_capability()
2177 __set_bit(code, dev->relbit); in input_set_capability()
2182 __set_bit(code, dev->absbit); in input_set_capability()
2186 __set_bit(code, dev->mscbit); in input_set_capability()
2190 __set_bit(code, dev->swbit); in input_set_capability()
2194 __set_bit(code, dev->ledbit); in input_set_capability()
2198 __set_bit(code, dev->sndbit); in input_set_capability()
2202 __set_bit(code, dev->ffbit); in input_set_capability()
2215 __set_bit(type, dev->evbit); in input_set_capability()
2225 if (dev->mt) { in input_estimate_events_per_packet()
2226 mt_slots = dev->mt->num_slots; in input_estimate_events_per_packet()
2227 } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) { in input_estimate_events_per_packet()
2228 mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum - in input_estimate_events_per_packet()
2229 dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1; in input_estimate_events_per_packet()
2231 } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { in input_estimate_events_per_packet()
2239 if (test_bit(EV_ABS, dev->evbit)) in input_estimate_events_per_packet()
2240 for_each_set_bit(i, dev->absbit, ABS_CNT) in input_estimate_events_per_packet()
2243 if (test_bit(EV_REL, dev->evbit)) in input_estimate_events_per_packet()
2244 events += bitmap_weight(dev->relbit, REL_CNT); in input_estimate_events_per_packet()
2254 if (!test_bit(EV_##type, dev->evbit)) \
2255 memset(dev->bits##bit, 0, \
2256 sizeof(dev->bits##bit)); \
2268 INPUT_CLEANSE_BITMASK(dev, SW, sw); in input_cleanse_bitmasks()
2279 list_for_each_entry_safe(handle, next, &dev->h_list, d_node) in __input_unregister_device()
2280 handle->handler->disconnect(handle); in __input_unregister_device()
2281 WARN_ON(!list_empty(&dev->h_list)); in __input_unregister_device()
2283 del_timer_sync(&dev->timer); in __input_unregister_device()
2284 list_del_init(&dev->node); in __input_unregister_device()
2290 device_del(&dev->dev); in __input_unregister_device()
2296 struct input_dev *input = devres->input; in devm_input_device_unregister()
2299 __func__, dev_name(&input->dev)); in devm_input_device_unregister()
2305 * dev->event_lock here to avoid racing with input_event
2313 spin_lock_irqsave(&dev->event_lock, flags); in input_repeat_key()
2315 if (!dev->inhibited && in input_repeat_key()
2316 test_bit(dev->repeat_key, dev->key) && in input_repeat_key()
2317 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { in input_repeat_key()
2320 input_handle_event(dev, EV_KEY, dev->repeat_key, 2); in input_repeat_key()
2323 if (dev->rep[REP_PERIOD]) in input_repeat_key()
2324 mod_timer(&dev->timer, jiffies + in input_repeat_key()
2325 msecs_to_jiffies(dev->rep[REP_PERIOD])); in input_repeat_key()
2328 spin_unlock_irqrestore(&dev->event_lock, flags); in input_repeat_key()
2332 * input_enable_softrepeat - enable software autorepeat
2341 dev->timer.function = input_repeat_key; in input_enable_softrepeat()
2342 dev->rep[REP_DELAY] = delay; in input_enable_softrepeat()
2343 dev->rep[REP_PERIOD] = period; in input_enable_softrepeat()
2349 lockdep_assert_held(&dev->mutex); in input_device_enabled()
2351 return !dev->inhibited && dev->users > 0; in input_device_enabled()
2362 if (dev->hint_events_per_packet < packet_size) in input_device_tune_vals()
2363 dev->hint_events_per_packet = packet_size; in input_device_tune_vals()
2365 max_vals = dev->hint_events_per_packet + 2; in input_device_tune_vals()
2366 if (dev->max_vals >= max_vals) in input_device_tune_vals()
2371 return -ENOMEM; in input_device_tune_vals()
2373 spin_lock_irq(&dev->event_lock); in input_device_tune_vals()
2374 dev->max_vals = max_vals; in input_device_tune_vals()
2375 swap(dev->vals, vals); in input_device_tune_vals()
2376 spin_unlock_irq(&dev->event_lock); in input_device_tune_vals()
2385 * input_register_device - register device with input core
2396 * Note that this function is also used to register managed input devices
2397 * (ones allocated with devm_input_allocate_device()). Such managed input
2400 * that tear down of managed input devices is internally a 2-step process:
2401 * registered managed input device is first unregistered, but stays in
2403 * not be delivered anywhere). The freeing of managed input device will
2414 if (test_bit(EV_ABS, dev->evbit) && !dev->absinfo) { in input_register_device()
2415 dev_err(&dev->dev, in input_register_device()
2416 "Absolute device without dev->absinfo, refusing to register\n"); in input_register_device()
2417 return -EINVAL; in input_register_device()
2420 if (dev->devres_managed) { in input_register_device()
2424 return -ENOMEM; in input_register_device()
2426 devres->input = dev; in input_register_device()
2430 __set_bit(EV_SYN, dev->evbit); in input_register_device()
2433 __clear_bit(KEY_RESERVED, dev->keybit); in input_register_device()
2435 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ in input_register_device()
2443 * If delay and period are pre-set by the driver, then autorepeating in input_register_device()
2446 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) in input_register_device()
2449 if (!dev->getkeycode) in input_register_device()
2450 dev->getkeycode = input_default_getkeycode; in input_register_device()
2452 if (!dev->setkeycode) in input_register_device()
2453 dev->setkeycode = input_default_setkeycode; in input_register_device()
2455 if (dev->poller) in input_register_device()
2456 input_dev_poller_finalize(dev->poller); in input_register_device()
2458 error = device_add(&dev->dev); in input_register_device()
2462 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); in input_register_device()
2464 dev->name ? dev->name : "Unspecified device", in input_register_device()
2472 list_add_tail(&dev->node, &input_dev_list); in input_register_device()
2481 if (dev->devres_managed) { in input_register_device()
2482 dev_dbg(dev->dev.parent, "%s: registering %s with devres.\n", in input_register_device()
2483 __func__, dev_name(&dev->dev)); in input_register_device()
2484 devres_add(dev->dev.parent, devres); in input_register_device()
2489 device_del(&dev->dev); in input_register_device()
2497 * input_unregister_device - unregister previously registered device
2505 if (dev->devres_managed) { in input_unregister_device()
2506 WARN_ON(devres_destroy(dev->dev.parent, in input_unregister_device()
2526 if (handler->filter) in input_handler_check_methods()
2528 if (handler->events) in input_handler_check_methods()
2530 if (handler->event) in input_handler_check_methods()
2535 __func__, handler->name); in input_handler_check_methods()
2536 return -EINVAL; in input_handler_check_methods()
2543 * input_register_handler - register a new input handler
2559 INIT_LIST_HEAD(&handler->h_list); in input_register_handler()
2565 list_add_tail(&handler->node, &input_handler_list); in input_register_handler()
2578 * input_unregister_handler - unregisters an input handler
2590 list_for_each_entry_safe(handle, next, &handler->h_list, h_node) in input_unregister_handler()
2591 handler->disconnect(handle); in input_unregister_handler()
2592 WARN_ON(!list_empty(&handler->h_list)); in input_unregister_handler()
2594 list_del_init(&handler->node); in input_unregister_handler()
2603 * input_handler_for_each_handle - handle iterator
2609 * it @data and stop when @fn returns a non-zero value. The function is
2622 list_for_each_entry_rcu(handle, &handler->h_list, h_node) { in input_handler_for_each_handle()
2636 * invokes handler->event() method for each event one by one.
2642 struct input_handler *handler = handle->handler; in input_handle_events_default()
2646 handler->event(handle, v->type, v->code, v->value); in input_handle_events_default()
2653 * handler->filter() method for each event one by one and removes events
2660 struct input_handler *handler = handle->handler; in input_handle_events_filter()
2665 if (handler->filter(handle, v->type, v->code, v->value)) in input_handle_events_filter()
2672 return end - vals; in input_handle_events_filter()
2686 * Sets up appropriate handle->event_handler based on the input_handler
2691 struct input_handler *handler = handle->handler; in input_handle_setup_event_handler()
2693 if (handler->filter) in input_handle_setup_event_handler()
2694 handle->handle_events = input_handle_events_filter; in input_handle_setup_event_handler()
2695 else if (handler->event) in input_handle_setup_event_handler()
2696 handle->handle_events = input_handle_events_default; in input_handle_setup_event_handler()
2697 else if (handler->events) in input_handle_setup_event_handler()
2698 handle->handle_events = handler->events; in input_handle_setup_event_handler()
2700 handle->handle_events = input_handle_events_null; in input_handle_setup_event_handler()
2704 * input_register_handle - register a new input handle
2716 struct input_handler *handler = handle->handler; in input_register_handle()
2717 struct input_dev *dev = handle->dev; in input_register_handle()
2722 * We take dev->mutex here to prevent race with in input_register_handle()
2725 error = mutex_lock_interruptible(&dev->mutex); in input_register_handle()
2733 if (handler->filter) in input_register_handle()
2734 list_add_rcu(&handle->d_node, &dev->h_list); in input_register_handle()
2736 list_add_tail_rcu(&handle->d_node, &dev->h_list); in input_register_handle()
2738 mutex_unlock(&dev->mutex); in input_register_handle()
2741 * Since we are supposed to be called from ->connect() in input_register_handle()
2742 * which is mutually exclusive with ->disconnect() in input_register_handle()
2746 list_add_tail_rcu(&handle->h_node, &handler->h_list); in input_register_handle()
2748 if (handler->start) in input_register_handle()
2749 handler->start(handle); in input_register_handle()
2756 * input_unregister_handle - unregister an input handle
2767 struct input_dev *dev = handle->dev; in input_unregister_handle()
2769 list_del_rcu(&handle->h_node); in input_unregister_handle()
2772 * Take dev->mutex to prevent race with input_release_device(). in input_unregister_handle()
2774 mutex_lock(&dev->mutex); in input_unregister_handle()
2775 list_del_rcu(&handle->d_node); in input_unregister_handle()
2776 mutex_unlock(&dev->mutex); in input_unregister_handle()
2783 * input_get_new_minor - allocates a new input minor number
2797 * This function should be called from input handler's ->connect() in input_get_new_minor()
2803 legacy_base + legacy_num - 1, in input_get_new_minor()
2810 INPUT_MAX_CHAR_DEVICES - 1, GFP_KERNEL); in input_get_new_minor()
2815 * input_free_minor - release previously allocated minor