summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgonzo <gonzo@FreeBSD.org>2016-11-06 21:41:26 +0000
committergonzo <gonzo@FreeBSD.org>2016-11-06 21:41:26 +0000
commit7c8722f9677c64d732c1591a3a3cf7ca0ba97ed9 (patch)
tree5de0c11f50d4c580c996e7896d321113e8330694
parentb82022461caea290c7bce683816b76f5bad5d78d (diff)
downloadFreeBSD-src-7c8722f9677c64d732c1591a3a3cf7ca0ba97ed9.zip
FreeBSD-src-7c8722f9677c64d732c1591a3a3cf7ca0ba97ed9.tar.gz
MFC r307804-r307805
r307804: EVDEV: Add shortcut functions for event types Add wrappers around generic evdev_push_event for specific event types: EV_KEY/EV_REL/EV_ABS etc... Submitted by: Vladimir Kondratiev <wulf@cicgroup.ru> r307805: EVDEV: ums evdev support improvements: locking and event reporting - Use ums lock as evdev lock - Do not cap axes values to sysmouse limits for evdev reports - Do not map T-axis events to buttons for evdev reports - Use shortcuts for event reporting Submitted by: Vladimir Kondratiev <wulf@cicgroup.ru> MFC after: 1 week
-rw-r--r--sys/dev/evdev/evdev.c15
-rw-r--r--sys/dev/evdev/evdev.h66
-rw-r--r--sys/dev/evdev/evdev_utils.c7
-rw-r--r--sys/dev/usb/input/ums.c63
4 files changed, 107 insertions, 44 deletions
diff --git a/sys/dev/evdev/evdev.c b/sys/dev/evdev/evdev.c
index 63e0496..4de5dee 100644
--- a/sys/dev/evdev/evdev.c
+++ b/sys/dev/evdev/evdev.c
@@ -822,21 +822,6 @@ push:
return (ret);
}
-inline int
-evdev_sync(struct evdev_dev *evdev)
-{
-
- return (evdev_push_event(evdev, EV_SYN, SYN_REPORT, 1));
-}
-
-
-inline int
-evdev_mt_sync(struct evdev_dev *evdev)
-{
-
- return (evdev_push_event(evdev, EV_SYN, SYN_MT_REPORT, 1));
-}
-
int
evdev_register_client(struct evdev_dev *evdev, struct evdev_client *client)
{
diff --git a/sys/dev/evdev/evdev.h b/sys/dev/evdev/evdev.h
index 7287e73..34808b4 100644
--- a/sys/dev/evdev/evdev.h
+++ b/sys/dev/evdev/evdev.h
@@ -97,8 +97,6 @@ int evdev_register(struct evdev_dev *);
int evdev_register_mtx(struct evdev_dev *, struct mtx *);
int evdev_unregister(struct evdev_dev *);
int evdev_push_event(struct evdev_dev *, uint16_t, uint16_t, int32_t);
-int evdev_sync(struct evdev_dev *);
-int evdev_mt_sync(struct evdev_dev *);
void evdev_support_prop(struct evdev_dev *, uint16_t);
void evdev_support_event(struct evdev_dev *, uint16_t);
void evdev_support_key(struct evdev_dev *, uint16_t);
@@ -129,4 +127,68 @@ void evdev_push_leds(struct evdev_dev *, int);
void evdev_push_repeats(struct evdev_dev *, keyboard_t *);
evdev_event_t evdev_ev_kbd_event;
+/* Event reporting shortcuts: */
+static __inline int
+evdev_sync(struct evdev_dev *evdev)
+{
+
+ return (evdev_push_event(evdev, EV_SYN, SYN_REPORT, 1));
+}
+
+static __inline int
+evdev_mt_sync(struct evdev_dev *evdev)
+{
+
+ return (evdev_push_event(evdev, EV_SYN, SYN_MT_REPORT, 1));
+}
+
+static __inline int
+evdev_push_key(struct evdev_dev *evdev, uint16_t code, int32_t value)
+{
+
+ return (evdev_push_event(evdev, EV_KEY, code, value != 0));
+}
+
+static __inline int
+evdev_push_rel(struct evdev_dev *evdev, uint16_t code, int32_t value)
+{
+
+ return (evdev_push_event(evdev, EV_REL, code, value));
+}
+
+static __inline int
+evdev_push_abs(struct evdev_dev *evdev, uint16_t code, int32_t value)
+{
+
+ return (evdev_push_event(evdev, EV_ABS, code, value));
+}
+
+static __inline int
+evdev_push_msc(struct evdev_dev *evdev, uint16_t code, int32_t value)
+{
+
+ return (evdev_push_event(evdev, EV_MSC, code, value));
+}
+
+static __inline int
+evdev_push_led(struct evdev_dev *evdev, uint16_t code, int32_t value)
+{
+
+ return (evdev_push_event(evdev, EV_LED, code, value != 0));
+}
+
+static __inline int
+evdev_push_snd(struct evdev_dev *evdev, uint16_t code, int32_t value)
+{
+
+ return (evdev_push_event(evdev, EV_SND, code, value != 0));
+}
+
+static __inline int
+evdev_push_sw(struct evdev_dev *evdev, uint16_t code, int32_t value)
+{
+
+ return (evdev_push_event(evdev, EV_SW, code, value != 0));
+}
+
#endif /* _DEV_EVDEV_EVDEV_H */
diff --git a/sys/dev/evdev/evdev_utils.c b/sys/dev/evdev/evdev_utils.c
index 47e5e64..8606342 100644
--- a/sys/dev/evdev/evdev_utils.c
+++ b/sys/dev/evdev/evdev_utils.c
@@ -271,8 +271,8 @@ evdev_push_mouse_btn(struct evdev_dev *evdev, int buttons)
size_t i;
for (i = 0; i < nitems(evdev_mouse_button_codes); i++)
- evdev_push_event(evdev, EV_KEY, evdev_mouse_button_codes[i],
- (buttons & (1 << i)) != 0);
+ evdev_push_key(evdev, evdev_mouse_button_codes[i],
+ buttons & (1 << i));
}
void
@@ -285,8 +285,7 @@ evdev_push_leds(struct evdev_dev *evdev, int leds)
return;
for (i = 0; i < nitems(evdev_led_codes); i++)
- evdev_push_event(evdev, EV_LED, evdev_led_codes[i],
- (leds & (1 << i)) != 0);
+ evdev_push_led(evdev, evdev_led_codes[i], leds & (1 << i));
}
void
diff --git a/sys/dev/usb/input/ums.c b/sys/dev/usb/input/ums.c
index 4d60517..6679ea3 100644
--- a/sys/dev/usb/input/ums.c
+++ b/sys/dev/usb/input/ums.c
@@ -173,6 +173,8 @@ static usb_fifo_ioctl_t ums_fifo_ioctl;
#ifdef EVDEV_SUPPORT
static evdev_open_t ums_ev_open;
static evdev_close_t ums_ev_close;
+static void ums_evdev_push(struct ums_softc *, int32_t, int32_t,
+ int32_t, int32_t, int32_t);
#endif
static void ums_start_rx(struct ums_softc *);
@@ -205,6 +207,9 @@ ums_put_queue_timeout(void *__sc)
mtx_assert(&sc->sc_mtx, MA_OWNED);
ums_put_queue(sc, 0, 0, 0, 0, 0);
+#ifdef EVDEV_SUPPORT
+ ums_evdev_push(sc, 0, 0, 0, 0, 0);
+#endif
}
static void
@@ -216,6 +221,9 @@ ums_intr_callback(struct usb_xfer *xfer, usb_error_t error)
uint8_t *buf = sc->sc_temp;
int32_t buttons = 0;
int32_t buttons_found = 0;
+#ifdef EVDEV_SUPPORT
+ int32_t buttons_reported = 0;
+#endif
int32_t dw = 0;
int32_t dx = 0;
int32_t dy = 0;
@@ -306,6 +314,9 @@ ums_intr_callback(struct usb_xfer *xfer, usb_error_t error)
if (++info != &sc->sc_info[UMS_INFO_MAX])
goto repeat;
+#ifdef EVDEV_SUPPORT
+ buttons_reported = buttons;
+#endif
/* keep old button value(s) for non-detected buttons */
buttons |= sc->sc_status.button & ~buttons_found;
@@ -351,6 +362,11 @@ ums_intr_callback(struct usb_xfer *xfer, usb_error_t error)
usb_callout_stop(&sc->sc_callout);
ums_put_queue(sc, dx, dy, dz, dt, buttons);
+#ifdef EVDEV_SUPPORT
+ ums_evdev_push(sc, dx, dy, dz, dt,
+ buttons_reported);
+#endif
+
}
}
case USB_ST_SETUP:
@@ -720,7 +736,7 @@ ums_attach(device_t dev)
for (i = 0; i < info->sc_buttons; i++)
evdev_support_key(sc->sc_evdev, BTN_MOUSE + i);
- err = evdev_register(sc->sc_evdev);
+ err = evdev_register_mtx(sc->sc_evdev, &sc->sc_mtx);
if (err)
goto detach;
#endif
@@ -891,27 +907,32 @@ ums_put_queue(struct ums_softc *sc, int32_t dx, int32_t dy,
}
usb_fifo_put_data_linear(sc->sc_fifo.fp[USB_FIFO_RX], buf,
sc->sc_mode.packetsize, 1);
-
-#ifdef EVDEV_SUPPORT
- if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
- /* Push evdev event */
- evdev_push_event(sc->sc_evdev, EV_REL, REL_X, dx);
- evdev_push_event(sc->sc_evdev, EV_REL, REL_Y, -dy);
- evdev_push_event(sc->sc_evdev, EV_REL, REL_WHEEL, -dz);
- evdev_push_event(sc->sc_evdev, EV_REL, REL_HWHEEL, dt);
- evdev_push_mouse_btn(sc->sc_evdev,
- (buttons & ~MOUSE_STDBUTTONS) |
- (buttons & (1 << 2) ? MOUSE_BUTTON1DOWN : 0) |
- (buttons & (1 << 1) ? MOUSE_BUTTON2DOWN : 0) |
- (buttons & (1 << 0) ? MOUSE_BUTTON3DOWN : 0));
- evdev_sync(sc->sc_evdev);
- }
-#endif
} else {
DPRINTF("Buffer full, discarded packet\n");
}
}
+#ifdef EVDEV_SUPPORT
+static void
+ums_evdev_push(struct ums_softc *sc, int32_t dx, int32_t dy,
+ int32_t dz, int32_t dt, int32_t buttons)
+{
+ if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
+ /* Push evdev event */
+ evdev_push_rel(sc->sc_evdev, REL_X, dx);
+ evdev_push_rel(sc->sc_evdev, REL_Y, -dy);
+ evdev_push_rel(sc->sc_evdev, REL_WHEEL, -dz);
+ evdev_push_rel(sc->sc_evdev, REL_HWHEEL, dt);
+ evdev_push_mouse_btn(sc->sc_evdev,
+ (buttons & ~MOUSE_STDBUTTONS) |
+ (buttons & (1 << 2) ? MOUSE_BUTTON1DOWN : 0) |
+ (buttons & (1 << 1) ? MOUSE_BUTTON2DOWN : 0) |
+ (buttons & (1 << 0) ? MOUSE_BUTTON3DOWN : 0));
+ evdev_sync(sc->sc_evdev);
+ }
+}
+#endif
+
static void
ums_reset_buf(struct ums_softc *sc)
{
@@ -925,7 +946,7 @@ ums_ev_open(struct evdev_dev *evdev, void *ev_softc)
{
struct ums_softc *sc = (struct ums_softc *)ev_softc;
- mtx_lock(&sc->sc_mtx);
+ mtx_assert(&sc->sc_mtx, MA_OWNED);
sc->sc_evflags = UMS_EVDEV_OPENED;
@@ -934,8 +955,6 @@ ums_ev_open(struct evdev_dev *evdev, void *ev_softc)
ums_start_rx(sc);
}
- mtx_unlock(&sc->sc_mtx);
-
return (0);
}
@@ -944,14 +963,12 @@ ums_ev_close(struct evdev_dev *evdev, void *ev_softc)
{
struct ums_softc *sc = (struct ums_softc *)ev_softc;
- mtx_lock(&sc->sc_mtx);
+ mtx_assert(&sc->sc_mtx, MA_OWNED);
sc->sc_evflags = 0;
if (sc->sc_fflags == 0)
ums_stop_rx(sc);
-
- mtx_unlock(&sc->sc_mtx);
}
#endif
OpenPOWER on IntegriCloud