1 /* $NetBSD: dzms.c,v 1.1 2000/12/02 17:03:55 ragge Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 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. 10 * 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. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: 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. All advertising materials mentioning features or use of this software 25 * must display the following acknowledgement: 26 * This product includes software developed by the University of 27 * California, Berkeley and its contributors. 28 * 4. Neither the name of the University nor the names of its contributors 29 * may be used to endorse or promote products derived from this software 30 * without specific prior written permission. 31 * 32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 42 * SUCH DAMAGE. 43 * 44 * @(#)ms.c 8.1 (Berkeley) 6/11/93 45 */ 46 47 /* 48 * VSXXX mice attached to line 1 of the DZ* 49 */ 50 51 #include <sys/param.h> 52 #include <sys/systm.h> 53 #include <sys/device.h> 54 #include <sys/ioctl.h> 55 #include <sys/syslog.h> 56 57 #include <machine/bus.h> 58 59 #include <dev/qbus/dzreg.h> 60 #include <dev/qbus/dzvar.h> 61 62 #include <dev/dec/dzkbdvar.h> 63 #include <dev/dec/lk201.h> 64 65 #include <dev/wscons/wsconsio.h> 66 #include <dev/wscons/wsmousevar.h> 67 68 #include "locators.h" 69 70 struct dzms_softc { /* driver status information */ 71 struct device dzms_dev; /* required first: base device */ 72 struct dz_linestate *dzms_ls; 73 74 int sc_enabled; /* input enabled? */ 75 int self_test; 76 77 int inputstate; 78 u_int buttons; 79 signed char dx; 80 signed char dy; 81 82 struct device *sc_wsmousedev; 83 }; 84 85 static int dzms_match __P((struct device *, struct cfdata *, void *)); 86 static void dzms_attach __P((struct device *, struct device *, void *)); 87 static int dzms_input __P((void *, int)); 88 89 struct cfattach dzms_ca = { 90 sizeof(struct dzms_softc), dzms_match, dzms_attach, 91 }; 92 93 static int dzms_enable __P((void *)); 94 static int dzms_ioctl __P((void *, u_long, caddr_t, int, struct proc *)); 95 static void dzms_disable __P((void *)); 96 97 const struct wsmouse_accessops dzms_accessops = { 98 dzms_enable, 99 dzms_ioctl, 100 dzms_disable, 101 }; 102 103 static int 104 dzms_match(parent, cf, aux) 105 struct device *parent; 106 struct cfdata *cf; 107 void *aux; 108 { 109 struct dzkm_attach_args *daa = aux; 110 111 /* Exact match is better than wildcard. */ 112 if (cf->cf_loc[DZCF_LINE] == daa->daa_line) 113 return 2; 114 115 /* This driver accepts wildcard. */ 116 if (cf->cf_loc[DZCF_LINE] == DZCF_LINE_DEFAULT) 117 return 1; 118 119 return 0; 120 } 121 122 static void 123 dzms_attach(parent, self, aux) 124 struct device *parent, *self; 125 void *aux; 126 { 127 struct dz_softc *dz = (void *)parent; 128 struct dzms_softc *dzms = (void *)self; 129 struct dzkm_attach_args *daa = aux; 130 struct dz_linestate *ls; 131 struct wsmousedev_attach_args a; 132 133 dz->sc_dz[daa->daa_line].dz_catch = dzms_input; 134 dz->sc_dz[daa->daa_line].dz_private = dzms; 135 ls = &dz->sc_dz[daa->daa_line]; 136 dzms->dzms_ls = ls; 137 138 printf("\n"); 139 140 a.accessops = &dzms_accessops; 141 a.accesscookie = dzms; 142 143 dzms->sc_enabled = 0; 144 dzms->self_test = 0; 145 dzms->sc_wsmousedev = config_found(self, &a, wsmousedevprint); 146 } 147 148 static int 149 dzms_enable(v) 150 void *v; 151 { 152 struct dzms_softc *sc = v; 153 154 if (sc->sc_enabled) 155 return EBUSY; 156 157 /* XXX mice presence test should be done in match/attach context XXX */ 158 sc->self_test = 1; 159 dzputc(sc->dzms_ls, MOUSE_SELF_TEST); 160 DELAY(100000); 161 if (sc->self_test < 0) { 162 sc->self_test = 0; 163 return EBUSY; 164 } else if (sc->self_test == 5) { 165 sc->self_test = 0; 166 sc->sc_enabled = 1; 167 } 168 sc->inputstate = 0; 169 170 dzputc(sc->dzms_ls, MOUSE_INCREMENTAL); 171 172 return 0; 173 } 174 175 static void 176 dzms_disable(v) 177 void *v; 178 { 179 struct dzms_softc *sc = v; 180 181 sc->sc_enabled = 0; 182 } 183 184 static int 185 dzms_ioctl(v, cmd, data, flag, p) 186 void *v; 187 u_long cmd; 188 caddr_t data; 189 int flag; 190 struct proc *p; 191 { 192 if (cmd == WSMOUSEIO_GTYPE) { 193 *(u_int *)data = WSMOUSE_TYPE_VSXXX; 194 return 0; 195 } 196 return -1; 197 } 198 199 static int 200 dzms_input(vsc, data) 201 void *vsc; 202 int data; 203 { 204 struct dzms_softc *sc = vsc; 205 206 /* XXX mice presence test should be done in match/attach context XXX */ 207 if (!sc->sc_enabled) { 208 if (sc->self_test > 0) { 209 if (data < 0) { 210 printf("Timeout on 1st byte of mouse self-test report\n"); 211 sc->self_test = -1; 212 } else { 213 sc->self_test++; 214 } 215 } 216 if (sc->self_test == 3) { 217 if ((data & 0x0f) != 0x2) { 218 printf("We don't have a mouse!!!\n"); 219 sc->self_test = -1; 220 } 221 } 222 /* Interrupts are not expected. Discard the byte. */ 223 return(1); 224 } 225 226 #define WSMS_BUTTON1 0x01 227 #define WSMS_BUTTON2 0x02 228 #define WSMS_BUTTON3 0x04 229 230 if ((data & MOUSE_START_FRAME) != 0) 231 sc->inputstate = 1; 232 else 233 sc->inputstate++; 234 235 if (sc->inputstate == 1) { 236 sc->buttons = 0; 237 if ((data & LEFT_BUTTON) != 0) 238 sc->buttons |= WSMS_BUTTON1; 239 if ((data & MIDDLE_BUTTON) != 0) 240 sc->buttons |= WSMS_BUTTON2; 241 if ((data & RIGHT_BUTTON) != 0) 242 sc->buttons |= WSMS_BUTTON3; 243 244 sc->dx = data & MOUSE_X_SIGN; 245 sc->dy = data & MOUSE_Y_SIGN; 246 } else if (sc->inputstate == 2) { 247 if (sc->dx == 0) 248 sc->dx = -data; 249 else 250 sc->dx = data; 251 } else if (sc->inputstate == 3) { 252 sc->inputstate = 0; 253 if (sc->dy == 0) 254 sc->dy = -data; 255 else 256 sc->dy = data; 257 wsmouse_input(sc->sc_wsmousedev, sc->buttons, 258 sc->dx, sc->dy, 0, WSMOUSE_INPUT_DELTA); 259 } 260 261 return(1); 262 } 263 264