Home | History | Annotate | Line # | Download | only in isa
      1 /*	$NetBSD: cy_isa.c,v 1.24 2023/11/20 04:26:34 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.24 2023/11/20 04:26:34 thorpej Exp $");
     14 
     15 #include <sys/param.h>
     16 #include <sys/systm.h>
     17 #include <sys/device.h>
     18 #include <sys/kmem.h>
     19 
     20 #include <sys/bus.h>
     21 #include <sys/intr.h>
     22 
     23 #include <dev/isa/isavar.h>
     24 #include <dev/isa/isareg.h>
     25 
     26 #include <dev/ic/cd1400reg.h>
     27 #include <dev/ic/cyreg.h>
     28 #include <dev/ic/cyvar.h>
     29 
     30 int	cy_isa_probe(device_t, cfdata_t, void *);
     31 void	cy_isa_attach(device_t, device_t, void *);
     32 
     33 CFATTACH_DECL_NEW(cy_isa, sizeof(struct cy_softc),
     34     cy_isa_probe, cy_isa_attach, NULL, NULL);
     35 
     36 int
     37 cy_isa_probe(device_t parent, cfdata_t match, void *aux)
     38 {
     39 	struct isa_attach_args *ia = aux;
     40 	struct cy_softc *sc;
     41 	int found = 0;
     42 
     43 	if (ia->ia_niomem < 1)
     44 		return (0);
     45 	if (ia->ia_nirq < 1)
     46 		return (0);
     47 
     48 	/* Disallow wildcarded memory address. */
     49 	if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
     50 		return 0;
     51 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
     52 		return 0;
     53 
     54 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
     55 
     56 	sc->sc_memt = ia->ia_memt;
     57 	sc->sc_bustype = CY_BUSTYPE_ISA;
     58 
     59 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr, CY_MEMSIZE, 0,
     60 	    &sc->sc_bsh) != 0)
     61 		goto out;
     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  out:
     77 	kmem_free(sc, sizeof(*sc));
     78 	return (found);
     79 }
     80 
     81 void
     82 cy_isa_attach(device_t parent, device_t self, void *aux)
     83 {
     84 	struct cy_softc *sc = device_private(self);
     85 	struct isa_attach_args *ia = aux;
     86 
     87 	sc->sc_dev = self;
     88 	sc->sc_memt = ia->ia_memt;
     89 	sc->sc_bustype = CY_BUSTYPE_ISA;
     90 
     91 	printf(": Cyclades-Y multiport serial\n");
     92 
     93 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr, CY_MEMSIZE, 0,
     94 	    &sc->sc_bsh) != 0) {
     95 		aprint_error_dev(sc->sc_dev,
     96 		    "unable to map device registers\n");
     97 		return;
     98 	}
     99 
    100 	if (cy_find(sc) == 0) {
    101 		aprint_error_dev(sc->sc_dev, "unable to find CD1400s\n");
    102 		return;
    103 	}
    104 
    105 	cy_attach(sc);
    106 
    107 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    108 	    IST_EDGE, IPL_TTY, cy_intr, sc);
    109 	if (sc->sc_ih == NULL)
    110 		aprint_error_dev(sc->sc_dev, "unable to establish interrupt\n");
    111 }
    112