]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/mpc8349emds/pci.c
da49a5d80dd26925db7aeee92dae41145894150e
[karo-tx-uboot.git] / board / mpc8349emds / pci.c
1 /*
2  * See file CREDITS for list of people who contributed to this
3  * project.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA
19  *
20  */
21
22 #include <asm/mmu.h>
23 #include <common.h>
24 #include <asm/global_data.h>
25 #include <pci.h>
26 #include <asm/mpc8349_pci.h>
27 #include <i2c.h>
28
29 DECLARE_GLOBAL_DATA_PTR;
30
31 #ifdef CONFIG_PCI
32
33 /* System RAM mapped to PCI space */
34 #define CONFIG_PCI_SYS_MEM_BUS  CFG_SDRAM_BASE
35 #define CONFIG_PCI_SYS_MEM_PHYS CFG_SDRAM_BASE
36
37 #ifndef CONFIG_PCI_PNP
38 static struct pci_config_table pci_mpc8349emds_config_table[] = {
39         {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
40          PCI_IDSEL_NUMBER, PCI_ANY_ID,
41          pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
42                                      PCI_ENET0_MEMADDR,
43                                      PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
44                 }
45         },
46         {}
47 };
48 #endif
49
50 static struct pci_controller pci_hose[] = {
51        {
52 #ifndef CONFIG_PCI_PNP
53        config_table:pci_mpc8349emds_config_table,
54 #endif
55        },
56        {
57 #ifndef CONFIG_PCI_PNP
58        config_table:pci_mpc8349emds_config_table,
59 #endif
60        }
61 };
62
63 /**************************************************************************
64  *
65  * pib_init() -- initialize the PCA9555PW IO expander on the PIB board
66  *
67  */
68 void
69 pib_init(void)
70 {
71         u8 val8, orig_i2c_bus;
72         /*
73          * Assign PIB PMC slot to desired PCI bus
74          */
75         /* Switch temporarily to I2C bus #2 */
76         orig_i2c_bus = i2c_get_bus_num();
77
78         if(orig_i2c_bus != 2)
79                 i2c_set_bus_num(2);
80
81         val8 = 0;
82         i2c_write(0x23, 0x6, 1, &val8, 1);
83         i2c_write(0x23, 0x7, 1, &val8, 1);
84         val8 = 0xff;
85         i2c_write(0x23, 0x2, 1, &val8, 1);
86         i2c_write(0x23, 0x3, 1, &val8, 1);
87
88         val8 = 0;
89         i2c_write(0x26, 0x6, 1, &val8, 1);
90         val8 = 0x34;
91         i2c_write(0x26, 0x7, 1, &val8, 1);
92 #if defined(PCI_64BIT)
93         val8 = 0xf4;    /* PMC2:PCI1/64-bit */
94 #elif defined(PCI_ALL_PCI1)
95         val8 = 0xf3;    /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */
96 #elif defined(PCI_ONE_PCI1)
97         val8 = 0xf9;    /* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */
98 #else
99         val8 = 0xf5;    /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */
100 #endif
101         i2c_write(0x26, 0x2, 1, &val8, 1);
102         val8 = 0xff;
103         i2c_write(0x26, 0x3, 1, &val8, 1);
104         val8 = 0;
105         i2c_write(0x27, 0x6, 1, &val8, 1);
106         i2c_write(0x27, 0x7, 1, &val8, 1);
107         val8 = 0xff;
108         i2c_write(0x27, 0x2, 1, &val8, 1);
109         val8 = 0xef;
110         i2c_write(0x27, 0x3, 1, &val8, 1);
111         asm("eieio");
112
113 #if defined(PCI_64BIT)
114         printf("PCI1: 64-bit on PMC2\n");
115 #elif defined(PCI_ALL_PCI1)
116         printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n");
117 #elif defined(PCI_ONE_PCI1)
118         printf("PCI1: 32-bit on PMC1\n");
119         printf("PCI2: 32-bit on PMC2, PMC3\n");
120 #else
121         printf("PCI1: 32-bit on PMC1, PMC2\n");
122         printf("PCI2: 32-bit on PMC3\n");
123 #endif
124         /* Reset to original I2C bus */
125         if(orig_i2c_bus != 2)
126                 i2c_set_bus_num(orig_i2c_bus);
127 }
128
129 /**************************************************************************
130  * pci_init_board()
131  *
132  * NOTICE: PCI2 is not currently supported
133  *
134  */
135 void
136 pci_init_board(void)
137 {
138         volatile immap_t *      immr;
139         volatile clk83xx_t *    clk;
140         volatile law83xx_t *    pci_law;
141         volatile pot83xx_t *    pci_pot;
142         volatile pcictrl83xx_t *        pci_ctrl;
143         volatile pciconf83xx_t *        pci_conf;
144         u16 reg16;
145         u32 reg32;
146         u32 dev;
147         struct  pci_controller * hose;
148
149         immr = (immap_t *)CFG_IMMR;
150         clk = (clk83xx_t *)&immr->clk;
151         pci_law = immr->sysconf.pcilaw;
152         pci_pot = immr->ios.pot;
153         pci_ctrl = immr->pci_ctrl;
154         pci_conf = immr->pci_conf;
155
156         hose = &pci_hose[0];
157
158         pib_init();
159
160         /*
161          * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
162          */
163
164         reg32 = clk->occr;
165         udelay(2000);
166         clk->occr = 0xff000000;
167         udelay(2000);
168
169         /*
170          * Release PCI RST Output signal
171          */
172         pci_ctrl[0].gcr = 0;
173         udelay(2000);
174         pci_ctrl[0].gcr = 1;
175
176 #ifdef CONFIG_MPC83XX_PCI2
177         pci_ctrl[1].gcr = 0;
178         udelay(2000);
179         pci_ctrl[1].gcr = 1;
180 #endif
181
182         /* We need to wait at least a 1sec based on PCI specs */
183         {
184                 int i;
185
186                 for (i = 0; i < 1000; ++i)
187                         udelay (1000);
188         }
189
190         /*
191          * Configure PCI Local Access Windows
192          */
193         pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
194         pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
195
196         pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
197         pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
198
199         /*
200          * Configure PCI Outbound Translation Windows
201          */
202
203         /* PCI1 mem space - prefetch */
204         pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
205         pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
206         pci_pot[0].pocmr = POCMR_EN | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
207
208         /* PCI1 IO space */
209         pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
210         pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
211         pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
212
213         /* PCI1 mmio - non-prefetch mem space */
214         pci_pot[2].potar = (CFG_PCI1_MMIO_BASE >> 12) & POTAR_TA_MASK;
215         pci_pot[2].pobar = (CFG_PCI1_MMIO_PHYS >> 12) & POBAR_BA_MASK;
216         pci_pot[2].pocmr = POCMR_EN | (POCMR_CM_256M & POCMR_CM_MASK);
217
218         /*
219          * Configure PCI Inbound Translation Windows
220          */
221
222         /* we need RAM mapped to PCI space for the devices to
223          * access main memory */
224         pci_ctrl[0].pitar1 = 0x0;
225         pci_ctrl[0].pibar1 = 0x0;
226         pci_ctrl[0].piebar1 = 0x0;
227         pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
228
229         hose->first_busno = 0;
230         hose->last_busno = 0xff;
231
232         /* PCI memory prefetch space */
233         pci_set_region(hose->regions + 0,
234                        CFG_PCI1_MEM_BASE,
235                        CFG_PCI1_MEM_PHYS,
236                        CFG_PCI1_MEM_SIZE,
237                        PCI_REGION_MEM|PCI_REGION_PREFETCH);
238
239         /* PCI memory space */
240         pci_set_region(hose->regions + 1,
241                        CFG_PCI1_MMIO_BASE,
242                        CFG_PCI1_MMIO_PHYS,
243                        CFG_PCI1_MMIO_SIZE,
244                        PCI_REGION_MEM);
245
246         /* PCI IO space */
247         pci_set_region(hose->regions + 2,
248                        CFG_PCI1_IO_BASE,
249                        CFG_PCI1_IO_PHYS,
250                        CFG_PCI1_IO_SIZE,
251                        PCI_REGION_IO);
252
253         /* System memory space */
254         pci_set_region(hose->regions + 3,
255                        CONFIG_PCI_SYS_MEM_BUS,
256                        CONFIG_PCI_SYS_MEM_PHYS,
257                        gd->ram_size,
258                        PCI_REGION_MEM | PCI_REGION_MEMORY);
259
260         hose->region_count = 4;
261
262         pci_setup_indirect(hose,
263                            (CFG_IMMR+0x8300),
264                            (CFG_IMMR+0x8304));
265
266         pci_register_hose(hose);
267
268         /*
269          * Write to Command register
270          */
271         reg16 = 0xff;
272         dev = PCI_BDF(hose->first_busno, 0, 0);
273         pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
274         reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
275         pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
276
277         /*
278          * Clear non-reserved bits in status register.
279          */
280         pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
281         pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
282         pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
283
284 #ifdef CONFIG_PCI_SCAN_SHOW
285         printf("PCI:   Bus Dev VenId DevId Class Int\n");
286 #endif
287         /*
288          * Hose scan.
289          */
290         hose->last_busno = pci_hose_scan(hose);
291
292 #ifdef CONFIG_MPC83XX_PCI2
293         hose = &pci_hose[1];
294
295         /*
296          * Configure PCI Outbound Translation Windows
297          */
298
299         /* PCI2 mem space - prefetch */
300         pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
301         pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
302         pci_pot[3].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
303
304         /* PCI2 IO space */
305         pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
306         pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
307         pci_pot[4].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
308
309         /* PCI2 mmio - non-prefetch mem space */
310         pci_pot[5].potar = (CFG_PCI2_MMIO_BASE >> 12) & POTAR_TA_MASK;
311         pci_pot[5].pobar = (CFG_PCI2_MMIO_PHYS >> 12) & POBAR_BA_MASK;
312         pci_pot[5].pocmr = POCMR_EN | POCMR_PCI2 | (POCMR_CM_256M & POCMR_CM_MASK);
313
314         /*
315          * Configure PCI Inbound Translation Windows
316          */
317
318         /* we need RAM mapped to PCI space for the devices to
319          * access main memory */
320         pci_ctrl[1].pitar1 = 0x0;
321         pci_ctrl[1].pibar1 = 0x0;
322         pci_ctrl[1].piebar1 = 0x0;
323         pci_ctrl[1].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
324
325         hose->first_busno = pci_hose[0].last_busno + 1;
326         hose->last_busno = 0xff;
327
328         /* PCI memory prefetch space */
329         pci_set_region(hose->regions + 0,
330                        CFG_PCI2_MEM_BASE,
331                        CFG_PCI2_MEM_PHYS,
332                        CFG_PCI2_MEM_SIZE,
333                        PCI_REGION_MEM|PCI_REGION_PREFETCH);
334
335         /* PCI memory space */
336         pci_set_region(hose->regions + 1,
337                        CFG_PCI2_MMIO_BASE,
338                        CFG_PCI2_MMIO_PHYS,
339                        CFG_PCI2_MMIO_SIZE,
340                        PCI_REGION_MEM);
341
342         /* PCI IO space */
343         pci_set_region(hose->regions + 2,
344                        CFG_PCI2_IO_BASE,
345                        CFG_PCI2_IO_PHYS,
346                        CFG_PCI2_IO_SIZE,
347                        PCI_REGION_IO);
348
349         /* System memory space */
350         pci_set_region(hose->regions + 3,
351                        CONFIG_PCI_SYS_MEM_BUS,
352                        CONFIG_PCI_SYS_MEM_PHYS,
353                        gd->ram_size,
354                        PCI_REGION_MEM | PCI_REGION_MEMORY);
355
356         hose->region_count = 4;
357
358         pci_setup_indirect(hose,
359                            (CFG_IMMR+0x8380),
360                            (CFG_IMMR+0x8384));
361
362         pci_register_hose(hose);
363
364         /*
365          * Write to Command register
366          */
367         reg16 = 0xff;
368         dev = PCI_BDF(hose->first_busno, 0, 0);
369         pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
370         reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
371         pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
372
373         /*
374          * Clear non-reserved bits in status register.
375          */
376         pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
377         pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
378         pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
379
380         /*
381          * Hose scan.
382          */
383         hose->last_busno = pci_hose_scan(hose);
384 #endif
385
386 }
387
388 #ifdef CONFIG_OF_FLAT_TREE
389 void
390 ft_pci_setup(void *blob, bd_t *bd)
391 {
392         u32 *p;
393         int len;
394
395         p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
396         if (p != NULL) {
397                 p[0] = pci_hose[0].first_busno;
398                 p[1] = pci_hose[0].last_busno;
399         }
400
401 #ifdef CONFIG_MPC83XX_PCI2
402         p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8600/bus-range", &len);
403         if (p != NULL) {
404                 p[0] = pci_hose[1].first_busno;
405                 p[1] = pci_hose[1].last_busno;
406         }
407 #endif
408 }
409 #endif /* CONFIG_OF_FLAT_TREE */
410 #endif /* CONFIG_PCI */