1 /* $NetBSD: ms_hb.c,v 1.7 2004/09/04 13:43:11 tsutsui 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/cdefs.h> 31 __KERNEL_RCSID(0, "$NetBSD: ms_hb.c,v 1.7 2004/09/04 13:43:11 tsutsui Exp $"); 32 33 #include <sys/param.h> 34 #include <sys/device.h> 35 #include <sys/systm.h> 36 37 #include <dev/wscons/wsconsio.h> 38 #include <dev/wscons/wsmousevar.h> 39 40 #include <machine/bus.h> 41 #include <machine/cpu.h> 42 43 #include <news68k/dev/hbvar.h> 44 #include <news68k/dev/ms_hbreg.h> 45 #include <news68k/dev/msvar.h> 46 47 #include <news68k/news68k/isr.h> 48 49 #define MS_SIZE 0x10 /* XXX */ 50 #define MS_IPL 5 51 52 static int ms_hb_match(struct device *, struct cfdata *, void *); 53 static void ms_hb_attach(struct device *, struct device *, void *); 54 static void ms_hb_init(struct ms_softc *); 55 int ms_hb_intr(void *); 56 57 static int ms_hb_enable(void *); 58 static int ms_hb_ioctl(void *, u_long, caddr_t, int, struct proc *); 59 static void ms_hb_disable(void *); 60 61 CFATTACH_DECL(ms_hb, sizeof(struct ms_softc), 62 ms_hb_match, ms_hb_attach, NULL, NULL); 63 64 struct wsmouse_accessops ms_hb_accessops = { 65 ms_hb_enable, 66 ms_hb_ioctl, 67 ms_hb_disable 68 }; 69 70 static int 71 ms_hb_match(struct device *parent, struct cfdata *cf, void *aux) 72 { 73 struct hb_attach_args *ha = aux; 74 u_int addr; 75 76 if (strcmp(ha->ha_name, "ms")) 77 return 0; 78 79 /* XXX no default address */ 80 if (ha->ha_address == (u_int)-1) 81 return 0; 82 83 addr = IIOV(ha->ha_address); /* XXX */ 84 85 if (badaddr((void *)addr, 1)) 86 return 0; 87 88 return 1; 89 } 90 91 static void 92 ms_hb_attach(struct device *parent, struct device *self, void *aux) 93 { 94 struct ms_softc *sc = (void *)self; 95 struct hb_attach_args *ha = aux; 96 bus_space_tag_t bt = ha->ha_bust; 97 bus_space_handle_t bh; 98 struct wsmousedev_attach_args wsa; 99 int ipl; 100 101 if (bus_space_map(bt, ha->ha_address, MS_SIZE, 0, &bh) != 0) { 102 printf("can't map device space\n"); 103 return; 104 } 105 106 printf("\n"); 107 108 sc->sc_bt = bt; 109 sc->sc_bh = bh; 110 sc->sc_offset = MS_REG_DATA; 111 ipl = ha->ha_ipl; 112 if (ipl == -1) 113 ipl = MS_IPL; 114 115 ms_hb_init(sc); 116 117 isrlink_autovec(ms_hb_intr, (void *)sc, ipl, ISRPRI_TTY); 118 119 wsa.accessops = &ms_hb_accessops; 120 wsa.accesscookie = sc; 121 sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint); 122 } 123 124 static void 125 ms_hb_init(struct ms_softc *sc) 126 { 127 bus_space_tag_t bt = sc->sc_bt; 128 bus_space_handle_t bh = sc->sc_bh; 129 130 bus_space_write_1(bt, bh, MS_REG_RESET, 0); 131 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE); 132 } 133 134 int 135 ms_hb_intr(void *v) 136 { 137 struct ms_softc *sc = v; 138 bus_space_tag_t bt = sc->sc_bt; 139 bus_space_handle_t bh = sc->sc_bh; 140 int handled = 0; 141 142 while ((bus_space_read_1(bt, bh, MS_REG_STAT) & MSSTAT_RDY) != 0) { 143 ms_intr(sc); 144 handled = 1; 145 } 146 if (handled) 147 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE); 148 149 return handled; 150 } 151 152 static int 153 ms_hb_enable(void *v) 154 { 155 struct ms_softc *sc = v; 156 bus_space_tag_t bt = sc->sc_bt; 157 bus_space_handle_t bh = sc->sc_bh; 158 159 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE); 160 161 return 0; 162 } 163 164 static void 165 ms_hb_disable(void *v) 166 { 167 struct ms_softc *sc = v; 168 bus_space_tag_t bt = sc->sc_bt; 169 bus_space_handle_t bh = sc->sc_bh; 170 171 bus_space_write_1(bt, bh, MS_REG_INTE, 0); 172 } 173 174 static int 175 ms_hb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p) 176 { 177 178 return EPASSTHROUGH; 179 } 180