FreeBSD/Linux Kernel Cross Reference
sys/pci/pcic_p.c
1 /*
2 * Copyright (c) 1997 Ted Faber
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice immediately at the beginning of the file, without modification,
11 * this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Absolutely no warranty of function or purpose is made by the author
16 * Ted Faber.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $FreeBSD$
30 */
31
32 #include "pci.h"
33 #if NPCI > 0
34
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
38 #include <pci/pcireg.h>
39 #include <pci/pcivar.h>
40 #include <pci/pcic_p.h>
41 #include <pccard/i82365.h>
42 #include <vm/vm.h>
43 #include <vm/pmap.h>
44
45 static u_long pcic_pci_count = 0;
46
47 static const char *pcic_pci_probe(pcici_t, pcidi_t);
48 static void pcic_pci_attach(pcici_t, int);
49
50 static void pd6832_legacy_init(pcici_t tag, int unit);
51
52 static struct pci_device pcic_pci_driver = {
53 "pcic",
54 pcic_pci_probe,
55 pcic_pci_attach,
56 &pcic_pci_count,
57 NULL
58 };
59
60 DATA_SET(pcidevice_set, pcic_pci_driver);
61
62 /*
63 * Return the ID string for the controller if the vendor/product id
64 * matches, NULL otherwise.
65 */
66 static const char *
67 pcic_pci_probe(pcici_t tag, pcidi_t type)
68 {
69 switch (type) {
70 case PCI_DEVICE_ID_PCIC_CLPD6832:
71 return ("Cirrus Logic PD6832 PCI/CardBus Bridge");
72 case PCI_DEVICE_ID_PCIC_TI1130:
73 return ("TI PCI-1130 PCI-CardBus Bridge");
74 case PCI_DEVICE_ID_PCIC_TI1131:
75 return ("TI PCI-1131 PCI-CardBus Bridge");
76 case PCI_DEVICE_ID_PCIC_TI1220:
77 return ("TI PCI-1220 PCI-CardBus Bridge");
78 case PCI_DEVICE_ID_PCIC_TI1221:
79 return ("TI PCI-1221 PCI-CardBus Bridge");
80 case PCI_DEVICE_ID_PCIC_TI1250:
81 return ("TI PCI-1250 PCI-CardBus Bridge");
82 case PCI_DEVICE_ID_PCIC_TI1251:
83 return ("TI PCI-1251 PCI-CardBus Bridge");
84 case PCI_DEVICE_ID_TOSHIBA_TOPIC95:
85 return ("Toshiba ToPIC95 PCI-CardBus Bridge");
86 case PCI_DEVICE_ID_TOSHIBA_TOPIC97:
87 return ("Toshiba ToPIC97 PCI-CardBus Bridge");
88 case PCI_DEVICE_ID_RICOH_RL5C465:
89 return ("Ricoh RL5C465 PCI-CardBus Bridge");
90 case PCI_DEVICE_ID_RICOH_RL5C475:
91 return ("Ricoh RL5C475 PCI-CardBus Bridge");
92 case PCI_DEVICE_ID_RICOH_RL5C476:
93 return ("Ricoh RL5C476 PCI-CardBus Bridge");
94 case PCI_DEVICE_ID_RICOH_RL5C478:
95 return ("Ricoh RL5C478 PCI-CardBus Bridge");
96 /* 16bit PC-card bridges */
97 case PCI_DEVICE_ID_PCIC_CLPD6729:
98 return ("Cirrus Logic PD6729/6730 PC-Card Controller");
99 case PCI_DEVICE_ID_PCIC_OZ6729:
100 return ("O2micro OZ6729 PC-Card Bridge");
101 case PCI_DEVICE_ID_PCIC_OZ6730:
102 return ("O2micro OZ6730 PC-Card Bridge");
103
104 default:
105 break;
106 }
107 return (NULL);
108 }
109
110
111 /*
112 * General PCI based card dispatch routine. Right now
113 * it only understands the CL-PD6832.
114 */
115 static void
116 pcic_pci_attach(pcici_t config_id, int unit)
117 {
118 u_long pcic_type; /* The vendor id of the PCI pcic */
119
120 pcic_type = pci_conf_read(config_id, PCI_ID_REG);
121
122 switch (pcic_type) {
123 case PCI_DEVICE_ID_PCIC_CLPD6832:
124 pd6832_legacy_init(config_id, unit);
125 break;
126 }
127
128 if (bootverbose) {
129 int i, j;
130 u_char *p;
131 u_long *pl;
132
133 printf("PCI Config space:\n");
134 for (j = 0; j < 0x98; j += 16) {
135 printf("%02x: ", j);
136 for (i = 0; i < 16; i += 4)
137 printf(" %08lx", pci_conf_read(config_id, i+j));
138 printf("\n");
139 }
140 p = (u_char *)pmap_mapdev(pci_conf_read(config_id, 0x10),
141 0x1000);
142 pl = (u_long *)p;
143 printf("Cardbus Socket registers:\n");
144 printf("00: ");
145 for (i = 0; i < 4; i += 1)
146 printf(" %08lx:", pl[i]);
147 printf("\n10: ");
148 for (i = 4; i < 8; i += 1)
149 printf(" %08lx:", pl[i]);
150 printf("\nExCa registers:\n");
151 for (i = 0; i < 0x40; i += 16)
152 printf("%02x: %16D\n", i, p + 0x800 + i, " ");
153 }
154 }
155
156 /*
157 * Set up the CL-PD6832 to look like a ISA based PCMCIA chip (a
158 * PD672X). This routine is called once per PCMCIA socket.
159 */
160 static void
161 pd6832_legacy_init(pcici_t tag, int unit)
162 {
163 u_long bcr; /* to set interrupts */
164 u_short io_port; /* the io_port to map this slot on */
165 static int num6832 = 0; /* The number of 6832s initialized */
166
167 /*
168 * Some BIOS leave the legacy address uninitialized. This
169 * insures that the PD6832 puts itself where the driver will
170 * look. We assume that multiple 6832's should be laid out
171 * sequentially. We only initialize the first socket's legacy port,
172 * the other is a dummy.
173 */
174 io_port = PCIC_INDEX_0 + num6832 * CLPD6832_NUM_REGS;
175 if (unit == 0)
176 pci_conf_write(tag, CLPD6832_LEGACY_16BIT_IOADDR,
177 io_port & ~PCI_MAP_IO);
178
179 /*
180 * I think this should be a call to pci_map_port, but that
181 * routine won't map regiaters above 0x28, and the register we
182 * need to map is 0x44.
183 */
184 io_port = pci_conf_read(tag, CLPD6832_LEGACY_16BIT_IOADDR)
185 & ~PCI_MAP_IO;
186
187 /*
188 * Configure the first I/O window to contain CLPD6832_NUM_REGS
189 * words and deactivate the second by setting the limit lower
190 * than the base.
191 */
192 pci_conf_write(tag, CLPD6832_IO_BASE0, io_port | 1);
193 pci_conf_write(tag, CLPD6832_IO_LIMIT0,
194 (io_port + CLPD6832_NUM_REGS) | 1);
195
196 pci_conf_write(tag, CLPD6832_IO_BASE1, (io_port + 0x20) | 1);
197 pci_conf_write(tag, CLPD6832_IO_LIMIT1, io_port | 1 );
198
199 /*
200 * Set default operating mode (I/O port space) and allocate
201 * this socket to the current unit.
202 */
203 pci_conf_write(tag, PCI_COMMAND_STATUS_REG, CLPD6832_COMMAND_DEFAULTS );
204 pci_conf_write(tag, CLPD6832_SOCKET, unit);
205
206 /*
207 * Set up the card inserted/card removed interrupts to come
208 * through the isa IRQ.
209 */
210 bcr = pci_conf_read(tag, CLPD6832_BRIDGE_CONTROL);
211 bcr |= (CLPD6832_BCR_ISA_IRQ|CLPD6832_BCR_MGMT_IRQ_ENA);
212 pci_conf_write(tag, CLPD6832_BRIDGE_CONTROL, bcr);
213
214 /* After initializing 2 sockets, the chip is fully configured */
215 if (unit == 1)
216 num6832++;
217
218 if (bootverbose)
219 printf("CardBus: Legacy PC-card 16bit I/O address [0x%x]\n",
220 io_port);
221 }
222 #endif /* NPCI > 0 */
Cache object: bee13e73a80dc9174f59d3c71cb72513
|