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