1 /* $NetBSD: dtms.c,v 1.9 2008/04/28 20:23:32 martin 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 * 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. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: dtms.c,v 1.9 2008/04/28 20:23:32 martin Exp $"); 34 35 #include "locators.h" 36 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> 42 43 #include <machine/bus.h> 44 45 #include <arch/pmax/tc/dtreg.h> 46 #include <arch/pmax/tc/dtvar.h> 47 48 #include <dev/wscons/wsconsio.h> 49 #include <dev/wscons/wsmousevar.h> 50 51 struct dtms_softc { 52 struct device sc_dv; 53 struct device *sc_wsmousedev; 54 int sc_enabled; 55 }; 56 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 *); 64 65 CFATTACH_DECL(dtms, sizeof(struct dtms_softc), 66 dtms_match, dtms_attach, NULL, NULL); 67 68 const struct wsmouse_accessops dtms_accessops = { 69 dtms_enable, 70 dtms_ioctl, 71 dtms_disable, 72 }; 73 74 int 75 dtms_match(struct device *parent, struct cfdata *cf, void *aux) 76 { 77 struct dt_attach_args *dta; 78 79 dta = aux; 80 return (dta->dta_addr == DT_ADDR_MOUSE); 81 } 82 83 void 84 dtms_attach(struct device *parent, struct device *self, void *aux) 85 { 86 struct wsmousedev_attach_args a; 87 struct dtms_softc *sc; 88 struct dt_softc *dt; 89 90 dt = (struct dt_softc *)parent; 91 sc = (struct dtms_softc *)self; 92 93 printf("\n"); 94 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; 98 } 99 100 a.accessops = &dtms_accessops; 101 a.accesscookie = sc; 102 sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint); 103 } 104 105 int 106 dtms_enable(void *cookie) 107 { 108 struct dtms_softc *sc; 109 110 sc = cookie; 111 if (sc->sc_enabled) 112 return (EBUSY); 113 sc->sc_enabled = 1; 114 115 return (0); 116 } 117 118 void 119 dtms_disable(void *cookie) 120 { 121 struct dtms_softc *sc; 122 123 sc = cookie; 124 sc->sc_enabled = 0; 125 } 126 127 int 128 dtms_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l) 129 { 130 131 if (cmd == WSMOUSEIO_GTYPE) { 132 *(u_int *)data = WSMOUSE_TYPE_VSXXX; 133 return (0); 134 } 135 136 return (EPASSTHROUGH); 137 } 138 139 void 140 dtms_handler(void *cookie, struct dt_msg *msg) 141 { 142 struct dtms_softc *sc; 143 int buttons, dx, dy; 144 short tmp; 145 146 sc = cookie; 147 148 if (!sc->sc_enabled) 149 return; 150 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; 157 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; 163 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; 169 170 wsmouse_input(sc->sc_wsmousedev, 171 buttons, 172 dx, dy, 0, 0, 173 WSMOUSE_INPUT_DELTA); 174 } 175