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 | 0x0f07cc04, 0x00adcc04, 0x00a74c00, 0x00bfcc04, |
| 31 | 0x1fffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05, |
| 32 | /* |
| 33 | * Burst Read. (Offset 8 in UPMA RAM) |
| 34 | */ |
| 35 | 0x0ff7fc04, 0x0ffffc04, 0x00bdfc04, 0x00fffc00, |
| 36 | 0x00fffc00, 0x00fffc00, 0x0ff77c00, 0x1ffffc05, |
| 37 | 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, |
| 38 | 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, |
| 39 | /* |
| 40 | * Single Write. (Offset 18 in UPMA RAM) |
| 41 | */ |
| 42 | 0x0f07cc04, 0x0fafcc00, 0x01ad0c04, 0x1ff74c07, |
| 43 | 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05, |
| 44 | /* |
| 45 | * Burst Write. (Offset 20 in UPMA RAM) |
| 46 | */ |
| 47 | 0x0ff7fc04, 0x0ffffc00, 0x00bd7c00, 0x00fffc00, |
| 48 | 0x00fffc00, 0x00fffc00, 0x0ffffc04, 0x0ff77c04, |
| 49 | 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, |
| 50 | 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, 0x1ffffc05, |
| 51 | /* |
| 52 | * Refresh (Offset 30 in UPMA RAM) |
| 53 | */ |
| 54 | 0xffffcc04, 0x1ff5cc84, 0xffffcc04, 0xffffcc04, |
| 55 | 0xffffcc84, 0xffffcc05, 0xffffcc04, 0xffffcc04, |
| 56 | 0xffffcc04, 0xffffcc04, 0xffffcc04, 0xffffcc04, |
| 57 | /* |
| 58 | * Exception. (Offset 3c in UPMA RAM) |
| 59 | */ |
| 60 | 0x1ff74c04, 0xffffcc07, 0xffffaa34, 0x1fb54a37 |
| 61 | }; |
| 62 | |
| 63 | /* ------------------------------------------------------------------------- */ |
| 64 | |
| 65 | |
| 66 | /* |
| 67 | * Check Board Identity: |
| 68 | * |
| 69 | * Test ID string (QS850, QS823, ...) |
| 70 | * |
| 71 | * Always return 1 |
| 72 | */ |
Wolfgang Denk | 45b16d2 | 2008-07-14 22:38:42 +0200 | [diff] [blame] | 73 | #if defined(CONFIG_QS850) |
| 74 | #define BOARD_IDENTITY "QS850" |
| 75 | #elif defined(CONFIG_QS823) |
| 76 | #define BOARD_IDENTITY "QS823" |
| 77 | #else |
| 78 | #define BOARD_IDENTITY "QS???" |
| 79 | #endif |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 80 | |
| 81 | int checkboard (void) |
| 82 | { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 83 | char *s, *e; |
| 84 | char buf[64]; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 85 | int i; |
| 86 | |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 87 | i = getenv_f("serial#", buf, sizeof(buf)); |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 88 | s = (i>0) ? buf : NULL; |
| 89 | |
Wolfgang Denk | 45b16d2 | 2008-07-14 22:38:42 +0200 | [diff] [blame] | 90 | if (!s || strncmp(s, BOARD_IDENTITY, 5)) { |
| 91 | puts ("### No HW ID - assuming " BOARD_IDENTITY); |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 92 | } else { |
| 93 | for (e=s; *e; ++e) { |
| 94 | if (*e == ' ') |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | for ( ; s<e; ++s) { |
| 99 | putc (*s); |
| 100 | } |
| 101 | } |
| 102 | putc ('\n'); |
| 103 | |
| 104 | return (0); |
| 105 | } |
| 106 | |
| 107 | /* ------------------------------------------------------------------------- */ |
| 108 | /* SDRAM Mode Register Definitions */ |
| 109 | |
| 110 | /* Set SDRAM Burst Length to 4 (010) */ |
| 111 | /* See Motorola MPC850 User Manual, Page 13-14 */ |
| 112 | #define SDRAM_BURST_LENGTH (2) |
| 113 | |
| 114 | /* Set Wrap Type to Sequential (0) */ |
| 115 | /* See Motorola MPC850 User Manual, Page 13-14 */ |
| 116 | #define SDRAM_WRAP_TYPE (0 << 3) |
| 117 | |
| 118 | /* Set /CAS Latentcy to 2 clocks */ |
| 119 | #define SDRAM_CAS_LATENTCY (2 << 4) |
| 120 | |
| 121 | /* The Mode Register value must be shifted left by 2, since it is */ |
| 122 | /* placed on the address bus, and the 2 LSBs are ignored for 32-bit accesses */ |
| 123 | #define SDRAM_MODE_REG ((SDRAM_BURST_LENGTH|SDRAM_WRAP_TYPE|SDRAM_CAS_LATENTCY) << 2) |
| 124 | |
| 125 | #define UPMA_RUN(loops,index) (0x80002000 + (loops<<8) + index) |
| 126 | |
| 127 | /* Please note a value of zero = 16 loops */ |
| 128 | #define REFRESH_INIT_LOOPS (0) |
| 129 | |
| 130 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 131 | phys_size_t initdram (int board_type) |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +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 | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 134 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 135 | long int size; |
| 136 | |
| 137 | upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint)); |
| 138 | |
| 139 | /* |
| 140 | * Prescaler for refresh |
| 141 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 142 | memctl->memc_mptpr = CONFIG_SYS_MPTPR; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 143 | |
| 144 | /* |
| 145 | * Map controller bank 1 to the SDRAM address |
| 146 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 147 | memctl->memc_or1 = CONFIG_SYS_OR1; |
| 148 | memctl->memc_br1 = CONFIG_SYS_BR1; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 149 | udelay(1000); |
| 150 | |
| 151 | /* perform SDRAM initialization sequence */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 152 | memctl->memc_mamr = CONFIG_SYS_16M_MAMR; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 153 | udelay(100); |
| 154 | |
| 155 | /* Program the SDRAM's Mode Register */ |
| 156 | memctl->memc_mar = SDRAM_MODE_REG; |
| 157 | |
| 158 | /* Run the Prechard Pattern at 0x3C */ |
| 159 | memctl->memc_mcr = UPMA_RUN(1,0x3c); |
| 160 | udelay(1); |
| 161 | |
| 162 | /* Run the Refresh program residing at MAD index 0x30 */ |
| 163 | /* This contains the CBR Refresh command with a loop */ |
| 164 | /* The SDRAM must be refreshed at least 2 times */ |
| 165 | /* Please note a value of zero = 16 loops */ |
| 166 | memctl->memc_mcr = UPMA_RUN(REFRESH_INIT_LOOPS,0x30); |
| 167 | udelay(1); |
| 168 | |
| 169 | /* Run the Exception program residing at MAD index 0x3E */ |
| 170 | /* This contains the Write Mode Register command */ |
| 171 | /* The Write Mode Register command uses the value written to MAR */ |
| 172 | memctl->memc_mcr = UPMA_RUN(1,0x3e); |
| 173 | |
| 174 | udelay (1000); |
| 175 | |
| 176 | /* |
| 177 | * Check for 32M SDRAM Memory Size |
| 178 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 179 | size = dram_size(CONFIG_SYS_32M_MAMR|MAMR_PTAE, |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 180 | (long *)SDRAM_BASE, SDRAM_32M_MAX_SIZE); |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 181 | udelay (1000); |
| 182 | |
| 183 | /* |
| 184 | * Check for 16M SDRAM Memory Size |
| 185 | */ |
| 186 | if (size != SDRAM_32M_MAX_SIZE) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 187 | size = dram_size(CONFIG_SYS_16M_MAMR|MAMR_PTAE, |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 188 | (long *)SDRAM_BASE, SDRAM_16M_MAX_SIZE); |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 189 | udelay (1000); |
| 190 | } |
| 191 | |
| 192 | udelay(10000); |
| 193 | return (size); |
| 194 | } |
| 195 | |
| 196 | /* ------------------------------------------------------------------------- */ |
| 197 | |
| 198 | /* |
| 199 | * Check memory range for valid RAM. A simple memory test determines |
| 200 | * the actually available RAM size between addresses `base' and |
| 201 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 202 | * - short between address lines |
| 203 | * - short between data lines |
| 204 | */ |
| 205 | |
| 206 | static long int dram_size (long int mamr_value, long int *base, long int maxsize) |
| 207 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 208 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 209 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 210 | |
| 211 | memctl->memc_mamr = mamr_value; |
| 212 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 213 | return (get_ram_size(base, maxsize)); |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 214 | } |