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 performs testing of FPGA SCRATCH register,
27 * gets FPGA version and run get_ram_size() on FPGA memory
34 DECLARE_GLOBAL_DATA_PTR;
36 #define FPGA_SCRATCH_REG 0xC4000050
37 #define FPGA_VERSION_REG 0xC4000040
38 #define FPGA_RAM_START 0xC4200000
39 #define FPGA_RAM_END 0xC4203FFF
40 #define FPGA_STAT 0xC400000C
42 #if CONFIG_POST & CONFIG_SYS_POST_BSPEC3
44 /* Testpattern for fpga memorytest */
45 static uint pattern[] = {
53 static int one_scratch_test(uint value)
58 out_be32((void *)FPGA_SCRATCH_REG, value);
59 /* read other location (protect against data lines capacity) */
60 ret = in_be16((void *)FPGA_VERSION_REG);
61 /* verify test pattern */
62 read_value = in_be32((void *)FPGA_SCRATCH_REG);
63 if (read_value != value) {
64 post_log("FPGA SCRATCH test failed write %08X, read %08X\n",
72 /* FPGA Memory-pattern-test */
73 static int fpga_mem_test(void * address)
80 old_value = in_be32(address);
82 while (pattern[i] != 0) {
83 out_be32(address, pattern[i]);
84 /* read other location (protect against data lines capacity) */
85 ret = in_be16((void *)FPGA_VERSION_REG);
86 /* verify test pattern */
87 read_value = in_be32(address);
89 if (read_value != pattern[i]) {
90 post_log("FPGA Memory test failed.");
91 post_log(" write %08X, read %08X at address %08X\n",
92 pattern[i], read_value, address);
101 out_be32(address, old_value);
104 /* Verify FPGA, get version & memory size */
105 int fpga_post_test(int flags)
114 old_value = in_be32((void *)FPGA_SCRATCH_REG);
116 if (one_scratch_test(0x55555555))
118 if (one_scratch_test(0xAAAAAAAA))
121 out_be32((void *)FPGA_SCRATCH_REG, old_value);
123 version = in_be16((void *)FPGA_VERSION_REG);
124 post_log("FPGA : version %u.%u\n",
125 (version >> 8) & 0xFF, version & 0xFF);
127 /* Enable write to FPGA RAM */
128 out_be32((void *)FPGA_STAT, in_be32((void *)FPGA_STAT) | 0x1000);
130 read_value = get_ram_size((void *)CONFIG_SYS_FPGA_BASE_1, 0x4000);
131 post_log("FPGA RAM size: %d bytes\n", read_value);
133 for (address = 0; address < 0x1000; address++) {
134 if (fpga_mem_test((void *)(FPGA_RAM_START + 4*address)) == 1) {
144 #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC3 */