2000-03-23 09:30:07 +03:00
|
|
|
/* $NetBSD: pms.c,v 1.21 2000/03/23 06:35:14 thorpej Exp $ */
|
1996-03-29 00:50:19 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 D.C. Tsen
|
1998-08-15 07:02:31 +04:00
|
|
|
* Copyright (c) 1994 Charles M. Hannum.
|
1996-03-29 00:50:19 +03:00
|
|
|
* Copyright (c) 1992, 1993 Erik Forsberg.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the RiscBSD team.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from:pms.c,v 1.24 1995/12/24 02:30:28 mycroft Exp
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ported from 386 version of PS/2 mouse driver.
|
|
|
|
* D.C. Tsen
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/device.h>
|
1996-10-16 01:06:51 +04:00
|
|
|
#include <sys/poll.h>
|
1996-03-29 00:50:19 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
#include <machine/bus.h>
|
1997-01-28 07:55:15 +03:00
|
|
|
#include <machine/conf.h>
|
1996-03-29 00:50:19 +03:00
|
|
|
#include <machine/mouse.h>
|
1997-10-14 23:35:34 +04:00
|
|
|
#include <arm32/dev/pmsvar.h>
|
1997-07-28 22:07:03 +04:00
|
|
|
|
1998-07-06 04:43:28 +04:00
|
|
|
#define MOUSE_IOC_ACK
|
|
|
|
|
1996-03-29 00:50:19 +03:00
|
|
|
/* mouse commands */
|
|
|
|
#define PMS_SET_SCALE11 0xe6 /* set scaling 1:1 */
|
|
|
|
#define PMS_SET_SCALE21 0xe7 /* set scaling 2:1 */
|
|
|
|
#define PMS_SET_RES 0xe8 /* set resolution */
|
|
|
|
#define PMS_GET_SCALE 0xe9 /* get scaling factor */
|
|
|
|
#define PMS_SET_STREAM 0xea /* set streaming mode */
|
|
|
|
#define PMS_SET_SAMPLE 0xf3 /* set sampling rate */
|
|
|
|
#define PMS_DEV_ENABLE 0xf4 /* mouse on */
|
|
|
|
#define PMS_DEV_DISABLE 0xf5 /* mouse off */
|
|
|
|
#define PMS_RESET 0xff /* reset */
|
|
|
|
|
|
|
|
#define PMS_CHUNK 128 /* chunk size for read */
|
|
|
|
#define PMS_BSIZE (20*64) /* buffer size */
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* function prototypes */
|
1996-03-29 00:50:19 +03:00
|
|
|
|
1996-10-16 01:06:51 +04:00
|
|
|
void pmswatchdog __P((void *));
|
1998-02-22 03:25:03 +03:00
|
|
|
#ifdef MOUSE_IOC_ACK
|
|
|
|
static void pmsputbuffer __P((struct pms_softc *sc, struct mousebufrec *buf));
|
|
|
|
#endif
|
1997-10-14 23:35:34 +04:00
|
|
|
static __inline void pms_flush __P((struct pms_softc *sc));
|
1996-03-29 00:50:19 +03:00
|
|
|
|
1999-01-24 01:18:41 +03:00
|
|
|
extern struct cfdriver opms_cd;
|
1996-03-29 00:50:19 +03:00
|
|
|
|
1998-01-13 05:09:58 +03:00
|
|
|
/* pms device driver structure */
|
1996-03-29 00:50:19 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
#define PMS_DATA 0
|
|
|
|
#define PMS_CR 1
|
|
|
|
#define PMS_STATUS 1
|
|
|
|
|
|
|
|
#define PMS_CR_ENABLE 0x08
|
|
|
|
#define PMS_CR_KDATAO 0x02
|
|
|
|
#define PMS_CR_KCLKO 0x01
|
|
|
|
|
|
|
|
#define PMS_ST_TXE 0x80
|
|
|
|
#define PMS_ST_TXB 0x40
|
|
|
|
#define PMS_ST_RXF 0x20
|
|
|
|
#define PMS_ST_RXB 0x10
|
|
|
|
#define PMS_ST_ENABLE 0x08
|
|
|
|
#define PMS_ST_RXPARITY 0x04
|
|
|
|
#define PMS_ST_KDATAI 0x02
|
|
|
|
#define PMS_ST_KCLKI 0x01
|
|
|
|
|
1996-03-29 00:50:19 +03:00
|
|
|
#define PMSUNIT(dev) (minor(dev))
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/*
|
|
|
|
* Flush any pending mouse data
|
|
|
|
*/
|
|
|
|
|
1997-01-06 07:47:53 +03:00
|
|
|
static __inline void
|
1997-10-14 23:35:34 +04:00
|
|
|
pms_flush(sc)
|
|
|
|
struct pms_softc *sc;
|
1996-03-29 00:50:19 +03:00
|
|
|
{
|
1996-05-08 01:04:08 +04:00
|
|
|
int n = 1000;
|
1997-10-14 23:35:34 +04:00
|
|
|
|
|
|
|
while (n-- && (bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_STATUS)
|
|
|
|
& PMS_ST_RXF)) {
|
1996-03-29 00:50:19 +03:00
|
|
|
delay(6);
|
1997-10-14 23:35:34 +04:00
|
|
|
(void) bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_DATA);
|
1996-03-29 00:50:19 +03:00
|
|
|
delay(6);
|
1997-10-14 23:35:34 +04:00
|
|
|
(void) bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_DATA);
|
1996-03-29 00:50:19 +03:00
|
|
|
delay(6);
|
1997-10-14 23:35:34 +04:00
|
|
|
(void) bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_DATA);
|
1996-03-29 00:50:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/*
|
|
|
|
* Send a command to the mouse
|
|
|
|
*/
|
|
|
|
|
1996-05-08 01:04:08 +04:00
|
|
|
static int
|
1997-10-14 23:35:34 +04:00
|
|
|
cmd_mouse(sc, cmd)
|
|
|
|
struct pms_softc * sc;
|
|
|
|
u_char cmd;
|
1996-03-29 00:50:19 +03:00
|
|
|
{
|
1997-10-14 23:35:34 +04:00
|
|
|
int c;
|
1996-03-29 00:50:19 +03:00
|
|
|
int i = 0;
|
|
|
|
int retry = 10;
|
|
|
|
|
|
|
|
for (i = 0; i < 1000; i++) {
|
1997-10-14 23:35:34 +04:00
|
|
|
if (bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_STATUS) & PMS_ST_TXE)
|
1996-03-29 00:50:19 +03:00
|
|
|
break;
|
|
|
|
delay(2);
|
|
|
|
}
|
|
|
|
if (i == 1000)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Mouse transmit not ready\n");
|
1996-03-29 00:50:19 +03:00
|
|
|
|
|
|
|
resend:
|
1997-10-14 23:35:34 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, PMS_DATA, cmd);
|
1996-03-29 00:50:19 +03:00
|
|
|
delay(2);
|
1997-10-14 23:35:34 +04:00
|
|
|
c = bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_STATUS);
|
1996-05-08 01:04:08 +04:00
|
|
|
i = 1000;
|
1997-10-14 23:35:34 +04:00
|
|
|
while (i-- && !(c & PMS_ST_RXF)) {
|
1996-03-29 00:50:19 +03:00
|
|
|
delay(1);
|
1997-10-14 23:35:34 +04:00
|
|
|
c = bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_STATUS);
|
1996-03-29 00:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
delay(10000);
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
c = bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_DATA);
|
1996-03-29 00:50:19 +03:00
|
|
|
if ((c == 0xFA) || (c == 0xEE))
|
1996-05-08 01:04:08 +04:00
|
|
|
return(0);
|
1996-03-29 00:50:19 +03:00
|
|
|
|
|
|
|
if (--retry) {
|
1997-10-14 23:35:34 +04:00
|
|
|
pms_flush(sc);
|
1996-03-29 00:50:19 +03:00
|
|
|
goto resend;
|
|
|
|
}
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
printf("%s: Mouse cmd failed, cmd = %x, status = %x\n", sc->sc_dev.dv_xname, cmd, c);
|
1996-05-08 01:04:08 +04:00
|
|
|
return(1);
|
1996-03-29 00:50:19 +03:00
|
|
|
}
|
|
|
|
|
1996-05-08 01:04:08 +04:00
|
|
|
/*
|
1997-10-14 23:35:34 +04:00
|
|
|
* initialise the mouse
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The sets up parts of the softc and then tests the mouse
|
|
|
|
* to make sure it is responding.
|
|
|
|
* It then configures the mouse as required.
|
1996-05-08 01:04:08 +04:00
|
|
|
*/
|
|
|
|
|
1996-03-29 00:50:19 +03:00
|
|
|
int
|
1997-10-14 23:35:34 +04:00
|
|
|
pmsinit(sc)
|
|
|
|
struct pms_softc *sc;
|
1996-05-08 01:04:08 +04:00
|
|
|
{
|
1996-03-29 00:50:19 +03:00
|
|
|
int i, j;
|
|
|
|
int mid;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* Set up softc */
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_init(&sc->sc_watchdog_ch);
|
1997-10-14 23:35:34 +04:00
|
|
|
sc->sc_state = 0;
|
|
|
|
sc->origx = 0;
|
|
|
|
sc->origy = 0;
|
|
|
|
sc->boundx = -4095;
|
|
|
|
sc->boundy = -4095;
|
|
|
|
sc->bounda = 4096;
|
|
|
|
sc->boundb = 4096;
|
1996-03-29 00:50:19 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* Enable the mouse */
|
1996-03-29 00:50:19 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, PMS_CR, PMS_CR_ENABLE);
|
1996-03-29 00:50:19 +03:00
|
|
|
|
|
|
|
i = 0;
|
1997-10-14 23:35:34 +04:00
|
|
|
while ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_STATUS) & 0x03)
|
|
|
|
!= 0x03) {
|
1996-03-29 00:50:19 +03:00
|
|
|
if (i++ > 10) {
|
1997-10-14 23:35:34 +04:00
|
|
|
printf("Mouse not found, status = <%x>.\n",
|
|
|
|
bus_space_read_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
PMS_STATUS));
|
1996-03-29 00:50:19 +03:00
|
|
|
return(0);
|
|
|
|
}
|
1997-10-14 23:35:34 +04:00
|
|
|
pms_flush(sc);
|
1996-03-29 00:50:19 +03:00
|
|
|
delay(2);
|
1997-10-14 23:35:34 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, PMS_CR, PMS_CR_ENABLE);
|
1996-03-29 00:50:19 +03:00
|
|
|
}
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
pms_flush(sc);
|
1996-03-29 00:50:19 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable, reset and enable the mouse.
|
|
|
|
*/
|
1997-10-14 23:35:34 +04:00
|
|
|
if (cmd_mouse(sc, PMS_DEV_DISABLE))
|
1996-05-08 01:04:08 +04:00
|
|
|
return(0);
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
cmd_mouse(sc, PMS_RESET);
|
1996-03-29 00:50:19 +03:00
|
|
|
delay(300000);
|
|
|
|
j = 10;
|
|
|
|
i = 0;
|
1997-10-14 23:35:34 +04:00
|
|
|
while ((mid = bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_DATA)) != 0xAA) {
|
1996-03-29 00:50:19 +03:00
|
|
|
if (++i > 500) {
|
|
|
|
if (--j < 0) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Mouse Reset failed, status = <%x>.\n", mid);
|
1996-03-29 00:50:19 +03:00
|
|
|
return(0);
|
|
|
|
}
|
1997-10-14 23:35:34 +04:00
|
|
|
pms_flush(sc);
|
|
|
|
cmd_mouse(sc, PMS_RESET);
|
1996-03-29 00:50:19 +03:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
delay(100000);
|
|
|
|
}
|
1997-10-14 23:35:34 +04:00
|
|
|
mid = bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_DATA);
|
1996-03-29 00:50:19 +03:00
|
|
|
#if 0
|
1997-10-14 23:35:34 +04:00
|
|
|
cmd_mouse(sc, PMS_SET_RES);
|
|
|
|
cmd_mouse(sc, 3); /* 8 counts/mm */
|
|
|
|
cmd_mouse(sc, PMS_SET_SCALE21);
|
1996-03-29 00:50:19 +03:00
|
|
|
#endif
|
1997-10-14 23:35:34 +04:00
|
|
|
cmd_mouse(sc, PMS_SET_SAMPLE);
|
|
|
|
cmd_mouse(sc, 40); /* 40 samples/sec */
|
|
|
|
cmd_mouse(sc, PMS_SET_STREAM);
|
|
|
|
cmd_mouse(sc, PMS_DEV_ENABLE);
|
|
|
|
return(1);
|
1996-03-29 00:50:19 +03:00
|
|
|
}
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/*
|
|
|
|
* device open routine
|
|
|
|
*/
|
1996-03-29 00:50:19 +03:00
|
|
|
int
|
|
|
|
pmsopen(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
int unit = PMSUNIT(dev);
|
|
|
|
struct pms_softc *sc;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* validate the unit and the softc */
|
1999-01-24 01:18:41 +03:00
|
|
|
if (unit >= opms_cd.cd_ndevs)
|
1996-03-29 00:50:19 +03:00
|
|
|
return ENXIO;
|
1999-01-24 01:18:41 +03:00
|
|
|
sc = opms_cd.cd_devs[unit];
|
1996-03-29 00:50:19 +03:00
|
|
|
if (!sc)
|
|
|
|
return ENXIO;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* Are we already open ? */
|
1996-03-29 00:50:19 +03:00
|
|
|
if (sc->sc_state & PMS_OPEN)
|
|
|
|
return EBUSY;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* initialise buffer */
|
1996-03-29 00:50:19 +03:00
|
|
|
if (clalloc(&sc->sc_q, PMS_BSIZE, 0) == -1)
|
|
|
|
return ENOMEM;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* set up the softc structure */
|
1996-10-16 01:06:51 +04:00
|
|
|
sc->sc_proc = p;
|
1996-10-30 02:28:12 +03:00
|
|
|
sc->sc_mode = MOUSEMODE_ABS;
|
1996-03-29 00:50:19 +03:00
|
|
|
sc->sc_state |= PMS_OPEN;
|
|
|
|
sc->sc_status = 0;
|
|
|
|
sc->sc_x = sc->sc_y = 0;
|
|
|
|
sc->lastx = -1;
|
|
|
|
sc->lasty = -1;
|
|
|
|
sc->lastb = -1;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* enable interrupts */
|
|
|
|
sc->sc_intenable(sc, 1);
|
|
|
|
|
|
|
|
/* install watchdog timeout */
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_reset(&sc->sc_watchdog_ch, 30 * hz,
|
|
|
|
pmswatchdog, sc);
|
1996-05-08 01:04:08 +04:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
return(0);
|
1996-03-29 00:50:19 +03:00
|
|
|
}
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/*
|
|
|
|
* driver close function
|
|
|
|
*/
|
1996-03-29 00:50:19 +03:00
|
|
|
int
|
|
|
|
pmsclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-01-24 01:18:41 +03:00
|
|
|
struct pms_softc *sc = opms_cd.cd_devs[PMSUNIT(dev)];
|
1996-03-29 00:50:19 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* remove the timeout */
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_stop(&sc->sc_watchdog_ch);
|
1996-05-08 01:04:08 +04:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* disable interrupts */
|
|
|
|
sc->sc_intenable(sc, 0);
|
1996-03-29 00:50:19 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* clean up*/
|
1996-10-16 01:06:51 +04:00
|
|
|
sc->sc_proc = NULL;
|
1996-03-29 00:50:19 +03:00
|
|
|
sc->sc_state &= ~PMS_OPEN;
|
|
|
|
sc->sc_x = sc->sc_y = 0;
|
|
|
|
|
|
|
|
clfree(&sc->sc_q);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pmsread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
|
|
|
{
|
1999-01-24 01:18:41 +03:00
|
|
|
struct pms_softc *sc = opms_cd.cd_devs[PMSUNIT(dev)];
|
1996-03-29 00:50:19 +03:00
|
|
|
int s;
|
|
|
|
int error = 0;
|
|
|
|
size_t length;
|
|
|
|
u_char buffer[PMS_CHUNK];
|
|
|
|
|
|
|
|
/* Block until mouse activity occured. */
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
while (sc->sc_q.c_cc == 0) {
|
|
|
|
if (flag & IO_NDELAY) {
|
1997-10-14 23:35:34 +04:00
|
|
|
(void)splx(s);
|
1996-03-29 00:50:19 +03:00
|
|
|
return EWOULDBLOCK;
|
|
|
|
}
|
|
|
|
sc->sc_state |= PMS_ASLP;
|
1996-04-27 02:01:51 +04:00
|
|
|
if ((error = tsleep((caddr_t)sc, (PZERO | PCATCH), "pmsread", 0))) {
|
1996-03-29 00:50:19 +03:00
|
|
|
sc->sc_state &= ~PMS_ASLP;
|
1997-10-14 23:35:34 +04:00
|
|
|
(void)splx(s);
|
1996-03-29 00:50:19 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transfer as many chunks as possible. */
|
|
|
|
|
|
|
|
while (sc->sc_q.c_cc > 0 && uio->uio_resid > 0) {
|
|
|
|
length = min(sc->sc_q.c_cc, uio->uio_resid);
|
|
|
|
if (length > sizeof(buffer))
|
|
|
|
length = sizeof(buffer);
|
|
|
|
|
|
|
|
/* Remove a small chunk from the input queue. */
|
|
|
|
(void) q_to_b(&sc->sc_q, buffer, length);
|
|
|
|
|
|
|
|
/* Copy the data to the user process. */
|
1996-04-27 02:01:51 +04:00
|
|
|
if ((error = uiomove(buffer, length, uio)))
|
1996-03-29 00:50:19 +03:00
|
|
|
break;
|
|
|
|
}
|
1997-10-14 23:35:34 +04:00
|
|
|
(void)splx(s);
|
1996-03-29 00:50:19 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pmsioctl(dev, cmd, addr, flag, p)
|
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t addr;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-01-24 01:18:41 +03:00
|
|
|
struct pms_softc *sc = opms_cd.cd_devs[PMSUNIT(dev)];
|
1996-03-29 00:50:19 +03:00
|
|
|
struct mouseinfo info;
|
|
|
|
int s;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MOUSEIOC_SETSTATE:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("MOUSEIOC_SETSTATE called\n");
|
1996-03-29 00:50:19 +03:00
|
|
|
break;
|
|
|
|
case MOUSEIOC_WRITEX:
|
|
|
|
sc->sc_x = *(int *) addr;
|
|
|
|
break;
|
|
|
|
case MOUSEIOC_WRITEY:
|
|
|
|
sc->sc_y = *(int *) addr;
|
|
|
|
break;
|
|
|
|
case MOUSEIOC_SETBOUNDS:
|
|
|
|
{
|
|
|
|
register struct mouse_boundingbox *bo = (void *) addr;
|
1996-10-16 01:06:51 +04:00
|
|
|
struct mousebufrec buffer;
|
|
|
|
|
1996-03-29 00:50:19 +03:00
|
|
|
sc->boundx = bo->x; sc->boundy = bo->y;
|
|
|
|
sc->bounda = bo->a; sc->boundb = bo->b;
|
1996-10-16 01:06:51 +04:00
|
|
|
|
|
|
|
buffer.status = IOC_ACK;
|
|
|
|
buffer.x = sc->origx;
|
|
|
|
buffer.y = sc->origy;
|
|
|
|
#ifdef MOUSE_IOC_ACK
|
|
|
|
pmsputbuffer(sc, &buffer);
|
|
|
|
#endif
|
1996-03-29 00:50:19 +03:00
|
|
|
break;
|
|
|
|
}
|
1996-10-30 02:28:12 +03:00
|
|
|
case MOUSEIOC_SETMODE:
|
|
|
|
{
|
|
|
|
struct mousebufrec buffer;
|
1998-02-22 03:25:03 +03:00
|
|
|
#ifdef MOUSE_IOC_ACK
|
1996-10-30 02:28:12 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
#endif
|
|
|
|
sc->sc_mode = *(int *)addr;
|
|
|
|
|
|
|
|
buffer.status = IOC_ACK;
|
|
|
|
buffer.x = sc->origx;
|
|
|
|
buffer.y = sc->origy;
|
|
|
|
#ifdef MOUSE_IOC_ACK
|
|
|
|
if (sc->sc_q.c_cc > 0)
|
1997-10-14 23:35:34 +04:00
|
|
|
printf("%s: setting mode with non empty buffer (%d)\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_q.c_cc);
|
1996-10-30 02:28:12 +03:00
|
|
|
pmsputbuffer(sc, &buffer);
|
|
|
|
(void)splx(s);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
1996-03-29 00:50:19 +03:00
|
|
|
case MOUSEIOC_SETORIGIN:
|
|
|
|
{
|
|
|
|
register struct mouse_origin *oo = (void *) addr;
|
1996-10-16 01:06:51 +04:00
|
|
|
struct mousebufrec buffer;
|
|
|
|
|
1996-03-29 00:50:19 +03:00
|
|
|
sc->origx = oo->x;
|
|
|
|
sc->origy = oo->y;
|
1996-10-16 01:06:51 +04:00
|
|
|
|
|
|
|
buffer.status = IOC_ACK;
|
|
|
|
buffer.x = sc->origx;
|
|
|
|
buffer.y = sc->origy;
|
|
|
|
#ifdef MOUSE_IOC_ACK
|
|
|
|
pmsputbuffer(sc, &buffer);
|
|
|
|
#endif
|
1996-03-29 00:50:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOUSEIOC_GETBOUNDS:
|
|
|
|
{
|
|
|
|
register struct mouse_boundingbox *bo = (void *) addr;
|
|
|
|
bo->x = sc->boundx; bo->y = sc->boundy;
|
|
|
|
bo->a = sc->bounda; bo->b = sc->boundb;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOUSEIOC_GETORIGIN:
|
|
|
|
{
|
|
|
|
register struct mouse_origin *oo = (void *) addr;
|
|
|
|
oo->x = sc->origx;
|
|
|
|
oo->y = sc->origy;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOUSEIOC_GETSTATE:
|
|
|
|
info.status = sc->sc_status;
|
|
|
|
if (sc->sc_x || sc->sc_y)
|
|
|
|
info.status |= MOVEMENT;
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
info.xmotion = sc->sc_x;
|
|
|
|
info.ymotion = sc->sc_y;
|
|
|
|
#else
|
|
|
|
if (sc->sc_x > sc->bounda)
|
|
|
|
info.xmotion = sc->bounda;
|
|
|
|
else if (sc->sc_x < sc->boundx)
|
|
|
|
info.xmotion = sc->boundx;
|
|
|
|
else
|
|
|
|
info.xmotion = sc->sc_x;
|
|
|
|
|
|
|
|
if (sc->sc_y > sc->boundb)
|
|
|
|
info.ymotion = sc->boundb;
|
|
|
|
else if (sc->sc_y < sc->boundy)
|
|
|
|
info.ymotion = sc->boundy;
|
|
|
|
else
|
|
|
|
info.ymotion = sc->sc_y;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Reset historical information. */
|
|
|
|
sc->sc_x = sc->sc_y = 0;
|
|
|
|
sc->sc_status &= ~BUTCHNGMASK;
|
|
|
|
ndflush(&sc->sc_q, sc->sc_q.c_cc);
|
|
|
|
|
|
|
|
error = copyout(&info, addr, sizeof(struct mouseinfo));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1997-10-14 23:35:34 +04:00
|
|
|
(void)splx(s);
|
1996-03-29 00:50:19 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Masks for the first byte of a packet */
|
|
|
|
#define PS2LBUTMASK 0x01
|
|
|
|
#define PS2RBUTMASK 0x02
|
|
|
|
#define PS2MBUTMASK 0x04
|
|
|
|
|
|
|
|
#define XNEG_MASK 0x10
|
|
|
|
#define YNEG_MASK 0x20
|
|
|
|
|
|
|
|
int
|
|
|
|
pmsintr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct pms_softc *sc = arg;
|
|
|
|
static int state = 0;
|
|
|
|
static u_char buttons;
|
|
|
|
u_char changed;
|
|
|
|
static int dx, dy;
|
|
|
|
int dosignal = 0;
|
|
|
|
int s;
|
|
|
|
u_char b;
|
|
|
|
struct mousebufrec mbuffer;
|
|
|
|
|
|
|
|
if ((sc->sc_state & PMS_OPEN) == 0) {
|
|
|
|
/* Interrupts are not expected. Discard the byte. */
|
1997-10-14 23:35:34 +04:00
|
|
|
pms_flush(sc);
|
1996-10-16 01:06:51 +04:00
|
|
|
return(-1); /* Could have been ours but pass it on */
|
1996-03-29 00:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case 0:
|
1997-10-14 23:35:34 +04:00
|
|
|
buttons = bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_DATA);
|
1996-03-29 00:50:19 +03:00
|
|
|
if ((buttons & 0xc0) == 0)
|
|
|
|
++state;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
1997-10-14 23:35:34 +04:00
|
|
|
dx = bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_DATA);
|
1996-03-29 00:50:19 +03:00
|
|
|
dx = (buttons & XNEG_MASK) ? -dx : dx;
|
|
|
|
++state;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
1997-10-14 23:35:34 +04:00
|
|
|
dy = bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_DATA);
|
1996-03-29 00:50:19 +03:00
|
|
|
dy = (buttons & YNEG_MASK) ? -dy : dy;
|
|
|
|
state = 0;
|
|
|
|
|
|
|
|
buttons = ((buttons & PS2LBUTMASK) << 2) |
|
|
|
|
((buttons & (PS2RBUTMASK | PS2MBUTMASK)) >> 1);
|
|
|
|
/*
|
|
|
|
* Ahhh, the Xarm server interrupt button bits reversed.
|
|
|
|
* If bit is set to 1, it means button is not pressed which is
|
|
|
|
* not what PS/2 mouse button bits said. Since we are simulating
|
|
|
|
* the quadmouse, that's not too picky about it.
|
|
|
|
*/
|
|
|
|
buttons ^= BUTSTATMASK;
|
|
|
|
changed = ((buttons ^ sc->sc_status) & BUTSTATMASK) << 3;
|
|
|
|
sc->sc_status = buttons | (sc->sc_status & ~BUTSTATMASK) | changed;
|
|
|
|
|
|
|
|
if (dx || dy || changed) {
|
|
|
|
if (dx < 0)
|
|
|
|
dx = -(256 + dx);
|
|
|
|
if (dy < 0)
|
|
|
|
dy = -(256 + dy);
|
|
|
|
|
|
|
|
/* Update accumulated movements. */
|
|
|
|
sc->sc_x += dx;
|
|
|
|
sc->sc_y += dy;
|
|
|
|
|
|
|
|
if (sc->sc_x > sc->bounda)
|
|
|
|
sc->sc_x = sc->bounda;
|
|
|
|
else if (sc->sc_x < sc->boundx)
|
|
|
|
sc->sc_x = sc->boundx;
|
|
|
|
|
|
|
|
if (sc->sc_y > sc->boundb)
|
|
|
|
sc->sc_y = sc->boundb;
|
|
|
|
else if (sc->sc_y < sc->boundy)
|
|
|
|
sc->sc_y = sc->boundy;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
if (sc->sc_q.c_cc == 0)
|
1996-03-29 00:50:19 +03:00
|
|
|
dosignal = 1;
|
|
|
|
|
|
|
|
/* Add this event to the queue. */
|
|
|
|
b = buttons & BUTSTATMASK;
|
|
|
|
mbuffer.status = b | (b ^ sc->lastb) << 3
|
1997-10-14 23:35:34 +04:00
|
|
|
| (((sc->sc_x==sc->lastx) && (sc->sc_y==sc->lasty))?0:MOVEMENT);
|
1996-03-29 00:50:19 +03:00
|
|
|
mbuffer.x = sc->sc_x * 2;
|
|
|
|
mbuffer.y = sc->sc_y * 2;
|
|
|
|
microtime(&mbuffer.event_time);
|
|
|
|
s = spltty();
|
|
|
|
(void) b_to_q((char *)&mbuffer, sizeof(mbuffer), &sc->sc_q);
|
|
|
|
(void) splx(s);
|
|
|
|
sc->lastx = sc->sc_x;
|
|
|
|
sc->lasty = sc->sc_y;
|
|
|
|
sc->lastb = b;
|
|
|
|
|
1996-10-30 02:28:12 +03:00
|
|
|
if(sc->sc_mode == MOUSEMODE_REL) {
|
|
|
|
sc->origx = sc->origy = 0;
|
|
|
|
sc->sc_x = sc->sc_y = 0;
|
|
|
|
}
|
|
|
|
|
1996-03-29 00:50:19 +03:00
|
|
|
selwakeup(&sc->sc_rsel);
|
|
|
|
if (sc->sc_state & PMS_ASLP) {
|
|
|
|
sc->sc_state &= ~PMS_ASLP;
|
|
|
|
wakeup((caddr_t)sc);
|
|
|
|
}
|
1999-06-01 13:34:06 +04:00
|
|
|
/* if (dosignal)*/
|
1996-10-16 01:06:51 +04:00
|
|
|
psignal(sc->sc_proc, SIGIO);
|
1996-03-29 00:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1996-10-16 01:06:51 +04:00
|
|
|
return(1); /* Claim interrupt */
|
1996-03-29 00:50:19 +03:00
|
|
|
}
|
|
|
|
|
1996-10-16 01:06:51 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
pmspoll(dev, events, p)
|
|
|
|
dev_t dev;
|
|
|
|
int events;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-01-24 01:18:41 +03:00
|
|
|
struct pms_softc *sc = opms_cd.cd_devs[PMSUNIT(dev)];
|
1996-10-16 01:06:51 +04:00
|
|
|
int revents = 0;
|
|
|
|
int s = spltty();
|
|
|
|
|
1999-02-02 07:02:26 +03:00
|
|
|
if (events & (POLLIN | POLLRDNORM)) {
|
1996-10-16 01:06:51 +04:00
|
|
|
if (sc->sc_q.c_cc > 0)
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
else
|
|
|
|
selrecord(p, &sc->sc_rsel);
|
1999-02-02 07:02:26 +03:00
|
|
|
}
|
1996-10-16 01:06:51 +04:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
(void)splx(s);
|
1996-10-16 01:06:51 +04:00
|
|
|
return (revents);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-08 01:04:08 +04:00
|
|
|
void
|
|
|
|
pmswatchdog(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
1997-10-14 23:35:34 +04:00
|
|
|
struct pms_softc *sc = arg;
|
1996-05-08 01:04:08 +04:00
|
|
|
int s;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
if ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, PMS_STATUS) & 0x03)
|
|
|
|
!= 0x03) {
|
|
|
|
printf("%s: Mouse is dead (%x), restart it\n",
|
|
|
|
sc->sc_dev.dv_xname, bus_space_read_1(sc->sc_iot,
|
|
|
|
sc->sc_ioh, PMS_STATUS));
|
1996-05-08 01:04:08 +04:00
|
|
|
s = spltty();
|
1997-10-14 23:35:34 +04:00
|
|
|
pmsinit(sc);
|
|
|
|
(void)splx(s);
|
1996-05-08 01:04:08 +04:00
|
|
|
}
|
|
|
|
}
|
1996-10-16 01:06:51 +04:00
|
|
|
|
1998-02-22 03:25:03 +03:00
|
|
|
#ifdef MOUSE_IOC_ACK
|
|
|
|
static void
|
1996-10-16 01:06:51 +04:00
|
|
|
pmsputbuffer(sc, buffer)
|
|
|
|
struct pms_softc *sc;
|
|
|
|
struct mousebufrec *buffer;
|
|
|
|
{
|
|
|
|
int s;
|
1997-10-14 23:35:34 +04:00
|
|
|
int dosignal = 0;
|
1996-10-16 01:06:51 +04:00
|
|
|
|
|
|
|
/* Time stamp the buffer */
|
|
|
|
microtime(&buffer->event_time);
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
if (sc->sc_q.c_cc == 0)
|
|
|
|
dosignal = 1;
|
1996-10-16 01:06:51 +04:00
|
|
|
|
|
|
|
s=spltty();
|
1997-10-14 23:35:34 +04:00
|
|
|
(void)b_to_q((char *)buffer, sizeof(*buffer), &sc->sc_q);
|
1996-10-16 01:06:51 +04:00
|
|
|
(void)splx(s);
|
|
|
|
selwakeup(&sc->sc_rsel);
|
|
|
|
|
|
|
|
if (sc->sc_state & PMS_ASLP) {
|
|
|
|
sc->sc_state &= ~PMS_ASLP;
|
|
|
|
wakeup((caddr_t)sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dosignal)
|
|
|
|
psignal(sc->sc_proc, SIGIO);
|
|
|
|
}
|
1998-02-22 03:25:03 +03:00
|
|
|
#endif
|
1997-10-14 23:35:34 +04:00
|
|
|
|
|
|
|
/* End of pms.c */
|