Lines Matching +full:abs +full:- +full:flat
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)
76 if (value > old_val - fuzz && value < old_val + fuzz)
79 if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2)
88 if (test_bit(EV_REP, dev->evbit) &&
89 dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] &&
90 dev->timer.function) {
91 dev->repeat_key = code;
92 mod_timer(&dev->timer,
93 jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]));
99 del_timer(&dev->timer);
108 * This function is called with dev->event_lock held and interrupts disabled.
116 lockdep_assert_held(&dev->event_lock);
120 handle = rcu_dereference(dev->grab);
122 count = handle->handle_events(handle, vals, count);
124 list_for_each_entry_rcu(handle, &dev->h_list, d_node)
125 if (handle->open) {
126 count = handle->handle_events(handle, vals,
136 if (test_bit(EV_REP, dev->evbit) && test_bit(EV_KEY, dev->evbit)) {
138 if (v->type == EV_KEY && v->value != 2) {
139 if (v->value)
140 input_start_autorepeat(dev, v->code);
158 struct input_mt *mt = dev->mt;
168 if (mt && *pval >= 0 && *pval < mt->num_slots)
169 mt->slot = *pval;
177 pold = &dev->absinfo[code].value;
179 pold = &mt->slots[mt->slot].abs[code - ABS_MT_FIRST];
180 is_new_slot = mt->slot != dev->absinfo[ABS_MT_SLOT].value;
183 * Bypass filtering for multi-touch events when
191 dev->absinfo[code].fuzz);
200 dev->absinfo[ABS_MT_SLOT].value = mt->slot;
213 /* filter-out events from inhibited devices */
214 if (dev->inhibited)
235 if (is_event_supported(code, dev->keybit, KEY_MAX)) {
237 /* auto-repeat bypasses state updates */
243 if (!!test_bit(code, dev->key) != !!value) {
245 __change_bit(code, dev->key);
252 if (is_event_supported(code, dev->swbit, SW_MAX) &&
253 !!test_bit(code, dev->sw) != !!value) {
255 __change_bit(code, dev->sw);
261 if (is_event_supported(code, dev->absbit, ABS_MAX))
267 if (is_event_supported(code, dev->relbit, REL_MAX) && value)
273 if (is_event_supported(code, dev->mscbit, MSC_MAX))
279 if (is_event_supported(code, dev->ledbit, LED_MAX) &&
280 !!test_bit(code, dev->led) != !!value) {
282 __change_bit(code, dev->led);
288 if (is_event_supported(code, dev->sndbit, SND_MAX)) {
290 if (!!test_bit(code, dev->snd) != !!value)
291 __change_bit(code, dev->snd);
297 if (code <= REP_MAX && value >= 0 && dev->rep[code] != value) {
298 dev->rep[code] = value;
320 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
321 dev->event(dev, type, code, value);
327 v = &dev->vals[dev->num_vals++];
328 v->type = EV_ABS;
329 v->code = ABS_MT_SLOT;
330 v->value = dev->mt->slot;
333 v = &dev->vals[dev->num_vals++];
334 v->type = type;
335 v->code = code;
336 v->value = value;
340 if (dev->num_vals >= 2)
341 input_pass_values(dev, dev->vals, dev->num_vals);
342 dev->num_vals = 0;
349 dev->timestamp[INPUT_CLK_MONO] = ktime_set(0, 0);
350 } else if (dev->num_vals >= dev->max_vals - 2) {
351 dev->vals[dev->num_vals++] = input_value_sync;
352 input_pass_values(dev, dev->vals, dev->num_vals);
353 dev->num_vals = 0;
362 lockdep_assert_held(&dev->event_lock);
374 * input_event() - report new input event
395 if (is_event_supported(type, dev->evbit, EV_MAX)) {
397 spin_lock_irqsave(&dev->event_lock, flags);
399 spin_unlock_irqrestore(&dev->event_lock, flags);
405 * input_inject_event() - send input event from input handler
418 struct input_dev *dev = handle->dev;
422 if (is_event_supported(type, dev->evbit, EV_MAX)) {
423 spin_lock_irqsave(&dev->event_lock, flags);
426 grab = rcu_dereference(dev->grab);
431 spin_unlock_irqrestore(&dev->event_lock, flags);
437 * input_alloc_absinfo - allocates array of input_absinfo structs
445 if (dev->absinfo)
448 dev->absinfo = kcalloc(ABS_CNT, sizeof(*dev->absinfo), GFP_KERNEL);
449 if (!dev->absinfo) {
450 dev_err(dev->dev.parent ?: &dev->dev,
455 * device with ABS bits but without absinfo.
462 int min, int max, int fuzz, int flat)
466 __set_bit(EV_ABS, dev->evbit);
467 __set_bit(axis, dev->absbit);
470 if (!dev->absinfo)
473 absinfo = &dev->absinfo[axis];
474 absinfo->minimum = min;
475 absinfo->maximum = max;
476 absinfo->fuzz = fuzz;
477 absinfo->flat = flat;
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
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) &&
499 test_bit(src_axis, src->absbit))))
507 if (!src->absinfo)
511 if (!dst->absinfo)
514 dst->absinfo[dst_axis] = src->absinfo[src_axis];
519 * input_grab_device - grabs device for exclusive use
528 struct input_dev *dev = handle->dev;
531 retval = mutex_lock_interruptible(&dev->mutex);
535 if (dev->grab) {
536 retval = -EBUSY;
540 rcu_assign_pointer(dev->grab, handle);
543 mutex_unlock(&dev->mutex);
550 struct input_dev *dev = handle->dev;
553 grabber = rcu_dereference_protected(dev->grab,
554 lockdep_is_held(&dev->mutex));
556 rcu_assign_pointer(dev->grab, NULL);
560 list_for_each_entry(handle, &dev->h_list, d_node)
561 if (handle->open && handle->handler->start)
562 handle->handler->start(handle);
567 * input_release_device - release previously grabbed device
577 struct input_dev *dev = handle->dev;
579 mutex_lock(&dev->mutex);
581 mutex_unlock(&dev->mutex);
586 * input_open_device - open input device
594 struct input_dev *dev = handle->dev;
597 retval = mutex_lock_interruptible(&dev->mutex);
601 if (dev->going_away) {
602 retval = -ENODEV;
606 handle->open++;
608 if (dev->users++ || dev->inhibited) {
616 if (dev->open) {
617 retval = dev->open(dev);
619 dev->users--;
620 handle->open--;
630 if (dev->poller)
631 input_dev_poller_start(dev->poller);
634 mutex_unlock(&dev->mutex);
641 struct input_dev *dev = handle->dev;
644 retval = mutex_lock_interruptible(&dev->mutex);
648 if (dev->flush)
649 retval = dev->flush(dev, file);
651 mutex_unlock(&dev->mutex);
657 * input_close_device - close input device
665 struct input_dev *dev = handle->dev;
667 mutex_lock(&dev->mutex);
671 if (!--dev->users && !dev->inhibited) {
672 if (dev->poller)
673 input_dev_poller_stop(dev->poller);
674 if (dev->close)
675 dev->close(dev);
678 if (!--handle->open) {
687 mutex_unlock(&dev->mutex);
693 * The function must be called with dev->event_lock held.
700 lockdep_assert_held(&dev->event_lock);
702 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
703 for_each_set_bit(code, dev->key, KEY_CNT) {
720 * Mark device as going away. Note that we take dev->mutex here
721 * not to protect access to dev->going_away but rather to ensure
724 mutex_lock(&dev->mutex);
725 dev->going_away = true;
726 mutex_unlock(&dev->mutex);
728 spin_lock_irq(&dev->event_lock);
739 list_for_each_entry(handle, &dev->h_list, d_node)
740 handle->open = 0;
742 spin_unlock_irq(&dev->event_lock);
746 * input_scancode_to_scalar() - converts scancode in &struct input_keymap_entry
758 switch (ke->len) {
760 *scancode = *((u8 *)ke->scancode);
764 *scancode = *((u16 *)ke->scancode);
768 *scancode = *((u32 *)ke->scancode);
772 return -EINVAL;
787 switch (dev->keycodesize) {
789 return ((u8 *)dev->keycode)[index];
792 return ((u16 *)dev->keycode)[index];
795 return ((u32 *)dev->keycode)[index];
805 if (!dev->keycodesize)
806 return -EINVAL;
808 if (ke->flags & INPUT_KEYMAP_BY_INDEX)
809 index = ke->index;
816 if (index >= dev->keycodemax)
817 return -EINVAL;
819 ke->keycode = input_fetch_keycode(dev, index);
820 ke->index = index;
821 ke->len = sizeof(index);
822 memcpy(ke->scancode, &index, sizeof(index));
835 if (!dev->keycodesize)
836 return -EINVAL;
838 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
839 index = ke->index;
846 if (index >= dev->keycodemax)
847 return -EINVAL;
849 if (dev->keycodesize < sizeof(ke->keycode) &&
850 (ke->keycode >> (dev->keycodesize * 8)))
851 return -EINVAL;
853 switch (dev->keycodesize) {
855 u8 *k = (u8 *)dev->keycode;
857 k[index] = ke->keycode;
861 u16 *k = (u16 *)dev->keycode;
863 k[index] = ke->keycode;
867 u32 *k = (u32 *)dev->keycode;
869 k[index] = ke->keycode;
875 __clear_bit(*old_keycode, dev->keybit);
876 for (i = 0; i < dev->keycodemax; i++) {
878 __set_bit(*old_keycode, dev->keybit);
885 __set_bit(ke->keycode, dev->keybit);
890 * input_get_keycode - retrieve keycode currently mapped to a given scancode
902 spin_lock_irqsave(&dev->event_lock, flags);
903 retval = dev->getkeycode(dev, ke);
904 spin_unlock_irqrestore(&dev->event_lock, flags);
911 * input_set_keycode - attribute a keycode to a given scancode
925 if (ke->keycode > KEY_MAX)
926 return -EINVAL;
928 spin_lock_irqsave(&dev->event_lock, flags);
930 retval = dev->setkeycode(dev, ke, &old_keycode);
935 __clear_bit(KEY_RESERVED, dev->keybit);
942 dev_warn(dev->dev.parent ?: &dev->dev,
945 } else if (test_bit(EV_KEY, dev->evbit) &&
946 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) &&
947 __test_and_clear_bit(old_keycode, dev->key)) {
961 spin_unlock_irqrestore(&dev->event_lock, flags);
970 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS)
971 if (id->bustype != dev->id.bustype)
974 if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR)
975 if (id->vendor != dev->id.vendor)
978 if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT)
979 if (id->product != dev->id.product)
982 if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION)
983 if (id->version != dev->id.version)
986 if (!bitmap_subset(id->evbit, dev->evbit, EV_MAX) ||
987 !bitmap_subset(id->keybit, dev->keybit, KEY_MAX) ||
988 !bitmap_subset(id->relbit, dev->relbit, REL_MAX) ||
989 !bitmap_subset(id->absbit, dev->absbit, ABS_MAX) ||
990 !bitmap_subset(id->mscbit, dev->mscbit, MSC_MAX) ||
991 !bitmap_subset(id->ledbit, dev->ledbit, LED_MAX) ||
992 !bitmap_subset(id->sndbit, dev->sndbit, SND_MAX) ||
993 !bitmap_subset(id->ffbit, dev->ffbit, FF_MAX) ||
994 !bitmap_subset(id->swbit, dev->swbit, SW_MAX) ||
995 !bitmap_subset(id->propbit, dev->propbit, INPUT_PROP_MAX)) {
1008 for (id = handler->id_table; id->flags || id->driver_info; id++) {
1010 (!handler->match || handler->match(handler, dev))) {
1025 return -ENODEV;
1027 error = handler->connect(handler, dev, id);
1028 if (error && error != -ENODEV)
1030 handler->name, kobject_name(&dev->dev.kobj), error);
1049 len += snprintf(buf + len, max(buf_size - len, 0),
1090 struct seq_file *seq = file->private_data;
1091 struct input_seq_state *state = seq->private;
1094 if (state->input_devices_state != input_devices_state) {
1095 state->input_devices_state = input_devices_state;
1104 struct input_seq_state *state = seq->private;
1109 state->mutex_acquired = false;
1113 state->mutex_acquired = true;
1125 struct input_seq_state *state = seq->private;
1127 if (state->mutex_acquired)
1140 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) {
1160 const char *path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
1164 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
1166 seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
1167 seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : "");
1169 seq_printf(seq, "U: Uniq=%s\n", dev->uniq ? dev->uniq : "");
1172 list_for_each_entry(handle, &dev->h_list, d_node)
1173 seq_printf(seq, "%s ", handle->name);
1176 input_seq_print_bitmap(seq, "PROP", dev->propbit, INPUT_PROP_MAX);
1178 input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX);
1179 if (test_bit(EV_KEY, dev->evbit))
1180 input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX);
1181 if (test_bit(EV_REL, dev->evbit))
1182 input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX);
1183 if (test_bit(EV_ABS, dev->evbit))
1184 input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX);
1185 if (test_bit(EV_MSC, dev->evbit))
1186 input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX);
1187 if (test_bit(EV_LED, dev->evbit))
1188 input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX);
1189 if (test_bit(EV_SND, dev->evbit))
1190 input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX);
1191 if (test_bit(EV_FF, dev->evbit))
1192 input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX);
1193 if (test_bit(EV_SW, dev->evbit))
1194 input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX);
1225 struct input_seq_state *state = seq->private;
1230 state->mutex_acquired = false;
1234 state->mutex_acquired = true;
1235 state->pos = *pos;
1242 struct input_seq_state *state = seq->private;
1244 state->pos = *pos + 1;
1251 struct input_seq_state *state = seq->private;
1253 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name);
1254 if (handler->filter)
1256 if (handler->legacy_minors)
1257 seq_printf(seq, " Minor=%d", handler->minor);
1289 return -ENOMEM;
1305 return -ENOMEM;
1329 input_dev->name ? input_dev->name : ""); \
1346 len += snprintf(buf + len, max(size - len, 0), "%X,", bit);
1356 "input:b%04Xv%04Xp%04Xe%04X-",
1357 id->id.bustype, id->id.vendor,
1358 id->id.product, id->id.version);
1360 len += input_print_modalias_bits(buf + len, size - len,
1361 'e', id->evbit, 0, EV_MAX);
1367 space = max(size - (len + 1), 0);
1369 klen = input_print_modalias_bits(buf + len, size - len,
1370 'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX);
1383 remainder = full_len - len;
1388 if (remainder <= space - 3) {
1394 for (int i = size - 1 - remainder - 3; i >= 0; i--) {
1404 len += input_print_modalias_bits(buf + len, size - len,
1405 'r', id->relbit, 0, REL_MAX);
1406 len += input_print_modalias_bits(buf + len, size - len,
1407 'a', id->absbit, 0, ABS_MAX);
1408 len += input_print_modalias_bits(buf + len, size - len,
1409 'm', id->mscbit, 0, MSC_MAX);
1410 len += input_print_modalias_bits(buf + len, size - len,
1411 'l', id->ledbit, 0, LED_MAX);
1412 len += input_print_modalias_bits(buf + len, size - len,
1413 's', id->sndbit, 0, SND_MAX);
1414 len += input_print_modalias_bits(buf + len, size - len,
1415 'f', id->ffbit, 0, FF_MAX);
1416 len += input_print_modalias_bits(buf + len, size - len,
1417 'w', id->swbit, 0, SW_MAX);
1446 if (len < PAGE_SIZE - 2)
1447 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1461 int len = input_print_bitmap(buf, PAGE_SIZE, input_dev->propbit,
1476 return sysfs_emit(buf, "%d\n", input_dev->inhibited);
1488 return -EINVAL;
1523 return sysfs_emit(buf, "%04x\n", input_dev->id.name); \
1552 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) {
1553 len += input_bits_to_string(buf + len, max(buf_size - len, 0),
1558 len += snprintf(buf + len, max(buf_size - len, 0), " ");
1569 len += snprintf(buf + len, max(buf_size - len, 0), "\n");
1581 input_dev->bm##bit, ev##_MAX, \
1590 INPUT_DEV_CAP_ATTR(ABS, abs);
1629 kfree(dev->poller);
1630 kfree(dev->absinfo);
1631 kfree(dev->vals);
1638 * Input uevent interface - loading event handlers based on
1647 return -ENOMEM;
1649 len = input_print_bitmap(&env->buf[env->buflen - 1],
1650 sizeof(env->buf) - env->buflen,
1652 if (len >= (sizeof(env->buf) - env->buflen))
1653 return -ENOMEM;
1655 env->buflen += len;
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;
1684 len = input_print_modalias(&env->buf[env->buflen - 1],
1685 (int)sizeof(env->buf) - env->buflen -
1688 if (len >= ((int)sizeof(env->buf) - env->buflen -
1690 return -ENOMEM;
1692 env->buflen += len;
1722 dev->id.bustype, dev->id.vendor,
1723 dev->id.product, dev->id.version);
1724 if (dev->name)
1725 INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name);
1726 if (dev->phys)
1727 INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys);
1728 if (dev->uniq)
1729 INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq);
1731 INPUT_ADD_HOTPLUG_BM_VAR("PROP=", dev->propbit, INPUT_PROP_MAX);
1733 INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX);
1734 if (test_bit(EV_KEY, dev->evbit))
1735 INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX);
1736 if (test_bit(EV_REL, dev->evbit))
1737 INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX);
1738 if (test_bit(EV_ABS, dev->evbit))
1739 INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX);
1740 if (test_bit(EV_MSC, dev->evbit))
1741 INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX);
1742 if (test_bit(EV_LED, dev->evbit))
1743 INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX);
1744 if (test_bit(EV_SND, dev->evbit))
1745 INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX);
1746 if (test_bit(EV_FF, dev->evbit))
1747 INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX);
1748 if (test_bit(EV_SW, dev->evbit))
1749 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX);
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)
1781 if (activate && test_bit(EV_REP, dev->evbit)) {
1782 dev->event(dev, EV_REP, REP_PERIOD, dev->rep[REP_PERIOD]);
1783 dev->event(dev, EV_REP, REP_DELAY, dev->rep[REP_DELAY]);
1788 * input_reset_device() - reset/restore the state of input device
1799 mutex_lock(&dev->mutex);
1800 spin_lock_irqsave(&dev->event_lock, flags);
1806 spin_unlock_irqrestore(&dev->event_lock, flags);
1807 mutex_unlock(&dev->mutex);
1813 mutex_lock(&dev->mutex);
1815 if (dev->inhibited)
1818 if (dev->users) {
1819 if (dev->close)
1820 dev->close(dev);
1821 if (dev->poller)
1822 input_dev_poller_stop(dev->poller);
1825 spin_lock_irq(&dev->event_lock);
1830 spin_unlock_irq(&dev->event_lock);
1832 dev->inhibited = true;
1835 mutex_unlock(&dev->mutex);
1843 mutex_lock(&dev->mutex);
1845 if (!dev->inhibited)
1848 if (dev->users) {
1849 if (dev->open) {
1850 ret = dev->open(dev);
1854 if (dev->poller)
1855 input_dev_poller_start(dev->poller);
1858 dev->inhibited = false;
1859 spin_lock_irq(&dev->event_lock);
1861 spin_unlock_irq(&dev->event_lock);
1864 mutex_unlock(&dev->mutex);
1872 spin_lock_irq(&input_dev->event_lock);
1884 spin_unlock_irq(&input_dev->event_lock);
1893 spin_lock_irq(&input_dev->event_lock);
1898 spin_unlock_irq(&input_dev->event_lock);
1907 spin_lock_irq(&input_dev->event_lock);
1916 spin_unlock_irq(&input_dev->event_lock);
1925 spin_lock_irq(&input_dev->event_lock);
1930 spin_unlock_irq(&input_dev->event_lock);
1962 * input_allocate_device - allocate memory for new input device
1972 static atomic_t input_no = ATOMIC_INIT(-1);
1984 dev->max_vals = 10;
1985 dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL);
1986 if (!dev->vals) {
1991 mutex_init(&dev->mutex);
1992 spin_lock_init(&dev->event_lock);
1993 timer_setup(&dev->timer, NULL, 0);
1994 INIT_LIST_HEAD(&dev->h_list);
1995 INIT_LIST_HEAD(&dev->node);
1997 dev->dev.type = &input_dev_type;
1998 dev->dev.class = &input_class;
1999 device_initialize(&dev->dev);
2006 dev_set_name(&dev->dev, "input%lu",
2023 return devres->input == data;
2029 struct input_dev *input = devres->input;
2032 __func__, dev_name(&input->dev));
2037 * devm_input_allocate_device - allocate managed input device
2070 input->dev.parent = dev;
2071 input->devres_managed = true;
2073 devres->input = input;
2081 * input_free_device - free memory occupied by input_dev structure
2097 if (dev->devres_managed)
2098 WARN_ON(devres_destroy(dev->dev.parent,
2108 * input_set_timestamp - set timestamp for input events
2123 dev->timestamp[INPUT_CLK_MONO] = timestamp;
2124 dev->timestamp[INPUT_CLK_REAL] = ktime_mono_to_real(timestamp);
2125 dev->timestamp[INPUT_CLK_BOOT] = ktime_mono_to_any(timestamp,
2131 * input_get_timestamp - get timestamp for input events
2134 * A valid timestamp is a timestamp of non-zero value.
2140 if (!ktime_compare(dev->timestamp[INPUT_CLK_MONO], invalid_timestamp))
2143 return dev->timestamp;
2148 * input_set_capability - mark device as capable of a certain event
2154 * bitmap the function also adjusts dev->evbit.
2168 __set_bit(code, dev->keybit);
2172 __set_bit(code, dev->relbit);
2177 __set_bit(code, dev->absbit);
2181 __set_bit(code, dev->mscbit);
2185 __set_bit(code, dev->swbit);
2189 __set_bit(code, dev->ledbit);
2193 __set_bit(code, dev->sndbit);
2197 __set_bit(code, dev->ffbit);
2210 __set_bit(type, dev->evbit);
2220 if (dev->mt) {
2221 mt_slots = dev->mt->num_slots;
2222 } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) {
2223 mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum -
2224 dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1;
2226 } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
2234 if (test_bit(EV_ABS, dev->evbit))
2235 for_each_set_bit(i, dev->absbit, ABS_CNT)
2238 if (test_bit(EV_REL, dev->evbit))
2239 events += bitmap_weight(dev->relbit, REL_CNT);
2249 if (!test_bit(EV_##type, dev->evbit)) \
2250 memset(dev->bits##bit, 0, \
2251 sizeof(dev->bits##bit)); \
2258 INPUT_CLEANSE_BITMASK(dev, ABS, abs);
2274 list_for_each_entry_safe(handle, next, &dev->h_list, d_node)
2275 handle->handler->disconnect(handle);
2276 WARN_ON(!list_empty(&dev->h_list));
2278 del_timer_sync(&dev->timer);
2279 list_del_init(&dev->node);
2285 device_del(&dev->dev);
2291 struct input_dev *input = devres->input;
2294 __func__, dev_name(&input->dev));
2300 * dev->event_lock here to avoid racing with input_event
2308 spin_lock_irqsave(&dev->event_lock, flags);
2310 if (!dev->inhibited &&
2311 test_bit(dev->repeat_key, dev->key) &&
2312 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {
2315 input_handle_event(dev, EV_KEY, dev->repeat_key, 2);
2318 if (dev->rep[REP_PERIOD])
2319 mod_timer(&dev->timer, jiffies +
2320 msecs_to_jiffies(dev->rep[REP_PERIOD]));
2323 spin_unlock_irqrestore(&dev->event_lock, flags);
2327 * input_enable_softrepeat - enable software autorepeat
2336 dev->timer.function = input_repeat_key;
2337 dev->rep[REP_DELAY] = delay;
2338 dev->rep[REP_PERIOD] = period;
2344 lockdep_assert_held(&dev->mutex);
2346 return !dev->inhibited && dev->users > 0;
2357 if (dev->hint_events_per_packet < packet_size)
2358 dev->hint_events_per_packet = packet_size;
2360 max_vals = dev->hint_events_per_packet + 2;
2361 if (dev->max_vals >= max_vals)
2366 return -ENOMEM;
2368 spin_lock_irq(&dev->event_lock);
2369 dev->max_vals = max_vals;
2370 swap(dev->vals, vals);
2371 spin_unlock_irq(&dev->event_lock);
2380 * input_register_device - register device with input core
2395 * that tear down of managed input devices is internally a 2-step process:
2409 if (test_bit(EV_ABS, dev->evbit) && !dev->absinfo) {
2410 dev_err(&dev->dev,
2411 "Absolute device without dev->absinfo, refusing to register\n");
2412 return -EINVAL;
2415 if (dev->devres_managed) {
2419 return -ENOMEM;
2421 devres->input = dev;
2425 __set_bit(EV_SYN, dev->evbit);
2428 __clear_bit(KEY_RESERVED, dev->keybit);
2430 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */
2438 * If delay and period are pre-set by the driver, then autorepeating
2441 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD])
2444 if (!dev->getkeycode)
2445 dev->getkeycode = input_default_getkeycode;
2447 if (!dev->setkeycode)
2448 dev->setkeycode = input_default_setkeycode;
2450 if (dev->poller)
2451 input_dev_poller_finalize(dev->poller);
2453 error = device_add(&dev->dev);
2457 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
2459 dev->name ? dev->name : "Unspecified device",
2467 list_add_tail(&dev->node, &input_dev_list);
2476 if (dev->devres_managed) {
2477 dev_dbg(dev->dev.parent, "%s: registering %s with devres.\n",
2478 __func__, dev_name(&dev->dev));
2479 devres_add(dev->dev.parent, devres);
2484 device_del(&dev->dev);
2492 * input_unregister_device - unregister previously registered device
2500 if (dev->devres_managed) {
2501 WARN_ON(devres_destroy(dev->dev.parent,
2521 if (handler->filter)
2523 if (handler->events)
2525 if (handler->event)
2530 __func__, handler->name);
2531 return -EINVAL;
2538 * input_register_handler - register a new input handler
2554 INIT_LIST_HEAD(&handler->h_list);
2560 list_add_tail(&handler->node, &input_handler_list);
2573 * input_unregister_handler - unregisters an input handler
2585 list_for_each_entry_safe(handle, next, &handler->h_list, h_node)
2586 handler->disconnect(handle);
2587 WARN_ON(!list_empty(&handler->h_list));
2589 list_del_init(&handler->node);
2598 * input_handler_for_each_handle - handle iterator
2604 * it @data and stop when @fn returns a non-zero value. The function is
2617 list_for_each_entry_rcu(handle, &handler->h_list, h_node) {
2631 * invokes handler->event() method for each event one by one.
2637 struct input_handler *handler = handle->handler;
2641 handler->event(handle, v->type, v->code, v->value);
2648 * handler->filter() method for each event one by one and removes events
2655 struct input_handler *handler = handle->handler;
2660 if (handler->filter(handle, v->type, v->code, v->value))
2667 return end - vals;
2681 * Sets up appropriate handle->event_handler based on the input_handler
2686 struct input_handler *handler = handle->handler;
2688 if (handler->filter)
2689 handle->handle_events = input_handle_events_filter;
2690 else if (handler->event)
2691 handle->handle_events = input_handle_events_default;
2692 else if (handler->events)
2693 handle->handle_events = handler->events;
2695 handle->handle_events = input_handle_events_null;
2699 * input_register_handle - register a new input handle
2711 struct input_handler *handler = handle->handler;
2712 struct input_dev *dev = handle->dev;
2717 * We take dev->mutex here to prevent race with
2720 error = mutex_lock_interruptible(&dev->mutex);
2728 if (handler->filter)
2729 list_add_rcu(&handle->d_node, &dev->h_list);
2731 list_add_tail_rcu(&handle->d_node, &dev->h_list);
2733 mutex_unlock(&dev->mutex);
2736 * Since we are supposed to be called from ->connect()
2737 * which is mutually exclusive with ->disconnect()
2741 list_add_tail_rcu(&handle->h_node, &handler->h_list);
2743 if (handler->start)
2744 handler->start(handle);
2751 * input_unregister_handle - unregister an input handle
2762 struct input_dev *dev = handle->dev;
2764 list_del_rcu(&handle->h_node);
2767 * Take dev->mutex to prevent race with input_release_device().
2769 mutex_lock(&dev->mutex);
2770 list_del_rcu(&handle->d_node);
2771 mutex_unlock(&dev->mutex);
2778 * input_get_new_minor - allocates a new input minor number
2792 * This function should be called from input handler's ->connect()
2798 legacy_base + legacy_num - 1,
2805 INPUT_MAX_CHAR_DEVICES - 1, GFP_KERNEL);
2810 * input_free_minor - release previously allocated minor