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