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