Merge branch 'mpc8349ads'
[platform/kernel/u-boot.git] / board / mpc8349ads / 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 #ifdef CONFIG_PCI
30
31 /* System RAM mapped to PCI space */
32 #define CONFIG_PCI_SYS_MEM_BUS  CFG_SDRAM_BASE
33 #define CONFIG_PCI_SYS_MEM_PHYS CFG_SDRAM_BASE
34
35 #ifndef CONFIG_PCI_PNP
36 static struct pci_config_table pci_mpc83xxads_config_table[] = {
37         {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
38          PCI_IDSEL_NUMBER, PCI_ANY_ID,
39          pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
40                                      PCI_ENET0_MEMADDR,
41                                      PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
42                 }
43         },
44         {}
45 };
46 #endif
47
48 static struct pci_controller pci_hose[] = {
49        {
50 #ifndef CONFIG_PCI_PNP
51        config_table:pci_mpc83xxads_config_table,
52 #endif
53        },
54        {
55 #ifndef CONFIG_PCI_PNP
56        config_table:pci_mpc83xxads_config_table,
57 #endif
58        }
59 };
60
61 /**************************************************************************
62  *
63  * pib_init() -- initialize the PCA9555PW IO expander on the PIB board
64  *
65  */
66 void
67 pib_init(void)
68 {
69         u8 val8;
70         /*
71          * Assign PIB PMC slot to desired PCI bus
72          */
73         mpc8349_i2c = (i2c_t*)(CFG_IMMRBAR + CFG_I2C2_OFFSET);
74         i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE);
75
76         val8 = 0;
77         i2c_write(0x23, 0x6, 1, &val8, 1);
78         i2c_write(0x23, 0x7, 1, &val8, 1);
79         val8 = 0xff;
80         i2c_write(0x23, 0x2, 1, &val8, 1);
81         i2c_write(0x23, 0x3, 1, &val8, 1);
82
83         val8 = 0;
84         i2c_write(0x26, 0x6, 1, &val8, 1);
85         val8 = 0x34;
86         i2c_write(0x26, 0x7, 1, &val8, 1);
87 #if defined(PCI_64BIT)
88         val8 = 0xf4;    /* PMC2:PCI1/64-bit */
89 #elif defined(PCI_ALL_PCI1)
90         val8 = 0xf3;    /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */
91 #elif defined(PCI_ONE_PCI1)
92         val8 = 0xf9;    /* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */
93 #else
94         val8 = 0xf5;    /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */
95 #endif
96         i2c_write(0x26, 0x2, 1, &val8, 1);
97         val8 = 0xff;
98         i2c_write(0x26, 0x3, 1, &val8, 1);
99         val8 = 0;
100         i2c_write(0x27, 0x6, 1, &val8, 1);
101         i2c_write(0x27, 0x7, 1, &val8, 1);
102         val8 = 0xff;
103         i2c_write(0x27, 0x2, 1, &val8, 1);
104         val8 = 0xef;
105         i2c_write(0x27, 0x3, 1, &val8, 1);
106         asm("eieio");
107
108 #if defined(PCI_64BIT)
109         printf("PCI1: 64-bit on PMC2\n");
110 #elif defined(PCI_ALL_PCI1)
111         printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n");
112 #elif defined(PCI_ONE_PCI1)
113         printf("PCI1: 32-bit on PMC1\n");
114         printf("PCI2: 32-bit on PMC2, PMC3\n");
115 #else
116         printf("PCI1: 32-bit on PMC1, PMC2\n");
117         printf("PCI2: 32-bit on PMC3\n");
118 #endif
119 }
120
121 /**************************************************************************
122  * pci_init_board()
123  *
124  * NOTICE: PCI2 is not currently supported
125  *
126  */
127 void
128 pci_init_board(void)
129 {
130         DECLARE_GLOBAL_DATA_PTR;
131         volatile immap_t *      immr;
132         volatile clk8349_t *    clk;
133         volatile law8349_t *    pci_law;
134         volatile pot8349_t *    pci_pot;
135         volatile pcictrl8349_t *        pci_ctrl;
136         volatile pciconf8349_t *        pci_conf;
137         u16 reg16;
138         u32 reg32;
139         struct  pci_controller * hose;
140
141         immr = (immap_t *)CFG_IMMRBAR;
142         clk = (clk8349_t *)&immr->clk;
143         pci_law = immr->sysconf.pcilaw;
144         pci_pot = immr->ios.pot;
145         pci_ctrl = immr->pci_ctrl;
146         pci_conf = immr->pci_conf;
147
148         hose = &pci_hose[0];
149
150         pib_init();
151
152         /*
153          * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
154          */
155
156         reg32 = clk->occr;
157         udelay(2000);
158         clk->occr = 0xff000000;
159         udelay(2000);
160
161         /*
162          * Release PCI RST Output signal
163          */
164         pci_ctrl[0].gcr = 0;
165         udelay(2000);
166         pci_ctrl[0].gcr = 1;
167
168 #ifdef CONFIG_MPC83XX_PCI2
169         pci_ctrl[1].gcr = 0;
170         udelay(2000);
171         pci_ctrl[1].gcr = 1;
172 #endif
173
174         /* We need to wait at least a 1sec based on PCI specs */
175         {
176                 int i;
177
178                 for (i = 0; i < 1000; ++i)
179                         udelay (1000);
180         }
181
182         /*
183          * Configure PCI Local Access Windows
184          */
185         pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
186         pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
187
188         pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
189         pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_32M;
190
191         /*
192          * Configure PCI Outbound Translation Windows
193          */
194
195         /* PCI1 mem space - prefetch */
196         pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
197         pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
198         pci_pot[0].pocmr = POCMR_EN | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
199
200         /* PCI1 IO space */
201         pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
202         pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
203         pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_16M & POCMR_CM_MASK);
204
205         /* PCI1 mmio - non-prefetch mem space */
206         pci_pot[2].potar = (CFG_PCI1_MMIO_BASE >> 12) & POTAR_TA_MASK;
207         pci_pot[2].pobar = (CFG_PCI1_MMIO_PHYS >> 12) & POBAR_BA_MASK;
208         pci_pot[2].pocmr = POCMR_EN | (POCMR_CM_256M & POCMR_CM_MASK);
209
210         /*
211          * Configure PCI Inbound Translation Windows
212          */
213
214         /* we need RAM mapped to PCI space for the devices to
215          * access main memory */
216         pci_ctrl[0].pitar1 = 0x0;
217         pci_ctrl[0].pibar1 = 0x0;
218         pci_ctrl[0].piebar1 = 0x0;
219         pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
220
221         hose->first_busno = 0;
222         hose->last_busno = 0xff;
223
224         /* PCI memory prefetch space */
225         pci_set_region(hose->regions + 0,
226                        CFG_PCI1_MEM_BASE,
227                        CFG_PCI1_MEM_PHYS,
228                        CFG_PCI1_MEM_SIZE,
229                        PCI_REGION_MEM|PCI_REGION_PREFETCH);
230
231         /* PCI memory space */
232         pci_set_region(hose->regions + 1,
233                        CFG_PCI1_MMIO_BASE,
234                        CFG_PCI1_MMIO_PHYS,
235                        CFG_PCI1_MMIO_SIZE,
236                        PCI_REGION_MEM);
237
238         /* PCI IO space */
239         pci_set_region(hose->regions + 2,
240                        CFG_PCI1_IO_BASE,
241                        CFG_PCI1_IO_PHYS,
242                        CFG_PCI1_IO_SIZE,
243                        PCI_REGION_IO);
244
245         /* System memory space */
246         pci_set_region(hose->regions + 3,
247                        CONFIG_PCI_SYS_MEM_BUS,
248                        CONFIG_PCI_SYS_MEM_PHYS,
249                        gd->ram_size,
250                        PCI_REGION_MEM | PCI_REGION_MEMORY);
251
252         hose->region_count = 4;
253
254         pci_setup_indirect(hose,
255                            (CFG_IMMRBAR+0x8300),
256                            (CFG_IMMRBAR+0x8304));
257
258         pci_register_hose(hose);
259
260         /*
261          * Write to Command register
262          */
263         reg16 = 0xff;
264         pci_hose_read_config_word (hose, PCI_BDF(0,0,0), PCI_COMMAND,
265                                         &reg16);
266         reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
267         pci_hose_write_config_word(hose, PCI_BDF(0,0,0), PCI_COMMAND,
268                                         reg16);
269
270         /*
271          * Clear non-reserved bits in status register.
272          */
273         pci_hose_write_config_word(hose, PCI_BDF(0,0,0), PCI_STATUS,
274                                         0xffff);
275         pci_hose_write_config_byte(hose, PCI_BDF(0,0,0), PCI_LATENCY_TIMER,
276                                         0x80);
277         pci_hose_write_config_byte(hose, PCI_BDF(0,0,0), PCI_CACHE_LINE_SIZE,
278                                         0x08);
279
280 #ifdef CONFIG_PCI_SCAN_SHOW
281         printf("PCI:   Bus Dev VenId DevId Class Int\n");
282 #endif
283         /*
284          * Hose scan.
285          */
286         hose->last_busno = pci_hose_scan(hose);
287
288 #ifdef CONFIG_MPC83XX_PCI2
289         hose = &pci_hose[1];
290
291         /*
292          * Configure PCI Outbound Translation Windows
293          */
294
295         /* PCI2 mem space - prefetch */
296         pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
297         pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
298         pci_pot[3].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
299
300         /* PCI2 IO space */
301         pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
302         pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
303         pci_pot[4].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_IO | (POCMR_CM_16M & POCMR_CM_MASK);
304
305         /* PCI2 mmio - non-prefetch mem space */
306         pci_pot[5].potar = (CFG_PCI2_MMIO_BASE >> 12) & POTAR_TA_MASK;
307         pci_pot[5].pobar = (CFG_PCI2_MMIO_PHYS >> 12) & POBAR_BA_MASK;
308         pci_pot[5].pocmr = POCMR_EN | POCMR_PCI2 | (POCMR_CM_256M & POCMR_CM_MASK);
309
310         /*
311          * Configure PCI Inbound Translation Windows
312          */
313
314         /* we need RAM mapped to PCI space for the devices to
315          * access main memory */
316         pci_ctrl[1].pitar1 = 0x0;
317         pci_ctrl[1].pibar1 = 0x0;
318         pci_ctrl[1].piebar1 = 0x0;
319         pci_ctrl[1].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
320
321         hose->first_busno = pci_hose[0].last_busno + 1;
322         hose->last_busno = 0xff;
323
324         /* PCI memory prefetch space */
325         pci_set_region(hose->regions + 0,
326                        CFG_PCI2_MEM_BASE,
327                        CFG_PCI2_MEM_PHYS,
328                        CFG_PCI2_MEM_SIZE,
329                        PCI_REGION_MEM|PCI_REGION_PREFETCH);
330
331         /* PCI memory space */
332         pci_set_region(hose->regions + 1,
333                        CFG_PCI2_MMIO_BASE,
334                        CFG_PCI2_MMIO_PHYS,
335                        CFG_PCI2_MMIO_SIZE,
336                        PCI_REGION_MEM);
337
338         /* PCI IO space */
339         pci_set_region(hose->regions + 2,
340                        CFG_PCI2_IO_BASE,
341                        CFG_PCI2_IO_PHYS,
342                        CFG_PCI2_IO_SIZE,
343                        PCI_REGION_IO);
344
345         /* System memory space */
346         pci_set_region(hose->regions + 3,
347                        CONFIG_PCI_SYS_MEM_BUS,
348                        CONFIG_PCI_SYS_MEM_PHYS,
349                        gd->ram_size,
350                        PCI_REGION_MEM | PCI_REGION_MEMORY);
351
352         hose->region_count = 4;
353
354         pci_setup_indirect(hose,
355                            (CFG_IMMRBAR+0x8380),
356                            (CFG_IMMRBAR+0x8384));
357
358         pci_register_hose(hose);
359
360         /*
361          * Write to Command register
362          */
363         reg16 = 0xff;
364         pci_hose_read_config_word (hose, PCI_BDF(0,0,0), PCI_COMMAND,
365                                         &reg16);
366         reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
367         pci_hose_write_config_word(hose, PCI_BDF(0,0,0), PCI_COMMAND,
368                                         reg16);
369
370         /*
371          * Clear non-reserved bits in status register.
372          */
373         pci_hose_write_config_word(hose, PCI_BDF(0,0,0), PCI_STATUS,
374                                         0xffff);
375         pci_hose_write_config_byte(hose, PCI_BDF(0,0,0), PCI_LATENCY_TIMER,
376                                         0x80);
377         pci_hose_write_config_byte(hose, PCI_BDF(0,0,0), PCI_CACHE_LINE_SIZE,
378                                         0x08);
379
380         /*
381          * Hose scan.
382          */
383         hose->last_busno = pci_hose_scan(hose);
384 #endif
385
386 }
387 #endif /* CONFIG_PCI */