10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 56990Sgd78059 * Common Development and Distribution License (the "License"). 66990Sgd78059 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*9840Sgdamore@opensolaris.org * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 270Sstevel@tonic-gate * 2/3/5 Button PS/2 Mouse Protocol 280Sstevel@tonic-gate * 290Sstevel@tonic-gate * This module dynamically determines the number of buttons on the mouse. 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/param.h> 330Sstevel@tonic-gate #include <sys/stream.h> 340Sstevel@tonic-gate #include <sys/vuid_event.h> 35*9840Sgdamore@opensolaris.org #include "vuidmice.h" 360Sstevel@tonic-gate #include <sys/vuid_wheel.h> 370Sstevel@tonic-gate #include <sys/mouse.h> 386990Sgd78059 #include <sys/strsun.h> 390Sstevel@tonic-gate #include <sys/ddi.h> 400Sstevel@tonic-gate #include <sys/sunddi.h> 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * BUT(1) LEFT BUTTON 440Sstevel@tonic-gate * BUT(2) MIDDLE BUTTON (if present) 450Sstevel@tonic-gate * BUT(3) RIGHT BUTTON 460Sstevel@tonic-gate */ 470Sstevel@tonic-gate 480Sstevel@tonic-gate #define PS2_BUTTONMASK 7 /* mask byte zero with this */ 490Sstevel@tonic-gate 500Sstevel@tonic-gate #define PS2_BUTTON_L (uchar_t)0x01 /* Left button pressed */ 510Sstevel@tonic-gate #define PS2_BUTTON_R (uchar_t)0x02 /* Right button pressed */ 520Sstevel@tonic-gate #define PS2_BUTTON_M (uchar_t)0x04 /* Middle button pressed */ 530Sstevel@tonic-gate #define PS2_DATA_XSIGN (uchar_t)0x10 /* X data sign bit */ 540Sstevel@tonic-gate #define PS2_DATA_YSIGN (uchar_t)0x20 /* Y data sign bit */ 550Sstevel@tonic-gate 560Sstevel@tonic-gate #define PS2_START 0 /* Beginning of packet */ 570Sstevel@tonic-gate #define PS2_BUTTON 1 /* Got button status */ 580Sstevel@tonic-gate #define PS2_MAYBE_REATTACH 2 /* Got button status */ 590Sstevel@tonic-gate #define PS2_DELTA_Y 3 /* Got delta X */ 600Sstevel@tonic-gate #define PS2_WHEEL_DELTA_Z 4 610Sstevel@tonic-gate #define PS2_WHEEL5_DELTA_Z 5 620Sstevel@tonic-gate #define PS2_WAIT_RESET_ACK 6 630Sstevel@tonic-gate #define PS2_WAIT_RESET_AA 7 640Sstevel@tonic-gate #define PS2_WAIT_RESET_00 8 650Sstevel@tonic-gate #define PS2_WAIT_SETRES0_ACK1 9 660Sstevel@tonic-gate #define PS2_WAIT_SETRES0_ACK2 10 /* -+ must be consecutive */ 670Sstevel@tonic-gate #define PS2_WAIT_SCALE1_1_ACK 11 /* | */ 680Sstevel@tonic-gate #define PS2_WAIT_SCALE1_2_ACK 12 /* | */ 690Sstevel@tonic-gate #define PS2_WAIT_SCALE1_3_ACK 13 /* -+ */ 700Sstevel@tonic-gate #define PS2_WAIT_STATREQ_ACK 14 710Sstevel@tonic-gate #define PS2_WAIT_STATUS_1 15 720Sstevel@tonic-gate #define PS2_WAIT_STATUS_BUTTONS 16 730Sstevel@tonic-gate #define PS2_WAIT_STATUS_REV 17 740Sstevel@tonic-gate #define PS2_WAIT_STATUS_3 18 750Sstevel@tonic-gate #define PS2_WAIT_WHEEL_SMPL1_CMD_ACK 19 /* Set the sample rate to 200 */ 760Sstevel@tonic-gate #define PS2_WAIT_WHEEL_SMPL1_RATE_ACK 20 770Sstevel@tonic-gate #define PS2_WAIT_WHEEL_SMPL2_CMD_ACK 21 /* Set the sample rate to 200 */ 780Sstevel@tonic-gate #define PS2_WAIT_WHEEL_SMPL2_RATE_ACK 22 790Sstevel@tonic-gate #define PS2_WAIT_WHEEL_SMPL3_CMD_ACK 23 /* Set the sample rate to 80 */ 800Sstevel@tonic-gate #define PS2_WAIT_WHEEL_SMPL3_RATE_ACK 24 810Sstevel@tonic-gate #define PS2_WAIT_WHEEL_DEV_CMD 25 820Sstevel@tonic-gate #define PS2_WAIT_WHEEL_DEV_ACK 26 /* Detected wheel mouse */ 830Sstevel@tonic-gate #define PS2_WAIT_WHEEL5_SMPL1_CMD_ACK 27 /* Set the sample rate to 200 */ 840Sstevel@tonic-gate #define PS2_WAIT_WHEEL5_SMPL1_RATE_ACK 28 850Sstevel@tonic-gate #define PS2_WAIT_WHEEL5_SMPL2_CMD_ACK 29 /* Set the sample rate to 200 */ 860Sstevel@tonic-gate #define PS2_WAIT_WHEEL5_SMPL2_RATE_ACK 30 870Sstevel@tonic-gate #define PS2_WAIT_WHEEL5_SMPL3_CMD_ACK 31 /* Set the sample rate to 100 */ 880Sstevel@tonic-gate #define PS2_WAIT_WHEEL5_SMPL3_RATE_ACK 32 890Sstevel@tonic-gate #define PS2_WAIT_WHEEL5_DEV_CMD 33 900Sstevel@tonic-gate #define PS2_WAIT_WHEEL5_DEV_ACK 34 /* Detected 5 button mouse */ 910Sstevel@tonic-gate #define PS2_WAIT_SETRES3_CMD 35 920Sstevel@tonic-gate #define PS2_WAIT_SETRES3_ACK1 36 930Sstevel@tonic-gate #define PS2_WAIT_SETRES3_ACK2 37 940Sstevel@tonic-gate #define PS2_WAIT_STREAM_ACK 38 950Sstevel@tonic-gate #define PS2_WAIT_ON_ACK 39 960Sstevel@tonic-gate 970Sstevel@tonic-gate #define MSE_AA 0xaa 980Sstevel@tonic-gate #define MSE_00 0x00 990Sstevel@tonic-gate 1000Sstevel@tonic-gate #define MOUSE_MODE_PLAIN 0 /* Normal PS/2 mouse - 3 byte msgs */ 1010Sstevel@tonic-gate #define MOUSE_MODE_WHEEL 1 /* Wheel mouse - 4 byte msgs */ 1020Sstevel@tonic-gate #define MOUSE_MODE_WHEEL5 2 /* Wheel + 5 btn mouse - 4 byte msgs */ 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate #define PS2_FLAG_NO_EXTN 0x08 /* Mouse doesn't obey extended cmds */ 1050Sstevel@tonic-gate #define PS2_FLAG_INIT_DONE 0x01 /* Mouse has been inited successfully */ 1060Sstevel@tonic-gate #define PS2_FLAG_INIT_TIMEOUT 0x02 /* Mouse init timeout */ 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * The RESET command takes more time 1100Sstevel@tonic-gate * before the PS/2 mouse is ready 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate #define PS2_INIT_TMOUT_RESET 500000 /* 500ms for RESET command */ 1130Sstevel@tonic-gate #define PS2_INIT_TMOUT_PER_CMD 200000 /* 200ms for each command-response */ 114993Slq150181 #define PS2_INIT_TMOUT_PER_GROUP 500000 /* 500ms for group commands */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate #define PS2_MAX_INIT_COUNT 5 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate static void vuidmice_send_wheel_event(queue_t *const, uchar_t, 1200Sstevel@tonic-gate uchar_t, uchar_t, int); 1210Sstevel@tonic-gate extern void VUID_PUTNEXT(queue_t *const, uchar_t, uchar_t, uchar_t, int); 1220Sstevel@tonic-gate extern void uniqtime32(struct timeval32 *); 1230Sstevel@tonic-gate static void VUID_INIT_TIMEOUT(void *q); 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* 1260Sstevel@tonic-gate * We apply timeout to nearly each command-response 1270Sstevel@tonic-gate * during initialization: 1280Sstevel@tonic-gate * 1290Sstevel@tonic-gate * Set timeout for RESET 1300Sstevel@tonic-gate * Set timeout for SET RESOLUTION 1310Sstevel@tonic-gate * Set timeout for SET SCALE 1320Sstevel@tonic-gate * Set timeout for SET SAMPLE RATE 1330Sstevel@tonic-gate * Set timeout for STATUS REQUEST 1340Sstevel@tonic-gate * Set timeout for GET DEV 1350Sstevel@tonic-gate * Set timeout for SET STREAM MODE and ENABLE. 1360Sstevel@tonic-gate * 1370Sstevel@tonic-gate * But for simplicity, sometimes we just apply the timeout 138993Slq150181 * to a function with group commands (e.g. wheel-mouse detection). 1390Sstevel@tonic-gate * 1400Sstevel@tonic-gate */ 1410Sstevel@tonic-gate static void 1420Sstevel@tonic-gate vuid_set_timeout(queue_t *const qp, clock_t time) 1430Sstevel@tonic-gate { 1440Sstevel@tonic-gate ASSERT(STATEP->init_tid == 0); 1450Sstevel@tonic-gate STATEP->init_tid = qtimeout(qp, VUID_INIT_TIMEOUT, 1460Sstevel@tonic-gate qp, drv_usectohz(time)); 1470Sstevel@tonic-gate } 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate static void 1500Sstevel@tonic-gate vuid_cancel_timeout(queue_t *const qp) 1510Sstevel@tonic-gate { 1520Sstevel@tonic-gate ASSERT(STATEP->init_tid != 0); 1530Sstevel@tonic-gate (void) quntimeout(qp, STATEP->init_tid); 1540Sstevel@tonic-gate STATEP->init_tid = 0; 1550Sstevel@tonic-gate } 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* 1580Sstevel@tonic-gate * vuidmice_send_wheel_event 1590Sstevel@tonic-gate * Convert wheel data to firm_events 1600Sstevel@tonic-gate */ 1610Sstevel@tonic-gate static void 1620Sstevel@tonic-gate vuidmice_send_wheel_event(queue_t *const qp, uchar_t event_id, 1630Sstevel@tonic-gate uchar_t event_pair_type, uchar_t event_pair, int event_value) 1640Sstevel@tonic-gate { 1650Sstevel@tonic-gate mblk_t *bp; 1660Sstevel@tonic-gate Firm_event *fep; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate if ((bp = allocb((int)sizeof (Firm_event), BPRI_HI)) == NULL) { 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate return; 1710Sstevel@tonic-gate } 1720Sstevel@tonic-gate 1736990Sgd78059 fep = (void *)bp->b_wptr; 1740Sstevel@tonic-gate fep->id = vuid_id_addr(vuid_first(VUID_WHEEL)) | 1750Sstevel@tonic-gate vuid_id_offset(event_id); 1760Sstevel@tonic-gate fep->pair_type = event_pair_type; 1770Sstevel@tonic-gate fep->pair = event_pair; 1780Sstevel@tonic-gate fep->value = event_value; 1790Sstevel@tonic-gate uniqtime32(&fep->time); 1800Sstevel@tonic-gate bp->b_wptr += sizeof (Firm_event); 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate if (canput(qp->q_next)) { 1830Sstevel@tonic-gate putnext(qp, bp); 1840Sstevel@tonic-gate } else { 1850Sstevel@tonic-gate (void) putbq(qp, bp); /* read side is blocked */ 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate } 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate static void 1910Sstevel@tonic-gate sendButtonEvent(queue_t *const qp) 1920Sstevel@tonic-gate { 1930Sstevel@tonic-gate static int bmap[3] = {1, 3, 2}; 1940Sstevel@tonic-gate uint_t b; 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate /* for each button, see if it has changed */ 1970Sstevel@tonic-gate for (b = 0; b < STATEP->nbuttons; b++) { 1980Sstevel@tonic-gate uchar_t mask = 0x1 << b; 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate if ((STATEP->buttons & mask) != (STATEP->oldbuttons & mask)) 2010Sstevel@tonic-gate VUID_PUTNEXT(qp, (uchar_t)BUT(bmap[b]), FE_PAIR_NONE, 0, 2026990Sgd78059 (STATEP->buttons & mask ? 1 : 0)); 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate } 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate void 2070Sstevel@tonic-gate put1(queue_t *const qp, int c) 2080Sstevel@tonic-gate { 2090Sstevel@tonic-gate mblk_t *bp; 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate if (bp = allocb(1, BPRI_MED)) { 2120Sstevel@tonic-gate *bp->b_wptr++ = (char)c; 2130Sstevel@tonic-gate putnext(qp, bp); 2140Sstevel@tonic-gate } 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate int 2180Sstevel@tonic-gate VUID_OPEN(queue_t *const qp) 2190Sstevel@tonic-gate { 2200Sstevel@tonic-gate STATEP->format = VUID_FIRM_EVENT; 2210Sstevel@tonic-gate STATEP->vuid_mouse_mode = MOUSE_MODE_PLAIN; 2220Sstevel@tonic-gate STATEP->inited = 0; 2230Sstevel@tonic-gate STATEP->nbuttons = 3; 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate STATEP->state = PS2_WAIT_RESET_ACK; 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate /* Set timeout for reset */ 2280Sstevel@tonic-gate vuid_set_timeout(qp, PS2_INIT_TMOUT_RESET); 2290Sstevel@tonic-gate 230993Slq150181 put1(WR(qp), MSERESET); 231993Slq150181 2320Sstevel@tonic-gate while ((STATEP->state != PS2_START) && 2330Sstevel@tonic-gate !(STATEP->inited & PS2_FLAG_INIT_TIMEOUT)) { 2340Sstevel@tonic-gate if (qwait_sig(qp) == 0) 2350Sstevel@tonic-gate break; 2360Sstevel@tonic-gate } 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate /* 2390Sstevel@tonic-gate * Later the PS/2 mouse maybe re-attach, so here 2400Sstevel@tonic-gate * clear the init_count. 2410Sstevel@tonic-gate */ 2420Sstevel@tonic-gate STATEP->init_count = 0; 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate return (0); 2450Sstevel@tonic-gate } 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate void 2480Sstevel@tonic-gate VUID_CLOSE(queue_t *const qp) 2490Sstevel@tonic-gate { 2500Sstevel@tonic-gate if (STATEP->init_tid != 0) 2510Sstevel@tonic-gate vuid_cancel_timeout(qp); 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate static void 2550Sstevel@tonic-gate VUID_INIT_TIMEOUT(void *q) 2560Sstevel@tonic-gate { 2570Sstevel@tonic-gate queue_t *qp = q; 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate STATEP->init_tid = 0; 2600Sstevel@tonic-gate 261822Ssethg /* 262822Ssethg * Some mice do not even send an error in response to 263822Ssethg * the wheel mouse sample commands, so if we're in any of 264822Ssethg * the PS2_WAIT_WHEEL_SMPL* states, and there has been 265822Ssethg * a timeout, assume the mouse cannot handle the extended 266822Ssethg * (wheel mouse) commands. 267822Ssethg */ 268822Ssethg if ((STATEP->state == PS2_WAIT_WHEEL_SMPL1_CMD_ACK) || 269822Ssethg (STATEP->state == PS2_WAIT_WHEEL_SMPL1_RATE_ACK) || 2700Sstevel@tonic-gate (STATEP->state == PS2_WAIT_WHEEL_SMPL2_RATE_ACK) || 2710Sstevel@tonic-gate (STATEP->state == PS2_WAIT_WHEEL_SMPL3_RATE_ACK)) { 2720Sstevel@tonic-gate /* 2730Sstevel@tonic-gate * We overload 'inited' to mark the PS/2 mouse 2740Sstevel@tonic-gate * as one which doesn't respond to extended commands. 2750Sstevel@tonic-gate */ 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate STATEP->inited |= PS2_FLAG_NO_EXTN; 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate if (++STATEP->init_count >= PS2_MAX_INIT_COUNT) { 2810Sstevel@tonic-gate STATEP->inited |= PS2_FLAG_INIT_TIMEOUT; 2820Sstevel@tonic-gate return; 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate STATEP->state = PS2_WAIT_RESET_ACK; 2870Sstevel@tonic-gate 288993Slq150181 vuid_set_timeout(qp, PS2_INIT_TMOUT_RESET); 289993Slq150181 2900Sstevel@tonic-gate /* try again */ 2910Sstevel@tonic-gate put1(WR(qp), MSERESET); 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate void 2950Sstevel@tonic-gate VUID_QUEUE(queue_t *const qp, mblk_t *mp) 2960Sstevel@tonic-gate { 2970Sstevel@tonic-gate int code; 2980Sstevel@tonic-gate clock_t now; 2990Sstevel@tonic-gate clock_t elapsed; 3000Sstevel@tonic-gate clock_t mouse_timeout; 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate mouse_timeout = drv_usectohz(250000); 3030Sstevel@tonic-gate now = ddi_get_lbolt(); 3040Sstevel@tonic-gate elapsed = now - STATEP->last_event_lbolt; 3050Sstevel@tonic-gate STATEP->last_event_lbolt = now; 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate while (mp->b_rptr < mp->b_wptr) { 3080Sstevel@tonic-gate code = *mp->b_rptr++; 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate switch (STATEP->state) { 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate /* 3130Sstevel@tonic-gate * Start state. We stay here if the start code is not 3140Sstevel@tonic-gate * received thus forcing us back into sync. When we get a 3150Sstevel@tonic-gate * start code the button mask comes with it forcing us to 3160Sstevel@tonic-gate * to the next state. 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate restart: 3190Sstevel@tonic-gate case PS2_START: 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate /* 3220Sstevel@tonic-gate * 3-byte packet format 3230Sstevel@tonic-gate * 3240Sstevel@tonic-gate * Bit 7 6 5 4 3 2 1 0 3250Sstevel@tonic-gate * Byte ---- ---- ----- ----- -- ------ ------ ------ 3260Sstevel@tonic-gate * 1 Y_Ov X_Ov Y_Sgn X_Sgn 1 MdlBtn RgtBtn LftBtn 3270Sstevel@tonic-gate * 2 |<--------------X Movement----------------->| 3280Sstevel@tonic-gate * 3 |<--------------Y Movement----------------->| 3290Sstevel@tonic-gate * 3300Sstevel@tonic-gate * 4-byte wheel packet format 3310Sstevel@tonic-gate * 3320Sstevel@tonic-gate * Bit 7 6 5 4 3 2 1 0 3330Sstevel@tonic-gate * Byte ---- ---- ----- ----- -- ------ ------ ------ 3340Sstevel@tonic-gate * 1 Y_Ov X_Ov Y_Sgn X_Sgn 1 MdlBtn RgtBtn LftBtn 3350Sstevel@tonic-gate * 2 |<--------------X Movement----------------->| 3360Sstevel@tonic-gate * 3 |<--------------Y Movement----------------->| 3370Sstevel@tonic-gate * 4 |<--------------Z Movement----------------->| 3380Sstevel@tonic-gate * 3390Sstevel@tonic-gate * 4-byte wheel+5 packet format 3400Sstevel@tonic-gate * 3410Sstevel@tonic-gate * Bit 7 6 5 4 3 2 1 0 3420Sstevel@tonic-gate * Byte ---- ---- ----- ----- -- ------ ------ ------ 3430Sstevel@tonic-gate * 1 Y_Ov X_Ov Y_Sgn X_Sgn 1 MdlBtn RgtBtn LftBtn 3440Sstevel@tonic-gate * 2 |<--------------X Movement----------------->| 3450Sstevel@tonic-gate * 3 |<--------------Y Movement----------------->| 3460Sstevel@tonic-gate * 4 0 0 5_Btn 4_Btn Z3 Z2 Z1 Z0 3470Sstevel@tonic-gate */ 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate if (!(STATEP->inited & PS2_FLAG_INIT_DONE)) { 3500Sstevel@tonic-gate STATEP->sync_byte = code & 0x8; 3510Sstevel@tonic-gate STATEP->inited |= PS2_FLAG_INIT_DONE; 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate /* 3540Sstevel@tonic-gate * the PS/2 mouse data format doesn't have any sort of sync 3550Sstevel@tonic-gate * data to make sure we are in sync with the packet stream, 3560Sstevel@tonic-gate * but the Technical Reference manual states that bits 2 & 3 3570Sstevel@tonic-gate * of the first byte are reserved. Logitech uses bit 2 for 3580Sstevel@tonic-gate * the middle button. We HOPE that noone uses bit 3 though, 3590Sstevel@tonic-gate * and decide we're out of sync if bit 3 is not set here. 3600Sstevel@tonic-gate */ 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate if ((code ^ STATEP->sync_byte) & 0x08) { 3630Sstevel@tonic-gate /* bit 3 not set */ 3640Sstevel@tonic-gate STATEP->state = PS2_START; 3650Sstevel@tonic-gate break; /* toss the code */ 3660Sstevel@tonic-gate } 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate /* get the button values */ 3690Sstevel@tonic-gate STATEP->buttons = code & PS2_BUTTONMASK; 3700Sstevel@tonic-gate if (STATEP->buttons != STATEP->oldbuttons) { 3710Sstevel@tonic-gate sendButtonEvent(qp); 3720Sstevel@tonic-gate STATEP->oldbuttons = STATEP->buttons; 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate /* bit 5 indicates Y value is negative (the sign bit) */ 3760Sstevel@tonic-gate if (code & PS2_DATA_YSIGN) 3770Sstevel@tonic-gate STATEP->deltay = -1 & ~0xff; 3780Sstevel@tonic-gate else 3790Sstevel@tonic-gate STATEP->deltay = 0; 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate /* bit 4 is X sign bit */ 3820Sstevel@tonic-gate if (code & PS2_DATA_XSIGN) 3830Sstevel@tonic-gate STATEP->deltax = -1 & ~0xff; 3840Sstevel@tonic-gate else 3850Sstevel@tonic-gate STATEP->deltax = 0; 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate if (code == MSE_AA) 3880Sstevel@tonic-gate STATEP->state = PS2_MAYBE_REATTACH; 3890Sstevel@tonic-gate else 3900Sstevel@tonic-gate STATEP->state = PS2_BUTTON; 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate break; 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate case PS2_MAYBE_REATTACH: 3950Sstevel@tonic-gate if (code == MSE_00) { 3960Sstevel@tonic-gate STATEP->state = PS2_WAIT_RESET_ACK; 3970Sstevel@tonic-gate vuid_set_timeout(qp, PS2_INIT_TMOUT_RESET); 398993Slq150181 put1(WR(qp), MSERESET); 3990Sstevel@tonic-gate break; 4000Sstevel@tonic-gate } 4010Sstevel@tonic-gate /*FALLTHROUGH*/ 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate case PS2_BUTTON: 4040Sstevel@tonic-gate /* 4050Sstevel@tonic-gate * Now for the 7 bits of delta x. "Or" in 4060Sstevel@tonic-gate * the sign bit and continue. This is ac- 4070Sstevel@tonic-gate * tually a signed 9 bit number, but I just 4080Sstevel@tonic-gate * truncate it to a signed char in order to 4090Sstevel@tonic-gate * avoid changing and retesting all of the 4100Sstevel@tonic-gate * mouse-related modules for this patch. 4110Sstevel@tonic-gate */ 4120Sstevel@tonic-gate if (elapsed > mouse_timeout) 4130Sstevel@tonic-gate goto restart; 4140Sstevel@tonic-gate STATEP->deltax |= code & 0xff; 4150Sstevel@tonic-gate STATEP->state = PS2_DELTA_Y; 4160Sstevel@tonic-gate break; 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate case PS2_DELTA_Y: 4190Sstevel@tonic-gate /* 4200Sstevel@tonic-gate * This byte is delta Y. If this is a plain mouse, 4210Sstevel@tonic-gate * we're done. Wheel mice have two different flavors 4220Sstevel@tonic-gate * of fourth byte. 4230Sstevel@tonic-gate */ 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate if (elapsed > mouse_timeout) { 4260Sstevel@tonic-gate goto restart; 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate STATEP->deltay |= code & 0xff; 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate if (STATEP->vuid_mouse_mode == MOUSE_MODE_WHEEL) { 4310Sstevel@tonic-gate STATEP->state = PS2_WHEEL_DELTA_Z; 4320Sstevel@tonic-gate break; 4330Sstevel@tonic-gate } else if (STATEP->vuid_mouse_mode == 4340Sstevel@tonic-gate MOUSE_MODE_WHEEL5) { 4350Sstevel@tonic-gate STATEP->state = PS2_WHEEL5_DELTA_Z; 4360Sstevel@tonic-gate break; 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate goto packet_complete; 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate case PS2_WHEEL5_DELTA_Z: 4410Sstevel@tonic-gate if (code & 0x10) { 4420Sstevel@tonic-gate /* fourth physical button */ 4430Sstevel@tonic-gate VUID_PUTNEXT(qp, (uchar_t)BUT(4), 4440Sstevel@tonic-gate FE_PAIR_NONE, 0, 1); 4450Sstevel@tonic-gate VUID_PUTNEXT(qp, (uchar_t)BUT(4), 4460Sstevel@tonic-gate FE_PAIR_NONE, 0, 0); 4470Sstevel@tonic-gate } else if (code & 0x20) { 4480Sstevel@tonic-gate /* fifth physical button */ 4490Sstevel@tonic-gate VUID_PUTNEXT(qp, (uchar_t)BUT(5), 4500Sstevel@tonic-gate FE_PAIR_NONE, 0, 1); 4510Sstevel@tonic-gate VUID_PUTNEXT(qp, (uchar_t)BUT(5), 4520Sstevel@tonic-gate FE_PAIR_NONE, 0, 0); 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate /*FALLTHROUGH*/ 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate case PS2_WHEEL_DELTA_Z: 4570Sstevel@tonic-gate /* 4580Sstevel@tonic-gate * Check whether reporting vertical wheel 4590Sstevel@tonic-gate * movements is enabled 4600Sstevel@tonic-gate */ 4610Sstevel@tonic-gate code &= 0xf; 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate if (STATEP->wheel_state_bf & (1 << 4646990Sgd78059 VUIDMICE_VERTICAL_WHEEL_ID)) { 4650Sstevel@tonic-gate /* 4660Sstevel@tonic-gate * PS/2 mouse reports -ve values 4670Sstevel@tonic-gate * when the wheel is scrolled up. So 4680Sstevel@tonic-gate * we need to convert it into +ve as 4690Sstevel@tonic-gate * X interprets a +ve value as wheel up event. 4700Sstevel@tonic-gate * Same is true for the horizontal wheel also. 4710Sstevel@tonic-gate * The mouse reports 0xf when scrolled up 4720Sstevel@tonic-gate * and 0x1 when scrolled down. This observation 4730Sstevel@tonic-gate * is based on Logitech, HCL, 4740Sstevel@tonic-gate * Microsoft and Black Cat mouse only 4750Sstevel@tonic-gate */ 4760Sstevel@tonic-gate if (code == 0xf) { 4770Sstevel@tonic-gate /* negative Z - wheel up */ 4780Sstevel@tonic-gate code |= 0xfffffff0; 4790Sstevel@tonic-gate vuidmice_send_wheel_event(qp, 0, 4800Sstevel@tonic-gate FE_PAIR_NONE, 0, -code); 4810Sstevel@tonic-gate } else if (code == 0x01) { 4820Sstevel@tonic-gate /* positive Z - wheel down */ 4830Sstevel@tonic-gate vuidmice_send_wheel_event(qp, 0, 4840Sstevel@tonic-gate FE_PAIR_NONE, 0, -code); 4850Sstevel@tonic-gate } 4860Sstevel@tonic-gate } 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate /* 4890Sstevel@tonic-gate * Check whether reporting horizontal wheel 4900Sstevel@tonic-gate * movements is enabled 4910Sstevel@tonic-gate */ 4920Sstevel@tonic-gate if (STATEP->wheel_state_bf & 4930Sstevel@tonic-gate (1 << VUIDMICE_HORIZONTAL_WHEEL_ID)) { 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate /* 4960Sstevel@tonic-gate * The mouse return -7 and +7 when it 4970Sstevel@tonic-gate * is scrolled horizontally 4980Sstevel@tonic-gate */ 4990Sstevel@tonic-gate if (code == 0x09) { 5000Sstevel@tonic-gate /* negative Z - wheel left */ 5010Sstevel@tonic-gate vuidmice_send_wheel_event(qp, 1, 5020Sstevel@tonic-gate FE_PAIR_NONE, 0, 1); 5030Sstevel@tonic-gate } else if (code == 0x07) { 5040Sstevel@tonic-gate /* positive Z - wheel right */ 5050Sstevel@tonic-gate vuidmice_send_wheel_event(qp, 1, 5060Sstevel@tonic-gate FE_PAIR_NONE, 0, -1); 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate } 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate packet_complete: 5110Sstevel@tonic-gate STATEP->state = PS2_START; 5120Sstevel@tonic-gate /* 5130Sstevel@tonic-gate * If we can peek at the next mouse character, and 5140Sstevel@tonic-gate * its not the start of the next packet, don't use 5150Sstevel@tonic-gate * this packet. 5160Sstevel@tonic-gate */ 5176990Sgd78059 if (mp->b_wptr > mp->b_rptr && 5180Sstevel@tonic-gate ((mp->b_rptr[0] ^ STATEP->sync_byte) & 0x08)) { 5190Sstevel@tonic-gate /* 5200Sstevel@tonic-gate * bit 3 not set 5210Sstevel@tonic-gate */ 5220Sstevel@tonic-gate break; 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate /* 5260Sstevel@tonic-gate * send the info to the next level -- 5270Sstevel@tonic-gate * need to send multiple events if we have both 5280Sstevel@tonic-gate * a delta *AND* button event(s) 5290Sstevel@tonic-gate */ 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate /* motion has occurred ... */ 5320Sstevel@tonic-gate if (STATEP->deltax) 5330Sstevel@tonic-gate VUID_PUTNEXT(qp, (uchar_t)LOC_X_DELTA, 5340Sstevel@tonic-gate FE_PAIR_ABSOLUTE, (uchar_t)LOC_X_ABSOLUTE, 5350Sstevel@tonic-gate STATEP->deltax); 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate if (STATEP->deltay) 5380Sstevel@tonic-gate VUID_PUTNEXT(qp, (uchar_t)LOC_Y_DELTA, 5390Sstevel@tonic-gate FE_PAIR_ABSOLUTE, (uchar_t)LOC_Y_ABSOLUTE, 5400Sstevel@tonic-gate STATEP->deltay); 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate STATEP->deltax = STATEP->deltay = 0; 5430Sstevel@tonic-gate break; 5440Sstevel@tonic-gate 5450Sstevel@tonic-gate case PS2_WAIT_RESET_ACK: 5460Sstevel@tonic-gate if (code != MSE_ACK) { 5470Sstevel@tonic-gate break; 5480Sstevel@tonic-gate } 549993Slq150181 550993Slq150181 /* 551993Slq150181 * On Dell latitude D800, we find that the MSE_ACK is 552993Slq150181 * coming up even after timeout in VUID_OPEN during 553993Slq150181 * early boot. So here (PS2_WAIT_RESET_ACK) we check 554993Slq150181 * if timeout happened before, if true, we reset the 555993Slq150181 * timeout to restart the initialization. 556993Slq150181 */ 557993Slq150181 if (STATEP->inited & PS2_FLAG_INIT_TIMEOUT) { 558993Slq150181 STATEP->inited &= ~PS2_FLAG_INIT_TIMEOUT; 559993Slq150181 vuid_set_timeout(qp, PS2_INIT_TMOUT_RESET); 560993Slq150181 } 561993Slq150181 5620Sstevel@tonic-gate STATEP->state = PS2_WAIT_RESET_AA; 5630Sstevel@tonic-gate break; 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate case PS2_WAIT_RESET_AA: 5660Sstevel@tonic-gate if (code != MSE_AA) { 5670Sstevel@tonic-gate break; 5680Sstevel@tonic-gate } 5690Sstevel@tonic-gate STATEP->state = PS2_WAIT_RESET_00; 5700Sstevel@tonic-gate break; 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate case PS2_WAIT_RESET_00: 5730Sstevel@tonic-gate if (code != MSE_00) { 5740Sstevel@tonic-gate break; 5750Sstevel@tonic-gate } 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate /* Reset has been ok */ 5780Sstevel@tonic-gate vuid_cancel_timeout(qp); 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate STATEP->state = PS2_WAIT_SETRES0_ACK1; 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate /* Set timeout for set res */ 583993Slq150181 vuid_set_timeout(qp, PS2_INIT_TMOUT_PER_GROUP); 5840Sstevel@tonic-gate 585993Slq150181 put1(WR(qp), MSESETRES); 5860Sstevel@tonic-gate break; 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate case PS2_WAIT_SETRES0_ACK1: 5890Sstevel@tonic-gate if (code != MSE_ACK) { 5900Sstevel@tonic-gate break; 5910Sstevel@tonic-gate } 592993Slq150181 STATEP->state = PS2_WAIT_SETRES0_ACK2; 5930Sstevel@tonic-gate put1(WR(qp), 0); 5940Sstevel@tonic-gate break; 5950Sstevel@tonic-gate 5960Sstevel@tonic-gate case PS2_WAIT_SETRES0_ACK2: 5970Sstevel@tonic-gate case PS2_WAIT_SCALE1_1_ACK: 5980Sstevel@tonic-gate case PS2_WAIT_SCALE1_2_ACK: 5990Sstevel@tonic-gate if (code != MSE_ACK) { 6000Sstevel@tonic-gate break; 6010Sstevel@tonic-gate } 602993Slq150181 STATEP->state++; 6030Sstevel@tonic-gate put1(WR(qp), MSESCALE1); 6040Sstevel@tonic-gate break; 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate case PS2_WAIT_SCALE1_3_ACK: 6070Sstevel@tonic-gate if (code != MSE_ACK) { 6080Sstevel@tonic-gate break; 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate /* Set res and scale have been ok */ 6120Sstevel@tonic-gate vuid_cancel_timeout(qp); 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate STATEP->state = PS2_WAIT_STATREQ_ACK; 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate /* Set timeout for status request */ 617993Slq150181 vuid_set_timeout(qp, PS2_INIT_TMOUT_PER_GROUP); 618993Slq150181 619993Slq150181 put1(WR(qp), MSESTATREQ); 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate break; 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate case PS2_WAIT_STATREQ_ACK: 6240Sstevel@tonic-gate if (code != MSE_ACK) { 6250Sstevel@tonic-gate break; 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate STATEP->state = PS2_WAIT_STATUS_1; 6280Sstevel@tonic-gate break; 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate case PS2_WAIT_STATUS_1: 6310Sstevel@tonic-gate STATEP->state = PS2_WAIT_STATUS_BUTTONS; 6320Sstevel@tonic-gate break; 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate case PS2_WAIT_STATUS_BUTTONS: 6350Sstevel@tonic-gate if (code != 0) { 6360Sstevel@tonic-gate STATEP->nbuttons = (uchar_t)code; 6370Sstevel@tonic-gate STATEP->state = (uchar_t)PS2_WAIT_STATUS_REV; 6380Sstevel@tonic-gate } else { 6390Sstevel@tonic-gate #if defined(VUID3PS2) 6400Sstevel@tonic-gate /* 6410Sstevel@tonic-gate * It seems that there are some 3-button mice 6420Sstevel@tonic-gate * that don't play the Logitech autodetect 6430Sstevel@tonic-gate * game. One is a Mouse Systems mouse OEM'ed 6440Sstevel@tonic-gate * by Intergraph. 6450Sstevel@tonic-gate * 6460Sstevel@tonic-gate * Until we find out how to autodetect these 6470Sstevel@tonic-gate * mice, we'll assume that if we're being 6480Sstevel@tonic-gate * compiled as vuid3ps2 and the mouse doesn't 6490Sstevel@tonic-gate * play the autodetect game, it's a 3-button 6500Sstevel@tonic-gate * mouse. This effectively disables 6510Sstevel@tonic-gate * autodetect for mice using vuid3ps2, but 6520Sstevel@tonic-gate * since vuid3ps2 is used only on x86 where 6530Sstevel@tonic-gate * we currently assume manual configuration, 6540Sstevel@tonic-gate * this shouldn't be a problem. At some point 6550Sstevel@tonic-gate * in the future when we *do* start using 6560Sstevel@tonic-gate * autodetect on x86, we should probably define 6570Sstevel@tonic-gate * VUIDPS2 instead of VUID3PS2. Even then, 6580Sstevel@tonic-gate * we could leave this code so that *some* 6590Sstevel@tonic-gate * mice could use autodetect and others not. 6600Sstevel@tonic-gate */ 6610Sstevel@tonic-gate STATEP->nbuttons = 3; 6620Sstevel@tonic-gate #else 6630Sstevel@tonic-gate STATEP->nbuttons = 2; 6640Sstevel@tonic-gate #endif 6650Sstevel@tonic-gate STATEP->state = PS2_WAIT_STATUS_3; 6660Sstevel@tonic-gate } 6670Sstevel@tonic-gate break; 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate case PS2_WAIT_STATUS_REV: 6700Sstevel@tonic-gate /*FALLTHROUGH*/ 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate case PS2_WAIT_STATUS_3: 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate /* Status request has been ok */ 6750Sstevel@tonic-gate vuid_cancel_timeout(qp); 6760Sstevel@tonic-gate 677993Slq150181 /* Set timeout for set res or sample rate */ 678993Slq150181 vuid_set_timeout(qp, PS2_INIT_TMOUT_PER_GROUP); 679993Slq150181 6800Sstevel@tonic-gate /* 6810Sstevel@tonic-gate * Start the wheel-mouse detection code. First, we look 6820Sstevel@tonic-gate * for standard wheel mice. If we set the sample rate 6830Sstevel@tonic-gate * to 200, 100, and then 80 and finally request the 6840Sstevel@tonic-gate * device ID, a wheel mouse will return an ID of 0x03. 6850Sstevel@tonic-gate * After that, we'll try for the wheel+5 variety. The 6860Sstevel@tonic-gate * incantation in this case is 200, 200, and 80. We'll 6870Sstevel@tonic-gate * get 0x04 back in that case. 6880Sstevel@tonic-gate */ 6890Sstevel@tonic-gate if (STATEP->inited & PS2_FLAG_NO_EXTN) { 6900Sstevel@tonic-gate STATEP->state = PS2_WAIT_SETRES3_ACK1; 6910Sstevel@tonic-gate put1(WR(qp), MSESETRES); 6920Sstevel@tonic-gate } else { 693993Slq150181 STATEP->state = PS2_WAIT_WHEEL_SMPL1_CMD_ACK; 6940Sstevel@tonic-gate put1(WR(qp), MSECHGMOD); 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate break; 6980Sstevel@tonic-gate case PS2_WAIT_WHEEL_SMPL1_CMD_ACK: 6990Sstevel@tonic-gate if (code != MSE_ACK) { 7000Sstevel@tonic-gate break; 7010Sstevel@tonic-gate } 702993Slq150181 STATEP->state = PS2_WAIT_WHEEL_SMPL1_RATE_ACK; 7030Sstevel@tonic-gate put1(WR(qp), 200); 7040Sstevel@tonic-gate break; 7050Sstevel@tonic-gate case PS2_WAIT_WHEEL_SMPL1_RATE_ACK: 7060Sstevel@tonic-gate if (code != MSE_ACK) { 7070Sstevel@tonic-gate break; 7080Sstevel@tonic-gate } 709993Slq150181 STATEP->state = PS2_WAIT_WHEEL_SMPL2_CMD_ACK; 7100Sstevel@tonic-gate put1(WR(qp), MSECHGMOD); 7110Sstevel@tonic-gate break; 7120Sstevel@tonic-gate 7130Sstevel@tonic-gate case PS2_WAIT_WHEEL_SMPL2_CMD_ACK: 7140Sstevel@tonic-gate if (code != MSE_ACK) { 7150Sstevel@tonic-gate break; 7160Sstevel@tonic-gate } 717993Slq150181 STATEP->state = PS2_WAIT_WHEEL_SMPL2_RATE_ACK; 7180Sstevel@tonic-gate put1(WR(qp), 100); 7190Sstevel@tonic-gate break; 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate case PS2_WAIT_WHEEL_SMPL2_RATE_ACK: 7220Sstevel@tonic-gate if (code != MSE_ACK) { 7230Sstevel@tonic-gate break; 7240Sstevel@tonic-gate } 725993Slq150181 STATEP->state = PS2_WAIT_WHEEL_SMPL3_CMD_ACK; 7260Sstevel@tonic-gate put1(WR(qp), MSECHGMOD); 7270Sstevel@tonic-gate break; 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate case PS2_WAIT_WHEEL_SMPL3_CMD_ACK: 7300Sstevel@tonic-gate if (code != MSE_ACK) { 7310Sstevel@tonic-gate break; 7320Sstevel@tonic-gate } 733993Slq150181 STATEP->state = PS2_WAIT_WHEEL_SMPL3_RATE_ACK; 7340Sstevel@tonic-gate put1(WR(qp), 80); 7350Sstevel@tonic-gate break; 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate case PS2_WAIT_WHEEL_SMPL3_RATE_ACK: 7380Sstevel@tonic-gate if (code != MSE_ACK) { 7390Sstevel@tonic-gate break; 7400Sstevel@tonic-gate } 7410Sstevel@tonic-gate 7420Sstevel@tonic-gate /* Set sample rate has been ok */ 7430Sstevel@tonic-gate vuid_cancel_timeout(qp); 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate STATEP->state = PS2_WAIT_WHEEL_DEV_CMD; 7460Sstevel@tonic-gate 7470Sstevel@tonic-gate /* Set timeout for get dev */ 7480Sstevel@tonic-gate vuid_set_timeout(qp, PS2_INIT_TMOUT_PER_CMD); 7490Sstevel@tonic-gate 750993Slq150181 put1(WR(qp), MSEGETDEV); 7510Sstevel@tonic-gate break; 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate case PS2_WAIT_WHEEL_DEV_CMD: 7540Sstevel@tonic-gate if (code != MSE_ACK) { 7550Sstevel@tonic-gate break; 7560Sstevel@tonic-gate } 7570Sstevel@tonic-gate STATEP->state = PS2_WAIT_WHEEL_DEV_ACK; 7580Sstevel@tonic-gate break; 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate case PS2_WAIT_WHEEL_DEV_ACK: 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate /* Get dev has been ok */ 7630Sstevel@tonic-gate vuid_cancel_timeout(qp); 7640Sstevel@tonic-gate 7650Sstevel@tonic-gate if (code != 0x03) { 7660Sstevel@tonic-gate STATEP->state = PS2_WAIT_SETRES3_ACK1; 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate /* Set timeout for set res */ 7690Sstevel@tonic-gate vuid_set_timeout(qp, PS2_INIT_TMOUT_PER_CMD); 7700Sstevel@tonic-gate 771993Slq150181 put1(WR(qp), MSESETRES); 772993Slq150181 7730Sstevel@tonic-gate break; 7740Sstevel@tonic-gate } 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate STATEP->vuid_mouse_mode = MOUSE_MODE_WHEEL; 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate /* 7790Sstevel@tonic-gate * Found wheel. By default enable the wheel. 7800Sstevel@tonic-gate */ 7810Sstevel@tonic-gate STATEP->wheel_state_bf |= VUID_WHEEL_STATE_ENABLED; 7820Sstevel@tonic-gate 7830Sstevel@tonic-gate STATEP->state = PS2_WAIT_WHEEL5_SMPL1_CMD_ACK; 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate /* Set timeout for set sample rate */ 786993Slq150181 vuid_set_timeout(qp, PS2_INIT_TMOUT_PER_GROUP); 787993Slq150181 788993Slq150181 /* We're on a roll - try for wheel+5 */ 789993Slq150181 put1(WR(qp), MSECHGMOD); 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate break; 7920Sstevel@tonic-gate 7930Sstevel@tonic-gate case PS2_WAIT_WHEEL5_SMPL1_CMD_ACK: 7940Sstevel@tonic-gate if (code != MSE_ACK) { 7950Sstevel@tonic-gate break; 7960Sstevel@tonic-gate } 797993Slq150181 STATEP->state = PS2_WAIT_WHEEL5_SMPL1_RATE_ACK; 7980Sstevel@tonic-gate put1(WR(qp), 200); 7990Sstevel@tonic-gate break; 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate case PS2_WAIT_WHEEL5_SMPL1_RATE_ACK: 8020Sstevel@tonic-gate if (code != MSE_ACK) { 8030Sstevel@tonic-gate break; 8040Sstevel@tonic-gate } 805993Slq150181 STATEP->state = PS2_WAIT_WHEEL5_SMPL2_CMD_ACK; 8060Sstevel@tonic-gate put1(WR(qp), MSECHGMOD); 8070Sstevel@tonic-gate break; 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate case PS2_WAIT_WHEEL5_SMPL2_CMD_ACK: 8100Sstevel@tonic-gate if (code != MSE_ACK) { 8110Sstevel@tonic-gate break; 8120Sstevel@tonic-gate } 813993Slq150181 STATEP->state = PS2_WAIT_WHEEL5_SMPL2_RATE_ACK; 8140Sstevel@tonic-gate put1(WR(qp), 200); 8150Sstevel@tonic-gate break; 8160Sstevel@tonic-gate 8170Sstevel@tonic-gate case PS2_WAIT_WHEEL5_SMPL2_RATE_ACK: 8180Sstevel@tonic-gate if (code != MSE_ACK) { 8190Sstevel@tonic-gate break; 8200Sstevel@tonic-gate } 821993Slq150181 STATEP->state = PS2_WAIT_WHEEL5_SMPL3_CMD_ACK; 8220Sstevel@tonic-gate put1(WR(qp), MSECHGMOD); 8230Sstevel@tonic-gate break; 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate case PS2_WAIT_WHEEL5_SMPL3_CMD_ACK: 8260Sstevel@tonic-gate if (code != MSE_ACK) { 8270Sstevel@tonic-gate break; 8280Sstevel@tonic-gate } 829993Slq150181 STATEP->state = PS2_WAIT_WHEEL5_SMPL3_RATE_ACK; 8300Sstevel@tonic-gate put1(WR(qp), 80); 8310Sstevel@tonic-gate break; 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate case PS2_WAIT_WHEEL5_SMPL3_RATE_ACK: 8340Sstevel@tonic-gate if (code != MSE_ACK) { 8350Sstevel@tonic-gate break; 8360Sstevel@tonic-gate } 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate /* Set sample rate has been ok */ 8390Sstevel@tonic-gate vuid_cancel_timeout(qp); 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate STATEP->state = PS2_WAIT_WHEEL5_DEV_CMD; 8420Sstevel@tonic-gate 8430Sstevel@tonic-gate /* Set timeout for wheel5 get dev */ 8440Sstevel@tonic-gate vuid_set_timeout(qp, PS2_INIT_TMOUT_PER_CMD); 8450Sstevel@tonic-gate 846993Slq150181 put1(WR(qp), MSEGETDEV); 847993Slq150181 8480Sstevel@tonic-gate break; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate case PS2_WAIT_WHEEL5_DEV_CMD: 8510Sstevel@tonic-gate if (code != MSE_ACK) { 8520Sstevel@tonic-gate break; 8530Sstevel@tonic-gate } 8540Sstevel@tonic-gate STATEP->state = PS2_WAIT_WHEEL5_DEV_ACK; 8550Sstevel@tonic-gate break; 8560Sstevel@tonic-gate 8570Sstevel@tonic-gate case PS2_WAIT_WHEEL5_DEV_ACK: 8580Sstevel@tonic-gate if (code == 0x04) { 8590Sstevel@tonic-gate STATEP->vuid_mouse_mode = MOUSE_MODE_WHEEL5; 8600Sstevel@tonic-gate STATEP->nbuttons = 5; 8610Sstevel@tonic-gate 8620Sstevel@tonic-gate /* 8630Sstevel@tonic-gate * Found wheel. By default enable the wheel. 8640Sstevel@tonic-gate */ 8650Sstevel@tonic-gate STATEP->wheel_state_bf |= 8660Sstevel@tonic-gate VUID_WHEEL_STATE_ENABLED << 8670Sstevel@tonic-gate MOUSE_MODE_WHEEL; 8680Sstevel@tonic-gate } 8690Sstevel@tonic-gate 8700Sstevel@tonic-gate /* Wheel5 get dev has been ok */ 8710Sstevel@tonic-gate vuid_cancel_timeout(qp); 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate /* FALLTHROUGH */ 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate case PS2_WAIT_SETRES3_CMD: 8760Sstevel@tonic-gate STATEP->state = PS2_WAIT_SETRES3_ACK1; 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate /* Set timeout for set res */ 8790Sstevel@tonic-gate vuid_set_timeout(qp, PS2_INIT_TMOUT_PER_CMD); 8800Sstevel@tonic-gate 881993Slq150181 put1(WR(qp), MSESETRES); 882993Slq150181 8830Sstevel@tonic-gate break; 8840Sstevel@tonic-gate 8850Sstevel@tonic-gate case PS2_WAIT_SETRES3_ACK1: 8860Sstevel@tonic-gate if (code != MSE_ACK) { 8870Sstevel@tonic-gate break; 8880Sstevel@tonic-gate } 889993Slq150181 STATEP->state = PS2_WAIT_SETRES3_ACK2; 8900Sstevel@tonic-gate put1(WR(qp), 3); 8910Sstevel@tonic-gate break; 8920Sstevel@tonic-gate 8930Sstevel@tonic-gate case PS2_WAIT_SETRES3_ACK2: 8940Sstevel@tonic-gate if (code != MSE_ACK) { 8950Sstevel@tonic-gate break; 8960Sstevel@tonic-gate } 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate /* Set res has been ok */ 8990Sstevel@tonic-gate vuid_cancel_timeout(qp); 9000Sstevel@tonic-gate 9010Sstevel@tonic-gate STATEP->state = PS2_WAIT_STREAM_ACK; 9020Sstevel@tonic-gate 9030Sstevel@tonic-gate /* Set timeout for enable */ 9040Sstevel@tonic-gate vuid_set_timeout(qp, PS2_INIT_TMOUT_PER_CMD); 9050Sstevel@tonic-gate 906993Slq150181 put1(WR(qp), MSESTREAM); 907993Slq150181 9080Sstevel@tonic-gate break; 9090Sstevel@tonic-gate 9100Sstevel@tonic-gate case PS2_WAIT_STREAM_ACK: 9110Sstevel@tonic-gate if (code != MSE_ACK) { 9120Sstevel@tonic-gate break; 9130Sstevel@tonic-gate } 914993Slq150181 STATEP->state = PS2_WAIT_ON_ACK; 9150Sstevel@tonic-gate put1(WR(qp), MSEON); 9160Sstevel@tonic-gate break; 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate case PS2_WAIT_ON_ACK: 9190Sstevel@tonic-gate if (code != MSE_ACK) { 9200Sstevel@tonic-gate break; 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate /* Enable has been ok */ 9240Sstevel@tonic-gate vuid_cancel_timeout(qp); 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate STATEP->state = PS2_START; 9270Sstevel@tonic-gate break; 9280Sstevel@tonic-gate } 9290Sstevel@tonic-gate } 9300Sstevel@tonic-gate freemsg(mp); 9310Sstevel@tonic-gate } 932