xref: /netbsd-src/sys/arch/news68k/dev/ms.c (revision 4b896b232495b7a9b8b94a1cf1e21873296d53b8)
1 /*	$NetBSD: ms.c,v 1.2 2003/07/15 02:59:26 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 Izumi Tsutsui.  All rights reserved.
5  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.2 2003/07/15 02:59:26 lukem Exp $");
32 
33 #include <sys/param.h>
34 #include <sys/device.h>
35 #include <sys/systm.h>
36 
37 #include <dev/wscons/wsconsio.h>
38 #include <dev/wscons/wsmousevar.h>
39 
40 #include <machine/cpu.h>
41 #include <machine/bus.h>
42 
43 #include <news68k/dev/msvar.h>
44 
45 void
46 ms_intr(sc)
47 	struct ms_softc *sc;
48 {
49 	bus_space_tag_t bt = sc->sc_bt;
50 	bus_space_handle_t bh = sc->sc_bh;
51 	bus_size_t offset = sc->sc_offset;
52 	int code, index, byte0, byte1, byte2;
53 	int button, dx, dy;
54 
55 	if (sc->sc_wsmousedev == NULL)
56 		return;
57 
58 	code = bus_space_read_1(bt, bh, offset);
59 	index = sc->sc_ndata;
60 
61 	if (code & MS_S_MARK) {
62 		sc->sc_buf[MS_S_BYTE] = code;
63 		sc->sc_ndata = MS_X_BYTE;
64 		return;
65 	}
66 
67 	if (index == MS_X_BYTE) {
68 		sc->sc_buf[MS_X_BYTE] = code;
69 		sc->sc_ndata = MS_Y_BYTE;
70 		return;
71 	}
72 
73 	if (index == MS_Y_BYTE) {
74 		sc->sc_buf[MS_Y_BYTE] = code;
75 		sc->sc_ndata = 0;
76 
77 		byte0 = sc->sc_buf[MS_S_BYTE];
78 		byte1 = sc->sc_buf[MS_X_BYTE];
79 		byte2 = sc->sc_buf[MS_Y_BYTE];
80 
81 		button = 0;
82 		if (byte0 & MS_S_SW1)
83 			button |= 0x01;
84 		if (byte0 & MS_S_SW3)
85 			button |= 0x02;
86 		if (byte0 & MS_S_SW2)
87 			button |= 0x04;
88 
89 		dx = byte1 & MS_X_DATA;
90 		if (byte0 & MS_S_XSIGN)
91 			dx = -dx;
92 		dy = byte2 & MS_Y_DATA;
93 		if (byte0 & MS_S_YSIGN)
94 			dy = -dy;
95 
96 		wsmouse_input(sc->sc_wsmousedev, button, dx, -dy, 0,
97 		    WSMOUSE_INPUT_DELTA);
98 	}
99 }
100