Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 1 | /* |
Heiko Schocher | 0809ea2 | 2008-10-15 09:34:05 +0200 | [diff] [blame] | 2 | * (C) Copyright 2007 - 2008 |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 3 | * Heiko Schocher, DENX Software Engineering, hs@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 <mpc8260.h> |
| 26 | #include <ioports.h> |
Heiko Schocher | 9661bf9 | 2008-10-15 09:36:03 +0200 | [diff] [blame] | 27 | #include <malloc.h> |
Heiko Schocher | 9e29919 | 2008-10-17 12:15:55 +0200 | [diff] [blame] | 28 | #include <asm/io.h> |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 29 | |
| 30 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
| 31 | #include <libfdt.h> |
| 32 | #endif |
| 33 | |
Heiko Schocher | 9661bf9 | 2008-10-15 09:36:03 +0200 | [diff] [blame] | 34 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
| 35 | #include <i2c.h> |
| 36 | #endif |
| 37 | |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 38 | #include "../common/common.h" |
| 39 | |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 40 | /* |
| 41 | * I/O Port configuration table |
| 42 | * |
| 43 | * if conf is 1, then that port pin will be configured at boot time |
| 44 | * according to the five values podr/pdir/ppar/psor/pdat for that entry |
| 45 | */ |
| 46 | const iop_conf_t iop_conf_tab[4][32] = { |
| 47 | |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 48 | /* Port A */ |
| 49 | { /* conf ppar psor pdir podr pdat */ |
| 50 | { 0, 0, 0, 0, 0, 0 }, /* PA31 */ |
| 51 | { 0, 0, 0, 0, 0, 0 }, /* PA30 */ |
| 52 | { 0, 0, 0, 0, 0, 0 }, /* PA29 */ |
| 53 | { 0, 0, 0, 0, 0, 0 }, /* PA28 */ |
| 54 | { 0, 0, 0, 0, 0, 0 }, /* PA27 */ |
| 55 | { 0, 0, 0, 0, 0, 0 }, /* PA26 */ |
| 56 | { 0, 0, 0, 0, 0, 0 }, /* PA25 */ |
| 57 | { 0, 0, 0, 0, 0, 0 }, /* PA24 */ |
| 58 | { 0, 0, 0, 0, 0, 0 }, /* PA23 */ |
| 59 | { 0, 0, 0, 0, 0, 0 }, /* PA22 */ |
| 60 | { 0, 0, 0, 0, 0, 0 }, /* PA21 */ |
| 61 | { 0, 0, 0, 0, 0, 0 }, /* PA20 */ |
| 62 | { 0, 0, 0, 0, 0, 0 }, /* PA19 */ |
| 63 | { 0, 0, 0, 0, 0, 0 }, /* PA18 */ |
| 64 | { 0, 0, 0, 0, 0, 0 }, /* PA17 */ |
| 65 | { 0, 0, 0, 0, 0, 0 }, /* PA16 */ |
| 66 | { 0, 0, 0, 0, 0, 0 }, /* PA15 */ |
| 67 | { 0, 0, 0, 0, 0, 0 }, /* PA14 */ |
| 68 | { 0, 0, 0, 0, 0, 0 }, /* PA13 */ |
| 69 | { 0, 0, 0, 0, 0, 0 }, /* PA12 */ |
| 70 | { 0, 0, 0, 0, 0, 0 }, /* PA11 */ |
| 71 | { 0, 0, 0, 0, 0, 0 }, /* PA10 */ |
| 72 | { 1, 1, 0, 1, 0, 0 }, /* PA9 SMC2 TxD */ |
| 73 | { 1, 1, 0, 0, 0, 0 }, /* PA8 SMC2 RxD */ |
| 74 | { 0, 0, 0, 0, 0, 0 }, /* PA7 */ |
| 75 | { 0, 0, 0, 0, 0, 0 }, /* PA6 */ |
| 76 | { 0, 0, 0, 0, 0, 0 }, /* PA5 */ |
| 77 | { 0, 0, 0, 0, 0, 0 }, /* PA4 */ |
| 78 | { 0, 0, 0, 0, 0, 0 }, /* PA3 */ |
| 79 | { 0, 0, 0, 0, 0, 0 }, /* PA2 */ |
| 80 | { 0, 0, 0, 0, 0, 0 }, /* PA1 */ |
| 81 | { 0, 0, 0, 0, 0, 0 } /* PA0 */ |
| 82 | }, |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 83 | |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 84 | /* Port B */ |
| 85 | { /* conf ppar psor pdir podr pdat */ |
| 86 | { 0, 0, 0, 0, 0, 0 }, /* PB31 */ |
| 87 | { 0, 0, 0, 0, 0, 0 }, /* PB30 */ |
| 88 | { 0, 0, 0, 0, 0, 0 }, /* PB29 */ |
| 89 | { 0, 0, 0, 0, 0, 0 }, /* PB28 */ |
| 90 | { 0, 0, 0, 0, 0, 0 }, /* PB27 */ |
| 91 | { 0, 0, 0, 0, 0, 0 }, /* PB26 */ |
| 92 | { 0, 0, 0, 0, 0, 0 }, /* PB25 */ |
| 93 | { 0, 0, 0, 0, 0, 0 }, /* PB24 */ |
| 94 | { 0, 0, 0, 0, 0, 0 }, /* PB23 */ |
| 95 | { 0, 0, 0, 0, 0, 0 }, /* PB22 */ |
| 96 | { 0, 0, 0, 0, 0, 0 }, /* PB21 */ |
| 97 | { 0, 0, 0, 0, 0, 0 }, /* PB20 */ |
| 98 | { 0, 0, 0, 0, 0, 0 }, /* PB19 */ |
| 99 | { 0, 0, 0, 0, 0, 0 }, /* PB18 */ |
| 100 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 101 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 102 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 103 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 104 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 105 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 106 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 107 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 108 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 109 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 110 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 111 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 112 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 113 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 114 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 115 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 116 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 117 | { 0, 0, 0, 0, 0, 0 } /* non-existent */ |
| 118 | }, |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 119 | |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 120 | /* Port C */ |
| 121 | { /* conf ppar psor pdir podr pdat */ |
| 122 | { 0, 0, 0, 0, 0, 0 }, /* PC31 */ |
| 123 | { 0, 0, 0, 0, 0, 0 }, /* PC30 */ |
| 124 | { 0, 0, 0, 0, 0, 0 }, /* PC29 */ |
| 125 | { 0, 0, 0, 0, 0, 0 }, /* PC28 */ |
| 126 | { 0, 0, 0, 0, 0, 0 }, /* PC27 */ |
| 127 | { 0, 0, 0, 0, 0, 0 }, /* PC26 */ |
| 128 | { 1, 1, 0, 0, 0, 0 }, /* PC25 RxClk */ |
| 129 | { 1, 1, 0, 0, 0, 0 }, /* PC24 TxClk */ |
| 130 | { 0, 0, 0, 0, 0, 0 }, /* PC23 */ |
| 131 | { 0, 0, 0, 0, 0, 0 }, /* PC22 */ |
| 132 | { 0, 0, 0, 0, 0, 0 }, /* PC21 */ |
| 133 | { 0, 0, 0, 0, 0, 0 }, /* PC20 */ |
| 134 | { 0, 0, 0, 0, 0, 0 }, /* PC19 */ |
| 135 | { 0, 0, 0, 0, 0, 0 }, /* PC18 */ |
| 136 | { 0, 0, 0, 0, 0, 0 }, /* PC17 */ |
| 137 | { 0, 0, 0, 0, 0, 0 }, /* PC16 */ |
| 138 | { 0, 0, 0, 0, 0, 0 }, /* PC15 */ |
| 139 | { 0, 0, 0, 0, 0, 0 }, /* PC14 */ |
| 140 | { 0, 0, 0, 0, 0, 0 }, /* PC13 */ |
| 141 | { 0, 0, 0, 0, 0, 0 }, /* PC12 */ |
| 142 | { 0, 0, 0, 0, 0, 0 }, /* PC11 */ |
| 143 | { 0, 0, 0, 0, 0, 0 }, /* PC10 */ |
| 144 | { 1, 1, 0, 0, 0, 0 }, /* PC9 SCC4: CTS */ |
| 145 | { 1, 1, 0, 0, 0, 0 }, /* PC8 SCC4: CD */ |
| 146 | { 0, 0, 0, 0, 0, 0 }, /* PC7 */ |
| 147 | { 0, 0, 0, 0, 0, 0 }, /* PC6 */ |
| 148 | { 0, 0, 0, 0, 0, 0 }, /* PC5 */ |
| 149 | { 0, 0, 0, 0, 0, 0 }, /* PC4 */ |
| 150 | { 0, 0, 0, 0, 0, 0 }, /* PC3 */ |
| 151 | { 0, 0, 0, 0, 0, 0 }, /* PC2 */ |
| 152 | { 0, 0, 0, 0, 0, 0 }, /* PC1 */ |
| 153 | { 0, 0, 0, 0, 0, 0 }, /* PC0 */ |
| 154 | }, |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 155 | |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 156 | /* Port D */ |
| 157 | { /* conf ppar psor pdir podr pdat */ |
| 158 | { 0, 0, 0, 0, 0, 0 }, /* PD31 */ |
| 159 | { 0, 0, 0, 0, 0, 0 }, /* PD30 */ |
| 160 | { 0, 0, 0, 0, 0, 0 }, /* PD29 */ |
| 161 | { 0, 0, 0, 0, 0, 0 }, /* PD28 */ |
| 162 | { 0, 0, 0, 0, 0, 0 }, /* PD27 */ |
| 163 | { 0, 0, 0, 0, 0, 0 }, /* PD26 */ |
| 164 | { 0, 0, 0, 0, 0, 0 }, /* PD25 */ |
| 165 | { 0, 0, 0, 0, 0, 0 }, /* PD24 */ |
| 166 | { 0, 0, 0, 0, 0, 0 }, /* PD23 */ |
| 167 | { 1, 1, 0, 0, 0, 0 }, /* PD22 SCC4: RXD */ |
| 168 | { 1, 1, 0, 1, 0, 0 }, /* PD21 SCC4: TXD */ |
| 169 | { 1, 1, 0, 1, 0, 0 }, /* PD20 SCC4: RTS */ |
| 170 | { 0, 0, 0, 0, 0, 0 }, /* PD19 */ |
| 171 | { 0, 0, 0, 0, 0, 0 }, /* PD18 */ |
| 172 | { 0, 0, 0, 0, 0, 0 }, /* PD17 */ |
| 173 | { 0, 0, 0, 0, 0, 0 }, /* PD16 */ |
Heiko Schocher | 9661bf9 | 2008-10-15 09:36:03 +0200 | [diff] [blame] | 174 | #if defined(CONFIG_HARD_I2C) |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 175 | { 1, 1, 1, 0, 1, 0 }, /* PD15 I2C SDA */ |
| 176 | { 1, 1, 1, 0, 1, 0 }, /* PD14 I2C SCL */ |
Heiko Schocher | 9661bf9 | 2008-10-15 09:36:03 +0200 | [diff] [blame] | 177 | #else |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 178 | { 1, 0, 0, 0, 1, 1 }, /* PD15 */ |
| 179 | { 1, 0, 0, 1, 1, 1 }, /* PD14 */ |
Heiko Schocher | 9661bf9 | 2008-10-15 09:36:03 +0200 | [diff] [blame] | 180 | #endif |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 181 | { 0, 0, 0, 0, 0, 0 }, /* PD13 */ |
| 182 | { 0, 0, 0, 0, 0, 0 }, /* PD12 */ |
| 183 | { 0, 0, 0, 0, 0, 0 }, /* PD11 */ |
| 184 | { 0, 0, 0, 0, 0, 0 }, /* PD10 */ |
| 185 | { 0, 0, 0, 0, 0, 0 }, /* PD9 */ |
| 186 | { 0, 0, 0, 0, 0, 0 }, /* PD8 */ |
| 187 | { 0, 0, 0, 0, 0, 0 }, /* PD7 */ |
| 188 | { 0, 0, 0, 0, 0, 0 }, /* PD6 */ |
| 189 | { 0, 0, 0, 0, 0, 0 }, /* PD5 */ |
| 190 | { 0, 0, 0, 0, 0, 0 }, /* PD4 */ |
| 191 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 192 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 193 | { 0, 0, 0, 0, 0, 0 }, /* non-existent */ |
| 194 | { 0, 0, 0, 0, 0, 0 } /* non-existent */ |
| 195 | } |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 196 | }; |
| 197 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 198 | /* |
| 199 | * Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 200 | * |
| 201 | * This routine performs standard 8260 initialization sequence |
| 202 | * and calculates the available memory size. It may be called |
| 203 | * several times to try different SDRAM configurations on both |
| 204 | * 60x and local buses. |
| 205 | */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 206 | static long int try_init(memctl8260_t *memctl, ulong sdmr, |
| 207 | ulong orx, uchar *base) |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 208 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 209 | uchar c = 0xff; |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 210 | ulong maxsize, size; |
| 211 | int i; |
| 212 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 213 | /* |
| 214 | * We must be able to test a location outsize the maximum legal size |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 215 | * to find out THAT we are outside; but this address still has to be |
| 216 | * mapped by the controller. That means, that the initial mapping has |
| 217 | * to be (at least) twice as large as the maximum expected size. |
| 218 | */ |
| 219 | maxsize = (1 + (~orx | 0x7fff))/* / 2*/; |
| 220 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 221 | out_be32(&memctl->memc_or1, orx); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 222 | |
| 223 | /* |
| 224 | * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35): |
| 225 | * |
| 226 | * "At system reset, initialization software must set up the |
| 227 | * programmable parameters in the memory controller banks registers |
| 228 | * (ORx, BRx, P/LSDMR). After all memory parameters are configured, |
| 229 | * system software should execute the following initialization sequence |
| 230 | * for each SDRAM device. |
| 231 | * |
| 232 | * 1. Issue a PRECHARGE-ALL-BANKS command |
| 233 | * 2. Issue eight CBR REFRESH commands |
| 234 | * 3. Issue a MODE-SET command to initialize the mode register |
| 235 | * |
| 236 | * The initial commands are executed by setting P/LSDMR[OP] and |
| 237 | * accessing the SDRAM with a single-byte transaction." |
| 238 | * |
| 239 | * The appropriate BRx/ORx registers have already been set when we |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 240 | * get here. The SDRAM can be accessed at the address |
| 241 | * CONFIG_SYS_SDRAM_BASE. |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 242 | */ |
| 243 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 244 | out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_PREA); |
| 245 | out_8(base, c); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 246 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 247 | out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_CBRR); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 248 | for (i = 0; i < 8; i++) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 249 | out_8(base, c); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 250 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 251 | out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_MRW); |
| 252 | /* setting MR on address lines */ |
| 253 | out_8((uchar *)(base + CONFIG_SYS_MRS_OFFS), c); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 254 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 255 | out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_NORM | PSDMR_RFEN); |
| 256 | out_8(base, c); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 257 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 258 | size = get_ram_size((long *)base, maxsize); |
| 259 | out_be32(&memctl->memc_or1, orx | ~(size - 1)); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 260 | |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 261 | return size; |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 264 | phys_size_t initdram(int board_type) |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 265 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 266 | immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
| 267 | memctl8260_t *memctl = &immap->im_memctl; |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 268 | |
| 269 | long psize; |
| 270 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 271 | out_8(&memctl->memc_psrt, CONFIG_SYS_PSRT); |
| 272 | out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 273 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 274 | #ifndef CONFIG_SYS_RAMBOOT |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 275 | /* 60x SDRAM setup: |
| 276 | */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 277 | psize = try_init(memctl, CONFIG_SYS_PSDMR, CONFIG_SYS_OR1, |
| 278 | (uchar *) CONFIG_SYS_SDRAM_BASE); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 279 | #endif /* CONFIG_SYS_RAMBOOT */ |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 280 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 281 | icache_enable(); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 282 | |
Holger Brunck | 2220e6c | 2011-04-08 02:47:25 +0000 | [diff] [blame] | 283 | return psize; |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | int checkboard(void) |
| 287 | { |
Heiko Schocher | af895e4 | 2011-02-22 08:58:19 +0100 | [diff] [blame] | 288 | #if defined(CONFIG_MGCOGE) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 289 | puts("Board: Keymile mgcoge"); |
Heiko Schocher | af895e4 | 2011-02-22 08:58:19 +0100 | [diff] [blame] | 290 | #else |
Holger Brunck | 489337f | 2011-05-02 22:56:55 +0000 | [diff] [blame] | 291 | puts("Board: Keymile mgcoge3ne"); |
Heiko Schocher | af895e4 | 2011-02-22 08:58:19 +0100 | [diff] [blame] | 292 | #endif |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 293 | if (ethernet_present()) |
| 294 | puts(" with PIGGY."); |
| 295 | puts("\n"); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 296 | return 0; |
| 297 | } |
| 298 | |
Andreas Huber | 91a3c14 | 2011-01-25 11:26:15 +0100 | [diff] [blame] | 299 | int last_stage_init(void) |
| 300 | { |
Huber, Andreas | f30c62b | 2011-05-02 22:56:54 +0000 | [diff] [blame] | 301 | struct bfticu_iomap *base = |
| 302 | (struct bfticu_iomap *)CONFIG_SYS_FPGA_BASE; |
Andreas Huber | 91a3c14 | 2011-01-25 11:26:15 +0100 | [diff] [blame] | 303 | u8 dip_switch; |
Huber, Andreas | f30c62b | 2011-05-02 22:56:54 +0000 | [diff] [blame] | 304 | |
| 305 | dip_switch = in_8(&base->mswitch); |
| 306 | dip_switch &= BFTICU_DIPSWITCH_MASK; |
Andreas Huber | 91a3c14 | 2011-01-25 11:26:15 +0100 | [diff] [blame] | 307 | /* dip switch 'full reset' or 'db erase' */ |
| 308 | if (dip_switch & 0x1 || dip_switch & 0x2) { |
| 309 | /* start bootloader */ |
| 310 | puts("DIP: Enabled\n"); |
| 311 | setenv("actual_bank", "0"); |
| 312 | } |
Heiko Schocher | f1fef1d | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 313 | set_km_env(); |
Andreas Huber | 91a3c14 | 2011-01-25 11:26:15 +0100 | [diff] [blame] | 314 | return 0; |
| 315 | } |
| 316 | |
Holger Brunck | 489337f | 2011-05-02 22:56:55 +0000 | [diff] [blame] | 317 | #ifdef CONFIG_MGCOGE3NE |
Holger Brunck | 1adfd9d | 2011-06-05 22:22:20 +0000 | [diff] [blame] | 318 | static void set_pin(int state, unsigned long mask); |
| 319 | |
Holger Brunck | 489337f | 2011-05-02 22:56:55 +0000 | [diff] [blame] | 320 | /* |
| 321 | * For mgcoge3ne boards, the mgcoge3un control is controlled from |
| 322 | * a GPIO line on the PPC CPU. If bobcatreset is set the line |
| 323 | * will toggle once what forces the mgocge3un part to restart |
| 324 | * immediately. |
| 325 | */ |
| 326 | void handle_mgcoge3un_reset(void) |
| 327 | { |
| 328 | char *bobcatreset = getenv("bobcatreset"); |
| 329 | if (bobcatreset) { |
| 330 | if (strcmp(bobcatreset, "true") == 0) { |
| 331 | puts("Forcing bobcat reset\n"); |
| 332 | set_pin(0, 0x00000004); /* clear PD29 to reset arm */ |
| 333 | udelay(1000); |
| 334 | set_pin(1, 0x00000004); |
| 335 | } else |
| 336 | set_pin(1, 0x00000004); /* set PD29 to not reset arm */ |
| 337 | } |
| 338 | } |
| 339 | #endif |
| 340 | |
Heiko Schocher | e492c90 | 2008-03-07 08:13:41 +0100 | [diff] [blame] | 341 | /* |
| 342 | * Early board initalization. |
| 343 | */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 344 | int board_early_init_r(void) |
Heiko Schocher | e492c90 | 2008-03-07 08:13:41 +0100 | [diff] [blame] | 345 | { |
Heiko Schocher | 8ed7434 | 2011-03-08 10:47:39 +0100 | [diff] [blame] | 346 | struct km_bec_fpga *base = |
| 347 | (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 348 | |
Heiko Schocher | e492c90 | 2008-03-07 08:13:41 +0100 | [diff] [blame] | 349 | /* setup the UPIOx */ |
Heiko Schocher | 4897ee3 | 2010-01-07 08:55:50 +0100 | [diff] [blame] | 350 | /* General Unit Reset disabled, Flash Bank enabled, UnitLed on */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 351 | out_8(&base->oprth, (WRG_RESET | H_OPORTS_14 | WRG_LED)); |
Heiko Schocher | 4897ee3 | 2010-01-07 08:55:50 +0100 | [diff] [blame] | 352 | /* SCC4 enable, halfduplex, FCC1 powerdown */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 353 | out_8(&base->oprtl, (H_OPORTS_SCC4_ENA | H_OPORTS_SCC4_FD_ENA | |
| 354 | H_OPORTS_FCC1_PW_DWN)); |
| 355 | |
Holger Brunck | 489337f | 2011-05-02 22:56:55 +0000 | [diff] [blame] | 356 | #ifdef CONFIG_MGCOGE3NE |
| 357 | handle_mgcoge3un_reset(); |
| 358 | #endif |
Heiko Schocher | e492c90 | 2008-03-07 08:13:41 +0100 | [diff] [blame] | 359 | return 0; |
| 360 | } |
| 361 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 362 | int hush_init_var(void) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 363 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 364 | ivm_read_eeprom(); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 365 | return 0; |
| 366 | } |
| 367 | |
Holger Brunck | 1adfd9d | 2011-06-05 22:22:20 +0000 | [diff] [blame] | 368 | #define SDA_MASK 0x00010000 |
| 369 | #define SCL_MASK 0x00020000 |
| 370 | |
| 371 | static void set_pin(int state, unsigned long mask) |
| 372 | { |
| 373 | ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3); |
| 374 | |
| 375 | if (state) |
| 376 | setbits_be32(&iop->pdat, mask); |
| 377 | else |
| 378 | clrbits_be32(&iop->pdat, mask); |
| 379 | |
| 380 | setbits_be32(&iop->pdir, mask); |
| 381 | } |
| 382 | |
| 383 | static int get_pin(unsigned long mask) |
| 384 | { |
| 385 | ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3); |
| 386 | |
| 387 | clrbits_be32(&iop->pdir, mask); |
| 388 | return 0 != (in_be32(&iop->pdat) & mask); |
| 389 | } |
| 390 | |
| 391 | void set_sda(int state) |
| 392 | { |
| 393 | set_pin(state, SDA_MASK); |
| 394 | } |
| 395 | |
| 396 | void set_scl(int state) |
| 397 | { |
| 398 | set_pin(state, SCL_MASK); |
| 399 | } |
| 400 | |
| 401 | int get_sda(void) |
| 402 | { |
| 403 | return get_pin(SDA_MASK); |
| 404 | } |
| 405 | |
| 406 | int get_scl(void) |
| 407 | { |
| 408 | return get_pin(SCL_MASK); |
| 409 | } |
| 410 | |
| 411 | #if defined(CONFIG_HARD_I2C) |
| 412 | static void setports(int gpio) |
| 413 | { |
| 414 | ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3); |
| 415 | |
| 416 | if (gpio) { |
| 417 | clrbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK)); |
| 418 | clrbits_be32(&iop->podr, (SDA_MASK | SCL_MASK)); |
| 419 | } else { |
| 420 | setbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK)); |
| 421 | clrbits_be32(&iop->pdir, (SDA_MASK | SCL_MASK)); |
| 422 | setbits_be32(&iop->podr, (SDA_MASK | SCL_MASK)); |
| 423 | } |
| 424 | } |
| 425 | #endif |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 426 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 427 | void ft_board_setup(void *blob, bd_t *bd) |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 428 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 429 | ft_cpu_setup(blob, bd); |
Heiko Schocher | ac9db06 | 2008-01-11 01:12:08 +0100 | [diff] [blame] | 430 | } |
| 431 | #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */ |