2 * Copyright (c) 2014 Jakub Wojciech Klama <jceel@FreeBSD.org>
3 * Copyright (c) 2015-2016 Vladimir Kondratyev <wulf@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include "opt_evdev.h"
32 #include <sys/param.h>
33 #include <sys/bitstring.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/module.h>
40 #include <sys/sysctl.h>
41 #include <sys/systm.h>
43 #include <dev/evdev/evdev.h>
44 #include <dev/evdev/evdev_private.h>
45 #include <dev/evdev/input.h>
48 #define debugf(evdev, fmt, args...) printf("evdev: " fmt "\n", ##args)
50 #define debugf(evdev, fmt, args...)
54 FEATURE(evdev, "Input event devices support");
56 FEATURE(evdev_support, "Evdev support in hybrid drivers");
60 enum evdev_sparse_result
62 EV_SKIP_EVENT, /* Event value not changed */
63 EV_REPORT_EVENT, /* Event value changed */
64 EV_REPORT_MT_SLOT, /* Event value and MT slot number changed */
67 MALLOC_DEFINE(M_EVDEV, "evdev", "evdev memory");
69 int evdev_rcpt_mask = EVDEV_RCPT_SYSMOUSE | EVDEV_RCPT_KBDMUX;
70 int evdev_sysmouse_t_axis = 0;
73 SYSCTL_NODE(_kern, OID_AUTO, evdev, CTLFLAG_RW, 0, "Evdev args");
74 SYSCTL_INT(_kern_evdev, OID_AUTO, rcpt_mask, CTLFLAG_RW, &evdev_rcpt_mask, 0,
75 "Who is receiving events: bit0 - sysmouse, bit1 - kbdmux, "
76 "bit2 - mouse hardware, bit3 - keyboard hardware");
77 SYSCTL_INT(_kern_evdev, OID_AUTO, sysmouse_t_axis, CTLFLAG_RW,
78 &evdev_sysmouse_t_axis, 0, "Extract T-axis from 0-none, 1-ums, 2-psm");
81 static void evdev_start_repeat(struct evdev_dev *, uint16_t);
82 static void evdev_stop_repeat(struct evdev_dev *);
83 static int evdev_check_event(struct evdev_dev *, uint16_t, uint16_t, int32_t);
86 bit_change(bitstr_t *bitstr, int bit, int value)
91 bit_clear(bitstr, bit);
98 return malloc(sizeof(struct evdev_dev), M_EVDEV, M_WAITOK | M_ZERO);
102 evdev_free(struct evdev_dev *evdev)
105 if (evdev != NULL && evdev->ev_cdev != NULL &&
106 evdev->ev_cdev->si_drv1 != NULL)
107 evdev_unregister(evdev);
109 free(evdev, M_EVDEV);
112 static struct input_absinfo *
113 evdev_alloc_absinfo(void)
116 return (malloc(sizeof(struct input_absinfo) * ABS_CNT, M_EVDEV,
121 evdev_free_absinfo(struct input_absinfo *absinfo)
124 free(absinfo, M_EVDEV);
128 evdev_set_report_size(struct evdev_dev *evdev, size_t report_size)
130 if (report_size > KEY_CNT + REL_CNT + ABS_CNT + MAX_MT_SLOTS * MT_CNT +
131 MSC_CNT + LED_CNT + SND_CNT + SW_CNT + FF_CNT)
134 evdev->ev_report_size = report_size;
139 evdev_estimate_report_size(struct evdev_dev *evdev)
145 * Keyboards generate one event per report but other devices with
146 * buttons like mouses can report events simultaneously
148 bit_ffs_at(evdev->ev_key_flags, KEY_OK, KEY_CNT - KEY_OK, &res);
150 bit_ffs(evdev->ev_key_flags, BTN_MISC, &res);
152 bit_count(evdev->ev_key_flags, BTN_MISC, KEY_OK - BTN_MISC, &res);
155 /* All relative axes can be reported simultaneously */
156 bit_count(evdev->ev_rel_flags, 0, REL_CNT, &res);
160 * All absolute axes can be reported simultaneously.
161 * Multitouch axes can be reported ABS_MT_SLOT times
163 if (evdev->ev_absinfo != NULL) {
164 bit_count(evdev->ev_abs_flags, 0, ABS_CNT, &res);
166 bit_count(evdev->ev_abs_flags, ABS_MT_FIRST, MT_CNT, &res);
168 res++; /* ABS_MT_SLOT or SYN_MT_REPORT */
169 if (bit_test(evdev->ev_abs_flags, ABS_MT_SLOT))
171 size += res * MAXIMAL_MT_SLOT(evdev);
174 size += res * (MAX_MT_REPORTS - 1);
178 /* All misc events can be reported simultaneously */
179 bit_count(evdev->ev_msc_flags, 0, MSC_CNT, &res);
182 /* All leds can be reported simultaneously */
183 bit_count(evdev->ev_led_flags, 0, LED_CNT, &res);
186 /* Assume other events are generated once per report */
187 bit_ffs(evdev->ev_snd_flags, SND_CNT, &res);
190 bit_ffs(evdev->ev_sw_flags, SW_CNT, &res);
193 /* XXX: FF part is not implemented yet */
195 size++; /* SYN_REPORT */
200 evdev_register_common(struct evdev_dev *evdev)
204 debugf(evdev, "%s: registered evdev provider: %s <%s>\n",
205 evdev->ev_shortname, evdev->ev_name, evdev->ev_serial);
207 /* Initialize internal structures */
208 LIST_INIT(&evdev->ev_clients);
210 if (evdev_event_supported(evdev, EV_REP) &&
211 bit_test(evdev->ev_flags, EVDEV_FLAG_SOFTREPEAT)) {
212 /* Initialize callout */
213 callout_init_mtx(&evdev->ev_rep_callout, &evdev->ev_mtx, 0);
215 if (evdev->ev_rep[REP_DELAY] == 0 &&
216 evdev->ev_rep[REP_PERIOD] == 0) {
217 /* Supply default values */
218 evdev->ev_rep[REP_DELAY] = 250;
219 evdev->ev_rep[REP_PERIOD] = 33;
223 /* Initialize multitouch protocol type B states */
224 if (bit_test(evdev->ev_abs_flags, ABS_MT_SLOT) &&
225 evdev->ev_absinfo != NULL && MAXIMAL_MT_SLOT(evdev) > 0)
226 evdev_mt_init(evdev);
228 /* Estimate maximum report size */
229 if (evdev->ev_report_size == 0) {
230 ret = evdev_set_report_size(evdev,
231 evdev_estimate_report_size(evdev));
236 /* Create char device node */
237 ret = evdev_cdev_create(evdev);
243 evdev_register(struct evdev_dev *evdev)
247 evdev->ev_lock_type = EV_LOCK_INTERNAL;
248 evdev->ev_lock = &evdev->ev_mtx;
249 mtx_init(&evdev->ev_mtx, "evmtx", NULL, MTX_DEF);
251 ret = evdev_register_common(evdev);
253 mtx_destroy(&evdev->ev_mtx);
259 evdev_register_mtx(struct evdev_dev *evdev, struct mtx *mtx)
262 evdev->ev_lock_type = EV_LOCK_MTX;
263 evdev->ev_lock = mtx;
264 return (evdev_register_common(evdev));
268 evdev_unregister(struct evdev_dev *evdev)
270 struct evdev_client *client;
272 debugf(evdev, "%s: unregistered evdev provider: %s\n",
273 evdev->ev_shortname, evdev->ev_name);
276 evdev->ev_cdev->si_drv1 = NULL;
277 /* Wake up sleepers */
278 LIST_FOREACH(client, &evdev->ev_clients, ec_link) {
279 evdev_revoke_client(client);
280 evdev_dispose_client(evdev, client);
281 EVDEV_CLIENT_LOCKQ(client);
282 evdev_notify_event(client);
283 EVDEV_CLIENT_UNLOCKQ(client);
287 /* destroy_dev can sleep so release lock */
288 ret = evdev_cdev_destroy(evdev);
289 evdev->ev_cdev = NULL;
290 if (ret == 0 && evdev->ev_lock_type == EV_LOCK_INTERNAL)
291 mtx_destroy(&evdev->ev_mtx);
293 evdev_free_absinfo(evdev->ev_absinfo);
294 evdev_mt_free(evdev);
300 evdev_set_name(struct evdev_dev *evdev, const char *name)
303 snprintf(evdev->ev_name, NAMELEN, "%s", name);
307 evdev_set_id(struct evdev_dev *evdev, uint16_t bustype, uint16_t vendor,
308 uint16_t product, uint16_t version)
311 evdev->ev_id = (struct input_id) {
320 evdev_set_phys(struct evdev_dev *evdev, const char *name)
323 snprintf(evdev->ev_shortname, NAMELEN, "%s", name);
327 evdev_set_serial(struct evdev_dev *evdev, const char *serial)
330 snprintf(evdev->ev_serial, NAMELEN, "%s", serial);
334 evdev_set_methods(struct evdev_dev *evdev, void *softc,
335 const struct evdev_methods *methods)
338 evdev->ev_methods = methods;
339 evdev->ev_softc = softc;
343 evdev_get_softc(struct evdev_dev *evdev)
346 return (evdev->ev_softc);
350 evdev_support_prop(struct evdev_dev *evdev, uint16_t prop)
353 KASSERT(prop < INPUT_PROP_CNT, ("invalid evdev input property"));
354 bit_set(evdev->ev_prop_flags, prop);
358 evdev_support_event(struct evdev_dev *evdev, uint16_t type)
361 KASSERT(type < EV_CNT, ("invalid evdev event property"));
362 bit_set(evdev->ev_type_flags, type);
366 evdev_support_key(struct evdev_dev *evdev, uint16_t code)
369 KASSERT(code < KEY_CNT, ("invalid evdev key property"));
370 bit_set(evdev->ev_key_flags, code);
374 evdev_support_rel(struct evdev_dev *evdev, uint16_t code)
377 KASSERT(code < REL_CNT, ("invalid evdev rel property"));
378 bit_set(evdev->ev_rel_flags, code);
382 evdev_support_abs(struct evdev_dev *evdev, uint16_t code, int32_t value,
383 int32_t minimum, int32_t maximum, int32_t fuzz, int32_t flat,
386 struct input_absinfo absinfo;
388 KASSERT(code < ABS_CNT, ("invalid evdev abs property"));
390 absinfo = (struct input_absinfo) {
396 .resolution = resolution,
398 evdev_set_abs_bit(evdev, code);
399 evdev_set_absinfo(evdev, code, &absinfo);
403 evdev_set_abs_bit(struct evdev_dev *evdev, uint16_t code)
406 KASSERT(code < ABS_CNT, ("invalid evdev abs property"));
407 if (evdev->ev_absinfo == NULL)
408 evdev->ev_absinfo = evdev_alloc_absinfo();
409 bit_set(evdev->ev_abs_flags, code);
413 evdev_support_msc(struct evdev_dev *evdev, uint16_t code)
416 KASSERT(code < MSC_CNT, ("invalid evdev msc property"));
417 bit_set(evdev->ev_msc_flags, code);
422 evdev_support_led(struct evdev_dev *evdev, uint16_t code)
425 KASSERT(code < LED_CNT, ("invalid evdev led property"));
426 bit_set(evdev->ev_led_flags, code);
430 evdev_support_snd(struct evdev_dev *evdev, uint16_t code)
433 KASSERT(code < SND_CNT, ("invalid evdev snd property"));
434 bit_set(evdev->ev_snd_flags, code);
438 evdev_support_sw(struct evdev_dev *evdev, uint16_t code)
441 KASSERT(code < SW_CNT, ("invalid evdev sw property"));
442 bit_set(evdev->ev_sw_flags, code);
446 evdev_event_supported(struct evdev_dev *evdev, uint16_t type)
449 KASSERT(type < EV_CNT, ("invalid evdev event property"));
450 return (bit_test(evdev->ev_type_flags, type));
454 evdev_set_absinfo(struct evdev_dev *evdev, uint16_t axis,
455 struct input_absinfo *absinfo)
458 KASSERT(axis < ABS_CNT, ("invalid evdev abs property"));
460 if (axis == ABS_MT_SLOT &&
461 (absinfo->maximum < 1 || absinfo->maximum >= MAX_MT_SLOTS))
464 if (evdev->ev_absinfo == NULL)
465 evdev->ev_absinfo = evdev_alloc_absinfo();
467 if (axis == ABS_MT_SLOT)
468 evdev->ev_absinfo[ABS_MT_SLOT].maximum = absinfo->maximum;
470 memcpy(&evdev->ev_absinfo[axis], absinfo,
471 sizeof(struct input_absinfo));
475 evdev_set_repeat_params(struct evdev_dev *evdev, uint16_t property, int value)
478 KASSERT(property < REP_CNT, ("invalid evdev repeat property"));
479 evdev->ev_rep[property] = value;
483 evdev_set_flag(struct evdev_dev *evdev, uint16_t flag)
486 KASSERT(flag < EVDEV_FLAG_CNT, ("invalid evdev flag property"));
487 bit_set(evdev->ev_flags, flag);
491 evdev_check_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
498 /* Allow SYN events implicitly */
499 if (type != EV_SYN && !evdev_event_supported(evdev, type))
511 if (!bit_test(evdev->ev_key_flags, code))
518 if (!bit_test(evdev->ev_rel_flags, code))
525 if (!bit_test(evdev->ev_abs_flags, code))
527 if (code == ABS_MT_SLOT &&
528 (value < 0 || value > MAXIMAL_MT_SLOT(evdev)))
530 if (ABS_IS_MT(code) && evdev->ev_mt == NULL &&
531 bit_test(evdev->ev_abs_flags, ABS_MT_SLOT))
538 if (!bit_test(evdev->ev_msc_flags, code))
545 if (!bit_test(evdev->ev_led_flags, code))
552 if (!bit_test(evdev->ev_snd_flags, code))
559 if (!bit_test(evdev->ev_sw_flags, code))
576 evdev_modify_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
580 EVDEV_LOCK_ASSERT(evdev);
584 if (!evdev_event_supported(evdev, EV_REP))
587 if (!bit_test(evdev->ev_flags, EVDEV_FLAG_SOFTREPEAT)) {
588 /* Detect driver key repeats. */
589 if (bit_test(evdev->ev_key_states, code) &&
590 *value == KEY_EVENT_DOWN)
591 *value = KEY_EVENT_REPEAT;
593 /* Start/stop callout for evdev repeats */
594 if (bit_test(evdev->ev_key_states, code) == !*value &&
595 !LIST_EMPTY(&evdev->ev_clients)) {
596 if (*value == KEY_EVENT_DOWN)
597 evdev_start_repeat(evdev, code);
599 evdev_stop_repeat(evdev);
605 /* TBD: implement fuzz */
610 static enum evdev_sparse_result
611 evdev_sparse_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
614 int32_t last_mt_slot;
616 EVDEV_LOCK_ASSERT(evdev);
619 * For certain event types, update device state bits
620 * and convert level reporting to edge reporting
627 if (bit_test(evdev->ev_key_states, code) == value)
628 return (EV_SKIP_EVENT);
629 bit_change(evdev->ev_key_states, code, value);
632 case KEY_EVENT_REPEAT:
633 if (bit_test(evdev->ev_key_states, code) == 0 ||
634 !evdev_event_supported(evdev, EV_REP))
635 return (EV_SKIP_EVENT);
639 return (EV_SKIP_EVENT);
644 if (bit_test(evdev->ev_led_states, code) == value)
645 return (EV_SKIP_EVENT);
646 bit_change(evdev->ev_led_states, code, value);
650 bit_change(evdev->ev_snd_states, code, value);
654 if (bit_test(evdev->ev_sw_states, code) == value)
655 return (EV_SKIP_EVENT);
656 bit_change(evdev->ev_sw_states, code, value);
660 if (evdev->ev_rep[code] == value)
661 return (EV_SKIP_EVENT);
662 evdev_set_repeat_params(evdev, code, value);
667 return (EV_SKIP_EVENT);
670 /* For EV_ABS, save last value in absinfo and ev_mt_states */
674 /* Postpone ABS_MT_SLOT till next event */
675 evdev_set_last_mt_slot(evdev, value);
676 return (EV_SKIP_EVENT);
678 case ABS_MT_FIRST ... ABS_MT_LAST:
679 /* Pass MT protocol type A events as is */
680 if (!bit_test(evdev->ev_abs_flags, ABS_MT_SLOT))
682 /* Don`t repeat MT protocol type B events */
683 last_mt_slot = evdev_get_last_mt_slot(evdev);
684 if (evdev_get_mt_value(evdev, last_mt_slot, code)
686 return (EV_SKIP_EVENT);
687 evdev_set_mt_value(evdev, last_mt_slot, code, value);
688 if (last_mt_slot != CURRENT_MT_SLOT(evdev)) {
689 CURRENT_MT_SLOT(evdev) = last_mt_slot;
690 evdev->ev_report_opened = true;
691 return (EV_REPORT_MT_SLOT);
696 if (evdev->ev_absinfo[code].value == value)
697 return (EV_SKIP_EVENT);
698 evdev->ev_absinfo[code].value = value;
703 if (code == SYN_REPORT) {
704 /* Count empty reports as well as non empty */
705 evdev->ev_report_count++;
706 /* Skip empty reports */
707 if (!evdev->ev_report_opened)
708 return (EV_SKIP_EVENT);
709 evdev->ev_report_opened = false;
710 return (EV_REPORT_EVENT);
715 evdev->ev_report_opened = true;
716 return (EV_REPORT_EVENT);
720 evdev_propagate_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
723 struct evdev_client *client;
725 debugf(evdev, "%s pushed event %d/%d/%d",
726 evdev->ev_shortname, type, code, value);
728 EVDEV_LOCK_ASSERT(evdev);
730 /* Propagate event through all clients */
731 LIST_FOREACH(client, &evdev->ev_clients, ec_link) {
732 if (evdev->ev_grabber != NULL && evdev->ev_grabber != client)
735 EVDEV_CLIENT_LOCKQ(client);
736 evdev_client_push(client, type, code, value);
737 if (type == EV_SYN && code == SYN_REPORT)
738 evdev_notify_event(client);
739 EVDEV_CLIENT_UNLOCKQ(client);
742 evdev->ev_event_count++;
746 evdev_send_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
749 enum evdev_sparse_result sparse;
751 EVDEV_LOCK_ASSERT(evdev);
753 sparse = evdev_sparse_event(evdev, type, code, value);
755 case EV_REPORT_MT_SLOT:
756 /* report postponed ABS_MT_SLOT */
757 evdev_propagate_event(evdev, EV_ABS, ABS_MT_SLOT,
758 CURRENT_MT_SLOT(evdev));
760 case EV_REPORT_EVENT:
761 evdev_propagate_event(evdev, type, code, value);
769 evdev_restore_after_kdb(struct evdev_dev *evdev)
773 EVDEV_LOCK_ASSERT(evdev);
775 /* Report postponed leds */
776 for (code = 0; code < LED_CNT; code++)
777 if (bit_test(evdev->ev_kdb_led_states, code))
778 evdev_send_event(evdev, EV_LED, code,
779 !bit_test(evdev->ev_led_states, code));
780 bit_nclear(evdev->ev_kdb_led_states, 0, LED_MAX);
782 /* Release stuck keys (CTRL + ALT + ESC) */
783 evdev_stop_repeat(evdev);
784 for (code = 0; code < KEY_CNT; code++) {
785 if (bit_test(evdev->ev_key_states, code)) {
786 evdev_send_event(evdev, EV_KEY, code, KEY_EVENT_UP);
787 evdev_send_event(evdev, EV_SYN, SYN_REPORT, 1);
793 evdev_push_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
797 if (evdev_check_event(evdev, type, code, value) != 0)
801 * Discard all but LEDs kdb events as unrelated to userspace.
802 * Aggregate LED updates and postpone reporting until kdb deactivation.
804 if (kdb_active || SCHEDULER_STOPPED()) {
805 evdev->ev_kdb_active = true;
807 bit_set(evdev->ev_kdb_led_states,
808 bit_test(evdev->ev_led_states, code) != value);
814 /* Fix evdev state corrupted with discarding of kdb events */
815 if (evdev->ev_kdb_active) {
816 evdev->ev_kdb_active = false;
817 evdev_restore_after_kdb(evdev);
820 evdev_modify_event(evdev, type, code, &value);
821 if (type == EV_SYN && code == SYN_REPORT &&
822 bit_test(evdev->ev_flags, EVDEV_FLAG_MT_AUTOREL))
823 evdev_send_mt_autorel(evdev);
824 if (type == EV_SYN && code == SYN_REPORT && evdev->ev_report_opened &&
825 bit_test(evdev->ev_flags, EVDEV_FLAG_MT_STCOMPAT))
826 evdev_send_mt_compat(evdev);
827 evdev_send_event(evdev, type, code, value);
835 evdev_inject_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
842 /* evdev repeats should not be processed by hardware driver */
843 if (bit_test(evdev->ev_flags, EVDEV_FLAG_SOFTREPEAT))
850 if (evdev->ev_methods != NULL &&
851 evdev->ev_methods->ev_event != NULL)
852 evdev->ev_methods->ev_event(evdev, type, code, value);
854 * Leds and driver repeats should be reported in ev_event
855 * method body to interoperate with kbdmux states and rates
856 * propagation so both ways (ioctl and evdev) of changing it
857 * will produce only one evdev event report to client.
859 if (type == EV_LED || type == EV_REP)
868 if (evdev->ev_lock_type != EV_LOCK_INTERNAL)
870 ret = evdev_push_event(evdev, type, code, value);
871 if (evdev->ev_lock_type != EV_LOCK_INTERNAL)
883 evdev_register_client(struct evdev_dev *evdev, struct evdev_client *client)
887 debugf(evdev, "adding new client for device %s", evdev->ev_shortname);
889 EVDEV_LOCK_ASSERT(evdev);
891 if (LIST_EMPTY(&evdev->ev_clients) && evdev->ev_methods != NULL &&
892 evdev->ev_methods->ev_open != NULL) {
893 debugf(evdev, "calling ev_open() on device %s",
894 evdev->ev_shortname);
895 ret = evdev->ev_methods->ev_open(evdev);
898 LIST_INSERT_HEAD(&evdev->ev_clients, client, ec_link);
903 evdev_dispose_client(struct evdev_dev *evdev, struct evdev_client *client)
905 debugf(evdev, "removing client for device %s", evdev->ev_shortname);
907 EVDEV_LOCK_ASSERT(evdev);
909 LIST_REMOVE(client, ec_link);
910 if (LIST_EMPTY(&evdev->ev_clients)) {
911 if (evdev->ev_methods != NULL &&
912 evdev->ev_methods->ev_close != NULL)
913 (void)evdev->ev_methods->ev_close(evdev);
914 if (evdev_event_supported(evdev, EV_REP) &&
915 bit_test(evdev->ev_flags, EVDEV_FLAG_SOFTREPEAT))
916 evdev_stop_repeat(evdev);
918 evdev_release_client(evdev, client);
922 evdev_grab_client(struct evdev_dev *evdev, struct evdev_client *client)
925 EVDEV_LOCK_ASSERT(evdev);
927 if (evdev->ev_grabber != NULL)
930 evdev->ev_grabber = client;
936 evdev_release_client(struct evdev_dev *evdev, struct evdev_client *client)
939 EVDEV_LOCK_ASSERT(evdev);
941 if (evdev->ev_grabber != client)
944 evdev->ev_grabber = NULL;
950 evdev_repeat_callout(void *arg)
952 struct evdev_dev *evdev = (struct evdev_dev *)arg;
954 evdev_send_event(evdev, EV_KEY, evdev->ev_rep_key, KEY_EVENT_REPEAT);
955 evdev_send_event(evdev, EV_SYN, SYN_REPORT, 1);
957 if (evdev->ev_rep[REP_PERIOD])
958 callout_reset(&evdev->ev_rep_callout,
959 evdev->ev_rep[REP_PERIOD] * hz / 1000,
960 evdev_repeat_callout, evdev);
962 evdev->ev_rep_key = KEY_RESERVED;
966 evdev_start_repeat(struct evdev_dev *evdev, uint16_t key)
969 EVDEV_LOCK_ASSERT(evdev);
971 if (evdev->ev_rep[REP_DELAY]) {
972 evdev->ev_rep_key = key;
973 callout_reset(&evdev->ev_rep_callout,
974 evdev->ev_rep[REP_DELAY] * hz / 1000,
975 evdev_repeat_callout, evdev);
980 evdev_stop_repeat(struct evdev_dev *evdev)
983 EVDEV_LOCK_ASSERT(evdev);
985 if (evdev->ev_rep_key != KEY_RESERVED) {
986 callout_stop(&evdev->ev_rep_callout);
987 evdev->ev_rep_key = KEY_RESERVED;
991 MODULE_VERSION(evdev, 1);