]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/mpc832xemds/pci.c
mpc83xx: Add support for the MPC832XEMDS board
[karo-tx-uboot.git] / board / mpc832xemds / pci.c
1 /*
2  * Copyright (C) 2006 Freescale Semiconductor, Inc.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  */
12
13 /*
14  * PCI Configuration space access support for MPC83xx PCI Bridge
15  */
16 #include <asm/mmu.h>
17 #include <asm/io.h>
18 #include <common.h>
19 #include <pci.h>
20 #include <i2c.h>
21
22 #include <asm/fsl_i2c.h>
23
24 DECLARE_GLOBAL_DATA_PTR;
25
26 #if defined(CONFIG_PCI)
27 #define PCI_FUNCTION_CONFIG   0x44
28 #define PCI_FUNCTION_CFG_LOCK 0x20
29
30 /*
31  * Initialize PCI Devices, report devices found
32  */
33 #ifndef CONFIG_PCI_PNP
34 static struct pci_config_table pci_mpc83xxemds_config_table[] = {
35         {
36                 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
37                 pci_cfgfunc_config_device,
38                 {PCI_ENET0_IOADDR,
39                 PCI_ENET0_MEMADDR,
40                 PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
41         },
42         {}
43 }
44 #endif
45 static struct pci_controller hose[] = {
46         {
47 #ifndef CONFIG_PCI_PNP
48                 config_table:pci_mpc83xxemds_config_table,
49 #endif
50         },
51 };
52
53 /**********************************************************************
54  * pci_init_board()
55  *********************************************************************/
56 void pci_init_board(void)
57 #ifdef CONFIG_PCISLAVE
58 {
59         u16 reg16;
60         volatile immap_t *immr;
61         volatile law83xx_t *pci_law;
62         volatile pot83xx_t *pci_pot;
63         volatile pcictrl83xx_t *pci_ctrl;
64         volatile pciconf83xx_t *pci_conf;
65
66         immr = (immap_t *) CFG_IMMR;
67         pci_law = immr->sysconf.pcilaw;
68         pci_pot = immr->ios.pot;
69         pci_ctrl = immr->pci_ctrl;
70         pci_conf = immr->pci_conf;
71         /*
72          * Configure PCI Inbound Translation Windows
73          */
74         pci_ctrl[0].pitar0 = 0x0;
75         pci_ctrl[0].pibar0 = 0x0;
76         pci_ctrl[0].piwar0 = PIWAR_EN | PIWAR_RTT_SNOOP |
77             PIWAR_WTT_SNOOP | PIWAR_IWS_4K;
78
79         pci_ctrl[0].pitar1 = 0x0;
80         pci_ctrl[0].pibar1 = 0x0;
81         pci_ctrl[0].piebar1 = 0x0;
82         pci_ctrl[0].piwar1 &= ~PIWAR_EN;
83
84         pci_ctrl[0].pitar2 = 0x0;
85         pci_ctrl[0].pibar2 = 0x0;
86         pci_ctrl[0].piebar2 = 0x0;
87         pci_ctrl[0].piwar2 &= ~PIWAR_EN;
88
89         hose[0].first_busno = 0;
90         hose[0].last_busno = 0xff;
91         pci_setup_indirect(&hose[0],
92                            (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304));
93         reg16 = 0xff;
94
95         pci_hose_read_config_word(&hose[0], PCI_BDF(0, 0, 0),
96                                   PCI_COMMAND, &reg16);
97         reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MEMORY;
98         pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0),
99                                    PCI_COMMAND, reg16);
100
101         /*
102          * Clear non-reserved bits in status register.
103          */
104         pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0),
105                                    PCI_STATUS, 0xffff);
106         pci_hose_write_config_byte(&hose[0], PCI_BDF(0, 0, 0),
107                                    PCI_LATENCY_TIMER, 0x80);
108
109         /*
110          * Unlock configuration lock in PCI function configuration register.
111          */
112         pci_hose_read_config_word(&hose[0], PCI_BDF(0, 0, 0),
113                                   PCI_FUNCTION_CONFIG, &reg16);
114         reg16 &= ~(PCI_FUNCTION_CFG_LOCK);
115         pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0),
116                                    PCI_FUNCTION_CONFIG, reg16);
117
118         printf("Enabled PCI 32bit Agent Mode\n");
119 }
120 #else
121 {
122         volatile immap_t *immr;
123         volatile clk83xx_t *clk;
124         volatile law83xx_t *pci_law;
125         volatile pot83xx_t *pci_pot;
126         volatile pcictrl83xx_t *pci_ctrl;
127         volatile pciconf83xx_t *pci_conf;
128
129         u8 val8, orig_i2c_bus;
130         u16 reg16;
131         u32 val32;
132         u32 dev;
133
134         immr = (immap_t *) CFG_IMMR;
135         clk = (clk83xx_t *) & immr->clk;
136         pci_law = immr->sysconf.pcilaw;
137         pci_pot = immr->ios.pot;
138         pci_ctrl = immr->pci_ctrl;
139         pci_conf = immr->pci_conf;
140         /*
141          * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
142          */
143         val32 = clk->occr;
144         udelay(2000);
145 #if defined(PCI_66M)
146         clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
147         printf("PCI clock is 66MHz\n");
148 #elif defined(PCI_33M)
149         clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2 |
150             OCCR_PCICD0 | OCCR_PCICD1 | OCCR_PCICD2 | OCCR_PCICR;
151         printf("PCI clock is 33MHz\n");
152 #else
153         clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
154         printf("PCI clock is 66MHz\n");
155 #endif
156         udelay(2000);
157
158         /*
159          * Configure PCI Local Access Windows
160          */
161         pci_law[0].bar = CFG_PCI_MEM_PHYS & LAWBAR_BAR;
162         pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
163
164         pci_law[1].bar = CFG_PCI_IO_PHYS & LAWBAR_BAR;
165         pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_1M;
166
167         /*
168          * Configure PCI Outbound Translation Windows
169          */
170
171         /* PCI mem space - prefetch */
172         pci_pot[0].potar = (CFG_PCI_MEM_BASE >> 12) & POTAR_TA_MASK;
173         pci_pot[0].pobar = (CFG_PCI_MEM_PHYS >> 12) & POBAR_BA_MASK;
174         pci_pot[0].pocmr =
175             POCMR_EN | POCMR_SE | (POCMR_CM_256M & POCMR_CM_MASK);
176
177         /* PCI mmio - non-prefetch mem space */
178         pci_pot[1].potar = (CFG_PCI_MMIO_BASE >> 12) & POTAR_TA_MASK;
179         pci_pot[1].pobar = (CFG_PCI_MMIO_PHYS >> 12) & POBAR_BA_MASK;
180         pci_pot[1].pocmr = POCMR_EN | (POCMR_CM_256M & POCMR_CM_MASK);
181
182         /* PCI IO space */
183         pci_pot[2].potar = (CFG_PCI_IO_BASE >> 12) & POTAR_TA_MASK;
184         pci_pot[2].pobar = (CFG_PCI_IO_PHYS >> 12) & POBAR_BA_MASK;
185         pci_pot[2].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
186
187         /*
188          * Configure PCI Inbound Translation Windows
189          */
190         pci_ctrl[0].pitar1 = (CFG_PCI_SLV_MEM_LOCAL >> 12) & PITAR_TA_MASK;
191         pci_ctrl[0].pibar1 = (CFG_PCI_SLV_MEM_BUS >> 12) & PIBAR_MASK;
192         pci_ctrl[0].piebar1 = 0x0;
193         pci_ctrl[0].piwar1 =
194             PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP |
195             PIWAR_IWS_2G;
196
197         /*
198          * Assign PIB PMC slot to desired PCI bus
199          */
200
201         /* Switch temporarily to I2C bus #2 */
202         orig_i2c_bus = i2c_get_bus_num();
203         i2c_set_bus_num(1);
204
205         val8 = 0;
206         i2c_write(0x23, 0x6, 1, &val8, 1);
207         i2c_write(0x23, 0x7, 1, &val8, 1);
208         val8 = 0xff;
209         i2c_write(0x23, 0x2, 1, &val8, 1);
210         i2c_write(0x23, 0x3, 1, &val8, 1);
211
212         val8 = 0;
213         i2c_write(0x26, 0x6, 1, &val8, 1);
214         val8 = 0x34;
215         i2c_write(0x26, 0x7, 1, &val8, 1);
216
217         val8 = 0xf9;            /* PMC2, PMC3 slot to PCI bus */
218         i2c_write(0x26, 0x2, 1, &val8, 1);
219         val8 = 0xff;
220         i2c_write(0x26, 0x3, 1, &val8, 1);
221
222         val8 = 0;
223         i2c_write(0x27, 0x6, 1, &val8, 1);
224         i2c_write(0x27, 0x7, 1, &val8, 1);
225         val8 = 0xff;
226         i2c_write(0x27, 0x2, 1, &val8, 1);
227         val8 = 0xef;
228         i2c_write(0x27, 0x3, 1, &val8, 1);
229         asm("eieio");
230
231         /* Reset to original I2C bus */
232         i2c_set_bus_num(orig_i2c_bus);
233
234         /*
235          * Release PCI RST Output signal
236          */
237         udelay(2000);
238         pci_ctrl[0].gcr = 1;
239         udelay(2000);
240
241         hose[0].first_busno = 0;
242         hose[0].last_busno = 0xff;
243
244         /* PCI memory prefetch space */
245         pci_set_region(hose[0].regions + 0,
246                        CFG_PCI_MEM_BASE,
247                        CFG_PCI_MEM_PHYS,
248                        CFG_PCI_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
249
250         /* PCI memory space */
251         pci_set_region(hose[0].regions + 1,
252                        CFG_PCI_MMIO_BASE,
253                        CFG_PCI_MMIO_PHYS, CFG_PCI_MMIO_SIZE, PCI_REGION_MEM);
254
255         /* PCI IO space */
256         pci_set_region(hose[0].regions + 2,
257                        CFG_PCI_IO_BASE,
258                        CFG_PCI_IO_PHYS, CFG_PCI_IO_SIZE, PCI_REGION_IO);
259
260         /* System memory space */
261         pci_set_region(hose[0].regions + 3,
262                        CFG_PCI_SLV_MEM_LOCAL,
263                        CFG_PCI_SLV_MEM_BUS,
264                        CFG_PCI_SLV_MEM_SIZE,
265                        PCI_REGION_MEM | PCI_REGION_MEMORY);
266
267         hose[0].region_count = 4;
268
269         pci_setup_indirect(&hose[0],
270                            (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304));
271
272         pci_register_hose(hose);
273
274         /*
275          * Write command register
276          */
277         reg16 = 0xff;
278         dev = PCI_BDF(0, 0, 0);
279         pci_hose_read_config_word(&hose[0], dev, PCI_COMMAND, &reg16);
280         reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
281         pci_hose_write_config_word(&hose[0], dev, PCI_COMMAND, reg16);
282
283         /*
284          * Clear non-reserved bits in status register.
285          */
286         pci_hose_write_config_word(&hose[0], dev, PCI_STATUS, 0xffff);
287         pci_hose_write_config_byte(&hose[0], dev, PCI_LATENCY_TIMER, 0x80);
288         pci_hose_write_config_byte(&hose[0], dev, PCI_CACHE_LINE_SIZE, 0x08);
289
290         printf("PCI 32bit bus on PMC2 & PMC3\n");
291
292         /*
293          * Hose scan.
294          */
295         hose->last_busno = pci_hose_scan(hose);
296 }
297 #endif                          /* CONFIG_PCISLAVE */
298
299 #ifdef CONFIG_OF_FLAT_TREE
300 void
301 ft_pci_setup(void *blob, bd_t *bd)
302 {
303         u32 *p;
304         int len;
305
306         p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
307         if (p != NULL) {
308                 p[0] = hose[0].first_busno;
309                 p[1] = hose[0].last_busno;
310         }
311 }
312 #endif                          /* CONFIG_OF_FLAT_TREE */
313 #endif                          /* CONFIG_PCI */