blob: 8eaf7cbde3071036a063f68758f2b508173b36ae [file] [log] [blame]
wdenkc1896002003-12-28 11:44:59 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2003
6 * Reinhard Meyer, EMK Elektronik GmbH, r.meyer@emk-elektronik.de
7 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkc1896002003-12-28 11:44:59 +00009 */
10
11#include <common.h>
12#include <mpc5xxx.h>
13#include <pci.h>
14
15/*****************************************************************************
16 * initialize SDRAM/DDRAM controller.
17 * TBD: get data from I2C EEPROM
18 *****************************************************************************/
Becky Bruce9973e3c2008-06-09 16:03:40 -050019phys_size_t initdram (int board_type)
wdenkc1896002003-12-28 11:44:59 +000020{
21 ulong dramsize = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020022#ifndef CONFIG_SYS_RAMBOOT
wdenkd4ca31c2004-01-02 14:00:00 +000023#if 0
wdenkc1896002003-12-28 11:44:59 +000024 ulong t;
25 ulong tap_del;
wdenkd4ca31c2004-01-02 14:00:00 +000026#endif
wdenkc1896002003-12-28 11:44:59 +000027
28 #define MODE_EN 0x80000000
29 #define SOFT_PRE 2
30 #define SOFT_REF 4
31
32 /* configure SDRAM start/end */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020033 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = (CONFIG_SYS_SDRAM_BASE & 0xFFF00000) | CONFIG_SYS_DRAM_RAM_SIZE;
wdenkc1896002003-12-28 11:44:59 +000034 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
35
36 /* setup config registers */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020037 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = CONFIG_SYS_DRAM_CONFIG1;
38 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = CONFIG_SYS_DRAM_CONFIG2;
wdenkc1896002003-12-28 11:44:59 +000039
40 /* unlock mode register */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN;
wdenkc1896002003-12-28 11:44:59 +000042 /* precharge all banks */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020043 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_PRE;
44#ifdef CONFIG_SYS_DRAM_DDR
wdenkc1896002003-12-28 11:44:59 +000045 /* set extended mode register */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020046 *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_EMODE;
wdenkc1896002003-12-28 11:44:59 +000047#endif
48 /* set mode register */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020049 *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_MODE | 0x0400;
wdenkc1896002003-12-28 11:44:59 +000050 /* precharge all banks */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020051 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_PRE;
wdenkc1896002003-12-28 11:44:59 +000052 /* auto refresh */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_REF;
wdenkc1896002003-12-28 11:44:59 +000054 /* set mode register */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055 *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_MODE;
wdenkc1896002003-12-28 11:44:59 +000056 /* normal operation */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020057 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL;
wdenkc1896002003-12-28 11:44:59 +000058 /* write default TAP delay */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020059 *(vu_long *)MPC5XXX_CDM_PORCFG = CONFIG_SYS_DRAM_TAP_DEL << 24;
wdenkc1896002003-12-28 11:44:59 +000060
61#if 0
wdenkd4ca31c2004-01-02 14:00:00 +000062 for (tap_del = 0; tap_del < 32; tap_del++)
63 {
wdenkc1896002003-12-28 11:44:59 +000064 *(vu_long *)MPC5XXX_CDM_PORCFG = tap_del << 24;
65
66 printf ("\nTAP Delay:%x Filling DRAM...", *(vu_long *)MPC5XXX_CDM_PORCFG);
67 for (t = 0; t < 0x04000000; t+=4)
68 *(vu_long *) t = t;
69 printf ("Checking DRAM...\n");
wdenkd4ca31c2004-01-02 14:00:00 +000070 for (t = 0; t < 0x04000000; t+=4)
71 {
wdenkc1896002003-12-28 11:44:59 +000072 ulong rval = *(vu_long *) t;
wdenkd4ca31c2004-01-02 14:00:00 +000073 if (rval != t)
74 {
wdenkc1896002003-12-28 11:44:59 +000075 printf ("mismatch at %x: ", t);
76 printf (" 1.read %x", rval);
77 printf (" 2.read %x", *(vu_long *) t);
78 printf (" 3.read %x", *(vu_long *) t);
79 break;
80 }
81 }
82 }
83#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020084#endif /* CONFIG_SYS_RAMBOOT */
wdenkc1896002003-12-28 11:44:59 +000085
86 dramsize = ((1 << (*(vu_long *)MPC5XXX_SDRAM_CS0CFG - 0x13)) << 20);
87
88 /* return total ram size */
89 return dramsize;
90}
91
92/*****************************************************************************
93 * print board identification
94 *****************************************************************************/
95int checkboard (void)
96{
97#if defined (CONFIG_EVAL5200)
98 puts ("Board: EMK TOP5200 on EVAL5200\n");
99#else
wdenk4d13cba2004-03-14 14:09:05 +0000100#if defined (CONFIG_LITE5200)
101 puts ("Board: LITE5200\n");
102#else
wdenkc1896002003-12-28 11:44:59 +0000103#if defined (CONFIG_MINI5200)
104 puts ("Board: EMK TOP5200 on MINI5200\n");
105#else
106 puts ("Board: EMK TOP5200\n");
107#endif
108#endif
wdenk4d13cba2004-03-14 14:09:05 +0000109#endif
wdenkc1896002003-12-28 11:44:59 +0000110 return 0;
111}
112
113/*****************************************************************************
114 * prepare for FLASH detection
115 *****************************************************************************/
116void flash_preinit(void)
117{
118 /*
119 * Now, when we are in RAM, enable flash write
120 * access for detection process.
121 * Note that CS_BOOT cannot be cleared when
122 * executing in flash.
123 */
124 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
125}
126
127/*****************************************************************************
128 * finalize FLASH setup
129 *****************************************************************************/
130void flash_afterinit(uint bank, ulong start, ulong size)
131{
132 if (bank == 0) { /* adjust mapping */
133 *(vu_long *)MPC5XXX_BOOTCS_START =
134 *(vu_long *)MPC5XXX_CS0_START = START_REG(start);
135 *(vu_long *)MPC5XXX_BOOTCS_STOP =
136 *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(start, size);
137 }
138}
139
140/*****************************************************************************
141 * otherinits after RAM is there and we are relocated to RAM
142 * note: though this is an int function, nobody cares for the result!
143 *****************************************************************************/
144int misc_init_r (void)
145{
wdenk4d13cba2004-03-14 14:09:05 +0000146#if !defined (CONFIG_LITE5200)
wdenkc1896002003-12-28 11:44:59 +0000147 /* read 'factory' part of EEPROM */
wdenk63e73c92004-02-23 22:22:28 +0000148 extern void read_factory_r (void);
149 read_factory_r ();
wdenk4d13cba2004-03-14 14:09:05 +0000150#endif
wdenkc1896002003-12-28 11:44:59 +0000151 return (0);
152}
153
154/*****************************************************************************
155 * initialize the PCI system
156 *****************************************************************************/
157#ifdef CONFIG_PCI
158static struct pci_controller hose;
159
160extern void pci_mpc5xxx_init(struct pci_controller *);
161
162void pci_init_board(void)
163{
164 pci_mpc5xxx_init(&hose);
165}
166#endif
wdenk4d13cba2004-03-14 14:09:05 +0000167
168/*****************************************************************************
wdenk498b8db2004-04-18 22:26:17 +0000169 * provide the IDE Reset Function
wdenk4d13cba2004-03-14 14:09:05 +0000170 *****************************************************************************/
Jon Loeliger77a31852007-07-10 10:39:10 -0500171#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
wdenk498b8db2004-04-18 22:26:17 +0000172
wdenk498b8db2004-04-18 22:26:17 +0000173void init_ide_reset (void)
174{
175 debug ("init_ide_reset\n");
176
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100177 /* Configure PSC1_4 as GPIO output for ATA reset */
wdenk498b8db2004-04-18 22:26:17 +0000178 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
179 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
180}
181
wdenk4d13cba2004-03-14 14:09:05 +0000182void ide_set_reset (int idereset)
183{
wdenk498b8db2004-04-18 22:26:17 +0000184 debug ("ide_reset(%d)\n", idereset);
185
wdenk4d13cba2004-03-14 14:09:05 +0000186 if (idereset) {
Bartlomiej Siekadae80f32006-11-01 01:38:16 +0100187 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
wdenk4d13cba2004-03-14 14:09:05 +0000188 } else {
Bartlomiej Siekadae80f32006-11-01 01:38:16 +0100189 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenk4d13cba2004-03-14 14:09:05 +0000190 }
wdenk4d13cba2004-03-14 14:09:05 +0000191}
Jon Loeliger77a31852007-07-10 10:39:10 -0500192#endif