ms_ap.c revision 1.5
1/* $NetBSD: ms_ap.c,v 1.5 2003/07/15 02:59:28 lukem Exp $ */ 2 3/*- 4 * Copyright (c) 2000 Tsubai Masanari. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> 30__KERNEL_RCSID(0, "$NetBSD: ms_ap.c,v 1.5 2003/07/15 02:59:28 lukem Exp $"); 31 32#include <sys/param.h> 33#include <sys/device.h> 34#include <sys/systm.h> 35 36#include <dev/wscons/wsconsio.h> 37#include <dev/wscons/wsmousevar.h> 38 39#include <machine/adrsmap.h> 40#include <newsmips/apbus/apbusvar.h> 41 42struct msreg { 43 u_int ms_data; 44 u_int ms_stat; 45 u_int ms_intr_en; 46 u_int ms_reset; 47 u_int ms_speed; 48}; 49 50struct ms_ap_softc { 51 struct device sc_dev; 52 volatile struct msreg *sc_reg; 53 struct device *sc_wsmousedev; 54 int sc_ndata; 55 u_char sc_buf[3]; 56}; 57 58int ms_ap_match(struct device *, struct cfdata *, void *); 59void ms_ap_attach(struct device *, struct device *, void *); 60int ms_ap_intr(void *); 61 62int ms_ap_enable(void *); 63int ms_ap_ioctl(void *, u_long, caddr_t, int, struct proc *); 64void ms_ap_disable(void *); 65 66CFATTACH_DECL(ms_ap, sizeof(struct ms_ap_softc), 67 ms_ap_match, ms_ap_attach, NULL, NULL); 68 69struct wsmouse_accessops ms_ap_accessops = { 70 ms_ap_enable, 71 ms_ap_ioctl, 72 ms_ap_disable 73}; 74 75int 76ms_ap_match(parent, cf, aux) 77 struct device *parent; 78 struct cfdata *cf; 79 void *aux; 80{ 81 struct apbus_attach_args *apa = aux; 82 83 if (strcmp(apa->apa_name, "ms") == 0) 84 return 1; 85 86 return 0; 87} 88 89void 90ms_ap_attach(parent, self, aux) 91 struct device *parent, *self; 92 void *aux; 93{ 94 struct ms_ap_softc *sc = (void *)self; 95 struct apbus_attach_args *apa = aux; 96 volatile struct msreg *reg = (void *)apa->apa_hwbase; 97 struct wsmousedev_attach_args aa; 98 99 printf(" slot%d addr 0x%lx\n", apa->apa_slotno, apa->apa_hwbase); 100 101 sc->sc_reg = reg; 102 103 reg->ms_reset = 0x03; 104 reg->ms_speed = 0x01; 105 reg->ms_intr_en = 0; 106 107 apbus_intr_establish(1, NEWS5000_INT1_KBD, 0, ms_ap_intr, sc, 108 "", apa->apa_ctlnum); 109 110 aa.accessops = &ms_ap_accessops; 111 aa.accesscookie = sc; 112 sc->sc_wsmousedev = config_found(self, &aa, wsmousedevprint); 113} 114 115int 116ms_ap_intr(v) 117 void *v; 118{ 119 struct ms_ap_softc *sc = v; 120 volatile struct msreg *reg = sc->sc_reg; 121 int code, index, byte0, byte1, byte2; 122 int button, dx, dy; 123 int rv = 0; 124 125 reg->ms_intr_en = 0; 126 127 while (reg->ms_stat & RX_MSRDY) { 128 rv = 1; 129 code = reg->ms_data; 130 index = sc->sc_ndata; 131 132 if (sc->sc_wsmousedev == NULL) 133 continue; 134 135 if (code & 0x80) { 136 sc->sc_buf[0] = code; 137 sc->sc_ndata = 1; 138 continue; 139 } 140 141 if (index == 1) { 142 sc->sc_buf[1] = code; 143 sc->sc_ndata++; 144 continue; 145 } 146 147 if (index == 2) { 148 sc->sc_buf[2] = code; 149 sc->sc_ndata++; 150 151 byte0 = sc->sc_buf[0]; 152 byte1 = sc->sc_buf[1]; 153 byte2 = sc->sc_buf[2]; 154 155 button = 0; 156 if (byte0 & 0x01) 157 button |= 1; 158 if (byte0 & 0x04) 159 button |= 2; 160 if (byte0 & 0x02) 161 button |= 4; 162 163 if (byte0 & 0x08) 164 dx = byte1 - 0x80; 165 else 166 dx = byte1; 167 if (byte0 & 0x10) 168 dy = byte2 - 0x80; 169 else 170 dy = byte2; 171 172 wsmouse_input(sc->sc_wsmousedev, button, dx, -dy, 0, 173 WSMOUSE_INPUT_DELTA); 174 } 175 } 176 177 reg->ms_intr_en = 1; 178 return rv; 179} 180 181int 182ms_ap_enable(v) 183 void *v; 184{ 185 struct ms_ap_softc *sc = v; 186 volatile struct msreg *reg = sc->sc_reg; 187 188 reg->ms_intr_en = 1; 189 return 0; 190} 191 192void 193ms_ap_disable(v) 194 void *v; 195{ 196 struct ms_ap_softc *sc = v; 197 volatile struct msreg *reg = sc->sc_reg; 198 199 reg->ms_intr_en = 0; 200} 201 202int 203ms_ap_ioctl(v, cmd, data, flag, p) 204 void *v; 205 u_long cmd; 206 caddr_t data; 207 int flag; 208 struct proc *p; 209{ 210 return EPASSTHROUGH; 211} 212