Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / pmax / tc / dtms.c
bloba3aa8708137fed22f96737b11c5d5dd98944a366
1 /* $NetBSD: dtms.c,v 1.8 2007/03/04 06:00:34 christos Exp $ */
3 /*-
4 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: dtms.c,v 1.8 2007/03/04 06:00:34 christos Exp $");
35 #include "locators.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/ioctl.h>
41 #include <sys/syslog.h>
43 #include <machine/bus.h>
45 #include <arch/pmax/tc/dtreg.h>
46 #include <arch/pmax/tc/dtvar.h>
48 #include <dev/wscons/wsconsio.h>
49 #include <dev/wscons/wsmousevar.h>
51 struct dtms_softc {
52 struct device sc_dv;
53 struct device *sc_wsmousedev;
54 int sc_enabled;
57 int dtms_match(struct device *, struct cfdata *, void *);
58 void dtms_attach(struct device *, struct device *, void *);
59 int dtms_input(void *, int);
60 int dtms_enable(void *);
61 int dtms_ioctl(void *, u_long, void *, int, struct lwp *);
62 void dtms_disable(void *);
63 void dtms_handler(void *, struct dt_msg *);
65 CFATTACH_DECL(dtms, sizeof(struct dtms_softc),
66 dtms_match, dtms_attach, NULL, NULL);
68 const struct wsmouse_accessops dtms_accessops = {
69 dtms_enable,
70 dtms_ioctl,
71 dtms_disable,
74 int
75 dtms_match(struct device *parent, struct cfdata *cf, void *aux)
77 struct dt_attach_args *dta;
79 dta = aux;
80 return (dta->dta_addr == DT_ADDR_MOUSE);
83 void
84 dtms_attach(struct device *parent, struct device *self, void *aux)
86 struct wsmousedev_attach_args a;
87 struct dtms_softc *sc;
88 struct dt_softc *dt;
90 dt = (struct dt_softc *)parent;
91 sc = (struct dtms_softc *)self;
93 printf("\n");
95 if (dt_establish_handler(dt, &dt_ms_dv, self, dtms_handler)) {
96 printf("%s: unable to establish handler\n", self->dv_xname);
97 return;
100 a.accessops = &dtms_accessops;
101 a.accesscookie = sc;
102 sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
106 dtms_enable(void *cookie)
108 struct dtms_softc *sc;
110 sc = cookie;
111 if (sc->sc_enabled)
112 return (EBUSY);
113 sc->sc_enabled = 1;
115 return (0);
118 void
119 dtms_disable(void *cookie)
121 struct dtms_softc *sc;
123 sc = cookie;
124 sc->sc_enabled = 0;
128 dtms_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
131 if (cmd == WSMOUSEIO_GTYPE) {
132 *(u_int *)data = WSMOUSE_TYPE_VSXXX;
133 return (0);
136 return (EPASSTHROUGH);
139 void
140 dtms_handler(void *cookie, struct dt_msg *msg)
142 struct dtms_softc *sc;
143 int buttons, dx, dy;
144 short tmp;
146 sc = cookie;
148 if (!sc->sc_enabled)
149 return;
151 tmp = DT_GET_SHORT(msg->body[0], msg->body[1]);
152 buttons = tmp & 1;
153 if (tmp & 2)
154 buttons |= 4;
155 if (tmp & 4)
156 buttons |= 2;
158 tmp = DT_GET_SHORT(msg->body[2], msg->body[3]);
159 if (tmp < 0)
160 dx = -(-tmp & 0x1f);
161 else
162 dx = tmp & 0x1f;
164 tmp = DT_GET_SHORT(msg->body[4], msg->body[5]);
165 if (tmp < 0)
166 dy = -(-tmp & 0x1f);
167 else
168 dy = tmp & 0x1f;
170 wsmouse_input(sc->sc_wsmousedev,
171 buttons,
172 dx, dy, 0, 0,
173 WSMOUSE_INPUT_DELTA);