1 /* $NetBSD: ms_hb.c,v 1.2 2002/03/17 19:40:45 atatat Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 Izumi Tsutsui. All rights reserved. 5 * Copyright (c) 2000 Tsubai Masanari. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include <sys/param.h> 31 #include <sys/device.h> 32 #include <sys/systm.h> 33 34 #include <dev/wscons/wsconsio.h> 35 #include <dev/wscons/wsmousevar.h> 36 37 #include <machine/bus.h> 38 #include <machine/cpu.h> 39 40 #include <news68k/dev/hbvar.h> 41 #include <news68k/dev/ms_hbreg.h> 42 #include <news68k/dev/msvar.h> 43 44 #include <news68k/news68k/isr.h> 45 46 #define MS_SIZE 0x10 /* XXX */ 47 #define MS_IPL 5 48 49 int ms_hb_match(struct device *, struct cfdata *, void *); 50 void ms_hb_attach(struct device *, struct device *, void *); 51 void ms_hb_init(struct ms_softc *); 52 int ms_hb_intr(void *); 53 54 int ms_hb_enable(void *); 55 int ms_hb_ioctl(void *, u_long, caddr_t, int, struct proc *); 56 void ms_hb_disable(void *); 57 58 struct cfattach ms_hb_ca = { 59 sizeof(struct ms_softc), ms_hb_match, ms_hb_attach 60 }; 61 62 struct wsmouse_accessops ms_hb_accessops = { 63 ms_hb_enable, 64 ms_hb_ioctl, 65 ms_hb_disable 66 }; 67 68 int 69 ms_hb_match(parent, cf, aux) 70 struct device *parent; 71 struct cfdata *cf; 72 void *aux; 73 { 74 struct hb_attach_args *ha = aux; 75 u_int addr; 76 77 if (strcmp(ha->ha_name, "ms")) 78 return 0; 79 80 /* XXX no default address */ 81 if (ha->ha_address == -1) 82 return 0; 83 84 addr = IIOV(ha->ha_address); /* XXX */ 85 86 if (badaddr((void *)addr, 1)) 87 return 0; 88 89 return 1; 90 } 91 92 void 93 ms_hb_attach(parent, self, aux) 94 struct device *parent; 95 struct device *self; 96 void *aux; 97 { 98 struct ms_softc *sc = (void *)self; 99 struct hb_attach_args *ha = aux; 100 bus_space_tag_t bt = ha->ha_bust; 101 bus_space_handle_t bh; 102 struct wsmousedev_attach_args wsa; 103 int ipl; 104 105 if (bus_space_map(bt, ha->ha_address, MS_SIZE, 0, &bh) != 0) { 106 printf("can't map device space\n"); 107 return; 108 } 109 110 printf("\n"); 111 112 sc->sc_bt = bt; 113 sc->sc_bh = bh; 114 sc->sc_offset = MS_REG_DATA; 115 ipl = ha->ha_ipl; 116 if (ipl == -1) 117 ipl = MS_IPL; 118 119 ms_hb_init(sc); 120 121 isrlink_autovec(ms_hb_intr, (void *)sc, ipl, ISRPRI_TTY); 122 123 wsa.accessops = &ms_hb_accessops; 124 wsa.accesscookie = sc; 125 sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint); 126 } 127 128 void 129 ms_hb_init(sc) 130 struct ms_softc *sc; 131 { 132 bus_space_tag_t bt = sc->sc_bt; 133 bus_space_handle_t bh = sc->sc_bh; 134 135 bus_space_write_1(bt, bh, MS_REG_RESET, 0); 136 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE); 137 } 138 139 int 140 ms_hb_intr(v) 141 void *v; 142 { 143 struct ms_softc *sc = v; 144 bus_space_tag_t bt = sc->sc_bt; 145 bus_space_handle_t bh = sc->sc_bh; 146 int handled = 0; 147 148 while ((bus_space_read_1(bt, bh, MS_REG_STAT) & MSSTAT_RDY) != 0) { 149 ms_intr(sc); 150 handled = 1; 151 } 152 if (handled) 153 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE); 154 155 return handled; 156 } 157 158 int 159 ms_hb_enable(v) 160 void *v; 161 { 162 struct ms_softc *sc = v; 163 bus_space_tag_t bt = sc->sc_bt; 164 bus_space_handle_t bh = sc->sc_bh; 165 166 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE); 167 168 return 0; 169 } 170 171 void 172 ms_hb_disable(v) 173 void *v; 174 { 175 struct ms_softc *sc = v; 176 bus_space_tag_t bt = sc->sc_bt; 177 bus_space_handle_t bh = sc->sc_bh; 178 179 bus_space_write_1(bt, bh, MS_REG_INTE, 0); 180 } 181 182 int 183 ms_hb_ioctl(v, cmd, data, flag, p) 184 void *v; 185 u_long cmd; 186 caddr_t data; 187 int flag; 188 struct proc *p; 189 { 190 return EPASSTHROUGH; 191 } 192