1 /* $OpenBSD: cy_pci.c,v 1.3 1996/11/28 23:28:02 niklas 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 * Supports both ISA and PCI Cyclom cards 12 * 13 * Uses CD1400 automatic CTS flow control, and 14 * if CY_HW_RTS is defined, uses CD1400 automatic input flow control. 15 * This requires a special cable that exchanges the RTS and DTR lines. 16 * 17 * Lots of debug output can be enabled by defining CY_DEBUG 18 * Some debugging counters (number of receive/transmit interrupts etc.) 19 * can be enabled by defining CY_DEBUG1 20 * 21 * This version uses the bus_mem/io_??() stuff 22 * 23 * NOT TESTED !!! 24 * 25 */ 26 27 #undef CY_DEBUG 28 #undef CY_DEBUG1 29 30 #include <sys/types.h> 31 #include <sys/param.h> 32 #include <sys/ioctl.h> 33 #include <sys/syslog.h> 34 #include <sys/fcntl.h> 35 #include <sys/tty.h> 36 #include <sys/proc.h> 37 #include <sys/conf.h> 38 #include <sys/user.h> 39 #include <sys/ioctl.h> 40 #include <sys/select.h> 41 #include <sys/device.h> 42 #include <sys/malloc.h> 43 #include <sys/systm.h> 44 #include <machine/bus.h> 45 #include <dev/pci/pcivar.h> 46 #include <dev/pci/pcireg.h> 47 #include <dev/pci/pcidevs.h> 48 49 #include <dev/ic/cd1400reg.h> 50 #include <dev/ic/cyreg.h> 51 52 /* Macros to clear/set/test flags. */ 53 #define SET(t, f) (t) |= (f) 54 #define CLR(t, f) (t) &= ~(f) 55 #define ISSET(t, f) ((t) & (f)) 56 57 int cy_probe_pci __P((struct device *, void *, void *)); 58 int cy_probe_common __P((int card, bus_space_tag_t, 59 bus_space_handle_t, int bustype)); 60 61 void cyattach __P((struct device *, struct device *, void *)); 62 63 struct cfattach cy_pci_ca = { 64 sizeof(struct cy_softc), cy_probe_pci, cyattach 65 }; 66 67 /* 68 * PCI probe 69 */ 70 int 71 cy_probe_pci(parent, match, aux) 72 struct device *parent; 73 void *match, *aux; 74 { 75 vm_offset_t v_addr, p_addr; 76 int card = ((struct device *)match)->dv_unit; 77 struct pci_attach_args *pa = aux; 78 bus_space_tag_t memt; 79 bus_space_handle_t memh; 80 bus_addr_t memaddr; 81 bus_size_t memsize; 82 bus_space_tag_t iot; 83 bus_space_handle_t ioh; 84 bus_addr_t iobase; 85 bus_size_t iosize; 86 int cacheable; 87 88 if(!(PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CYCLADES && 89 (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CYCLADES_CYCLOMY_1 || 90 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CYCLADES_CYCLOMY_2))) 91 return 0; 92 93 #ifdef CY_DEBUG 94 printf("cy: Found Cyclades PCI device, id = 0x%x\n", pa->pa_id); 95 #endif 96 97 memt = pa->pa_memt; 98 iot = pa->pa_iot; 99 100 if(pci_mem_find(pa->pa_pc, pa->pa_tag, 0x18, 101 &memaddr, &memsize, &cacheable) != 0) { 102 printf("cy%d: can't find PCI card memory", card); 103 return 0; 104 } 105 106 /* map the memory (non-cacheable) */ 107 if(bus_space_map(memt, memaddr, memsize, 0, &memh) != 0) { 108 printf("cy%d: couldn't map PCI memory region\n", card); 109 return 0; 110 } 111 112 /* the PCI Cyclom IO space is only used for enabling interrupts */ 113 if(pci_io_find(pa->pa_pc, pa->pa_tag, 0x14, &iobase, &iosize) != 0) { 114 bus_space_unmap(memt, memh, memsize); 115 printf("cy%d: couldn't find PCI io region\n", card); 116 return 0; 117 } 118 119 if(bus_space_map(iot, iobase, iosize, &ioh) != 0) { 120 bus_space_unmap(memt, memh, memsize); 121 printf("cy%d: couldn't map PCI io region\n", card); 122 return 0; 123 } 124 125 #ifdef CY_DEBUG 126 printf("cy%d: pci mapped mem 0x%lx (size %d), io 0x%x (size %d)\n", 127 card, memaddr, memsize, iobase, iosize); 128 #endif 129 130 if(cy_probe_common(card, memt, memh, CY_BUSTYPE_PCI) == 0) { 131 bus_space_unmap(memt, memh, memsize); 132 bus_space_unmap(iot, ioh, iosize); 133 printf("cy%d: PCI Cyclom card with no CD1400s!?\n", card); 134 return 0; 135 } 136 137 /* Enable PCI card interrupts */ 138 bus_space_write_2(iot, ioh, CY_PCI_INTENA, 139 bus_space_read_2(iot, ioh, CY_PCI_INTENA) | 0x900); 140 141 return 1; 142 } 143