MINI2440: Add a command to re-init CFI NOR
[u-boot-openmoko/mini2440.git] / post / lib_ppc / load.c
blob393c56830d9d6cd4aa445df1880c629a30b6a8b0
1 /*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
6 * project.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
24 #include <common.h>
27 * CPU test
28 * Load instructions: lbz(x)(u), lhz(x)(u), lha(x)(u), lwz(x)(u)
30 * All operations are performed on a 16-byte array. The array
31 * is 4-byte aligned. The base register points to offset 8.
32 * The immediate offset (index register) ranges in [-8 ... +7].
33 * The test cases are composed so that they do not
34 * cause alignment exceptions.
35 * The test contains a pre-built table describing all test cases.
36 * The table entry contains:
37 * the instruction opcode, the array contents, the value of the index
38 * register and the expected value of the destination register.
39 * After executing the instruction, the test verifies the
40 * value of the destination register and the value of the base
41 * register (it must change for "load with update" instructions).
44 #ifdef CONFIG_POST
46 #include <post.h>
47 #include "cpu_asm.h"
49 #if CONFIG_POST & CFG_POST_CPU
51 extern void cpu_post_exec_22w (ulong *code, ulong *op1, ulong op2, ulong *op3);
52 extern void cpu_post_exec_21w (ulong *code, ulong *op1, ulong *op2);
54 static struct cpu_post_load_s
56 ulong cmd;
57 uint width;
58 int update;
59 int index;
60 ulong offset;
61 } cpu_post_load_table[] =
64 OP_LWZ,
71 OP_LHA,
78 OP_LHZ,
85 OP_LBZ,
92 OP_LWZU,
99 OP_LHAU,
106 OP_LHZU,
113 OP_LBZU,
120 OP_LWZX,
127 OP_LHAX,
134 OP_LHZX,
141 OP_LBZX,
148 OP_LWZUX,
155 OP_LHAUX,
162 OP_LHZUX,
169 OP_LBZUX,
176 static unsigned int cpu_post_load_size =
177 sizeof (cpu_post_load_table) / sizeof (struct cpu_post_load_s);
179 int cpu_post_test_load (void)
181 int ret = 0;
182 unsigned int i;
184 for (i = 0; i < cpu_post_load_size && ret == 0; i++)
186 struct cpu_post_load_s *test = cpu_post_load_table + i;
187 uchar data[16] =
188 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
189 ulong base0 = (ulong) (data + 8);
190 ulong base = base0;
191 ulong value;
193 if (test->index)
195 ulong code[] =
197 ASM_12(test->cmd, 5, 3, 4),
198 ASM_BLR,
201 cpu_post_exec_22w (code, &base, test->offset, &value);
203 else
205 ulong code[] =
207 ASM_11I(test->cmd, 4, 3, test->offset),
208 ASM_BLR,
211 cpu_post_exec_21w (code, &base, &value);
214 if (ret == 0)
216 if (test->update)
217 ret = base == base0 + test->offset ? 0 : -1;
218 else
219 ret = base == base0 ? 0 : -1;
222 if (ret == 0)
224 switch (test->width)
226 case 1:
227 ret = *(uchar *)(base0 + test->offset) == value ?
228 0 : -1;
229 break;
230 case 2:
231 ret = *(ushort *)(base0 + test->offset) == value ?
232 0 : -1;
233 break;
234 case 3:
235 ret = *(short *)(base0 + test->offset) == value ?
236 0 : -1;
237 break;
238 case 4:
239 ret = *(ulong *)(base0 + test->offset) == value ?
240 0 : -1;
241 break;
245 if (ret != 0)
247 post_log ("Error at load test %d !\n", i);
251 return ret;
254 #endif
255 #endif