1 /* $NetBSD: dzms.c,v 1.20 2009/05/12 12:11:54 cegger Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * @(#)ms.c 8.1 (Berkeley) 6/11/93
44 * VSXXX mice attached to line 1 of the DZ*
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: dzms.c,v 1.20 2009/05/12 12:11:54 cegger Exp $");
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/device.h>
53 #include <sys/ioctl.h>
54 #include <sys/syslog.h>
55 #include <sys/kernel.h>
61 #include <dev/dec/dzreg.h>
62 #include <dev/dec/dzvar.h>
63 #include <dev/dec/dzkbdvar.h>
64 #include <dev/dec/lk201.h>
66 #include <dev/wscons/wsconsio.h>
67 #include <dev/wscons/wsmousevar.h>
71 struct dzms_softc
{ /* driver status information */
72 struct device dzms_dev
; /* required first: base device */
73 struct dz_linestate
*dzms_ls
;
75 int sc_enabled
; /* input enabled? */
82 device_t sc_wsmousedev
;
85 static int dzms_match(device_t
, cfdata_t
, void *);
86 static void dzms_attach(device_t
, device_t
, void *);
87 static int dzms_input(void *, int);
89 CFATTACH_DECL(dzms
, sizeof(struct dzms_softc
),
90 dzms_match
, dzms_attach
, NULL
, NULL
);
92 static int dzms_enable(void *);
93 static int dzms_ioctl(void *, u_long
, void *, int, struct lwp
*);
94 static void dzms_disable(void *);
96 const struct wsmouse_accessops dzms_accessops
= {
103 dzms_match(device_t parent
, cfdata_t cf
, void *aux
)
105 struct dzkm_attach_args
*daa
= aux
;
107 /* Exact match is better than wildcard. */
108 if (cf
->cf_loc
[DZCF_LINE
] == daa
->daa_line
)
111 /* This driver accepts wildcard. */
112 if (cf
->cf_loc
[DZCF_LINE
] == DZCF_LINE_DEFAULT
)
119 dzms_attach(device_t parent
, device_t self
, void *aux
)
121 struct dz_softc
*dz
= device_private(parent
);
122 struct dzms_softc
*dzms
= device_private(self
);
123 struct dzkm_attach_args
*daa
= aux
;
124 struct dz_linestate
*ls
;
125 struct wsmousedev_attach_args a
;
127 dz
->sc_dz
[daa
->daa_line
].dz_catch
= dzms_input
;
128 dz
->sc_dz
[daa
->daa_line
].dz_private
= dzms
;
129 ls
= &dz
->sc_dz
[daa
->daa_line
];
134 a
.accessops
= &dzms_accessops
;
135 a
.accesscookie
= dzms
;
137 dzms
->sc_enabled
= 0;
138 dzms
->sc_selftest
= 0;
139 dzms
->sc_wsmousedev
= config_found(self
, &a
, wsmousedevprint
);
145 struct dzms_softc
*sc
= v
;
150 sc
->sc_selftest
= 4; /* wait for 4 byte reply upto 1/2 sec */
151 dzputc(sc
->dzms_ls
, MOUSE_SELF_TEST
);
152 (void)tsleep(dzms_enable
, TTIPRI
, "dzmsopen", hz
/ 2);
153 if (sc
->sc_selftest
!= 0) {
158 dzputc(sc
->dzms_ls
, MOUSE_INCREMENTAL
);
165 dzms_disable(void *v
)
167 struct dzms_softc
*sc
= v
;
173 dzms_ioctl(void *v
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
175 if (cmd
== WSMOUSEIO_GTYPE
) {
176 *(u_int
*)data
= WSMOUSE_TYPE_VSXXX
;
183 dzms_input(void *vsc
, int data
)
185 struct dzms_softc
*sc
= vsc
;
187 if (sc
->sc_enabled
== 0) {
188 if (sc
->sc_selftest
> 0) {
189 sc
->sc_selftest
-= 1;
190 if (sc
->sc_selftest
== 0)
196 #define WSMS_BUTTON1 0x01
197 #define WSMS_BUTTON2 0x02
198 #define WSMS_BUTTON3 0x04
200 if ((data
& MOUSE_START_FRAME
) != 0)
205 if (sc
->inputstate
== 1) {
207 if ((data
& LEFT_BUTTON
) != 0)
208 sc
->buttons
|= WSMS_BUTTON1
;
209 if ((data
& MIDDLE_BUTTON
) != 0)
210 sc
->buttons
|= WSMS_BUTTON2
;
211 if ((data
& RIGHT_BUTTON
) != 0)
212 sc
->buttons
|= WSMS_BUTTON3
;
214 sc
->dx
= data
& MOUSE_X_SIGN
;
215 sc
->dy
= data
& MOUSE_Y_SIGN
;
216 } else if (sc
->inputstate
== 2) {
221 } else if (sc
->inputstate
== 3) {
227 wsmouse_input(sc
->sc_wsmousedev
,
229 sc
->dx
, sc
->dy
, 0, 0,
230 WSMOUSE_INPUT_DELTA
);