Home | History | Annotate | Line # | Download | only in dev
gvpio.c revision 1.6.8.2
      1 /*	$NetBSD: gvpio.c,v 1.6.8.2 2002/09/17 21:13:02 nathanw 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.6.8.2 2002/09/17 21:13:02 nathanw 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 struct cfattach gvpio_ca = {
     75 	sizeof(struct gvpio_softc), gvpiomatch, gvpioattach
     76 };
     77 
     78 int
     79 gvpiomatch(struct device *parent, struct cfdata *cfp, void *auxp)
     80 {
     81 
     82 	struct gvpbus_args *gap;
     83 
     84 	gap = auxp;
     85 
     86 	if (gap->flags & GVP_IO)
     87 		return (1);
     88 
     89 	return (0);
     90 }
     91 
     92 struct gvpio_devs {
     93 	char *name;
     94 	int off;
     95 	int arg;
     96 	int ipl;
     97 } gvpiodevs[] = {
     98 	{ "com", 0x0b0, 115200 * 16 * 4, 6 },
     99 	{ "com", 0x130, 115200 * 16 * 4, 6 },
    100 	{ "lpt", 0x1b0, 0, 2 },
    101 	{ 0 }
    102 };
    103 
    104 void
    105 gvpioattach(struct device *parent, struct device *self, void *auxp)
    106 {
    107 	struct gvpio_softc *giosc;
    108 	struct gvpio_devs  *giosd;
    109 	struct gvpbus_args *gap;
    110 	struct supio_attach_args supa;
    111 	volatile caddr_t gbase;
    112 	u_int16_t needpsl;
    113 
    114 	giosc = (struct gvpio_softc *)self;
    115 	gap = auxp;
    116 
    117 	if (parent)
    118 		printf("\n");
    119 
    120 	gbase = gap->zargs.va;
    121 	giosc->sc_cntr = &gbase[0x41];
    122 	giosc->sc_bst.base = (u_long)gbase + 1;
    123 	giosc->sc_bst.absm = &amiga_bus_stride_2;
    124 	LIST_INIT(&giosc->sc_comhdls);
    125 	giosd = gvpiodevs;
    126 
    127 	supa.supio_iot = &giosc->sc_bst;
    128 
    129 	gbase[0x041] = 0;
    130 	gbase[0x161 + 1*2] = 0;
    131 	gbase[0x261 + 1*2] = 0;
    132 	gbase[0x361 + 2*2] = 0;
    133 	gbase[0x461] = 0xd0;
    134 
    135 	while (giosd->name) {
    136 		supa.supio_name = giosd->name;
    137 		supa.supio_iobase = giosd->off;
    138 		supa.supio_arg = giosd->arg;
    139 		supa.supio_ipl = giosd->ipl;
    140 		config_found(self, &supa, gvpioprint); /* XXX */
    141 		++giosd;
    142 	}
    143 	if (giosc->sc_comhdls.lh_first) {
    144 		/* XXX this should be really in the interupt stuff */
    145 		needpsl = PSL_S|PSL_IPL6;
    146 		if (amiga_serialspl < needpsl) {
    147 			printf("%s: raising amiga_serialspl from 0x%x to 0x%x\n",
    148 			    giosc->sc_dev.dv_xname, amiga_serialspl, needpsl);
    149 			amiga_serialspl = needpsl;
    150 		}
    151 		giosc->sc_comisr.isr_intr = gvp_com_intr;
    152 		giosc->sc_comisr.isr_arg = giosc;
    153 		giosc->sc_comisr.isr_ipl = 6;
    154 		add_isr(&giosc->sc_comisr);
    155 	}
    156 	gbase[0x041] = 0x08;
    157 }
    158 
    159 int
    160 gvpioprint(void *auxp, const char *pnp)
    161 {
    162 	struct supio_attach_args *supa;
    163 	supa = auxp;
    164 
    165 	if (pnp == NULL)
    166 		return(QUIET);
    167 
    168 	printf("%s at %s port 0x%02x ipl %d",
    169 	    supa->supio_name, pnp, supa->supio_iobase, supa->supio_ipl);
    170 
    171 	return(UNCONF);
    172 }
    173 
    174 void
    175 gvp_com_intr_establish(struct device *self, struct gvpcom_int_hdl *p)
    176 {
    177 	struct gvpio_softc *sc;
    178 
    179 	sc = (struct gvpio_softc *)self;
    180 	LIST_INSERT_HEAD(&sc->sc_comhdls, p, next);
    181 
    182 }
    183 
    184 int
    185 gvp_com_intr(void *p)
    186 {
    187 	struct gvpio_softc *sc;
    188 	struct gvpcom_int_hdl *np;
    189 	volatile caddr_t cntr;
    190 
    191 	sc = (struct gvpio_softc *)p;
    192 
    193 	cntr = sc->sc_cntr;
    194 
    195 	if (!(*cntr & 0x2))
    196 		return (0);
    197 
    198 	*cntr &= ~0xa;
    199 
    200 	for (np = sc->sc_comhdls.lh_first; np != NULL;
    201 	    np = np->next.le_next) {
    202 
    203 		(*np->f)(np->p);
    204 	}
    205 	*cntr |= 0x8;
    206 
    207 	return (1);
    208 }
    209