blob: 79cb3f1343d3344fc89ca00c4445b7c805e963b2 [file] [log] [blame]
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +01001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7 *
8 * (C) Copyright 2005-2009
9 * Modified for InterControl digsyMTC MPC5200 board by
10 * Frank Bodammer, GCD Hard- & Software GmbH,
11 * frank.bodammer@gcd-solutions.de
12 *
13 * (C) Copyright 2009
14 * Grzegorz Bernacki, Semihalf, gjb@semihalf.com
15 *
16 * See file CREDITS for list of people who contributed to this
17 * project.
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License as
21 * published by the Free Software Foundation; either version 2 of
22 * the License, or (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
33 */
34
35#include <common.h>
36#include <mpc5xxx.h>
37#include <net.h>
38#include <pci.h>
39#include <asm/processor.h>
40#include <asm/io.h>
41#include "eeprom.h"
Heiko Schocher13f805e2011-01-13 08:25:00 +010042#if defined(CONFIG_DIGSY_REV5)
43#include "is45s16800a2.h"
44#include <mtd/cfi_flash.h>
45#else
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +010046#include "is42s16800a-7t.h"
Heiko Schocher13f805e2011-01-13 08:25:00 +010047#endif
48#include <libfdt.h>
Heiko Schochere9ef3f42011-01-21 07:23:35 +010049#include <fdt_support.h>
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +010050
51DECLARE_GLOBAL_DATA_PTR;
52
53extern int usb_cpu_init(void);
54
Heiko Schocher13f805e2011-01-13 08:25:00 +010055#if defined(CONFIG_DIGSY_REV5)
56/*
57 * The M29W128GH needs a specail reset command function,
58 * details see the doc/README.cfi file
59 */
60void flash_cmd_reset(flash_info_t *info)
61{
62 flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
63}
64#endif
65
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +010066#ifndef CONFIG_SYS_RAMBOOT
67static void sdram_start(int hi_addr)
68{
69 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
70 long control = SDRAM_CONTROL | hi_addr_bit;
71
72 /* unlock mode register */
73 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
74
75 /* precharge all banks */
76 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
77
78 /* auto refresh */
79 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
80
81 /* set mode register */
82 out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
83
84 /* normal operation */
85 out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
86}
87#endif
88
89/*
90 * ATTENTION: Although partially referenced initdram does NOT make real use
91 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if
92 * CONFIG_SYS_SDRAM_BASE is something else than 0x00000000.
93 */
94
95phys_size_t initdram(int board_type)
96{
97 ulong dramsize = 0;
98 ulong dramsize2 = 0;
99 uint svr, pvr;
100#ifndef CONFIG_SYS_RAMBOOT
101 ulong test1, test2;
102
103 /* setup SDRAM chip selects */
104 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001C); /* 512MB at 0x0 */
105 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000); /* disabled */
106
107 /* setup config registers */
108 out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
109 out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
110
111 /* find RAM size using SDRAM CS0 only */
112 sdram_start(0);
113 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
114 sdram_start(1);
115 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
116 if (test1 > test2) {
117 sdram_start(0);
118 dramsize = test1;
119 } else {
120 dramsize = test2;
121 }
122
123 /* memory smaller than 1MB is impossible */
124 if (dramsize < (1 << 20))
125 dramsize = 0;
126
127 /* set SDRAM CS0 size according to the amount of RAM found */
128 if (dramsize > 0) {
129 out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
130 (0x13 + __builtin_ffs(dramsize >> 20) - 1));
131 } else {
132 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */
133 }
134
135 /* let SDRAM CS1 start right after CS0 */
136 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize + 0x0000001C);
137
138 /* find RAM size using SDRAM CS1 only */
139 test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
140 0x08000000);
141 dramsize2 = test1;
142
143 /* memory smaller than 1MB is impossible */
144 if (dramsize2 < (1 << 20))
145 dramsize2 = 0;
146
147 /* set SDRAM CS1 size according to the amount of RAM found */
148 if (dramsize2 > 0) {
149 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, (dramsize |
150 (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
151 } else {
152 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize); /* disabled */
153 }
154
155#else /* CONFIG_SYS_RAMBOOT */
156
157 /* retrieve size of memory connected to SDRAM CS0 */
158 dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
159 if (dramsize >= 0x13)
160 dramsize = (1 << (dramsize - 0x13)) << 20;
161 else
162 dramsize = 0;
163
164 /* retrieve size of memory connected to SDRAM CS1 */
165 dramsize2 = in_be32((void *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
166 if (dramsize2 >= 0x13)
167 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
168 else
169 dramsize2 = 0;
170
171#endif /* CONFIG_SYS_RAMBOOT */
172
173 /*
174 * On MPC5200B we need to set the special configuration delay in the
175 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
176 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
177 *
178 * "The SDelay should be written to a value of 0x00000004. It is
179 * required to account for changes caused by normal wafer processing
180 * parameters."
181 */
182 svr = get_svr();
183 pvr = get_pvr();
184 if ((SVR_MJREV(svr) >= 2) &&
185 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
186 out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
187
188 return dramsize + dramsize2;
189}
190
191int checkboard(void)
192{
193 char *s = getenv("serial#");
194
195 puts ("Board: InterControl digsyMTC");
Heiko Schocher13f805e2011-01-13 08:25:00 +0100196#if defined(CONFIG_DIGSY_REV5)
197 puts (" rev5");
198#endif
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +0100199 if (s != NULL) {
200 puts(", ");
201 puts(s);
202 }
203 putc('\n');
204
205 return 0;
206}
207
208int board_early_init_r(void)
209{
Grzegorz Bernacki89d90332009-06-12 11:33:53 +0200210#ifdef CONFIG_MPC52XX_SPI
211 struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt*)MPC5XXX_GPT;
212#endif
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +0100213 /*
214 * Now, when we are in RAM, enable flash write access for detection
215 * process. Note that CS_BOOT cannot be cleared when executing in
216 * flash.
217 */
218 /* disable CS_BOOT */
219 clrbits_be32((void *)MPC5XXX_ADDECR, (1 << 25));
220 /* enable CS1 */
221 setbits_be32((void *)MPC5XXX_ADDECR, (1 << 17));
222 /* enable CS0 */
223 setbits_be32((void *)MPC5XXX_ADDECR, (1 << 16));
224
225#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
226 /* Low level USB init, required for proper kernel operation */
227 usb_cpu_init();
228#endif
Grzegorz Bernacki89d90332009-06-12 11:33:53 +0200229#ifdef CONFIG_MPC52XX_SPI
230 /* GPT 6 Output Enable */
231 out_be32(&gpt[6].emsr, 0x00000034);
232 /* GPT 7 Output Enable */
233 out_be32(&gpt[7].emsr, 0x00000034);
234#endif
235
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +0100236 return (0);
237}
238
239void board_get_enetaddr (uchar * enet)
240{
241 ushort read = 0;
242 ushort addr_of_eth_addr = 0;
243 ushort len_sys = 0;
244 ushort len_sys_cfg = 0;
245
246 /* check identification word */
247 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_IDENT, (uchar *)&read, 2);
248 if (read != EEPROM_IDENT)
249 return;
250
251 /* calculate offset of config area */
252 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYS, (uchar *)&len_sys, 2);
253 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYSCFG,
254 (uchar *)&len_sys_cfg, 2);
255 addr_of_eth_addr = (len_sys + len_sys_cfg + EEPROM_ADDR_ETHADDR) << 1;
256 if (addr_of_eth_addr >= EEPROM_LEN)
257 return;
258
259 eeprom_read(EEPROM_ADDR, addr_of_eth_addr, enet, 6);
260}
261
262int misc_init_r(void)
263{
264 uchar enetaddr[6];
265
266 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
267 board_get_enetaddr(enetaddr);
268 eth_setenv_enetaddr("ethaddr", enetaddr);
269 }
270
271 return 0;
272}
273
274#ifdef CONFIG_PCI
275static struct pci_controller hose;
276
277extern void pci_mpc5xxx_init(struct pci_controller *);
278
279void pci_init_board(void)
280{
281 pci_mpc5xxx_init(&hose);
282}
283#endif
284
285#ifdef CONFIG_CMD_IDE
286
287#ifdef CONFIG_IDE_RESET
288
289void init_ide_reset(void)
290{
291 debug ("init_ide_reset\n");
292
293 /* set gpio output value to 1 */
294 setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
295 /* open drain output */
296 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
297 /* direction output */
298 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
299 /* enable gpio */
300 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
301
302}
303
304void ide_set_reset(int idereset)
305{
306 debug ("ide_reset(%d)\n", idereset);
307
308 /* set gpio output value to 0 */
309 clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
310 /* open drain output */
311 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
312 /* direction output */
313 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
314 /* enable gpio */
315 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
316
317 udelay(10000);
318
319 /* set gpio output value to 1 */
320 setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
321 /* open drain output */
322 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
323 /* direction output */
324 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
325 /* enable gpio */
326 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
327}
328#endif /* CONFIG_IDE_RESET */
Heiko Schocher13f805e2011-01-13 08:25:00 +0100329#endif /* CONFIG_CMD_IDE */
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +0100330
331#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Heiko Schocher13f805e2011-01-13 08:25:00 +0100332static void ft_delete_node(void *fdt, const char *compat)
333{
334 int off = -1;
335 int ret;
336
337 off = fdt_node_offset_by_compatible(fdt, -1, compat);
338 if (off < 0) {
339 printf("Could not find %s node.\n", compat);
340 return;
341 }
342
343 ret = fdt_del_node(fdt, off);
344 if (ret < 0)
345 printf("Could not delete %s node.\n", compat);
346}
347#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
348static void ft_adapt_flash_base(void *blob)
349{
350 flash_info_t *dev = &flash_info[0];
351 int off;
352 struct fdt_property *prop;
353 int len;
354 u32 *reg, *reg2;
355
356 off = fdt_node_offset_by_compatible(blob, -1, "fsl,mpc5200b-lpb");
357 if (off < 0) {
358 printf("Could not find fsl,mpc5200b-lpb node.\n");
359 return;
360 }
361
362 /* found compatible property */
363 prop = fdt_get_property_w(blob, off, "ranges", &len);
364 if (prop) {
365 reg = reg2 = (u32 *)&prop->data[0];
366
367 reg[2] = dev->start[0];
368 reg[3] = dev->size;
369 fdt_setprop(blob, off, "ranges", reg2, len);
370 } else
371 printf("Could not find ranges\n");
372}
373
374extern ulong flash_get_size (phys_addr_t base, int banknum);
375
376/* Update the Flash Baseaddr settings */
377int update_flash_size (int flash_size)
378{
379 volatile struct mpc5xxx_mmap_ctl *mm =
380 (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
381 flash_info_t *dev;
382 int i;
383 int size = 0;
384 unsigned long base = 0x0;
385 u32 *cs_reg = (u32 *)&mm->cs0_start;
386
387 for (i = 0; i < 2; i++) {
388 dev = &flash_info[i];
389
390 if (dev->size) {
391 /* calculate new base addr for this chipselect */
392 base -= dev->size;
393 out_be32(cs_reg, START_REG(base));
394 cs_reg++;
395 out_be32(cs_reg, STOP_REG(base, dev->size));
396 cs_reg++;
397 /* recalculate the sectoraddr in the cfi driver */
398 size += flash_get_size(base, i);
399 }
400 }
401 gd->bd->bi_flashstart = base;
402 return 0;
403}
404#endif /* defined(CONFIG_SYS_UPDATE_FLASH_SIZE) */
405
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +0100406void ft_board_setup(void *blob, bd_t *bd)
407{
Heiko Schocherb5ea4082011-04-03 20:10:20 +0000408 int phy_addr = CONFIG_PHY_ADDR;
409 char eth_path[] = "/soc5200@f0000000/mdio@3000/ethernet-phy@0";
410
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +0100411 ft_cpu_setup(blob, bd);
Heiko Schocher13f805e2011-01-13 08:25:00 +0100412 /*
413 * There are 2 RTC nodes in the DTS, so remove
414 * the unneeded node here.
415 */
416#if defined(CONFIG_DIGSY_REV5)
417 ft_delete_node(blob, "dallas,ds1339");
418#else
419 ft_delete_node(blob, "mc,rv3029c2");
420#endif
421#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
Heiko Schochere9ef3f42011-01-21 07:23:35 +0100422#ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
423 /* Update reg property in all nor flash nodes too */
424 fdt_fixup_nor_flash_size(blob);
425#endif
Heiko Schocher13f805e2011-01-13 08:25:00 +0100426 ft_adapt_flash_base(blob);
427#endif
Heiko Schocherb5ea4082011-04-03 20:10:20 +0000428 /* fix up the phy address */
429 do_fixup_by_path(blob, eth_path, "reg", &phy_addr, sizeof(int), 0);
Grzegorz Bernackiafc9d6d2009-03-17 10:06:40 +0100430}
431#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */