cy_pci.c revision 1.2
1/* $NetBSD: cy_pci.c,v 1.2 1996/10/10 19:52:10 christos Exp $ */ 2 3/* 4 * cy_pci.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/param.h> 13#include <sys/systm.h> 14#include <sys/device.h> 15 16#include <machine/bus.h> 17#include <machine/intr.h> 18 19#include <dev/pci/pcivar.h> 20#include <dev/pci/pcireg.h> 21#include <dev/pci/pcidevs.h> 22 23#include <dev/ic/cd1400reg.h> 24#include <dev/ic/cyreg.h> 25#include <dev/ic/cyvar.h> 26 27static int cy_probe_pci __P((struct device *, void *, void *)); 28static void cy_attach_pci __P((struct device *, struct device *, void *)); 29static int cy_map_pci __P((struct pci_attach_args *, struct cy_softc *, 30 bus_io_handle_t *, bus_mem_size_t *, bus_io_size_t *)); 31static void cy_unmap_pci __P((struct cy_softc *, bus_io_handle_t, 32 bus_mem_size_t, bus_io_size_t)); 33 34struct cfattach cy_pci_ca = { 35 sizeof(struct cy_softc), cy_probe_pci, cy_attach_pci 36}; 37 38static int 39cy_map_pci(pa, sc, ioh, iosize, memsize) 40 struct pci_attach_args *pa; 41 struct cy_softc *sc; 42 bus_io_handle_t *ioh; 43 bus_mem_size_t *memsize; 44 bus_io_size_t *iosize; 45{ 46 bus_io_addr_t iobase; 47 bus_mem_addr_t memaddr; 48 int cacheable; 49 50 if (pci_mem_find(pa->pa_pc, pa->pa_tag, 0x18, &memaddr, memsize, 51 &cacheable) != 0) { 52 kprintf("%s: can't find PCI card memory", sc->sc_dev.dv_xname); 53 return 0; 54 } 55 /* map the memory (non-cacheable) */ 56 if (bus_mem_map(sc->sc_bc, memaddr, *memsize, 0, &sc->sc_memh) != 0) { 57 kprintf("%s: couldn't map PCI memory region\n", 58 sc->sc_dev.dv_xname); 59 return 0; 60 } 61 /* the PCI Cyclom IO space is only used for enabling interrupts */ 62 if (pci_io_find(pa->pa_pc, pa->pa_tag, 0x14, &iobase, iosize) != 0) { 63 kprintf("%s: couldn't find PCI io region\n", 64 sc->sc_dev.dv_xname); 65 goto unmapmem; 66 } 67 if (bus_io_map(sc->sc_bc, iobase, *iosize, ioh) != 0) { 68 kprintf("%s: couldn't map PCI io region\n", sc->sc_dev.dv_xname); 69 goto unmapio; 70 } 71 return 1; 72 73unmapio: 74 bus_io_unmap(sc->sc_bc, *ioh, *iosize); 75unmapmem: 76 bus_mem_unmap(sc->sc_bc, sc->sc_memh, *memsize); 77 return 0; 78} 79 80static void 81cy_unmap_pci(sc, ioh, iosize, memsize) 82 struct cy_softc *sc; 83 bus_io_handle_t ioh; 84 bus_io_size_t iosize; 85 bus_mem_size_t memsize; 86 87{ 88 bus_io_unmap(sc->sc_bc, ioh, iosize); 89 bus_mem_unmap(sc->sc_bc, sc->sc_memh, memsize); 90} 91 92static int 93cy_probe_pci(parent, match, aux) 94 struct device *parent; 95 void *match, *aux; 96{ 97 struct pci_attach_args *pa = aux; 98 bus_io_handle_t ioh; 99 bus_mem_size_t memsize; 100 bus_io_size_t iosize; 101 int rv = 0; 102 struct cy_softc sc; 103 104 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_CYCLADES) 105 return 0; 106 107 switch (PCI_PRODUCT(pa->pa_id)) { 108 case PCI_PRODUCT_CYCLADES_CYCLOMY_1: 109 break; 110 case PCI_PRODUCT_CYCLADES_CYCLOMY_2: 111 break; 112 default: 113 return 0; 114 } 115 116#ifdef CY_DEBUG 117 kprintf("cy: Found Cyclades PCI device, id = 0x%x\n", pa->pa_id); 118#endif 119 memcpy(&sc.sc_dev, match, sizeof(struct device)); 120 121 sc.sc_bc = pa->pa_bc; 122 sc.sc_bustype = CY_BUSTYPE_PCI; 123 124 if (cy_map_pci(pa, &sc, &ioh, &iosize, &memsize) == 0) 125 return 0; 126 127#ifdef CY_DEBUG 128 kprintf("%s: pci mapped mem 0x%lx (size %d), io 0x%x (size %d)\n", 129 sc.sc_dev.dv_xname, memaddr, memsize, iobase, iosize); 130#endif 131 132 if ((rv = cy_find(&sc)) == 0) 133 kprintf("%s: PCI Cyclom card with no CD1400s!?\n", 134 sc.sc_dev.dv_xname); 135 136 cy_unmap_pci(&sc, ioh, iosize, memsize); 137 return rv; 138} 139 140 141static void 142cy_attach_pci(parent, self, aux) 143 struct device *parent, *self; 144 void *aux; 145{ 146 struct cy_softc *sc = (void *) self; 147 pci_intr_handle_t intrhandle; 148 bus_io_handle_t ioh; 149 bus_mem_size_t memsize; 150 bus_io_size_t iosize; 151 struct pci_attach_args *pa = aux; 152 153 sc->sc_bc = pa->pa_bc; 154 sc->sc_bustype = CY_BUSTYPE_PCI; 155 156 if (cy_map_pci(pa, sc, &ioh, &iosize, &memsize) == 0) 157 panic("%s: mapping failed", sc->sc_dev.dv_xname); 158 159 if (cy_find(sc) == 0) 160 panic("%s: Cannot find card", sc->sc_dev.dv_xname); 161 162 cy_attach(parent, self, aux); 163 164 /* Enable PCI card interrupts */ 165 bus_io_write_2(sc->sc_bc, ioh, CY_PCI_INTENA, 166 bus_io_read_2(sc->sc_bc, ioh, CY_PCI_INTENA) | 0x900); 167 168 if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin, 169 pa->pa_intrline, &intrhandle) != 0) 170 panic("%s: couldn't map PCI interrupt", sc->sc_dev.dv_xname); 171 172 173 sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, 174 IPL_TTY, cy_intr, sc); 175 176 if (sc->sc_ih == NULL) 177 panic("%s: couldn't establish interrupt", sc->sc_dev.dv_xname); 178} 179