Home | History | Annotate | Line # | Download | only in isa
cy_isa.c revision 1.22
      1 /*	$NetBSD: cy_isa.c,v 1.22 2007/10/19 12:00:15 ad 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.22 2007/10/19 12:00:15 ad Exp $");
     14 
     15 #include <sys/param.h>
     16 #include <sys/systm.h>
     17 #include <sys/device.h>
     18 
     19 #include <sys/bus.h>
     20 #include <sys/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 CFATTACH_DECL(cy_isa, sizeof(struct cy_softc),
     33     cy_isa_probe, cy_isa_attach, NULL, NULL);
     34 
     35 int
     36 cy_isa_probe(struct device *parent, struct cfdata *match, void *aux)
     37 {
     38 	struct isa_attach_args *ia = aux;
     39 	struct cy_softc sc;
     40 	int found;
     41 
     42 	if (ia->ia_niomem < 1)
     43 		return (0);
     44 	if (ia->ia_nirq < 1)
     45 		return (0);
     46 
     47 	memcpy(&sc.sc_dev, match, sizeof(struct device));
     48 
     49 	sc.sc_memt = ia->ia_memt;
     50 	sc.sc_bustype = CY_BUSTYPE_ISA;
     51 
     52 	/* Disallow wildcarded memory address. */
     53 	if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
     54 		return 0;
     55 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
     56 		return 0;
     57 
     58 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr, CY_MEMSIZE, 0,
     59 	    &sc.sc_bsh) != 0)
     60 		return 0;
     61 
     62 	found = cy_find(&sc);
     63 
     64 	bus_space_unmap(ia->ia_memt, sc.sc_bsh, CY_MEMSIZE);
     65 
     66 	if (found) {
     67 		ia->ia_niomem = 1;
     68 		ia->ia_iomem[0].ir_size = CY_MEMSIZE;
     69 
     70 		ia->ia_nirq = 1;
     71 
     72 		ia->ia_nio = 0;
     73 		ia->ia_ndrq = 0;
     74 	}
     75 	return (found);
     76 }
     77 
     78 void
     79 cy_isa_attach(struct device *parent, struct device *self, void *aux)
     80 {
     81 	struct cy_softc *sc = (void *) self;
     82 	struct isa_attach_args *ia = aux;
     83 
     84 	sc->sc_memt = ia->ia_memt;
     85 	sc->sc_bustype = CY_BUSTYPE_ISA;
     86 
     87 	printf(": Cyclades-Y multiport serial\n");
     88 
     89 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr, CY_MEMSIZE, 0,
     90 	    &sc->sc_bsh) != 0) {
     91 		printf("%s: unable to map device registers\n",
     92 		    sc->sc_dev.dv_xname);
     93 		return;
     94 	}
     95 
     96 	if (cy_find(sc) == 0) {
     97 		printf("%s: unable to find CD1400s\n", sc->sc_dev.dv_xname);
     98 		return;
     99 	}
    100 
    101 	cy_attach(sc);
    102 
    103 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    104 	    IST_EDGE, IPL_TTY, cy_intr, sc);
    105 	if (sc->sc_ih == NULL)
    106 		printf("%s: unable to establish interrupt",
    107 		    sc->sc_dev.dv_xname);
    108 }
    109