blob: dc4a4768cda01117a880b609dec874afa9ebb2f2 [file] [log] [blame]
wdenk3bbc8992003-12-07 22:27:15 +00001/*
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 Denk1a459662013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
wdenk3bbc8992003-12-07 22:27:15 +000012 */
13
14#include <common.h>
15#include <asm/u-boot.h>
16#include <commproc.h>
17#include "mpc8xx.h"
18
19/* ------------------------------------------------------------------------- */
20
21static long int dram_size (long int, long int *, long int);
22
23/* ------------------------------------------------------------------------- */
24
25const 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 Denk45b16d22008-07-14 22:38:42 +020073#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
wdenk3bbc8992003-12-07 22:27:15 +000080
81int checkboard (void)
82{
Wolfgang Denk77ddac92005-10-13 16:45:02 +020083 char *s, *e;
84 char buf[64];
wdenk3bbc8992003-12-07 22:27:15 +000085 int i;
86
Wolfgang Denkcdb74972010-07-24 21:55:43 +020087 i = getenv_f("serial#", buf, sizeof(buf));
wdenk3bbc8992003-12-07 22:27:15 +000088 s = (i>0) ? buf : NULL;
89
Wolfgang Denk45b16d22008-07-14 22:38:42 +020090 if (!s || strncmp(s, BOARD_IDENTITY, 5)) {
91 puts ("### No HW ID - assuming " BOARD_IDENTITY);
wdenk3bbc8992003-12-07 22:27:15 +000092 } 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 Bruce9973e3c2008-06-09 16:03:40 -0500131phys_size_t initdram (int board_type)
wdenk3bbc8992003-12-07 22:27:15 +0000132{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200133 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
wdenk3bbc8992003-12-07 22:27:15 +0000134 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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200142 memctl->memc_mptpr = CONFIG_SYS_MPTPR;
wdenk3bbc8992003-12-07 22:27:15 +0000143
144 /*
145 * Map controller bank 1 to the SDRAM address
146 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200147 memctl->memc_or1 = CONFIG_SYS_OR1;
148 memctl->memc_br1 = CONFIG_SYS_BR1;
wdenk3bbc8992003-12-07 22:27:15 +0000149 udelay(1000);
150
151 /* perform SDRAM initialization sequence */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200152 memctl->memc_mamr = CONFIG_SYS_16M_MAMR;
wdenk3bbc8992003-12-07 22:27:15 +0000153 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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200179 size = dram_size(CONFIG_SYS_32M_MAMR|MAMR_PTAE,
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200180 (long *)SDRAM_BASE, SDRAM_32M_MAX_SIZE);
wdenk3bbc8992003-12-07 22:27:15 +0000181 udelay (1000);
182
183 /*
184 * Check for 16M SDRAM Memory Size
185 */
186 if (size != SDRAM_32M_MAX_SIZE) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200187 size = dram_size(CONFIG_SYS_16M_MAMR|MAMR_PTAE,
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200188 (long *)SDRAM_BASE, SDRAM_16M_MAX_SIZE);
wdenk3bbc8992003-12-07 22:27:15 +0000189 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
206static long int dram_size (long int mamr_value, long int *base, long int maxsize)
207{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200208 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
wdenk3bbc8992003-12-07 22:27:15 +0000209 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenk3bbc8992003-12-07 22:27:15 +0000210
211 memctl->memc_mamr = mamr_value;
212
wdenkc83bf6a2004-01-06 22:38:14 +0000213 return (get_ram_size(base, maxsize));
wdenk3bbc8992003-12-07 22:27:15 +0000214}