1 /* $NetBSD: cy_pci.c,v 1.22 2007/10/19 12:00:42 ad 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/cdefs.h> 13 __KERNEL_RCSID(0, "$NetBSD: cy_pci.c,v 1.22 2007/10/19 12:00:42 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/pci/pcivar.h> 23 #include <dev/pci/pcireg.h> 24 #include <dev/pci/pcidevs.h> 25 26 #include <dev/ic/cd1400reg.h> 27 #include <dev/ic/cyreg.h> 28 #include <dev/ic/cyvar.h> 29 30 struct cy_pci_softc { 31 struct cy_softc sc_cy; /* real cy softc */ 32 33 bus_space_tag_t sc_iot; /* PLX runtime i/o tag */ 34 bus_space_handle_t sc_ioh; /* PLX runtime i/o handle */ 35 }; 36 37 static const struct cy_pci_product { 38 pci_product_id_t cp_product; /* product ID */ 39 pcireg_t cp_memtype; /* memory type */ 40 } cy_pci_products[] = { 41 { PCI_PRODUCT_CYCLADES_CYCLOMY_1, 42 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT_1M }, 43 { PCI_PRODUCT_CYCLADES_CYCLOM4Y_1, 44 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT_1M }, 45 { PCI_PRODUCT_CYCLADES_CYCLOM8Y_1, 46 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT_1M }, 47 48 { PCI_PRODUCT_CYCLADES_CYCLOMY_2, 49 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT }, 50 { PCI_PRODUCT_CYCLADES_CYCLOM4Y_2, 51 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT }, 52 { PCI_PRODUCT_CYCLADES_CYCLOM8Y_2, 53 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT }, 54 55 { 0, 56 0 }, 57 }; 58 static const int cy_pci_nproducts = 59 sizeof(cy_pci_products) / sizeof(cy_pci_products[0]); 60 61 static const struct cy_pci_product * 62 cy_pci_lookup(const struct pci_attach_args *pa) 63 { 64 const struct cy_pci_product *cp; 65 int i; 66 67 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_CYCLADES) 68 return (NULL); 69 70 for (i = 0; i < cy_pci_nproducts; i++) { 71 cp = &cy_pci_products[i]; 72 if (PCI_PRODUCT(pa->pa_id) == cp->cp_product) 73 return (cp); 74 } 75 return (NULL); 76 } 77 78 static int 79 cy_pci_match(struct device *parent, struct cfdata *match, 80 void *aux) 81 { 82 struct pci_attach_args *pa = aux; 83 84 return (cy_pci_lookup(pa) != NULL); 85 } 86 87 static void 88 cy_pci_attach(struct device *parent, struct device *self, void *aux) 89 { 90 struct cy_pci_softc *psc = (void *) self; 91 struct cy_softc *sc = (void *) &psc->sc_cy; 92 struct pci_attach_args *pa = aux; 93 pci_intr_handle_t ih; 94 const struct cy_pci_product *cp; 95 const char *intrstr; 96 int plx_ver; 97 98 aprint_naive(": Multi-port serial controller\n"); 99 100 sc->sc_bustype = CY_BUSTYPE_PCI; 101 102 cp = cy_pci_lookup(pa); 103 if (cp == NULL) 104 panic("cy_pci_attach: impossible"); 105 106 aprint_normal(": Cyclades-Y multiport serial\n"); 107 108 if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_IO, 0, 109 &psc->sc_iot, &psc->sc_ioh, NULL, NULL) != 0) { 110 aprint_error("%s: unable to map PLX registers\n", 111 sc->sc_dev.dv_xname); 112 return; 113 } 114 115 if (pci_mapreg_map(pa, 0x18, cp->cp_memtype, 0, 116 &sc->sc_memt, &sc->sc_bsh, NULL, NULL) != 0) { 117 aprint_error("%s: unable to map device registers\n", 118 sc->sc_dev.dv_xname); 119 return; 120 } 121 122 if (cy_find(sc) == 0) { 123 aprint_error("%s: unable to find CD1400s\n", 124 sc->sc_dev.dv_xname); 125 return; 126 } 127 128 /* 129 * XXX Like the Cyclades-Z, we should really check the EEPROM to 130 * determine the "poll or interrupt" setting. For now, we always 131 * map the interrupt and enable it in the PLX. 132 */ 133 134 /* Map and establish the interrupt. */ 135 if (pci_intr_map(pa, &ih) != 0) { 136 aprint_error(": unable to map interrupt\n"); 137 return; 138 } 139 intrstr = pci_intr_string(pa->pa_pc, ih); 140 sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_TTY, cy_intr, sc); 141 if (sc->sc_ih == NULL) { 142 aprint_error(": unable to establish interrupt"); 143 if (intrstr != NULL) 144 aprint_normal(" at %s", intrstr); 145 aprint_normal("\n"); 146 return; 147 } 148 aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr); 149 150 cy_attach(sc); 151 152 plx_ver = bus_space_read_1(sc->sc_memt, sc->sc_bsh, CY_PLX_VER) & 0x0f; 153 154 /* Enable PCI card interrupts */ 155 switch (plx_ver) { 156 case CY_PLX_9050: 157 bus_space_write_2(psc->sc_iot, psc->sc_ioh, CY_PCI_INTENA_9050, 158 bus_space_read_2(psc->sc_iot, psc->sc_ioh, 159 CY_PCI_INTENA_9050) | 0x40); 160 break; 161 162 case CY_PLX_9060: 163 case CY_PLX_9080: 164 default: 165 bus_space_write_2(psc->sc_iot, psc->sc_ioh, CY_PCI_INTENA, 166 bus_space_read_2(psc->sc_iot, psc->sc_ioh, 167 CY_PCI_INTENA) | 0x900); 168 } 169 } 170 171 CFATTACH_DECL(cy_pci, sizeof(struct cy_pci_softc), 172 cy_pci_match, cy_pci_attach, NULL, NULL); 173