]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/bf533-stamp/bf533-stamp.c
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / board / bf533-stamp / bf533-stamp.c
1 /*
2  * U-boot - main board file
3  *
4  * Copyright (c) 2005-2008 Analog Devices Inc.
5  *
6  * (C) Copyright 2000-2004
7  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25  * MA 02110-1301 USA
26  */
27
28 #include <common.h>
29 #include <asm/io.h>
30 #include "bf533-stamp.h"
31
32 DECLARE_GLOBAL_DATA_PTR;
33
34 int checkboard(void)
35 {
36         printf("Board: ADI BF533 Stamp board\n");
37         printf("       Support: http://blackfin.uclinux.org/\n");
38         return 0;
39 }
40
41 phys_size_t initdram(int board_type)
42 {
43         gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
44         gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
45         return gd->bd->bi_memsize;
46 }
47
48 /* PF0 and PF1 are used to switch between the ethernet and flash:
49  *         PF0  PF1
50  *  flash:  0    0
51  *  ether:  1    0
52  */
53 void swap_to(int device_id)
54 {
55         bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF1 | PF0);
56         SSYNC();
57         bfin_write_FIO_FLAG_C(PF1);
58         if (device_id == ETHERNET)
59                 bfin_write_FIO_FLAG_S(PF0);
60         else if (device_id == FLASH)
61                 bfin_write_FIO_FLAG_C(PF0);
62         else
63                 printf("Unknown device to switch\n");
64         SSYNC();
65 }
66
67 #if defined(CONFIG_MISC_INIT_R)
68 /* miscellaneous platform dependent initialisations */
69 int misc_init_r(void)
70 {
71         int i;
72         int cf_stat = 0;
73
74         /* Check whether CF card is inserted */
75         *pFIO_EDGE = FIO_EDGE_CF_BITS;
76         *pFIO_POLAR = FIO_POLAR_CF_BITS;
77         for (i = 0; i < 0x300; i++)
78                 asm("nop;");
79
80         if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
81                 cf_stat = 0;
82         } else {
83                 cf_stat = 1;
84         }
85
86         *pFIO_EDGE = FIO_EDGE_BITS;
87         *pFIO_POLAR = FIO_POLAR_BITS;
88
89         if (cf_stat) {
90                 printf("Booting from COMPACT flash\n");
91
92                 for (i = 0; i < 0x1000; i++)
93                         asm("nop;");
94                 for (i = 0; i < 0x1000; i++)
95                         asm("nop;");
96                 for (i = 0; i < 0x1000; i++)
97                         asm("nop;");
98
99                 serial_setbrg();
100                 ide_init();
101
102                 setenv("bootargs", "");
103                 setenv("bootcmd",
104                        "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
105         } else {
106                 printf("Booting from FLASH\n");
107         }
108
109         return 0;
110 }
111 #endif
112
113 #ifdef CONFIG_STAMP_CF
114
115 void cf_outb(unsigned char val, volatile unsigned char *addr)
116 {
117         /*
118          * Set PF1 PF0 respectively to 0 1 to divert address
119          * to the expansion memory banks
120          */
121         *pFIO_FLAG_S = CF_PF0;
122         *pFIO_FLAG_C = CF_PF1;
123         SSYNC();
124
125         *(addr) = val;
126         SSYNC();
127
128         /* Setback PF1 PF0 to 0 0 to address external
129          * memory banks  */
130         *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0;
131         SSYNC();
132 }
133
134 unsigned char cf_inb(volatile unsigned char *addr)
135 {
136         volatile unsigned char c;
137
138         *pFIO_FLAG_S = CF_PF0;
139         *pFIO_FLAG_C = CF_PF1;
140         SSYNC();
141
142         c = *(addr);
143         SSYNC();
144
145         *pFIO_FLAG_C = CF_PF1_PF0;
146         SSYNC();
147
148         return c;
149 }
150
151 void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
152 {
153         int i;
154
155         *pFIO_FLAG_S = CF_PF0;
156         *pFIO_FLAG_C = CF_PF1;
157         SSYNC();
158
159         for (i = 0; i < words; i++) {
160                 *(sect_buf + i) = *(addr);
161                 SSYNC();
162         }
163
164         *pFIO_FLAG_C = CF_PF1_PF0;
165         SSYNC();
166 }
167
168 void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
169 {
170         int i;
171
172         *pFIO_FLAG_S = CF_PF0;
173         *pFIO_FLAG_C = CF_PF1;
174         SSYNC();
175
176         for (i = 0; i < words; i++) {
177                 *(addr) = *(sect_buf + i);
178                 SSYNC();
179         }
180
181         *pFIO_FLAG_C = CF_PF1_PF0;
182         SSYNC();
183 }
184 #endif
185
186 #ifdef CONFIG_SHOW_BOOT_PROGRESS
187
188 #define STATUS_LED_OFF 0
189 #define STATUS_LED_ON  1
190
191 static void stamp_led_set(int LED1, int LED2, int LED3)
192 {
193         bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
194         bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
195
196         if (LED1 == STATUS_LED_OFF)
197                 *pFIO_FLAG_S = PF2;
198         else
199                 *pFIO_FLAG_C = PF2;
200         if (LED2 == STATUS_LED_OFF)
201                 *pFIO_FLAG_S = PF3;
202         else
203                 *pFIO_FLAG_C = PF3;
204         if (LED3 == STATUS_LED_OFF)
205                 *pFIO_FLAG_S = PF4;
206         else
207                 *pFIO_FLAG_C = PF4;
208         SSYNC();
209 }
210
211 void show_boot_progress(int status)
212 {
213         switch (status) {
214         case 1:
215                 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
216                 break;
217         case 2:
218                 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
219                 break;
220         case 3:
221                 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
222                 break;
223         case 4:
224                 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
225                 break;
226         case 5:
227         case 6:
228                 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
229                 break;
230         case 7:
231         case 8:
232                 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
233                 break;
234         case 9:
235         case 10:
236         case 11:
237         case 12:
238         case 13:
239         case 14:
240         case 15:
241                 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF);
242                 break;
243         default:
244                 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
245                 break;
246         }
247 }
248 #endif
249
250 #ifdef CONFIG_STATUS_LED
251 #include <status_led.h>
252
253 static void set_led(int pf, int state)
254 {
255         switch (state) {
256                 case STATUS_LED_OFF:      bfin_write_FIO_FLAG_S(pf); break;
257                 case STATUS_LED_BLINKING: bfin_write_FIO_FLAG_T(pf); break;
258                 case STATUS_LED_ON:       bfin_write_FIO_FLAG_C(pf); break;
259         }
260 }
261
262 static void set_leds(led_id_t mask, int state)
263 {
264         if (mask & 0x1) set_led(PF2, state);
265         if (mask & 0x2) set_led(PF3, state);
266         if (mask & 0x4) set_led(PF4, state);
267 }
268
269 void __led_init(led_id_t mask, int state)
270 {
271         bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
272         bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
273 }
274
275 void __led_set(led_id_t mask, int state)
276 {
277         set_leds(mask, state);
278 }
279
280 void __led_toggle(led_id_t mask)
281 {
282         set_leds(mask, STATUS_LED_BLINKING);
283 }
284
285 #endif