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