vsxxx.c revision 1.2.6.2 1 1.2.6.2 bouyer /* $NetBSD: vsxxx.c,v 1.2.6.2 2000/11/20 11:39:54 bouyer Exp $ */
2 1.2.6.2 bouyer
3 1.2.6.2 bouyer /*
4 1.2.6.2 bouyer * Copyright (c) 1999 Tohru Nishimura. All rights reserved.
5 1.2.6.2 bouyer *
6 1.2.6.2 bouyer * Redistribution and use in source and binary forms, with or without
7 1.2.6.2 bouyer * modification, are permitted provided that the following conditions
8 1.2.6.2 bouyer * are met:
9 1.2.6.2 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.2.6.2 bouyer * notice, this list of conditions and the following disclaimer.
11 1.2.6.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.2.6.2 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.2.6.2 bouyer * documentation and/or other materials provided with the distribution.
14 1.2.6.2 bouyer * 3. All advertising materials mentioning features or use of this software
15 1.2.6.2 bouyer * must display the following acknowledgement:
16 1.2.6.2 bouyer * This product includes software developed by Tohru Nishimura.
17 1.2.6.2 bouyer * for the NetBSD Project.
18 1.2.6.2 bouyer * 4. The name of the author may not be used to endorse or promote products
19 1.2.6.2 bouyer * derived from this software without specific prior written permission
20 1.2.6.2 bouyer *
21 1.2.6.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.2.6.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.2.6.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.2.6.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.2.6.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.2.6.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.2.6.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.2.6.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.2.6.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.2.6.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.2.6.2 bouyer */
32 1.2.6.2 bouyer
33 1.2.6.2 bouyer #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
34 1.2.6.2 bouyer
35 1.2.6.2 bouyer __KERNEL_RCSID(0, "$NetBSD: vsxxx.c,v 1.2.6.2 2000/11/20 11:39:54 bouyer Exp $");
36 1.2.6.2 bouyer
37 1.2.6.2 bouyer /*
38 1.2.6.2 bouyer * Common machinary for VSXXX mice and tablet
39 1.2.6.2 bouyer */
40 1.2.6.2 bouyer
41 1.2.6.2 bouyer #include <sys/param.h>
42 1.2.6.2 bouyer #include <sys/systm.h>
43 1.2.6.2 bouyer #include <sys/device.h>
44 1.2.6.2 bouyer
45 1.2.6.2 bouyer #include <dev/wscons/wsconsio.h>
46 1.2.6.2 bouyer #include <dev/wscons/wsmousevar.h>
47 1.2.6.2 bouyer
48 1.2.6.2 bouyer #include <dev/dec/vsxxxvar.h>
49 1.2.6.2 bouyer
50 1.2.6.2 bouyer /*
51 1.2.6.2 bouyer * XXX XXX XXX
52 1.2.6.2 bouyer *
53 1.2.6.2 bouyer * collect various mice and tablet parameters/protocol design
54 1.2.6.2 bouyer * and establish vsxxx.h
55 1.2.6.2 bouyer *
56 1.2.6.2 bouyer * XXX XXX XXX
57 1.2.6.2 bouyer */
58 1.2.6.2 bouyer #define VS_SELFTEST 'T'
59 1.2.6.2 bouyer #define VS_INCREMENTAL 'R'
60 1.2.6.2 bouyer #define VS_PROMPTING 'D'
61 1.2.6.2 bouyer #define VS_REQ_POSITION 'P'
62 1.2.6.2 bouyer
63 1.2.6.2 bouyer #define VS_MOUSE_REPSZ 3
64 1.2.6.2 bouyer #define VS_TABLET_REPSZ 5
65 1.2.6.2 bouyer
66 1.2.6.2 bouyer /* first octet */
67 1.2.6.2 bouyer #define VS_START_FRAME 0x80
68 1.2.6.2 bouyer #define VS_R_BUTTON 0x01
69 1.2.6.2 bouyer #define VS_M_BUTTON 0x02
70 1.2.6.2 bouyer #define VS_L_BUTTON 0x04
71 1.2.6.2 bouyer #define VS_Y_SIGN 0x08
72 1.2.6.2 bouyer #define VS_X_SIGN 0x10
73 1.2.6.2 bouyer
74 1.2.6.2 bouyer /* low order 4 bit of the second octet in a SELFTEST reply */
75 1.2.6.2 bouyer #define VS_MOUSE 0x2
76 1.2.6.2 bouyer #define VS_TABLET 0x4
77 1.2.6.2 bouyer
78 1.2.6.2 bouyer extern struct cfdriver vsms_cd;
79 1.2.6.2 bouyer
80 1.2.6.2 bouyer static int vsxxx_enable __P((void *));
81 1.2.6.2 bouyer static int vsxxx_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
82 1.2.6.2 bouyer static void vsxxx_disable __P((void *));
83 1.2.6.2 bouyer
84 1.2.6.2 bouyer struct wsmouse_accessops vsxxx_accessops = { /* EXPORT */
85 1.2.6.2 bouyer vsxxx_enable, /* MD? */
86 1.2.6.2 bouyer vsxxx_ioctl,
87 1.2.6.2 bouyer vsxxx_disable, /* MD? */
88 1.2.6.2 bouyer };
89 1.2.6.2 bouyer
90 1.2.6.2 bouyer static int
91 1.2.6.2 bouyer vsxxx_enable(v)
92 1.2.6.2 bouyer void *v;
93 1.2.6.2 bouyer {
94 1.2.6.2 bouyer /* turn on the hardware? */
95 1.2.6.2 bouyer ((struct vsxxx_softc *)v)->sc_nbyte = 0;
96 1.2.6.2 bouyer return 0;
97 1.2.6.2 bouyer }
98 1.2.6.2 bouyer
99 1.2.6.2 bouyer static void
100 1.2.6.2 bouyer vsxxx_disable(v)
101 1.2.6.2 bouyer void *v;
102 1.2.6.2 bouyer {
103 1.2.6.2 bouyer /* turn off the hardware? */
104 1.2.6.2 bouyer }
105 1.2.6.2 bouyer
106 1.2.6.2 bouyer /*ARGUSED*/
107 1.2.6.2 bouyer static int
108 1.2.6.2 bouyer vsxxx_ioctl(v, cmd, data, flag, p)
109 1.2.6.2 bouyer void *v;
110 1.2.6.2 bouyer u_long cmd;
111 1.2.6.2 bouyer caddr_t data;
112 1.2.6.2 bouyer int flag;
113 1.2.6.2 bouyer struct proc *p;
114 1.2.6.2 bouyer {
115 1.2.6.2 bouyer if (cmd == WSMOUSEIO_GTYPE) {
116 1.2.6.2 bouyer *(u_int *)data = WSMOUSE_TYPE_VSXXX;
117 1.2.6.2 bouyer return 0;
118 1.2.6.2 bouyer }
119 1.2.6.2 bouyer return ENOTTY;
120 1.2.6.2 bouyer }
121 1.2.6.2 bouyer
122 1.2.6.2 bouyer /* EXPORT */ void
123 1.2.6.2 bouyer vsxxx_input(data)
124 1.2.6.2 bouyer int data;
125 1.2.6.2 bouyer {
126 1.2.6.2 bouyer struct vsxxx_softc *sc = (void *)vsms_cd.cd_devs[0];
127 1.2.6.2 bouyer int x, y;
128 1.2.6.2 bouyer
129 1.2.6.2 bouyer if (data & VS_START_FRAME)
130 1.2.6.2 bouyer sc->sc_nbyte = 0;
131 1.2.6.2 bouyer
132 1.2.6.2 bouyer sc->sc_report.raw[sc->sc_nbyte++] = data;
133 1.2.6.2 bouyer
134 1.2.6.2 bouyer if (sc->sc_nbyte < VS_MOUSE_REPSZ)
135 1.2.6.2 bouyer return;
136 1.2.6.2 bouyer sc->sc_nbyte = 0;
137 1.2.6.2 bouyer
138 1.2.6.2 bouyer x = sc->sc_report.ms.xpos;
139 1.2.6.2 bouyer y = sc->sc_report.ms.ypos;
140 1.2.6.2 bouyer if ((sc->sc_report.raw[0] & VS_X_SIGN) == 0)
141 1.2.6.2 bouyer x = -x;
142 1.2.6.2 bouyer if ((sc->sc_report.raw[0] & VS_Y_SIGN) != 0)
143 1.2.6.2 bouyer y = -y; /* Eeeh? */
144 1.2.6.2 bouyer wsmouse_input(sc->sc_wsmousedev, sc->sc_report.raw[0] & 07, x, y, 0,
145 1.2.6.2 bouyer WSMOUSE_INPUT_DELTA);
146 1.2.6.2 bouyer }
147