]> 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 <netdev.h>
30 #include <asm/io.h>
31 #include "bf533-stamp.h"
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 int checkboard(void)
36 {
37         printf("Board: ADI BF533 Stamp board\n");
38         printf("       Support: http://blackfin.uclinux.org/\n");
39         return 0;
40 }
41
42 phys_size_t initdram(int board_type)
43 {
44         gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
45         gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
46         return gd->bd->bi_memsize;
47 }
48
49 /* PF0 and PF1 are used to switch between the ethernet and flash:
50  *         PF0  PF1
51  *  flash:  0    0
52  *  ether:  1    0
53  */
54 void swap_to(int device_id)
55 {
56         bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF1 | PF0);
57         SSYNC();
58         bfin_write_FIO_FLAG_C(PF1);
59         if (device_id == ETHERNET)
60                 bfin_write_FIO_FLAG_S(PF0);
61         else if (device_id == FLASH)
62                 bfin_write_FIO_FLAG_C(PF0);
63         else
64                 printf("Unknown device to switch\n");
65         SSYNC();
66 }
67
68 #if defined(CONFIG_MISC_INIT_R)
69 /* miscellaneous platform dependent initialisations */
70 int misc_init_r(void)
71 {
72         int i;
73         int cf_stat = 0;
74
75         /* Check whether CF card is inserted */
76         *pFIO_EDGE = FIO_EDGE_CF_BITS;
77         *pFIO_POLAR = FIO_POLAR_CF_BITS;
78         for (i = 0; i < 0x300; i++)
79                 asm("nop;");
80
81         if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
82                 cf_stat = 0;
83         } else {
84                 cf_stat = 1;
85         }
86
87         *pFIO_EDGE = FIO_EDGE_BITS;
88         *pFIO_POLAR = FIO_POLAR_BITS;
89
90         if (cf_stat) {
91                 printf("Booting from COMPACT flash\n");
92
93                 for (i = 0; i < 0x1000; i++)
94                         asm("nop;");
95                 for (i = 0; i < 0x1000; i++)
96                         asm("nop;");
97                 for (i = 0; i < 0x1000; i++)
98                         asm("nop;");
99
100                 serial_setbrg();
101                 ide_init();
102
103                 setenv("bootargs", "");
104                 setenv("bootcmd",
105                        "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
106         } else {
107                 printf("Booting from FLASH\n");
108         }
109
110         return 0;
111 }
112 #endif
113
114 #ifdef CONFIG_STAMP_CF
115
116 void cf_outb(unsigned char val, volatile unsigned char *addr)
117 {
118         /*
119          * Set PF1 PF0 respectively to 0 1 to divert address
120          * to the expansion memory banks
121          */
122         *pFIO_FLAG_S = CF_PF0;
123         *pFIO_FLAG_C = CF_PF1;
124         SSYNC();
125
126         *(addr) = val;
127         SSYNC();
128
129         /* Setback PF1 PF0 to 0 0 to address external
130          * memory banks  */
131         *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0;
132         SSYNC();
133 }
134
135 unsigned char cf_inb(volatile unsigned char *addr)
136 {
137         volatile unsigned char c;
138
139         *pFIO_FLAG_S = CF_PF0;
140         *pFIO_FLAG_C = CF_PF1;
141         SSYNC();
142
143         c = *(addr);
144         SSYNC();
145
146         *pFIO_FLAG_C = CF_PF1_PF0;
147         SSYNC();
148
149         return c;
150 }
151
152 void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
153 {
154         int i;
155
156         *pFIO_FLAG_S = CF_PF0;
157         *pFIO_FLAG_C = CF_PF1;
158         SSYNC();
159
160         for (i = 0; i < words; i++) {
161                 *(sect_buf + i) = *(addr);
162                 SSYNC();
163         }
164
165         *pFIO_FLAG_C = CF_PF1_PF0;
166         SSYNC();
167 }
168
169 void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
170 {
171         int i;
172
173         *pFIO_FLAG_S = CF_PF0;
174         *pFIO_FLAG_C = CF_PF1;
175         SSYNC();
176
177         for (i = 0; i < words; i++) {
178                 *(addr) = *(sect_buf + i);
179                 SSYNC();
180         }
181
182         *pFIO_FLAG_C = CF_PF1_PF0;
183         SSYNC();
184 }
185 #endif
186
187 #ifdef CONFIG_SHOW_BOOT_PROGRESS
188
189 #define STATUS_LED_OFF 0
190 #define STATUS_LED_ON  1
191
192 static void stamp_led_set(int LED1, int LED2, int LED3)
193 {
194         bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
195         bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
196
197         if (LED1 == STATUS_LED_OFF)
198                 *pFIO_FLAG_S = PF2;
199         else
200                 *pFIO_FLAG_C = PF2;
201         if (LED2 == STATUS_LED_OFF)
202                 *pFIO_FLAG_S = PF3;
203         else
204                 *pFIO_FLAG_C = PF3;
205         if (LED3 == STATUS_LED_OFF)
206                 *pFIO_FLAG_S = PF4;
207         else
208                 *pFIO_FLAG_C = PF4;
209         SSYNC();
210 }
211
212 void show_boot_progress(int status)
213 {
214         switch (status) {
215         case 1:
216                 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
217                 break;
218         case 2:
219                 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
220                 break;
221         case 3:
222                 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
223                 break;
224         case 4:
225                 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
226                 break;
227         case 5:
228         case 6:
229                 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
230                 break;
231         case 7:
232         case 8:
233                 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
234                 break;
235         case 9:
236         case 10:
237         case 11:
238         case 12:
239         case 13:
240         case 14:
241         case 15:
242                 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF);
243                 break;
244         default:
245                 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
246                 break;
247         }
248 }
249 #endif
250
251 #ifdef CONFIG_STATUS_LED
252 #include <status_led.h>
253
254 static void set_led(int pf, int state)
255 {
256         switch (state) {
257                 case STATUS_LED_OFF:      bfin_write_FIO_FLAG_S(pf); break;
258                 case STATUS_LED_BLINKING: bfin_write_FIO_FLAG_T(pf); break;
259                 case STATUS_LED_ON:       bfin_write_FIO_FLAG_C(pf); break;
260         }
261 }
262
263 static void set_leds(led_id_t mask, int state)
264 {
265         if (mask & 0x1) set_led(PF2, state);
266         if (mask & 0x2) set_led(PF3, state);
267         if (mask & 0x4) set_led(PF4, state);
268 }
269
270 void __led_init(led_id_t mask, int state)
271 {
272         bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
273         bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
274 }
275
276 void __led_set(led_id_t mask, int state)
277 {
278         set_leds(mask, state);
279 }
280
281 void __led_toggle(led_id_t mask)
282 {
283         set_leds(mask, STATUS_LED_BLINKING);
284 }
285
286 #endif
287
288 #ifdef CONFIG_SMC91111
289 int board_eth_init(bd_t *bis)
290 {
291         return smc91111_initialize(0, CONFIG_SMC91111_BASE);
292 }
293 #endif