Home | History | Annotate | Line # | Download | only in isa
cy_isa.c revision 1.14
      1 /*	$NetBSD: cy_isa.c,v 1.14 2002/01/07 21:47:04 thorpej Exp $	*/
      2 
      3 /*
      4  * cy.c
      5  *
      6  * Driver for Cyclades Cyclom-8/16/32 multiport serial cards
      7  * (currently not tested with Cyclom-32 cards)
      8  *
      9  * Timo Rossi, 1996
     10  */
     11 
     12 #include <sys/cdefs.h>
     13 __KERNEL_RCSID(0, "$NetBSD: cy_isa.c,v 1.14 2002/01/07 21:47:04 thorpej Exp $");
     14 
     15 #include <sys/param.h>
     16 #include <sys/systm.h>
     17 #include <sys/device.h>
     18 
     19 #include <machine/bus.h>
     20 #include <machine/intr.h>
     21 
     22 #include <dev/isa/isavar.h>
     23 #include <dev/isa/isareg.h>
     24 
     25 #include <dev/ic/cd1400reg.h>
     26 #include <dev/ic/cyreg.h>
     27 #include <dev/ic/cyvar.h>
     28 
     29 int	cy_isa_probe(struct device *, struct cfdata *, void *);
     30 void	cy_isa_attach(struct device *, struct device *, void *);
     31 
     32 struct cfattach cy_isa_ca = {
     33 	sizeof(struct cy_softc), cy_isa_probe, cy_isa_attach
     34 };
     35 
     36 int
     37 cy_isa_probe(struct device *parent, struct cfdata *match, void *aux)
     38 {
     39 	struct isa_attach_args *ia = aux;
     40 	struct cy_softc sc;
     41 	int found;
     42 
     43 	if (ia->ia_niomem < 1)
     44 		return (0);
     45 	if (ia->ia_nirq < 1)
     46 		return (0);
     47 
     48 	memcpy(&sc.sc_dev, match, sizeof(struct device));
     49 
     50 	sc.sc_memt = ia->ia_memt;
     51 	sc.sc_bustype = CY_BUSTYPE_ISA;
     52 
     53 	/* Disallow wildcarded memory address. */
     54 	if (ia->ia_iomem[0].ir_addr == ISACF_IOMEM_DEFAULT)
     55 		return 0;
     56 	if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT)
     57 		return 0;
     58 
     59 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr, CY_MEMSIZE, 0,
     60 	    &sc.sc_bsh) != 0)
     61 		return 0;
     62 
     63 	found = cy_find(&sc);
     64 
     65 	bus_space_unmap(ia->ia_memt, sc.sc_bsh, CY_MEMSIZE);
     66 
     67 	if (found) {
     68 		ia->ia_niomem = 1;
     69 		ia->ia_iomem[0].ir_size = CY_MEMSIZE;
     70 
     71 		ia->ia_nirq = 1;
     72 
     73 		ia->ia_nio = 0;
     74 		ia->ia_ndrq = 0;
     75 	}
     76 	return (found);
     77 }
     78 
     79 void
     80 cy_isa_attach(struct device *parent, struct device *self, void *aux)
     81 {
     82 	struct cy_softc *sc = (void *) self;
     83 	struct isa_attach_args *ia = aux;
     84 
     85 	sc->sc_memt = ia->ia_memt;
     86 	sc->sc_bustype = CY_BUSTYPE_ISA;
     87 
     88 	printf(": Cyclades-Y multiport serial\n");
     89 
     90 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr, CY_MEMSIZE, 0,
     91 	    &sc->sc_bsh) != 0) {
     92 		printf("%s: unable to map device registers\n",
     93 		    sc->sc_dev.dv_xname);
     94 		return;
     95 	}
     96 
     97 	if (cy_find(sc) == 0) {
     98 		printf("%s: unable to find CD1400s\n", sc->sc_dev.dv_xname);
     99 		return;
    100 	}
    101 
    102 	cy_attach(sc);
    103 
    104 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    105 	    IST_EDGE, IPL_TTY, cy_intr, sc);
    106 	if (sc->sc_ih == NULL)
    107 		printf("%s: unable to establish interrupt",
    108 		    sc->sc_dev.dv_xname);
    109 }
    110