wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * MuLogic B.V. |
| 4 | * |
| 5 | * (C) Copyright 2002 |
| 6 | * Simple Network Magic Corporation, dnevil@snmc.com |
| 7 | * |
| 8 | * (C) Copyright 2000 |
| 9 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 10 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <asm/u-boot.h> |
| 16 | #include <commproc.h> |
| 17 | #include "mpc8xx.h" |
| 18 | |
| 19 | /* ------------------------------------------------------------------------- */ |
| 20 | |
| 21 | static long int dram_size (long int, long int *, long int); |
| 22 | |
| 23 | /* ------------------------------------------------------------------------- */ |
| 24 | |
| 25 | const uint sdram_table[] = |
| 26 | { |
| 27 | /* |
| 28 | * Single Read. (Offset 0 in UPMA RAM) |
| 29 | */ |
| 30 | 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00, |
| 31 | 0x1FF77C47, 0x1FF77C35, 0xEFEABC34, 0x1FB57C35, |
| 32 | /* |
| 33 | * Burst Read. (Offset 8 in UPMA RAM) |
| 34 | */ |
| 35 | 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00, |
| 36 | 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, |
| 37 | 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, |
| 38 | 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, |
| 39 | /* |
| 40 | * Single Write. (Offset 18 in UPMA RAM) |
| 41 | */ |
| 42 | 0x1F27FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, |
| 43 | 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, |
| 44 | /* |
| 45 | * Burst Write. (Offset 20 in UPMA RAM) |
| 46 | */ |
| 47 | 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00, |
| 48 | 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, 0xFFFFEC04, |
| 49 | 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, |
| 50 | 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, |
| 51 | /* |
| 52 | * Refresh (Offset 30 in UPMA RAM) |
| 53 | */ |
| 54 | 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04, |
| 55 | 0xFFFFFC84, 0xFFFFFC07, 0xFFFFEC04, 0xFFFFEC04, |
| 56 | 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04, |
| 57 | /* |
| 58 | * Exception. (Offset 3c in UPMA RAM) |
| 59 | */ |
| 60 | 0x7FFFFC07, 0xFFFFEC04, 0xFFFFEC04, 0xFFFFEC04 |
| 61 | }; |
| 62 | |
| 63 | /* ------------------------------------------------------------------------- */ |
| 64 | |
| 65 | |
| 66 | /* |
| 67 | * Check Board Identity: |
| 68 | * |
| 69 | * Test ID string (QS860T...) |
| 70 | * |
| 71 | * Always return 1 |
| 72 | */ |
| 73 | |
| 74 | int checkboard (void) |
| 75 | { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 76 | char *s, *e; |
| 77 | char buf[64]; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 78 | int i; |
| 79 | |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 80 | i = getenv_f("serial#", buf, sizeof(buf)); |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 81 | s = (i>0) ? buf : NULL; |
| 82 | |
| 83 | if (!s || strncmp(s, "QS860T", 6)) { |
| 84 | puts ("### No HW ID - assuming QS860T"); |
| 85 | } else { |
| 86 | for (e=s; *e; ++e) { |
| 87 | if (*e == ' ') |
| 88 | break; |
| 89 | } |
| 90 | |
| 91 | for ( ; s<e; ++s) { |
| 92 | putc (*s); |
| 93 | } |
| 94 | } |
| 95 | putc ('\n'); |
| 96 | |
| 97 | return (0); |
| 98 | } |
| 99 | |
| 100 | /* ------------------------------------------------------------------------- */ |
| 101 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 102 | phys_size_t initdram (int board_type) |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 103 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 105 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 106 | long int size; |
| 107 | |
| 108 | upmconfig(UPMB, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint)); |
| 109 | |
| 110 | /* |
| 111 | * Prescaler for refresh |
| 112 | */ |
| 113 | memctl->memc_mptpr = 0x0400; |
| 114 | |
| 115 | /* |
| 116 | * Map controller bank 2 to the SDRAM address |
| 117 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 118 | memctl->memc_or2 = CONFIG_SYS_OR2; |
| 119 | memctl->memc_br2 = CONFIG_SYS_BR2; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 120 | udelay(200); |
| 121 | |
| 122 | /* perform SDRAM initialization sequence */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 123 | memctl->memc_mbmr = CONFIG_SYS_16M_MBMR; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 124 | udelay(100); |
| 125 | |
| 126 | memctl->memc_mar = 0x00000088; |
| 127 | memctl->memc_mcr = 0x80804105; /* run precharge pattern */ |
| 128 | udelay(1); |
| 129 | |
| 130 | /* Run two refresh cycles on SDRAM */ |
| 131 | memctl->memc_mbmr = 0x18802118; |
| 132 | memctl->memc_mcr = 0x80804130; |
| 133 | memctl->memc_mbmr = 0x18802114; |
| 134 | memctl->memc_mcr = 0x80804106; |
| 135 | |
| 136 | udelay (1000); |
| 137 | |
| 138 | #if 0 |
| 139 | /* |
| 140 | * Check for 64M SDRAM Memory Size |
| 141 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 142 | size = dram_size (CONFIG_SYS_64M_MBMR, (ulong *)SDRAM_BASE, SDRAM_64M_MAX_SIZE); |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 143 | udelay (1000); |
| 144 | |
| 145 | /* |
| 146 | * Check for 16M SDRAM Memory Size |
| 147 | */ |
| 148 | if (size != SDRAM_64M_MAX_SIZE) { |
| 149 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 150 | size = dram_size (CONFIG_SYS_16M_MBMR, (long *)SDRAM_BASE, SDRAM_16M_MAX_SIZE); |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 151 | udelay (1000); |
| 152 | #if 0 |
| 153 | } |
| 154 | |
| 155 | memctl->memc_or2 = ((-size) & 0xFFFF0000) | SDRAM_TIMING; |
| 156 | #endif |
| 157 | |
| 158 | |
| 159 | udelay(10000); |
| 160 | |
| 161 | |
| 162 | #if 0 |
| 163 | |
| 164 | /* |
| 165 | * Also, map other memory to correct position |
| 166 | */ |
| 167 | |
| 168 | /* |
| 169 | * Map the 8M Intel Flash device to chip select 1 |
| 170 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 171 | memctl->memc_or1 = CONFIG_SYS_OR1; |
| 172 | memctl->memc_br1 = CONFIG_SYS_BR1; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 173 | |
| 174 | |
| 175 | /* |
| 176 | * Map 64K NVRAM, Sipex Device, NAND Ctl Reg, and LED Ctl Reg |
| 177 | * to chip select 3 |
| 178 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 179 | memctl->memc_or3 = CONFIG_SYS_OR3; |
| 180 | memctl->memc_br3 = CONFIG_SYS_BR3; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 181 | |
| 182 | /* |
| 183 | * Map chip selects 4, 5, 6, & 7 for external expansion connector |
| 184 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 185 | memctl->memc_or4 = CONFIG_SYS_OR4; |
| 186 | memctl->memc_br4 = CONFIG_SYS_BR4; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 187 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 188 | memctl->memc_or5 = CONFIG_SYS_OR5; |
| 189 | memctl->memc_br5 = CONFIG_SYS_BR5; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 190 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 191 | memctl->memc_or6 = CONFIG_SYS_OR6; |
| 192 | memctl->memc_br6 = CONFIG_SYS_BR6; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 193 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 194 | memctl->memc_or7 = CONFIG_SYS_OR7; |
| 195 | memctl->memc_br7 = CONFIG_SYS_BR7; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 196 | |
| 197 | #endif |
| 198 | |
| 199 | return (size); |
| 200 | } |
| 201 | |
| 202 | /* ------------------------------------------------------------------------- */ |
| 203 | |
| 204 | /* |
| 205 | * Check memory range for valid RAM. A simple memory test determines |
| 206 | * the actually available RAM size between addresses `base' and |
| 207 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 208 | * - short between address lines |
| 209 | * - short between data lines |
| 210 | */ |
| 211 | |
| 212 | static long int dram_size (long int mbmr_value, long int *base, long int maxsize) |
| 213 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 214 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 215 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 216 | |
| 217 | memctl->memc_mbmr = mbmr_value; |
| 218 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 219 | return (get_ram_size(base, maxsize)); |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 220 | } |