Deleted Added
sdiff udiff text old ( 334763 ) new ( 343158 )
full compact
1/*-
2 * Copyright (c) 1992, 1993 Erik Forsberg.
3 * Copyright (c) 1996, 1997 Kazutaka YOKOTA.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 45 unchanged lines hidden (view full) ---

54 * HiNote UltraII/Latitude/Armada laptops.
55 * - 30 July 1997. Added APM support.
56 * - 5 March 1997. Defined driver configuration flags (PSM_CONFIG_XXX).
57 * Improved sync check logic.
58 * Vendor specific support routines.
59 */
60
61#include <sys/cdefs.h>
62__FBSDID("$FreeBSD: stable/11/sys/dev/atkbdc/psm.c 334763 2018-06-07 07:43:58Z hselasky $");
63
64#include "opt_isa.h"
65#include "opt_psm.h"
66#include "opt_evdev.h"
67
68#include <sys/param.h>
69#include <sys/systm.h>
70#include <sys/kernel.h>

--- 60 unchanged lines hidden (view full) ---

131/* end of driver specific options */
132
133#define PSMCPNP_DRIVER_NAME "psmcpnp"
134
135struct psmcpnp_softc {
136 enum {
137 PSMCPNP_GENERIC,
138 PSMCPNP_FORCEPAD,
139 PSMCPNP_HPSYN81,
140 } type; /* Based on PnP ID */
141};
142
143/* input queue */
144#define PSM_BUFSIZE 960
145#define PSM_SMALLBUFSIZE 240
146
147/* operation levels */
148#define PSM_LEVEL_BASE 0
149#define PSM_LEVEL_STANDARD 1
150#define PSM_LEVEL_NATIVE 2
151#define PSM_LEVEL_MIN PSM_LEVEL_BASE
152#define PSM_LEVEL_MAX PSM_LEVEL_NATIVE
153
154/* Logitech PS2++ protocol */
155#define MOUSE_PS2PLUS_CHECKBITS(b) \
156 ((((b[2] & 0x03) << 2) | 0x02) == (b[1] & 0x0f))
157#define MOUSE_PS2PLUS_PACKET_TYPE(b) \
158 (((b[0] & 0x30) >> 2) | ((b[1] & 0x30) >> 4))
159
160/* ring buffer */
161typedef struct ringbuf {

--- 8 unchanged lines hidden (view full) ---

170 u_char ipacket[16]; /* interim input buffer */
171 int inputbytes; /* # of bytes in the input buffer */
172} packetbuf_t;
173
174#ifndef PSM_PACKETQUEUE
175#define PSM_PACKETQUEUE 128
176#endif
177
178/*
179 * Typical bezel limits. Taken from 'Synaptics
180 * PS/2 TouchPad Interfacing Guide' p.3.2.3.
181 */
182#define SYNAPTICS_DEFAULT_MAX_X 5472
183#define SYNAPTICS_DEFAULT_MAX_Y 4448
184#define SYNAPTICS_DEFAULT_MIN_X 1472
185#define SYNAPTICS_DEFAULT_MIN_Y 1408
186
187typedef struct synapticsinfo {
188 struct sysctl_ctx_list sysctl_ctx;
189 struct sysctl_oid *sysctl_tree;
190 int directional_scrolls;
191 int two_finger_scroll;
192 int min_pressure;
193 int max_pressure;
194 int max_width;

--- 248 unchanged lines hidden (view full) ---

443 struct callout callout; /* watchdog timer call out */
444 struct callout softcallout; /* buffer timer call out */
445 struct cdev *dev;
446 struct cdev *bdev;
447 int lasterr;
448 int cmdcount;
449 struct sigio *async; /* Processes waiting for SIGIO */
450 int extended_buttons;
451#ifdef EVDEV_SUPPORT
452 struct evdev_dev *evdev_a; /* Absolute reporting device */
453 struct evdev_dev *evdev_r; /* Relative reporting device */
454#endif
455};
456static devclass_t psm_devclass;
457
458/* driver state flags (state) */

--- 149 unchanged lines hidden (view full) ---

608static int timeelapsed(const struct timeval *, int, int,
609 const struct timeval *);
610static void dropqueue(struct psm_softc *);
611static void flushpackets(struct psm_softc *);
612static void proc_mmanplus(struct psm_softc *, packetbuf_t *,
613 mousestatus_t *, int *, int *, int *);
614static int proc_synaptics(struct psm_softc *, packetbuf_t *,
615 mousestatus_t *, int *, int *, int *);
616static void proc_versapad(struct psm_softc *, packetbuf_t *,
617 mousestatus_t *, int *, int *, int *);
618static int proc_elantech(struct psm_softc *, packetbuf_t *,
619 mousestatus_t *, int *, int *, int *);
620static int psmpalmdetect(struct psm_softc *, finger_t *, int);
621static void psmgestures(struct psm_softc *, finger_t *, int,
622 mousestatus_t *);
623static void psmsmoother(struct psm_softc *, finger_t *, int,

--- 13 unchanged lines hidden (view full) ---

637static probefunc_t enable_aglide;
638static probefunc_t enable_kmouse;
639static probefunc_t enable_msexplorer;
640static probefunc_t enable_msintelli;
641static probefunc_t enable_4dmouse;
642static probefunc_t enable_4dplus;
643static probefunc_t enable_mmanplus;
644static probefunc_t enable_synaptics;
645static probefunc_t enable_trackpoint;
646static probefunc_t enable_versapad;
647static probefunc_t enable_elantech;
648
649static void set_trackpoint_parameters(struct psm_softc *sc);
650static void synaptics_passthrough_on(struct psm_softc *sc);
651static void synaptics_passthrough_off(struct psm_softc *sc);
652static int synaptics_preferred_mode(struct psm_softc *sc);

--- 4 unchanged lines hidden (view full) ---

657 u_char syncmask;
658 int packetsize;
659 probefunc_t *probefunc;
660} vendortype[] = {
661 /*
662 * WARNING: the order of probe is very important. Don't mess it
663 * unless you know what you are doing.
664 */
665 { MOUSE_MODEL_NET, /* Genius NetMouse */
666 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_gmouse },
667 { MOUSE_MODEL_NETSCROLL, /* Genius NetScroll */
668 0xc8, 6, enable_groller },
669 { MOUSE_MODEL_MOUSEMANPLUS, /* Logitech MouseMan+ */
670 0x08, MOUSE_PS2_PACKETSIZE, enable_mmanplus },
671 { MOUSE_MODEL_EXPLORER, /* Microsoft IntelliMouse Explorer */
672 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msexplorer },

--- 411 unchanged lines hidden (view full) ---

1084
1085 return (TRUE);
1086}
1087
1088static int
1089doopen(struct psm_softc *sc, int command_byte)
1090{
1091 int stat[3];
1092
1093 /*
1094 * FIXME: Synaptics TouchPad seems to go back to Relative Mode with
1095 * no obvious reason. Thus we check the current mode and restore the
1096 * Absolute Mode if it was cleared.
1097 *
1098 * The previous hack at the end of psmprobe() wasn't efficient when
1099 * moused(8) was restarted.
1100 *
1101 * A Reset (FF) or Set Defaults (F6) command would clear the
1102 * Absolute Mode bit. But a verbose boot or debug.psm.loglevel=5
1103 * doesn't show any evidence of such a command.
1104 */
1105 if (sc->hw.model == MOUSE_MODEL_SYNAPTICS) {
1106 mouse_ext_command(sc->kbdc, 1);
1107 get_mouse_status(sc->kbdc, stat, 0, 3);
1108 if ((SYNAPTICS_VERSION_GE(sc->synhw, 7, 5) ||
1109 stat[1] == 0x46 || stat[1] == 0x47) &&
1110 stat[2] == 0x40) {
1111 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
1112 VLOG(5, (LOG_DEBUG, "psm%d: Synaptis Absolute Mode "
1113 "hopefully restored\n",
1114 sc->unit));
1115 }
1116 }
1117
1118 /*
1119 * A user may want to disable tap and drag gestures on a Synaptics
1120 * TouchPad when it operates in Relative Mode.
1121 */
1122 if (sc->hw.model == MOUSE_MODEL_GENERIC) {
1123 if (tap_enabled > 0) {

--- 232 unchanged lines hidden (view full) ---

1356 sc->config |=
1357#ifdef PSM_RESETAFTERSUSPEND
1358 PSM_CONFIG_INITAFTERSUSPEND;
1359#else
1360 PSM_CONFIG_HOOKRESUME;
1361#endif
1362#endif /* PSM_HOOKRESUME | PSM_HOOKAPM */
1363 sc->flags = 0;
1364 if (bootverbose)
1365 ++verbose;
1366
1367 device_set_desc(dev, "PS/2 Mouse");
1368
1369 if (!kbdc_lock(sc->kbdc, TRUE)) {
1370 printf("psm%d: unable to lock the controller.\n", unit);
1371 if (bootverbose)

--- 453 unchanged lines hidden (view full) ---

1825 evdev_support_key(evdev_a, BTN_BACK);
1826 evdev_support_key(evdev_a, BTN_FORWARD);
1827 }
1828 if (sc->synhw.capExtended && (sc->synhw.nExtendedButtons > 0))
1829 for (i = 0; i < sc->synhw.nExtendedButtons; i++)
1830 evdev_support_key(evdev_a, BTN_0 + i);
1831
1832 error = evdev_register_mtx(evdev_a, &Giant);
1833 if (!error && sc->synhw.capPassthrough) {
1834 guest_model = sc->tpinfo.sysctl_tree != NULL ?
1835 MOUSE_MODEL_TRACKPOINT : MOUSE_MODEL_GENERIC;
1836 error = psm_register(dev, guest_model);
1837 }
1838 if (error)
1839 evdev_free(evdev_a);
1840 else
1841 sc->evdev_a = evdev_a;

--- 1103 unchanged lines hidden (view full) ---

2945static void
2946psmintr(void *arg)
2947{
2948 struct psm_softc *sc = arg;
2949 struct timeval now;
2950 int c;
2951 packetbuf_t *pb;
2952
2953
2954 /* read until there is nothing to read */
2955 while((c = read_aux_data_no_wait(sc->kbdc)) != -1) {
2956 pb = &sc->pqueue[sc->pqueue_end];
2957
2958 /* discard the byte if the device is not open */
2959 if (!(sc->state & (PSM_OPEN | PSM_EV_OPEN_R | PSM_EV_OPEN_A)))
2960 continue;

--- 335 unchanged lines hidden (view full) ---

3296 }
3297
3298 switch (w) {
3299 case 3:
3300 /*
3301 * Handle packets from the guest device. See:
3302 * Synaptics PS/2 TouchPad Interfacing Guide, Section 5.1
3303 */
3304 if (sc->synhw.capPassthrough) {
3305 *x = ((pb->ipacket[1] & 0x10) ?
3306 pb->ipacket[4] - 256 : pb->ipacket[4]);
3307 *y = ((pb->ipacket[1] & 0x20) ?
3308 pb->ipacket[5] - 256 : pb->ipacket[5]);
3309 *z = 0;
3310
3311 guest_buttons = 0;
3312 if (pb->ipacket[1] & 0x01)

--- 283 unchanged lines hidden (view full) ---

3596 *z = 0;
3597 ms->button &= ~(MOUSE_BUTTON4DOWN | MOUSE_BUTTON5DOWN |
3598 MOUSE_BUTTON6DOWN | MOUSE_BUTTON7DOWN);
3599
3600 return (0);
3601}
3602
3603static int
3604psmpalmdetect(struct psm_softc *sc, finger_t *f, int nfingers)
3605{
3606 if (!(
3607 ((sc->synhw.capMultiFinger || sc->synhw.capAdvancedGestures) &&
3608 !sc->synhw.capReportsV && nfingers > 1) ||
3609 (sc->synhw.capReportsV && nfingers > 2) ||
3610 (sc->synhw.capPalmDetect && f->w <= sc->syninfo.max_width) ||
3611 (!sc->synhw.capPalmDetect && f->p <= sc->syninfo.max_pressure) ||

--- 1318 unchanged lines hidden (view full) ---

4930 (pb->ipacket[2] & 0x07) ;
4931 } else {
4932 /* preserve previous button states */
4933 ms.button |= ms.obutton & MOUSE_EXTBUTTONS;
4934 }
4935 break;
4936
4937 case MOUSE_MODEL_SYNAPTICS:
4938 if (proc_synaptics(sc, pb, &ms, &x, &y, &z) != 0) {
4939 VLOG(3, (LOG_DEBUG, "synaptics: "
4940 "packet rejected\n"));
4941 goto next;
4942 }
4943 break;
4944
4945 case MOUSE_MODEL_ELANTECH:

--- 1094 unchanged lines hidden (view full) ---

6040 */
6041 if ((sc->synhw.capAdvancedGestures || sc->synhw.capReportsV) &&
6042 sc->hw.model == MOUSE_MODEL_SYNAPTICS && !(mode_byte & (1 << 5))) {
6043 mouse_ext_command(sc->kbdc, 3);
6044 set_mouse_sampling_rate(sc->kbdc, 0xc8);
6045 }
6046}
6047
6048static int
6049enable_synaptics(struct psm_softc *sc, enum probearg arg)
6050{
6051 device_t psmcpnp;
6052 struct psmcpnp_softc *psmcpnp_sc;
6053 KBDC kbdc = sc->kbdc;
6054 synapticshw_t synhw;
6055 int status[3];
6056 int buttons, middle_byte;
6057
6058 VLOG(3, (LOG_DEBUG, "synaptics: BEGIN init\n"));
6059
6060 /*
6061 * Just to be on the safe side: this avoids troubles with
6062 * following mouse_ext_command() when the previous command
6063 * was PSMC_SET_RESOLUTION. Set Scaling has no effect on
6064 * Synaptics Touchpad behaviour.
6065 */
6066 set_mouse_scaling(kbdc, 1);
6067
6068 /* Identify the Touchpad version. */
6069 if (mouse_ext_command(kbdc, 0) == 0)
6070 return (FALSE);
6071 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6072 return (FALSE);
6073 middle_byte = status[1];
6074 if (middle_byte != 0x46 && middle_byte != 0x47)
6075 return (FALSE);
6076
6077 bzero(&synhw, sizeof(synhw));
6078 synhw.infoMinor = status[0];
6079 synhw.infoMajor = status[2] & 0x0f;
6080
6081 if (verbose >= 2)
6082 printf("Synaptics Touchpad v%d.%d\n", synhw.infoMajor,
6083 synhw.infoMinor);
6084
6085 /*
6086 * Most synaptics touchpads return 0x47 in middle byte in responce to
6087 * identify command as stated in p.4.4 of "Synaptics PS/2 TouchPad
6088 * Interfacing Guide" and we only support v4.0 or better. But some
6089 * devices return 0x46 here and have a different numbering scheme.
6090 * In the case of 0x46, we allow versions as low as v2.0
6091 */
6092 if ((middle_byte == 0x47 && synhw.infoMajor < 4) ||
6093 (middle_byte == 0x46 && synhw.infoMajor < 2)) {
6094 printf(" Unsupported (pre-v4) Touchpad detected\n");
6095 return (FALSE);
6096 }
6097
6098 /* Get the Touchpad model information. */
6099 if (mouse_ext_command(kbdc, 3) == 0)
6100 return (FALSE);
6101 if (get_mouse_status(kbdc, status, 0, 3) != 3)

--- 24 unchanged lines hidden (view full) ---

6126 printf(" infoGeometry: %d\n", synhw.infoGeometry);
6127 }
6128
6129 /* Read the extended capability bits. */
6130 if (mouse_ext_command(kbdc, 2) == 0)
6131 return (FALSE);
6132 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6133 return (FALSE);
6134 if (!SYNAPTICS_VERSION_GE(synhw, 7, 5) && status[1] != middle_byte) {
6135 printf(" Failed to read extended capability bits\n");
6136 return (FALSE);
6137 }
6138
6139 psmcpnp = devclass_get_device(devclass_find(PSMCPNP_DRIVER_NAME),
6140 sc->unit);
6141 psmcpnp_sc = (psmcpnp != NULL) ? device_get_softc(psmcpnp) : NULL;
6142
6143 /*
6144 * Set conservative defaults for 0x46 middle byte touchpads
6145 * as ExtendedQueries return bogus data.
6146 */
6147 if (middle_byte == 0x46) {
6148 synhw.capExtended = 1;
6149 synhw.capPalmDetect = 1;
6150 synhw.capPassthrough = 1;
6151 synhw.capMultiFinger = 1;
6152 synhw.maximumXCoord = SYNAPTICS_DEFAULT_MAX_X;
6153 synhw.maximumYCoord = SYNAPTICS_DEFAULT_MAX_Y;
6154 synhw.minimumXCoord = SYNAPTICS_DEFAULT_MIN_X;
6155 synhw.minimumYCoord = SYNAPTICS_DEFAULT_MIN_Y;
6156 /* Enable multitouch mode for HW v8.1 devices */
6157 if (psmcpnp_sc != NULL &&
6158 psmcpnp_sc->type == PSMCPNP_HPSYN81)
6159 synhw.capReportsV = 1;
6160 } else
6161 synhw.capExtended = (status[0] & 0x80) != 0;
6162
6163 /* Set the different capabilities when they exist. */
6164 buttons = 0;
6165 if (synhw.capExtended && middle_byte == 0x47) {
6166 synhw.nExtendedQueries = (status[0] & 0x70) >> 4;
6167 synhw.capMiddle = (status[0] & 0x04) != 0;
6168 synhw.capPassthrough = (status[2] & 0x80) != 0;
6169 synhw.capLowPower = (status[2] & 0x40) != 0;
6170 synhw.capMultiFingerReport =
6171 (status[2] & 0x20) != 0;
6172 synhw.capSleep = (status[2] & 0x10) != 0;
6173 synhw.capFourButtons = (status[2] & 0x08) != 0;

--- 105 unchanged lines hidden (view full) ---

6279 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6280 return (FALSE);
6281
6282 synhw.maximumXCoord = (status[0] << 5) |
6283 ((status[1] & 0x0f) << 1);
6284 synhw.maximumYCoord = (status[2] << 5) |
6285 ((status[1] & 0xf0) >> 3);
6286 } else {
6287 synhw.maximumXCoord = SYNAPTICS_DEFAULT_MAX_X;
6288 synhw.maximumYCoord = SYNAPTICS_DEFAULT_MAX_Y;
6289 }
6290
6291 if (synhw.capReportsMin) {
6292 if (!set_mouse_scaling(kbdc, 1))
6293 return (FALSE);
6294 if (mouse_ext_command(kbdc, 0x0f) == 0)
6295 return (FALSE);
6296 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6297 return (FALSE);
6298
6299 synhw.minimumXCoord = (status[0] << 5) |
6300 ((status[1] & 0x0f) << 1);
6301 synhw.minimumYCoord = (status[2] << 5) |
6302 ((status[1] & 0xf0) >> 3);
6303 } else {
6304 synhw.minimumXCoord = SYNAPTICS_DEFAULT_MIN_X;
6305 synhw.minimumYCoord = SYNAPTICS_DEFAULT_MIN_Y;
6306 }
6307
6308 /*
6309 * ClickPad properties are not exported through PS/2
6310 * protocol. Detection is based on controller's PnP ID.
6311 */
6312 if (synhw.capClickPad && psmcpnp_sc != NULL) {
6313 switch (psmcpnp_sc->type) {

--- 69 unchanged lines hidden (view full) ---

6383 * XXX: Note the Synaptics documentation also defines the first
6384 * byte of the response to this query to be a constant 0x3b, this
6385 * does not appear to be true for Touchpads with guest devices.
6386 */
6387 if (mouse_ext_command(kbdc, 1) == 0)
6388 return (FALSE);
6389 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6390 return (FALSE);
6391 if (!SYNAPTICS_VERSION_GE(synhw, 7, 5) && status[1] != middle_byte) {
6392 printf(" Failed to read mode byte\n");
6393 return (FALSE);
6394 }
6395
6396 if (arg == PROBE)
6397 sc->synhw = synhw;
6398 if (!synaptics_support)
6399 return (FALSE);

--- 806 unchanged lines hidden (view full) ---

7206
7207/* _HID list for quirk detection. Any device below has _CID from psmcpnp_ids */
7208static struct isa_pnp_id forcepad_ids[] = {
7209 { 0x0d302e4f, "HP PS/2 forcepad port" }, /* SYN300D, EB 1040 */
7210 { 0x14302e4f, "HP PS/2 forcepad port" }, /* SYN3014, EB 1040 */
7211 { 0 }
7212};
7213
7214/* List of HW v8.1 synaptics touchpads erroneously detected as HW v2.0 */
7215static struct isa_pnp_id hpsyn81_ids[] = {
7216 { 0x9e012e4f, "HP PS/2 trackpad port" }, /* SYN019E, EB 9470 */
7217 { 0 }
7218};
7219
7220static int
7221create_a_copy(device_t atkbdc, device_t me)
7222{
7223 device_t psm;
7224 u_long irq;
7225
7226 /* find the PS/2 mouse device instance under the keyboard controller */
7227 psm = device_find_child(atkbdc, PSM_DRIVER_NAME,

--- 17 unchanged lines hidden (view full) ---

7245{
7246 struct psmcpnp_softc *sc = device_get_softc(dev);
7247 struct resource *res;
7248 u_long irq;
7249 int rid;
7250
7251 if (ISA_PNP_PROBE(device_get_parent(dev), dev, forcepad_ids) == 0)
7252 sc->type = PSMCPNP_FORCEPAD;
7253 else if(ISA_PNP_PROBE(device_get_parent(dev), dev, hpsyn81_ids) == 0)
7254 sc->type = PSMCPNP_HPSYN81;
7255 else if (ISA_PNP_PROBE(device_get_parent(dev), dev, psmcpnp_ids) == 0)
7256 sc->type = PSMCPNP_GENERIC;
7257 else
7258 return (ENXIO);
7259
7260 /*
7261 * The PnP BIOS and ACPI are supposed to assign an IRQ (12)
7262 * to the PS/2 mouse device node. But, some buggy PnP BIOS

--- 42 unchanged lines hidden ---