]>
git.ipfire.org Git - people/ms/u-boot.git/blob - post/board/lwmon5/gdc.c
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
)
69 /* write test pattern */
70 out_be32((void *)GDC_SCRATCH_REG
, value
);
71 /* read other location (protect against data lines capacity) */
72 ret
= in_be32((void *)GDC_RAM_START
);
73 /* verify test pattern */
74 read_value
= in_be32((void *)GDC_SCRATCH_REG
);
75 if (read_value
!= value
) {
76 post_log("GDC SCRATCH test failed write %08X, read %08X\n",
80 return (read_value
!= value
);
83 /* test with a given static 32 bit pattern in a given memory addressrange */
84 static int gdc_post_test1(ulong
*start
, ulong size
, ulong val
)
91 for (i
= 0; i
< size
/ sizeof(ulong
); i
++) {
97 for (i
= 0; i
< size
/ sizeof(ulong
); i
++) {
99 if (readback
!= val
) {
100 post_log("GDC Memory error at %08x, "
101 "wrote %08x, read %08x !\n",
102 mem
+ i
, val
, readback
);
113 /* test with dynamic 32 bit pattern in a given memory addressrange */
114 static int gdc_post_test2(ulong
*start
, ulong size
)
121 for (i
= 0; i
< size
/ sizeof(ulong
); i
++) {
122 mem
[i
] = 1 << (i
% 32);
127 for (i
= 0; i
< size
/ sizeof(ulong
); i
++) {
129 if (readback
!= 1 << (i
% 32)) {
130 post_log("GDC Memory error at %08x, "
131 "wrote %08x, read %08x !\n",
132 mem
+ i
, 1 << (i
% 32), readback
);
143 /* test with dynamic 32 bit pattern in a given memory addressrange */
144 static int gdc_post_test3(ulong
*start
, ulong size
)
151 for (i
= 0; i
< size
/ sizeof(ulong
); i
++) {
157 for (i
= 0; i
< size
/ sizeof(ulong
); i
++) {
160 post_log("GDC Memory error at %08x, "
161 "wrote %08x, read %08x !\n",
162 mem
+ i
, i
, readback
);
173 /* test with dynamic 32 bit pattern in a given memory addressrange */
174 static int gdc_post_test4(ulong
*start
, ulong size
)
181 for (i
= 0; i
< size
/ sizeof(ulong
); i
++) {
187 for (i
= 0; i
< size
/ sizeof(ulong
); i
++) {
189 if (readback
!= ~i
) {
190 post_log("GDC Memory error at %08x, "
191 "wrote %08x, read %08x !\n",
192 mem
+ i
, ~i
, readback
);
203 /* do some patterntests in a given addressrange */
204 int gdc_mem_test(ulong
*start
, ulong size
)
209 * check addressrange and do different static and dynamic
210 * pattern tests with it.
212 if (((void *)start
) + size
<= (void *)GDC_RAM_END
) {
214 ret
= gdc_post_test1(start
, size
, 0x00000000);
217 ret
= gdc_post_test1(start
, size
, 0xffffffff);
220 ret
= gdc_post_test1(start
, size
, 0x55555555);
223 ret
= gdc_post_test1(start
, size
, 0xaaaaaaaa);
226 ret
= gdc_post_test2(start
, size
);
229 ret
= gdc_post_test3(start
, size
);
232 ret
= gdc_post_test4(start
, size
);
238 /* test function of gdc memory addresslines*/
239 static int gdc_post_addrline(ulong
*address
, ulong
*base
, ulong size
)
247 end
= (ulong
*)((ulong
)base
+ size
);
249 for (xor = sizeof(long); xor > 0; xor <<= 1) {
250 target
= (ulong
*)((ulong
)address
^ xor);
251 if ((target
>= base
) && (target
< end
)) {
256 if (readback
== *address
) {
257 post_log("GDC Memory (address line) error at %08x"
258 "XOR value %08x !\n",
259 address
, target
, xor);
268 static int gdc_post_dataline(ulong
*address
)
270 unsigned long temp32
= 0;
274 for (i
= 0; i
< ARRAY_SIZE(pattern
); i
++) {
275 *address
= pattern
[i
];
277 * Put a different pattern on the data lines: otherwise they
278 * may float long enough to read back what we wrote.
280 *(address
+ 1) = otherpattern
;
283 if (temp32
!= pattern
[i
]){
284 post_log("GDC Memory (date line) error at %08x, "
285 "wrote %08x, read %08x !\n",
286 address
, pattern
[i
], temp32
);
294 /* Verify GDC, get memory size, verify GDC memory */
295 int gdc_post_test(int flags
)
302 old_value
= in_be32((void *)GDC_SCRATCH_REG
);
305 * GPIOC2 register behaviour: the LIME graphics processor has a
306 * maximum of 5 GPIO ports that can be used in this hardware
307 * configuration. Thus only the bits for these 5 GPIOs can be
308 * activated in the GPIOC2 register. All other bits will always be
311 if (gdc_test_reg_one(0x00150015))
313 if (gdc_test_reg_one(0x000A000A))
316 out_be32((void *)GDC_SCRATCH_REG
, old_value
);
318 old_value
= in_be32((void *)GDC_VERSION_REG
);
319 post_log("GDC chip version %u.%u, year %04X\n",
320 (old_value
>> 8) & 0xFF, old_value
& 0xFF,
321 (old_value
>> 16) & 0xFFFF);
323 old_value
= get_ram_size((void *)GDC_RAM_START
,
326 debug("GDC RAM size (ist): %d bytes\n", old_value
);
327 debug("GDC RAM size (soll): %d bytes\n", GDC_RAM_SIZE
);
328 post_log("GDC RAM size: %d bytes\n", old_value
);
330 /* Test SDRAM datalines */
331 if (gdc_post_dataline((ulong
*)GDC_RAM_START
)) {
337 /* Test SDRAM adresslines */
338 if (gdc_post_addrline((ulong
*)GDC_RAM_START
,
339 (ulong
*)GDC_RAM_START
, GDC_RAM_SIZE
)) {
344 if (gdc_post_addrline((ulong
*)GDC_RAM_END
- sizeof(long),
345 (ulong
*)GDC_RAM_START
, GDC_RAM_SIZE
)) {
351 /* memory pattern test */
352 debug("GDC Memory test (flags %8x:%8x)\n", flags
,
353 POST_SLOWTEST
| POST_MANUAL
);
355 if (flags
& POST_MANUAL
) {
356 debug("Full memory test\n");
357 if (gdc_mem_test((ulong
*)GDC_RAM_START
, GDC_RAM_SIZE
)) {
361 /* load splashscreen again */
363 debug("smart memory test\n");
364 for (i
= 0; i
< (GDC_RAM_SIZE
>> 20) && ret
== 0; i
++) {
366 ret
= gdc_mem_test((ulong
*)(GDC_RAM_START
+
370 ret
= gdc_mem_test((ulong
*)(GDC_RAM_START
+
371 (i
<< 20) + 0xff800),
380 #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC4 */