xref: /openbsd-src/sys/dev/pci/cy_pci.c (revision 62a742911104f98b9185b2c6b6007d9b1c36396c)
1 /*	$OpenBSD: cy_pci.c,v 1.4 1997/08/12 18:33:25 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   int card = ((struct device *)match)->dv_unit;
76   struct pci_attach_args *pa = aux;
77   bus_space_tag_t memt;
78   bus_space_handle_t memh;
79   bus_addr_t memaddr;
80   bus_size_t memsize;
81   bus_space_tag_t iot;
82   bus_space_handle_t ioh;
83   bus_addr_t iobase;
84   bus_size_t iosize;
85   int cacheable;
86 
87   if(!(PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CYCLADES &&
88        (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CYCLADES_CYCLOMY_1 ||
89 	PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CYCLADES_CYCLOMY_2)))
90     return 0;
91 
92 #ifdef CY_DEBUG
93   printf("cy: Found Cyclades PCI device, id = 0x%x\n", pa->pa_id);
94 #endif
95 
96   memt = pa->pa_memt;
97   iot = pa->pa_iot;
98 
99   if(pci_mem_find(pa->pa_pc, pa->pa_tag, 0x18,
100 		  &memaddr, &memsize, &cacheable) != 0) {
101     printf("cy%d: can't find PCI card memory", card);
102     return 0;
103   }
104 
105   /* map the memory (non-cacheable) */
106   if(bus_space_map(memt, memaddr, memsize, 0, &memh) != 0) {
107     printf("cy%d: couldn't map PCI memory region\n", card);
108     return 0;
109   }
110 
111   /* the PCI Cyclom IO space is only used for enabling interrupts */
112   if(pci_io_find(pa->pa_pc, pa->pa_tag, 0x14, &iobase, &iosize) != 0) {
113     bus_space_unmap(memt, memh, memsize);
114     printf("cy%d: couldn't find PCI io region\n", card);
115     return 0;
116   }
117 
118   if(bus_space_map(iot, iobase, iosize, 0, &ioh) != 0) {
119     bus_space_unmap(memt, memh, memsize);
120     printf("cy%d: couldn't map PCI io region\n", card);
121     return 0;
122   }
123 
124 #ifdef CY_DEBUG
125   printf("cy%d: pci mapped mem 0x%lx (size %d), io 0x%x (size %d)\n",
126 	 card, memaddr, memsize, iobase, iosize);
127 #endif
128 
129   if(cy_probe_common(card, memt, memh, CY_BUSTYPE_PCI) == 0) {
130     bus_space_unmap(memt, memh, memsize);
131     bus_space_unmap(iot, ioh, iosize);
132     printf("cy%d: PCI Cyclom card with no CD1400s!?\n", card);
133     return 0;
134   }
135 
136   /* Enable PCI card interrupts */
137   bus_space_write_2(iot, ioh, CY_PCI_INTENA,
138       bus_space_read_2(iot, ioh, CY_PCI_INTENA) | 0x900);
139 
140   return 1;
141 }
142