wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 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 | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include "mpc8xx.h" |
| 10 | #include <linux/mtd/doc2000.h> |
| 11 | |
| 12 | extern int kbd_init(void); |
| 13 | extern int drv_kbd_init(void); |
| 14 | |
| 15 | /* ------------------------------------------------------------------------- */ |
| 16 | |
| 17 | static long int dram_size (long int, long int *, long int); |
| 18 | |
| 19 | /* ------------------------------------------------------------------------- */ |
| 20 | |
| 21 | #define _NOT_USED_ 0xFFFFFFFF |
| 22 | |
| 23 | const uint sdram_table[] = |
| 24 | { |
| 25 | /* |
| 26 | * Single Read. (Offset 0 in UPMA RAM) |
| 27 | */ |
| 28 | 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00, |
| 29 | 0x1FF77C47, /* last */ |
| 30 | /* |
| 31 | * SDRAM Initialization (offset 5 in UPMA RAM) |
| 32 | * |
| 33 | * This is no UPM entry point. The following definition uses |
| 34 | * the remaining space to establish an initialization |
| 35 | * sequence, which is executed by a RUN command. |
| 36 | * |
| 37 | */ |
| 38 | 0x1FF77C34, 0xEFEABC34, 0x1FB57C35, /* last */ |
| 39 | /* |
| 40 | * Burst Read. (Offset 8 in UPMA RAM) |
| 41 | */ |
| 42 | 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00, |
| 43 | 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, /* last */ |
| 44 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 45 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 46 | /* |
| 47 | * Single Write. (Offset 18 in UPMA RAM) |
| 48 | */ |
| 49 | 0x1F27FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, /* last */ |
| 50 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 51 | /* |
| 52 | * Burst Write. (Offset 20 in UPMA RAM) |
| 53 | */ |
| 54 | 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00, |
| 55 | 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, /* last */ |
| 56 | _NOT_USED_, |
| 57 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 58 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 59 | /* |
| 60 | * Refresh (Offset 30 in UPMA RAM) |
| 61 | */ |
| 62 | 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04, |
| 63 | 0xFFFFFC84, 0xFFFFFC07, /* last */ |
| 64 | _NOT_USED_, _NOT_USED_, |
| 65 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 66 | /* |
| 67 | * Exception. (Offset 3c in UPMA RAM) |
| 68 | */ |
| 69 | 0x1FF7FC07, /* last */ |
| 70 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 71 | }; |
| 72 | |
| 73 | const uint static_table[] = |
| 74 | { |
| 75 | /* |
| 76 | * Single Read. (Offset 0 in UPMA RAM) |
| 77 | */ |
| 78 | 0x0FFFFC04, 0x0FF3FC04, 0x0FF3CC04, 0x0FF3CC04, |
| 79 | 0x0FF3EC04, 0x0FF3CC00, 0x0FF7FC04, 0x3FFFFC04, |
| 80 | 0xFFFFFC04, 0xFFFFFC05, /* last */ |
Wolfgang Denk | 93e1459 | 2013-10-04 17:43:24 +0200 | [diff] [blame] | 81 | _NOT_USED_, _NOT_USED_, |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 82 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 83 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 84 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 85 | /* |
| 86 | * Single Write. (Offset 18 in UPMA RAM) |
| 87 | */ |
| 88 | 0x0FFFFC04, 0x00FFFC04, 0x00FFFC04, 0x00FFFC04, |
| 89 | 0x01FFFC00, 0x3FFFFC04, 0xFFFFFC04, 0xFFFFFC05, /* last */ |
| 90 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 91 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 92 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 93 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 94 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 95 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 96 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 97 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 98 | }; |
| 99 | |
| 100 | /* ------------------------------------------------------------------------- */ |
| 101 | |
| 102 | /* |
| 103 | * Check Board Identity: |
| 104 | * |
| 105 | * Test TQ ID string (TQM8xx...) |
| 106 | * If present, check for "L" type (no second DRAM bank), |
| 107 | * otherwise "L" type is assumed as default. |
| 108 | * |
| 109 | * Return 1 for "L" type, 0 else. |
| 110 | */ |
| 111 | |
| 112 | int checkboard (void) |
| 113 | { |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 114 | char buf[64]; |
| 115 | int i = getenv_f("serial#", buf, sizeof(buf)); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 116 | |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 117 | if (i < 0 || strncmp(buf, "TQM8", 4)) { |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 118 | printf ("### No HW ID - assuming RBC823\n"); |
| 119 | return (0); |
| 120 | } |
| 121 | |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 122 | puts(buf); |
| 123 | putc('\n'); |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 124 | |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 125 | return (0); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /* ------------------------------------------------------------------------- */ |
| 129 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 130 | phys_size_t initdram (int board_type) |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 131 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 132 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 133 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 134 | long int size_b0, size8, size9; |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 135 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 136 | upmconfig (UPMA, (uint *) sdram_table, |
| 137 | sizeof (sdram_table) / sizeof (uint)); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 138 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 139 | /* |
| 140 | * 1 Bank of 64Mbit x 2 devices |
| 141 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 142 | memctl->memc_mptpr = CONFIG_SYS_MPTPR_1BK_4K; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 143 | memctl->memc_mar = 0x00000088; |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 144 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 145 | /* |
| 146 | * Map controller SDRAM bank 0 |
| 147 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 148 | memctl->memc_or4 = CONFIG_SYS_OR4_PRELIM; |
| 149 | memctl->memc_br4 = CONFIG_SYS_BR4_PRELIM; |
| 150 | memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 151 | udelay (200); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 152 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 153 | /* |
| 154 | * Perform SDRAM initializsation sequence |
| 155 | */ |
| 156 | memctl->memc_mcr = 0x80008105; /* SDRAM bank 0 */ |
| 157 | udelay (1); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 158 | memctl->memc_mamr = (CONFIG_SYS_MAMR_8COL & ~(MAMR_TLFA_MSK)) | MAMR_TLFA_8X; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 159 | udelay (200); |
| 160 | memctl->memc_mcr = 0x80008130; /* SDRAM bank 0 - execute twice */ |
| 161 | udelay (1); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 162 | memctl->memc_mamr = (CONFIG_SYS_MAMR_8COL & ~(MAMR_TLFA_MSK)) | MAMR_TLFA_4X; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 163 | udelay (200); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 164 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 165 | memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */ |
| 166 | udelay (1000); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 167 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 168 | /* |
| 169 | * Preliminary prescaler for refresh (depends on number of |
| 170 | * banks): This value is selected for four cycles every 62.4 us |
| 171 | * with two SDRAM banks or four cycles every 31.2 us with one |
| 172 | * bank. It will be adjusted after memory sizing. |
| 173 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 174 | memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K; /* 16: but should be: CONFIG_SYS_MPTPR_1BK_4K */ |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 175 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 176 | /* |
| 177 | * Check Bank 0 Memory Size for re-configuration |
| 178 | * |
| 179 | * try 8 column mode |
| 180 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 181 | size8 = dram_size (CONFIG_SYS_MAMR_8COL, (long *) SDRAM_BASE4_PRELIM, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 182 | SDRAM_MAX_SIZE); |
| 183 | udelay (1000); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 184 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 185 | /* |
| 186 | * try 9 column mode |
| 187 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 188 | size9 = dram_size (CONFIG_SYS_MAMR_9COL, (long *) SDRAM_BASE4_PRELIM, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 189 | SDRAM_MAX_SIZE); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 190 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 191 | if (size8 < size9) { /* leave configuration at 9 columns */ |
| 192 | size_b0 = size9; |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 193 | /* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 194 | } else { /* back to 8 columns */ |
| 195 | size_b0 = size8; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 196 | memctl->memc_mamr = CONFIG_SYS_MAMR_8COL; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 197 | udelay (500); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 198 | /* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 199 | } |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 200 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 201 | udelay (1000); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 202 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 203 | /* |
| 204 | * Adjust refresh rate depending on SDRAM type, both banks |
| 205 | * For types > 128 MBit leave it at the current (fast) rate |
| 206 | */ |
| 207 | if ((size_b0 < 0x02000000)) { |
| 208 | /* reduce to 15.6 us (62.4 us / quad) */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 209 | memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 210 | udelay (1000); |
| 211 | } |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 212 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 213 | /* SDRAM Bank 0 is bigger - map first */ |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 214 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 215 | memctl->memc_or4 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM; |
| 216 | memctl->memc_br4 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 217 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 218 | udelay (10000); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 219 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 220 | return (size_b0); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* ------------------------------------------------------------------------- */ |
| 224 | |
| 225 | /* |
| 226 | * Check memory range for valid RAM. A simple memory test determines |
| 227 | * the actually available RAM size between addresses `base' and |
| 228 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 229 | * - short between address lines |
| 230 | * - short between data lines |
| 231 | */ |
| 232 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 233 | static long int dram_size (long int mamr_value, long int *base, |
| 234 | long int maxsize) |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 235 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 236 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 237 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 238 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 239 | memctl->memc_mamr = mamr_value; |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 240 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 241 | return (get_ram_size (base, maxsize)); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Wolfgang Denk | 7640f41 | 2009-07-19 19:37:24 +0200 | [diff] [blame] | 244 | #ifdef CONFIG_CMD_DOC |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 245 | void doc_init (void) |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 246 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 247 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 248 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 249 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 250 | upmconfig (UPMB, (uint *) static_table, |
| 251 | sizeof (static_table) / sizeof (uint)); |
| 252 | memctl->memc_mbmr = MAMR_DSA_1_CYCL; |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 253 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 254 | doc_probe (FLASH_BASE1_PRELIM); |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 255 | } |
Wolfgang Denk | 7640f41 | 2009-07-19 19:37:24 +0200 | [diff] [blame] | 256 | #endif |