]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/freescale/mpc8360erdk/mpc8360erdk.c
Merge branch 'master' of git://www.denx.de/git/u-boot into new-image
[karo-tx-uboot.git] / board / freescale / mpc8360erdk / mpc8360erdk.c
1 /*
2  * Copyright (C) 2006 Freescale Semiconductor, Inc.
3  *                    Dave Liu <daveliu@freescale.com>
4  *
5  * Copyright (C) 2007 Logic Product Development, Inc.
6  *                    Peter Barada <peterb@logicpd.com>
7  *
8  * Copyright (C) 2007 MontaVista Software, Inc.
9  *                    Anton Vorontsov <avorontsov@ru.mvista.com>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (at your option) any later version.
15  */
16
17 #include <common.h>
18 #include <ioports.h>
19 #include <mpc83xx.h>
20 #include <i2c.h>
21 #include <miiphy.h>
22 #include <asm/io.h>
23 #include <asm/mmu.h>
24 #include <pci.h>
25 #include <libfdt.h>
26
27 const qe_iop_conf_t qe_iop_conf_tab[] = {
28         /* MDIO */
29         {0,  1, 3, 0, 2}, /* MDIO */
30         {0,  2, 1, 0, 1}, /* MDC */
31
32         /* UCC1 - UEC (Gigabit) */
33         {0,  3, 1, 0, 1}, /* TxD0 */
34         {0,  4, 1, 0, 1}, /* TxD1 */
35         {0,  5, 1, 0, 1}, /* TxD2 */
36         {0,  6, 1, 0, 1}, /* TxD3 */
37         {0,  9, 2, 0, 1}, /* RxD0 */
38         {0, 10, 2, 0, 1}, /* RxD1 */
39         {0, 11, 2, 0, 1}, /* RxD2 */
40         {0, 12, 2, 0, 1}, /* RxD3 */
41         {0,  7, 1, 0, 1}, /* TX_EN */
42         {0,  8, 1, 0, 1}, /* TX_ER */
43         {0, 15, 2, 0, 1}, /* RX_DV */
44         {0,  0, 2, 0, 1}, /* RX_CLK */
45         {2,  9, 1, 0, 3}, /* GTX_CLK - CLK10 */
46         {2,  8, 2, 0, 1}, /* GTX125 - CLK9 */
47
48         /* UCC2 - UEC (Gigabit) */
49         {0, 17, 1, 0, 1}, /* TxD0 */
50         {0, 18, 1, 0, 1}, /* TxD1 */
51         {0, 19, 1, 0, 1}, /* TxD2 */
52         {0, 20, 1, 0, 1}, /* TxD3 */
53         {0, 23, 2, 0, 1}, /* RxD0 */
54         {0, 24, 2, 0, 1}, /* RxD1 */
55         {0, 25, 2, 0, 1}, /* RxD2 */
56         {0, 26, 2, 0, 1}, /* RxD3 */
57         {0, 21, 1, 0, 1}, /* TX_EN */
58         {0, 22, 1, 0, 1}, /* TX_ER */
59         {0, 29, 2, 0, 1}, /* RX_DV */
60         {0, 31, 2, 0, 1}, /* RX_CLK */
61         {2,  2, 1, 0, 2}, /* GTX_CLK - CLK10 */
62         {2,  3, 2, 0, 1}, /* GTX125 - CLK4 */
63
64         /* UCC7 - UEC */
65         {4,  0, 1, 0, 1}, /* TxD0 */
66         {4,  1, 1, 0, 1}, /* TxD1 */
67         {4,  2, 1, 0, 1}, /* TxD2 */
68         {4,  3, 1, 0, 1}, /* TxD3 */
69         {4,  6, 2, 0, 1}, /* RxD0 */
70         {4,  7, 2, 0, 1}, /* RxD1 */
71         {4,  8, 2, 0, 1}, /* RxD2 */
72         {4,  9, 2, 0, 1}, /* RxD3 */
73         {4,  4, 1, 0, 1}, /* TX_EN */
74         {4,  5, 1, 0, 1}, /* TX_ER */
75         {4, 12, 2, 0, 1}, /* RX_DV */
76         {4, 13, 2, 0, 1}, /* RX_ER */
77         {4, 10, 2, 0, 1}, /* COL */
78         {4, 11, 2, 0, 1}, /* CRS */
79         {2, 18, 2, 0, 1}, /* TX_CLK - CLK19 */
80         {2, 19, 2, 0, 1}, /* RX_CLK - CLK20 */
81
82         /* UCC4 - UEC */
83         {1, 14, 1, 0, 1}, /* TxD0 */
84         {1, 15, 1, 0, 1}, /* TxD1 */
85         {1, 16, 1, 0, 1}, /* TxD2 */
86         {1, 17, 1, 0, 1}, /* TxD3 */
87         {1, 20, 2, 0, 1}, /* RxD0 */
88         {1, 21, 2, 0, 1}, /* RxD1 */
89         {1, 22, 2, 0, 1}, /* RxD2 */
90         {1, 23, 2, 0, 1}, /* RxD3 */
91         {1, 18, 1, 0, 1}, /* TX_EN */
92         {1, 19, 1, 0, 2}, /* TX_ER */
93         {1, 26, 2, 0, 1}, /* RX_DV */
94         {1, 27, 2, 0, 1}, /* RX_ER */
95         {1, 24, 2, 0, 1}, /* COL */
96         {1, 25, 2, 0, 1}, /* CRS */
97         {2,  6, 2, 0, 1}, /* TX_CLK - CLK7 */
98         {2,  7, 2, 0, 1}, /* RX_CLK - CLK8 */
99
100         /* PCI1 */
101         {5,  4, 2, 0, 3}, /* PCI_M66EN */
102         {5,  5, 1, 0, 3}, /* PCI_INTA */
103         {5,  6, 1, 0, 3}, /* PCI_RSTO */
104         {5,  7, 3, 0, 3}, /* PCI_C_BE0 */
105         {5,  8, 3, 0, 3}, /* PCI_C_BE1 */
106         {5,  9, 3, 0, 3}, /* PCI_C_BE2 */
107         {5, 10, 3, 0, 3}, /* PCI_C_BE3 */
108         {5, 11, 3, 0, 3}, /* PCI_PAR */
109         {5, 12, 3, 0, 3}, /* PCI_FRAME */
110         {5, 13, 3, 0, 3}, /* PCI_TRDY */
111         {5, 14, 3, 0, 3}, /* PCI_IRDY */
112         {5, 15, 3, 0, 3}, /* PCI_STOP */
113         {5, 16, 3, 0, 3}, /* PCI_DEVSEL */
114         {5, 17, 0, 0, 0}, /* PCI_IDSEL */
115         {5, 18, 3, 0, 3}, /* PCI_SERR */
116         {5, 19, 3, 0, 3}, /* PCI_PERR */
117         {5, 20, 3, 0, 3}, /* PCI_REQ0 */
118         {5, 21, 2, 0, 3}, /* PCI_REQ1 */
119         {5, 22, 2, 0, 3}, /* PCI_GNT2 */
120         {5, 23, 3, 0, 3}, /* PCI_GNT0 */
121         {5, 24, 1, 0, 3}, /* PCI_GNT1 */
122         {5, 25, 1, 0, 3}, /* PCI_GNT2 */
123         {5, 26, 0, 0, 0}, /* PCI_CLK0 */
124         {5, 27, 0, 0, 0}, /* PCI_CLK1 */
125         {5, 28, 0, 0, 0}, /* PCI_CLK2 */
126         {5, 29, 0, 0, 3}, /* PCI_SYNC_OUT */
127         {6,  0, 3, 0, 3}, /* PCI_AD0 */
128         {6,  1, 3, 0, 3}, /* PCI_AD1 */
129         {6,  2, 3, 0, 3}, /* PCI_AD2 */
130         {6,  3, 3, 0, 3}, /* PCI_AD3 */
131         {6,  4, 3, 0, 3}, /* PCI_AD4 */
132         {6,  5, 3, 0, 3}, /* PCI_AD5 */
133         {6,  6, 3, 0, 3}, /* PCI_AD6 */
134         {6,  7, 3, 0, 3}, /* PCI_AD7 */
135         {6,  8, 3, 0, 3}, /* PCI_AD8 */
136         {6,  9, 3, 0, 3}, /* PCI_AD9 */
137         {6, 10, 3, 0, 3}, /* PCI_AD10 */
138         {6, 11, 3, 0, 3}, /* PCI_AD11 */
139         {6, 12, 3, 0, 3}, /* PCI_AD12 */
140         {6, 13, 3, 0, 3}, /* PCI_AD13 */
141         {6, 14, 3, 0, 3}, /* PCI_AD14 */
142         {6, 15, 3, 0, 3}, /* PCI_AD15 */
143         {6, 16, 3, 0, 3}, /* PCI_AD16 */
144         {6, 17, 3, 0, 3}, /* PCI_AD17 */
145         {6, 18, 3, 0, 3}, /* PCI_AD18 */
146         {6, 19, 3, 0, 3}, /* PCI_AD19 */
147         {6, 20, 3, 0, 3}, /* PCI_AD20 */
148         {6, 21, 3, 0, 3}, /* PCI_AD21 */
149         {6, 22, 3, 0, 3}, /* PCI_AD22 */
150         {6, 23, 3, 0, 3}, /* PCI_AD23 */
151         {6, 24, 3, 0, 3}, /* PCI_AD24 */
152         {6, 25, 3, 0, 3}, /* PCI_AD25 */
153         {6, 26, 3, 0, 3}, /* PCI_AD26 */
154         {6, 27, 3, 0, 3}, /* PCI_AD27 */
155         {6, 28, 3, 0, 3}, /* PCI_AD28 */
156         {6, 29, 3, 0, 3}, /* PCI_AD29 */
157         {6, 30, 3, 0, 3}, /* PCI_AD30 */
158         {6, 31, 3, 0, 3}, /* PCI_AD31 */
159
160         /* NAND */
161         {4, 18, 2, 0, 0}, /* NAND_RYnBY */
162
163         /* DUART - UART2 */
164         {5,  0, 1, 0, 2}, /* UART2_SOUT */
165         {5,  2, 1, 0, 1}, /* UART2_RTS */
166         {5,  3, 2, 0, 2}, /* UART2_SIN */
167         {5,  1, 2, 0, 3}, /* UART2_CTS */
168
169         /* UCC5 - UART3 */
170         {3,  0, 1, 0, 1}, /* UART3_TX */
171         {3,  4, 1, 0, 1}, /* UART3_RTS */
172         {3,  6, 2, 0, 1}, /* UART3_RX */
173         {3, 12, 2, 0, 0}, /* UART3_CTS */
174         {3, 13, 2, 0, 0}, /* UCC5_CD */
175
176         /* UCC6 - UART4 */
177         {3, 14, 1, 0, 1}, /* UART4_TX */
178         {3, 18, 1, 0, 1}, /* UART4_RTS */
179         {3, 20, 2, 0, 1}, /* UART4_RX */
180         {3, 26, 2, 0, 0}, /* UART4_CTS */
181         {3, 27, 2, 0, 0}, /* UCC6_CD */
182
183         /* Fujitsu MB86277 (MINT) graphics controller */
184         {0, 30, 1, 0, 0}, /* nSRESET_GRAPHICS */
185         {1,  5, 1, 0, 0}, /* nXRST_GRAPHICS */
186         {1,  7, 1, 0, 0}, /* LVDS_BKLT_CTR */
187         {2, 16, 1, 0, 0}, /* LVDS_BKLT_EN */
188
189         /* END of table */
190         {0,  0, 0, 0, QE_IOP_TAB_END},
191 };
192
193 int board_early_init_f(void)
194 {
195         return 0;
196 }
197
198 int board_early_init_r(void)
199 {
200         void *reg = (void *)(CFG_IMMR + 0x14a8);
201         u32 val;
202
203         /*
204          * Because of errata in the UCCs, we have to write to the reserved
205          * registers to slow the clocks down.
206          */
207         val = in_be32(reg);
208         /* UCC1 */
209         val |= 0x00003000;
210         /* UCC2 */
211         val |= 0x0c000000;
212         out_be32(reg, val);
213
214         return 0;
215 }
216
217 int fixed_sdram(void)
218 {
219         volatile immap_t *im = (immap_t *)CFG_IMMR;
220         u32 msize = 0;
221         u32 ddr_size;
222         u32 ddr_size_log2;
223
224         msize = CFG_DDR_SIZE;
225         for (ddr_size = msize << 20, ddr_size_log2 = 0;
226              (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
227                 if (ddr_size & 1)
228                         return -1;
229         }
230
231         im->sysconf.ddrlaw[0].ar =
232             LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
233
234         im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
235         im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
236         im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
237         im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
238         im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
239         im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
240         im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
241         im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
242         im->ddr.sdram_mode = CFG_DDR_MODE;
243         im->ddr.sdram_mode2 = CFG_DDR_MODE2;
244         im->ddr.sdram_interval = CFG_DDR_INTERVAL;
245         im->ddr.sdram_clk_cntl = CFG_DDR_CLK_CNTL;
246         udelay(200);
247         im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
248
249         return msize;
250 }
251
252 long int initdram(int board_type)
253 {
254 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
255         extern void ddr_enable_ecc(unsigned int dram_size);
256 #endif
257         volatile immap_t *im = (immap_t *)CFG_IMMR;
258         u32 msize = 0;
259
260         if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
261                 return -1;
262
263         /* DDR SDRAM - Main SODIMM */
264         im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
265         msize = fixed_sdram();
266
267 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
268         /*
269          * Initialize DDR ECC byte
270          */
271         ddr_enable_ecc(msize * 1024 * 1024);
272 #endif
273
274         /* return total bus SDRAM size(bytes)  -- DDR */
275         return (msize * 1024 * 1024);
276 }
277
278 int checkboard(void)
279 {
280         puts("Board: Freescale/Logic MPC8360ERDK\n");
281         return 0;
282 }
283
284 static struct pci_region pci_regions[] = {
285         {
286                 .bus_start = CFG_PCI1_MEM_BASE,
287                 .phys_start = CFG_PCI1_MEM_PHYS,
288                 .size = CFG_PCI1_MEM_SIZE,
289                 .flags = PCI_REGION_MEM | PCI_REGION_PREFETCH,
290         },
291         {
292                 .bus_start = CFG_PCI1_MMIO_BASE,
293                 .phys_start = CFG_PCI1_MMIO_PHYS,
294                 .size = CFG_PCI1_MMIO_SIZE,
295                 .flags = PCI_REGION_MEM,
296         },
297         {
298                 .bus_start = CFG_PCI1_IO_BASE,
299                 .phys_start = CFG_PCI1_IO_PHYS,
300                 .size = CFG_PCI1_IO_SIZE,
301                 .flags = PCI_REGION_IO,
302         },
303 };
304
305 void pci_init_board(void)
306 {
307         volatile immap_t *immr = (volatile immap_t *)CFG_IMMR;
308         volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
309         volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
310         struct pci_region *reg[] = { pci_regions, };
311
312 #if defined(PCI_33M)
313         clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2 |
314                     OCCR_PCICD0 | OCCR_PCICD1 | OCCR_PCICD2 | OCCR_PCICR;
315         printf("PCI clock is 33MHz\n");
316 #else
317         clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
318         printf("PCI clock is 66MHz\n");
319 #endif
320
321         udelay(2000);
322
323         /* Configure PCI Local Access Windows */
324         pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
325         pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
326
327         pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
328         pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
329
330         mpc83xx_pci_init(1, reg, 0);
331 }
332
333 #if defined(CONFIG_OF_BOARD_SETUP)
334 void ft_board_setup(void *blob, bd_t *bd)
335 {
336         ft_cpu_setup(blob, bd);
337         ft_pci_setup(blob, bd);
338 }
339 #endif