qms.c revision 1.1.6.3 1 1.1.6.3 jdolecek /* $NetBSD: qms.c,v 1.1.6.3 2002/06/17 19:49:40 jdolecek Exp $ */
2 1.1.6.2 thorpej
3 1.1.6.2 thorpej /*
4 1.1.6.2 thorpej * Copyright (c) Scott Stevens 1995 All rights reserved
5 1.1.6.2 thorpej * Copyright (c) Melvin Tang-Richardson 1995 All rights reserved
6 1.1.6.2 thorpej * Copyright (c) Mark Brinicombe 1995 All rights reserved
7 1.1.6.2 thorpej *
8 1.1.6.2 thorpej * Redistribution and use in source and binary forms, with or without
9 1.1.6.2 thorpej * modification, are permitted provided that the following conditions
10 1.1.6.2 thorpej * are met:
11 1.1.6.2 thorpej * 1. Redistributions of source code must retain the above copyright
12 1.1.6.2 thorpej * notice, this list of conditions and the following disclaimer.
13 1.1.6.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.6.2 thorpej * notice, this list of conditions and the following disclaimer in the
15 1.1.6.2 thorpej * documentation and/or other materials provided with the distribution.
16 1.1.6.2 thorpej * 3. All advertising materials mentioning features or use of this software
17 1.1.6.2 thorpej * must display the following acknowledgement:
18 1.1.6.2 thorpej * This product includes software developed for the NetBSD Project.
19 1.1.6.2 thorpej * 4. The name of the author may not be used to endorse or promote products
20 1.1.6.2 thorpej * derived from this software without specific prior written permission.
21 1.1.6.2 thorpej *
22 1.1.6.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1.6.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1.6.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1.6.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1.6.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1.6.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1.6.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1.6.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1.6.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1.6.2 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1.6.2 thorpej */
33 1.1.6.2 thorpej
34 1.1.6.2 thorpej /*
35 1.1.6.2 thorpej * Quadrature mouse driver
36 1.1.6.2 thorpej */
37 1.1.6.2 thorpej
38 1.1.6.2 thorpej #include <sys/param.h>
39 1.1.6.2 thorpej #include <sys/systm.h>
40 1.1.6.2 thorpej #include <sys/conf.h>
41 1.1.6.2 thorpej #include <sys/ioctl.h>
42 1.1.6.2 thorpej #include <sys/tty.h>
43 1.1.6.2 thorpej #include <sys/kernel.h>
44 1.1.6.2 thorpej #include <sys/types.h>
45 1.1.6.2 thorpej #include <sys/device.h>
46 1.1.6.2 thorpej #include <sys/proc.h>
47 1.1.6.2 thorpej #include <sys/time.h>
48 1.1.6.2 thorpej #include <sys/errno.h>
49 1.1.6.2 thorpej #include <dev/cons.h>
50 1.1.6.2 thorpej #include <sys/fcntl.h>
51 1.1.6.2 thorpej #include <sys/signalvar.h>
52 1.1.6.2 thorpej #include <sys/vnode.h>
53 1.1.6.2 thorpej #include <sys/time.h>
54 1.1.6.2 thorpej #include <sys/poll.h>
55 1.1.6.2 thorpej
56 1.1.6.2 thorpej #include <machine/bus.h>
57 1.1.6.2 thorpej #include <machine/conf.h>
58 1.1.6.2 thorpej #include <machine/mouse.h>
59 1.1.6.2 thorpej #include <arm/iomd/qmsvar.h>
60 1.1.6.2 thorpej
61 1.1.6.2 thorpej #define MOUSE_IOC_ACK
62 1.1.6.2 thorpej
63 1.1.6.2 thorpej #define QMOUSE_BSIZE 12*64
64 1.1.6.2 thorpej
65 1.1.6.2 thorpej #ifdef MOUSE_IOC_ACK
66 1.1.6.2 thorpej static void qmsputbuffer __P((struct qms_softc *sc, struct mousebufrec *buf));
67 1.1.6.2 thorpej #endif
68 1.1.6.2 thorpej
69 1.1.6.2 thorpej extern struct cfdriver qms_cd;
70 1.1.6.2 thorpej
71 1.1.6.2 thorpej /* qms device structure */
72 1.1.6.2 thorpej
73 1.1.6.2 thorpej /* Offsets of hardware registers */
74 1.1.6.2 thorpej #define QMS_MOUSEX 0 /* 16 bit X register */
75 1.1.6.2 thorpej #define QMS_MOUSEY 1 /* 16 bit Y register */
76 1.1.6.2 thorpej
77 1.1.6.2 thorpej #define QMS_BUTTONS 0 /* mouse buttons register */
78 1.1.6.2 thorpej
79 1.1.6.2 thorpej /*
80 1.1.6.2 thorpej * generic attach routine. This does the generic part of the driver
81 1.1.6.2 thorpej * attachment and is called from the bus specific attach routine.
82 1.1.6.2 thorpej */
83 1.1.6.2 thorpej
84 1.1.6.2 thorpej void
85 1.1.6.2 thorpej qmsattach(sc)
86 1.1.6.2 thorpej struct qms_softc *sc;
87 1.1.6.2 thorpej {
88 1.1.6.2 thorpej /* Set up origin and multipliers */
89 1.1.6.2 thorpej sc->origx = 0;
90 1.1.6.2 thorpej sc->origy = 0;
91 1.1.6.2 thorpej sc->xmult = 2;
92 1.1.6.2 thorpej sc->ymult = 2;
93 1.1.6.2 thorpej
94 1.1.6.2 thorpej /* Set up bounding box */
95 1.1.6.2 thorpej sc->boundx = -4095;
96 1.1.6.2 thorpej sc->boundy = -4095;
97 1.1.6.2 thorpej sc->bounda = 4096;
98 1.1.6.2 thorpej sc->boundb = 4096;
99 1.1.6.2 thorpej
100 1.1.6.2 thorpej sc->sc_state = 0;
101 1.1.6.2 thorpej
102 1.1.6.2 thorpej /* Set the mouse X & Y registers to a known state */
103 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, sc->origx);
104 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, sc->origx);
105 1.1.6.2 thorpej }
106 1.1.6.2 thorpej
107 1.1.6.2 thorpej int
108 1.1.6.2 thorpej qmsopen(dev, flag, mode, p)
109 1.1.6.2 thorpej dev_t dev;
110 1.1.6.2 thorpej int flag;
111 1.1.6.2 thorpej int mode;
112 1.1.6.2 thorpej struct proc *p;
113 1.1.6.2 thorpej {
114 1.1.6.2 thorpej struct qms_softc *sc;
115 1.1.6.2 thorpej int unit = minor(dev);
116 1.1.6.2 thorpej
117 1.1.6.2 thorpej /* validate the unit and softc */
118 1.1.6.2 thorpej if (unit >= qms_cd.cd_ndevs)
119 1.1.6.2 thorpej return(ENXIO);
120 1.1.6.2 thorpej
121 1.1.6.2 thorpej sc = qms_cd.cd_devs[unit];
122 1.1.6.2 thorpej
123 1.1.6.2 thorpej if (!sc) return(ENXIO);
124 1.1.6.2 thorpej
125 1.1.6.2 thorpej /* check if we are already open */
126 1.1.6.2 thorpej if (sc->sc_state & QMOUSE_OPEN) return(EBUSY);
127 1.1.6.2 thorpej
128 1.1.6.2 thorpej /* update softc */
129 1.1.6.2 thorpej sc->sc_proc = p;
130 1.1.6.2 thorpej
131 1.1.6.2 thorpej sc->lastx = -1;
132 1.1.6.2 thorpej sc->lasty = -1;
133 1.1.6.2 thorpej sc->lastb = -1;
134 1.1.6.2 thorpej
135 1.1.6.2 thorpej /* initialise buffer */
136 1.1.6.2 thorpej if (clalloc(&sc->sc_buffer, QMOUSE_BSIZE, 0) == -1)
137 1.1.6.2 thorpej return(ENOMEM);
138 1.1.6.2 thorpej
139 1.1.6.2 thorpej /* set mode and state */
140 1.1.6.2 thorpej sc->sc_mode = MOUSEMODE_ABS;
141 1.1.6.2 thorpej sc->sc_state |= QMOUSE_OPEN;
142 1.1.6.2 thorpej
143 1.1.6.2 thorpej /* enable interrupts */
144 1.1.6.2 thorpej sc->sc_intenable(sc, 1);
145 1.1.6.2 thorpej
146 1.1.6.2 thorpej return(0);
147 1.1.6.2 thorpej }
148 1.1.6.2 thorpej
149 1.1.6.2 thorpej
150 1.1.6.2 thorpej int
151 1.1.6.2 thorpej qmsclose(dev, flag, mode, p)
152 1.1.6.2 thorpej dev_t dev;
153 1.1.6.2 thorpej int flag;
154 1.1.6.2 thorpej int mode;
155 1.1.6.2 thorpej struct proc *p;
156 1.1.6.2 thorpej {
157 1.1.6.2 thorpej int unit = minor(dev);
158 1.1.6.2 thorpej struct qms_softc *sc = qms_cd.cd_devs[unit];
159 1.1.6.2 thorpej
160 1.1.6.2 thorpej /* disable interrupts */
161 1.1.6.2 thorpej sc->sc_intenable(sc, 0);
162 1.1.6.2 thorpej
163 1.1.6.2 thorpej /* clean up */
164 1.1.6.2 thorpej sc->sc_proc = NULL;
165 1.1.6.2 thorpej sc->sc_state = 0;
166 1.1.6.2 thorpej
167 1.1.6.2 thorpej clfree(&sc->sc_buffer);
168 1.1.6.2 thorpej
169 1.1.6.2 thorpej return(0);
170 1.1.6.2 thorpej }
171 1.1.6.2 thorpej
172 1.1.6.2 thorpej int
173 1.1.6.2 thorpej qmsread(dev, uio, flag)
174 1.1.6.2 thorpej dev_t dev;
175 1.1.6.2 thorpej struct uio *uio;
176 1.1.6.2 thorpej int flag;
177 1.1.6.2 thorpej {
178 1.1.6.2 thorpej int unit = minor(dev);
179 1.1.6.2 thorpej struct qms_softc *sc = qms_cd.cd_devs[unit];
180 1.1.6.2 thorpej int error;
181 1.1.6.2 thorpej int s;
182 1.1.6.2 thorpej int length;
183 1.1.6.2 thorpej u_char buffer[128];
184 1.1.6.2 thorpej
185 1.1.6.2 thorpej error = 0;
186 1.1.6.2 thorpej s = spltty();
187 1.1.6.2 thorpej while (sc->sc_buffer.c_cc == 0) {
188 1.1.6.2 thorpej if (flag & IO_NDELAY) {
189 1.1.6.2 thorpej (void)splx(s);
190 1.1.6.2 thorpej return(EWOULDBLOCK);
191 1.1.6.2 thorpej }
192 1.1.6.2 thorpej sc->sc_state |= QMOUSE_ASLEEP;
193 1.1.6.2 thorpej if ((error = tsleep((caddr_t)sc, PZERO | PCATCH, "qmsread", 0))) {
194 1.1.6.2 thorpej sc->sc_state &= ~QMOUSE_ASLEEP;
195 1.1.6.2 thorpej (void)splx(s);
196 1.1.6.2 thorpej return(error);
197 1.1.6.2 thorpej }
198 1.1.6.2 thorpej }
199 1.1.6.2 thorpej
200 1.1.6.2 thorpej while (sc->sc_buffer.c_cc > 0 && uio->uio_resid > 0) {
201 1.1.6.2 thorpej length = min(sc->sc_buffer.c_cc, uio->uio_resid);
202 1.1.6.2 thorpej if(length>sizeof(buffer))
203 1.1.6.2 thorpej length=sizeof(buffer);
204 1.1.6.2 thorpej
205 1.1.6.2 thorpej (void)q_to_b(&sc->sc_buffer, buffer, length);
206 1.1.6.2 thorpej
207 1.1.6.2 thorpej if ((error = (uiomove(buffer, length, uio))))
208 1.1.6.2 thorpej break;
209 1.1.6.2 thorpej }
210 1.1.6.2 thorpej (void)splx(s);
211 1.1.6.2 thorpej return(error);
212 1.1.6.2 thorpej }
213 1.1.6.2 thorpej
214 1.1.6.2 thorpej
215 1.1.6.2 thorpej #define FMT_START \
216 1.1.6.2 thorpej int x = bus_space_read_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX) & 0xffff; \
217 1.1.6.2 thorpej int y = bus_space_read_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY) & 0xffff; \
218 1.1.6.2 thorpej int b = bus_space_read_1(sc->sc_iot, sc->sc_butioh, QMS_BUTTONS) & 0x70;\
219 1.1.6.2 thorpej if (x & 0x8000) x |= 0xffff0000; \
220 1.1.6.2 thorpej if (y & 0x8000) y |= 0xffff0000; \
221 1.1.6.2 thorpej x = (x - sc->origx); \
222 1.1.6.2 thorpej y = (y - sc->origy); \
223 1.1.6.2 thorpej if (x < (sc->boundx)) x = sc->boundx; \
224 1.1.6.2 thorpej if (x > (sc->bounda)) x = sc->bounda; \
225 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, x + sc->origx); \
226 1.1.6.2 thorpej if (y < (sc->boundy)) y = sc->boundy; \
227 1.1.6.2 thorpej if (y > (sc->boundb)) y = sc->boundb; \
228 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY, y + sc->origy); \
229 1.1.6.2 thorpej x = x * sc->xmult; \
230 1.1.6.2 thorpej y = y * sc->ymult;
231 1.1.6.2 thorpej
232 1.1.6.2 thorpej #define FMT_END
233 1.1.6.2 thorpej
234 1.1.6.2 thorpej
235 1.1.6.2 thorpej int
236 1.1.6.2 thorpej qmsioctl(dev, cmd, data, flag, p)
237 1.1.6.2 thorpej dev_t dev;
238 1.1.6.2 thorpej u_long cmd;
239 1.1.6.2 thorpej caddr_t data;
240 1.1.6.2 thorpej int flag;
241 1.1.6.2 thorpej struct proc *p;
242 1.1.6.2 thorpej {
243 1.1.6.2 thorpej struct qms_softc *sc = qms_cd.cd_devs[minor(dev)];
244 1.1.6.2 thorpej
245 1.1.6.2 thorpej switch (cmd) {
246 1.1.6.2 thorpej case MOUSEIOC_WRITEX:
247 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX,
248 1.1.6.2 thorpej *(int *)data + sc->origx);
249 1.1.6.2 thorpej return 0;
250 1.1.6.2 thorpej case MOUSEIOC_WRITEY:
251 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY,
252 1.1.6.2 thorpej *(int *)data + sc->origy);
253 1.1.6.2 thorpej return 0;
254 1.1.6.2 thorpej case MOUSEIOC_SETSTATE:
255 1.1.6.2 thorpej {
256 1.1.6.2 thorpej struct mouse_state *co = (void *)data;
257 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, co->x);
258 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY, co->y);
259 1.1.6.2 thorpej return 0;
260 1.1.6.2 thorpej }
261 1.1.6.2 thorpej case MOUSEIOC_SETBOUNDS:
262 1.1.6.2 thorpej {
263 1.1.6.2 thorpej struct mouse_boundingbox *bo = (void *)data;
264 1.1.6.2 thorpej struct mousebufrec buffer;
265 1.1.6.2 thorpej #ifdef MOUSE_IOC_ACK
266 1.1.6.2 thorpej int s;
267 1.1.6.2 thorpej
268 1.1.6.2 thorpej s = spltty();
269 1.1.6.2 thorpej #endif
270 1.1.6.2 thorpej
271 1.1.6.2 thorpej sc->boundx = bo->x;
272 1.1.6.2 thorpej sc->boundy = bo->y;
273 1.1.6.2 thorpej sc->bounda = bo->a;
274 1.1.6.2 thorpej sc->boundb = bo->b;
275 1.1.6.2 thorpej
276 1.1.6.2 thorpej buffer.status = IOC_ACK;
277 1.1.6.2 thorpej buffer.x = sc->origx;
278 1.1.6.2 thorpej buffer.y = sc->origy;
279 1.1.6.2 thorpej #ifdef MOUSE_IOC_ACK
280 1.1.6.2 thorpej if (sc->sc_buffer.c_cc > 0)
281 1.1.6.2 thorpej printf("%s: setting bounding with non empty buffer (%d)\n",
282 1.1.6.2 thorpej sc->sc_device.dv_xname, sc->sc_buffer.c_cc);
283 1.1.6.2 thorpej qmsputbuffer(sc, &buffer);
284 1.1.6.2 thorpej (void)splx(s);
285 1.1.6.2 thorpej #endif
286 1.1.6.2 thorpej return 0;
287 1.1.6.2 thorpej }
288 1.1.6.2 thorpej case MOUSEIOC_SETMODE:
289 1.1.6.2 thorpej {
290 1.1.6.2 thorpej struct mousebufrec buffer;
291 1.1.6.2 thorpej #ifdef MOUSE_IOC_ACK
292 1.1.6.2 thorpej int s;
293 1.1.6.2 thorpej
294 1.1.6.2 thorpej s = spltty();
295 1.1.6.2 thorpej #endif
296 1.1.6.2 thorpej sc->sc_mode = *(int *)data;
297 1.1.6.2 thorpej
298 1.1.6.2 thorpej buffer.status = IOC_ACK;
299 1.1.6.2 thorpej buffer.x = sc->origx;
300 1.1.6.2 thorpej buffer.y = sc->origy;
301 1.1.6.2 thorpej #ifdef MOUSE_IOC_ACK
302 1.1.6.2 thorpej if (sc->sc_buffer.c_cc > 0)
303 1.1.6.2 thorpej printf("%s: setting mode with non empty buffer (%d)\n",
304 1.1.6.2 thorpej sc->sc_device.dv_xname, sc->sc_buffer.c_cc);
305 1.1.6.2 thorpej qmsputbuffer(sc, &buffer);
306 1.1.6.2 thorpej (void)splx(s);
307 1.1.6.2 thorpej #endif
308 1.1.6.2 thorpej return 0;
309 1.1.6.2 thorpej }
310 1.1.6.2 thorpej case MOUSEIOC_SETORIGIN:
311 1.1.6.2 thorpej {
312 1.1.6.2 thorpej struct mouse_origin *oo = (void *)data;
313 1.1.6.2 thorpej struct mousebufrec buffer;
314 1.1.6.2 thorpej #ifdef MOUSE_IOC_ACK
315 1.1.6.2 thorpej int s;
316 1.1.6.2 thorpej
317 1.1.6.2 thorpej s = spltty();
318 1.1.6.2 thorpej #endif
319 1.1.6.2 thorpej /* Need to fix up! */
320 1.1.6.2 thorpej sc->origx = oo->x;
321 1.1.6.2 thorpej sc->origy = oo->y;
322 1.1.6.2 thorpej
323 1.1.6.2 thorpej buffer.status = IOC_ACK;
324 1.1.6.2 thorpej buffer.x = sc->origx;
325 1.1.6.2 thorpej buffer.y = sc->origy;
326 1.1.6.2 thorpej #ifdef MOUSE_IOC_ACK
327 1.1.6.2 thorpej if (sc->sc_buffer.c_cc > 0)
328 1.1.6.2 thorpej printf("%s: setting origin with non empty buffer (%d)\n",
329 1.1.6.2 thorpej sc->sc_device.dv_xname, sc->sc_buffer.c_cc);
330 1.1.6.2 thorpej qmsputbuffer(sc, &buffer);
331 1.1.6.2 thorpej (void)splx(s);
332 1.1.6.2 thorpej #endif
333 1.1.6.2 thorpej return 0;
334 1.1.6.2 thorpej }
335 1.1.6.2 thorpej case MOUSEIOC_GETSTATE:
336 1.1.6.2 thorpej {
337 1.1.6.2 thorpej struct mouse_state *co = (void *)data;
338 1.1.6.2 thorpej FMT_START
339 1.1.6.2 thorpej co->x = x;
340 1.1.6.2 thorpej co->y = y;
341 1.1.6.2 thorpej co->buttons = b ^ 0x70;
342 1.1.6.2 thorpej FMT_END
343 1.1.6.2 thorpej return 0;
344 1.1.6.2 thorpej }
345 1.1.6.2 thorpej case MOUSEIOC_GETBOUNDS:
346 1.1.6.2 thorpej {
347 1.1.6.2 thorpej struct mouse_boundingbox *bo = (void *)data;
348 1.1.6.2 thorpej bo->x = sc->boundx;
349 1.1.6.2 thorpej bo->y = sc->boundy;
350 1.1.6.2 thorpej bo->a = sc->bounda;
351 1.1.6.2 thorpej bo->b = sc->boundb;
352 1.1.6.2 thorpej return 0;
353 1.1.6.2 thorpej }
354 1.1.6.2 thorpej case MOUSEIOC_GETORIGIN:
355 1.1.6.2 thorpej {
356 1.1.6.2 thorpej struct mouse_origin *oo = (void *)data;
357 1.1.6.2 thorpej oo->x = sc->origx;
358 1.1.6.2 thorpej oo->y = sc->origy;
359 1.1.6.2 thorpej return 0;
360 1.1.6.2 thorpej }
361 1.1.6.2 thorpej }
362 1.1.6.2 thorpej
363 1.1.6.2 thorpej return (EINVAL);
364 1.1.6.2 thorpej }
365 1.1.6.2 thorpej
366 1.1.6.2 thorpej
367 1.1.6.2 thorpej int
368 1.1.6.2 thorpej qmsintr(arg)
369 1.1.6.2 thorpej void *arg;
370 1.1.6.2 thorpej {
371 1.1.6.2 thorpej struct qms_softc *sc = arg;
372 1.1.6.2 thorpej int s;
373 1.1.6.2 thorpej struct mousebufrec buffer;
374 1.1.6.2 thorpej int dosignal=0;
375 1.1.6.2 thorpej
376 1.1.6.2 thorpej FMT_START
377 1.1.6.2 thorpej
378 1.1.6.2 thorpej b &= 0x70;
379 1.1.6.2 thorpej b >>= 4;
380 1.1.6.2 thorpej if (x != sc->lastx || y != sc->lasty || b != sc->lastb) {
381 1.1.6.2 thorpej /* Mouse state changed */
382 1.1.6.2 thorpej buffer.status = b | ( b ^ sc->lastb) << 3 | (((x==sc->lastx) && (y==sc->lasty))?0:MOVEMENT);
383 1.1.6.2 thorpej if(sc->sc_mode == MOUSEMODE_REL) {
384 1.1.6.2 thorpej sc->origx = sc->origy = 0;
385 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, sc->origx);
386 1.1.6.2 thorpej bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY, sc->origy);
387 1.1.6.2 thorpej }
388 1.1.6.2 thorpej buffer.x = x;
389 1.1.6.2 thorpej buffer.y = y;
390 1.1.6.2 thorpej microtime(&buffer.event_time);
391 1.1.6.2 thorpej
392 1.1.6.2 thorpej if (sc->sc_buffer.c_cc == 0)
393 1.1.6.2 thorpej dosignal = 1;
394 1.1.6.2 thorpej
395 1.1.6.2 thorpej s = spltty();
396 1.1.6.2 thorpej (void)b_to_q((char *)&buffer, sizeof(buffer), &sc->sc_buffer);
397 1.1.6.2 thorpej (void)splx(s);
398 1.1.6.2 thorpej selwakeup(&sc->sc_rsel);
399 1.1.6.2 thorpej
400 1.1.6.2 thorpej if (sc->sc_state & QMOUSE_ASLEEP) {
401 1.1.6.2 thorpej sc->sc_state &= ~QMOUSE_ASLEEP;
402 1.1.6.2 thorpej wakeup((caddr_t)sc);
403 1.1.6.2 thorpej }
404 1.1.6.2 thorpej
405 1.1.6.2 thorpej /* if (dosignal)*/
406 1.1.6.2 thorpej psignal(sc->sc_proc, SIGIO);
407 1.1.6.2 thorpej
408 1.1.6.2 thorpej sc->lastx = x;
409 1.1.6.2 thorpej sc->lasty = y;
410 1.1.6.2 thorpej sc->lastb = b;
411 1.1.6.2 thorpej }
412 1.1.6.2 thorpej
413 1.1.6.2 thorpej FMT_END
414 1.1.6.2 thorpej return(0); /* Pass interrupt on down the chain */
415 1.1.6.2 thorpej }
416 1.1.6.2 thorpej
417 1.1.6.2 thorpej
418 1.1.6.2 thorpej int
419 1.1.6.2 thorpej qmspoll(dev, events, p)
420 1.1.6.2 thorpej dev_t dev;
421 1.1.6.2 thorpej int events;
422 1.1.6.2 thorpej struct proc *p;
423 1.1.6.2 thorpej {
424 1.1.6.2 thorpej struct qms_softc *sc = qms_cd.cd_devs[minor(dev)];
425 1.1.6.2 thorpej int revents = 0;
426 1.1.6.2 thorpej int s = spltty();
427 1.1.6.2 thorpej
428 1.1.6.2 thorpej if (events & (POLLIN | POLLRDNORM)) {
429 1.1.6.2 thorpej if (sc->sc_buffer.c_cc > 0)
430 1.1.6.2 thorpej revents |= events & (POLLIN | POLLRDNORM);
431 1.1.6.2 thorpej else
432 1.1.6.2 thorpej selrecord(p, &sc->sc_rsel);
433 1.1.6.2 thorpej }
434 1.1.6.2 thorpej
435 1.1.6.2 thorpej (void)splx(s);
436 1.1.6.2 thorpej return (revents);
437 1.1.6.2 thorpej }
438 1.1.6.2 thorpej
439 1.1.6.2 thorpej
440 1.1.6.2 thorpej #ifdef MOUSE_IOC_ACK
441 1.1.6.2 thorpej static void
442 1.1.6.2 thorpej qmsputbuffer(sc, buffer)
443 1.1.6.2 thorpej struct qms_softc *sc;
444 1.1.6.2 thorpej struct mousebufrec *buffer;
445 1.1.6.2 thorpej {
446 1.1.6.2 thorpej int s;
447 1.1.6.2 thorpej int dosignal = 0;
448 1.1.6.2 thorpej
449 1.1.6.2 thorpej /* Time stamp the buffer */
450 1.1.6.2 thorpej microtime(&buffer->event_time);
451 1.1.6.2 thorpej
452 1.1.6.2 thorpej if (sc->sc_buffer.c_cc == 0)
453 1.1.6.2 thorpej dosignal=1;
454 1.1.6.2 thorpej
455 1.1.6.2 thorpej s = spltty();
456 1.1.6.2 thorpej (void)b_to_q((char *)buffer, sizeof(*buffer), &sc->sc_buffer);
457 1.1.6.2 thorpej (void)splx(s);
458 1.1.6.2 thorpej selwakeup(&sc->sc_rsel);
459 1.1.6.2 thorpej
460 1.1.6.2 thorpej if (sc->sc_state & QMOUSE_ASLEEP) {
461 1.1.6.2 thorpej sc->sc_state &= ~QMOUSE_ASLEEP;
462 1.1.6.2 thorpej wakeup((caddr_t)sc);
463 1.1.6.2 thorpej }
464 1.1.6.2 thorpej
465 1.1.6.2 thorpej if (dosignal)
466 1.1.6.2 thorpej psignal(sc->sc_proc, SIGIO);
467 1.1.6.2 thorpej }
468 1.1.6.2 thorpej #endif
469 1.1.6.2 thorpej
470 1.1.6.3 jdolecek /* XXXLUKEM (jdolecek) kqueue hooks not tested */
471 1.1.6.3 jdolecek static void
472 1.1.6.3 jdolecek filt_qmsrdetach(struct knote *kn)
473 1.1.6.3 jdolecek {
474 1.1.6.3 jdolecek struct qms_softc *sc = (void *) kn->kn_hook;
475 1.1.6.3 jdolecek int s;
476 1.1.6.3 jdolecek
477 1.1.6.3 jdolecek s = spltty();
478 1.1.6.3 jdolecek SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext);
479 1.1.6.3 jdolecek splx(s);
480 1.1.6.3 jdolecek }
481 1.1.6.3 jdolecek
482 1.1.6.3 jdolecek static int
483 1.1.6.3 jdolecek filt_qmsread(struct knote *kn, long hint)
484 1.1.6.3 jdolecek {
485 1.1.6.3 jdolecek struct qms_softc *sc = (void *) kn->kn_hook;
486 1.1.6.3 jdolecek
487 1.1.6.3 jdolecek kn->kn_data = sc->sc_buffer.c_cc;
488 1.1.6.3 jdolecek return (kn->kn_data > 0);
489 1.1.6.3 jdolecek }
490 1.1.6.3 jdolecek
491 1.1.6.3 jdolecek static const struct filterops qmsread_filtops =
492 1.1.6.3 jdolecek { 1, NULL, filt_qmsrdetach, filt_qmsread };
493 1.1.6.3 jdolecek
494 1.1.6.3 jdolecek int
495 1.1.6.3 jdolecek qmskqfilter(dev_t dev, struct knote *kn)
496 1.1.6.3 jdolecek {
497 1.1.6.3 jdolecek struct qms_softc *sc = qms_cd.cd_devs[minor(dev)];
498 1.1.6.3 jdolecek struct klist *klist;
499 1.1.6.3 jdolecek int s;
500 1.1.6.3 jdolecek
501 1.1.6.3 jdolecek switch (kn->kn_filter) {
502 1.1.6.3 jdolecek case EVFILT_READ:
503 1.1.6.3 jdolecek klist = &sc->sc_rsel.si_klist;
504 1.1.6.3 jdolecek kn->kn_fop = &qmsread_filtops;
505 1.1.6.3 jdolecek break;
506 1.1.6.3 jdolecek
507 1.1.6.3 jdolecek default:
508 1.1.6.3 jdolecek return (1);
509 1.1.6.3 jdolecek }
510 1.1.6.3 jdolecek
511 1.1.6.3 jdolecek kn->kn_hook = (void *) sc;
512 1.1.6.3 jdolecek
513 1.1.6.3 jdolecek s = spltty();
514 1.1.6.3 jdolecek SLIST_INSERT_HEAD(klist, kn, kn_selnext);
515 1.1.6.3 jdolecek splx(s);
516 1.1.6.3 jdolecek
517 1.1.6.3 jdolecek return (0);
518 1.1.6.3 jdolecek }
519 1.1.6.3 jdolecek
520 1.1.6.2 thorpej /* End of qms.c */
521