diff options
author | Ulf Brosziewski <bru@cvs.openbsd.org> | 2017-10-28 14:31:30 +0000 |
---|---|---|
committer | Ulf Brosziewski <bru@cvs.openbsd.org> | 2017-10-28 14:31:30 +0000 |
commit | ad95ab40a106c0d66d2d08914670f31d0181d7f6 (patch) | |
tree | 6cc0cbd63458da1edf0e1a383901f457c0cf1131 /sys/dev | |
parent | 91e82d29f2d105da65ff39086c6956e0e15a50fc (diff) |
Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.
The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.
ok stsp
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/pckbc/pms.c | 179 |
1 files changed, 86 insertions, 93 deletions
diff --git a/sys/dev/pckbc/pms.c b/sys/dev/pckbc/pms.c index 11052e4bf99..a81417d60e1 100644 --- a/sys/dev/pckbc/pms.c +++ b/sys/dev/pckbc/pms.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pms.c,v 1.80 2017/08/26 18:34:04 bru Exp $ */ +/* $OpenBSD: pms.c,v 1.81 2017/10/28 14:31:29 bru Exp $ */ /* $NetBSD: psm.c,v 1.11 2000/06/05 22:20:57 sommerfeld Exp $ */ /*- @@ -130,9 +130,6 @@ struct elantech_softc { #define ELANTECH_F_CRC_ENABLED 0x10 int fw_version; - int min_x, min_y; - int max_x, max_y; - u_int mt_slots; int width; @@ -140,10 +137,8 @@ struct elantech_softc { u_char parity[256]; u_char p1, p2, p3; - /* Compat mode */ - int wsmode; + int max_x, max_y; int old_x, old_y; - u_int old_buttons; }; struct pms_softc { /* driver status information */ @@ -303,7 +298,6 @@ int alps_sec_proc(struct pms_softc *); int alps_get_hwinfo(struct pms_softc *); int elantech_knock(struct pms_softc *); -void elantech_send_input(struct pms_softc *, int, int, int, int); int elantech_get_hwinfo_v1(struct pms_softc *); int elantech_get_hwinfo_v2(struct pms_softc *); int elantech_get_hwinfo_v3(struct pms_softc *); @@ -1709,6 +1703,7 @@ int elantech_get_hwinfo_v1(struct pms_softc *sc) { struct elantech_softc *elantech = sc->elantech; + struct wsmousehw *hw; int fw_version; u_char capabilities[3]; @@ -1733,10 +1728,13 @@ elantech_get_hwinfo_v1(struct pms_softc *sc) if (elantech_set_absolute_mode_v1(sc)) return (-1); - elantech->min_x = ELANTECH_V1_X_MIN; - elantech->max_x = ELANTECH_V1_X_MAX; - elantech->min_y = ELANTECH_V1_Y_MIN; - elantech->max_y = ELANTECH_V1_Y_MAX; + hw = wsmouse_get_hw(sc->sc_wsmousedev); + hw->type = WSMOUSE_TYPE_ELANTECH; + hw->hw_type = WSMOUSEHW_TOUCHPAD; + hw->x_min = ELANTECH_V1_X_MIN; + hw->x_max = ELANTECH_V1_X_MAX; + hw->y_min = ELANTECH_V1_Y_MIN; + hw->y_max = ELANTECH_V1_Y_MAX; return (0); } @@ -1745,6 +1743,7 @@ int elantech_get_hwinfo_v2(struct pms_softc *sc) { struct elantech_softc *elantech = sc->elantech; + struct wsmousehw *hw; int fw_version, ic_ver; u_char capabilities[3]; int i, fixed_dpi; @@ -1768,10 +1767,14 @@ elantech_get_hwinfo_v2(struct pms_softc *sc) if (elantech_set_absolute_mode_v2(sc)) return (-1); + hw = wsmouse_get_hw(sc->sc_wsmousedev); + hw->type = WSMOUSE_TYPE_ELANTECH; + hw->hw_type = WSMOUSEHW_TOUCHPAD; + if (fw_version == 0x20800 || fw_version == 0x20b00 || fw_version == 0x20030) { - elantech->max_x = ELANTECH_V2_X_MAX; - elantech->max_y = ELANTECH_V2_Y_MAX; + hw->x_max = ELANTECH_V2_X_MAX; + hw->y_max = ELANTECH_V2_Y_MAX; } else { if (pms_spec_cmd(sc, ELANTECH_QUE_FW_ID) || pms_get_status(sc, resp)) @@ -1782,17 +1785,17 @@ elantech_get_hwinfo_v2(struct pms_softc *sc) if (pms_spec_cmd(sc, ELANTECH_QUE_SAMPLE) || pms_get_status(sc, resp)) return (-1); - elantech->max_x = (capabilities[1] - i) * resp[1] / 2; - elantech->max_y = (capabilities[2] - i) * resp[2] / 2; + hw->x_max = (capabilities[1] - i) * resp[1] / 2; + hw->y_max = (capabilities[2] - i) * resp[2] / 2; } else if (fw_version == 0x040216) { - elantech->max_x = 819; - elantech->max_y = 405; + hw->x_max = 819; + hw->y_max = 405; } else if (fw_version == 0x040219 || fw_version == 0x040215) { - elantech->max_x = 900; - elantech->max_y = 500; + hw->x_max = 900; + hw->y_max = 500; } else { - elantech->max_x = (capabilities[1] - i) * 64; - elantech->max_y = (capabilities[2] - i) * 64; + hw->x_max = (capabilities[1] - i) * 64; + hw->y_max = (capabilities[2] - i) * 64; } } @@ -1803,6 +1806,7 @@ int elantech_get_hwinfo_v3(struct pms_softc *sc) { struct elantech_softc *elantech = sc->elantech; + struct wsmousehw *hw; int fw_version; u_char resp[3]; @@ -1825,8 +1829,12 @@ elantech_get_hwinfo_v3(struct pms_softc *sc) pms_get_status(sc, resp)) return (-1); - elantech->max_x = (resp[0] & 0x0f) << 8 | resp[1]; - elantech->max_y = (resp[0] & 0xf0) << 4 | resp[2]; + hw = wsmouse_get_hw(sc->sc_wsmousedev); + hw->x_max = elantech->max_x = (resp[0] & 0x0f) << 8 | resp[1]; + hw->y_max = elantech->max_y = (resp[0] & 0xf0) << 4 | resp[2]; + + hw->type = WSMOUSE_TYPE_ELANTECH; + hw->hw_type = WSMOUSEHW_TOUCHPAD; return (0); } @@ -1929,6 +1937,13 @@ pms_enable_elantech_v1(struct pms_softc *sc) sc->elantech = NULL; goto err; } + if (wsmouse_configure(sc->sc_wsmousedev, NULL, 0)) { + free(sc->elantech, M_DEVBUF, + sizeof(struct elantech_softc)); + sc->elantech = NULL; + printf("%s: elantech: setup failed\n", DEVNAME(sc)); + goto err; + } printf("%s: Elantech Touchpad, version %d, firmware 0x%x\n", DEVNAME(sc), 1, sc->elantech->fw_version); @@ -1969,6 +1984,13 @@ pms_enable_elantech_v2(struct pms_softc *sc) sc->elantech = NULL; goto err; } + if (wsmouse_configure(sc->sc_wsmousedev, NULL, 0)) { + free(sc->elantech, M_DEVBUF, + sizeof(struct elantech_softc)); + sc->elantech = NULL; + printf("%s: elantech: setup failed\n", DEVNAME(sc)); + goto err; + } printf("%s: Elantech Touchpad, version %d, firmware 0x%x\n", DEVNAME(sc), 2, sc->elantech->fw_version); @@ -2006,6 +2028,13 @@ pms_enable_elantech_v3(struct pms_softc *sc) sc->elantech = NULL; goto err; } + if (wsmouse_configure(sc->sc_wsmousedev, NULL, 0)) { + free(sc->elantech, M_DEVBUF, + sizeof(struct elantech_softc)); + sc->elantech = NULL; + printf("%s: elantech: setup failed\n", DEVNAME(sc)); + goto err; + } printf("%s: Elantech Touchpad, version %d, firmware 0x%x\n", DEVNAME(sc), 3, sc->elantech->fw_version); @@ -2044,12 +2073,12 @@ pms_enable_elantech_v4(struct pms_softc *sc) goto err; } if (wsmouse_configure(sc->sc_wsmousedev, NULL, 0)) { - free(sc->elantech, M_DEVBUF, 0); + free(sc->elantech, M_DEVBUF, + sizeof(struct elantech_softc)); sc->elantech = NULL; - printf("%s: setup failed\n", DEVNAME(sc)); + printf("%s: elantech: setup failed\n", DEVNAME(sc)); goto err; } - wsmouse_set_mode(sc->sc_wsmousedev, WSMOUSE_COMPAT); printf("%s: Elantech Clickpad, version %d, firmware 0x%x\n", DEVNAME(sc), 4, sc->elantech->fw_version); @@ -2068,7 +2097,6 @@ int pms_ioctl_elantech(struct pms_softc *sc, u_long cmd, caddr_t data, int flag, struct proc *p) { - struct elantech_softc *elantech = sc->elantech; struct wsmouse_calibcoords *wsmc = (struct wsmouse_calibcoords *)data; struct wsmousehw *hw; int wsmode; @@ -2078,29 +2106,20 @@ pms_ioctl_elantech(struct pms_softc *sc, u_long cmd, caddr_t data, int flag, *(u_int *)data = WSMOUSE_TYPE_ELANTECH; break; case WSMOUSEIO_GCALIBCOORDS: - if (sc->protocol->type == PMS_ELANTECH_V4) { - hw = wsmouse_get_hw(sc->sc_wsmousedev); - wsmc->minx = hw->x_min; - wsmc->maxx = hw->x_max; - wsmc->miny = hw->y_min; - wsmc->maxy = hw->y_max; - } else { - wsmc->minx = elantech->min_x; - wsmc->maxx = elantech->max_x; - wsmc->miny = elantech->min_y; - wsmc->maxy = elantech->max_y; - } + hw = wsmouse_get_hw(sc->sc_wsmousedev); + wsmc->minx = hw->x_min; + wsmc->maxx = hw->x_max; + wsmc->miny = hw->y_min; + wsmc->maxy = hw->y_max; wsmc->swapxy = 0; - wsmc->resx = 0; - wsmc->resy = 0; + wsmc->resx = hw->h_res; + wsmc->resy = hw->v_res; break; case WSMOUSEIO_SETMODE: wsmode = *(u_int *)data; if (wsmode != WSMOUSE_COMPAT && wsmode != WSMOUSE_NATIVE) return (EINVAL); - elantech->wsmode = wsmode; - if (sc->protocol->type == PMS_ELANTECH_V4) - wsmouse_set_mode(sc->sc_wsmousedev, wsmode); + wsmouse_set_mode(sc->sc_wsmousedev, wsmode); break; default: return (-1); @@ -2236,6 +2255,16 @@ pms_proc_elantech_v1(struct pms_softc *sc) { struct elantech_softc *elantech = sc->elantech; int x, y, w, z; + u_int buttons; + + buttons = butmap[sc->packet[0] & 3]; + + if (elantech->flags & ELANTECH_F_HAS_ROCKER) { + if (sc->packet[0] & 0x40) /* up */ + buttons |= WSMOUSE_BUTTON(4); + if (sc->packet[0] & 0x80) /* down */ + buttons |= WSMOUSE_BUTTON(5); + } if (elantech->flags & ELANTECH_F_HW_V1_OLD) w = ((sc->packet[1] & 0x80) >> 7) + @@ -2254,7 +2283,7 @@ pms_proc_elantech_v1(struct pms_softc *sc) z = 0; } - elantech_send_input(sc, x, y, z, w); + WSMOUSE_TOUCH(sc->sc_wsmousedev, buttons, x, y, z, w); } void @@ -2263,6 +2292,7 @@ pms_proc_elantech_v2(struct pms_softc *sc) const u_char debounce_pkt[] = { 0x84, 0xff, 0xff, 0x02, 0xff, 0xff }; struct elantech_softc *elantech = sc->elantech; int x, y, w, z; + u_int buttons; /* * The hardware sends this packet when in debounce state. @@ -2271,6 +2301,8 @@ pms_proc_elantech_v2(struct pms_softc *sc) if (!memcmp(sc->packet, debounce_pkt, sizeof(debounce_pkt))) return; + buttons = butmap[sc->packet[0] & 3]; + w = (sc->packet[0] & 0xc0) >> 6; if (w == 1 || w == 3) { x = ((sc->packet[1] & 0x0f) << 8) | sc->packet[2]; @@ -2290,7 +2322,7 @@ pms_proc_elantech_v2(struct pms_softc *sc) z = 0; } - elantech_send_input(sc, x, y, z, w); + WSMOUSE_TOUCH(sc->sc_wsmousedev, buttons, x, y, z, w); } void @@ -2299,6 +2331,9 @@ pms_proc_elantech_v3(struct pms_softc *sc) const u_char debounce_pkt[] = { 0xc4, 0xff, 0xff, 0x02, 0xff, 0xff }; struct elantech_softc *elantech = sc->elantech; int x, y, w, z; + u_int buttons; + + buttons = butmap[sc->packet[0] & 3]; x = ((sc->packet[1] & 0x0f) << 8 | sc->packet[2]); y = ((sc->packet[4] & 0x0f) << 8 | sc->packet[5]); @@ -2339,7 +2374,9 @@ pms_proc_elantech_v3(struct pms_softc *sc) else if (w) z = SYNAPTICS_PRESSURE; - elantech_send_input(sc, x, y, z, w); + WSMOUSE_TOUCH(sc->sc_wsmousedev, buttons, x, y, z, w); + elantech->old_x = x; + elantech->old_y = y; } void @@ -2394,52 +2431,8 @@ pms_proc_elantech_v4(struct pms_softc *sc) return; } - buttons = 0; - if (sc->packet[0] & 0x01) - buttons |= WSMOUSE_BUTTON(1); - if (sc->packet[0] & 0x02) - buttons |= WSMOUSE_BUTTON(3); + buttons = butmap[sc->packet[0] & 3]; wsmouse_buttons(sc_wsmousedev, buttons); wsmouse_input_sync(sc_wsmousedev); } - -void -elantech_send_input(struct pms_softc *sc, int x, int y, int z, int w) -{ - struct elantech_softc *elantech = sc->elantech; - int dx, dy; - u_int buttons = 0; - - if (sc->packet[0] & 0x01) - buttons |= WSMOUSE_BUTTON(1); - if (sc->packet[0] & 0x02) - buttons |= WSMOUSE_BUTTON(3); - - if (elantech->flags & ELANTECH_F_HAS_ROCKER) { - if (sc->packet[0] & 0x40) /* up */ - buttons |= WSMOUSE_BUTTON(4); - if (sc->packet[0] & 0x80) /* down */ - buttons |= WSMOUSE_BUTTON(5); - } - - if (elantech->wsmode == WSMOUSE_NATIVE) { - WSMOUSE_TOUCH(sc->sc_wsmousedev, buttons, x, y, z, w); - } else { - dx = dy = 0; - - if ((elantech->flags & ELANTECH_F_REPORTS_PRESSURE) && - z > SYNAPTICS_PRESSURE) { - dx = x - elantech->old_x; - dy = y - elantech->old_y; - dx /= SYNAPTICS_SCALE; - dy /= SYNAPTICS_SCALE; - } - if (dx || dy || buttons != elantech->old_buttons) - WSMOUSE_INPUT(sc->sc_wsmousedev, buttons, dx, dy, 0, 0); - elantech->old_buttons = buttons; - } - - elantech->old_x = x; - elantech->old_y = y; -} |