]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/freescale/mpc8360emds/mpc8360emds.c
Merge branch 'master' of git://www.denx.de/git/u-boot-sh
[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 <spd.h>
19 #include <miiphy.h>
20 #if defined(CONFIG_PCI)
21 #include <pci.h>
22 #endif
23 #if defined(CONFIG_SPD_EEPROM)
24 #include <spd_sdram.h>
25 #else
26 #include <asm/mmu.h>
27 #endif
28 #if defined(CONFIG_OF_LIBFDT)
29 #include <libfdt.h>
30 #endif
31 #if defined(CONFIG_PQ_MDS_PIB)
32 #include "../common/pq-mds-pib.h"
33 #endif
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 int board_early_init_f(void)
97 {
98
99         u8 *bcsr = (u8 *)CFG_BCSR;
100         const immap_t *immr = (immap_t *)CFG_IMMR;
101
102         /* Enable flash write */
103         bcsr[0xa] &= ~0x04;
104
105         /* Disable G1TXCLK, G2TXCLK h/w buffers (rev.2 h/w bug workaround) */
106         if (immr->sysconf.spridr == SPR_8360_REV20 ||
107             immr->sysconf.spridr == SPR_8360E_REV20 ||
108             immr->sysconf.spridr == SPR_8360_REV21 ||
109             immr->sysconf.spridr == SPR_8360E_REV21)
110                 bcsr[0xe] = 0x30;
111
112         /* Enable second UART */
113         bcsr[0x9] &= ~0x01;
114
115         return 0;
116 }
117
118 int board_early_init_r(void)
119 {
120 #ifdef CONFIG_PQ_MDS_PIB
121         pib_init();
122 #endif
123         return 0;
124 }
125
126 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
127 extern void ddr_enable_ecc(unsigned int dram_size);
128 #endif
129 int fixed_sdram(void);
130 void sdram_init(void);
131
132 long int initdram(int board_type)
133 {
134         volatile immap_t *im = (immap_t *) CFG_IMMR;
135         u32 msize = 0;
136
137         if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
138                 return -1;
139
140         /* DDR SDRAM - Main SODIMM */
141         im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
142 #if defined(CONFIG_SPD_EEPROM)
143         msize = spd_sdram();
144 #else
145         msize = fixed_sdram();
146 #endif
147
148 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
149         /*
150          * Initialize DDR ECC byte
151          */
152         ddr_enable_ecc(msize * 1024 * 1024);
153 #endif
154         /*
155          * Initialize SDRAM if it is on local bus.
156          */
157         sdram_init();
158
159         /* return total bus SDRAM size(bytes)  -- DDR */
160         return (msize * 1024 * 1024);
161 }
162
163 #if !defined(CONFIG_SPD_EEPROM)
164 /*************************************************************************
165  *  fixed sdram init -- doesn't use serial presence detect.
166  ************************************************************************/
167 int fixed_sdram(void)
168 {
169         volatile immap_t *im = (immap_t *) CFG_IMMR;
170         u32 msize = 0;
171         u32 ddr_size;
172         u32 ddr_size_log2;
173
174         msize = CFG_DDR_SIZE;
175         for (ddr_size = msize << 20, ddr_size_log2 = 0;
176              (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
177                 if (ddr_size & 1) {
178                         return -1;
179                 }
180         }
181         im->sysconf.ddrlaw[0].ar =
182             LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
183 #if (CFG_DDR_SIZE != 256)
184 #warning Currenly any ddr size other than 256 is not supported
185 #endif
186 #ifdef CONFIG_DDR_II
187         im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
188         im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
189         im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
190         im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
191         im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
192         im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
193         im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
194         im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
195         im->ddr.sdram_mode = CFG_DDR_MODE;
196         im->ddr.sdram_mode2 = CFG_DDR_MODE2;
197         im->ddr.sdram_interval = CFG_DDR_INTERVAL;
198         im->ddr.sdram_clk_cntl = CFG_DDR_CLK_CNTL;
199 #else
200         im->ddr.csbnds[0].csbnds = 0x00000007;
201         im->ddr.csbnds[1].csbnds = 0x0008000f;
202
203         im->ddr.cs_config[0] = CFG_DDR_CONFIG;
204         im->ddr.cs_config[1] = CFG_DDR_CONFIG;
205
206         im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
207         im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
208         im->ddr.sdram_cfg = CFG_DDR_CONTROL;
209
210         im->ddr.sdram_mode = CFG_DDR_MODE;
211         im->ddr.sdram_interval = CFG_DDR_INTERVAL;
212 #endif
213         udelay(200);
214         im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
215
216         return msize;
217 }
218 #endif                          /*!CFG_SPD_EEPROM */
219
220 int checkboard(void)
221 {
222         puts("Board: Freescale MPC8360EMDS\n");
223         return 0;
224 }
225
226 /*
227  * if MPC8360EMDS is soldered with SDRAM
228  */
229 #if defined(CFG_BR2_PRELIM)  \
230         && defined(CFG_OR2_PRELIM) \
231         && defined(CFG_LBLAWBAR2_PRELIM) \
232         && defined(CFG_LBLAWAR2_PRELIM)
233 /*
234  * Initialize SDRAM memory on the Local Bus.
235  */
236
237 void sdram_init(void)
238 {
239         volatile immap_t *immap = (immap_t *) CFG_IMMR;
240         volatile lbus83xx_t *lbc = &immap->lbus;
241         uint *sdram_addr = (uint *) CFG_LBC_SDRAM_BASE;
242
243         /*
244          * Setup SDRAM Base and Option Registers, already done in cpu_init.c
245          */
246         /*setup mtrpt, lsrt and lbcr for LB bus */
247         lbc->lbcr = CFG_LBC_LBCR;
248         lbc->mrtpr = CFG_LBC_MRTPR;
249         lbc->lsrt = CFG_LBC_LSRT;
250         asm("sync");
251
252         /*
253          * Configure the SDRAM controller Machine Mode Register.
254          */
255         lbc->lsdmr = CFG_LBC_LSDMR_5;   /* Normal Operation */
256         lbc->lsdmr = CFG_LBC_LSDMR_1;   /* Precharge All Banks */
257         asm("sync");
258         *sdram_addr = 0xff;
259         udelay(100);
260
261         /*
262          * We need do 8 times auto refresh operation.
263          */
264         lbc->lsdmr = CFG_LBC_LSDMR_2;
265         asm("sync");
266         *sdram_addr = 0xff;     /* 1 times */
267         udelay(100);
268         *sdram_addr = 0xff;     /* 2 times */
269         udelay(100);
270         *sdram_addr = 0xff;     /* 3 times */
271         udelay(100);
272         *sdram_addr = 0xff;     /* 4 times */
273         udelay(100);
274         *sdram_addr = 0xff;     /* 5 times */
275         udelay(100);
276         *sdram_addr = 0xff;     /* 6 times */
277         udelay(100);
278         *sdram_addr = 0xff;     /* 7 times */
279         udelay(100);
280         *sdram_addr = 0xff;     /* 8 times */
281         udelay(100);
282
283         /* Mode register write operation */
284         lbc->lsdmr = CFG_LBC_LSDMR_4;
285         asm("sync");
286         *(sdram_addr + 0xcc) = 0xff;
287         udelay(100);
288
289         /* Normal operation */
290         lbc->lsdmr = CFG_LBC_LSDMR_5 | 0x40000000;
291         asm("sync");
292         *sdram_addr = 0xff;
293         udelay(100);
294 }
295 #else
296 void sdram_init(void)
297 {
298 }
299 #endif
300
301 #if defined(CONFIG_OF_BOARD_SETUP)
302 void ft_board_setup(void *blob, bd_t *bd)
303 {
304         const immap_t *immr = (immap_t *)CFG_IMMR;
305
306         ft_cpu_setup(blob, bd);
307 #ifdef CONFIG_PCI
308         ft_pci_setup(blob, bd);
309 #endif
310         /*
311          * mpc8360ea pb mds errata 2: RGMII timing
312          * if on mpc8360ea rev. 2.1,
313          * change both ucc phy-connection-types from rgmii-id to rgmii-rxid
314          */
315         if (immr->sysconf.spridr == SPR_8360_REV21 ||
316             immr->sysconf.spridr == SPR_8360E_REV21) {
317                 int nodeoffset;
318                 const char *prop;
319                 int path;
320
321                 nodeoffset = fdt_path_offset(blob, "/aliases");
322                 if (nodeoffset >= 0) {
323 #if defined(CONFIG_HAS_ETH0)
324                         /* fixup UCC 1 if using rgmii-id mode */
325                         prop = fdt_getprop(blob, nodeoffset, "ethernet0", NULL);
326                         if (prop) {
327                                 path = fdt_path_offset(blob, prop);
328                                 prop = fdt_getprop(blob, path,
329                                                    "phy-connection-type", 0);
330                                 if (prop && (strcmp(prop, "rgmii-id") == 0))
331                                         fdt_setprop(blob, path,
332                                                     "phy-connection-type",
333                                                     "rgmii-rxid",
334                                                     sizeof("rgmii-rxid"));
335                         }
336 #endif
337 #if defined(CONFIG_HAS_ETH1)
338                         /* fixup UCC 2 if using rgmii-id mode */
339                         prop = fdt_getprop(blob, nodeoffset, "ethernet1", NULL);
340                         if (prop) {
341                                 path = fdt_path_offset(blob, prop);
342                                 prop = fdt_getprop(blob, path,
343                                                    "phy-connection-type", 0);
344                                 if (prop && (strcmp(prop, "rgmii-id") == 0))
345                                         fdt_setprop(blob, path,
346                                                     "phy-connection-type",
347                                                     "rgmii-rxid",
348                                                     sizeof("rgmii-rxid"));
349                         }
350 #endif
351                 }
352         }
353 }
354 #endif