blob: 4e844ba432677540b74fc295b2c7aee9a72d7f72 [file] [log] [blame]
Mike Frysinger4de1a5d2009-02-22 16:26:35 -05001/*
2 * BF537-STAMP POST code
3 *
4 * Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (c) 2005-2009 Analog Devices Inc.
7 *
8 * Licensed under the GPL-2 or later.
9 */
10
11#include <common.h>
12#include <config.h>
13#include <command.h>
14#include <asm/blackfin.h>
15
16#define POST_WORD_ADDR 0xFF903FFC
17
18/* Using sw10-PF5 as the hotkey */
19int post_hotkeys_pressed(void)
20{
21 int delay = 3;
22 int i;
23 unsigned short value;
24
25 *pPORTF_FER &= ~PF5;
26 *pPORTFIO_DIR &= ~PF5;
27 *pPORTFIO_INEN |= PF5;
28
29 printf("########Press SW10 to enter Memory POST########: %2d ", delay);
30 while (delay--) {
31 for (i = 0; i < 100; i++) {
32 value = *pPORTFIO & PF5;
33 if (value != 0) {
34 break;
35 }
36 udelay(10000);
37 }
38 printf("\b\b\b%2d ", delay);
39 }
40 printf("\b\b\b 0");
41 printf("\n");
42 if (value == 0)
43 return 0;
44 else {
45 printf("Hotkey has been pressed, Enter POST . . . . . .\n");
46 return 1;
47 }
48}
49
50void post_word_store(ulong a)
51{
52 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
53 *save_addr = a;
54}
55
56ulong post_word_load(void)
57{
58 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
59 return *save_addr;
60}
61
62int uart_post_test(int flags)
63{
64 return 0;
65}
66
67#define BLOCK_SIZE 0x10000
68#define VERIFY_ADDR 0x2000000
69extern int erase_block_flash(int);
70extern int write_data(long lStart, long lCount, uchar * pnData);
71int flash_post_test(int flags)
72{
73 unsigned short *pbuf, *temp;
74 int offset, n, i;
75 int value = 0;
76 int result = 0;
77 printf("\n");
78 pbuf = (unsigned short *)VERIFY_ADDR;
79 temp = pbuf;
80 for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
81 offset = (n - 7) * BLOCK_SIZE;
82 printf("--------Erase block:%2d..", n);
83 erase_block_flash(n);
84 printf("OK\r");
85 printf("--------Program block:%2d...", n);
86 write_data(CONFIG_SYS_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
87 printf("OK\r");
88 printf("--------Verify block:%2d...", n);
89 for (i = 0; i < BLOCK_SIZE; i += 2) {
90 if (*(unsigned short *)(CONFIG_SYS_FLASH_BASE + offset + i) !=
91 *temp++) {
92 value = 1;
93 result = 1;
94 }
95 }
96 if (value)
97 printf("failed\n");
98 else
99 printf("OK %3d%%\r",
100 (int)(
101 (n + 1 -
102 FLASH_START_POST_BLOCK) *
103 100 / (FLASH_END_POST_BLOCK -
104 FLASH_START_POST_BLOCK)));
105
106 temp = pbuf;
107 value = 0;
108 }
109 printf("\n");
110 if (result)
111 return -1;
112 else
113 return 0;
114}
115
116/****************************************************
117 * LED1 ---- PF6 LED2 ---- PF7 *
118 * LED3 ---- PF8 LED4 ---- PF9 *
119 * LED5 ---- PF10 LED6 ---- PF11 *
120 ****************************************************/
121int led_post_test(int flags)
122{
123 *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
124 *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
125 *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
126 *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
127 udelay(1000000);
128 printf("LED1 on");
129 *pPORTFIO |= PF6;
130 udelay(1000000);
131 printf("\b\b\b\b\b\b\b");
132 printf("LED2 on");
133 *pPORTFIO |= PF7;
134 udelay(1000000);
135 printf("\b\b\b\b\b\b\b");
136 printf("LED3 on");
137 *pPORTFIO |= PF8;
138 udelay(1000000);
139 printf("\b\b\b\b\b\b\b");
140 printf("LED4 on");
141 *pPORTFIO |= PF9;
142 udelay(1000000);
143 printf("\b\b\b\b\b\b\b");
144 printf("LED5 on");
145 *pPORTFIO |= PF10;
146 udelay(1000000);
147 printf("\b\b\b\b\b\b\b");
148 printf("lED6 on");
149 *pPORTFIO |= PF11;
150 printf("\b\b\b\b\b\b\b ");
151 return 0;
152}
153
154/************************************************
155 * SW10 ---- PF5 SW11 ---- PF4 *
156 * SW12 ---- PF3 SW13 ---- PF2 *
157 ************************************************/
158int button_post_test(int flags)
159{
160 int i, delay = 5;
161 unsigned short value = 0;
162 int result = 0;
163
164 *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
165 *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
166 *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
167
168 printf("\n--------Press SW10: %2d ", delay);
169 while (delay--) {
170 for (i = 0; i < 100; i++) {
171 value = *pPORTFIO & PF5;
172 if (value != 0) {
173 break;
174 }
175 udelay(10000);
176 }
177 printf("\b\b\b%2d ", delay);
178 }
179 if (value != 0)
180 printf("\b\bOK");
181 else {
182 result = -1;
183 printf("\b\bfailed");
184 }
185
186 delay = 5;
187 printf("\n--------Press SW11: %2d ", delay);
188 while (delay--) {
189 for (i = 0; i < 100; i++) {
190 value = *pPORTFIO & PF4;
191 if (value != 0) {
192 break;
193 }
194 udelay(10000);
195 }
196 printf("\b\b\b%2d ", delay);
197 }
198 if (value != 0)
199 printf("\b\bOK");
200 else {
201 result = -1;
202 printf("\b\bfailed");
203 }
204
205 delay = 5;
206 printf("\n--------Press SW12: %2d ", delay);
207 while (delay--) {
208 for (i = 0; i < 100; i++) {
209 value = *pPORTFIO & PF3;
210 if (value != 0) {
211 break;
212 }
213 udelay(10000);
214 }
215 printf("\b\b\b%2d ", delay);
216 }
217 if (value != 0)
218 printf("\b\bOK");
219 else {
220 result = -1;
221 printf("\b\bfailed");
222 }
223
224 delay = 5;
225 printf("\n--------Press SW13: %2d ", delay);
226 while (delay--) {
227 for (i = 0; i < 100; i++) {
228 value = *pPORTFIO & PF2;
229 if (value != 0) {
230 break;
231 }
232 udelay(10000);
233 }
234 printf("\b\b\b%2d ", delay);
235 }
236 if (value != 0)
237 printf("\b\bOK");
238 else {
239 result = -1;
240 printf("\b\bfailed");
241 }
242 printf("\n");
243 return result;
244}