1 /* $NetBSD: gvpio.c,v 1.12 2002/10/02 04:55:51 thorpej 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 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Ignatios Souvatzis 18 * for the NetBSD Project. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <sys/cdefs.h> 35 __KERNEL_RCSID(0, "$NetBSD: gvpio.c,v 1.12 2002/10/02 04:55:51 thorpej Exp $"); 36 37 /* 38 * GVP I/O Extender 39 */ 40 41 #include <sys/types.h> 42 43 #include <sys/conf.h> 44 #include <sys/device.h> 45 #include <sys/systm.h> 46 #include <sys/param.h> 47 48 #include <machine/bus.h> 49 #include <machine/intr.h> 50 51 #include <amiga/include/cpu.h> 52 53 #include <amiga/amiga/device.h> 54 #include <amiga/amiga/drcustom.h> 55 56 #include <amiga/dev/supio.h> 57 #include <amiga/dev/zbusvar.h> 58 #include <amiga/dev/gvpbusvar.h> 59 60 struct gvpio_softc { 61 struct device sc_dev; 62 struct bus_space_tag sc_bst; 63 caddr_t sc_cntr; 64 LIST_HEAD(, gvpcom_int_hdl) sc_comhdls; 65 struct isr sc_comisr; 66 }; 67 68 int gvpiomatch(struct device *, struct cfdata *, void *); 69 void gvpioattach(struct device *, struct device *, void *); 70 int gvpioprint(void *auxp, const char *); 71 int gvp_com_intr(void *); 72 void gvp_com_intr_establish(struct device *, struct gvpcom_int_hdl *); 73 74 CFATTACH_DECL(gvpio, sizeof(struct gvpio_softc), 75 gvpiomatch, gvpioattach, NULL, NULL); 76 77 int 78 gvpiomatch(struct device *parent, struct cfdata *cfp, void *auxp) 79 { 80 81 struct gvpbus_args *gap; 82 83 gap = auxp; 84 85 if (gap->flags & GVP_IO) 86 return (1); 87 88 return (0); 89 } 90 91 struct gvpio_devs { 92 char *name; 93 int off; 94 int arg; 95 int ipl; 96 } gvpiodevs[] = { 97 { "com", 0x0b0, 115200 * 16 * 4, 6 }, 98 { "com", 0x130, 115200 * 16 * 4, 6 }, 99 { "lpt", 0x1b0, 0, 2 }, 100 { 0 } 101 }; 102 103 void 104 gvpioattach(struct device *parent, struct device *self, void *auxp) 105 { 106 struct gvpio_softc *giosc; 107 struct gvpio_devs *giosd; 108 struct gvpbus_args *gap; 109 struct supio_attach_args supa; 110 volatile caddr_t gbase; 111 u_int16_t needpsl; 112 113 giosc = (struct gvpio_softc *)self; 114 gap = auxp; 115 116 if (parent) 117 printf("\n"); 118 119 gbase = gap->zargs.va; 120 giosc->sc_cntr = &gbase[0x41]; 121 giosc->sc_bst.base = (u_long)gbase + 1; 122 giosc->sc_bst.absm = &amiga_bus_stride_2; 123 LIST_INIT(&giosc->sc_comhdls); 124 giosd = gvpiodevs; 125 126 supa.supio_iot = &giosc->sc_bst; 127 128 gbase[0x041] = 0; 129 gbase[0x161 + 1*2] = 0; 130 gbase[0x261 + 1*2] = 0; 131 gbase[0x361 + 2*2] = 0; 132 gbase[0x461] = 0xd0; 133 134 while (giosd->name) { 135 supa.supio_name = giosd->name; 136 supa.supio_iobase = giosd->off; 137 supa.supio_arg = giosd->arg; 138 supa.supio_ipl = giosd->ipl; 139 config_found(self, &supa, gvpioprint); /* XXX */ 140 ++giosd; 141 } 142 if (giosc->sc_comhdls.lh_first) { 143 /* XXX this should be really in the interupt stuff */ 144 needpsl = PSL_S|PSL_IPL6; 145 if (amiga_serialspl < needpsl) { 146 printf("%s: raising amiga_serialspl from 0x%x to 0x%x\n", 147 giosc->sc_dev.dv_xname, amiga_serialspl, needpsl); 148 amiga_serialspl = needpsl; 149 } 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 printf("%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 caddr_t 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