wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 1 | /* |
| 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 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <mpc5xxx.h> |
| 29 | #include <pci.h> |
| 30 | |
| 31 | /***************************************************************************** |
| 32 | * initialize SDRAM/DDRAM controller. |
| 33 | * TBD: get data from I2C EEPROM |
| 34 | *****************************************************************************/ |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 35 | phys_size_t initdram (int board_type) |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 36 | { |
| 37 | ulong dramsize = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 38 | #ifndef CONFIG_SYS_RAMBOOT |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 39 | #if 0 |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 40 | ulong t; |
| 41 | ulong tap_del; |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 42 | #endif |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 43 | |
| 44 | #define MODE_EN 0x80000000 |
| 45 | #define SOFT_PRE 2 |
| 46 | #define SOFT_REF 4 |
| 47 | |
| 48 | /* configure SDRAM start/end */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = (CONFIG_SYS_SDRAM_BASE & 0xFFF00000) | CONFIG_SYS_DRAM_RAM_SIZE; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 50 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */ |
| 51 | |
| 52 | /* setup config registers */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = CONFIG_SYS_DRAM_CONFIG1; |
| 54 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = CONFIG_SYS_DRAM_CONFIG2; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 55 | |
| 56 | /* unlock mode register */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 57 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 58 | /* precharge all banks */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 59 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_PRE; |
| 60 | #ifdef CONFIG_SYS_DRAM_DDR |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 61 | /* set extended mode register */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 62 | *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_EMODE; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 63 | #endif |
| 64 | /* set mode register */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 65 | *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_MODE | 0x0400; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 66 | /* precharge all banks */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 67 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_PRE; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 68 | /* auto refresh */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 69 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_REF; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 70 | /* set mode register */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 71 | *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_MODE; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 72 | /* normal operation */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 74 | /* write default TAP delay */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 75 | *(vu_long *)MPC5XXX_CDM_PORCFG = CONFIG_SYS_DRAM_TAP_DEL << 24; |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 76 | |
| 77 | #if 0 |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 78 | for (tap_del = 0; tap_del < 32; tap_del++) |
| 79 | { |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 80 | *(vu_long *)MPC5XXX_CDM_PORCFG = tap_del << 24; |
| 81 | |
| 82 | printf ("\nTAP Delay:%x Filling DRAM...", *(vu_long *)MPC5XXX_CDM_PORCFG); |
| 83 | for (t = 0; t < 0x04000000; t+=4) |
| 84 | *(vu_long *) t = t; |
| 85 | printf ("Checking DRAM...\n"); |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 86 | for (t = 0; t < 0x04000000; t+=4) |
| 87 | { |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 88 | ulong rval = *(vu_long *) t; |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 89 | if (rval != t) |
| 90 | { |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 91 | printf ("mismatch at %x: ", t); |
| 92 | printf (" 1.read %x", rval); |
| 93 | printf (" 2.read %x", *(vu_long *) t); |
| 94 | printf (" 3.read %x", *(vu_long *) t); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 100 | #endif /* CONFIG_SYS_RAMBOOT */ |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 101 | |
| 102 | dramsize = ((1 << (*(vu_long *)MPC5XXX_SDRAM_CS0CFG - 0x13)) << 20); |
| 103 | |
| 104 | /* return total ram size */ |
| 105 | return dramsize; |
| 106 | } |
| 107 | |
| 108 | /***************************************************************************** |
| 109 | * print board identification |
| 110 | *****************************************************************************/ |
| 111 | int checkboard (void) |
| 112 | { |
| 113 | #if defined (CONFIG_EVAL5200) |
| 114 | puts ("Board: EMK TOP5200 on EVAL5200\n"); |
| 115 | #else |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 116 | #if defined (CONFIG_LITE5200) |
| 117 | puts ("Board: LITE5200\n"); |
| 118 | #else |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 119 | #if defined (CONFIG_MINI5200) |
| 120 | puts ("Board: EMK TOP5200 on MINI5200\n"); |
| 121 | #else |
| 122 | puts ("Board: EMK TOP5200\n"); |
| 123 | #endif |
| 124 | #endif |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 125 | #endif |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /***************************************************************************** |
| 130 | * prepare for FLASH detection |
| 131 | *****************************************************************************/ |
| 132 | void flash_preinit(void) |
| 133 | { |
| 134 | /* |
| 135 | * Now, when we are in RAM, enable flash write |
| 136 | * access for detection process. |
| 137 | * Note that CS_BOOT cannot be cleared when |
| 138 | * executing in flash. |
| 139 | */ |
| 140 | *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */ |
| 141 | } |
| 142 | |
| 143 | /***************************************************************************** |
| 144 | * finalize FLASH setup |
| 145 | *****************************************************************************/ |
| 146 | void flash_afterinit(uint bank, ulong start, ulong size) |
| 147 | { |
| 148 | if (bank == 0) { /* adjust mapping */ |
| 149 | *(vu_long *)MPC5XXX_BOOTCS_START = |
| 150 | *(vu_long *)MPC5XXX_CS0_START = START_REG(start); |
| 151 | *(vu_long *)MPC5XXX_BOOTCS_STOP = |
| 152 | *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(start, size); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /***************************************************************************** |
| 157 | * otherinits after RAM is there and we are relocated to RAM |
| 158 | * note: though this is an int function, nobody cares for the result! |
| 159 | *****************************************************************************/ |
| 160 | int misc_init_r (void) |
| 161 | { |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 162 | #if !defined (CONFIG_LITE5200) |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 163 | /* read 'factory' part of EEPROM */ |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 164 | extern void read_factory_r (void); |
| 165 | read_factory_r (); |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 166 | #endif |
wdenk | c189600 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 167 | return (0); |
| 168 | } |
| 169 | |
| 170 | /***************************************************************************** |
| 171 | * initialize the PCI system |
| 172 | *****************************************************************************/ |
| 173 | #ifdef CONFIG_PCI |
| 174 | static struct pci_controller hose; |
| 175 | |
| 176 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 177 | |
| 178 | void pci_init_board(void) |
| 179 | { |
| 180 | pci_mpc5xxx_init(&hose); |
| 181 | } |
| 182 | #endif |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 183 | |
| 184 | /***************************************************************************** |
wdenk | 498b8db | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 185 | * provide the IDE Reset Function |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 186 | *****************************************************************************/ |
Jon Loeliger | 77a3185 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 187 | #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET) |
wdenk | 498b8db | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 188 | |
wdenk | 498b8db | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 189 | void init_ide_reset (void) |
| 190 | { |
| 191 | debug ("init_ide_reset\n"); |
| 192 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 193 | /* Configure PSC1_4 as GPIO output for ATA reset */ |
wdenk | 498b8db | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 194 | *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4; |
| 195 | *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4; |
| 196 | } |
| 197 | |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 198 | void ide_set_reset (int idereset) |
| 199 | { |
wdenk | 498b8db | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 200 | debug ("ide_reset(%d)\n", idereset); |
| 201 | |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 202 | if (idereset) { |
Bartlomiej Sieka | dae80f3 | 2006-11-01 01:38:16 +0100 | [diff] [blame] | 203 | *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4; |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 204 | } else { |
Bartlomiej Sieka | dae80f3 | 2006-11-01 01:38:16 +0100 | [diff] [blame] | 205 | *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4; |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 206 | } |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 207 | } |
Jon Loeliger | 77a3185 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 208 | #endif |