psm.c revision 69438
141016Sdfr/*- 241016Sdfr * Copyright (c) 1992, 1993 Erik Forsberg. 341016Sdfr * Copyright (c) 1996, 1997 Kazutaka YOKOTA. 441016Sdfr * All rights reserved. 541016Sdfr * 641016Sdfr * Redistribution and use in source and binary forms, with or without 741016Sdfr * modification, are permitted provided that the following conditions 841016Sdfr * are met: 941016Sdfr * 1. Redistributions of source code must retain the above copyright 1041016Sdfr * notice, this list of conditions and the following disclaimer. 1141016Sdfr * 1241016Sdfr * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED 1341016Sdfr * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1441016Sdfr * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 1541016Sdfr * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1641016Sdfr * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1741016Sdfr * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1841016Sdfr * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1941016Sdfr * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 2041016Sdfr * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 2141016Sdfr * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2241016Sdfr * 2350477Speter * $FreeBSD: head/sys/dev/atkbdc/psm.c 69438 2000-12-01 05:24:30Z yokota $ 2441016Sdfr */ 2541016Sdfr 2641016Sdfr/* 2741016Sdfr * Ported to 386bsd Oct 17, 1992 2841016Sdfr * Sandi Donno, Computer Science, University of Cape Town, South Africa 2941016Sdfr * Please send bug reports to sandi@cs.uct.ac.za 3041016Sdfr * 3141016Sdfr * Thanks are also due to Rick Macklem, rick@snowhite.cis.uoguelph.ca - 3241016Sdfr * although I was only partially successful in getting the alpha release 3341016Sdfr * of his "driver for the Logitech and ATI Inport Bus mice for use with 3441016Sdfr * 386bsd and the X386 port" to work with my Microsoft mouse, I nevertheless 3541016Sdfr * found his code to be an invaluable reference when porting this driver 3641016Sdfr * to 386bsd. 3741016Sdfr * 3841016Sdfr * Further modifications for latest 386BSD+patchkit and port to NetBSD, 3941016Sdfr * Andrew Herbert <andrew@werple.apana.org.au> - 8 June 1993 4041016Sdfr * 4141016Sdfr * Cloned from the Microsoft Bus Mouse driver, also by Erik Forsberg, by 4241016Sdfr * Andrew Herbert - 12 June 1993 4341016Sdfr * 4441016Sdfr * Modified for PS/2 mouse by Charles Hannum <mycroft@ai.mit.edu> 4541016Sdfr * - 13 June 1993 4641016Sdfr * 4741016Sdfr * Modified for PS/2 AUX mouse by Shoji Yuen <yuen@nuie.nagoya-u.ac.jp> 4841016Sdfr * - 24 October 1993 4941016Sdfr * 5041016Sdfr * Hardware access routines and probe logic rewritten by 5141016Sdfr * Kazutaka Yokota <yokota@zodiac.mech.utsunomiya-u.ac.jp> 5241016Sdfr * - 3, 14, 22 October 1996. 5341016Sdfr * - 12 November 1996. IOCTLs and rearranging `psmread', `psmioctl'... 5441016Sdfr * - 14, 30 November 1996. Uses `kbdio.c'. 5541016Sdfr * - 13 December 1996. Uses queuing version of `kbdio.c'. 5641016Sdfr * - January/February 1997. Tweaked probe logic for 5741016Sdfr * HiNote UltraII/Latitude/Armada laptops. 5841016Sdfr * - 30 July 1997. Added APM support. 5941016Sdfr * - 5 March 1997. Defined driver configuration flags (PSM_CONFIG_XXX). 6041016Sdfr * Improved sync check logic. 6141016Sdfr * Vendor specific support routines. 6241016Sdfr */ 6341016Sdfr 6441016Sdfr#include "opt_psm.h" 6541016Sdfr 6641016Sdfr#include <sys/param.h> 6741016Sdfr#include <sys/systm.h> 6841016Sdfr#include <sys/kernel.h> 6941016Sdfr#include <sys/module.h> 7041016Sdfr#include <sys/bus.h> 7141016Sdfr#include <sys/conf.h> 7241016Sdfr#include <sys/poll.h> 7341016Sdfr#include <sys/syslog.h> 7445720Speter#include <machine/bus.h> 7541181Sdfr#include <sys/rman.h> 7641016Sdfr#include <sys/select.h> 7741016Sdfr#include <sys/uio.h> 7841016Sdfr 7941016Sdfr#include <machine/limits.h> 8066860Sphk#include <sys/mouse.h> 8141181Sdfr#include <machine/resource.h> 8241016Sdfr 8341016Sdfr#include <isa/isavar.h> 8443105Sdfr#include <dev/kbd/atkbdcreg.h> 8541016Sdfr 8641016Sdfr/* 8741016Sdfr * Driver specific options: the following options may be set by 8841016Sdfr * `options' statements in the kernel configuration file. 8941016Sdfr */ 9041016Sdfr 9141016Sdfr/* debugging */ 9241016Sdfr#ifndef PSM_DEBUG 9341016Sdfr#define PSM_DEBUG 0 /* logging: 0: none, 1: brief, 2: verbose */ 9441016Sdfr#endif 9541016Sdfr 9641016Sdfr/* end of driver specific options */ 9741016Sdfr 9841016Sdfr/* input queue */ 9941016Sdfr#define PSM_BUFSIZE 960 10041016Sdfr#define PSM_SMALLBUFSIZE 240 10141016Sdfr 10241016Sdfr/* operation levels */ 10341016Sdfr#define PSM_LEVEL_BASE 0 10441016Sdfr#define PSM_LEVEL_STANDARD 1 10541016Sdfr#define PSM_LEVEL_NATIVE 2 10641016Sdfr#define PSM_LEVEL_MIN PSM_LEVEL_BASE 10741016Sdfr#define PSM_LEVEL_MAX PSM_LEVEL_NATIVE 10841016Sdfr 10948778Syokota/* Logitech PS2++ protocol */ 11048778Syokota#define MOUSE_PS2PLUS_CHECKBITS(b) \ 11148778Syokota ((((b[2] & 0x03) << 2) | 0x02) == (b[1] & 0x0f)) 11248778Syokota#define MOUSE_PS2PLUS_PACKET_TYPE(b) \ 11348778Syokota (((b[0] & 0x30) >> 2) | ((b[1] & 0x30) >> 4)) 11448778Syokota 11541016Sdfr/* some macros */ 11641016Sdfr#define PSM_UNIT(dev) (minor(dev) >> 1) 11741016Sdfr#define PSM_NBLOCKIO(dev) (minor(dev) & 1) 11841016Sdfr#define PSM_MKMINOR(unit,block) (((unit) << 1) | ((block) ? 0:1)) 11941016Sdfr 12041016Sdfr#ifndef max 12141016Sdfr#define max(x,y) ((x) > (y) ? (x) : (y)) 12241016Sdfr#endif 12341016Sdfr#ifndef min 12441016Sdfr#define min(x,y) ((x) < (y) ? (x) : (y)) 12541016Sdfr#endif 12641016Sdfr 12748778Syokota#define abs(x) (((x) < 0) ? -(x) : (x)) 12848778Syokota 12941016Sdfr/* ring buffer */ 13041016Sdfrtypedef struct ringbuf { 13141016Sdfr int count; /* # of valid elements in the buffer */ 13241016Sdfr int head; /* head pointer */ 13341016Sdfr int tail; /* tail poiner */ 13441016Sdfr unsigned char buf[PSM_BUFSIZE]; 13541016Sdfr} ringbuf_t; 13641016Sdfr 13741016Sdfr/* driver control block */ 13841016Sdfrstruct psm_softc { /* Driver status information */ 13941016Sdfr struct selinfo rsel; /* Process selecting for Input */ 14041016Sdfr unsigned char state; /* Mouse driver state */ 14141016Sdfr int config; /* driver configuration flags */ 14241016Sdfr int flags; /* other flags */ 14341016Sdfr KBDC kbdc; /* handle to access the keyboard controller */ 14458230Syokota struct resource *intr; /* IRQ resource */ 14558230Syokota void *ih; /* interrupt handle */ 14641016Sdfr mousehw_t hw; /* hardware information */ 14741016Sdfr mousemode_t mode; /* operation mode */ 14841016Sdfr mousemode_t dflt_mode; /* default operation mode */ 14941016Sdfr mousestatus_t status; /* accumulated mouse movement */ 15041016Sdfr ringbuf_t queue; /* mouse status queue */ 15141016Sdfr unsigned char ipacket[16]; /* interim input buffer */ 15241016Sdfr int inputbytes; /* # of bytes in the input buffer */ 15341016Sdfr int button; /* the latest button state */ 15449965Syokota int xold; /* previous absolute X position */ 15549965Syokota int yold; /* previous absolute Y position */ 15658230Syokota int watchdog; /* watchdog timer flag */ 15758230Syokota struct callout_handle callout; /* watchdog timer call out */ 15858230Syokota dev_t dev; 15958230Syokota dev_t bdev; 16041016Sdfr}; 16141016Sdfrdevclass_t psm_devclass; 16241016Sdfr#define PSM_SOFTC(unit) ((struct psm_softc*)devclass_get_softc(psm_devclass, unit)) 16341016Sdfr 16441016Sdfr/* driver state flags (state) */ 16541016Sdfr#define PSM_VALID 0x80 16641016Sdfr#define PSM_OPEN 1 /* Device is open */ 16741016Sdfr#define PSM_ASLP 2 /* Waiting for mouse data */ 16841016Sdfr 16941016Sdfr/* driver configuration flags (config) */ 17041016Sdfr#define PSM_CONFIG_RESOLUTION 0x000f /* resolution */ 17141016Sdfr#define PSM_CONFIG_ACCEL 0x00f0 /* acceleration factor */ 17241016Sdfr#define PSM_CONFIG_NOCHECKSYNC 0x0100 /* disable sync. test */ 17345789Speter#define PSM_CONFIG_NOIDPROBE 0x0200 /* disable mouse model probe */ 17445789Speter#define PSM_CONFIG_NORESET 0x0400 /* don't reset the mouse */ 17545789Speter#define PSM_CONFIG_FORCETAP 0x0800 /* assume `tap' action exists */ 17645789Speter#define PSM_CONFIG_IGNPORTERROR 0x1000 /* ignore error in aux port test */ 17758230Syokota#define PSM_CONFIG_HOOKRESUME 0x2000 /* hook the system resume event */ 17858230Syokota#define PSM_CONFIG_INITAFTERSUSPEND 0x4000 /* init the device at the resume event */ 17941016Sdfr 18041016Sdfr#define PSM_CONFIG_FLAGS (PSM_CONFIG_RESOLUTION \ 18141016Sdfr | PSM_CONFIG_ACCEL \ 18245789Speter | PSM_CONFIG_NOCHECKSYNC \ 18345789Speter | PSM_CONFIG_NOIDPROBE \ 18445789Speter | PSM_CONFIG_NORESET \ 18545789Speter | PSM_CONFIG_FORCETAP \ 18658230Syokota | PSM_CONFIG_IGNPORTERROR \ 18758230Syokota | PSM_CONFIG_HOOKRESUME \ 18858230Syokota | PSM_CONFIG_INITAFTERSUSPEND) 18941016Sdfr 19041016Sdfr/* other flags (flags) */ 19149965Syokota#define PSM_FLAGS_FINGERDOWN 0x0001 /* VersaPad finger down */ 19241016Sdfr 19341016Sdfr/* for backward compatibility */ 19441016Sdfr#define OLD_MOUSE_GETHWINFO _IOR('M', 1, old_mousehw_t) 19541016Sdfr#define OLD_MOUSE_GETMODE _IOR('M', 2, old_mousemode_t) 19641016Sdfr#define OLD_MOUSE_SETMODE _IOW('M', 3, old_mousemode_t) 19741016Sdfr 19841016Sdfrtypedef struct old_mousehw { 19941016Sdfr int buttons; 20041016Sdfr int iftype; 20141016Sdfr int type; 20241016Sdfr int hwid; 20341016Sdfr} old_mousehw_t; 20441016Sdfr 20541016Sdfrtypedef struct old_mousemode { 20641016Sdfr int protocol; 20741016Sdfr int rate; 20841016Sdfr int resolution; 20941016Sdfr int accelfactor; 21041016Sdfr} old_mousemode_t; 21141016Sdfr 21241016Sdfr/* packet formatting function */ 21341016Sdfrtypedef int packetfunc_t __P((struct psm_softc *, unsigned char *, 21441016Sdfr int *, int, mousestatus_t *)); 21541016Sdfr 21641016Sdfr/* function prototypes */ 21741016Sdfrstatic int psmprobe __P((device_t)); 21841016Sdfrstatic int psmattach __P((device_t)); 21958230Syokotastatic int psmdetach __P((device_t)); 22054629Syokotastatic int psmresume __P((device_t)); 22141016Sdfr 22241016Sdfrstatic d_open_t psmopen; 22341016Sdfrstatic d_close_t psmclose; 22441016Sdfrstatic d_read_t psmread; 22541016Sdfrstatic d_ioctl_t psmioctl; 22641016Sdfrstatic d_poll_t psmpoll; 22741016Sdfr 22841016Sdfrstatic int enable_aux_dev __P((KBDC)); 22941016Sdfrstatic int disable_aux_dev __P((KBDC)); 23041016Sdfrstatic int get_mouse_status __P((KBDC, int *, int, int)); 23141016Sdfrstatic int get_aux_id __P((KBDC)); 23241016Sdfrstatic int set_mouse_sampling_rate __P((KBDC, int)); 23341016Sdfrstatic int set_mouse_scaling __P((KBDC, int)); 23441016Sdfrstatic int set_mouse_resolution __P((KBDC, int)); 23541016Sdfrstatic int set_mouse_mode __P((KBDC)); 23641016Sdfrstatic int get_mouse_buttons __P((KBDC)); 23741016Sdfrstatic int is_a_mouse __P((int)); 23841016Sdfrstatic void recover_from_error __P((KBDC)); 23941016Sdfrstatic int restore_controller __P((KBDC, int)); 24041016Sdfrstatic int reinitialize __P((int, mousemode_t *)); 24141016Sdfrstatic int doopen __P((int, int)); 24258230Syokotastatic char *model_name __P((int)); 24358230Syokotastatic void psmintr __P((void *)); 24458230Syokotastatic void psmtimeout __P((void *)); 24541016Sdfr 24641016Sdfr/* vendor specific features */ 24741016Sdfrtypedef int probefunc_t __P((struct psm_softc *)); 24841016Sdfr 24941016Sdfrstatic int mouse_id_proc1 __P((KBDC, int, int, int *)); 25069438Syokotastatic int mouse_ext_command __P((KBDC, int)); 25141016Sdfrstatic probefunc_t enable_groller; 25241016Sdfrstatic probefunc_t enable_gmouse; 25341016Sdfrstatic probefunc_t enable_aglide; 25441016Sdfrstatic probefunc_t enable_kmouse; 25558230Syokotastatic probefunc_t enable_msexplorer; 25641016Sdfrstatic probefunc_t enable_msintelli; 25758230Syokotastatic probefunc_t enable_4dmouse; 25858230Syokotastatic probefunc_t enable_4dplus; 25941016Sdfrstatic probefunc_t enable_mmanplus; 26049965Syokotastatic probefunc_t enable_versapad; 26141016Sdfrstatic int tame_mouse __P((struct psm_softc *, mousestatus_t *, unsigned char *)); 26241016Sdfr 26341016Sdfrstatic struct { 26441016Sdfr int model; 26541016Sdfr unsigned char syncmask; 26641016Sdfr int packetsize; 26741016Sdfr probefunc_t *probefunc; 26841016Sdfr} vendortype[] = { 26958230Syokota /* 27058230Syokota * WARNING: the order of probe is very important. Don't mess it 27158230Syokota * unless you know what you are doing. 27258230Syokota */ 27341016Sdfr { MOUSE_MODEL_NET, /* Genius NetMouse */ 27458230Syokota 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_gmouse, }, 27541016Sdfr { MOUSE_MODEL_NETSCROLL, /* Genius NetScroll */ 27641016Sdfr 0xc8, 6, enable_groller, }, 27758230Syokota { MOUSE_MODEL_MOUSEMANPLUS, /* Logitech MouseMan+ */ 27858230Syokota 0x08, MOUSE_PS2_PACKETSIZE, enable_mmanplus, }, 27958230Syokota { MOUSE_MODEL_EXPLORER, /* Microsoft IntelliMouse Explorer */ 28058230Syokota 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msexplorer, }, 28158230Syokota { MOUSE_MODEL_4D, /* A4 Tech 4D Mouse */ 28258230Syokota 0x08, MOUSE_4D_PACKETSIZE, enable_4dmouse, }, 28358230Syokota { MOUSE_MODEL_4DPLUS, /* A4 Tech 4D+ Mouse */ 28458230Syokota 0xc8, MOUSE_4DPLUS_PACKETSIZE, enable_4dplus, }, 28558230Syokota { MOUSE_MODEL_INTELLI, /* Microsoft IntelliMouse */ 28658230Syokota 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msintelli, }, 28741016Sdfr { MOUSE_MODEL_GLIDEPOINT, /* ALPS GlidePoint */ 28841016Sdfr 0xc0, MOUSE_PS2_PACKETSIZE, enable_aglide, }, 28941016Sdfr { MOUSE_MODEL_THINK, /* Kensignton ThinkingMouse */ 29041016Sdfr 0x80, MOUSE_PS2_PACKETSIZE, enable_kmouse, }, 29149965Syokota { MOUSE_MODEL_VERSAPAD, /* Interlink electronics VersaPad */ 29249965Syokota 0xe8, MOUSE_PS2VERSA_PACKETSIZE, enable_versapad, }, 29341016Sdfr { MOUSE_MODEL_GENERIC, 29441016Sdfr 0xc0, MOUSE_PS2_PACKETSIZE, NULL, }, 29541016Sdfr}; 29663951Syokota#define GENERIC_MOUSE_ENTRY ((sizeof(vendortype) / sizeof(*vendortype)) - 1) 29741016Sdfr 29841016Sdfr/* device driver declarateion */ 29941016Sdfrstatic device_method_t psm_methods[] = { 30041016Sdfr /* Device interface */ 30141016Sdfr DEVMETHOD(device_probe, psmprobe), 30241016Sdfr DEVMETHOD(device_attach, psmattach), 30358230Syokota DEVMETHOD(device_detach, psmdetach), 30454629Syokota DEVMETHOD(device_resume, psmresume), 30541016Sdfr 30641016Sdfr { 0, 0 } 30741016Sdfr}; 30841016Sdfr 30941016Sdfrstatic driver_t psm_driver = { 31041016Sdfr "psm", 31141016Sdfr psm_methods, 31241016Sdfr sizeof(struct psm_softc), 31341016Sdfr}; 31441016Sdfr 31558230Syokota#if notyet 31658230Syokotastatic struct isa_pnp_id psm_ids[] = { 31758230Syokota { 0x130fd041, "PS/2 mouse port" }, /* PNP0F13 */ 31858230Syokota { 0x1303d041, "PS/2 port" }, /* PNP0313, XXX */ 31958230Syokota { 0 } 32058230Syokota}; 32158230Syokota#endif 32258230Syokota 32341016Sdfr#define CDEV_MAJOR 21 32441016Sdfr 32547625Sphkstatic struct cdevsw psm_cdevsw = { 32647625Sphk /* open */ psmopen, 32747625Sphk /* close */ psmclose, 32847625Sphk /* read */ psmread, 32947625Sphk /* write */ nowrite, 33047625Sphk /* ioctl */ psmioctl, 33147625Sphk /* poll */ psmpoll, 33247625Sphk /* mmap */ nommap, 33347625Sphk /* strategy */ nostrategy, 33447625Sphk /* name */ "psm", 33547625Sphk /* maj */ CDEV_MAJOR, 33647625Sphk /* dump */ nodump, 33747625Sphk /* psize */ nopsize, 33847625Sphk /* flags */ 0, 33947625Sphk /* bmaj */ -1 34041016Sdfr}; 34141016Sdfr 34241016Sdfr/* debug message level */ 34341016Sdfrstatic int verbose = PSM_DEBUG; 34441016Sdfr 34541016Sdfr/* device I/O routines */ 34641016Sdfrstatic int 34741016Sdfrenable_aux_dev(KBDC kbdc) 34841016Sdfr{ 34941016Sdfr int res; 35041016Sdfr 35141016Sdfr res = send_aux_command(kbdc, PSMC_ENABLE_DEV); 35241016Sdfr if (verbose >= 2) 35341016Sdfr log(LOG_DEBUG, "psm: ENABLE_DEV return code:%04x\n", res); 35441016Sdfr 35541016Sdfr return (res == PSM_ACK); 35641016Sdfr} 35741016Sdfr 35841016Sdfrstatic int 35941016Sdfrdisable_aux_dev(KBDC kbdc) 36041016Sdfr{ 36141016Sdfr int res; 36241016Sdfr 36341016Sdfr res = send_aux_command(kbdc, PSMC_DISABLE_DEV); 36441016Sdfr if (verbose >= 2) 36541016Sdfr log(LOG_DEBUG, "psm: DISABLE_DEV return code:%04x\n", res); 36641016Sdfr 36741016Sdfr return (res == PSM_ACK); 36841016Sdfr} 36941016Sdfr 37041016Sdfrstatic int 37141016Sdfrget_mouse_status(KBDC kbdc, int *status, int flag, int len) 37241016Sdfr{ 37341016Sdfr int cmd; 37441016Sdfr int res; 37541016Sdfr int i; 37641016Sdfr 37741016Sdfr switch (flag) { 37841016Sdfr case 0: 37941016Sdfr default: 38041016Sdfr cmd = PSMC_SEND_DEV_STATUS; 38141016Sdfr break; 38241016Sdfr case 1: 38341016Sdfr cmd = PSMC_SEND_DEV_DATA; 38441016Sdfr break; 38541016Sdfr } 38641016Sdfr empty_aux_buffer(kbdc, 5); 38741016Sdfr res = send_aux_command(kbdc, cmd); 38841016Sdfr if (verbose >= 2) 38941016Sdfr log(LOG_DEBUG, "psm: SEND_AUX_DEV_%s return code:%04x\n", 39041016Sdfr (flag == 1) ? "DATA" : "STATUS", res); 39141016Sdfr if (res != PSM_ACK) 39241016Sdfr return 0; 39341016Sdfr 39441016Sdfr for (i = 0; i < len; ++i) { 39541016Sdfr status[i] = read_aux_data(kbdc); 39641016Sdfr if (status[i] < 0) 39741016Sdfr break; 39841016Sdfr } 39941016Sdfr 40041016Sdfr if (verbose) { 40141016Sdfr log(LOG_DEBUG, "psm: %s %02x %02x %02x\n", 40241016Sdfr (flag == 1) ? "data" : "status", status[0], status[1], status[2]); 40341016Sdfr } 40441016Sdfr 40541016Sdfr return i; 40641016Sdfr} 40741016Sdfr 40841016Sdfrstatic int 40941016Sdfrget_aux_id(KBDC kbdc) 41041016Sdfr{ 41141016Sdfr int res; 41241016Sdfr int id; 41341016Sdfr 41441016Sdfr empty_aux_buffer(kbdc, 5); 41541016Sdfr res = send_aux_command(kbdc, PSMC_SEND_DEV_ID); 41641016Sdfr if (verbose >= 2) 41741016Sdfr log(LOG_DEBUG, "psm: SEND_DEV_ID return code:%04x\n", res); 41841016Sdfr if (res != PSM_ACK) 41941016Sdfr return (-1); 42041016Sdfr 42141016Sdfr /* 10ms delay */ 42241016Sdfr DELAY(10000); 42341016Sdfr 42441016Sdfr id = read_aux_data(kbdc); 42541016Sdfr if (verbose >= 2) 42641016Sdfr log(LOG_DEBUG, "psm: device ID: %04x\n", id); 42741016Sdfr 42841016Sdfr return id; 42941016Sdfr} 43041016Sdfr 43141016Sdfrstatic int 43241016Sdfrset_mouse_sampling_rate(KBDC kbdc, int rate) 43341016Sdfr{ 43441016Sdfr int res; 43541016Sdfr 43641016Sdfr res = send_aux_command_and_data(kbdc, PSMC_SET_SAMPLING_RATE, rate); 43741016Sdfr if (verbose >= 2) 43841016Sdfr log(LOG_DEBUG, "psm: SET_SAMPLING_RATE (%d) %04x\n", rate, res); 43941016Sdfr 44041016Sdfr return ((res == PSM_ACK) ? rate : -1); 44141016Sdfr} 44241016Sdfr 44341016Sdfrstatic int 44441016Sdfrset_mouse_scaling(KBDC kbdc, int scale) 44541016Sdfr{ 44641016Sdfr int res; 44741016Sdfr 44841016Sdfr switch (scale) { 44941016Sdfr case 1: 45041016Sdfr default: 45141016Sdfr scale = PSMC_SET_SCALING11; 45241016Sdfr break; 45341016Sdfr case 2: 45441016Sdfr scale = PSMC_SET_SCALING21; 45541016Sdfr break; 45641016Sdfr } 45741016Sdfr res = send_aux_command(kbdc, scale); 45841016Sdfr if (verbose >= 2) 45941016Sdfr log(LOG_DEBUG, "psm: SET_SCALING%s return code:%04x\n", 46041016Sdfr (scale == PSMC_SET_SCALING21) ? "21" : "11", res); 46141016Sdfr 46241016Sdfr return (res == PSM_ACK); 46341016Sdfr} 46441016Sdfr 46541016Sdfr/* `val' must be 0 through PSMD_MAX_RESOLUTION */ 46641016Sdfrstatic int 46741016Sdfrset_mouse_resolution(KBDC kbdc, int val) 46841016Sdfr{ 46941016Sdfr int res; 47041016Sdfr 47141016Sdfr res = send_aux_command_and_data(kbdc, PSMC_SET_RESOLUTION, val); 47241016Sdfr if (verbose >= 2) 47341016Sdfr log(LOG_DEBUG, "psm: SET_RESOLUTION (%d) %04x\n", val, res); 47441016Sdfr 47541016Sdfr return ((res == PSM_ACK) ? val : -1); 47641016Sdfr} 47741016Sdfr 47841016Sdfr/* 47941016Sdfr * NOTE: once `set_mouse_mode()' is called, the mouse device must be 48041016Sdfr * re-enabled by calling `enable_aux_dev()' 48141016Sdfr */ 48241016Sdfrstatic int 48341016Sdfrset_mouse_mode(KBDC kbdc) 48441016Sdfr{ 48541016Sdfr int res; 48641016Sdfr 48741016Sdfr res = send_aux_command(kbdc, PSMC_SET_STREAM_MODE); 48841016Sdfr if (verbose >= 2) 48941016Sdfr log(LOG_DEBUG, "psm: SET_STREAM_MODE return code:%04x\n", res); 49041016Sdfr 49141016Sdfr return (res == PSM_ACK); 49241016Sdfr} 49341016Sdfr 49441016Sdfrstatic int 49541016Sdfrget_mouse_buttons(KBDC kbdc) 49641016Sdfr{ 49741016Sdfr int c = 2; /* assume two buttons by default */ 49841016Sdfr int status[3]; 49941016Sdfr 50041016Sdfr /* 50141016Sdfr * NOTE: a special sequence to obtain Logitech Mouse specific 50241016Sdfr * information: set resolution to 25 ppi, set scaling to 1:1, set 50341016Sdfr * scaling to 1:1, set scaling to 1:1. Then the second byte of the 50441016Sdfr * mouse status bytes is the number of available buttons. 50541016Sdfr * Some manufactures also support this sequence. 50641016Sdfr */ 50741016Sdfr if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW) 50841016Sdfr return c; 50941016Sdfr if (set_mouse_scaling(kbdc, 1) && set_mouse_scaling(kbdc, 1) 51041016Sdfr && set_mouse_scaling(kbdc, 1) 51141016Sdfr && (get_mouse_status(kbdc, status, 0, 3) >= 3)) { 51241016Sdfr if (status[1] != 0) 51341016Sdfr return status[1]; 51441016Sdfr } 51541016Sdfr return c; 51641016Sdfr} 51741016Sdfr 51841016Sdfr/* misc subroutines */ 51941016Sdfr/* 52041016Sdfr * Someday, I will get the complete list of valid pointing devices and 52141016Sdfr * their IDs... XXX 52241016Sdfr */ 52341016Sdfrstatic int 52441016Sdfris_a_mouse(int id) 52541016Sdfr{ 52641016Sdfr#if 0 52741016Sdfr static int valid_ids[] = { 52841016Sdfr PSM_MOUSE_ID, /* mouse */ 52941016Sdfr PSM_BALLPOINT_ID, /* ballpoint device */ 53041016Sdfr PSM_INTELLI_ID, /* Intellimouse */ 53158230Syokota PSM_EXPLORER_ID, /* Intellimouse Explorer */ 53241016Sdfr -1 /* end of table */ 53341016Sdfr }; 53441016Sdfr int i; 53541016Sdfr 53641016Sdfr for (i = 0; valid_ids[i] >= 0; ++i) 53741016Sdfr if (valid_ids[i] == id) 53841016Sdfr return TRUE; 53941016Sdfr return FALSE; 54041016Sdfr#else 54141016Sdfr return TRUE; 54241016Sdfr#endif 54341016Sdfr} 54441016Sdfr 54541016Sdfrstatic char * 54641016Sdfrmodel_name(int model) 54741016Sdfr{ 54841016Sdfr static struct { 54941016Sdfr int model_code; 55041016Sdfr char *model_name; 55141016Sdfr } models[] = { 55258230Syokota { MOUSE_MODEL_NETSCROLL, "NetScroll" }, 55358230Syokota { MOUSE_MODEL_NET, "NetMouse/NetScroll Optical" }, 55441016Sdfr { MOUSE_MODEL_GLIDEPOINT, "GlidePoint" }, 55541016Sdfr { MOUSE_MODEL_THINK, "ThinkingMouse" }, 55641016Sdfr { MOUSE_MODEL_INTELLI, "IntelliMouse" }, 55741016Sdfr { MOUSE_MODEL_MOUSEMANPLUS, "MouseMan+" }, 55849965Syokota { MOUSE_MODEL_VERSAPAD, "VersaPad" }, 55958230Syokota { MOUSE_MODEL_EXPLORER, "IntelliMouse Explorer" }, 56058230Syokota { MOUSE_MODEL_4D, "4D Mouse" }, 56158230Syokota { MOUSE_MODEL_4DPLUS, "4D+ Mouse" }, 56241016Sdfr { MOUSE_MODEL_GENERIC, "Generic PS/2 mouse" }, 56341016Sdfr { MOUSE_MODEL_UNKNOWN, NULL }, 56441016Sdfr }; 56541016Sdfr int i; 56641016Sdfr 56741016Sdfr for (i = 0; models[i].model_code != MOUSE_MODEL_UNKNOWN; ++i) { 56841016Sdfr if (models[i].model_code == model) 56941016Sdfr return models[i].model_name; 57041016Sdfr } 57141016Sdfr return "Unknown"; 57241016Sdfr} 57341016Sdfr 57441016Sdfrstatic void 57541016Sdfrrecover_from_error(KBDC kbdc) 57641016Sdfr{ 57741016Sdfr /* discard anything left in the output buffer */ 57841016Sdfr empty_both_buffers(kbdc, 10); 57941016Sdfr 58041016Sdfr#if 0 58141016Sdfr /* 58241016Sdfr * NOTE: KBDC_RESET_KBD may not restore the communication between the 58341016Sdfr * keyboard and the controller. 58441016Sdfr */ 58541016Sdfr reset_kbd(kbdc); 58641016Sdfr#else 58741016Sdfr /* 58841016Sdfr * NOTE: somehow diagnostic and keyboard port test commands bring the 58941016Sdfr * keyboard back. 59041016Sdfr */ 59141016Sdfr if (!test_controller(kbdc)) 59241016Sdfr log(LOG_ERR, "psm: keyboard controller failed.\n"); 59341016Sdfr /* if there isn't a keyboard in the system, the following error is OK */ 59441016Sdfr if (test_kbd_port(kbdc) != 0) { 59541016Sdfr if (verbose) 59641016Sdfr log(LOG_ERR, "psm: keyboard port failed.\n"); 59741016Sdfr } 59841016Sdfr#endif 59941016Sdfr} 60041016Sdfr 60141016Sdfrstatic int 60241016Sdfrrestore_controller(KBDC kbdc, int command_byte) 60341016Sdfr{ 60441016Sdfr empty_both_buffers(kbdc, 10); 60541016Sdfr 60641016Sdfr if (!set_controller_command_byte(kbdc, 0xff, command_byte)) { 60741016Sdfr log(LOG_ERR, "psm: failed to restore the keyboard controller " 60841016Sdfr "command byte.\n"); 60958230Syokota empty_both_buffers(kbdc, 10); 61041016Sdfr return FALSE; 61141016Sdfr } else { 61258230Syokota empty_both_buffers(kbdc, 10); 61341016Sdfr return TRUE; 61441016Sdfr } 61541016Sdfr} 61641016Sdfr 61741016Sdfr/* 61841016Sdfr * Re-initialize the aux port and device. The aux port must be enabled 61941016Sdfr * and its interrupt must be disabled before calling this routine. 62041016Sdfr * The aux device will be disabled before returning. 62141016Sdfr * The keyboard controller must be locked via `kbdc_lock()' before 62241016Sdfr * calling this routine. 62341016Sdfr */ 62441016Sdfrstatic int 62541016Sdfrreinitialize(int unit, mousemode_t *mode) 62641016Sdfr{ 62741016Sdfr struct psm_softc *sc = PSM_SOFTC(unit); 62841016Sdfr KBDC kbdc = sc->kbdc; 62941016Sdfr int stat[3]; 63041016Sdfr int i; 63141016Sdfr 63241016Sdfr switch((i = test_aux_port(kbdc))) { 63341016Sdfr case 1: /* ignore this error */ 63441016Sdfr case PSM_ACK: 63541016Sdfr if (verbose) 63641016Sdfr log(LOG_DEBUG, "psm%d: strange result for test aux port (%d).\n", 63741016Sdfr unit, i); 63841016Sdfr /* fall though */ 63941016Sdfr case 0: /* no error */ 64041016Sdfr break; 64141016Sdfr case -1: /* time out */ 64241016Sdfr default: /* error */ 64341016Sdfr recover_from_error(kbdc); 64445789Speter if (sc->config & PSM_CONFIG_IGNPORTERROR) 64545789Speter break; 64641016Sdfr log(LOG_ERR, "psm%d: the aux port is not functioning (%d).\n", 64741016Sdfr unit, i); 64841016Sdfr return FALSE; 64941016Sdfr } 65041016Sdfr 65145789Speter if (sc->config & PSM_CONFIG_NORESET) { 65245789Speter /* 65345789Speter * Don't try to reset the pointing device. It may possibly be 65445789Speter * left in the unknown state, though... 65545789Speter */ 65645789Speter } else { 65745789Speter /* 65845789Speter * NOTE: some controllers appears to hang the `keyboard' when 65945789Speter * the aux port doesn't exist and `PSMC_RESET_DEV' is issued. 66045789Speter */ 66145789Speter if (!reset_aux_dev(kbdc)) { 66245789Speter recover_from_error(kbdc); 66345789Speter log(LOG_ERR, "psm%d: failed to reset the aux device.\n", unit); 66445789Speter return FALSE; 66545789Speter } 66641016Sdfr } 66741016Sdfr 66841016Sdfr /* 66941016Sdfr * both the aux port and the aux device is functioning, see 67041016Sdfr * if the device can be enabled. 67141016Sdfr */ 67241016Sdfr if (!enable_aux_dev(kbdc) || !disable_aux_dev(kbdc)) { 67341016Sdfr log(LOG_ERR, "psm%d: failed to enable the aux device.\n", unit); 67441016Sdfr return FALSE; 67541016Sdfr } 67641016Sdfr empty_both_buffers(kbdc, 10); /* remove stray data if any */ 67741016Sdfr 67845789Speter if (sc->config & PSM_CONFIG_NOIDPROBE) { 67945789Speter i = GENERIC_MOUSE_ENTRY; 68045789Speter } else { 68145789Speter /* FIXME: hardware ID, mouse buttons? */ 68241016Sdfr 68345789Speter /* other parameters */ 68445789Speter for (i = 0; vendortype[i].probefunc != NULL; ++i) { 68545789Speter if ((*vendortype[i].probefunc)(sc)) { 68645789Speter if (verbose >= 2) 68745789Speter log(LOG_ERR, "psm%d: found %s\n", 68845789Speter unit, model_name(vendortype[i].model)); 68945789Speter break; 69045789Speter } 69141016Sdfr } 69241016Sdfr } 69341016Sdfr 69441016Sdfr sc->hw.model = vendortype[i].model; 69541016Sdfr sc->mode.packetsize = vendortype[i].packetsize; 69641016Sdfr 69741016Sdfr /* set mouse parameters */ 69841016Sdfr if (mode != (mousemode_t *)NULL) { 69941016Sdfr if (mode->rate > 0) 70041016Sdfr mode->rate = set_mouse_sampling_rate(kbdc, mode->rate); 70141016Sdfr if (mode->resolution >= 0) 70241016Sdfr mode->resolution = set_mouse_resolution(kbdc, mode->resolution); 70341016Sdfr set_mouse_scaling(kbdc, 1); 70441016Sdfr set_mouse_mode(kbdc); 70541016Sdfr } 70641016Sdfr 70741016Sdfr /* request a data packet and extract sync. bits */ 70841016Sdfr if (get_mouse_status(kbdc, stat, 1, 3) < 3) { 70941016Sdfr log(LOG_DEBUG, "psm%d: failed to get data (reinitialize).\n", unit); 71041016Sdfr sc->mode.syncmask[0] = 0; 71141016Sdfr } else { 71241016Sdfr sc->mode.syncmask[1] = stat[0] & sc->mode.syncmask[0]; /* syncbits */ 71341016Sdfr /* the NetScroll Mouse will send three more bytes... Ignore them */ 71441016Sdfr empty_aux_buffer(kbdc, 5); 71541016Sdfr } 71641016Sdfr 71741016Sdfr /* just check the status of the mouse */ 71841016Sdfr if (get_mouse_status(kbdc, stat, 0, 3) < 3) 71941016Sdfr log(LOG_DEBUG, "psm%d: failed to get status (reinitialize).\n", unit); 72041016Sdfr 72141016Sdfr return TRUE; 72241016Sdfr} 72341016Sdfr 72441016Sdfrstatic int 72541016Sdfrdoopen(int unit, int command_byte) 72641016Sdfr{ 72741016Sdfr struct psm_softc *sc = PSM_SOFTC(unit); 72841016Sdfr int stat[3]; 72941016Sdfr 73041016Sdfr /* enable the mouse device */ 73141016Sdfr if (!enable_aux_dev(sc->kbdc)) { 73241016Sdfr /* MOUSE ERROR: failed to enable the mouse because: 73341016Sdfr * 1) the mouse is faulty, 73441016Sdfr * 2) the mouse has been removed(!?) 73541016Sdfr * In the latter case, the keyboard may have hung, and need 73641016Sdfr * recovery procedure... 73741016Sdfr */ 73841016Sdfr recover_from_error(sc->kbdc); 73941016Sdfr#if 0 74041016Sdfr /* FIXME: we could reset the mouse here and try to enable 74141016Sdfr * it again. But it will take long time and it's not a good 74241016Sdfr * idea to disable the keyboard that long... 74341016Sdfr */ 74441016Sdfr if (!reinitialize(unit, &sc->mode) || !enable_aux_dev(sc->kbdc)) { 74541016Sdfr recover_from_error(sc->kbdc); 74641016Sdfr#else 74741016Sdfr { 74841016Sdfr#endif 74941016Sdfr restore_controller(sc->kbdc, command_byte); 75041016Sdfr /* mark this device is no longer available */ 75141016Sdfr sc->state &= ~PSM_VALID; 75241016Sdfr log(LOG_ERR, "psm%d: failed to enable the device (doopen).\n", 75341016Sdfr unit); 75441016Sdfr return (EIO); 75541016Sdfr } 75641016Sdfr } 75741016Sdfr 75841016Sdfr if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3) 75941016Sdfr log(LOG_DEBUG, "psm%d: failed to get status (doopen).\n", unit); 76041016Sdfr 76141016Sdfr /* enable the aux port and interrupt */ 76241016Sdfr if (!set_controller_command_byte(sc->kbdc, 76341016Sdfr kbdc_get_device_mask(sc->kbdc), 76441016Sdfr (command_byte & KBD_KBD_CONTROL_BITS) 76541016Sdfr | KBD_ENABLE_AUX_PORT | KBD_ENABLE_AUX_INT)) { 76641016Sdfr /* CONTROLLER ERROR */ 76741016Sdfr disable_aux_dev(sc->kbdc); 76841016Sdfr restore_controller(sc->kbdc, command_byte); 76941016Sdfr log(LOG_ERR, "psm%d: failed to enable the aux interrupt (doopen).\n", 77041016Sdfr unit); 77141016Sdfr return (EIO); 77241016Sdfr } 77341016Sdfr 77458230Syokota /* start the watchdog timer */ 77558230Syokota sc->watchdog = FALSE; 77666229Sjhb sc->callout = timeout(psmtimeout, (void *)(uintptr_t)unit, hz*2); 77758230Syokota 77841016Sdfr return (0); 77941016Sdfr} 78041016Sdfr 78141016Sdfr/* psm driver entry points */ 78241016Sdfr 78341016Sdfr#define endprobe(v) { if (bootverbose) \ 78441016Sdfr --verbose; \ 78541016Sdfr kbdc_set_device_mask(sc->kbdc, mask); \ 78641016Sdfr kbdc_lock(sc->kbdc, FALSE); \ 78741016Sdfr return (v); \ 78841016Sdfr } 78941016Sdfr 79041016Sdfrstatic int 79141016Sdfrpsmprobe(device_t dev) 79241016Sdfr{ 79341016Sdfr int unit = device_get_unit(dev); 79441016Sdfr struct psm_softc *sc = device_get_softc(dev); 79558230Syokota uintptr_t irq; 79645720Speter uintptr_t flags; 79741016Sdfr int stat[3]; 79841016Sdfr int command_byte; 79941016Sdfr int mask; 80058230Syokota int rid; 80141016Sdfr int i; 80241016Sdfr 80341016Sdfr#if 0 80441016Sdfr kbdc_debug(TRUE); 80541016Sdfr#endif 80658230Syokota 80758230Syokota#if notyet 80858230Syokota /* check PnP IDs */ 80958230Syokota if (XXX_PNP_PROBE(device_get_parent(dev), dev, psm_ids) == ENXIO) 81058230Syokota return ENXIO; 81158230Syokota#endif 81258230Syokota 81358230Syokota BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq); 81443105Sdfr BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags); 81543105Sdfr 81658230Syokota sc->kbdc = atkbdc_open(device_get_unit(device_get_parent(dev))); 81743105Sdfr sc->config = flags & PSM_CONFIG_FLAGS; 81858230Syokota /* XXX: for backward compatibility */ 81958230Syokota#if defined(PSM_HOOKRESUME) || defined(PSM_HOOKAPM) 82058230Syokota sc->config |= 82158230Syokota#ifdef PSM_RESETAFTERSUSPEND 82258230Syokota PSM_CONFIG_HOOKRESUME | PSM_CONFIG_INITAFTERSUSPEND; 82358230Syokota#else 82458230Syokota PSM_CONFIG_HOOKRESUME; 82558230Syokota#endif 82658230Syokota#endif /* PSM_HOOKRESUME | PSM_HOOKAPM */ 82741016Sdfr sc->flags = 0; 82841016Sdfr if (bootverbose) 82941016Sdfr ++verbose; 83041016Sdfr 83143105Sdfr device_set_desc(dev, "PS/2 Mouse"); 83243105Sdfr 83341016Sdfr if (!kbdc_lock(sc->kbdc, TRUE)) { 83441016Sdfr printf("psm%d: unable to lock the controller.\n", unit); 83541016Sdfr if (bootverbose) 83641016Sdfr --verbose; 83741016Sdfr return (ENXIO); 83841016Sdfr } 83941016Sdfr 84041016Sdfr /* 84141016Sdfr * NOTE: two bits in the command byte controls the operation of the 84241016Sdfr * aux port (mouse port): the aux port disable bit (bit 5) and the aux 84341016Sdfr * port interrupt (IRQ 12) enable bit (bit 2). 84441016Sdfr */ 84541016Sdfr 84641016Sdfr /* discard anything left after the keyboard initialization */ 84741016Sdfr empty_both_buffers(sc->kbdc, 10); 84841016Sdfr 84941016Sdfr /* save the current command byte; it will be used later */ 85041016Sdfr mask = kbdc_get_device_mask(sc->kbdc) & ~KBD_AUX_CONTROL_BITS; 85141016Sdfr command_byte = get_controller_command_byte(sc->kbdc); 85241016Sdfr if (verbose) 85341016Sdfr printf("psm%d: current command byte:%04x\n", unit, command_byte); 85441016Sdfr if (command_byte == -1) { 85541016Sdfr /* CONTROLLER ERROR */ 85641016Sdfr printf("psm%d: unable to get the current command byte value.\n", 85741016Sdfr unit); 85841016Sdfr endprobe(ENXIO); 85941016Sdfr } 86041016Sdfr 86141016Sdfr /* 86241016Sdfr * disable the keyboard port while probing the aux port, which must be 86341016Sdfr * enabled during this routine 86441016Sdfr */ 86541016Sdfr if (!set_controller_command_byte(sc->kbdc, 86641016Sdfr KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS, 86741016Sdfr KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT 86841016Sdfr | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) { 86941016Sdfr /* 87041016Sdfr * this is CONTROLLER ERROR; I don't know how to recover 87141016Sdfr * from this error... 87241016Sdfr */ 87341016Sdfr restore_controller(sc->kbdc, command_byte); 87441016Sdfr printf("psm%d: unable to set the command byte.\n", unit); 87541016Sdfr endprobe(ENXIO); 87641016Sdfr } 87745789Speter write_controller_command(sc->kbdc, KBDC_ENABLE_AUX_PORT); 87841016Sdfr 87941016Sdfr /* 88041016Sdfr * NOTE: `test_aux_port()' is designed to return with zero if the aux 88141016Sdfr * port exists and is functioning. However, some controllers appears 88241016Sdfr * to respond with zero even when the aux port doesn't exist. (It may 88341016Sdfr * be that this is only the case when the controller DOES have the aux 88441016Sdfr * port but the port is not wired on the motherboard.) The keyboard 88541016Sdfr * controllers without the port, such as the original AT, are 88641016Sdfr * supporsed to return with an error code or simply time out. In any 88741016Sdfr * case, we have to continue probing the port even when the controller 88841016Sdfr * passes this test. 88941016Sdfr * 89041016Sdfr * XXX: some controllers erroneously return the error code 1 when 89141016Sdfr * it has the perfectly functional aux port. We have to ignore this 89241016Sdfr * error code. Even if the controller HAS error with the aux port, 89341016Sdfr * it will be detected later... 89441016Sdfr * XXX: another incompatible controller returns PSM_ACK (0xfa)... 89541016Sdfr */ 89641016Sdfr switch ((i = test_aux_port(sc->kbdc))) { 89741016Sdfr case 1: /* ignore this error */ 89841016Sdfr case PSM_ACK: 89941016Sdfr if (verbose) 90041016Sdfr printf("psm%d: strange result for test aux port (%d).\n", 90141016Sdfr unit, i); 90241016Sdfr /* fall though */ 90341016Sdfr case 0: /* no error */ 90441016Sdfr break; 90541016Sdfr case -1: /* time out */ 90641016Sdfr default: /* error */ 90741016Sdfr recover_from_error(sc->kbdc); 90845789Speter if (sc->config & PSM_CONFIG_IGNPORTERROR) 90945789Speter break; 91041016Sdfr restore_controller(sc->kbdc, command_byte); 91141016Sdfr if (verbose) 91241016Sdfr printf("psm%d: the aux port is not functioning (%d).\n", 91341016Sdfr unit, i); 91441016Sdfr endprobe(ENXIO); 91541016Sdfr } 91641016Sdfr 91745789Speter if (sc->config & PSM_CONFIG_NORESET) { 91845789Speter /* 91945789Speter * Don't try to reset the pointing device. It may possibly be 92045789Speter * left in the unknown state, though... 92145789Speter */ 92245789Speter } else { 92345789Speter /* 92445789Speter * NOTE: some controllers appears to hang the `keyboard' when the aux 92545789Speter * port doesn't exist and `PSMC_RESET_DEV' is issued. 92645789Speter */ 92745789Speter if (!reset_aux_dev(sc->kbdc)) { 92845789Speter recover_from_error(sc->kbdc); 92945789Speter restore_controller(sc->kbdc, command_byte); 93045789Speter if (verbose) 93145789Speter printf("psm%d: failed to reset the aux device.\n", unit); 93245789Speter endprobe(ENXIO); 93345789Speter } 93441016Sdfr } 93545789Speter 93641016Sdfr /* 93741016Sdfr * both the aux port and the aux device is functioning, see if the 93841016Sdfr * device can be enabled. NOTE: when enabled, the device will start 93941016Sdfr * sending data; we shall immediately disable the device once we know 94041016Sdfr * the device can be enabled. 94141016Sdfr */ 94241016Sdfr if (!enable_aux_dev(sc->kbdc) || !disable_aux_dev(sc->kbdc)) { 94345789Speter /* MOUSE ERROR */ 94445789Speter recover_from_error(sc->kbdc); 94545789Speter restore_controller(sc->kbdc, command_byte); 94645789Speter if (verbose) 94745789Speter printf("psm%d: failed to enable the aux device.\n", unit); 94841016Sdfr endprobe(ENXIO); 94941016Sdfr } 95041016Sdfr 95141016Sdfr /* save the default values after reset */ 95241016Sdfr if (get_mouse_status(sc->kbdc, stat, 0, 3) >= 3) { 95341016Sdfr sc->dflt_mode.rate = sc->mode.rate = stat[2]; 95441016Sdfr sc->dflt_mode.resolution = sc->mode.resolution = stat[1]; 95541016Sdfr } else { 95641016Sdfr sc->dflt_mode.rate = sc->mode.rate = -1; 95741016Sdfr sc->dflt_mode.resolution = sc->mode.resolution = -1; 95841016Sdfr } 95941016Sdfr 96041016Sdfr /* hardware information */ 96141016Sdfr sc->hw.iftype = MOUSE_IF_PS2; 96241016Sdfr 96341016Sdfr /* verify the device is a mouse */ 96441016Sdfr sc->hw.hwid = get_aux_id(sc->kbdc); 96541016Sdfr if (!is_a_mouse(sc->hw.hwid)) { 96641016Sdfr restore_controller(sc->kbdc, command_byte); 96741016Sdfr if (verbose) 96841016Sdfr printf("psm%d: unknown device type (%d).\n", unit, sc->hw.hwid); 96941016Sdfr endprobe(ENXIO); 97041016Sdfr } 97141016Sdfr switch (sc->hw.hwid) { 97241016Sdfr case PSM_BALLPOINT_ID: 97341016Sdfr sc->hw.type = MOUSE_TRACKBALL; 97441016Sdfr break; 97541016Sdfr case PSM_MOUSE_ID: 97641016Sdfr case PSM_INTELLI_ID: 97758230Syokota case PSM_EXPLORER_ID: 97858230Syokota case PSM_4DMOUSE_ID: 97958230Syokota case PSM_4DPLUS_ID: 98041016Sdfr sc->hw.type = MOUSE_MOUSE; 98141016Sdfr break; 98241016Sdfr default: 98341016Sdfr sc->hw.type = MOUSE_UNKNOWN; 98441016Sdfr break; 98541016Sdfr } 98641016Sdfr 98745789Speter if (sc->config & PSM_CONFIG_NOIDPROBE) { 98845789Speter sc->hw.buttons = 2; 98945789Speter i = GENERIC_MOUSE_ENTRY; 99045789Speter } else { 99145789Speter /* # of buttons */ 99245789Speter sc->hw.buttons = get_mouse_buttons(sc->kbdc); 99341016Sdfr 99445789Speter /* other parameters */ 99545789Speter for (i = 0; vendortype[i].probefunc != NULL; ++i) { 99645789Speter if ((*vendortype[i].probefunc)(sc)) { 99745789Speter if (verbose >= 2) 99845789Speter printf("psm%d: found %s\n", 99945789Speter unit, model_name(vendortype[i].model)); 100045789Speter break; 100145789Speter } 100241016Sdfr } 100341016Sdfr } 100441016Sdfr 100541016Sdfr sc->hw.model = vendortype[i].model; 100641016Sdfr 100741016Sdfr sc->dflt_mode.level = PSM_LEVEL_BASE; 100841016Sdfr sc->dflt_mode.packetsize = MOUSE_PS2_PACKETSIZE; 100941016Sdfr sc->dflt_mode.accelfactor = (sc->config & PSM_CONFIG_ACCEL) >> 4; 101041016Sdfr if (sc->config & PSM_CONFIG_NOCHECKSYNC) 101141016Sdfr sc->dflt_mode.syncmask[0] = 0; 101241016Sdfr else 101341016Sdfr sc->dflt_mode.syncmask[0] = vendortype[i].syncmask; 101445789Speter if (sc->config & PSM_CONFIG_FORCETAP) 101545789Speter sc->mode.syncmask[0] &= ~MOUSE_PS2_TAP; 101641016Sdfr sc->dflt_mode.syncmask[1] = 0; /* syncbits */ 101741016Sdfr sc->mode = sc->dflt_mode; 101841016Sdfr sc->mode.packetsize = vendortype[i].packetsize; 101941016Sdfr 102041016Sdfr /* set mouse parameters */ 102148773Syokota#if 0 102248773Syokota /* 102348773Syokota * A version of Logitech FirstMouse+ won't report wheel movement, 102448773Syokota * if SET_DEFAULTS is sent... Don't use this command. 102548773Syokota * This fix was found by Takashi Nishida. 102648773Syokota */ 102741016Sdfr i = send_aux_command(sc->kbdc, PSMC_SET_DEFAULTS); 102841016Sdfr if (verbose >= 2) 102941016Sdfr printf("psm%d: SET_DEFAULTS return code:%04x\n", unit, i); 103048773Syokota#endif 103141016Sdfr if (sc->config & PSM_CONFIG_RESOLUTION) { 103241016Sdfr sc->mode.resolution 103341016Sdfr = set_mouse_resolution(sc->kbdc, 103448773Syokota (sc->config & PSM_CONFIG_RESOLUTION) - 1); 103548773Syokota } else if (sc->mode.resolution >= 0) { 103648773Syokota sc->mode.resolution 103748773Syokota = set_mouse_resolution(sc->kbdc, sc->dflt_mode.resolution); 103841016Sdfr } 103948773Syokota if (sc->mode.rate > 0) { 104048773Syokota sc->mode.rate = set_mouse_sampling_rate(sc->kbdc, sc->dflt_mode.rate); 104148773Syokota } 104248773Syokota set_mouse_scaling(sc->kbdc, 1); 104341016Sdfr 104441016Sdfr /* request a data packet and extract sync. bits */ 104541016Sdfr if (get_mouse_status(sc->kbdc, stat, 1, 3) < 3) { 104641016Sdfr printf("psm%d: failed to get data.\n", unit); 104741016Sdfr sc->mode.syncmask[0] = 0; 104841016Sdfr } else { 104941016Sdfr sc->mode.syncmask[1] = stat[0] & sc->mode.syncmask[0]; /* syncbits */ 105041016Sdfr /* the NetScroll Mouse will send three more bytes... Ignore them */ 105141016Sdfr empty_aux_buffer(sc->kbdc, 5); 105241016Sdfr } 105341016Sdfr 105441016Sdfr /* just check the status of the mouse */ 105541016Sdfr /* 105641016Sdfr * NOTE: XXX there are some arcane controller/mouse combinations out 105741016Sdfr * there, which hung the controller unless there is data transmission 105841016Sdfr * after ACK from the mouse. 105941016Sdfr */ 106041016Sdfr if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3) { 106141016Sdfr printf("psm%d: failed to get status.\n", unit); 106241016Sdfr } else { 106341016Sdfr /* 106441016Sdfr * When in its native mode, some mice operate with different 106541016Sdfr * default parameters than in the PS/2 compatible mode. 106641016Sdfr */ 106741016Sdfr sc->dflt_mode.rate = sc->mode.rate = stat[2]; 106841016Sdfr sc->dflt_mode.resolution = sc->mode.resolution = stat[1]; 106941016Sdfr } 107041016Sdfr 107141016Sdfr /* disable the aux port for now... */ 107241016Sdfr if (!set_controller_command_byte(sc->kbdc, 107341016Sdfr KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS, 107441016Sdfr (command_byte & KBD_KBD_CONTROL_BITS) 107541016Sdfr | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) { 107641016Sdfr /* 107741016Sdfr * this is CONTROLLER ERROR; I don't know the proper way to 107841016Sdfr * recover from this error... 107941016Sdfr */ 108041016Sdfr restore_controller(sc->kbdc, command_byte); 108141016Sdfr printf("psm%d: unable to set the command byte.\n", unit); 108241016Sdfr endprobe(ENXIO); 108341016Sdfr } 108441016Sdfr 108558230Syokota /* see if IRQ is available */ 108658230Syokota rid = 0; 108758230Syokota sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1, 108858230Syokota RF_ACTIVE); 108958230Syokota if (sc->intr == NULL) { 109058230Syokota printf("psm%d: unable to allocate the IRQ resource (%d).\n", 109166229Sjhb unit, (int)irq); 109258230Syokota endprobe(ENXIO); 109358230Syokota } else { 109458230Syokota bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr); 109558230Syokota } 109658230Syokota 109741016Sdfr /* done */ 109841016Sdfr kbdc_set_device_mask(sc->kbdc, mask | KBD_AUX_CONTROL_BITS); 109941016Sdfr kbdc_lock(sc->kbdc, FALSE); 110041016Sdfr return (0); 110141016Sdfr} 110241016Sdfr 110341016Sdfrstatic int 110441016Sdfrpsmattach(device_t dev) 110541016Sdfr{ 110641016Sdfr int unit = device_get_unit(dev); 110741016Sdfr struct psm_softc *sc = device_get_softc(dev); 110845720Speter uintptr_t irq; 110958230Syokota int error; 111058230Syokota int rid; 111141016Sdfr 111241016Sdfr if (sc == NULL) /* shouldn't happen */ 111341016Sdfr return (ENXIO); 111441016Sdfr 111541016Sdfr /* Setup initial state */ 111641016Sdfr sc->state = PSM_VALID; 111758230Syokota callout_handle_init(&sc->callout); 111841016Sdfr 111958230Syokota /* Setup our interrupt handler */ 112058230Syokota rid = 0; 112158230Syokota BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq); 112258230Syokota sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1, 112358230Syokota RF_ACTIVE); 112458230Syokota if (sc->intr == NULL) 112558230Syokota return (ENXIO); 112658230Syokota error = BUS_SETUP_INTR(device_get_parent(dev), dev, sc->intr, 112758230Syokota INTR_TYPE_TTY, psmintr, sc, &sc->ih); 112858230Syokota if (error) { 112958230Syokota bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr); 113058230Syokota return (error); 113158230Syokota } 113258230Syokota 113341016Sdfr /* Done */ 113458230Syokota sc->dev = make_dev(&psm_cdevsw, PSM_MKMINOR(unit, FALSE), 0, 0, 0666, 113558230Syokota "psm%d", unit); 113658230Syokota sc->bdev = make_dev(&psm_cdevsw, PSM_MKMINOR(unit, TRUE), 0, 0, 0666, 113758230Syokota "bpsm%d", unit); 113841016Sdfr 113941016Sdfr if (!verbose) { 114041016Sdfr printf("psm%d: model %s, device ID %d\n", 114148778Syokota unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff); 114241016Sdfr } else { 114348778Syokota printf("psm%d: model %s, device ID %d-%02x, %d buttons\n", 114448778Syokota unit, model_name(sc->hw.model), 114548778Syokota sc->hw.hwid & 0x00ff, sc->hw.hwid >> 8, sc->hw.buttons); 114641016Sdfr printf("psm%d: config:%08x, flags:%08x, packet size:%d\n", 114741016Sdfr unit, sc->config, sc->flags, sc->mode.packetsize); 114841016Sdfr printf("psm%d: syncmask:%02x, syncbits:%02x\n", 114941016Sdfr unit, sc->mode.syncmask[0], sc->mode.syncmask[1]); 115041016Sdfr } 115141016Sdfr 115241016Sdfr if (bootverbose) 115341016Sdfr --verbose; 115441016Sdfr 115541016Sdfr return (0); 115641016Sdfr} 115741016Sdfr 115841016Sdfrstatic int 115958230Syokotapsmdetach(device_t dev) 116058230Syokota{ 116158230Syokota struct psm_softc *sc; 116258230Syokota int rid; 116358230Syokota 116458230Syokota sc = device_get_softc(dev); 116558230Syokota if (sc->state & PSM_OPEN) 116658230Syokota return EBUSY; 116758230Syokota 116858230Syokota rid = 0; 116958230Syokota BUS_TEARDOWN_INTR(device_get_parent(dev), dev, sc->intr, sc->ih); 117058230Syokota bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr); 117158230Syokota 117258230Syokota destroy_dev(sc->dev); 117358230Syokota destroy_dev(sc->bdev); 117458230Syokota 117558230Syokota return 0; 117658230Syokota} 117758230Syokota 117858230Syokotastatic int 117941016Sdfrpsmopen(dev_t dev, int flag, int fmt, struct proc *p) 118041016Sdfr{ 118141016Sdfr int unit = PSM_UNIT(dev); 118241016Sdfr struct psm_softc *sc; 118341016Sdfr int command_byte; 118441016Sdfr int err; 118541016Sdfr int s; 118641016Sdfr 118741016Sdfr /* Get device data */ 118841016Sdfr sc = PSM_SOFTC(unit); 118941016Sdfr if ((sc == NULL) || (sc->state & PSM_VALID) == 0) 119041016Sdfr /* the device is no longer valid/functioning */ 119141016Sdfr return (ENXIO); 119241016Sdfr 119341016Sdfr /* Disallow multiple opens */ 119441016Sdfr if (sc->state & PSM_OPEN) 119541016Sdfr return (EBUSY); 119641016Sdfr 119741016Sdfr device_busy(devclass_get_device(psm_devclass, unit)); 119841016Sdfr 119941016Sdfr /* Initialize state */ 120041016Sdfr sc->rsel.si_flags = 0; 120141016Sdfr sc->rsel.si_pid = 0; 120241016Sdfr sc->mode.level = sc->dflt_mode.level; 120341016Sdfr sc->mode.protocol = sc->dflt_mode.protocol; 120458230Syokota sc->watchdog = FALSE; 120541016Sdfr 120641016Sdfr /* flush the event queue */ 120741016Sdfr sc->queue.count = 0; 120841016Sdfr sc->queue.head = 0; 120941016Sdfr sc->queue.tail = 0; 121041016Sdfr sc->status.flags = 0; 121141016Sdfr sc->status.button = 0; 121241016Sdfr sc->status.obutton = 0; 121341016Sdfr sc->status.dx = 0; 121441016Sdfr sc->status.dy = 0; 121541016Sdfr sc->status.dz = 0; 121641016Sdfr sc->button = 0; 121741016Sdfr 121841016Sdfr /* empty input buffer */ 121941016Sdfr bzero(sc->ipacket, sizeof(sc->ipacket)); 122041016Sdfr sc->inputbytes = 0; 122141016Sdfr 122241016Sdfr /* don't let timeout routines in the keyboard driver to poll the kbdc */ 122341016Sdfr if (!kbdc_lock(sc->kbdc, TRUE)) 122441016Sdfr return (EIO); 122541016Sdfr 122641016Sdfr /* save the current controller command byte */ 122741016Sdfr s = spltty(); 122841016Sdfr command_byte = get_controller_command_byte(sc->kbdc); 122941016Sdfr 123041016Sdfr /* enable the aux port and temporalily disable the keyboard */ 123141016Sdfr if ((command_byte == -1) 123241016Sdfr || !set_controller_command_byte(sc->kbdc, 123341016Sdfr kbdc_get_device_mask(sc->kbdc), 123441016Sdfr KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT 123541016Sdfr | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) { 123641016Sdfr /* CONTROLLER ERROR; do you know how to get out of this? */ 123741016Sdfr kbdc_lock(sc->kbdc, FALSE); 123841016Sdfr splx(s); 123941016Sdfr log(LOG_ERR, "psm%d: unable to set the command byte (psmopen).\n", 124041016Sdfr unit); 124141016Sdfr return (EIO); 124241016Sdfr } 124341016Sdfr /* 124441016Sdfr * Now that the keyboard controller is told not to generate 124541016Sdfr * the keyboard and mouse interrupts, call `splx()' to allow 124641016Sdfr * the other tty interrupts. The clock interrupt may also occur, 124741016Sdfr * but timeout routines will be blocked by the poll flag set 124841016Sdfr * via `kbdc_lock()' 124941016Sdfr */ 125041016Sdfr splx(s); 125141016Sdfr 125241016Sdfr /* enable the mouse device */ 125341016Sdfr err = doopen(unit, command_byte); 125441016Sdfr 125541016Sdfr /* done */ 125641016Sdfr if (err == 0) 125741016Sdfr sc->state |= PSM_OPEN; 125841016Sdfr kbdc_lock(sc->kbdc, FALSE); 125941016Sdfr return (err); 126041016Sdfr} 126141016Sdfr 126241016Sdfrstatic int 126341016Sdfrpsmclose(dev_t dev, int flag, int fmt, struct proc *p) 126441016Sdfr{ 126541016Sdfr int unit = PSM_UNIT(dev); 126641016Sdfr struct psm_softc *sc = PSM_SOFTC(unit); 126741016Sdfr int stat[3]; 126841016Sdfr int command_byte; 126941016Sdfr int s; 127041016Sdfr 127141016Sdfr /* don't let timeout routines in the keyboard driver to poll the kbdc */ 127241016Sdfr if (!kbdc_lock(sc->kbdc, TRUE)) 127341016Sdfr return (EIO); 127441016Sdfr 127541016Sdfr /* save the current controller command byte */ 127641016Sdfr s = spltty(); 127741016Sdfr command_byte = get_controller_command_byte(sc->kbdc); 127841016Sdfr if (command_byte == -1) { 127941016Sdfr kbdc_lock(sc->kbdc, FALSE); 128041016Sdfr splx(s); 128141016Sdfr return (EIO); 128241016Sdfr } 128341016Sdfr 128441016Sdfr /* disable the aux interrupt and temporalily disable the keyboard */ 128541016Sdfr if (!set_controller_command_byte(sc->kbdc, 128641016Sdfr kbdc_get_device_mask(sc->kbdc), 128741016Sdfr KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT 128841016Sdfr | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) { 128941016Sdfr log(LOG_ERR, "psm%d: failed to disable the aux int (psmclose).\n", 129058230Syokota unit); 129141016Sdfr /* CONTROLLER ERROR; 129241016Sdfr * NOTE: we shall force our way through. Because the only 129341016Sdfr * ill effect we shall see is that we may not be able 129441016Sdfr * to read ACK from the mouse, and it doesn't matter much 129541016Sdfr * so long as the mouse will accept the DISABLE command. 129641016Sdfr */ 129741016Sdfr } 129841016Sdfr splx(s); 129941016Sdfr 130058230Syokota /* stop the watchdog timer */ 130166229Sjhb untimeout(psmtimeout, (void *)(uintptr_t)unit, sc->callout); 130258230Syokota callout_handle_init(&sc->callout); 130358230Syokota 130441016Sdfr /* remove anything left in the output buffer */ 130541016Sdfr empty_aux_buffer(sc->kbdc, 10); 130641016Sdfr 130741016Sdfr /* disable the aux device, port and interrupt */ 130841016Sdfr if (sc->state & PSM_VALID) { 130941016Sdfr if (!disable_aux_dev(sc->kbdc)) { 131041016Sdfr /* MOUSE ERROR; 131141016Sdfr * NOTE: we don't return error and continue, pretending 131241016Sdfr * we have successfully disabled the device. It's OK because 131341016Sdfr * the interrupt routine will discard any data from the mouse 131441016Sdfr * hereafter. 131541016Sdfr */ 131641016Sdfr log(LOG_ERR, "psm%d: failed to disable the device (psmclose).\n", 131758230Syokota unit); 131841016Sdfr } 131941016Sdfr 132041016Sdfr if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3) 132141016Sdfr log(LOG_DEBUG, "psm%d: failed to get status (psmclose).\n", 132258230Syokota unit); 132341016Sdfr } 132441016Sdfr 132541016Sdfr if (!set_controller_command_byte(sc->kbdc, 132641016Sdfr kbdc_get_device_mask(sc->kbdc), 132741016Sdfr (command_byte & KBD_KBD_CONTROL_BITS) 132841016Sdfr | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) { 132941016Sdfr /* CONTROLLER ERROR; 133041016Sdfr * we shall ignore this error; see the above comment. 133141016Sdfr */ 133241016Sdfr log(LOG_ERR, "psm%d: failed to disable the aux port (psmclose).\n", 133358230Syokota unit); 133441016Sdfr } 133541016Sdfr 133641016Sdfr /* remove anything left in the output buffer */ 133741016Sdfr empty_aux_buffer(sc->kbdc, 10); 133841016Sdfr 133941016Sdfr /* close is almost always successful */ 134041016Sdfr sc->state &= ~PSM_OPEN; 134141016Sdfr kbdc_lock(sc->kbdc, FALSE); 134241016Sdfr device_unbusy(devclass_get_device(psm_devclass, unit)); 134341016Sdfr return (0); 134441016Sdfr} 134541016Sdfr 134641016Sdfrstatic int 134741016Sdfrtame_mouse(struct psm_softc *sc, mousestatus_t *status, unsigned char *buf) 134841016Sdfr{ 134941016Sdfr static unsigned char butmapps2[8] = { 135041016Sdfr 0, 135141016Sdfr MOUSE_PS2_BUTTON1DOWN, 135241016Sdfr MOUSE_PS2_BUTTON2DOWN, 135341016Sdfr MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN, 135441016Sdfr MOUSE_PS2_BUTTON3DOWN, 135541016Sdfr MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON3DOWN, 135641016Sdfr MOUSE_PS2_BUTTON2DOWN | MOUSE_PS2_BUTTON3DOWN, 135741016Sdfr MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN | MOUSE_PS2_BUTTON3DOWN, 135841016Sdfr }; 135941016Sdfr static unsigned char butmapmsc[8] = { 136041016Sdfr MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP, 136141016Sdfr MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP, 136241016Sdfr MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP, 136341016Sdfr MOUSE_MSC_BUTTON3UP, 136441016Sdfr MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP, 136541016Sdfr MOUSE_MSC_BUTTON2UP, 136641016Sdfr MOUSE_MSC_BUTTON1UP, 136741016Sdfr 0, 136841016Sdfr }; 136941016Sdfr int mapped; 137041016Sdfr int i; 137141016Sdfr 137241016Sdfr if (sc->mode.level == PSM_LEVEL_BASE) { 137341016Sdfr mapped = status->button & ~MOUSE_BUTTON4DOWN; 137441016Sdfr if (status->button & MOUSE_BUTTON4DOWN) 137541016Sdfr mapped |= MOUSE_BUTTON1DOWN; 137641016Sdfr status->button = mapped; 137741016Sdfr buf[0] = MOUSE_PS2_SYNC | butmapps2[mapped & MOUSE_STDBUTTONS]; 137841016Sdfr i = max(min(status->dx, 255), -256); 137941016Sdfr if (i < 0) 138041016Sdfr buf[0] |= MOUSE_PS2_XNEG; 138141016Sdfr buf[1] = i; 138241016Sdfr i = max(min(status->dy, 255), -256); 138341016Sdfr if (i < 0) 138441016Sdfr buf[0] |= MOUSE_PS2_YNEG; 138541016Sdfr buf[2] = i; 138641016Sdfr return MOUSE_PS2_PACKETSIZE; 138741016Sdfr } else if (sc->mode.level == PSM_LEVEL_STANDARD) { 138841016Sdfr buf[0] = MOUSE_MSC_SYNC | butmapmsc[status->button & MOUSE_STDBUTTONS]; 138941016Sdfr i = max(min(status->dx, 255), -256); 139041016Sdfr buf[1] = i >> 1; 139141016Sdfr buf[3] = i - buf[1]; 139241016Sdfr i = max(min(status->dy, 255), -256); 139341016Sdfr buf[2] = i >> 1; 139441016Sdfr buf[4] = i - buf[2]; 139541016Sdfr i = max(min(status->dz, 127), -128); 139641016Sdfr buf[5] = (i >> 1) & 0x7f; 139741016Sdfr buf[6] = (i - (i >> 1)) & 0x7f; 139841016Sdfr buf[7] = (~status->button >> 3) & 0x7f; 139941016Sdfr return MOUSE_SYS_PACKETSIZE; 140041016Sdfr } 140141016Sdfr return sc->inputbytes;; 140241016Sdfr} 140341016Sdfr 140441016Sdfrstatic int 140541016Sdfrpsmread(dev_t dev, struct uio *uio, int flag) 140641016Sdfr{ 140741016Sdfr register struct psm_softc *sc = PSM_SOFTC(PSM_UNIT(dev)); 140841016Sdfr unsigned char buf[PSM_SMALLBUFSIZE]; 140941016Sdfr int error = 0; 141041016Sdfr int s; 141141016Sdfr int l; 141241016Sdfr 141341016Sdfr if ((sc->state & PSM_VALID) == 0) 141441016Sdfr return EIO; 141541016Sdfr 141641016Sdfr /* block until mouse activity occured */ 141741016Sdfr s = spltty(); 141841016Sdfr while (sc->queue.count <= 0) { 141941016Sdfr if (PSM_NBLOCKIO(dev)) { 142041016Sdfr splx(s); 142141016Sdfr return EWOULDBLOCK; 142241016Sdfr } 142341016Sdfr sc->state |= PSM_ASLP; 142441016Sdfr error = tsleep((caddr_t) sc, PZERO | PCATCH, "psmrea", 0); 142541016Sdfr sc->state &= ~PSM_ASLP; 142641016Sdfr if (error) { 142741016Sdfr splx(s); 142841016Sdfr return error; 142941016Sdfr } else if ((sc->state & PSM_VALID) == 0) { 143041016Sdfr /* the device disappeared! */ 143141016Sdfr splx(s); 143241016Sdfr return EIO; 143341016Sdfr } 143441016Sdfr } 143541016Sdfr splx(s); 143641016Sdfr 143741016Sdfr /* copy data to the user land */ 143841016Sdfr while ((sc->queue.count > 0) && (uio->uio_resid > 0)) { 143941016Sdfr s = spltty(); 144041016Sdfr l = min(sc->queue.count, uio->uio_resid); 144141016Sdfr if (l > sizeof(buf)) 144241016Sdfr l = sizeof(buf); 144341016Sdfr if (l > sizeof(sc->queue.buf) - sc->queue.head) { 144441016Sdfr bcopy(&sc->queue.buf[sc->queue.head], &buf[0], 144541016Sdfr sizeof(sc->queue.buf) - sc->queue.head); 144641016Sdfr bcopy(&sc->queue.buf[0], 144741016Sdfr &buf[sizeof(sc->queue.buf) - sc->queue.head], 144841016Sdfr l - (sizeof(sc->queue.buf) - sc->queue.head)); 144941016Sdfr } else { 145041016Sdfr bcopy(&sc->queue.buf[sc->queue.head], &buf[0], l); 145141016Sdfr } 145241016Sdfr sc->queue.count -= l; 145341016Sdfr sc->queue.head = (sc->queue.head + l) % sizeof(sc->queue.buf); 145441016Sdfr splx(s); 145541016Sdfr error = uiomove(buf, l, uio); 145641016Sdfr if (error) 145741016Sdfr break; 145841016Sdfr } 145941016Sdfr 146041016Sdfr return error; 146141016Sdfr} 146241016Sdfr 146341016Sdfrstatic int 146441016Sdfrblock_mouse_data(struct psm_softc *sc, int *c) 146541016Sdfr{ 146641016Sdfr int s; 146741016Sdfr 146841016Sdfr if (!kbdc_lock(sc->kbdc, TRUE)) 146941016Sdfr return EIO; 147041016Sdfr 147141016Sdfr s = spltty(); 147241016Sdfr *c = get_controller_command_byte(sc->kbdc); 147341016Sdfr if ((*c == -1) 147441016Sdfr || !set_controller_command_byte(sc->kbdc, 147541016Sdfr kbdc_get_device_mask(sc->kbdc), 147641016Sdfr KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT 147741016Sdfr | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) { 147841016Sdfr /* this is CONTROLLER ERROR */ 147941016Sdfr splx(s); 148041016Sdfr kbdc_lock(sc->kbdc, FALSE); 148141016Sdfr return EIO; 148241016Sdfr } 148341016Sdfr 148441016Sdfr /* 148541016Sdfr * The device may be in the middle of status data transmission. 148641016Sdfr * The transmission will be interrupted, thus, incomplete status 148741016Sdfr * data must be discarded. Although the aux interrupt is disabled 148841016Sdfr * at the keyboard controller level, at most one aux interrupt 148941016Sdfr * may have already been pending and a data byte is in the 149041016Sdfr * output buffer; throw it away. Note that the second argument 149141016Sdfr * to `empty_aux_buffer()' is zero, so that the call will just 149241016Sdfr * flush the internal queue. 149341016Sdfr * `psmintr()' will be invoked after `splx()' if an interrupt is 149441016Sdfr * pending; it will see no data and returns immediately. 149541016Sdfr */ 149641016Sdfr empty_aux_buffer(sc->kbdc, 0); /* flush the queue */ 149741016Sdfr read_aux_data_no_wait(sc->kbdc); /* throw away data if any */ 149841016Sdfr sc->inputbytes = 0; 149941016Sdfr splx(s); 150041016Sdfr 150141016Sdfr return 0; 150241016Sdfr} 150341016Sdfr 150441016Sdfrstatic int 150541016Sdfrunblock_mouse_data(struct psm_softc *sc, int c) 150641016Sdfr{ 150741016Sdfr int error = 0; 150841016Sdfr 150941016Sdfr /* 151041016Sdfr * We may have seen a part of status data during `set_mouse_XXX()'. 151141016Sdfr * they have been queued; flush it. 151241016Sdfr */ 151341016Sdfr empty_aux_buffer(sc->kbdc, 0); 151441016Sdfr 151541016Sdfr /* restore ports and interrupt */ 151641016Sdfr if (!set_controller_command_byte(sc->kbdc, 151741016Sdfr kbdc_get_device_mask(sc->kbdc), 151841016Sdfr c & (KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS))) { 151941016Sdfr /* CONTROLLER ERROR; this is serious, we may have 152041016Sdfr * been left with the inaccessible keyboard and 152141016Sdfr * the disabled mouse interrupt. 152241016Sdfr */ 152341016Sdfr error = EIO; 152441016Sdfr } 152541016Sdfr 152641016Sdfr kbdc_lock(sc->kbdc, FALSE); 152741016Sdfr return error; 152841016Sdfr} 152941016Sdfr 153041016Sdfrstatic int 153141016Sdfrpsmioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) 153241016Sdfr{ 153341016Sdfr struct psm_softc *sc = PSM_SOFTC(PSM_UNIT(dev)); 153441016Sdfr mousemode_t mode; 153541016Sdfr mousestatus_t status; 153641016Sdfr#if (defined(MOUSE_GETVARS)) 153741016Sdfr mousevar_t *var; 153841016Sdfr#endif 153941016Sdfr mousedata_t *data; 154041016Sdfr int stat[3]; 154141016Sdfr int command_byte; 154241016Sdfr int error = 0; 154341016Sdfr int s; 154441016Sdfr 154541016Sdfr /* Perform IOCTL command */ 154641016Sdfr switch (cmd) { 154741016Sdfr 154841016Sdfr case OLD_MOUSE_GETHWINFO: 154941016Sdfr s = spltty(); 155041016Sdfr ((old_mousehw_t *)addr)->buttons = sc->hw.buttons; 155141016Sdfr ((old_mousehw_t *)addr)->iftype = sc->hw.iftype; 155241016Sdfr ((old_mousehw_t *)addr)->type = sc->hw.type; 155348778Syokota ((old_mousehw_t *)addr)->hwid = sc->hw.hwid & 0x00ff; 155441016Sdfr splx(s); 155541016Sdfr break; 155641016Sdfr 155741016Sdfr case MOUSE_GETHWINFO: 155841016Sdfr s = spltty(); 155941016Sdfr *(mousehw_t *)addr = sc->hw; 156041016Sdfr if (sc->mode.level == PSM_LEVEL_BASE) 156141016Sdfr ((mousehw_t *)addr)->model = MOUSE_MODEL_GENERIC; 156241016Sdfr splx(s); 156341016Sdfr break; 156441016Sdfr 156541016Sdfr case OLD_MOUSE_GETMODE: 156641016Sdfr s = spltty(); 156741016Sdfr switch (sc->mode.level) { 156841016Sdfr case PSM_LEVEL_BASE: 156941016Sdfr ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2; 157041016Sdfr break; 157141016Sdfr case PSM_LEVEL_STANDARD: 157241016Sdfr ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE; 157341016Sdfr break; 157441016Sdfr case PSM_LEVEL_NATIVE: 157541016Sdfr ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2; 157641016Sdfr break; 157741016Sdfr } 157841016Sdfr ((old_mousemode_t *)addr)->rate = sc->mode.rate; 157941016Sdfr ((old_mousemode_t *)addr)->resolution = sc->mode.resolution; 158041016Sdfr ((old_mousemode_t *)addr)->accelfactor = sc->mode.accelfactor; 158141016Sdfr splx(s); 158241016Sdfr break; 158341016Sdfr 158441016Sdfr case MOUSE_GETMODE: 158541016Sdfr s = spltty(); 158641016Sdfr *(mousemode_t *)addr = sc->mode; 158741016Sdfr ((mousemode_t *)addr)->resolution = 158841016Sdfr MOUSE_RES_LOW - sc->mode.resolution; 158941016Sdfr switch (sc->mode.level) { 159041016Sdfr case PSM_LEVEL_BASE: 159141016Sdfr ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2; 159241016Sdfr ((mousemode_t *)addr)->packetsize = MOUSE_PS2_PACKETSIZE; 159341016Sdfr break; 159441016Sdfr case PSM_LEVEL_STANDARD: 159541016Sdfr ((mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE; 159641016Sdfr ((mousemode_t *)addr)->packetsize = MOUSE_SYS_PACKETSIZE; 159741016Sdfr ((mousemode_t *)addr)->syncmask[0] = MOUSE_SYS_SYNCMASK; 159841016Sdfr ((mousemode_t *)addr)->syncmask[1] = MOUSE_SYS_SYNC; 159941016Sdfr break; 160041016Sdfr case PSM_LEVEL_NATIVE: 160141016Sdfr /* FIXME: this isn't quite correct... XXX */ 160241016Sdfr ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2; 160341016Sdfr break; 160441016Sdfr } 160541016Sdfr splx(s); 160641016Sdfr break; 160741016Sdfr 160841016Sdfr case OLD_MOUSE_SETMODE: 160941016Sdfr case MOUSE_SETMODE: 161041016Sdfr if (cmd == OLD_MOUSE_SETMODE) { 161141016Sdfr mode.rate = ((old_mousemode_t *)addr)->rate; 161241016Sdfr /* 161341016Sdfr * resolution old I/F new I/F 161441016Sdfr * default 0 0 161541016Sdfr * low 1 -2 161641016Sdfr * medium low 2 -3 161741016Sdfr * medium high 3 -4 161841016Sdfr * high 4 -5 161941016Sdfr */ 162041016Sdfr if (((old_mousemode_t *)addr)->resolution > 0) 162141016Sdfr mode.resolution = -((old_mousemode_t *)addr)->resolution - 1; 162241016Sdfr mode.accelfactor = ((old_mousemode_t *)addr)->accelfactor; 162341016Sdfr mode.level = -1; 162441016Sdfr } else { 162541016Sdfr mode = *(mousemode_t *)addr; 162641016Sdfr } 162741016Sdfr 162841016Sdfr /* adjust and validate parameters. */ 162941016Sdfr if (mode.rate > UCHAR_MAX) 163041016Sdfr return EINVAL; 163141016Sdfr if (mode.rate == 0) 163241016Sdfr mode.rate = sc->dflt_mode.rate; 163341016Sdfr else if (mode.rate == -1) 163441016Sdfr /* don't change the current setting */ 163541016Sdfr ; 163641016Sdfr else if (mode.rate < 0) 163741016Sdfr return EINVAL; 163841016Sdfr if (mode.resolution >= UCHAR_MAX) 163941016Sdfr return EINVAL; 164041016Sdfr if (mode.resolution >= 200) 164141016Sdfr mode.resolution = MOUSE_RES_HIGH; 164241016Sdfr else if (mode.resolution >= 100) 164341016Sdfr mode.resolution = MOUSE_RES_MEDIUMHIGH; 164441016Sdfr else if (mode.resolution >= 50) 164541016Sdfr mode.resolution = MOUSE_RES_MEDIUMLOW; 164641016Sdfr else if (mode.resolution > 0) 164741016Sdfr mode.resolution = MOUSE_RES_LOW; 164841016Sdfr if (mode.resolution == MOUSE_RES_DEFAULT) 164941016Sdfr mode.resolution = sc->dflt_mode.resolution; 165041016Sdfr else if (mode.resolution == -1) 165141016Sdfr /* don't change the current setting */ 165241016Sdfr ; 165341016Sdfr else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */ 165441016Sdfr mode.resolution = MOUSE_RES_LOW - mode.resolution; 165541016Sdfr if (mode.level == -1) 165641016Sdfr /* don't change the current setting */ 165741016Sdfr mode.level = sc->mode.level; 165841016Sdfr else if ((mode.level < PSM_LEVEL_MIN) || (mode.level > PSM_LEVEL_MAX)) 165941016Sdfr return EINVAL; 166041016Sdfr if (mode.accelfactor == -1) 166141016Sdfr /* don't change the current setting */ 166241016Sdfr mode.accelfactor = sc->mode.accelfactor; 166341016Sdfr else if (mode.accelfactor < 0) 166441016Sdfr return EINVAL; 166541016Sdfr 166641016Sdfr /* don't allow anybody to poll the keyboard controller */ 166741016Sdfr error = block_mouse_data(sc, &command_byte); 166841016Sdfr if (error) 166941016Sdfr return error; 167041016Sdfr 167141016Sdfr /* set mouse parameters */ 167241016Sdfr if (mode.rate > 0) 167341016Sdfr mode.rate = set_mouse_sampling_rate(sc->kbdc, mode.rate); 167441016Sdfr if (mode.resolution >= 0) 167541016Sdfr mode.resolution = set_mouse_resolution(sc->kbdc, mode.resolution); 167641016Sdfr set_mouse_scaling(sc->kbdc, 1); 167741016Sdfr get_mouse_status(sc->kbdc, stat, 0, 3); 167841016Sdfr 167941016Sdfr s = spltty(); 168041016Sdfr sc->mode.rate = mode.rate; 168141016Sdfr sc->mode.resolution = mode.resolution; 168241016Sdfr sc->mode.accelfactor = mode.accelfactor; 168341016Sdfr sc->mode.level = mode.level; 168441016Sdfr splx(s); 168541016Sdfr 168641016Sdfr unblock_mouse_data(sc, command_byte); 168741016Sdfr break; 168841016Sdfr 168941016Sdfr case MOUSE_GETLEVEL: 169041016Sdfr *(int *)addr = sc->mode.level; 169141016Sdfr break; 169241016Sdfr 169341016Sdfr case MOUSE_SETLEVEL: 169441016Sdfr if ((*(int *)addr < PSM_LEVEL_MIN) || (*(int *)addr > PSM_LEVEL_MAX)) 169541016Sdfr return EINVAL; 169641016Sdfr sc->mode.level = *(int *)addr; 169741016Sdfr break; 169841016Sdfr 169941016Sdfr case MOUSE_GETSTATUS: 170041016Sdfr s = spltty(); 170141016Sdfr status = sc->status; 170241016Sdfr sc->status.flags = 0; 170341016Sdfr sc->status.obutton = sc->status.button; 170441016Sdfr sc->status.button = 0; 170541016Sdfr sc->status.dx = 0; 170641016Sdfr sc->status.dy = 0; 170741016Sdfr sc->status.dz = 0; 170841016Sdfr splx(s); 170941016Sdfr *(mousestatus_t *)addr = status; 171041016Sdfr break; 171141016Sdfr 171241016Sdfr#if (defined(MOUSE_GETVARS)) 171341016Sdfr case MOUSE_GETVARS: 171441016Sdfr var = (mousevar_t *)addr; 171541016Sdfr bzero(var, sizeof(*var)); 171641016Sdfr s = spltty(); 171741016Sdfr var->var[0] = MOUSE_VARS_PS2_SIG; 171841016Sdfr var->var[1] = sc->config; 171941016Sdfr var->var[2] = sc->flags; 172041016Sdfr splx(s); 172141016Sdfr break; 172241016Sdfr 172341016Sdfr case MOUSE_SETVARS: 172441016Sdfr return ENODEV; 172541016Sdfr#endif /* MOUSE_GETVARS */ 172641016Sdfr 172741016Sdfr case MOUSE_READSTATE: 172841016Sdfr case MOUSE_READDATA: 172941016Sdfr data = (mousedata_t *)addr; 173041016Sdfr if (data->len > sizeof(data->buf)/sizeof(data->buf[0])) 173141016Sdfr return EINVAL; 173241016Sdfr 173341016Sdfr error = block_mouse_data(sc, &command_byte); 173441016Sdfr if (error) 173541016Sdfr return error; 173641016Sdfr if ((data->len = get_mouse_status(sc->kbdc, data->buf, 173741016Sdfr (cmd == MOUSE_READDATA) ? 1 : 0, data->len)) <= 0) 173841016Sdfr error = EIO; 173941016Sdfr unblock_mouse_data(sc, command_byte); 174041016Sdfr break; 174141016Sdfr 174241016Sdfr#if (defined(MOUSE_SETRESOLUTION)) 174341016Sdfr case MOUSE_SETRESOLUTION: 174441016Sdfr mode.resolution = *(int *)addr; 174541016Sdfr if (mode.resolution >= UCHAR_MAX) 174641016Sdfr return EINVAL; 174741016Sdfr else if (mode.resolution >= 200) 174841016Sdfr mode.resolution = MOUSE_RES_HIGH; 174941016Sdfr else if (mode.resolution >= 100) 175041016Sdfr mode.resolution = MOUSE_RES_MEDIUMHIGH; 175141016Sdfr else if (mode.resolution >= 50) 175241016Sdfr mode.resolution = MOUSE_RES_MEDIUMLOW; 175341016Sdfr else if (mode.resolution > 0) 175441016Sdfr mode.resolution = MOUSE_RES_LOW; 175541016Sdfr if (mode.resolution == MOUSE_RES_DEFAULT) 175641016Sdfr mode.resolution = sc->dflt_mode.resolution; 175741016Sdfr else if (mode.resolution == -1) 175841016Sdfr mode.resolution = sc->mode.resolution; 175941016Sdfr else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */ 176041016Sdfr mode.resolution = MOUSE_RES_LOW - mode.resolution; 176141016Sdfr 176241016Sdfr error = block_mouse_data(sc, &command_byte); 176341016Sdfr if (error) 176441016Sdfr return error; 176541016Sdfr sc->mode.resolution = set_mouse_resolution(sc->kbdc, mode.resolution); 176641016Sdfr if (sc->mode.resolution != mode.resolution) 176741016Sdfr error = EIO; 176841016Sdfr unblock_mouse_data(sc, command_byte); 176941016Sdfr break; 177041016Sdfr#endif /* MOUSE_SETRESOLUTION */ 177141016Sdfr 177241016Sdfr#if (defined(MOUSE_SETRATE)) 177341016Sdfr case MOUSE_SETRATE: 177441016Sdfr mode.rate = *(int *)addr; 177541016Sdfr if (mode.rate > UCHAR_MAX) 177641016Sdfr return EINVAL; 177741016Sdfr if (mode.rate == 0) 177841016Sdfr mode.rate = sc->dflt_mode.rate; 177941016Sdfr else if (mode.rate < 0) 178041016Sdfr mode.rate = sc->mode.rate; 178141016Sdfr 178241016Sdfr error = block_mouse_data(sc, &command_byte); 178341016Sdfr if (error) 178441016Sdfr return error; 178541016Sdfr sc->mode.rate = set_mouse_sampling_rate(sc->kbdc, mode.rate); 178641016Sdfr if (sc->mode.rate != mode.rate) 178741016Sdfr error = EIO; 178841016Sdfr unblock_mouse_data(sc, command_byte); 178941016Sdfr break; 179041016Sdfr#endif /* MOUSE_SETRATE */ 179141016Sdfr 179241016Sdfr#if (defined(MOUSE_SETSCALING)) 179341016Sdfr case MOUSE_SETSCALING: 179441016Sdfr if ((*(int *)addr <= 0) || (*(int *)addr > 2)) 179541016Sdfr return EINVAL; 179641016Sdfr 179741016Sdfr error = block_mouse_data(sc, &command_byte); 179841016Sdfr if (error) 179941016Sdfr return error; 180041016Sdfr if (!set_mouse_scaling(sc->kbdc, *(int *)addr)) 180141016Sdfr error = EIO; 180241016Sdfr unblock_mouse_data(sc, command_byte); 180341016Sdfr break; 180441016Sdfr#endif /* MOUSE_SETSCALING */ 180541016Sdfr 180641016Sdfr#if (defined(MOUSE_GETHWID)) 180741016Sdfr case MOUSE_GETHWID: 180841016Sdfr error = block_mouse_data(sc, &command_byte); 180941016Sdfr if (error) 181041016Sdfr return error; 181148778Syokota sc->hw.hwid &= ~0x00ff; 181248778Syokota sc->hw.hwid |= get_aux_id(sc->kbdc); 181348778Syokota *(int *)addr = sc->hw.hwid & 0x00ff; 181441016Sdfr unblock_mouse_data(sc, command_byte); 181541016Sdfr break; 181641016Sdfr#endif /* MOUSE_GETHWID */ 181741016Sdfr 181841016Sdfr default: 181941016Sdfr return ENOTTY; 182041016Sdfr } 182141016Sdfr 182241016Sdfr return error; 182341016Sdfr} 182441016Sdfr 182541016Sdfrstatic void 182658230Syokotapsmtimeout(void *arg) 182758230Syokota{ 182858230Syokota struct psm_softc *sc; 182958230Syokota int unit; 183065045Syokota int s; 183158230Syokota 183266229Sjhb unit = (int)(uintptr_t)arg; 183358230Syokota sc = devclass_get_softc(psm_devclass, unit); 183465045Syokota s = spltty(); 183563746Syokota if (sc->watchdog && kbdc_lock(sc->kbdc, TRUE)) { 183658230Syokota if (verbose >= 4) 183758230Syokota log(LOG_DEBUG, "psm%d: lost interrupt?\n", unit); 183858230Syokota psmintr(sc); 183963746Syokota kbdc_lock(sc->kbdc, FALSE); 184058230Syokota } 184158230Syokota sc->watchdog = TRUE; 184265045Syokota splx(s); 184366229Sjhb sc->callout = timeout(psmtimeout, (void *)(uintptr_t)unit, hz); 184458230Syokota} 184558230Syokota 184658230Syokotastatic void 184741016Sdfrpsmintr(void *arg) 184841016Sdfr{ 184941016Sdfr /* 185041016Sdfr * the table to turn PS/2 mouse button bits (MOUSE_PS2_BUTTON?DOWN) 185141016Sdfr * into `mousestatus' button bits (MOUSE_BUTTON?DOWN). 185241016Sdfr */ 185341016Sdfr static int butmap[8] = { 185441016Sdfr 0, 185541016Sdfr MOUSE_BUTTON1DOWN, 185641016Sdfr MOUSE_BUTTON3DOWN, 185741016Sdfr MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, 185841016Sdfr MOUSE_BUTTON2DOWN, 185941016Sdfr MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN, 186041016Sdfr MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN, 186141016Sdfr MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN 186241016Sdfr }; 186349965Syokota static int butmap_versapad[8] = { 186449965Syokota 0, 186549965Syokota MOUSE_BUTTON3DOWN, 186649965Syokota 0, 186749965Syokota MOUSE_BUTTON3DOWN, 186849965Syokota MOUSE_BUTTON1DOWN, 186949965Syokota MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, 187049965Syokota MOUSE_BUTTON1DOWN, 187149965Syokota MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN 187249965Syokota }; 187341016Sdfr register struct psm_softc *sc = arg; 187441016Sdfr mousestatus_t ms; 187541016Sdfr int x, y, z; 187641016Sdfr int c; 187741016Sdfr int l; 187849965Syokota int x0, y0; 187941016Sdfr 188041016Sdfr /* read until there is nothing to read */ 188141016Sdfr while((c = read_aux_data_no_wait(sc->kbdc)) != -1) { 188241016Sdfr 188341016Sdfr /* discard the byte if the device is not open */ 188441016Sdfr if ((sc->state & PSM_OPEN) == 0) 188541016Sdfr continue; 188641016Sdfr 188741016Sdfr sc->ipacket[sc->inputbytes++] = c; 188841016Sdfr if (sc->inputbytes < sc->mode.packetsize) 188941016Sdfr continue; 189041016Sdfr 189141016Sdfr#if 0 189241016Sdfr log(LOG_DEBUG, "psmintr: %02x %02x %02x %02x %02x %02x\n", 189341016Sdfr sc->ipacket[0], sc->ipacket[1], sc->ipacket[2], 189441016Sdfr sc->ipacket[3], sc->ipacket[4], sc->ipacket[5]); 189541016Sdfr#endif 189641016Sdfr 189741016Sdfr c = sc->ipacket[0]; 189841016Sdfr 189963746Syokota if ((c & sc->mode.syncmask[0]) != sc->mode.syncmask[1]) { 190063746Syokota log(LOG_DEBUG, "psmintr: out of sync (%04x != %04x).\n", 190163746Syokota c & sc->mode.syncmask[0], sc->mode.syncmask[1]); 190263746Syokota sc->inputbytes = 0; 190363746Syokota continue; 190463746Syokota } 190563746Syokota 190649965Syokota /* 190741016Sdfr * A kludge for Kensington device! 190841016Sdfr * The MSB of the horizontal count appears to be stored in 190958230Syokota * a strange place. 191041016Sdfr */ 191158230Syokota if (sc->hw.model == MOUSE_MODEL_THINK) 191249965Syokota sc->ipacket[1] |= (c & MOUSE_PS2_XOVERFLOW) ? 0x80 : 0; 191341016Sdfr 191441016Sdfr /* ignore the overflow bits... */ 191541016Sdfr x = (c & MOUSE_PS2_XNEG) ? sc->ipacket[1] - 256 : sc->ipacket[1]; 191641016Sdfr y = (c & MOUSE_PS2_YNEG) ? sc->ipacket[2] - 256 : sc->ipacket[2]; 191741016Sdfr z = 0; 191841016Sdfr ms.obutton = sc->button; /* previous button state */ 191941016Sdfr ms.button = butmap[c & MOUSE_PS2_BUTTONS]; 192045789Speter /* `tapping' action */ 192145789Speter if (sc->config & PSM_CONFIG_FORCETAP) 192245789Speter ms.button |= ((c & MOUSE_PS2_TAP)) ? 0 : MOUSE_BUTTON4DOWN; 192341016Sdfr 192441016Sdfr switch (sc->hw.model) { 192541016Sdfr 192658230Syokota case MOUSE_MODEL_EXPLORER: 192758230Syokota /* 192858230Syokota * b7 b6 b5 b4 b3 b2 b1 b0 192958230Syokota * byte 1: oy ox sy sx 1 M R L 193058230Syokota * byte 2: x x x x x x x x 193158230Syokota * byte 3: y y y y y y y y 193258230Syokota * byte 4: * * S2 S1 s d2 d1 d0 193358230Syokota * 193458230Syokota * L, M, R, S1, S2: left, middle, right and side buttons 193558230Syokota * s: wheel data sign bit 193658230Syokota * d2-d0: wheel data 193758230Syokota */ 193858230Syokota z = (sc->ipacket[3] & MOUSE_EXPLORER_ZNEG) 193958230Syokota ? (sc->ipacket[3] & 0x0f) - 16 : (sc->ipacket[3] & 0x0f); 194058230Syokota ms.button |= (sc->ipacket[3] & MOUSE_EXPLORER_BUTTON4DOWN) 194158230Syokota ? MOUSE_BUTTON4DOWN : 0; 194258230Syokota ms.button |= (sc->ipacket[3] & MOUSE_EXPLORER_BUTTON5DOWN) 194358230Syokota ? MOUSE_BUTTON5DOWN : 0; 194458230Syokota break; 194558230Syokota 194641016Sdfr case MOUSE_MODEL_INTELLI: 194741016Sdfr case MOUSE_MODEL_NET: 194841016Sdfr /* wheel data is in the fourth byte */ 194941016Sdfr z = (char)sc->ipacket[3]; 195058230Syokota /* some mice may send 7 when there is no Z movement?! XXX */ 195158230Syokota if ((z >= 7) || (z <= -7)) 195258230Syokota z = 0; 195358230Syokota /* some compatible mice have additional buttons */ 195458230Syokota ms.button |= (c & MOUSE_PS2INTELLI_BUTTON4DOWN) 195558230Syokota ? MOUSE_BUTTON4DOWN : 0; 195658230Syokota ms.button |= (c & MOUSE_PS2INTELLI_BUTTON5DOWN) 195758230Syokota ? MOUSE_BUTTON5DOWN : 0; 195841016Sdfr break; 195941016Sdfr 196041016Sdfr case MOUSE_MODEL_MOUSEMANPLUS: 196148778Syokota /* 196248778Syokota * PS2++ protocl packet 196348778Syokota * 196448778Syokota * b7 b6 b5 b4 b3 b2 b1 b0 196548778Syokota * byte 1: * 1 p3 p2 1 * * * 196648778Syokota * byte 2: c1 c2 p1 p0 d1 d0 1 0 196748778Syokota * 196848778Syokota * p3-p0: packet type 196948778Syokota * c1, c2: c1 & c2 == 1, if p2 == 0 197048778Syokota * c1 & c2 == 0, if p2 == 1 197148778Syokota * 197248778Syokota * packet type: 0 (device type) 197348778Syokota * See comments in enable_mmanplus() below. 197448778Syokota * 197548778Syokota * packet type: 1 (wheel data) 197648778Syokota * 197748778Syokota * b7 b6 b5 b4 b3 b2 b1 b0 197848778Syokota * byte 3: h * B5 B4 s d2 d1 d0 197948778Syokota * 198048778Syokota * h: 1, if horizontal roller data 198148778Syokota * 0, if vertical roller data 198248778Syokota * B4, B5: button 4 and 5 198348778Syokota * s: sign bit 198448778Syokota * d2-d0: roller data 198548778Syokota * 198648778Syokota * packet type: 2 (reserved) 198748778Syokota */ 198848778Syokota if (((c & MOUSE_PS2PLUS_SYNCMASK) == MOUSE_PS2PLUS_SYNC) 198948778Syokota && (abs(x) > 191) 199048778Syokota && MOUSE_PS2PLUS_CHECKBITS(sc->ipacket)) { 199141016Sdfr /* the extended data packet encodes button and wheel events */ 199248778Syokota switch (MOUSE_PS2PLUS_PACKET_TYPE(sc->ipacket)) { 199348778Syokota case 1: 199448778Syokota /* wheel data packet */ 199548778Syokota x = y = 0; 199648778Syokota if (sc->ipacket[2] & 0x80) { 199748778Syokota /* horizontal roller count - ignore it XXX*/ 199848778Syokota } else { 199948778Syokota /* vertical roller count */ 200048778Syokota z = (sc->ipacket[2] & MOUSE_PS2PLUS_ZNEG) 200148778Syokota ? (sc->ipacket[2] & 0x0f) - 16 200248778Syokota : (sc->ipacket[2] & 0x0f); 200348778Syokota } 200448778Syokota ms.button |= (sc->ipacket[2] & MOUSE_PS2PLUS_BUTTON4DOWN) 200548778Syokota ? MOUSE_BUTTON4DOWN : 0; 200648778Syokota ms.button |= (sc->ipacket[2] & MOUSE_PS2PLUS_BUTTON5DOWN) 200748778Syokota ? MOUSE_BUTTON5DOWN : 0; 200848778Syokota break; 200948778Syokota case 2: 201058230Syokota /* this packet type is reserved by Logitech... */ 201158230Syokota /* 201258230Syokota * IBM ScrollPoint Mouse uses this packet type to 201358230Syokota * encode both vertical and horizontal scroll movement. 201458230Syokota */ 201558230Syokota x = y = 0; 201658230Syokota /* horizontal count */ 201758230Syokota if (sc->ipacket[2] & 0x0f) 201858230Syokota z = (sc->ipacket[2] & MOUSE_SPOINT_WNEG) ? -2 : 2; 201958230Syokota /* vertical count */ 202058230Syokota if (sc->ipacket[2] & 0xf0) 202158230Syokota z = (sc->ipacket[2] & MOUSE_SPOINT_ZNEG) ? -1 : 1; 202258230Syokota#if 0 202358230Syokota /* vertical count */ 202458230Syokota z = (sc->ipacket[2] & MOUSE_SPOINT_ZNEG) 202558230Syokota ? ((sc->ipacket[2] >> 4) & 0x0f) - 16 202658230Syokota : ((sc->ipacket[2] >> 4) & 0x0f); 202758230Syokota /* horizontal count */ 202858230Syokota w = (sc->ipacket[2] & MOUSE_SPOINT_WNEG) 202958230Syokota ? (sc->ipacket[2] & 0x0f) - 16 203058230Syokota : (sc->ipacket[2] & 0x0f); 203158230Syokota#endif 203258230Syokota break; 203348778Syokota case 0: 203448778Syokota /* device type packet - shouldn't happen */ 203548778Syokota /* FALL THROUGH */ 203648778Syokota default: 203748778Syokota x = y = 0; 203848778Syokota ms.button = ms.obutton; 203958230Syokota if (bootverbose) 204058230Syokota log(LOG_DEBUG, "psmintr: unknown PS2++ packet type %d: " 204158230Syokota "0x%02x 0x%02x 0x%02x\n", 204258230Syokota MOUSE_PS2PLUS_PACKET_TYPE(sc->ipacket), 204358230Syokota sc->ipacket[0], sc->ipacket[1], sc->ipacket[2]); 204448778Syokota break; 204548778Syokota } 204641016Sdfr } else { 204741016Sdfr /* preserve button states */ 204841016Sdfr ms.button |= ms.obutton & MOUSE_EXTBUTTONS; 204941016Sdfr } 205041016Sdfr break; 205141016Sdfr 205241016Sdfr case MOUSE_MODEL_GLIDEPOINT: 205341016Sdfr /* `tapping' action */ 205441016Sdfr ms.button |= ((c & MOUSE_PS2_TAP)) ? 0 : MOUSE_BUTTON4DOWN; 205541016Sdfr break; 205641016Sdfr 205741016Sdfr case MOUSE_MODEL_NETSCROLL: 205858230Syokota /* three addtional bytes encode buttons and wheel events */ 205958230Syokota ms.button |= (sc->ipacket[3] & MOUSE_PS2_BUTTON3DOWN) 206041016Sdfr ? MOUSE_BUTTON4DOWN : 0; 206158230Syokota ms.button |= (sc->ipacket[3] & MOUSE_PS2_BUTTON1DOWN) 206258230Syokota ? MOUSE_BUTTON5DOWN : 0; 206341016Sdfr z = (sc->ipacket[3] & MOUSE_PS2_XNEG) 206441016Sdfr ? sc->ipacket[4] - 256 : sc->ipacket[4]; 206541016Sdfr break; 206641016Sdfr 206741016Sdfr case MOUSE_MODEL_THINK: 206841016Sdfr /* the fourth button state in the first byte */ 206941016Sdfr ms.button |= (c & MOUSE_PS2_TAP) ? MOUSE_BUTTON4DOWN : 0; 207041016Sdfr break; 207141016Sdfr 207249965Syokota case MOUSE_MODEL_VERSAPAD: 207349965Syokota /* VersaPad PS/2 absolute mode message format 207449965Syokota * 207549965Syokota * [packet1] 7 6 5 4 3 2 1 0(LSB) 207649965Syokota * ipacket[0]: 1 1 0 A 1 L T R 207749965Syokota * ipacket[1]: H7 H6 H5 H4 H3 H2 H1 H0 207849965Syokota * ipacket[2]: V7 V6 V5 V4 V3 V2 V1 V0 207949965Syokota * ipacket[3]: 1 1 1 A 1 L T R 208049965Syokota * ipacket[4]:V11 V10 V9 V8 H11 H10 H9 H8 208149965Syokota * ipacket[5]: 0 P6 P5 P4 P3 P2 P1 P0 208249965Syokota * 208349965Syokota * [note] 208449965Syokota * R: right physical mouse button (1=on) 208549965Syokota * T: touch pad virtual button (1=tapping) 208649965Syokota * L: left physical mouse button (1=on) 208749965Syokota * A: position data is valid (1=valid) 208849965Syokota * H: horizontal data (12bit signed integer. H11 is sign bit.) 208949965Syokota * V: vertical data (12bit signed integer. V11 is sign bit.) 209049965Syokota * P: pressure data 209149965Syokota * 209249965Syokota * Tapping is mapped to MOUSE_BUTTON4. 209349965Syokota */ 209449965Syokota ms.button = butmap_versapad[c & MOUSE_PS2VERSA_BUTTONS]; 209549965Syokota ms.button |= (c & MOUSE_PS2VERSA_TAP) ? MOUSE_BUTTON4DOWN : 0; 209649965Syokota x = y = 0; 209749965Syokota if (c & MOUSE_PS2VERSA_IN_USE) { 209849965Syokota x0 = sc->ipacket[1] | (((sc->ipacket[4]) & 0x0f) << 8); 209949965Syokota y0 = sc->ipacket[2] | (((sc->ipacket[4]) & 0xf0) << 4); 210049965Syokota if (x0 & 0x800) 210149965Syokota x0 -= 0x1000; 210249965Syokota if (y0 & 0x800) 210349965Syokota y0 -= 0x1000; 210449965Syokota if (sc->flags & PSM_FLAGS_FINGERDOWN) { 210549965Syokota x = sc->xold - x0; 210649965Syokota y = y0 - sc->yold; 210749965Syokota if (x < 0) /* XXX */ 210849965Syokota x++; 210949965Syokota else if (x) 211049965Syokota x--; 211149965Syokota if (y < 0) 211249965Syokota y++; 211349965Syokota else if (y) 211449965Syokota y--; 211549965Syokota } else { 211649965Syokota sc->flags |= PSM_FLAGS_FINGERDOWN; 211749965Syokota } 211849965Syokota sc->xold = x0; 211949965Syokota sc->yold = y0; 212049965Syokota } else { 212149965Syokota sc->flags &= ~PSM_FLAGS_FINGERDOWN; 212249965Syokota } 212349965Syokota c = ((x < 0) ? MOUSE_PS2_XNEG : 0) 212449965Syokota | ((y < 0) ? MOUSE_PS2_YNEG : 0); 212549965Syokota break; 212649965Syokota 212758230Syokota case MOUSE_MODEL_4D: 212858230Syokota /* 212958230Syokota * b7 b6 b5 b4 b3 b2 b1 b0 213058230Syokota * byte 1: s2 d2 s1 d1 1 M R L 213158230Syokota * byte 2: sx x x x x x x x 213258230Syokota * byte 3: sy y y y y y y y 213358230Syokota * 213458230Syokota * s1: wheel 1 direction 213558230Syokota * d1: wheel 1 data 213658230Syokota * s2: wheel 2 direction 213758230Syokota * d2: wheel 2 data 213858230Syokota */ 213958230Syokota x = (sc->ipacket[1] & 0x80) ? sc->ipacket[1] - 256 : sc->ipacket[1]; 214058230Syokota y = (sc->ipacket[2] & 0x80) ? sc->ipacket[2] - 256 : sc->ipacket[2]; 214158230Syokota switch (c & MOUSE_4D_WHEELBITS) { 214258230Syokota case 0x10: 214358230Syokota z = 1; 214458230Syokota break; 214558230Syokota case 0x30: 214658230Syokota z = -1; 214758230Syokota break; 214858230Syokota case 0x40: /* 2nd wheel turning right XXX */ 214958230Syokota z = 2; 215058230Syokota break; 215158230Syokota case 0xc0: /* 2nd wheel turning left XXX */ 215258230Syokota z = -2; 215358230Syokota break; 215458230Syokota } 215558230Syokota break; 215658230Syokota 215758230Syokota case MOUSE_MODEL_4DPLUS: 215858230Syokota if ((x < 16 - 256) && (y < 16 - 256)) { 215958230Syokota /* 216058230Syokota * b7 b6 b5 b4 b3 b2 b1 b0 216158230Syokota * byte 1: 0 0 1 1 1 M R L 216258230Syokota * byte 2: 0 0 0 0 1 0 0 0 216358230Syokota * byte 3: 0 0 0 0 S s d1 d0 216458230Syokota * 216558230Syokota * L, M, R, S: left, middle, right and side buttons 216658230Syokota * s: wheel data sign bit 216758230Syokota * d1-d0: wheel data 216858230Syokota */ 216958230Syokota x = y = 0; 217058230Syokota if (sc->ipacket[2] & MOUSE_4DPLUS_BUTTON4DOWN) 217158230Syokota ms.button |= MOUSE_BUTTON4DOWN; 217258230Syokota z = (sc->ipacket[2] & MOUSE_4DPLUS_ZNEG) 217358230Syokota ? ((sc->ipacket[2] & 0x07) - 8) 217458230Syokota : (sc->ipacket[2] & 0x07) ; 217558230Syokota } else { 217658230Syokota /* preserve previous button states */ 217758230Syokota ms.button |= ms.obutton & MOUSE_EXTBUTTONS; 217858230Syokota } 217958230Syokota break; 218058230Syokota 218141016Sdfr case MOUSE_MODEL_GENERIC: 218241016Sdfr default: 218341016Sdfr break; 218441016Sdfr } 218541016Sdfr 218641016Sdfr /* scale values */ 218741016Sdfr if (sc->mode.accelfactor >= 1) { 218841016Sdfr if (x != 0) { 218941016Sdfr x = x * x / sc->mode.accelfactor; 219041016Sdfr if (x == 0) 219141016Sdfr x = 1; 219241016Sdfr if (c & MOUSE_PS2_XNEG) 219341016Sdfr x = -x; 219441016Sdfr } 219541016Sdfr if (y != 0) { 219641016Sdfr y = y * y / sc->mode.accelfactor; 219741016Sdfr if (y == 0) 219841016Sdfr y = 1; 219941016Sdfr if (c & MOUSE_PS2_YNEG) 220041016Sdfr y = -y; 220141016Sdfr } 220241016Sdfr } 220341016Sdfr 220441016Sdfr ms.dx = x; 220541016Sdfr ms.dy = y; 220641016Sdfr ms.dz = z; 220741016Sdfr ms.flags = ((x || y || z) ? MOUSE_POSCHANGED : 0) 220841016Sdfr | (ms.obutton ^ ms.button); 220941016Sdfr 221041016Sdfr if (sc->mode.level < PSM_LEVEL_NATIVE) 221141016Sdfr sc->inputbytes = tame_mouse(sc, &ms, sc->ipacket); 221241016Sdfr 221341016Sdfr sc->status.flags |= ms.flags; 221441016Sdfr sc->status.dx += ms.dx; 221541016Sdfr sc->status.dy += ms.dy; 221641016Sdfr sc->status.dz += ms.dz; 221741016Sdfr sc->status.button = ms.button; 221841016Sdfr sc->button = ms.button; 221941016Sdfr 222058230Syokota sc->watchdog = FALSE; 222158230Syokota 222241016Sdfr /* queue data */ 222341016Sdfr if (sc->queue.count + sc->inputbytes < sizeof(sc->queue.buf)) { 222441016Sdfr l = min(sc->inputbytes, sizeof(sc->queue.buf) - sc->queue.tail); 222541016Sdfr bcopy(&sc->ipacket[0], &sc->queue.buf[sc->queue.tail], l); 222641016Sdfr if (sc->inputbytes > l) 222741016Sdfr bcopy(&sc->ipacket[l], &sc->queue.buf[0], sc->inputbytes - l); 222841016Sdfr sc->queue.tail = 222941016Sdfr (sc->queue.tail + sc->inputbytes) % sizeof(sc->queue.buf); 223041016Sdfr sc->queue.count += sc->inputbytes; 223141016Sdfr } 223241016Sdfr sc->inputbytes = 0; 223341016Sdfr 223441016Sdfr if (sc->state & PSM_ASLP) { 223541016Sdfr sc->state &= ~PSM_ASLP; 223641016Sdfr wakeup((caddr_t) sc); 223741016Sdfr } 223841016Sdfr selwakeup(&sc->rsel); 223941016Sdfr } 224041016Sdfr} 224141016Sdfr 224241016Sdfrstatic int 224341016Sdfrpsmpoll(dev_t dev, int events, struct proc *p) 224441016Sdfr{ 224541016Sdfr struct psm_softc *sc = PSM_SOFTC(PSM_UNIT(dev)); 224641016Sdfr int s; 224741016Sdfr int revents = 0; 224841016Sdfr 224941016Sdfr /* Return true if a mouse event available */ 225041016Sdfr s = spltty(); 225145789Speter if (events & (POLLIN | POLLRDNORM)) { 225241016Sdfr if (sc->queue.count > 0) 225341016Sdfr revents |= events & (POLLIN | POLLRDNORM); 225441016Sdfr else 225541016Sdfr selrecord(p, &sc->rsel); 225645789Speter } 225741016Sdfr splx(s); 225841016Sdfr 225941016Sdfr return (revents); 226041016Sdfr} 226141016Sdfr 226241016Sdfr/* vendor/model specific routines */ 226341016Sdfr 226441016Sdfrstatic int mouse_id_proc1(KBDC kbdc, int res, int scale, int *status) 226541016Sdfr{ 226641016Sdfr if (set_mouse_resolution(kbdc, res) != res) 226741016Sdfr return FALSE; 226841016Sdfr if (set_mouse_scaling(kbdc, scale) 226941016Sdfr && set_mouse_scaling(kbdc, scale) 227041016Sdfr && set_mouse_scaling(kbdc, scale) 227141016Sdfr && (get_mouse_status(kbdc, status, 0, 3) >= 3)) 227241016Sdfr return TRUE; 227341016Sdfr return FALSE; 227441016Sdfr} 227541016Sdfr 227669438Syokotastatic int 227769438Syokotamouse_ext_command(KBDC kbdc, int command) 227869438Syokota{ 227969438Syokota int c; 228069438Syokota 228169438Syokota c = (command >> 6) & 0x03; 228269438Syokota if (set_mouse_resolution(kbdc, c) != c) 228369438Syokota return FALSE; 228469438Syokota c = (command >> 4) & 0x03; 228569438Syokota if (set_mouse_resolution(kbdc, c) != c) 228669438Syokota return FALSE; 228769438Syokota c = (command >> 2) & 0x03; 228869438Syokota if (set_mouse_resolution(kbdc, c) != c) 228969438Syokota return FALSE; 229069438Syokota c = (command >> 0) & 0x03; 229169438Syokota if (set_mouse_resolution(kbdc, c) != c) 229269438Syokota return FALSE; 229369438Syokota return TRUE; 229469438Syokota} 229569438Syokota 229641016Sdfr#if notyet 229741016Sdfr/* Logitech MouseMan Cordless II */ 229841016Sdfrstatic int 229941016Sdfrenable_lcordless(struct psm_softc *sc) 230041016Sdfr{ 230141016Sdfr int status[3]; 230241016Sdfr int ch; 230341016Sdfr 230441016Sdfr if (!mouse_id_proc1(sc->kbdc, PSMD_RES_HIGH, 2, status)) 230541016Sdfr return FALSE; 230641016Sdfr if (status[1] == PSMD_RES_HIGH) 230741016Sdfr return FALSE; 230841016Sdfr ch = (status[0] & 0x07) - 1; /* channel # */ 230941016Sdfr if ((ch <= 0) || (ch > 4)) 231041016Sdfr return FALSE; 231141016Sdfr /* 231241016Sdfr * status[1]: always one? 231341016Sdfr * status[2]: battery status? (0-100) 231441016Sdfr */ 231541016Sdfr return TRUE; 231641016Sdfr} 231741016Sdfr#endif /* notyet */ 231841016Sdfr 231958230Syokota/* Genius NetScroll Mouse, MouseSystems SmartScroll Mouse */ 232041016Sdfrstatic int 232141016Sdfrenable_groller(struct psm_softc *sc) 232241016Sdfr{ 232341016Sdfr int status[3]; 232441016Sdfr 232541016Sdfr /* 232641016Sdfr * The special sequence to enable the fourth button and the 232741016Sdfr * roller. Immediately after this sequence check status bytes. 232841016Sdfr * if the mouse is NetScroll, the second and the third bytes are 232941016Sdfr * '3' and 'D'. 233041016Sdfr */ 233141016Sdfr 233241016Sdfr /* 233341016Sdfr * If the mouse is an ordinary PS/2 mouse, the status bytes should 233441016Sdfr * look like the following. 233541016Sdfr * 233641016Sdfr * byte 1 bit 7 always 0 233741016Sdfr * bit 6 stream mode (0) 233841016Sdfr * bit 5 disabled (0) 233941016Sdfr * bit 4 1:1 scaling (0) 234041016Sdfr * bit 3 always 0 234141016Sdfr * bit 0-2 button status 234241016Sdfr * byte 2 resolution (PSMD_RES_HIGH) 234341016Sdfr * byte 3 report rate (?) 234441016Sdfr */ 234541016Sdfr 234641016Sdfr if (!mouse_id_proc1(sc->kbdc, PSMD_RES_HIGH, 1, status)) 234741016Sdfr return FALSE; 234841016Sdfr if ((status[1] != '3') || (status[2] != 'D')) 234941016Sdfr return FALSE; 235058230Syokota /* FIXME: SmartScroll Mouse has 5 buttons! XXX */ 235141016Sdfr sc->hw.buttons = 4; 235241016Sdfr return TRUE; 235341016Sdfr} 235441016Sdfr 235558230Syokota/* Genius NetMouse/NetMouse Pro, ASCII Mie Mouse, NetScroll Optical */ 235641016Sdfrstatic int 235741016Sdfrenable_gmouse(struct psm_softc *sc) 235841016Sdfr{ 235941016Sdfr int status[3]; 236041016Sdfr 236141016Sdfr /* 236241016Sdfr * The special sequence to enable the middle, "rubber" button. 236341016Sdfr * Immediately after this sequence check status bytes. 236441016Sdfr * if the mouse is NetMouse, NetMouse Pro, or ASCII MIE Mouse, 236541016Sdfr * the second and the third bytes are '3' and 'U'. 236641016Sdfr * NOTE: NetMouse reports that it has three buttons although it has 236741016Sdfr * two buttons and a rubber button. NetMouse Pro and MIE Mouse 236841016Sdfr * say they have three buttons too and they do have a button on the 236941016Sdfr * side... 237041016Sdfr */ 237141016Sdfr if (!mouse_id_proc1(sc->kbdc, PSMD_RES_HIGH, 1, status)) 237241016Sdfr return FALSE; 237341016Sdfr if ((status[1] != '3') || (status[2] != 'U')) 237441016Sdfr return FALSE; 237541016Sdfr return TRUE; 237641016Sdfr} 237741016Sdfr 237841016Sdfr/* ALPS GlidePoint */ 237941016Sdfrstatic int 238041016Sdfrenable_aglide(struct psm_softc *sc) 238141016Sdfr{ 238241016Sdfr int status[3]; 238341016Sdfr 238441016Sdfr /* 238541016Sdfr * The special sequence to obtain ALPS GlidePoint specific 238641016Sdfr * information. Immediately after this sequence, status bytes will 238741016Sdfr * contain something interesting. 238841016Sdfr * NOTE: ALPS produces several models of GlidePoint. Some of those 238941016Sdfr * do not respond to this sequence, thus, cannot be detected this way. 239041016Sdfr */ 239150149Syokota if (set_mouse_sampling_rate(sc->kbdc, 100) != 100) 239250149Syokota return FALSE; 239341016Sdfr if (!mouse_id_proc1(sc->kbdc, PSMD_RES_LOW, 2, status)) 239441016Sdfr return FALSE; 239550149Syokota if ((status[1] == PSMD_RES_LOW) || (status[2] == 100)) 239641016Sdfr return FALSE; 239741016Sdfr return TRUE; 239841016Sdfr} 239941016Sdfr 240041016Sdfr/* Kensington ThinkingMouse/Trackball */ 240141016Sdfrstatic int 240241016Sdfrenable_kmouse(struct psm_softc *sc) 240341016Sdfr{ 240441016Sdfr static unsigned char rate[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 }; 240541016Sdfr KBDC kbdc = sc->kbdc; 240641016Sdfr int status[3]; 240741016Sdfr int id1; 240841016Sdfr int id2; 240941016Sdfr int i; 241041016Sdfr 241141016Sdfr id1 = get_aux_id(kbdc); 241241016Sdfr if (set_mouse_sampling_rate(kbdc, 10) != 10) 241341016Sdfr return FALSE; 241441016Sdfr /* 241541016Sdfr * The device is now in the native mode? It returns a different 241641016Sdfr * ID value... 241741016Sdfr */ 241841016Sdfr id2 = get_aux_id(kbdc); 241941016Sdfr if ((id1 == id2) || (id2 != 2)) 242041016Sdfr return FALSE; 242141016Sdfr 242241016Sdfr if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW) 242341016Sdfr return FALSE; 242441016Sdfr#if PSM_DEBUG >= 2 242541016Sdfr /* at this point, resolution is LOW, sampling rate is 10/sec */ 242641016Sdfr if (get_mouse_status(kbdc, status, 0, 3) < 3) 242741016Sdfr return FALSE; 242841016Sdfr#endif 242941016Sdfr 243041016Sdfr /* 243141016Sdfr * The special sequence to enable the third and fourth buttons. 243241016Sdfr * Otherwise they behave like the first and second buttons. 243341016Sdfr */ 243441016Sdfr for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i) { 243541016Sdfr if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i]) 243641016Sdfr return FALSE; 243741016Sdfr } 243841016Sdfr 243941016Sdfr /* 244041016Sdfr * At this point, the device is using default resolution and 244141016Sdfr * sampling rate for the native mode. 244241016Sdfr */ 244341016Sdfr if (get_mouse_status(kbdc, status, 0, 3) < 3) 244441016Sdfr return FALSE; 244541016Sdfr if ((status[1] == PSMD_RES_LOW) || (status[2] == rate[i - 1])) 244641016Sdfr return FALSE; 244741016Sdfr 244841016Sdfr /* the device appears be enabled by this sequence, diable it for now */ 244941016Sdfr disable_aux_dev(kbdc); 245041016Sdfr empty_aux_buffer(kbdc, 5); 245141016Sdfr 245241016Sdfr return TRUE; 245341016Sdfr} 245441016Sdfr 245558230Syokota/* Logitech MouseMan+/FirstMouse+, IBM ScrollPoint Mouse */ 245641016Sdfrstatic int 245741016Sdfrenable_mmanplus(struct psm_softc *sc) 245841016Sdfr{ 245941016Sdfr KBDC kbdc = sc->kbdc; 246041016Sdfr int data[3]; 246141016Sdfr 246241016Sdfr /* the special sequence to enable the fourth button and the roller. */ 246358230Syokota /* 246458230Syokota * NOTE: for ScrollPoint to respond correctly, the SET_RESOLUTION 246558230Syokota * must be called exactly three times since the last RESET command 246658230Syokota * before this sequence. XXX 246758230Syokota */ 246869438Syokota if (!set_mouse_scaling(kbdc, 1)) 246969438Syokota return FALSE; 247069438Syokota if (!mouse_ext_command(kbdc, 0x39) || !mouse_ext_command(kbdc, 0xdb)) 247169438Syokota return FALSE; 247241016Sdfr if (get_mouse_status(kbdc, data, 1, 3) < 3) 247341016Sdfr return FALSE; 247441016Sdfr 247548778Syokota /* 247648778Syokota * PS2++ protocl, packet type 0 247741016Sdfr * 247848778Syokota * b7 b6 b5 b4 b3 b2 b1 b0 247948778Syokota * byte 1: * 1 p3 p2 1 * * * 248048778Syokota * byte 2: 1 1 p1 p0 m1 m0 1 0 248148778Syokota * byte 3: m7 m6 m5 m4 m3 m2 m1 m0 248248778Syokota * 248348778Syokota * p3-p0: packet type: 0 248458230Syokota * m7-m0: model ID: MouseMan+:0x50, FirstMouse+:0x51, ScrollPoint:0x58... 248541016Sdfr */ 248648778Syokota /* check constant bits */ 248748778Syokota if ((data[0] & MOUSE_PS2PLUS_SYNCMASK) != MOUSE_PS2PLUS_SYNC) 248841016Sdfr return FALSE; 248948778Syokota if ((data[1] & 0xc3) != 0xc2) 249048778Syokota return FALSE; 249148778Syokota /* check d3-d0 in byte 2 */ 249248778Syokota if (!MOUSE_PS2PLUS_CHECKBITS(data)) 249348778Syokota return FALSE; 249448778Syokota /* check p3-p0 */ 249548778Syokota if (MOUSE_PS2PLUS_PACKET_TYPE(data) != 0) 249648778Syokota return FALSE; 249741016Sdfr 249848778Syokota sc->hw.hwid &= 0x00ff; 249948778Syokota sc->hw.hwid |= data[2] << 8; /* save model ID */ 250048778Syokota 250141016Sdfr /* 250241016Sdfr * MouseMan+ (or FirstMouse+) is now in its native mode, in which 250341016Sdfr * the wheel and the fourth button events are encoded in the 250441016Sdfr * special data packet. The mouse may be put in the IntelliMouse mode 250541016Sdfr * if it is initialized by the IntelliMouse's method. 250641016Sdfr */ 250741016Sdfr return TRUE; 250841016Sdfr} 250941016Sdfr 251058230Syokota/* MS IntelliMouse Explorer */ 251158230Syokotastatic int 251258230Syokotaenable_msexplorer(struct psm_softc *sc) 251358230Syokota{ 251458923Syokota static unsigned char rate0[] = { 200, 100, 80, }; 251558923Syokota static unsigned char rate1[] = { 200, 200, 80, }; 251658230Syokota KBDC kbdc = sc->kbdc; 251758230Syokota int id; 251858230Syokota int i; 251958230Syokota 252069438Syokota /* the special sequence to enable the extra buttons and the roller. */ 252169438Syokota for (i = 0; i < sizeof(rate1)/sizeof(rate1[0]); ++i) { 252269438Syokota if (set_mouse_sampling_rate(kbdc, rate1[i]) != rate1[i]) 252369438Syokota return FALSE; 252469438Syokota } 252569438Syokota /* the device will give the genuine ID only after the above sequence */ 252669438Syokota id = get_aux_id(kbdc); 252769438Syokota if (id != PSM_EXPLORER_ID) 252869438Syokota return FALSE; 252969438Syokota 253069438Syokota sc->hw.hwid = id; 253169438Syokota sc->hw.buttons = 5; /* IntelliMouse Explorer XXX */ 253269438Syokota 253358923Syokota /* 253458923Syokota * XXX: this is a kludge to fool some KVM switch products 253558923Syokota * which think they are clever enough to know the 4-byte IntelliMouse 253658923Syokota * protocol, and assume any other protocols use 3-byte packets. 253758923Syokota * They don't convey 4-byte data packets from the IntelliMouse Explorer 253858923Syokota * correctly to the host computer because of this! 253958923Syokota * The following sequence is actually IntelliMouse's "wake up" 254058923Syokota * sequence; it will make the KVM think the mouse is IntelliMouse 254158923Syokota * when it is in fact IntelliMouse Explorer. 254258923Syokota */ 254358923Syokota for (i = 0; i < sizeof(rate0)/sizeof(rate0[0]); ++i) { 254458923Syokota if (set_mouse_sampling_rate(kbdc, rate0[i]) != rate0[i]) 254569438Syokota break; 254658923Syokota } 254758923Syokota id = get_aux_id(kbdc); 254858923Syokota 254958230Syokota return TRUE; 255058230Syokota} 255158230Syokota 255241016Sdfr/* MS IntelliMouse */ 255341016Sdfrstatic int 255441016Sdfrenable_msintelli(struct psm_softc *sc) 255541016Sdfr{ 255641016Sdfr /* 255741016Sdfr * Logitech MouseMan+ and FirstMouse+ will also respond to this 255841016Sdfr * probe routine and act like IntelliMouse. 255941016Sdfr */ 256041016Sdfr 256141016Sdfr static unsigned char rate[] = { 200, 100, 80, }; 256241016Sdfr KBDC kbdc = sc->kbdc; 256341016Sdfr int id; 256441016Sdfr int i; 256541016Sdfr 256641016Sdfr /* the special sequence to enable the third button and the roller. */ 256741016Sdfr for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i) { 256841016Sdfr if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i]) 256941016Sdfr return FALSE; 257041016Sdfr } 257141016Sdfr /* the device will give the genuine ID only after the above sequence */ 257241016Sdfr id = get_aux_id(kbdc); 257341016Sdfr if (id != PSM_INTELLI_ID) 257441016Sdfr return FALSE; 257541016Sdfr 257641016Sdfr sc->hw.hwid = id; 257741016Sdfr sc->hw.buttons = 3; 257841016Sdfr 257941016Sdfr return TRUE; 258041016Sdfr} 258141016Sdfr 258258230Syokota/* A4 Tech 4D Mouse */ 258358230Syokotastatic int 258458230Syokotaenable_4dmouse(struct psm_softc *sc) 258558230Syokota{ 258658230Syokota /* 258758230Syokota * Newer wheel mice from A4 Tech may use the 4D+ protocol. 258858230Syokota */ 258958230Syokota 259058230Syokota static unsigned char rate[] = { 200, 100, 80, 60, 40, 20 }; 259158230Syokota KBDC kbdc = sc->kbdc; 259258230Syokota int id; 259358230Syokota int i; 259458230Syokota 259558230Syokota for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i) { 259658230Syokota if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i]) 259758230Syokota return FALSE; 259858230Syokota } 259958230Syokota id = get_aux_id(kbdc); 260058230Syokota /* 260158923Syokota * WinEasy 4D, 4 Way Scroll 4D: 6 260258230Syokota * Cable-Free 4D: 8 (4DPLUS) 260358923Syokota * WinBest 4D+, 4 Way Scroll 4D+: 8 (4DPLUS) 260458230Syokota */ 260558230Syokota if (id != PSM_4DMOUSE_ID) 260658230Syokota return FALSE; 260758230Syokota 260858230Syokota sc->hw.hwid = id; 260958230Syokota sc->hw.buttons = 3; /* XXX some 4D mice have 4? */ 261058230Syokota 261158230Syokota return TRUE; 261258230Syokota} 261358230Syokota 261458230Syokota/* A4 Tech 4D+ Mouse */ 261558230Syokotastatic int 261658230Syokotaenable_4dplus(struct psm_softc *sc) 261758230Syokota{ 261858230Syokota /* 261958230Syokota * Newer wheel mice from A4 Tech seem to use this protocol. 262058230Syokota * Older models are recognized as either 4D Mouse or IntelliMouse. 262158230Syokota */ 262258230Syokota KBDC kbdc = sc->kbdc; 262358230Syokota int id; 262458230Syokota 262558230Syokota /* 262658230Syokota * enable_4dmouse() already issued the following ID sequence... 262758230Syokota static unsigned char rate[] = { 200, 100, 80, 60, 40, 20 }; 262858230Syokota int i; 262958230Syokota 263058230Syokota for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i) { 263158230Syokota if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i]) 263258230Syokota return FALSE; 263358230Syokota } 263458230Syokota */ 263558230Syokota 263658230Syokota id = get_aux_id(kbdc); 263758230Syokota if (id != PSM_4DPLUS_ID) 263858230Syokota return FALSE; 263958230Syokota 264058230Syokota sc->hw.hwid = id; 264158230Syokota sc->hw.buttons = 4; /* XXX */ 264258230Syokota 264358230Syokota return TRUE; 264458230Syokota} 264558230Syokota 264649965Syokota/* Interlink electronics VersaPad */ 264749965Syokotastatic int 264849965Syokotaenable_versapad(struct psm_softc *sc) 264949965Syokota{ 265049965Syokota KBDC kbdc = sc->kbdc; 265149965Syokota int data[3]; 265249965Syokota 265349965Syokota set_mouse_resolution(kbdc, PSMD_RES_MEDIUM_HIGH); /* set res. 2 */ 265449965Syokota set_mouse_sampling_rate(kbdc, 100); /* set rate 100 */ 265549965Syokota set_mouse_scaling(kbdc, 1); /* set scale 1:1 */ 265649965Syokota set_mouse_scaling(kbdc, 1); /* set scale 1:1 */ 265749965Syokota set_mouse_scaling(kbdc, 1); /* set scale 1:1 */ 265849965Syokota set_mouse_scaling(kbdc, 1); /* set scale 1:1 */ 265949965Syokota if (get_mouse_status(kbdc, data, 0, 3) < 3) /* get status */ 266049965Syokota return FALSE; 266149965Syokota if (data[2] != 0xa || data[1] != 0 ) /* rate == 0xa && res. == 0 */ 266249965Syokota return FALSE; 266349965Syokota set_mouse_scaling(kbdc, 1); /* set scale 1:1 */ 266449965Syokota 266558230Syokota sc->config |= PSM_CONFIG_HOOKRESUME | PSM_CONFIG_INITAFTERSUSPEND; 266658230Syokota 266749965Syokota return TRUE; /* PS/2 absolute mode */ 266849965Syokota} 266949965Syokota 267041016Sdfrstatic int 267154629Syokotapsmresume(device_t dev) 267241016Sdfr{ 267354629Syokota struct psm_softc *sc = device_get_softc(dev); 267454629Syokota int unit = device_get_unit(dev); 267541016Sdfr int err = 0; 267641016Sdfr int s; 267741016Sdfr int c; 267841016Sdfr 267941016Sdfr if (verbose >= 2) 268054629Syokota log(LOG_NOTICE, "psm%d: system resume hook called.\n", unit); 268141016Sdfr 268258230Syokota if (!(sc->config & PSM_CONFIG_HOOKRESUME)) 268358230Syokota return (0); 268458230Syokota 268541016Sdfr /* don't let anybody mess with the aux device */ 268641016Sdfr if (!kbdc_lock(sc->kbdc, TRUE)) 268741016Sdfr return (EIO); 268841016Sdfr s = spltty(); 268941016Sdfr 269058230Syokota /* block our watchdog timer */ 269158230Syokota sc->watchdog = FALSE; 269266229Sjhb untimeout(psmtimeout, (void *)(uintptr_t)unit, sc->callout); 269358230Syokota callout_handle_init(&sc->callout); 269458230Syokota 269541016Sdfr /* save the current controller command byte */ 269641016Sdfr empty_both_buffers(sc->kbdc, 10); 269741016Sdfr c = get_controller_command_byte(sc->kbdc); 269841016Sdfr if (verbose >= 2) 269941016Sdfr log(LOG_DEBUG, "psm%d: current command byte: %04x (psmresume).\n", 270041016Sdfr unit, c); 270141016Sdfr 270241016Sdfr /* enable the aux port but disable the aux interrupt and the keyboard */ 270341016Sdfr if ((c == -1) || !set_controller_command_byte(sc->kbdc, 270441016Sdfr kbdc_get_device_mask(sc->kbdc), 270541016Sdfr KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT 270641016Sdfr | KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) { 270741016Sdfr /* CONTROLLER ERROR */ 270841016Sdfr splx(s); 270941016Sdfr kbdc_lock(sc->kbdc, FALSE); 271041016Sdfr log(LOG_ERR, "psm%d: unable to set the command byte (psmresume).\n", 271141016Sdfr unit); 271241016Sdfr return (EIO); 271341016Sdfr } 271441016Sdfr 271541016Sdfr /* flush any data */ 271641016Sdfr if (sc->state & PSM_VALID) { 271741016Sdfr disable_aux_dev(sc->kbdc); /* this may fail; but never mind... */ 271841016Sdfr empty_aux_buffer(sc->kbdc, 10); 271941016Sdfr } 272041016Sdfr sc->inputbytes = 0; 272141016Sdfr 272241016Sdfr /* try to detect the aux device; are you still there? */ 272358230Syokota if (sc->config & PSM_CONFIG_INITAFTERSUSPEND) { 272458230Syokota if (reinitialize(unit, &sc->mode)) { 272558230Syokota /* yes */ 272658230Syokota sc->state |= PSM_VALID; 272758230Syokota } else { 272858230Syokota /* the device has gone! */ 272958230Syokota restore_controller(sc->kbdc, c); 273058230Syokota sc->state &= ~PSM_VALID; 273158230Syokota log(LOG_ERR, "psm%d: the aux device has gone! (psmresume).\n", 273258230Syokota unit); 273358230Syokota err = ENXIO; 273458230Syokota } 273541016Sdfr } 273641016Sdfr splx(s); 273741016Sdfr 273841016Sdfr /* restore the driver state */ 273941016Sdfr if ((sc->state & PSM_OPEN) && (err == 0)) { 274041016Sdfr /* enable the aux device and the port again */ 274141016Sdfr err = doopen(unit, c); 274241016Sdfr if (err != 0) 274341016Sdfr log(LOG_ERR, "psm%d: failed to enable the device (psmresume).\n", 274441016Sdfr unit); 274541016Sdfr } else { 274641016Sdfr /* restore the keyboard port and disable the aux port */ 274741016Sdfr if (!set_controller_command_byte(sc->kbdc, 274841016Sdfr kbdc_get_device_mask(sc->kbdc), 274941016Sdfr (c & KBD_KBD_CONTROL_BITS) 275041016Sdfr | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) { 275141016Sdfr /* CONTROLLER ERROR */ 275241016Sdfr log(LOG_ERR, "psm%d: failed to disable the aux port (psmresume).\n", 275341016Sdfr unit); 275441016Sdfr err = EIO; 275541016Sdfr } 275641016Sdfr } 275741016Sdfr 275841016Sdfr /* done */ 275941016Sdfr kbdc_lock(sc->kbdc, FALSE); 276041016Sdfr if ((sc->state & PSM_ASLP) && !(sc->state & PSM_VALID)) { 276141016Sdfr /* 276241016Sdfr * Release the blocked process; it must be notified that the device 276341016Sdfr * cannot be accessed anymore. 276441016Sdfr */ 276541016Sdfr sc->state &= ~PSM_ASLP; 276641016Sdfr wakeup((caddr_t)sc); 276741016Sdfr } 276841016Sdfr 276941016Sdfr if (verbose >= 2) 277054629Syokota log(LOG_DEBUG, "psm%d: system resume hook exiting.\n", unit); 277141016Sdfr 277241016Sdfr return (err); 277341016Sdfr} 277441016Sdfr 277552997SpeterDRIVER_MODULE(psm, atkbdc, psm_driver, psm_devclass, 0, 0); 2776