wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2008 |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Heiko Schocher | 6ed3b9d | 2010-02-09 15:50:21 +0100 | [diff] [blame] | 9 | #include <hwconfig.h> |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 10 | #include <mpc8xx.h> |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 11 | #ifdef CONFIG_PS2MULT |
| 12 | #include <ps2mult.h> |
| 13 | #endif |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 14 | |
Heiko Schocher | 6ed3b9d | 2010-02-09 15:50:21 +0100 | [diff] [blame] | 15 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
| 16 | #include <libfdt.h> |
| 17 | #endif |
| 18 | |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 19 | extern flash_info_t flash_info[]; /* FLASH chips info */ |
| 20 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 22 | |
| 23 | static long int dram_size (long int, long int *, long int); |
| 24 | |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 25 | #define _NOT_USED_ 0xFFFFFFFF |
| 26 | |
Jens Gehrlein | 22d1a56 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 27 | /* UPM initialization table for SDRAM: 40, 50, 66 MHz CLKOUT @ CAS latency 2, tWR=2 */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 28 | const uint sdram_table[] = |
| 29 | { |
| 30 | /* |
| 31 | * Single Read. (Offset 0 in UPMA RAM) |
| 32 | */ |
| 33 | 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00, |
| 34 | 0x1FF5FC47, /* last */ |
| 35 | /* |
| 36 | * SDRAM Initialization (offset 5 in UPMA RAM) |
| 37 | * |
| 38 | * This is no UPM entry point. The following definition uses |
| 39 | * the remaining space to establish an initialization |
| 40 | * sequence, which is executed by a RUN command. |
| 41 | * |
| 42 | */ |
| 43 | 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */ |
| 44 | /* |
| 45 | * Burst Read. (Offset 8 in UPMA RAM) |
| 46 | */ |
| 47 | 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00, |
| 48 | 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */ |
| 49 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 50 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 51 | /* |
| 52 | * Single Write. (Offset 18 in UPMA RAM) |
| 53 | */ |
Jens Gehrlein | 22d1a56 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 54 | 0x1F0DFC04, 0xEEABBC00, 0x11B77C04, 0xEFFAFC44, |
| 55 | 0x1FF5FC47, /* last */ |
| 56 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 57 | /* |
| 58 | * Burst Write. (Offset 20 in UPMA RAM) |
| 59 | */ |
| 60 | 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00, |
Jens Gehrlein | 22d1a56 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 61 | 0xF0AFFC00, 0xF0AFFC04, 0xE1BAFC44, 0x1FF5FC47, /* last */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 62 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 63 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 64 | /* |
| 65 | * Refresh (Offset 30 in UPMA RAM) |
| 66 | */ |
| 67 | 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04, |
| 68 | 0xFFFFFC84, 0xFFFFFC07, /* last */ |
| 69 | _NOT_USED_, _NOT_USED_, |
| 70 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 71 | /* |
| 72 | * Exception. (Offset 3c in UPMA RAM) |
| 73 | */ |
Jens Gehrlein | 22d1a56 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 74 | 0xFFFFFC07, /* last */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 75 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 76 | }; |
| 77 | |
| 78 | /* ------------------------------------------------------------------------- */ |
| 79 | |
| 80 | |
| 81 | /* |
| 82 | * Check Board Identity: |
| 83 | * |
| 84 | * Test TQ ID string (TQM8xx...) |
| 85 | * If present, check for "L" type (no second DRAM bank), |
| 86 | * otherwise "L" type is assumed as default. |
| 87 | * |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 88 | * Set board_type to 'L' for "L" type, 'M' for "M" type, 0 else. |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 89 | */ |
| 90 | |
| 91 | int checkboard (void) |
| 92 | { |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 93 | char buf[64]; |
| 94 | int i; |
| 95 | int l = getenv_f("serial#", buf, sizeof(buf)); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 96 | |
| 97 | puts ("Board: "); |
| 98 | |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 99 | if (l < 0 || strncmp(buf, "TQM8", 4)) { |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 100 | puts ("### No HW ID - assuming TQM8xxL\n"); |
| 101 | return (0); |
| 102 | } |
| 103 | |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 104 | if ((buf[6] == 'L')) { /* a TQM8xxL type */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 105 | gd->board_type = 'L'; |
| 106 | } |
| 107 | |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 108 | if ((buf[6] == 'M')) { /* a TQM8xxM type */ |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 109 | gd->board_type = 'M'; |
| 110 | } |
| 111 | |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 112 | if ((buf[6] == 'D')) { /* a TQM885D type */ |
Markus Klotzbuecher | 090eb73 | 2006-07-12 15:26:01 +0200 | [diff] [blame] | 113 | gd->board_type = 'D'; |
| 114 | } |
| 115 | |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 116 | for (i = 0; i < l; ++i) { |
| 117 | if (buf[i] == ' ') |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 118 | break; |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 119 | putc (buf[i]); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 120 | } |
Wolfgang Denk | 8cba090 | 2006-05-12 16:15:46 +0200 | [diff] [blame] | 121 | #ifdef CONFIG_VIRTLAB2 |
| 122 | puts (" (Virtlab2)"); |
| 123 | #endif |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 124 | putc ('\n'); |
| 125 | |
| 126 | return (0); |
| 127 | } |
| 128 | |
| 129 | /* ------------------------------------------------------------------------- */ |
| 130 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 131 | phys_size_t initdram (int board_type) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 132 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 133 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 134 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | c178d3d | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 135 | long int size8, size9, size10; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 136 | long int size_b0 = 0; |
| 137 | long int size_b1 = 0; |
| 138 | |
| 139 | upmconfig (UPMA, (uint *) sdram_table, |
| 140 | sizeof (sdram_table) / sizeof (uint)); |
| 141 | |
| 142 | /* |
| 143 | * Preliminary prescaler for refresh (depends on number of |
| 144 | * banks): This value is selected for four cycles every 62.4 us |
| 145 | * with two SDRAM banks or four cycles every 31.2 us with one |
| 146 | * bank. It will be adjusted after memory sizing. |
| 147 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 148 | memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_8K; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * The following value is used as an address (i.e. opcode) for |
| 152 | * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If |
| 153 | * the port size is 32bit the SDRAM does NOT "see" the lower two |
| 154 | * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for |
| 155 | * MICRON SDRAMs: |
| 156 | * -> 0 00 010 0 010 |
| 157 | * | | | | +- Burst Length = 4 |
| 158 | * | | | +----- Burst Type = Sequential |
| 159 | * | | +------- CAS Latency = 2 |
| 160 | * | +----------- Operating Mode = Standard |
| 161 | * +-------------- Write Burst Mode = Programmed Burst Length |
| 162 | */ |
| 163 | memctl->memc_mar = 0x00000088; |
| 164 | |
| 165 | /* |
| 166 | * Map controller banks 2 and 3 to the SDRAM banks 2 and 3 at |
| 167 | * preliminary addresses - these have to be modified after the |
| 168 | * SDRAM size has been determined. |
| 169 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 170 | memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM; |
| 171 | memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 172 | |
| 173 | #ifndef CONFIG_CAN_DRIVER |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 174 | if ((board_type != 'L') && |
Markus Klotzbuecher | 090eb73 | 2006-07-12 15:26:01 +0200 | [diff] [blame] | 175 | (board_type != 'M') && |
Martin Krause | 11d9eec | 2007-09-26 17:55:56 +0200 | [diff] [blame] | 176 | (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 177 | memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM; |
| 178 | memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 179 | } |
| 180 | #endif /* CONFIG_CAN_DRIVER */ |
| 181 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 182 | memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 183 | |
| 184 | udelay (200); |
| 185 | |
| 186 | /* perform SDRAM initializsation sequence */ |
| 187 | |
| 188 | memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */ |
| 189 | udelay (1); |
| 190 | memctl->memc_mcr = 0x80004230; /* SDRAM bank 0 - execute twice */ |
| 191 | udelay (1); |
| 192 | |
| 193 | #ifndef CONFIG_CAN_DRIVER |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 194 | if ((board_type != 'L') && |
Markus Klotzbuecher | 090eb73 | 2006-07-12 15:26:01 +0200 | [diff] [blame] | 195 | (board_type != 'M') && |
Wolfgang Denk | fc1840e | 2006-07-21 18:51:56 +0200 | [diff] [blame] | 196 | (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 197 | memctl->memc_mcr = 0x80006105; /* SDRAM bank 1 */ |
| 198 | udelay (1); |
| 199 | memctl->memc_mcr = 0x80006230; /* SDRAM bank 1 - execute twice */ |
| 200 | udelay (1); |
| 201 | } |
| 202 | #endif /* CONFIG_CAN_DRIVER */ |
| 203 | |
| 204 | memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */ |
| 205 | |
| 206 | udelay (1000); |
| 207 | |
| 208 | /* |
| 209 | * Check Bank 0 Memory Size for re-configuration |
| 210 | * |
| 211 | * try 8 column mode |
| 212 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 213 | size8 = dram_size (CONFIG_SYS_MAMR_8COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE); |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 214 | debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size8 >> 20); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 215 | |
| 216 | udelay (1000); |
| 217 | |
| 218 | /* |
| 219 | * try 9 column mode |
| 220 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 221 | size9 = dram_size (CONFIG_SYS_MAMR_9COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE); |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 222 | debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size9 >> 20); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 223 | |
wdenk | c178d3d | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 224 | udelay(1000); |
| 225 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 226 | #if defined(CONFIG_SYS_MAMR_10COL) |
wdenk | c178d3d | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 227 | /* |
| 228 | * try 10 column mode |
| 229 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 230 | size10 = dram_size (CONFIG_SYS_MAMR_10COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE); |
wdenk | c178d3d | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 231 | debug ("SDRAM Bank 0 in 10 column mode: %ld MB\n", size10 >> 20); |
| 232 | #else |
| 233 | size10 = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 234 | #endif /* CONFIG_SYS_MAMR_10COL */ |
wdenk | c178d3d | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 235 | |
| 236 | if ((size8 < size10) && (size9 < size10)) { |
| 237 | size_b0 = size10; |
| 238 | } else if ((size8 < size9) && (size10 < size9)) { |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 239 | size_b0 = size9; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 240 | memctl->memc_mamr = CONFIG_SYS_MAMR_9COL; |
wdenk | c178d3d | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 241 | udelay (500); |
| 242 | } else { |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 243 | size_b0 = size8; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 244 | memctl->memc_mamr = CONFIG_SYS_MAMR_8COL; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 245 | udelay (500); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 246 | } |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 247 | debug ("SDRAM Bank 0: %ld MB\n", size_b0 >> 20); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 248 | |
| 249 | #ifndef CONFIG_CAN_DRIVER |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 250 | if ((board_type != 'L') && |
Markus Klotzbuecher | 090eb73 | 2006-07-12 15:26:01 +0200 | [diff] [blame] | 251 | (board_type != 'M') && |
Martin Krause | 11d9eec | 2007-09-26 17:55:56 +0200 | [diff] [blame] | 252 | (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 253 | /* |
| 254 | * Check Bank 1 Memory Size |
| 255 | * use current column settings |
| 256 | * [9 column SDRAM may also be used in 8 column mode, |
| 257 | * but then only half the real size will be used.] |
| 258 | */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 259 | size_b1 = dram_size (memctl->memc_mamr, (long int *)SDRAM_BASE3_PRELIM, |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 260 | SDRAM_MAX_SIZE); |
| 261 | debug ("SDRAM Bank 1: %ld MB\n", size_b1 >> 20); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 262 | } else { |
| 263 | size_b1 = 0; |
| 264 | } |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 265 | #endif /* CONFIG_CAN_DRIVER */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 266 | |
| 267 | udelay (1000); |
| 268 | |
| 269 | /* |
| 270 | * Adjust refresh rate depending on SDRAM type, both banks |
| 271 | * For types > 128 MBit leave it at the current (fast) rate |
| 272 | */ |
| 273 | if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) { |
| 274 | /* reduce to 15.6 us (62.4 us / quad) */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 275 | memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 276 | udelay (1000); |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * Final mapping: map bigger bank first |
| 281 | */ |
| 282 | if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */ |
| 283 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 284 | memctl->memc_or3 = ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM; |
| 285 | memctl->memc_br3 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 286 | |
| 287 | if (size_b0 > 0) { |
| 288 | /* |
| 289 | * Position Bank 0 immediately above Bank 1 |
| 290 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 291 | memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM; |
| 292 | memctl->memc_br2 = ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V) |
wdenk | c178d3d | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 293 | + size_b1; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 294 | } else { |
| 295 | unsigned long reg; |
| 296 | |
| 297 | /* |
| 298 | * No bank 0 |
| 299 | * |
| 300 | * invalidate bank |
| 301 | */ |
| 302 | memctl->memc_br2 = 0; |
| 303 | |
| 304 | /* adjust refresh rate depending on SDRAM type, one bank */ |
| 305 | reg = memctl->memc_mptpr; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 306 | reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 307 | memctl->memc_mptpr = reg; |
| 308 | } |
| 309 | |
| 310 | } else { /* SDRAM Bank 0 is bigger - map first */ |
| 311 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 312 | memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 313 | memctl->memc_br2 = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 314 | (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 315 | |
| 316 | if (size_b1 > 0) { |
| 317 | /* |
| 318 | * Position Bank 1 immediately above Bank 0 |
| 319 | */ |
| 320 | memctl->memc_or3 = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 321 | ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 322 | memctl->memc_br3 = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 323 | ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 324 | + size_b0; |
| 325 | } else { |
| 326 | unsigned long reg; |
| 327 | |
| 328 | #ifndef CONFIG_CAN_DRIVER |
| 329 | /* |
| 330 | * No bank 1 |
| 331 | * |
| 332 | * invalidate bank |
| 333 | */ |
| 334 | memctl->memc_br3 = 0; |
| 335 | #endif /* CONFIG_CAN_DRIVER */ |
| 336 | |
| 337 | /* adjust refresh rate depending on SDRAM type, one bank */ |
| 338 | reg = memctl->memc_mptpr; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 339 | reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 340 | memctl->memc_mptpr = reg; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | udelay (10000); |
| 345 | |
| 346 | #ifdef CONFIG_CAN_DRIVER |
Jens Gehrlein | 9d29250 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 347 | /* UPM initialization for CAN @ CLKOUT <= 66 MHz */ |
| 348 | |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 349 | /* Initialize OR3 / BR3 */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 350 | memctl->memc_or3 = CONFIG_SYS_OR3_CAN; |
| 351 | memctl->memc_br3 = CONFIG_SYS_BR3_CAN; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 352 | |
| 353 | /* Initialize MBMR */ |
wdenk | fd3103b | 2003-11-25 16:55:19 +0000 | [diff] [blame] | 354 | memctl->memc_mbmr = MBMR_GPL_B4DIS; /* GPL_B4 ouput line Disable */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 355 | |
| 356 | /* Initialize UPMB for CAN: single read */ |
Jens Gehrlein | 9d29250 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 357 | memctl->memc_mdr = 0xFFFFCC04; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 358 | memctl->memc_mcr = 0x0100 | UPMB; |
| 359 | |
| 360 | memctl->memc_mdr = 0x0FFFD004; |
| 361 | memctl->memc_mcr = 0x0101 | UPMB; |
| 362 | |
| 363 | memctl->memc_mdr = 0x0FFFC000; |
| 364 | memctl->memc_mcr = 0x0102 | UPMB; |
| 365 | |
| 366 | memctl->memc_mdr = 0x3FFFC004; |
| 367 | memctl->memc_mcr = 0x0103 | UPMB; |
| 368 | |
Jens Gehrlein | 9d29250 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 369 | memctl->memc_mdr = 0xFFFFDC07; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 370 | memctl->memc_mcr = 0x0104 | UPMB; |
| 371 | |
| 372 | /* Initialize UPMB for CAN: single write */ |
Jens Gehrlein | 9d29250 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 373 | memctl->memc_mdr = 0xFFFCCC04; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 374 | memctl->memc_mcr = 0x0118 | UPMB; |
| 375 | |
Jens Gehrlein | 9d29250 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 376 | memctl->memc_mdr = 0xCFFCDC04; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 377 | memctl->memc_mcr = 0x0119 | UPMB; |
| 378 | |
Jens Gehrlein | 9d29250 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 379 | memctl->memc_mdr = 0x3FFCC000; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 380 | memctl->memc_mcr = 0x011A | UPMB; |
| 381 | |
Jens Gehrlein | 9d29250 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 382 | memctl->memc_mdr = 0xFFFCC004; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 383 | memctl->memc_mcr = 0x011B | UPMB; |
| 384 | |
Jens Gehrlein | 9d29250 | 2007-09-26 17:55:54 +0200 | [diff] [blame] | 385 | memctl->memc_mdr = 0xFFFDC405; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 386 | memctl->memc_mcr = 0x011C | UPMB; |
| 387 | #endif /* CONFIG_CAN_DRIVER */ |
| 388 | |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 389 | #ifdef CONFIG_ISP1362_USB |
| 390 | /* Initialize OR5 / BR5 */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 391 | memctl->memc_or5 = CONFIG_SYS_OR5_ISP1362; |
| 392 | memctl->memc_br5 = CONFIG_SYS_BR5_ISP1362; |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 393 | #endif /* CONFIG_ISP1362_USB */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 394 | return (size_b0 + size_b1); |
| 395 | } |
| 396 | |
| 397 | /* ------------------------------------------------------------------------- */ |
| 398 | |
| 399 | /* |
| 400 | * Check memory range for valid RAM. A simple memory test determines |
| 401 | * the actually available RAM size between addresses `base' and |
| 402 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 403 | * - short between address lines |
| 404 | * - short between data lines |
| 405 | */ |
| 406 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 407 | static long int dram_size (long int mamr_value, long int *base, long int maxsize) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 408 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 409 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 410 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 411 | |
| 412 | memctl->memc_mamr = mamr_value; |
| 413 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 414 | return (get_ram_size(base, maxsize)); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* ------------------------------------------------------------------------- */ |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 418 | |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 419 | #ifdef CONFIG_MISC_INIT_R |
Mike Frysinger | 9c15010 | 2009-02-11 20:09:52 -0500 | [diff] [blame] | 420 | extern void load_sernum_ethaddr(void); |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 421 | int misc_init_r (void) |
| 422 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 423 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 424 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 425 | |
Mike Frysinger | 9c15010 | 2009-02-11 20:09:52 -0500 | [diff] [blame] | 426 | load_sernum_ethaddr(); |
| 427 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 428 | #ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 429 | int scy, trlx, flash_or_timing, clk_diff; |
| 430 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 431 | scy = (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_SCY_MSK) >> 4; |
| 432 | if (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_TRLX) { |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 433 | trlx = OR_TRLX; |
| 434 | scy *= 2; |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 435 | } else { |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 436 | trlx = 0; |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 437 | } |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 438 | |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 439 | /* |
| 440 | * We assume that each 10MHz of bus clock require 1-clk SCY |
| 441 | * adjustment. |
| 442 | */ |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 443 | clk_diff = (gd->bus_clk / 1000000) - 50; |
| 444 | |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 445 | /* |
| 446 | * We need proper rounding here. This is what the "+5" and "-5" |
| 447 | * are here for. |
| 448 | */ |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 449 | if (clk_diff >= 0) |
| 450 | scy += (clk_diff + 5) / 10; |
| 451 | else |
| 452 | scy += (clk_diff - 5) / 10; |
| 453 | |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 454 | /* |
| 455 | * For bus frequencies above 50MHz, we want to use relaxed timing |
| 456 | * (OR_TRLX). |
| 457 | */ |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 458 | if (gd->bus_clk >= 50000000) |
| 459 | trlx = OR_TRLX; |
| 460 | else |
| 461 | trlx = 0; |
| 462 | |
| 463 | if (trlx) |
| 464 | scy /= 2; |
| 465 | |
| 466 | if (scy > 0xf) |
| 467 | scy = 0xf; |
| 468 | if (scy < 1) |
| 469 | scy = 1; |
| 470 | |
| 471 | flash_or_timing = (scy << 4) | trlx | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 472 | (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & ~(OR_TRLX | OR_SCY_MSK)); |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 473 | |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 474 | memctl->memc_or0 = |
| 475 | flash_or_timing | (-flash_info[0].size & OR_AM_MSK); |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 476 | #else |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 477 | memctl->memc_or0 = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 478 | CONFIG_SYS_OR_TIMING_FLASH | (-flash_info[0].size & OR_AM_MSK); |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 479 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 480 | memctl->memc_br0 = (CONFIG_SYS_FLASH_BASE & BR_BA_MSK) | BR_MS_GPCM | BR_V; |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 481 | |
| 482 | debug ("## BR0: 0x%08x OR0: 0x%08x\n", |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 483 | memctl->memc_br0, memctl->memc_or0); |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 484 | |
| 485 | if (flash_info[1].size) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 486 | #ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 487 | memctl->memc_or1 = flash_or_timing | |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 488 | (-flash_info[1].size & 0xFFFF8000); |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 489 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 490 | memctl->memc_or1 = CONFIG_SYS_OR_TIMING_FLASH | |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 491 | (-flash_info[1].size & 0xFFFF8000); |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 492 | #endif |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 493 | memctl->memc_br1 = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 494 | ((CONFIG_SYS_FLASH_BASE + |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 495 | flash_info[0]. |
| 496 | size) & BR_BA_MSK) | BR_MS_GPCM | BR_V; |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 497 | |
| 498 | debug ("## BR1: 0x%08x OR1: 0x%08x\n", |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 499 | memctl->memc_br1, memctl->memc_or1); |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 500 | } else { |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 501 | memctl->memc_br1 = 0; /* invalidate bank */ |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 502 | |
| 503 | debug ("## DISABLE BR1: 0x%08x OR1: 0x%08x\n", |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 504 | memctl->memc_br1, memctl->memc_or1); |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | # ifdef CONFIG_IDE_LED |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 508 | /* Configure PA15 as output port */ |
| 509 | immap->im_ioport.iop_padir |= 0x0001; |
| 510 | immap->im_ioport.iop_paodr |= 0x0001; |
| 511 | immap->im_ioport.iop_papar &= ~0x0001; |
| 512 | immap->im_ioport.iop_padat &= ~0x0001; /* turn it off */ |
wdenk | cfca5e6 | 2004-08-01 13:09:47 +0000 | [diff] [blame] | 513 | # endif |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 514 | |
| 515 | #ifdef CONFIG_NSCU |
| 516 | /* wake up ethernet module */ |
Wolfgang Denk | 87b4ef5 | 2008-09-17 10:17:55 +0200 | [diff] [blame] | 517 | immap->im_ioport.iop_pcpar &= ~0x0004; /* GPIO pin */ |
| 518 | immap->im_ioport.iop_pcdir |= 0x0004; /* output */ |
| 519 | immap->im_ioport.iop_pcso &= ~0x0004; /* for clarity */ |
| 520 | immap->im_ioport.iop_pcdat |= 0x0004; /* enable */ |
| 521 | #endif /* CONFIG_NSCU */ |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 522 | |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 523 | return (0); |
| 524 | } |
Wolfgang Denk | 7c803be | 2008-09-16 18:02:19 +0200 | [diff] [blame] | 525 | #endif /* CONFIG_MISC_INIT_R */ |
| 526 | |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 527 | |
wdenk | cfca5e6 | 2004-08-01 13:09:47 +0000 | [diff] [blame] | 528 | # ifdef CONFIG_IDE_LED |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 529 | void ide_led (uchar led, uchar status) |
| 530 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 531 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 532 | |
| 533 | /* We have one led for both pcmcia slots */ |
| 534 | if (status) { /* led on */ |
| 535 | immap->im_ioport.iop_padat |= 0x0001; |
| 536 | } else { |
| 537 | immap->im_ioport.iop_padat &= ~0x0001; |
| 538 | } |
| 539 | } |
wdenk | cfca5e6 | 2004-08-01 13:09:47 +0000 | [diff] [blame] | 540 | # endif |
wdenk | cfca5e6 | 2004-08-01 13:09:47 +0000 | [diff] [blame] | 541 | |
Haavard Skinnemoen | 6b59e03 | 2008-09-01 16:21:22 +0200 | [diff] [blame] | 542 | #ifdef CONFIG_LCD_INFO |
| 543 | #include <lcd.h> |
Anatolij Gustschin | 1450c4a | 2008-11-03 15:30:34 +0100 | [diff] [blame] | 544 | #include <version.h> |
Peter Tyser | 561858e | 2008-11-03 09:30:59 -0600 | [diff] [blame] | 545 | #include <timestamp.h> |
Haavard Skinnemoen | 6b59e03 | 2008-09-01 16:21:22 +0200 | [diff] [blame] | 546 | |
| 547 | void lcd_show_board_info(void) |
| 548 | { |
Anatolij Gustschin | 1450c4a | 2008-11-03 15:30:34 +0100 | [diff] [blame] | 549 | char temp[32]; |
| 550 | |
Peter Tyser | 561858e | 2008-11-03 09:30:59 -0600 | [diff] [blame] | 551 | lcd_printf ("%s (%s - %s)\n", U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME); |
Haavard Skinnemoen | 6b59e03 | 2008-09-01 16:21:22 +0200 | [diff] [blame] | 552 | lcd_printf ("(C) 2008 DENX Software Engineering GmbH\n"); |
| 553 | lcd_printf (" Wolfgang DENK, wd@denx.de\n"); |
| 554 | #ifdef CONFIG_LCD_INFO_BELOW_LOGO |
| 555 | lcd_printf ("MPC823 CPU at %s MHz\n", |
| 556 | strmhz(temp, gd->cpu_clk)); |
Haavard Skinnemoen | 6b59e03 | 2008-09-01 16:21:22 +0200 | [diff] [blame] | 557 | lcd_printf (" %ld MB RAM, %ld MB Flash\n", |
| 558 | gd->ram_size >> 20, |
| 559 | gd->bd->bi_flashsize >> 20 ); |
| 560 | #else |
| 561 | /* leave one blank line */ |
| 562 | lcd_printf ("\nMPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash\n", |
| 563 | strmhz(temp, gd->cpu_clk), |
| 564 | gd->ram_size >> 20, |
| 565 | gd->bd->bi_flashsize >> 20 ); |
| 566 | #endif /* CONFIG_LCD_INFO_BELOW_LOGO */ |
| 567 | } |
| 568 | #endif /* CONFIG_LCD_INFO */ |
| 569 | |
Heiko Schocher | 6ed3b9d | 2010-02-09 15:50:21 +0100 | [diff] [blame] | 570 | /* |
| 571 | * Device Tree Support |
| 572 | */ |
| 573 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
| 574 | int fdt_set_node_and_value (void *blob, |
| 575 | char *nodename, |
| 576 | char *regname, |
| 577 | void *var, |
| 578 | int size) |
| 579 | { |
| 580 | int ret = 0; |
| 581 | int nodeoffset = 0; |
| 582 | |
| 583 | nodeoffset = fdt_path_offset (blob, nodename); |
| 584 | if (nodeoffset >= 0) { |
| 585 | ret = fdt_setprop (blob, nodeoffset, regname, var, |
| 586 | size); |
| 587 | if (ret < 0) { |
| 588 | printf("ft_blob_update(): " |
| 589 | "cannot set %s/%s property; err: %s\n", |
| 590 | nodename, regname, fdt_strerror (ret)); |
| 591 | } |
| 592 | } else { |
| 593 | printf("ft_blob_update(): " |
| 594 | "cannot find %s node err:%s\n", |
| 595 | nodename, fdt_strerror (nodeoffset)); |
| 596 | } |
| 597 | return ret; |
| 598 | } |
| 599 | |
| 600 | int fdt_del_node_name (void *blob, char *nodename) |
| 601 | { |
| 602 | int ret = 0; |
| 603 | int nodeoffset = 0; |
| 604 | |
| 605 | nodeoffset = fdt_path_offset (blob, nodename); |
| 606 | if (nodeoffset >= 0) { |
| 607 | ret = fdt_del_node (blob, nodeoffset); |
| 608 | if (ret < 0) { |
| 609 | printf("%s: cannot delete %s; err: %s\n", |
| 610 | __func__, nodename, fdt_strerror (ret)); |
| 611 | } |
| 612 | } else { |
| 613 | printf("%s: cannot find %s node err:%s\n", |
| 614 | __func__, nodename, fdt_strerror (nodeoffset)); |
| 615 | } |
| 616 | return ret; |
| 617 | } |
| 618 | |
| 619 | int fdt_del_prop_name (void *blob, char *nodename, char *propname) |
| 620 | { |
| 621 | int ret = 0; |
| 622 | int nodeoffset = 0; |
| 623 | |
| 624 | nodeoffset = fdt_path_offset (blob, nodename); |
| 625 | if (nodeoffset >= 0) { |
| 626 | ret = fdt_delprop (blob, nodeoffset, propname); |
| 627 | if (ret < 0) { |
| 628 | printf("%s: cannot delete %s %s; err: %s\n", |
| 629 | __func__, nodename, propname, |
| 630 | fdt_strerror (ret)); |
| 631 | } |
| 632 | } else { |
| 633 | printf("%s: cannot find %s node err:%s\n", |
| 634 | __func__, nodename, fdt_strerror (nodeoffset)); |
| 635 | } |
| 636 | return ret; |
| 637 | } |
| 638 | |
| 639 | /* |
| 640 | * update "brg" property in the blob |
| 641 | */ |
| 642 | void ft_blob_update (void *blob, bd_t *bd) |
| 643 | { |
| 644 | uchar enetaddr[6]; |
| 645 | ulong brg_data = 0; |
| 646 | |
| 647 | /* BRG */ |
| 648 | brg_data = cpu_to_be32(bd->bi_busfreq); |
| 649 | fdt_set_node_and_value(blob, |
| 650 | "/soc/cpm", "brg-frequency", |
| 651 | &brg_data, sizeof(brg_data)); |
| 652 | |
| 653 | /* MAC addr */ |
| 654 | if (eth_getenv_enetaddr("ethaddr", enetaddr)) { |
| 655 | fdt_set_node_and_value(blob, |
| 656 | "ethernet0", "local-mac-address", |
| 657 | enetaddr, sizeof(u8) * 6); |
| 658 | } |
| 659 | |
| 660 | if (hwconfig_arg_cmp("fec", "off")) { |
| 661 | /* no FEC on this plattform, delete DTS nodes */ |
| 662 | fdt_del_node_name (blob, "ethernet1"); |
| 663 | fdt_del_node_name (blob, "mdio1"); |
| 664 | /* also the aliases entries */ |
| 665 | fdt_del_prop_name (blob, "/aliases", "ethernet1"); |
| 666 | fdt_del_prop_name (blob, "/aliases", "mdio1"); |
| 667 | } else { |
| 668 | /* adjust local-mac-address for FEC ethernet */ |
| 669 | if (eth_getenv_enetaddr("eth1addr", enetaddr)) { |
| 670 | fdt_set_node_and_value(blob, |
| 671 | "ethernet1", "local-mac-address", |
| 672 | enetaddr, sizeof(u8) * 6); |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 677 | int ft_board_setup(void *blob, bd_t *bd) |
Heiko Schocher | 6ed3b9d | 2010-02-09 15:50:21 +0100 | [diff] [blame] | 678 | { |
| 679 | ft_cpu_setup(blob, bd); |
| 680 | ft_blob_update(blob, bd); |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 681 | |
| 682 | return 0; |
Heiko Schocher | 6ed3b9d | 2010-02-09 15:50:21 +0100 | [diff] [blame] | 683 | } |
| 684 | #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */ |
| 685 | |
Guennadi Liakhovetski | efc6f44 | 2008-01-10 17:59:07 +0100 | [diff] [blame] | 686 | /* ---------------------------------------------------------------------------- */ |
| 687 | /* TK885D specific initializaion */ |
| 688 | /* ---------------------------------------------------------------------------- */ |
| 689 | #ifdef CONFIG_TK885D |
| 690 | #include <miiphy.h> |
| 691 | int last_stage_init(void) |
| 692 | { |
| 693 | const unsigned char phy[] = {CONFIG_FEC1_PHY, CONFIG_FEC2_PHY}; |
| 694 | unsigned short reg; |
| 695 | int ret, i = 100; |
| 696 | char *s; |
| 697 | |
| 698 | mii_init(); |
| 699 | /* Without this delay 0xff is read from the UART buffer later in |
| 700 | * abortboot() and autoboot is aborted */ |
| 701 | udelay(10000); |
| 702 | while (tstc() && i--) |
| 703 | (void)getc(); |
| 704 | |
| 705 | /* Check if auto-negotiation is prohibited */ |
| 706 | s = getenv("phy_auto_nego"); |
| 707 | |
| 708 | if (!s || !strcmp(s, "on")) |
| 709 | /* Nothing to do - autonegotiation by default */ |
| 710 | return 0; |
| 711 | |
| 712 | for (i = 0; i < 2; i++) { |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 713 | ret = miiphy_read("FEC", phy[i], MII_BMCR, ®); |
Guennadi Liakhovetski | efc6f44 | 2008-01-10 17:59:07 +0100 | [diff] [blame] | 714 | if (ret) { |
| 715 | printf("Cannot read BMCR on PHY %d\n", phy[i]); |
| 716 | return 0; |
| 717 | } |
| 718 | /* Auto-negotiation off, hard set full duplex, 100Mbps */ |
Heiko Schocher | 48690d8 | 2010-07-20 17:45:02 +0200 | [diff] [blame] | 719 | ret = miiphy_write("FEC", phy[i], |
Mike Frysinger | 8ef583a | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 720 | MII_BMCR, (reg | BMCR_SPEED100 | |
| 721 | BMCR_FULLDPLX) & ~BMCR_ANENABLE); |
Guennadi Liakhovetski | efc6f44 | 2008-01-10 17:59:07 +0100 | [diff] [blame] | 722 | if (ret) { |
| 723 | printf("Cannot write BMCR on PHY %d\n", phy[i]); |
| 724 | return 0; |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | return 0; |
| 729 | } |
Guennadi Liakhovetski | efc6f44 | 2008-01-10 17:59:07 +0100 | [diff] [blame] | 730 | #endif |