dtms.c revision 1.3
1/* $NetBSD: dtms.c,v 1.3 2003/12/23 09:39:46 ad 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.3 2003/12/23 09:39:46 ad 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 58struct dtms_softc { 59 struct device sc_dv; 60 struct device *sc_wsmousedev; 61 int sc_enabled; 62}; 63 64int dtms_match(struct device *, struct cfdata *, void *); 65void dtms_attach(struct device *, struct device *, void *); 66int dtms_input(void *, int); 67int dtms_enable(void *); 68int dtms_ioctl(void *, u_long, caddr_t, int, struct proc *); 69void dtms_disable(void *); 70void dtms_handler(void *, struct dt_msg *); 71 72CFATTACH_DECL(dtms, sizeof(struct dtms_softc), 73 dtms_match, dtms_attach, NULL, NULL); 74 75const struct wsmouse_accessops dtms_accessops = { 76 dtms_enable, 77 dtms_ioctl, 78 dtms_disable, 79}; 80 81int 82dtms_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 90void 91dtms_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 112int 113dtms_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 125void 126dtms_disable(void *cookie) 127{ 128 struct dtms_softc *sc; 129 130 sc = cookie; 131 sc->sc_enabled = 0; 132} 133 134int 135dtms_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p) 136{ 137 138 if (cmd == WSMOUSEIO_GTYPE) { 139 *(u_int *)data = WSMOUSE_TYPE_VSXXX; 140 return (0); 141 } 142 143 return (-1); 144} 145 146void 147dtms_handler(void *cookie, struct dt_msg *msg) 148{ 149 struct dtms_softc *sc; 150 int buttons, dx, dy, tmp; 151 152 sc = cookie; 153 154 if (!sc->sc_enabled) 155 return; 156 157 tmp = DT_GET_SHORT(msg->body[0], msg->body[1]); 158 buttons = ((tmp >> 1) & 0x3) | ((tmp << 2) & 0x4); 159 160 tmp = DT_GET_SHORT(msg->body[2], msg->body[3]); 161 if (tmp < 0) 162 dx = -(-tmp & 0x1f); 163 else 164 dx = tmp & 0x1f; 165 166 tmp = DT_GET_SHORT(msg->body[4], msg->body[5]); 167 if (tmp < 0) 168 dy = -(-tmp & 0x1f); 169 else 170 dy = tmp & 0x1f; 171 172 wsmouse_input(sc->sc_wsmousedev, buttons, dx, dy, 0, 173 WSMOUSE_INPUT_DELTA); 174} 175