3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
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
14 * Grzegorz Bernacki, Semihalf, gjb@semihalf.com
16 * See file CREDITS for list of people who contributed to this
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.
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.
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,
39 #include <asm/processor.h>
42 #if defined(CONFIG_DIGSY_REV5)
43 #include "is45s16800a2.h"
44 #include <mtd/cfi_flash.h>
46 #include "is42s16800a-7t.h"
50 DECLARE_GLOBAL_DATA_PTR;
52 extern int usb_cpu_init(void);
54 #if defined(CONFIG_DIGSY_REV5)
56 * The M29W128GH needs a specail reset command function,
57 * details see the doc/README.cfi file
59 void flash_cmd_reset(flash_info_t *info)
61 flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
65 #ifndef CONFIG_SYS_RAMBOOT
66 static void sdram_start(int hi_addr)
68 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
69 long control = SDRAM_CONTROL | hi_addr_bit;
71 /* unlock mode register */
72 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
74 /* precharge all banks */
75 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
78 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
80 /* set mode register */
81 out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
83 /* normal operation */
84 out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
89 * ATTENTION: Although partially referenced initdram does NOT make real use
90 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if
91 * CONFIG_SYS_SDRAM_BASE is something else than 0x00000000.
94 phys_size_t initdram(int board_type)
99 #ifndef CONFIG_SYS_RAMBOOT
102 /* setup SDRAM chip selects */
103 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001C); /* 512MB at 0x0 */
104 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000); /* disabled */
106 /* setup config registers */
107 out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
108 out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
110 /* find RAM size using SDRAM CS0 only */
112 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
114 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
122 /* memory smaller than 1MB is impossible */
123 if (dramsize < (1 << 20))
126 /* set SDRAM CS0 size according to the amount of RAM found */
128 out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
129 (0x13 + __builtin_ffs(dramsize >> 20) - 1));
131 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */
134 /* let SDRAM CS1 start right after CS0 */
135 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize + 0x0000001C);
137 /* find RAM size using SDRAM CS1 only */
138 test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
142 /* memory smaller than 1MB is impossible */
143 if (dramsize2 < (1 << 20))
146 /* set SDRAM CS1 size according to the amount of RAM found */
148 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, (dramsize |
149 (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
151 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize); /* disabled */
154 #else /* CONFIG_SYS_RAMBOOT */
156 /* retrieve size of memory connected to SDRAM CS0 */
157 dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
158 if (dramsize >= 0x13)
159 dramsize = (1 << (dramsize - 0x13)) << 20;
163 /* retrieve size of memory connected to SDRAM CS1 */
164 dramsize2 = in_be32((void *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
165 if (dramsize2 >= 0x13)
166 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
170 #endif /* CONFIG_SYS_RAMBOOT */
173 * On MPC5200B we need to set the special configuration delay in the
174 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
175 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
177 * "The SDelay should be written to a value of 0x00000004. It is
178 * required to account for changes caused by normal wafer processing
183 if ((SVR_MJREV(svr) >= 2) &&
184 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
185 out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
187 return dramsize + dramsize2;
192 char *s = getenv("serial#");
194 puts ("Board: InterControl digsyMTC");
195 #if defined(CONFIG_DIGSY_REV5)
207 int board_early_init_r(void)
209 #ifdef CONFIG_MPC52XX_SPI
210 struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt*)MPC5XXX_GPT;
213 * Now, when we are in RAM, enable flash write access for detection
214 * process. Note that CS_BOOT cannot be cleared when executing in
217 /* disable CS_BOOT */
218 clrbits_be32((void *)MPC5XXX_ADDECR, (1 << 25));
220 setbits_be32((void *)MPC5XXX_ADDECR, (1 << 17));
222 setbits_be32((void *)MPC5XXX_ADDECR, (1 << 16));
224 #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
225 /* Low level USB init, required for proper kernel operation */
228 #ifdef CONFIG_MPC52XX_SPI
229 /* GPT 6 Output Enable */
230 out_be32(&gpt[6].emsr, 0x00000034);
231 /* GPT 7 Output Enable */
232 out_be32(&gpt[7].emsr, 0x00000034);
238 void board_get_enetaddr (uchar * enet)
241 ushort addr_of_eth_addr = 0;
243 ushort len_sys_cfg = 0;
245 /* check identification word */
246 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_IDENT, (uchar *)&read, 2);
247 if (read != EEPROM_IDENT)
250 /* calculate offset of config area */
251 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYS, (uchar *)&len_sys, 2);
252 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYSCFG,
253 (uchar *)&len_sys_cfg, 2);
254 addr_of_eth_addr = (len_sys + len_sys_cfg + EEPROM_ADDR_ETHADDR) << 1;
255 if (addr_of_eth_addr >= EEPROM_LEN)
258 eeprom_read(EEPROM_ADDR, addr_of_eth_addr, enet, 6);
261 int misc_init_r(void)
265 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
266 board_get_enetaddr(enetaddr);
267 eth_setenv_enetaddr("ethaddr", enetaddr);
274 static struct pci_controller hose;
276 extern void pci_mpc5xxx_init(struct pci_controller *);
278 void pci_init_board(void)
280 pci_mpc5xxx_init(&hose);
284 #ifdef CONFIG_CMD_IDE
286 #ifdef CONFIG_IDE_RESET
288 void init_ide_reset(void)
290 debug ("init_ide_reset\n");
292 /* set gpio output value to 1 */
293 setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
294 /* open drain output */
295 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
296 /* direction output */
297 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
299 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
303 void ide_set_reset(int idereset)
305 debug ("ide_reset(%d)\n", idereset);
307 /* set gpio output value to 0 */
308 clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
309 /* open drain output */
310 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
311 /* direction output */
312 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
314 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
318 /* set gpio output value to 1 */
319 setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
320 /* open drain output */
321 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
322 /* direction output */
323 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
325 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
327 #endif /* CONFIG_IDE_RESET */
328 #endif /* CONFIG_CMD_IDE */
330 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
331 static void ft_delete_node(void *fdt, const char *compat)
336 off = fdt_node_offset_by_compatible(fdt, -1, compat);
338 printf("Could not find %s node.\n", compat);
342 ret = fdt_del_node(fdt, off);
344 printf("Could not delete %s node.\n", compat);
346 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
347 static void ft_adapt_flash_base(void *blob)
349 flash_info_t *dev = &flash_info[0];
351 struct fdt_property *prop;
355 off = fdt_node_offset_by_compatible(blob, -1, "fsl,mpc5200b-lpb");
357 printf("Could not find fsl,mpc5200b-lpb node.\n");
361 /* found compatible property */
362 prop = fdt_get_property_w(blob, off, "ranges", &len);
364 reg = reg2 = (u32 *)&prop->data[0];
366 reg[2] = dev->start[0];
368 fdt_setprop(blob, off, "ranges", reg2, len);
370 printf("Could not find ranges\n");
373 extern ulong flash_get_size (phys_addr_t base, int banknum);
375 /* Update the Flash Baseaddr settings */
376 int update_flash_size (int flash_size)
378 volatile struct mpc5xxx_mmap_ctl *mm =
379 (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
383 unsigned long base = 0x0;
384 u32 *cs_reg = (u32 *)&mm->cs0_start;
386 for (i = 0; i < 2; i++) {
387 dev = &flash_info[i];
390 /* calculate new base addr for this chipselect */
392 out_be32(cs_reg, START_REG(base));
394 out_be32(cs_reg, STOP_REG(base, dev->size));
396 /* recalculate the sectoraddr in the cfi driver */
397 size += flash_get_size(base, i);
400 gd->bd->bi_flashstart = base;
403 #endif /* defined(CONFIG_SYS_UPDATE_FLASH_SIZE) */
405 void ft_board_setup(void *blob, bd_t *bd)
407 ft_cpu_setup(blob, bd);
409 * There are 2 RTC nodes in the DTS, so remove
410 * the unneeded node here.
412 #if defined(CONFIG_DIGSY_REV5)
413 ft_delete_node(blob, "dallas,ds1339");
415 ft_delete_node(blob, "mc,rv3029c2");
417 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
418 ft_adapt_flash_base(blob);
421 #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */