1 /* $NetBSD: gvpio.c,v 1.1 1997/10/19 21:22:23 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 * 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 /* 35 * GVP I/O Extender 36 */ 37 38 #include <sys/types.h> 39 40 #include <sys/conf.h> 41 #include <sys/device.h> 42 #include <sys/systm.h> 43 #include <sys/param.h> 44 45 #include <machine/bus.h> 46 #include <machine/conf.h> 47 #include <machine/intr.h> 48 49 #include <amiga/include/cpu.h> 50 51 #include <amiga/amiga/device.h> 52 #include <amiga/amiga/drcustom.h> 53 54 #include <amiga/dev/supio.h> 55 #include <amiga/dev/zbusvar.h> 56 #include <amiga/dev/gvpbusvar.h> 57 #include <amiga/dev/gvpiovar.h> 58 59 struct gvpio_softc { 60 struct device sc_dev; 61 struct bus_space_tag sc_bst; 62 caddr_t sc_cntr; 63 LIST_HEAD(, gvpcom_int_hdl) sc_comhdls; 64 struct isr sc_comisr; 65 }; 66 67 int gvpiomatch __P((struct device *, struct cfdata *, void *)); 68 void gvpioattach __P((struct device *, struct device *, void *)); 69 int gvpioprint __P((void *auxp, const char *)); 70 int gvp_com_intr __P((void *)); 71 72 struct cfattach gvpio_ca = { 73 sizeof(struct gvpio_softc), gvpiomatch, gvpioattach 74 }; 75 76 struct cfdriver gvpio_cd = { 77 NULL, "gvpio", DV_DULL 78 }; 79 80 int 81 gvpiomatch(parent, cfp, auxp) 82 struct device *parent; 83 struct cfdata *cfp; 84 void *auxp; 85 { 86 87 struct gvpbus_args *gap; 88 89 gap = auxp; 90 91 if (gap->flags & GVP_IO) 92 return (1); 93 94 return (0); 95 } 96 97 struct gvpio_devs { 98 char *name; 99 int off; 100 int arg; 101 int ipl; 102 } gvpiodevs[] = { 103 { "com", 0x0b0, 115200 * 16 * 4, 6 }, 104 { "com", 0x130, 115200 * 16 * 4, 6 }, 105 { "lpt", 0x1b0, 0, 2 }, 106 { 0 } 107 }; 108 109 void 110 gvpioattach(parent, self, auxp) 111 struct device *parent, *self; 112 void *auxp; 113 { 114 struct gvpio_softc *giosc; 115 struct gvpio_devs *giosd; 116 struct gvpbus_args *gap; 117 struct supio_attach_args supa; 118 volatile caddr_t gbase; 119 u_int16_t needpsl; 120 121 giosc = (struct gvpio_softc *)self; 122 gap = auxp; 123 124 if (parent) 125 printf("\n"); 126 127 gbase = gap->zargs.va; 128 giosc->sc_cntr = &gbase[0x41]; 129 giosc->sc_bst.base = (u_long)gbase + 1; 130 giosc->sc_bst.stride = 1; 131 LIST_INIT(&giosc->sc_comhdls); 132 giosd = gvpiodevs; 133 134 supa.supio_iot = &giosc->sc_bst; 135 136 gbase[0x041] = 0; 137 gbase[0x161 + 1*2] = 0; 138 gbase[0x261 + 1*2] = 0; 139 gbase[0x361 + 2*2] = 0; 140 gbase[0x461] = 0xd0; 141 142 while (giosd->name) { 143 supa.supio_name = giosd->name; 144 supa.supio_iobase = giosd->off; 145 supa.supio_arg = giosd->arg; 146 supa.supio_ipl = giosd->ipl; 147 config_found(self, &supa, gvpioprint); /* XXX */ 148 ++giosd; 149 } 150 if (giosc->sc_comhdls.lh_first) { 151 /* XXX this should be really in the interupt stuff */ 152 needpsl = PSL_S|PSL_IPL6; 153 if (amiga_ttyspl < needpsl) { 154 printf("%s: raising amiga_ttyspl from 0x%x to 0x%x\n", 155 giosc->sc_dev.dv_xname, amiga_ttyspl, needpsl); 156 amiga_ttyspl = needpsl; 157 } 158 giosc->sc_comisr.isr_intr = gvp_com_intr; 159 giosc->sc_comisr.isr_arg = giosc; 160 giosc->sc_comisr.isr_ipl = 6; 161 add_isr(&giosc->sc_comisr); 162 } 163 gbase[0x041] = 0x08; 164 } 165 166 int 167 gvpioprint(auxp, pnp) 168 void *auxp; 169 const char *pnp; 170 { 171 struct supio_attach_args *supa; 172 supa = auxp; 173 174 if (pnp == NULL) 175 return(QUIET); 176 177 printf("%s at %s port 0x%02x ipl %d", 178 supa->supio_name, pnp, supa->supio_iobase, supa->supio_ipl); 179 180 return(UNCONF); 181 } 182 183 void 184 gvp_com_intr_establish(self, p) 185 struct device *self; 186 struct gvpcom_int_hdl *p; 187 { 188 struct gvpio_softc *sc; 189 190 sc = (struct gvpio_softc *)self; 191 LIST_INSERT_HEAD(&sc->sc_comhdls, p, next); 192 193 } 194 195 int 196 gvp_com_intr(p) 197 void *p; 198 { 199 struct gvpio_softc *sc; 200 struct gvpcom_int_hdl *np; 201 volatile caddr_t cntr; 202 203 sc = (struct gvpio_softc *)p; 204 205 cntr = sc->sc_cntr; 206 207 if (!(*cntr & 0x2)) 208 return (0); 209 210 *cntr &= ~0xa; 211 212 for (np = sc->sc_comhdls.lh_first; np != NULL; 213 np = np->next.le_next) { 214 215 (*np->f)(np->p); 216 } 217 *cntr |= 0x8; 218 219 return (1); 220 } 221