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