1 /* $NetBSD: gvpio.c,v 1.17 2009/11/09 15:35:27 is 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.17 2009/11/09 15:35:27 is 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 u_int16_t needpsl; 106 107 giosc = (struct gvpio_softc *)self; 108 gap = auxp; 109 110 if (parent) 111 printf("\n"); 112 113 gbase = gap->zargs.va; 114 giosc->sc_cntr = &gbase[0x41]; 115 giosc->sc_bst.base = (u_long)gbase + 1; 116 giosc->sc_bst.absm = &amiga_bus_stride_2; 117 LIST_INIT(&giosc->sc_comhdls); 118 giosd = gvpiodevs; 119 120 supa.supio_iot = &giosc->sc_bst; 121 122 gbase[0x041] = 0; 123 gbase[0x161 + 1*2] = 0; 124 gbase[0x261 + 1*2] = 0; 125 gbase[0x361 + 2*2] = 0; 126 gbase[0x461] = 0xd0; 127 128 while (giosd->name) { 129 supa.supio_name = giosd->name; 130 supa.supio_iobase = giosd->off; 131 supa.supio_arg = giosd->arg; 132 supa.supio_ipl = giosd->ipl; 133 config_found(self, &supa, gvpioprint); /* XXX */ 134 ++giosd; 135 } 136 if (giosc->sc_comhdls.lh_first) { 137 /* XXX this should be really in the interrupt stuff */ 138 needpsl = PSL_S|PSL_IPL6; 139 if (ipl2spl_table[IPL_SERIAL] < needpsl) { 140 printf("%s: raising ipl2spl_table[IPL_SERIAL] " 141 "from 0x%x to 0x%x\n", 142 giosc->sc_dev.dv_xname, ipl2spl_table[IPL_SERIAL], 143 needpsl); 144 ipl2spl_table[IPL_SERIAL] = needpsl; 145 } 146 giosc->sc_comisr.isr_intr = gvp_com_intr; 147 giosc->sc_comisr.isr_arg = giosc; 148 giosc->sc_comisr.isr_ipl = 6; 149 add_isr(&giosc->sc_comisr); 150 } 151 gbase[0x041] = 0x08; 152 } 153 154 int 155 gvpioprint(void *auxp, const char *pnp) 156 { 157 struct supio_attach_args *supa; 158 supa = auxp; 159 160 if (pnp == NULL) 161 return(QUIET); 162 163 aprint_normal("%s at %s port 0x%02x ipl %d", 164 supa->supio_name, pnp, supa->supio_iobase, supa->supio_ipl); 165 166 return(UNCONF); 167 } 168 169 void 170 gvp_com_intr_establish(struct device *self, struct gvpcom_int_hdl *p) 171 { 172 struct gvpio_softc *sc; 173 174 sc = (struct gvpio_softc *)self; 175 LIST_INSERT_HEAD(&sc->sc_comhdls, p, next); 176 177 } 178 179 int 180 gvp_com_intr(void *p) 181 { 182 struct gvpio_softc *sc; 183 struct gvpcom_int_hdl *np; 184 volatile void *cntr; 185 186 sc = (struct gvpio_softc *)p; 187 188 cntr = sc->sc_cntr; 189 190 if (!(*cntr & 0x2)) 191 return (0); 192 193 *cntr &= ~0xa; 194 195 for (np = sc->sc_comhdls.lh_first; np != NULL; 196 np = np->next.le_next) { 197 198 (*np->f)(np->p); 199 } 200 *cntr |= 0x8; 201 202 return (1); 203 } 204