1 /* $NetBSD: gvpio.c,v 1.18 2010/02/02 19:03:31 phx Exp $ */ 2 3 /* 4 * Copyright (c) 1997 Ignatios Souvatzis 5 * 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: gvpio.c,v 1.18 2010/02/02 19:03:31 phx Exp $"); 30 31 /* 32 * GVP I/O Extender 33 */ 34 35 #include <sys/types.h> 36 37 #include <sys/conf.h> 38 #include <sys/device.h> 39 #include <sys/systm.h> 40 #include <sys/param.h> 41 42 #include <machine/bus.h> 43 #include <machine/intr.h> 44 45 #include <amiga/include/cpu.h> 46 47 #include <amiga/amiga/device.h> 48 #include <amiga/amiga/drcustom.h> 49 50 #include <amiga/dev/supio.h> 51 #include <amiga/dev/zbusvar.h> 52 #include <amiga/dev/gvpbusvar.h> 53 54 struct gvpio_softc { 55 struct device sc_dev; 56 struct bus_space_tag sc_bst; 57 void *sc_cntr; 58 LIST_HEAD(, gvpcom_int_hdl) sc_comhdls; 59 struct isr sc_comisr; 60 }; 61 62 int gvpiomatch(struct device *, struct cfdata *, void *); 63 void gvpioattach(struct device *, struct device *, void *); 64 int gvpioprint(void *auxp, const char *); 65 int gvp_com_intr(void *); 66 void gvp_com_intr_establish(struct device *, struct gvpcom_int_hdl *); 67 68 CFATTACH_DECL(gvpio, sizeof(struct gvpio_softc), 69 gvpiomatch, gvpioattach, NULL, NULL); 70 71 int 72 gvpiomatch(struct device *parent, struct cfdata *cfp, void *auxp) 73 { 74 75 struct gvpbus_args *gap; 76 77 gap = auxp; 78 79 if (gap->flags & GVP_IO) 80 return (1); 81 82 return (0); 83 } 84 85 struct gvpio_devs { 86 char *name; 87 int off; 88 int arg; 89 int ipl; 90 } gvpiodevs[] = { 91 { "com", 0x0b0, 115200 * 16 * 4, 6 }, 92 { "com", 0x130, 115200 * 16 * 4, 6 }, 93 { "lpt", 0x1b0, 0, 2 }, 94 { 0 } 95 }; 96 97 void 98 gvpioattach(struct device *parent, struct device *self, void *auxp) 99 { 100 struct gvpio_softc *giosc; 101 struct gvpio_devs *giosd; 102 struct gvpbus_args *gap; 103 struct supio_attach_args supa; 104 volatile void *gbase; 105 #ifdef __m68k__ 106 u_int16_t needpsl; 107 #endif 108 109 giosc = (struct gvpio_softc *)self; 110 gap = auxp; 111 112 if (parent) 113 printf("\n"); 114 115 gbase = gap->zargs.va; 116 giosc->sc_cntr = &gbase[0x41]; 117 giosc->sc_bst.base = (u_long)gbase + 1; 118 giosc->sc_bst.absm = &amiga_bus_stride_2; 119 LIST_INIT(&giosc->sc_comhdls); 120 giosd = gvpiodevs; 121 122 supa.supio_iot = &giosc->sc_bst; 123 124 gbase[0x041] = 0; 125 gbase[0x161 + 1*2] = 0; 126 gbase[0x261 + 1*2] = 0; 127 gbase[0x361 + 2*2] = 0; 128 gbase[0x461] = 0xd0; 129 130 while (giosd->name) { 131 supa.supio_name = giosd->name; 132 supa.supio_iobase = giosd->off; 133 supa.supio_arg = giosd->arg; 134 supa.supio_ipl = giosd->ipl; 135 config_found(self, &supa, gvpioprint); /* XXX */ 136 ++giosd; 137 } 138 if (giosc->sc_comhdls.lh_first) { 139 #ifdef __m68k__ 140 /* XXX this should be really in the interrupt stuff */ 141 needpsl = PSL_S|PSL_IPL6; 142 if (ipl2spl_table[IPL_SERIAL] < needpsl) { 143 printf("%s: raising ipl2spl_table[IPL_SERIAL] " 144 "from 0x%x to 0x%x\n", 145 giosc->sc_dev.dv_xname, ipl2spl_table[IPL_SERIAL], 146 needpsl); 147 ipl2spl_table[IPL_SERIAL] = needpsl; 148 } 149 #endif 150 giosc->sc_comisr.isr_intr = gvp_com_intr; 151 giosc->sc_comisr.isr_arg = giosc; 152 giosc->sc_comisr.isr_ipl = 6; 153 add_isr(&giosc->sc_comisr); 154 } 155 gbase[0x041] = 0x08; 156 } 157 158 int 159 gvpioprint(void *auxp, const char *pnp) 160 { 161 struct supio_attach_args *supa; 162 supa = auxp; 163 164 if (pnp == NULL) 165 return(QUIET); 166 167 aprint_normal("%s at %s port 0x%02x ipl %d", 168 supa->supio_name, pnp, supa->supio_iobase, supa->supio_ipl); 169 170 return(UNCONF); 171 } 172 173 void 174 gvp_com_intr_establish(struct device *self, struct gvpcom_int_hdl *p) 175 { 176 struct gvpio_softc *sc; 177 178 sc = (struct gvpio_softc *)self; 179 LIST_INSERT_HEAD(&sc->sc_comhdls, p, next); 180 181 } 182 183 int 184 gvp_com_intr(void *p) 185 { 186 struct gvpio_softc *sc; 187 struct gvpcom_int_hdl *np; 188 volatile void *cntr; 189 190 sc = (struct gvpio_softc *)p; 191 192 cntr = sc->sc_cntr; 193 194 if (!(*cntr & 0x2)) 195 return (0); 196 197 *cntr &= ~0xa; 198 199 for (np = sc->sc_comhdls.lh_first; np != NULL; 200 np = np->next.le_next) { 201 202 (*np->f)(np->p); 203 } 204 *cntr |= 0x8; 205 206 return (1); 207 } 208