wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 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 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <mpc5xxx.h> |
wdenk | 96e48cf | 2003-08-05 18:22:44 +0000 | [diff] [blame] | 26 | #include <pci.h> |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 27 | |
wdenk | d94f92c | 2003-08-28 09:41:22 +0000 | [diff] [blame] | 28 | #ifndef CFG_RAMBOOT |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 29 | static void sdram_start (int hi_addr) |
| 30 | { |
| 31 | long hi_addr_bit = hi_addr ? 0x01000000 : 0; |
| 32 | |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 33 | #ifdef CONFIG_MPC5200_DDR |
| 34 | /* unlock mode register */ |
| 35 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xf05f0f00 | hi_addr_bit; |
| 36 | /* precharge all banks */ |
| 37 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xf05f0f02 | hi_addr_bit; |
| 38 | /* set mode register: extended mode */ |
| 39 | *(vu_long *)MPC5XXX_SDRAM_MODE = 0x40090000; |
| 40 | /* set mode register: reset DLL */ |
| 41 | *(vu_long *)MPC5XXX_SDRAM_MODE = 0x058d0000; |
| 42 | /* precharge all banks */ |
| 43 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xf05f0f02 | hi_addr_bit; |
| 44 | /* auto refresh */ |
| 45 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xf05f0f04 | hi_addr_bit; |
| 46 | /* set mode register */ |
| 47 | *(vu_long *)MPC5XXX_SDRAM_MODE = 0x018d0000; |
| 48 | /* normal operation */ |
| 49 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0x705f0f00 | hi_addr_bit; |
| 50 | #else |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 51 | /* unlock mode register */ |
| 52 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0000 | hi_addr_bit; |
| 53 | /* precharge all banks */ |
| 54 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0002 | hi_addr_bit; |
| 55 | /* set mode register */ |
| 56 | #if defined(CONFIG_MPC5200) |
wdenk | f8d813e | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 57 | *(vu_long *)MPC5XXX_SDRAM_MODE = 0x00cd0000; |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 58 | #elif defined(CONFIG_MGT5100) |
| 59 | *(vu_long *)MPC5XXX_SDRAM_MODE = 0x008d0000; |
| 60 | #endif |
wdenk | f8d813e | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 61 | /* auto refresh */ |
| 62 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0004 | hi_addr_bit; |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 63 | /* auto refresh */ |
| 64 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0xd04f0004 | hi_addr_bit; |
| 65 | /* set mode register */ |
wdenk | f8d813e | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 66 | *(vu_long *)MPC5XXX_SDRAM_MODE = 0x00cd0000; |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 67 | /* normal operation */ |
| 68 | *(vu_long *)MPC5XXX_SDRAM_CTRL = 0x504f0000 | hi_addr_bit; |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 69 | #endif |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 70 | } |
wdenk | d94f92c | 2003-08-28 09:41:22 +0000 | [diff] [blame] | 71 | #endif |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 72 | |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 73 | long int initdram (int board_type) |
| 74 | { |
wdenk | d94f92c | 2003-08-28 09:41:22 +0000 | [diff] [blame] | 75 | ulong dramsize = 0; |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 76 | #ifdef CONFIG_MPC5200_DDR |
| 77 | ulong dramsize2 = 0; |
| 78 | #endif |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 79 | #ifndef CFG_RAMBOOT |
wdenk | d94f92c | 2003-08-28 09:41:22 +0000 | [diff] [blame] | 80 | ulong test1, test2; |
| 81 | |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 82 | /* configure SDRAM start/end */ |
| 83 | #if defined(CONFIG_MPC5200) |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 84 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */ |
| 85 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */ |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 86 | |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 87 | #ifdef CONFIG_MPC5200_DDR |
| 88 | /* setup config registers */ |
| 89 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = 0x73722930; |
| 90 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = 0x47770000; |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 91 | |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 92 | /* set tap delay to 0x10 */ |
| 93 | *(vu_long *)MPC5XXX_CDM_PORCFG = 0x10000000; |
| 94 | #else |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 95 | /* setup config registers */ |
wdenk | f8d813e | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 96 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = 0xd2322800; |
| 97 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = 0x8ad70000; |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 98 | #endif |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 99 | |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 100 | #elif defined(CONFIG_MGT5100) |
| 101 | *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000; |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 102 | *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */ |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 103 | *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */ |
| 104 | |
| 105 | /* setup config registers */ |
| 106 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = 0xc2222600; |
| 107 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = 0x88b70004; |
| 108 | |
| 109 | /* address select register */ |
| 110 | *(vu_long *)MPC5XXX_SDRAM_XLBSEL = 0x03000000; |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 111 | #endif |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 112 | sdram_start(0); |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 113 | test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000); |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 114 | sdram_start(1); |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 115 | test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000); |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 116 | if (test1 > test2) { |
| 117 | sdram_start(0); |
| 118 | dramsize = test1; |
| 119 | } else { |
| 120 | dramsize = test2; |
| 121 | } |
| 122 | #if defined(CONFIG_MPC5200) |
| 123 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = |
| 124 | (0x13 + __builtin_ffs(dramsize >> 20) - 1); |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 125 | #ifdef CONFIG_MPC5200_DDR |
| 126 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */ |
| 127 | sdram_start(0); |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 128 | test1 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000); |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 129 | sdram_start(1); |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 130 | test2 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000); |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 131 | if (test1 > test2) { |
| 132 | sdram_start(0); |
| 133 | dramsize2 = test1; |
| 134 | } else { |
| 135 | dramsize2 = test2; |
| 136 | } |
| 137 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = |
| 138 | dramsize + (0x13 + __builtin_ffs(dramsize2 >> 20) - 1); |
| 139 | #else |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 140 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */ |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 141 | #endif |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 142 | #elif defined(CONFIG_MGT5100) |
| 143 | *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15); |
| 144 | #endif |
| 145 | |
wdenk | 5cf9da4 | 2003-11-07 13:42:26 +0000 | [diff] [blame] | 146 | #else /* CFG_RAMBOOT */ |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 147 | #ifdef CONFIG_MGT5100 |
| 148 | *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */ |
wdenk | d94f92c | 2003-08-28 09:41:22 +0000 | [diff] [blame] | 149 | dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15); |
| 150 | #else |
| 151 | dramsize = ((1 << (*(vu_long *)MPC5XXX_SDRAM_CS0CFG - 0x13)) << 20); |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 152 | #ifdef CONFIG_MPC5200_DDR |
| 153 | dramsize2 = ((1 << (*(vu_long *)MPC5XXX_SDRAM_CS1CFG - 0x13)) << 20); |
| 154 | #endif |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 155 | #endif |
wdenk | d94f92c | 2003-08-28 09:41:22 +0000 | [diff] [blame] | 156 | #endif /* CFG_RAMBOOT */ |
wdenk | b2001f2 | 2003-12-20 22:45:10 +0000 | [diff] [blame] | 157 | |
| 158 | #ifdef CONFIG_MPC5200_DDR |
| 159 | dramsize += dramsize2; |
| 160 | #endif |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 161 | /* return total ram size */ |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 162 | return dramsize; |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | int checkboard (void) |
| 166 | { |
| 167 | #if defined(CONFIG_MPC5200) |
| 168 | puts ("Board: Motorola MPC5200 (IceCube)\n"); |
| 169 | #elif defined(CONFIG_MGT5100) |
| 170 | puts ("Board: Motorola MGT5100 (IceCube)\n"); |
| 171 | #endif |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | void flash_preinit(void) |
| 176 | { |
| 177 | /* |
| 178 | * Now, when we are in RAM, enable flash write |
| 179 | * access for detection process. |
| 180 | * Note that CS_BOOT cannot be cleared when |
| 181 | * executing in flash. |
| 182 | */ |
| 183 | #if defined(CONFIG_MGT5100) |
| 184 | *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */ |
| 185 | *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */ |
| 186 | #endif |
| 187 | *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */ |
| 188 | } |
wdenk | 96e48cf | 2003-08-05 18:22:44 +0000 | [diff] [blame] | 189 | |
wdenk | 7152b1d | 2003-09-05 23:19:14 +0000 | [diff] [blame] | 190 | void flash_afterinit(ulong size) |
| 191 | { |
| 192 | if (size == 0x800000) { /* adjust mapping */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 193 | *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START = |
wdenk | 7152b1d | 2003-09-05 23:19:14 +0000 | [diff] [blame] | 194 | START_REG(CFG_BOOTCS_START | size); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 195 | *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP = |
wdenk | 7152b1d | 2003-09-05 23:19:14 +0000 | [diff] [blame] | 196 | STOP_REG(CFG_BOOTCS_START | size, size); |
| 197 | } |
| 198 | } |
| 199 | |
wdenk | 96e48cf | 2003-08-05 18:22:44 +0000 | [diff] [blame] | 200 | #ifdef CONFIG_PCI |
| 201 | static struct pci_controller hose; |
| 202 | |
| 203 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 204 | |
| 205 | void pci_init_board(void) |
| 206 | { |
| 207 | pci_mpc5xxx_init(&hose); |
| 208 | } |
| 209 | #endif |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 210 | |
| 211 | #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) |
| 212 | |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 213 | #define GPIO_PSC1_4 0x01000000UL |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 214 | |
| 215 | void init_ide_reset (void) |
| 216 | { |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 217 | debug ("init_ide_reset\n"); |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame^] | 218 | |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 219 | /* Configure PSC1_4 as GPIO output for ATA reset */ |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 220 | *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4; |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 221 | *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4; |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void ide_set_reset (int idereset) |
| 225 | { |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 226 | debug ("ide_reset(%d)\n", idereset); |
| 227 | |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 228 | if (idereset) { |
| 229 | *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4; |
| 230 | } else { |
wdenk | 4d13cba | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 231 | *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4; |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */ |