blob: 5881111c70e7c43bfcf6fdc0eb568757fe7b6742 [file] [log] [blame]
wdenk682011f2003-06-03 23:54:09 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk682011f2003-06-03 23:54:09 +00006 */
7
8#include <common.h>
9#include "mpc8xx.h"
10#include <linux/mtd/doc2000.h>
11
12extern int kbd_init(void);
13extern int drv_kbd_init(void);
14
15/* ------------------------------------------------------------------------- */
16
17static long int dram_size (long int, long int *, long int);
18
19/* ------------------------------------------------------------------------- */
20
21#define _NOT_USED_ 0xFFFFFFFF
22
23const 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
73const 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 Denk93e14592013-10-04 17:43:24 +020081 _NOT_USED_, _NOT_USED_,
wdenk682011f2003-06-03 23:54:09 +000082 _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
112int checkboard (void)
113{
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000114 char buf[64];
115 int i = getenv_f("serial#", buf, sizeof(buf));
wdenk682011f2003-06-03 23:54:09 +0000116
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000117 if (i < 0 || strncmp(buf, "TQM8", 4)) {
wdenkc83bf6a2004-01-06 22:38:14 +0000118 printf ("### No HW ID - assuming RBC823\n");
119 return (0);
120 }
121
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000122 puts(buf);
123 putc('\n');
wdenkc83bf6a2004-01-06 22:38:14 +0000124
wdenk682011f2003-06-03 23:54:09 +0000125 return (0);
wdenk682011f2003-06-03 23:54:09 +0000126}
127
128/* ------------------------------------------------------------------------- */
129
Becky Bruce9973e3c2008-06-09 16:03:40 -0500130phys_size_t initdram (int board_type)
wdenk682011f2003-06-03 23:54:09 +0000131{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200132 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenkc83bf6a2004-01-06 22:38:14 +0000133 volatile memctl8xx_t *memctl = &immap->im_memctl;
134 long int size_b0, size8, size9;
wdenk682011f2003-06-03 23:54:09 +0000135
wdenkc83bf6a2004-01-06 22:38:14 +0000136 upmconfig (UPMA, (uint *) sdram_table,
137 sizeof (sdram_table) / sizeof (uint));
wdenk682011f2003-06-03 23:54:09 +0000138
wdenkc83bf6a2004-01-06 22:38:14 +0000139 /*
140 * 1 Bank of 64Mbit x 2 devices
141 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200142 memctl->memc_mptpr = CONFIG_SYS_MPTPR_1BK_4K;
wdenkc83bf6a2004-01-06 22:38:14 +0000143 memctl->memc_mar = 0x00000088;
wdenk682011f2003-06-03 23:54:09 +0000144
wdenkc83bf6a2004-01-06 22:38:14 +0000145 /*
146 * Map controller SDRAM bank 0
147 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200148 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 */
wdenkc83bf6a2004-01-06 22:38:14 +0000151 udelay (200);
wdenk682011f2003-06-03 23:54:09 +0000152
wdenkc83bf6a2004-01-06 22:38:14 +0000153 /*
154 * Perform SDRAM initializsation sequence
155 */
156 memctl->memc_mcr = 0x80008105; /* SDRAM bank 0 */
157 udelay (1);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200158 memctl->memc_mamr = (CONFIG_SYS_MAMR_8COL & ~(MAMR_TLFA_MSK)) | MAMR_TLFA_8X;
wdenkc83bf6a2004-01-06 22:38:14 +0000159 udelay (200);
160 memctl->memc_mcr = 0x80008130; /* SDRAM bank 0 - execute twice */
161 udelay (1);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200162 memctl->memc_mamr = (CONFIG_SYS_MAMR_8COL & ~(MAMR_TLFA_MSK)) | MAMR_TLFA_4X;
wdenkc83bf6a2004-01-06 22:38:14 +0000163 udelay (200);
wdenk682011f2003-06-03 23:54:09 +0000164
wdenkc83bf6a2004-01-06 22:38:14 +0000165 memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
166 udelay (1000);
wdenk682011f2003-06-03 23:54:09 +0000167
wdenkc83bf6a2004-01-06 22:38:14 +0000168 /*
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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200174 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K; /* 16: but should be: CONFIG_SYS_MPTPR_1BK_4K */
wdenk682011f2003-06-03 23:54:09 +0000175
wdenkc83bf6a2004-01-06 22:38:14 +0000176 /*
177 * Check Bank 0 Memory Size for re-configuration
178 *
179 * try 8 column mode
180 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200181 size8 = dram_size (CONFIG_SYS_MAMR_8COL, (long *) SDRAM_BASE4_PRELIM,
wdenkc83bf6a2004-01-06 22:38:14 +0000182 SDRAM_MAX_SIZE);
183 udelay (1000);
wdenk682011f2003-06-03 23:54:09 +0000184
wdenkc83bf6a2004-01-06 22:38:14 +0000185 /*
186 * try 9 column mode
187 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200188 size9 = dram_size (CONFIG_SYS_MAMR_9COL, (long *) SDRAM_BASE4_PRELIM,
wdenkc83bf6a2004-01-06 22:38:14 +0000189 SDRAM_MAX_SIZE);
wdenk682011f2003-06-03 23:54:09 +0000190
wdenkc83bf6a2004-01-06 22:38:14 +0000191 if (size8 < size9) { /* leave configuration at 9 columns */
192 size_b0 = size9;
wdenk682011f2003-06-03 23:54:09 +0000193/* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */
wdenkc83bf6a2004-01-06 22:38:14 +0000194 } else { /* back to 8 columns */
195 size_b0 = size8;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200196 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL;
wdenkc83bf6a2004-01-06 22:38:14 +0000197 udelay (500);
wdenk682011f2003-06-03 23:54:09 +0000198/* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */
wdenkc83bf6a2004-01-06 22:38:14 +0000199 }
wdenk682011f2003-06-03 23:54:09 +0000200
wdenkc83bf6a2004-01-06 22:38:14 +0000201 udelay (1000);
wdenk682011f2003-06-03 23:54:09 +0000202
wdenkc83bf6a2004-01-06 22:38:14 +0000203 /*
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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200209 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K;
wdenkc83bf6a2004-01-06 22:38:14 +0000210 udelay (1000);
211 }
wdenk682011f2003-06-03 23:54:09 +0000212
wdenkc83bf6a2004-01-06 22:38:14 +0000213 /* SDRAM Bank 0 is bigger - map first */
wdenk682011f2003-06-03 23:54:09 +0000214
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200215 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;
wdenk682011f2003-06-03 23:54:09 +0000217
wdenkc83bf6a2004-01-06 22:38:14 +0000218 udelay (10000);
wdenk682011f2003-06-03 23:54:09 +0000219
wdenkc83bf6a2004-01-06 22:38:14 +0000220 return (size_b0);
wdenk682011f2003-06-03 23:54:09 +0000221}
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
wdenkc83bf6a2004-01-06 22:38:14 +0000233static long int dram_size (long int mamr_value, long int *base,
234 long int maxsize)
wdenk682011f2003-06-03 23:54:09 +0000235{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200236 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenkc83bf6a2004-01-06 22:38:14 +0000237 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenk682011f2003-06-03 23:54:09 +0000238
wdenkc83bf6a2004-01-06 22:38:14 +0000239 memctl->memc_mamr = mamr_value;
wdenk682011f2003-06-03 23:54:09 +0000240
wdenkc83bf6a2004-01-06 22:38:14 +0000241 return (get_ram_size (base, maxsize));
wdenk682011f2003-06-03 23:54:09 +0000242}
243
Wolfgang Denk7640f412009-07-19 19:37:24 +0200244#ifdef CONFIG_CMD_DOC
wdenkc83bf6a2004-01-06 22:38:14 +0000245void doc_init (void)
wdenk682011f2003-06-03 23:54:09 +0000246{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200247 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenkc83bf6a2004-01-06 22:38:14 +0000248 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenk682011f2003-06-03 23:54:09 +0000249
wdenkc83bf6a2004-01-06 22:38:14 +0000250 upmconfig (UPMB, (uint *) static_table,
251 sizeof (static_table) / sizeof (uint));
252 memctl->memc_mbmr = MAMR_DSA_1_CYCL;
wdenk682011f2003-06-03 23:54:09 +0000253
wdenkc83bf6a2004-01-06 22:38:14 +0000254 doc_probe (FLASH_BASE1_PRELIM);
wdenk682011f2003-06-03 23:54:09 +0000255}
Wolfgang Denk7640f412009-07-19 19:37:24 +0200256#endif