2 * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
4 * Developed for DENX Software Engineering GmbH
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 /* This test attempts to verify board GDC. A scratch register tested, then
27 * simple memory test (get_ram_size()) run over GDC memory.
35 DECLARE_GLOBAL_DATA_PTR;
37 #define GDC_SCRATCH_REG 0xC1FF8044
38 #define GDC_VERSION_REG 0xC1FF8084
39 #define GDC_HOST_BASE 0xC1FC0000
40 #define GDC_RAM_START 0xC0000000
41 #define GDC_RAM_END (GDC_HOST_BASE - 1)
42 #define GDC_RAM_SIZE (GDC_RAM_END - GDC_RAM_START)
44 #if CONFIG_POST & CONFIG_SYS_POST_BSPEC4
46 const static unsigned long pattern[] = {
61 const static unsigned long otherpattern = 0x01234567;
63 /* test write/read og a given LIME Register */
64 static int gdc_test_reg_one(uint value)
68 /* write test pattern */
69 out_be32((void *)GDC_SCRATCH_REG, value);
70 /* read other location (protect against data lines capacity) */
71 in_be32((void *)GDC_RAM_START);
72 /* verify test pattern */
73 read_value = in_be32((void *)GDC_SCRATCH_REG);
74 if (read_value != value) {
75 post_log("GDC SCRATCH test failed write %08X, read %08X\n",
79 return (read_value != value);
82 /* test with a given static 32 bit pattern in a given memory addressrange */
83 static int gdc_post_test1(ulong *start, ulong size, ulong val)
90 for (i = 0; i < size / sizeof(ulong); i++) {
96 for (i = 0; i < size / sizeof(ulong); i++) {
98 if (readback != val) {
99 post_log("GDC Memory error at %08x, "
100 "wrote %08x, read %08x !\n",
101 mem + i, val, readback);
112 /* test with dynamic 32 bit pattern in a given memory addressrange */
113 static int gdc_post_test2(ulong *start, ulong size)
120 for (i = 0; i < size / sizeof(ulong); i++) {
121 mem[i] = 1 << (i % 32);
126 for (i = 0; i < size / sizeof(ulong); i++) {
128 if (readback != 1 << (i % 32)) {
129 post_log("GDC Memory error at %08x, "
130 "wrote %08x, read %08x !\n",
131 mem + i, 1 << (i % 32), readback);
142 /* test with dynamic 32 bit pattern in a given memory addressrange */
143 static int gdc_post_test3(ulong *start, ulong size)
150 for (i = 0; i < size / sizeof(ulong); i++) {
156 for (i = 0; i < size / sizeof(ulong); i++) {
159 post_log("GDC Memory error at %08x, "
160 "wrote %08x, read %08x !\n",
161 mem + i, i, readback);
172 /* test with dynamic 32 bit pattern in a given memory addressrange */
173 static int gdc_post_test4(ulong *start, ulong size)
180 for (i = 0; i < size / sizeof(ulong); i++) {
186 for (i = 0; i < size / sizeof(ulong); i++) {
188 if (readback != ~i) {
189 post_log("GDC Memory error at %08x, "
190 "wrote %08x, read %08x !\n",
191 mem + i, ~i, readback);
202 /* do some patterntests in a given addressrange */
203 int gdc_mem_test(ulong *start, ulong size)
208 * check addressrange and do different static and dynamic
209 * pattern tests with it.
211 if (((void *)start) + size <= (void *)GDC_RAM_END) {
213 ret = gdc_post_test1(start, size, 0x00000000);
216 ret = gdc_post_test1(start, size, 0xffffffff);
219 ret = gdc_post_test1(start, size, 0x55555555);
222 ret = gdc_post_test1(start, size, 0xaaaaaaaa);
225 ret = gdc_post_test2(start, size);
228 ret = gdc_post_test3(start, size);
231 ret = gdc_post_test4(start, size);
237 /* test function of gdc memory addresslines*/
238 static int gdc_post_addrline(ulong *address, ulong *base, ulong size)
246 end = (ulong *)((ulong)base + size);
248 for (xor = sizeof(long); xor > 0; xor <<= 1) {
249 target = (ulong *)((ulong)address ^ xor);
250 if ((target >= base) && (target < end)) {
255 if (readback == *address) {
256 post_log("GDC Memory (address line) error at %08x"
257 "XOR value %08x !\n",
258 address, target , xor);
267 static int gdc_post_dataline(ulong *address)
269 unsigned long temp32 = 0;
273 for (i = 0; i < ARRAY_SIZE(pattern); i++) {
274 *address = pattern[i];
276 * Put a different pattern on the data lines: otherwise they
277 * may float long enough to read back what we wrote.
279 *(address + 1) = otherpattern;
282 if (temp32 != pattern[i]){
283 post_log("GDC Memory (date line) error at %08x, "
284 "wrote %08x, read %08x !\n",
285 address, pattern[i], temp32);
293 /* Verify GDC, get memory size, verify GDC memory */
294 int gdc_post_test(int flags)
301 old_value = in_be32((void *)GDC_SCRATCH_REG);
304 * GPIOC2 register behaviour: the LIME graphics processor has a
305 * maximum of 5 GPIO ports that can be used in this hardware
306 * configuration. Thus only the bits for these 5 GPIOs can be
307 * activated in the GPIOC2 register. All other bits will always be
310 if (gdc_test_reg_one(0x00150015))
312 if (gdc_test_reg_one(0x000A000A))
315 out_be32((void *)GDC_SCRATCH_REG, old_value);
317 old_value = in_be32((void *)GDC_VERSION_REG);
318 post_log("GDC chip version %u.%u, year %04X\n",
319 (old_value >> 8) & 0xFF, old_value & 0xFF,
320 (old_value >> 16) & 0xFFFF);
322 old_value = get_ram_size((void *)GDC_RAM_START,
325 debug("GDC RAM size (ist): %d bytes\n", old_value);
326 debug("GDC RAM size (soll): %d bytes\n", GDC_RAM_SIZE);
327 post_log("GDC RAM size: %d bytes\n", old_value);
329 /* Test SDRAM datalines */
330 if (gdc_post_dataline((ulong *)GDC_RAM_START)) {
336 /* Test SDRAM adresslines */
337 if (gdc_post_addrline((ulong *)GDC_RAM_START,
338 (ulong *)GDC_RAM_START, GDC_RAM_SIZE)) {
343 if (gdc_post_addrline((ulong *)GDC_RAM_END - sizeof(long),
344 (ulong *)GDC_RAM_START, GDC_RAM_SIZE)) {
350 /* memory pattern test */
351 debug("GDC Memory test (flags %8x:%8x)\n", flags,
352 POST_SLOWTEST | POST_MANUAL);
354 if (flags & POST_MANUAL) {
355 debug("Full memory test\n");
356 if (gdc_mem_test((ulong *)GDC_RAM_START, GDC_RAM_SIZE)) {
360 /* load splashscreen again */
362 debug("smart memory test\n");
363 for (i = 0; i < (GDC_RAM_SIZE >> 20) && ret == 0; i++) {
365 ret = gdc_mem_test((ulong *)(GDC_RAM_START +
369 ret = gdc_mem_test((ulong *)(GDC_RAM_START +
370 (i << 20) + 0xff800),
379 #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC4 */