mpc83xx: mpc8360emds: Don't use LBC SDRAM when DDR is available
[platform/kernel/u-boot.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 #if defined(CONFIG_OF_LIBFDT)
25 #include <libfdt.h>
26 #endif
27 #if defined(CONFIG_PQ_MDS_PIB)
28 #include "../common/pq-mds-pib.h"
29 #endif
30
31 const qe_iop_conf_t qe_iop_conf_tab[] = {
32         /* GETH1 */
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         {1,  6, 1, 0, 3}, /* TxD4 */
38         {1,  7, 1, 0, 1}, /* TxD5 */
39         {1,  9, 1, 0, 2}, /* TxD6 */
40         {1, 10, 1, 0, 2}, /* TxD7 */
41         {0,  9, 2, 0, 1}, /* RxD0 */
42         {0, 10, 2, 0, 1}, /* RxD1 */
43         {0, 11, 2, 0, 1}, /* RxD2 */
44         {0, 12, 2, 0, 1}, /* RxD3 */
45         {0, 13, 2, 0, 1}, /* RxD4 */
46         {1,  1, 2, 0, 2}, /* RxD5 */
47         {1,  0, 2, 0, 2}, /* RxD6 */
48         {1,  4, 2, 0, 2}, /* RxD7 */
49         {0,  7, 1, 0, 1}, /* TX_EN */
50         {0,  8, 1, 0, 1}, /* TX_ER */
51         {0, 15, 2, 0, 1}, /* RX_DV */
52         {0, 16, 2, 0, 1}, /* RX_ER */
53         {0,  0, 2, 0, 1}, /* RX_CLK */
54         {2,  9, 1, 0, 3}, /* GTX_CLK - CLK10 */
55         {2,  8, 2, 0, 1}, /* GTX125 - CLK9 */
56         /* GETH2 */
57         {0, 17, 1, 0, 1}, /* TxD0 */
58         {0, 18, 1, 0, 1}, /* TxD1 */
59         {0, 19, 1, 0, 1}, /* TxD2 */
60         {0, 20, 1, 0, 1}, /* TxD3 */
61         {1,  2, 1, 0, 1}, /* TxD4 */
62         {1,  3, 1, 0, 2}, /* TxD5 */
63         {1,  5, 1, 0, 3}, /* TxD6 */
64         {1,  8, 1, 0, 3}, /* TxD7 */
65         {0, 23, 2, 0, 1}, /* RxD0 */
66         {0, 24, 2, 0, 1}, /* RxD1 */
67         {0, 25, 2, 0, 1}, /* RxD2 */
68         {0, 26, 2, 0, 1}, /* RxD3 */
69         {0, 27, 2, 0, 1}, /* RxD4 */
70         {1, 12, 2, 0, 2}, /* RxD5 */
71         {1, 13, 2, 0, 3}, /* RxD6 */
72         {1, 11, 2, 0, 2}, /* RxD7 */
73         {0, 21, 1, 0, 1}, /* TX_EN */
74         {0, 22, 1, 0, 1}, /* TX_ER */
75         {0, 29, 2, 0, 1}, /* RX_DV */
76         {0, 30, 2, 0, 1}, /* RX_ER */
77         {0, 31, 2, 0, 1}, /* RX_CLK */
78         {2,  2, 1, 0, 2}, /* GTX_CLK = CLK10 */
79         {2,  3, 2, 0, 1}, /* GTX125 - CLK4 */
80
81         {0,  1, 3, 0, 2}, /* MDIO */
82         {0,  2, 1, 0, 1}, /* MDC */
83
84         {5,  0, 1, 0, 2}, /* UART2_SOUT */
85         {5,  1, 2, 0, 3}, /* UART2_CTS */
86         {5,  2, 1, 0, 1}, /* UART2_RTS */
87         {5,  3, 2, 0, 2}, /* UART2_SIN */
88
89         {0,  0, 0, 0, QE_IOP_TAB_END}, /* END of table */
90 };
91
92 int board_early_init_f(void)
93 {
94
95         u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
96         const immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
97
98         /* Enable flash write */
99         bcsr[0xa] &= ~0x04;
100
101         /* Disable G1TXCLK, G2TXCLK h/w buffers (rev.2.x h/w bug workaround) */
102         if (REVID_MAJOR(immr->sysconf.spridr) == 2)
103                 bcsr[0xe] = 0x30;
104
105         /* Enable second UART */
106         bcsr[0x9] &= ~0x01;
107
108         return 0;
109 }
110
111 int board_early_init_r(void)
112 {
113 #ifdef CONFIG_PQ_MDS_PIB
114         pib_init();
115 #endif
116         return 0;
117 }
118
119 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
120 extern void ddr_enable_ecc(unsigned int dram_size);
121 #endif
122 int fixed_sdram(void);
123 static int sdram_init(unsigned int base);
124
125 phys_size_t initdram(int board_type)
126 {
127         volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
128         u32 msize = 0;
129         u32 lbc_sdram_size;
130
131         if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
132                 return -1;
133
134         /* DDR SDRAM - Main SODIMM */
135         im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
136 #if defined(CONFIG_SPD_EEPROM)
137         msize = spd_sdram();
138 #else
139         msize = fixed_sdram();
140 #endif
141
142 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
143         /*
144          * Initialize DDR ECC byte
145          */
146         ddr_enable_ecc(msize * 1024 * 1024);
147 #endif
148         /*
149          * Initialize SDRAM if it is on local bus.
150          */
151         lbc_sdram_size = sdram_init(msize * 1024 * 1024);
152         if (!msize)
153                 msize = lbc_sdram_size;
154
155         /* return total bus SDRAM size(bytes)  -- DDR */
156         return (msize * 1024 * 1024);
157 }
158
159 #if !defined(CONFIG_SPD_EEPROM)
160 /*************************************************************************
161  *  fixed sdram init -- doesn't use serial presence detect.
162  ************************************************************************/
163 int fixed_sdram(void)
164 {
165         volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
166         u32 msize = 0;
167         u32 ddr_size;
168         u32 ddr_size_log2;
169
170         msize = CONFIG_SYS_DDR_SIZE;
171         for (ddr_size = msize << 20, ddr_size_log2 = 0;
172              (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
173                 if (ddr_size & 1) {
174                         return -1;
175                 }
176         }
177         im->sysconf.ddrlaw[0].ar =
178             LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
179 #if (CONFIG_SYS_DDR_SIZE != 256)
180 #warning Currenly any ddr size other than 256 is not supported
181 #endif
182 #ifdef CONFIG_DDR_II
183         im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
184         im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
185         im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
186         im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
187         im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
188         im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
189         im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
190         im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
191         im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
192         im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
193         im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
194         im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
195 #else
196         im->ddr.csbnds[0].csbnds = 0x00000007;
197         im->ddr.csbnds[1].csbnds = 0x0008000f;
198
199         im->ddr.cs_config[0] = CONFIG_SYS_DDR_CONFIG;
200         im->ddr.cs_config[1] = CONFIG_SYS_DDR_CONFIG;
201
202         im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
203         im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
204         im->ddr.sdram_cfg = CONFIG_SYS_DDR_CONTROL;
205
206         im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
207         im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
208 #endif
209         udelay(200);
210         im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
211
212         return msize;
213 }
214 #endif                          /*!CONFIG_SYS_SPD_EEPROM */
215
216 int checkboard(void)
217 {
218         puts("Board: Freescale MPC8360EMDS\n");
219         return 0;
220 }
221
222 /*
223  * if MPC8360EMDS is soldered with SDRAM
224  */
225 #ifdef CONFIG_SYS_LB_SDRAM
226 /*
227  * Initialize SDRAM memory on the Local Bus.
228  */
229
230 static int sdram_init(unsigned int base)
231 {
232         volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
233         volatile fsl_lbus_t *lbc = &immap->lbus;
234         const int sdram_size = CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024;
235         int rem = base % sdram_size;
236         uint *sdram_addr;
237
238         /* window base address should be aligned to the window size */
239         if (rem)
240                 base = base - rem + sdram_size;
241
242         sdram_addr = (uint *)base;
243         /*
244          * Setup SDRAM Base and Option Registers
245          */
246         immap->lbus.bank[2].br = base | CONFIG_SYS_BR2;
247         immap->lbus.bank[2].or = CONFIG_SYS_OR2;
248         immap->sysconf.lblaw[2].bar = base;
249         immap->sysconf.lblaw[2].ar = CONFIG_SYS_LBLAWAR2;
250
251         /*setup mtrpt, lsrt and lbcr for LB bus */
252         lbc->lbcr = CONFIG_SYS_LBC_LBCR;
253         lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
254         lbc->lsrt = CONFIG_SYS_LBC_LSRT;
255         asm("sync");
256
257         /*
258          * Configure the SDRAM controller Machine Mode Register.
259          */
260         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;    /* Normal Operation */
261         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;    /* Precharge All Banks */
262         asm("sync");
263         *sdram_addr = 0xff;
264         udelay(100);
265
266         /*
267          * We need do 8 times auto refresh operation.
268          */
269         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
270         asm("sync");
271         *sdram_addr = 0xff;     /* 1 times */
272         udelay(100);
273         *sdram_addr = 0xff;     /* 2 times */
274         udelay(100);
275         *sdram_addr = 0xff;     /* 3 times */
276         udelay(100);
277         *sdram_addr = 0xff;     /* 4 times */
278         udelay(100);
279         *sdram_addr = 0xff;     /* 5 times */
280         udelay(100);
281         *sdram_addr = 0xff;     /* 6 times */
282         udelay(100);
283         *sdram_addr = 0xff;     /* 7 times */
284         udelay(100);
285         *sdram_addr = 0xff;     /* 8 times */
286         udelay(100);
287
288         /* Mode register write operation */
289         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
290         asm("sync");
291         *(sdram_addr + 0xcc) = 0xff;
292         udelay(100);
293
294         /* Normal operation */
295         lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5 | 0x40000000;
296         asm("sync");
297         *sdram_addr = 0xff;
298         udelay(100);
299
300         /*
301          * In non-aligned case we don't [normally] use that memory because
302          * there is a hole.
303          */
304         if (rem)
305                 return 0;
306         return CONFIG_SYS_LBC_SDRAM_SIZE;
307 }
308 #else
309 static int sdram_init(unsigned int base) { return 0; }
310 #endif
311
312 #if defined(CONFIG_OF_BOARD_SETUP)
313 void ft_board_setup(void *blob, bd_t *bd)
314 {
315         const immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
316
317         ft_cpu_setup(blob, bd);
318 #ifdef CONFIG_PCI
319         ft_pci_setup(blob, bd);
320 #endif
321         /*
322          * mpc8360ea pb mds errata 2: RGMII timing
323          * if on mpc8360ea rev. 2.1,
324          * change both ucc phy-connection-types from rgmii-id to rgmii-rxid
325          */
326         if ((REVID_MAJOR(immr->sysconf.spridr) == 2) &&
327             (REVID_MINOR(immr->sysconf.spridr) == 1)) {
328                 int nodeoffset;
329                 const char *prop;
330                 int path;
331
332                 nodeoffset = fdt_path_offset(blob, "/aliases");
333                 if (nodeoffset >= 0) {
334 #if defined(CONFIG_HAS_ETH0)
335                         /* fixup UCC 1 if using rgmii-id mode */
336                         prop = fdt_getprop(blob, nodeoffset, "ethernet0", NULL);
337                         if (prop) {
338                                 path = fdt_path_offset(blob, prop);
339                                 prop = fdt_getprop(blob, path,
340                                                    "phy-connection-type", 0);
341                                 if (prop && (strcmp(prop, "rgmii-id") == 0))
342                                         fdt_setprop(blob, path,
343                                                     "phy-connection-type",
344                                                     "rgmii-rxid",
345                                                     sizeof("rgmii-rxid"));
346                         }
347 #endif
348 #if defined(CONFIG_HAS_ETH1)
349                         /* fixup UCC 2 if using rgmii-id mode */
350                         prop = fdt_getprop(blob, nodeoffset, "ethernet1", NULL);
351                         if (prop) {
352                                 path = fdt_path_offset(blob, prop);
353                                 prop = fdt_getprop(blob, path,
354                                                    "phy-connection-type", 0);
355                                 if (prop && (strcmp(prop, "rgmii-id") == 0))
356                                         fdt_setprop(blob, path,
357                                                     "phy-connection-type",
358                                                     "rgmii-rxid",
359                                                     sizeof("rgmii-rxid"));
360                         }
361 #endif
362                 }
363         }
364 }
365 #endif