xref: /netbsd-src/sys/arch/news68k/dev/ms.c (revision b87210fa510e6eecfd48e218f3aefcb05cbe4636)
1*b87210faStsutsui /*	$NetBSD: ms.c,v 1.6 2008/05/14 13:29:28 tsutsui Exp $	*/
208f4daf2Stsutsui 
308f4daf2Stsutsui /*-
408f4daf2Stsutsui  * Copyright (c) 2001 Izumi Tsutsui.  All rights reserved.
5*b87210faStsutsui  *
6*b87210faStsutsui  * Redistribution and use in source and binary forms, with or without
7*b87210faStsutsui  * modification, are permitted provided that the following conditions
8*b87210faStsutsui  * are met:
9*b87210faStsutsui  * 1. Redistributions of source code must retain the above copyright
10*b87210faStsutsui  *    notice, this list of conditions and the following disclaimer.
11*b87210faStsutsui  * 2. Redistributions in binary form must reproduce the above copyright
12*b87210faStsutsui  *    notice, this list of conditions and the following disclaimer in the
13*b87210faStsutsui  *    documentation and/or other materials provided with the distribution.
14*b87210faStsutsui  *
15*b87210faStsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*b87210faStsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*b87210faStsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*b87210faStsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*b87210faStsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*b87210faStsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*b87210faStsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*b87210faStsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*b87210faStsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*b87210faStsutsui  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*b87210faStsutsui  */
26*b87210faStsutsui 
27*b87210faStsutsui /*-
2808f4daf2Stsutsui  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
2908f4daf2Stsutsui  *
3008f4daf2Stsutsui  * Redistribution and use in source and binary forms, with or without
3108f4daf2Stsutsui  * modification, are permitted provided that the following conditions
3208f4daf2Stsutsui  * are met:
3308f4daf2Stsutsui  * 1. Redistributions of source code must retain the above copyright
3408f4daf2Stsutsui  *    notice, this list of conditions and the following disclaimer.
3508f4daf2Stsutsui  * 2. Redistributions in binary form must reproduce the above copyright
3608f4daf2Stsutsui  *    notice, this list of conditions and the following disclaimer in the
3708f4daf2Stsutsui  *    documentation and/or other materials provided with the distribution.
3808f4daf2Stsutsui  * 3. The name of the author may not be used to endorse or promote products
3908f4daf2Stsutsui  *    derived from this software without specific prior written permission.
4008f4daf2Stsutsui  *
4108f4daf2Stsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
4208f4daf2Stsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4308f4daf2Stsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
4408f4daf2Stsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
4508f4daf2Stsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4608f4daf2Stsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4708f4daf2Stsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4808f4daf2Stsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4908f4daf2Stsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5008f4daf2Stsutsui  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5108f4daf2Stsutsui  */
5208f4daf2Stsutsui 
53ed517291Slukem #include <sys/cdefs.h>
54*b87210faStsutsui __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.6 2008/05/14 13:29:28 tsutsui Exp $");
55ed517291Slukem 
5608f4daf2Stsutsui #include <sys/param.h>
5708f4daf2Stsutsui #include <sys/device.h>
5808f4daf2Stsutsui #include <sys/systm.h>
5908f4daf2Stsutsui 
6008f4daf2Stsutsui #include <dev/wscons/wsconsio.h>
6108f4daf2Stsutsui #include <dev/wscons/wsmousevar.h>
6208f4daf2Stsutsui 
6308f4daf2Stsutsui #include <machine/cpu.h>
6408f4daf2Stsutsui #include <machine/bus.h>
6508f4daf2Stsutsui 
6608f4daf2Stsutsui #include <news68k/dev/msvar.h>
6708f4daf2Stsutsui 
6808f4daf2Stsutsui void
ms_intr(struct ms_softc * sc)6952b46dcfStsutsui ms_intr(struct ms_softc *sc)
7008f4daf2Stsutsui {
7108f4daf2Stsutsui 	bus_space_tag_t bt = sc->sc_bt;
7208f4daf2Stsutsui 	bus_space_handle_t bh = sc->sc_bh;
7308f4daf2Stsutsui 	bus_size_t offset = sc->sc_offset;
7408f4daf2Stsutsui 	int code, index, byte0, byte1, byte2;
7508f4daf2Stsutsui 	int button, dx, dy;
7608f4daf2Stsutsui 
7708f4daf2Stsutsui 	if (sc->sc_wsmousedev == NULL)
7808f4daf2Stsutsui 		return;
7908f4daf2Stsutsui 
8008f4daf2Stsutsui 	code = bus_space_read_1(bt, bh, offset);
8108f4daf2Stsutsui 	index = sc->sc_ndata;
8208f4daf2Stsutsui 
8308f4daf2Stsutsui 	if (code & MS_S_MARK) {
8408f4daf2Stsutsui 		sc->sc_buf[MS_S_BYTE] = code;
8508f4daf2Stsutsui 		sc->sc_ndata = MS_X_BYTE;
8608f4daf2Stsutsui 		return;
8708f4daf2Stsutsui 	}
8808f4daf2Stsutsui 
8908f4daf2Stsutsui 	if (index == MS_X_BYTE) {
9008f4daf2Stsutsui 		sc->sc_buf[MS_X_BYTE] = code;
9108f4daf2Stsutsui 		sc->sc_ndata = MS_Y_BYTE;
9208f4daf2Stsutsui 		return;
9308f4daf2Stsutsui 	}
9408f4daf2Stsutsui 
9508f4daf2Stsutsui 	if (index == MS_Y_BYTE) {
9608f4daf2Stsutsui 		sc->sc_buf[MS_Y_BYTE] = code;
9708f4daf2Stsutsui 		sc->sc_ndata = 0;
9808f4daf2Stsutsui 
9908f4daf2Stsutsui 		byte0 = sc->sc_buf[MS_S_BYTE];
10008f4daf2Stsutsui 		byte1 = sc->sc_buf[MS_X_BYTE];
10108f4daf2Stsutsui 		byte2 = sc->sc_buf[MS_Y_BYTE];
10208f4daf2Stsutsui 
10308f4daf2Stsutsui 		button = 0;
10408f4daf2Stsutsui 		if (byte0 & MS_S_SW1)
10508f4daf2Stsutsui 			button |= 0x01;
10608f4daf2Stsutsui 		if (byte0 & MS_S_SW3)
10708f4daf2Stsutsui 			button |= 0x02;
10808f4daf2Stsutsui 		if (byte0 & MS_S_SW2)
10908f4daf2Stsutsui 			button |= 0x04;
11008f4daf2Stsutsui 
11108f4daf2Stsutsui 		dx = byte1 & MS_X_DATA;
11208f4daf2Stsutsui 		if (byte0 & MS_S_XSIGN)
11308f4daf2Stsutsui 			dx = -dx;
11408f4daf2Stsutsui 		dy = byte2 & MS_Y_DATA;
11508f4daf2Stsutsui 		if (byte0 & MS_S_YSIGN)
11608f4daf2Stsutsui 			dy = -dy;
11708f4daf2Stsutsui 
11857c0199dSplunky 		wsmouse_input(sc->sc_wsmousedev,
11957c0199dSplunky 				button,
12057c0199dSplunky 				dx, -dy, 0, 0,
12108f4daf2Stsutsui 		    		WSMOUSE_INPUT_DELTA);
12208f4daf2Stsutsui 	}
12308f4daf2Stsutsui }
124