1 /* $NetBSD: dtms.c,v 1.6 2005/12/11 12:18:41 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Andrew Doran. 9 * 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. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: dtms.c,v 1.6 2005/12/11 12:18:41 christos Exp $"); 41 42 #include "locators.h" 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/device.h> 47 #include <sys/ioctl.h> 48 #include <sys/syslog.h> 49 50 #include <machine/bus.h> 51 52 #include <arch/pmax/tc/dtreg.h> 53 #include <arch/pmax/tc/dtvar.h> 54 55 #include <dev/wscons/wsconsio.h> 56 #include <dev/wscons/wsmousevar.h> 57 58 struct dtms_softc { 59 struct device sc_dv; 60 struct device *sc_wsmousedev; 61 int sc_enabled; 62 }; 63 64 int dtms_match(struct device *, struct cfdata *, void *); 65 void dtms_attach(struct device *, struct device *, void *); 66 int dtms_input(void *, int); 67 int dtms_enable(void *); 68 int dtms_ioctl(void *, u_long, caddr_t, int, struct lwp *); 69 void dtms_disable(void *); 70 void dtms_handler(void *, struct dt_msg *); 71 72 CFATTACH_DECL(dtms, sizeof(struct dtms_softc), 73 dtms_match, dtms_attach, NULL, NULL); 74 75 const struct wsmouse_accessops dtms_accessops = { 76 dtms_enable, 77 dtms_ioctl, 78 dtms_disable, 79 }; 80 81 int 82 dtms_match(struct device *parent, struct cfdata *cf, void *aux) 83 { 84 struct dt_attach_args *dta; 85 86 dta = aux; 87 return (dta->dta_addr == DT_ADDR_MOUSE); 88 } 89 90 void 91 dtms_attach(struct device *parent, struct device *self, void *aux) 92 { 93 struct wsmousedev_attach_args a; 94 struct dtms_softc *sc; 95 struct dt_softc *dt; 96 97 dt = (struct dt_softc *)parent; 98 sc = (struct dtms_softc *)self; 99 100 printf("\n"); 101 102 if (dt_establish_handler(dt, &dt_ms_dv, self, dtms_handler)) { 103 printf("%s: unable to establish handler\n", self->dv_xname); 104 return; 105 } 106 107 a.accessops = &dtms_accessops; 108 a.accesscookie = sc; 109 sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint); 110 } 111 112 int 113 dtms_enable(void *cookie) 114 { 115 struct dtms_softc *sc; 116 117 sc = cookie; 118 if (sc->sc_enabled) 119 return (EBUSY); 120 sc->sc_enabled = 1; 121 122 return (0); 123 } 124 125 void 126 dtms_disable(void *cookie) 127 { 128 struct dtms_softc *sc; 129 130 sc = cookie; 131 sc->sc_enabled = 0; 132 } 133 134 int 135 dtms_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l) 136 { 137 138 if (cmd == WSMOUSEIO_GTYPE) { 139 *(u_int *)data = WSMOUSE_TYPE_VSXXX; 140 return (0); 141 } 142 143 return (EPASSTHROUGH); 144 } 145 146 void 147 dtms_handler(void *cookie, struct dt_msg *msg) 148 { 149 struct dtms_softc *sc; 150 int buttons, dx, dy; 151 short tmp; 152 153 sc = cookie; 154 155 if (!sc->sc_enabled) 156 return; 157 158 tmp = DT_GET_SHORT(msg->body[0], msg->body[1]); 159 buttons = tmp & 1; 160 if (tmp & 2) 161 buttons |= 4; 162 if (tmp & 4) 163 buttons |= 2; 164 165 tmp = DT_GET_SHORT(msg->body[2], msg->body[3]); 166 if (tmp < 0) 167 dx = -(-tmp & 0x1f); 168 else 169 dx = tmp & 0x1f; 170 171 tmp = DT_GET_SHORT(msg->body[4], msg->body[5]); 172 if (tmp < 0) 173 dy = -(-tmp & 0x1f); 174 else 175 dy = tmp & 0x1f; 176 177 wsmouse_input(sc->sc_wsmousedev, buttons, dx, dy, 0, 178 WSMOUSE_INPUT_DELTA); 179 } 180