]> git.sur5r.net Git - u-boot/blob - board/bf537-stamp/post.c
Blackfin: bf537-stamp: convert to gpio post hotkey
[u-boot] / board / bf537-stamp / post.c
1 /*
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 #include <asm/gpio.h>
16
17 int uart_post_test(int flags)
18 {
19         return 0;
20 }
21
22 #define BLOCK_SIZE 0x10000
23 #define VERIFY_ADDR 0x2000000
24 extern int erase_block_flash(int);
25 extern int write_data(long lStart, long lCount, uchar * pnData);
26 int flash_post_test(int flags)
27 {
28         unsigned short *pbuf, *temp;
29         int offset, n, i;
30         int value = 0;
31         int result = 0;
32         printf("\n");
33         pbuf = (unsigned short *)VERIFY_ADDR;
34         temp = pbuf;
35         for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
36                 offset = (n - 7) * BLOCK_SIZE;
37                 printf("--------Erase   block:%2d..", n);
38                 erase_block_flash(n);
39                 printf("OK\r");
40                 printf("--------Program block:%2d...", n);
41                 write_data(CONFIG_SYS_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
42                 printf("OK\r");
43                 printf("--------Verify  block:%2d...", n);
44                 for (i = 0; i < BLOCK_SIZE; i += 2) {
45                         if (*(unsigned short *)(CONFIG_SYS_FLASH_BASE + offset + i) !=
46                             *temp++) {
47                                 value = 1;
48                                 result = 1;
49                         }
50                 }
51                 if (value)
52                         printf("failed\n");
53                 else
54                         printf("OK              %3d%%\r",
55                                (int)(
56                                      (n + 1 -
57                                       FLASH_START_POST_BLOCK) *
58                                      100 / (FLASH_END_POST_BLOCK -
59                                             FLASH_START_POST_BLOCK)));
60
61                 temp = pbuf;
62                 value = 0;
63         }
64         printf("\n");
65         if (result)
66                 return -1;
67         else
68                 return 0;
69 }
70
71 /****************************************************
72  * LED1 ---- PF6        LED2 ---- PF7               *
73  * LED3 ---- PF8        LED4 ---- PF9               *
74  * LED5 ---- PF10       LED6 ---- PF11              *
75  ****************************************************/
76 int led_post_test(int flags)
77 {
78         unsigned int leds[] = {
79                 GPIO_PF6, GPIO_PF7, GPIO_PF8,
80                 GPIO_PF9, GPIO_PF10, GPIO_PF11,
81         };
82         int i;
83
84         for (i = 0; i < ARRAY_SIZE(leds); ++i) {
85                 gpio_request(leds[i], "post");
86                 gpio_direction_output(leds[i], 0);
87
88                 printf("LED%i on", i + 1);
89                 gpio_set_value(leds[i], 1);
90                 udelay(1000000);
91                 printf("\b\b\b\b\b\b\b");
92
93                 gpio_free(leds[i]);
94         }
95
96         return 0;
97 }
98
99 /************************************************
100  *  SW10 ---- PF5       SW11 ---- PF4           *
101  *  SW12 ---- PF3       SW13 ---- PF2           *
102  ************************************************/
103 int button_post_test(int flags)
104 {
105         unsigned int buttons[] = {
106                 GPIO_PF2, GPIO_PF3, GPIO_PF4, GPIO_PF5,
107         };
108         unsigned int sws[] = { 13, 12, 11, 10, };
109         int i, delay = 5;
110         unsigned short value = 0;
111         int result = 0;
112
113         for (i = 0; i < ARRAY_SIZE(buttons); ++i) {
114                 gpio_request(buttons[i], "post");
115                 gpio_direction_input(buttons[i]);
116
117                 delay = 5;
118                 printf("\n--------Press SW%i: %2d ", sws[i], delay);
119                 while (delay--) {
120                         for (i = 0; i < 100; i++) {
121                                 value = gpio_get_value(buttons[i]);
122                                 if (value != 0)
123                                         break;
124                                 udelay(10000);
125                         }
126                         printf("\b\b\b%2d ", delay);
127                 }
128                 if (value != 0)
129                         puts("\b\bOK");
130                 else {
131                         result = -1;
132                         puts("\b\bfailed");
133                 }
134
135                 gpio_free(buttons[i]);
136         }
137
138         puts("\n");
139
140         return result;
141 }