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: src/sys/pci/pcic_p.c,v 1.4.2.3 1999/09/05 08:21:23 peter Exp $
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 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 char *
67 pcic_pci_probe(pcici_t tag, pcidi_t type)
68 {
69 switch (type) {
70 case PCI_DEVICE_ID_PCIC_CLPD6729:
71 return ("Cirrus Logic PD6729/6730 PC-Card Controller");
72 case PCI_DEVICE_ID_PCIC_CLPD6832:
73 return ("Cirrus Logic PD6832 CardBus Adapter");
74 case PCI_DEVICE_ID_PCIC_TI1130:
75 return ("TI 1130 PCMCIA/CardBus Bridge");
76 case PCI_DEVICE_ID_PCIC_TI1131:
77 return ("TI 1131 PCI to PCMCIA/CardBus bridge");
78 default:
79 break;
80 }
81 return (NULL);
82 }
83
84
85 /*
86 * General PCI based card dispatch routine. Right now
87 * it only understands the CL-PD6832.
88 */
89 static void
90 pcic_pci_attach(pcici_t config_id, int unit)
91 {
92 u_long pcic_type; /* The vendor id of the PCI pcic */
93
94 pcic_type = pci_conf_read(config_id, PCI_ID_REG);
95
96 switch (pcic_type) {
97 case PCI_DEVICE_ID_PCIC_CLPD6832:
98 pd6832_legacy_init(config_id, unit);
99 break;
100 }
101
102 if (bootverbose) {
103 int i, j;
104 u_char *p;
105 u_long *pl;
106
107 printf("PCI Config space:\n");
108 for (j = 0; j < 0x98; j += 16) {
109 printf("%02x: ", j);
110 for (i = 0; i < 16; i += 4)
111 printf(" %08x", pci_conf_read(config_id, i+j));
112 printf("\n");
113 }
114 p = (u_char *)pmap_mapdev(pci_conf_read(config_id, 0x10),
115 0x1000);
116 pl = (u_long *)p;
117 printf("Cardbus Socket registers:\n");
118 printf("00: ");
119 for (i = 0; i < 4; i += 1)
120 printf(" %08x:", pl[i]);
121 printf("\n10: ");
122 for (i = 4; i < 8; i += 1)
123 printf(" %08x:", pl[i]);
124 printf("\nExCa registers:\n");
125 for (i = 0; i < 0x40; i += 16)
126 printf("%02x: %16D\n", i, p + 0x800 + i, " ");
127 }
128 }
129
130 /*
131 * Set up the CL-PD6832 to look like a ISA based PCMCIA chip (a
132 * PD672X). This routine is called once per PCMCIA socket.
133 */
134 static void
135 pd6832_legacy_init(pcici_t tag, int unit)
136 {
137 u_long bcr; /* to set interrupts */
138 u_short io_port; /* the io_port to map this slot on */
139 static int num6832 = 0; /* The number of 6832s initialized */
140
141 /*
142 * Some BIOS leave the legacy address uninitialized. This
143 * insures that the PD6832 puts itself where the driver will
144 * look. We assume that multiple 6832's should be laid out
145 * sequentially. We only initialize the first socket's legacy port,
146 * the other is a dummy.
147 */
148 io_port = PCIC_INDEX_0 + num6832 * CLPD6832_NUM_REGS;
149 if (unit == 0)
150 pci_conf_write(tag, CLPD6832_LEGACY_16BIT_IOADDR,
151 io_port & ~PCI_MAP_IO);
152
153 /*
154 * I think this should be a call to pci_map_port, but that
155 * routine won't map regiaters above 0x28, and the register we
156 * need to map is 0x44.
157 */
158 io_port = pci_conf_read(tag, CLPD6832_LEGACY_16BIT_IOADDR)
159 & ~PCI_MAP_IO;
160
161 /*
162 * Configure the first I/O window to contain CLPD6832_NUM_REGS
163 * words and deactivate the second by setting the limit lower
164 * than the base.
165 */
166 pci_conf_write(tag, CLPD6832_IO_BASE0, io_port | 1);
167 pci_conf_write(tag, CLPD6832_IO_LIMIT0,
168 (io_port + CLPD6832_NUM_REGS) | 1);
169
170 pci_conf_write(tag, CLPD6832_IO_BASE1, (io_port + 0x20) | 1);
171 pci_conf_write(tag, CLPD6832_IO_LIMIT1, io_port | 1 );
172
173 /*
174 * Set default operating mode (I/O port space) and allocate
175 * this socket to the current unit.
176 */
177 pci_conf_write(tag, PCI_COMMAND_STATUS_REG, CLPD6832_COMMAND_DEFAULTS );
178 pci_conf_write(tag, CLPD6832_SOCKET, unit);
179
180 /*
181 * Set up the card inserted/card removed interrupts to come
182 * through the isa IRQ.
183 */
184 bcr = pci_conf_read(tag, CLPD6832_BRIDGE_CONTROL);
185 bcr |= (CLPD6832_BCR_ISA_IRQ|CLPD6832_BCR_MGMT_IRQ_ENA);
186 pci_conf_write(tag, CLPD6832_BRIDGE_CONTROL, bcr);
187
188 /* After initializing 2 sockets, the chip is fully configured */
189 if (unit == 1)
190 num6832++;
191
192 if (bootverbose)
193 printf("CardBus: Legacy PC-card 16bit I/O address [0x%x]\n",
194 io_port);
195 }
196 #endif /* NPCI > 0 */
Cache object: 40cf7d2f641b8c3ad3d464f1417fe167
|