]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/freescale/mpc8360emds/mpc8360emds.c
Merge branch 'master' of git://git.denx.de/u-boot-ti
[karo-tx-uboot.git] / board / freescale / mpc8360emds / mpc8360emds.c
1 /*
2  * Copyright (C) 2006 Freescale Semiconductor, Inc.
3  * Dave Liu <daveliu@freescale.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  */
13
14 #include <common.h>
15 #include <ioports.h>
16 #include <mpc83xx.h>
17 #include <i2c.h>
18 #include <miiphy.h>
19 #if defined(CONFIG_PCI)
20 #include <pci.h>
21 #endif
22 #include <spd_sdram.h>
23 #include <asm/mmu.h>
24 #include <asm/io.h>
25 #if defined(CONFIG_OF_LIBFDT)
26 #include <libfdt.h>
27 #endif
28 #include <hwconfig.h>
29 #include <fdt_support.h>
30 #if defined(CONFIG_PQ_MDS_PIB)
31 #include "../common/pq-mds-pib.h"
32 #endif
33 #include "../../../drivers/qe/uec.h"
34
35 const qe_iop_conf_t qe_iop_conf_tab[] = {
36         /* GETH1 */
37         {0,  3, 1, 0, 1}, /* TxD0 */
38         {0,  4, 1, 0, 1}, /* TxD1 */
39         {0,  5, 1, 0, 1}, /* TxD2 */
40         {0,  6, 1, 0, 1}, /* TxD3 */
41         {1,  6, 1, 0, 3}, /* TxD4 */
42         {1,  7, 1, 0, 1}, /* TxD5 */
43         {1,  9, 1, 0, 2}, /* TxD6 */
44         {1, 10, 1, 0, 2}, /* TxD7 */
45         {0,  9, 2, 0, 1}, /* RxD0 */
46         {0, 10, 2, 0, 1}, /* RxD1 */
47         {0, 11, 2, 0, 1}, /* RxD2 */
48         {0, 12, 2, 0, 1}, /* RxD3 */
49         {0, 13, 2, 0, 1}, /* RxD4 */
50         {1,  1, 2, 0, 2}, /* RxD5 */
51         {1,  0, 2, 0, 2}, /* RxD6 */
52         {1,  4, 2, 0, 2}, /* RxD7 */
53         {0,  7, 1, 0, 1}, /* TX_EN */
54         {0,  8, 1, 0, 1}, /* TX_ER */
55         {0, 15, 2, 0, 1}, /* RX_DV */
56         {0, 16, 2, 0, 1}, /* RX_ER */
57         {0,  0, 2, 0, 1}, /* RX_CLK */
58         {2,  9, 1, 0, 3}, /* GTX_CLK - CLK10 */
59         {2,  8, 2, 0, 1}, /* GTX125 - CLK9 */
60         /* GETH2 */
61         {0, 17, 1, 0, 1}, /* TxD0 */
62         {0, 18, 1, 0, 1}, /* TxD1 */
63         {0, 19, 1, 0, 1}, /* TxD2 */
64         {0, 20, 1, 0, 1}, /* TxD3 */
65         {1,  2, 1, 0, 1}, /* TxD4 */
66         {1,  3, 1, 0, 2}, /* TxD5 */
67         {1,  5, 1, 0, 3}, /* TxD6 */
68         {1,  8, 1, 0, 3}, /* TxD7 */
69         {0, 23, 2, 0, 1}, /* RxD0 */
70         {0, 24, 2, 0, 1}, /* RxD1 */
71         {0, 25, 2, 0, 1}, /* RxD2 */
72         {0, 26, 2, 0, 1}, /* RxD3 */
73         {0, 27, 2, 0, 1}, /* RxD4 */
74         {1, 12, 2, 0, 2}, /* RxD5 */
75         {1, 13, 2, 0, 3}, /* RxD6 */
76         {1, 11, 2, 0, 2}, /* RxD7 */
77         {0, 21, 1, 0, 1}, /* TX_EN */
78         {0, 22, 1, 0, 1}, /* TX_ER */
79         {0, 29, 2, 0, 1}, /* RX_DV */
80         {0, 30, 2, 0, 1}, /* RX_ER */
81         {0, 31, 2, 0, 1}, /* RX_CLK */
82         {2,  2, 1, 0, 2}, /* GTX_CLK = CLK10 */
83         {2,  3, 2, 0, 1}, /* GTX125 - CLK4 */
84
85         {0,  1, 3, 0, 2}, /* MDIO */
86         {0,  2, 1, 0, 1}, /* MDC */
87
88         {5,  0, 1, 0, 2}, /* UART2_SOUT */
89         {5,  1, 2, 0, 3}, /* UART2_CTS */
90         {5,  2, 1, 0, 1}, /* UART2_RTS */
91         {5,  3, 2, 0, 2}, /* UART2_SIN */
92
93         {0,  0, 0, 0, QE_IOP_TAB_END}, /* END of table */
94 };
95
96 /* Handle "mpc8360ea rev.2.1 erratum 2: RGMII Timing"? */
97 static int board_handle_erratum2(void)
98 {
99         const immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
100
101         return REVID_MAJOR(immr->sysconf.spridr) == 2 &&
102                REVID_MINOR(immr->sysconf.spridr) == 1;
103 }
104
105 int board_early_init_f(void)
106 {
107         const immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
108         u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
109
110         /* Enable flash write */
111         bcsr[0xa] &= ~0x04;
112
113         /* Disable G1TXCLK, G2TXCLK h/w buffers (rev.2.x h/w bug workaround) */
114         if (REVID_MAJOR(immr->sysconf.spridr) == 2)
115                 bcsr[0xe] = 0x30;
116
117         /* Enable second UART */
118         bcsr[0x9] &= ~0x01;
119
120         if (board_handle_erratum2()) {
121                 void *immap = (immap_t *)(CONFIG_SYS_IMMR + 0x14a8);
122
123                 /*
124                  * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2)
125                  * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1)
126                  */
127                 setbits_be32(immap, 0x0c003000);
128
129                 /*
130                  * IMMR + 0x14AC[20:27] = 10101010
131                  * (data delay for both UCC's)
132                  */
133                 clrsetbits_be32(immap + 4, 0xff0, 0xaa0);
134         }
135         return 0;
136 }
137
138 int board_early_init_r(void)
139 {
140 #ifdef CONFIG_PQ_MDS_PIB
141         pib_init();
142 #endif
143         return 0;
144 }
145
146 #ifdef CONFIG_UEC_ETH
147 static uec_info_t uec_info[] = {
148 #ifdef CONFIG_UEC_ETH1
149         STD_UEC_INFO(1),
150 #endif
151 #ifdef CONFIG_UEC_ETH2
152         STD_UEC_INFO(2),
153 #endif
154 };
155
156 int board_eth_init(bd_t *bd)
157 {
158         if (board_handle_erratum2()) {
159                 int i;
160
161                 for (i = 0; i < ARRAY_SIZE(uec_info); i++)
162                         uec_info[i].enet_interface_type = RGMII_RXID;
163                         uec_info[i].speed = 1000;
164         }
165         return uec_eth_init(bd, uec_info, ARRAY_SIZE(uec_info));
166 }
167 #endif /* CONFIG_UEC_ETH */
168
169 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
170 extern void ddr_enable_ecc(unsigned int dram_size);
171 #endif
172 int fixed_sdram(void);
173 static int sdram_init(unsigned int base);
174
175 phys_size_t initdram(int board_type)
176 {
177         volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
178         u32 msize = 0;
179         u32 lbc_sdram_size;
180
181         if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
182                 return -1;
183
184         /* DDR SDRAM - Main SODIMM */
185         im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
186 #if defined(CONFIG_SPD_EEPROM)
187         msize = spd_sdram();
188 #else
189         msize = fixed_sdram();
190 #endif
191
192 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
193         /*
194          * Initialize DDR ECC byte
195          */
196         ddr_enable_ecc(msize * 1024 * 1024);
197 #endif
198         /*
199          * Initialize SDRAM if it is on local bus.
200          */
201         lbc_sdram_size = sdram_init(msize * 1024 * 1024);
202         if (!msize)
203                 msize = lbc_sdram_size;
204
205         /* return total bus SDRAM size(bytes)  -- DDR */
206         return (msize * 1024 * 1024);
207 }
208
209 #if !defined(CONFIG_SPD_EEPROM)
210 /*************************************************************************
211  *  fixed sdram init -- doesn't use serial presence detect.
212  ************************************************************************/
213 int fixed_sdram(void)
214 {
215         volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
216         u32 msize = 0;
217         u32 ddr_size;
218         u32 ddr_size_log2;
219
220         msize = CONFIG_SYS_DDR_SIZE;
221         for (ddr_size = msize << 20, ddr_size_log2 = 0;
222              (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
223                 if (ddr_size & 1) {
224                         return -1;
225                 }
226         }
227         im->sysconf.ddrlaw[0].ar =
228             LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
229 #if (CONFIG_SYS_DDR_SIZE != 256)
230 #warning Currenly any ddr size other than 256 is not supported
231 #endif
232 #ifdef CONFIG_DDR_II
233         im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
234         im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
235         im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
236         im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
237         im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
238         im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
239         im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
240         im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
241         im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
242         im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
243         im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
244         im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
245 #else
246         im->ddr.csbnds[0].csbnds = 0x00000007;
247         im->ddr.csbnds[1].csbnds = 0x0008000f;
248
249         im->ddr.cs_config[0] = CONFIG_SYS_DDR_CONFIG;
250         im->ddr.cs_config[1] = CONFIG_SYS_DDR_CONFIG;
251
252         im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
253         im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
254         im->ddr.sdram_cfg = CONFIG_SYS_DDR_CONTROL;
255
256         im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
257         im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
258 #endif
259         udelay(200);
260         im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
261
262         return msize;
263 }
264 #endif                          /*!CONFIG_SYS_SPD_EEPROM */
265
266 int checkboard(void)
267 {
268         puts("Board: Freescale MPC8360EMDS\n");
269         return 0;
270 }
271
272 /*
273  * if MPC8360EMDS is soldered with SDRAM
274  */
275 #ifdef CONFIG_SYS_LB_SDRAM
276 /*
277  * Initialize SDRAM memory on the Local Bus.
278  */
279
280 static int sdram_init(unsigned int base)
281 {
282         volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
283         fsl_lbc_t *lbc = LBC_BASE_ADDR;
284         const int sdram_size = CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024;
285         int rem = base % sdram_size;
286         uint *sdram_addr;
287
288         /* window base address should be aligned to the window size */
289         if (rem)
290                 base = base - rem + sdram_size;
291
292         sdram_addr = (uint *)base;
293         /*
294          * Setup SDRAM Base and Option Registers
295          */
296         set_lbc_br(2, base | CONFIG_SYS_BR2);
297         set_lbc_or(2, CONFIG_SYS_OR2);
298         immap->sysconf.lblaw[2].bar = base;
299         immap->sysconf.lblaw[2].ar = CONFIG_SYS_LBLAWAR2;
300
301         /*setup mtrpt, lsrt and lbcr for LB bus */
302         lbc->lbcr = CONFIG_SYS_LBC_LBCR;
303         lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
304         lbc->lsrt = CONFIG_SYS_LBC_LSRT;
305         asm("sync");
306
307         /*
308          * Configure the SDRAM controller Machine Mode Register.
309          */
310         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;    /* Normal Operation */
311         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;    /* Precharge All Banks */
312         asm("sync");
313         *sdram_addr = 0xff;
314         udelay(100);
315
316         /*
317          * We need do 8 times auto refresh operation.
318          */
319         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
320         asm("sync");
321         *sdram_addr = 0xff;     /* 1 times */
322         udelay(100);
323         *sdram_addr = 0xff;     /* 2 times */
324         udelay(100);
325         *sdram_addr = 0xff;     /* 3 times */
326         udelay(100);
327         *sdram_addr = 0xff;     /* 4 times */
328         udelay(100);
329         *sdram_addr = 0xff;     /* 5 times */
330         udelay(100);
331         *sdram_addr = 0xff;     /* 6 times */
332         udelay(100);
333         *sdram_addr = 0xff;     /* 7 times */
334         udelay(100);
335         *sdram_addr = 0xff;     /* 8 times */
336         udelay(100);
337
338         /* Mode register write operation */
339         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
340         asm("sync");
341         *(sdram_addr + 0xcc) = 0xff;
342         udelay(100);
343
344         /* Normal operation */
345         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5 | 0x40000000;
346         asm("sync");
347         *sdram_addr = 0xff;
348         udelay(100);
349
350         /*
351          * In non-aligned case we don't [normally] use that memory because
352          * there is a hole.
353          */
354         if (rem)
355                 return 0;
356         return CONFIG_SYS_LBC_SDRAM_SIZE;
357 }
358 #else
359 static int sdram_init(unsigned int base) { return 0; }
360 #endif
361
362 #if defined(CONFIG_OF_BOARD_SETUP)
363 static void ft_board_fixup_qe_usb(void *blob, bd_t *bd)
364 {
365         if (!hwconfig_subarg_cmp("qe_usb", "mode", "peripheral"))
366                 return;
367
368         do_fixup_by_compat(blob, "fsl,mpc8323-qe-usb", "mode",
369                            "peripheral", sizeof("peripheral"), 1);
370 }
371
372 void ft_board_setup(void *blob, bd_t *bd)
373 {
374         ft_cpu_setup(blob, bd);
375 #ifdef CONFIG_PCI
376         ft_pci_setup(blob, bd);
377 #endif
378         ft_board_fixup_qe_usb(blob, bd);
379         /*
380          * mpc8360ea pb mds errata 2: RGMII timing
381          * if on mpc8360ea rev. 2.1,
382          * change both ucc phy-connection-types from rgmii-id to rgmii-rxid
383          */
384         if (board_handle_erratum2()) {
385                 int nodeoffset;
386                 const char *prop;
387                 int path;
388
389                 nodeoffset = fdt_path_offset(blob, "/aliases");
390                 if (nodeoffset >= 0) {
391 #if defined(CONFIG_HAS_ETH0)
392                         /* fixup UCC 1 if using rgmii-id mode */
393                         prop = fdt_getprop(blob, nodeoffset, "ethernet0", NULL);
394                         if (prop) {
395                                 path = fdt_path_offset(blob, prop);
396                                 prop = fdt_getprop(blob, path,
397                                                    "phy-connection-type", 0);
398                                 if (prop && (strcmp(prop, "rgmii-id") == 0))
399                                         fdt_setprop(blob, path,
400                                                     "phy-connection-type",
401                                                     "rgmii-rxid",
402                                                     sizeof("rgmii-rxid"));
403                         }
404 #endif
405 #if defined(CONFIG_HAS_ETH1)
406                         /* fixup UCC 2 if using rgmii-id mode */
407                         prop = fdt_getprop(blob, nodeoffset, "ethernet1", NULL);
408                         if (prop) {
409                                 path = fdt_path_offset(blob, prop);
410                                 prop = fdt_getprop(blob, path,
411                                                    "phy-connection-type", 0);
412                                 if (prop && (strcmp(prop, "rgmii-id") == 0))
413                                         fdt_setprop(blob, path,
414                                                     "phy-connection-type",
415                                                     "rgmii-rxid",
416                                                     sizeof("rgmii-rxid"));
417                         }
418 #endif
419                 }
420         }
421 }
422 #endif