blob: 7108ddae4506922f9cb88b525c4bc70c128cdbc7 [file] [log] [blame]
Aubrey.Li3f0606a2007-03-09 13:38:44 +08001/*
Mike Frysinger23fd9592008-10-11 22:40:22 -04002 * U-boot - main board file
Aubrey.Li3f0606a2007-03-09 13:38:44 +08003 *
Mike Frysinger23fd9592008-10-11 22:40:22 -04004 * Copyright (c) 2005-2008 Analog Devices Inc.
Aubrey.Li3f0606a2007-03-09 13:38:44 +08005 *
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
Aubrey Li155fd762007-04-05 18:31:18 +080024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 * MA 02110-1301 USA
Aubrey.Li3f0606a2007-03-09 13:38:44 +080026 */
27
28#include <common.h>
Aubrey Li8440bb12007-03-12 00:25:14 +080029#include <asm/io.h>
Aubrey.Li3f0606a2007-03-09 13:38:44 +080030#include "bf533-stamp.h"
31
Wolfgang Denk1218abf2007-09-15 20:48:41 +020032DECLARE_GLOBAL_DATA_PTR;
33
Aubrey.Li3f0606a2007-03-09 13:38:44 +080034int checkboard(void)
35{
Aubrey.Li3f0606a2007-03-09 13:38:44 +080036 printf("Board: ADI BF533 Stamp board\n");
37 printf(" Support: http://blackfin.uclinux.org/\n");
38 return 0;
39}
40
Becky Bruce9973e3c2008-06-09 16:03:40 -050041phys_size_t initdram(int board_type)
Aubrey.Li3f0606a2007-03-09 13:38:44 +080042{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020043 gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
44 gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
Mike Frysinger41f33252008-10-11 20:31:17 -040045 return gd->bd->bi_memsize;
Aubrey.Li3f0606a2007-03-09 13:38:44 +080046}
47
Mike Frysinger1f75d6f2008-10-11 22:38:37 -040048/* PF0 and PF1 are used to switch between the ethernet and flash:
49 * PF0 PF1
50 * flash: 0 0
51 * ether: 1 0
52 */
Aubrey.Li3f0606a2007-03-09 13:38:44 +080053void swap_to(int device_id)
54{
Mike Frysinger1f75d6f2008-10-11 22:38:37 -040055 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();
Aubrey.Li3f0606a2007-03-09 13:38:44 +080065}
66
67#if defined(CONFIG_MISC_INIT_R)
68/* miscellaneous platform dependent initialisations */
69int 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
Aubrey.Li3f0606a2007-03-09 13:38:44 +080092 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
115void 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;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500123 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800124
125 *(addr) = val;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500126 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800127
128 /* Setback PF1 PF0 to 0 0 to address external
129 * memory banks */
130 *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500131 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800132}
133
134unsigned 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;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500140 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800141
142 c = *(addr);
Mike Frysingerd4d77302008-02-04 19:26:55 -0500143 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800144
145 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500146 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800147
148 return c;
149}
150
151void 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;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500157 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800158
159 for (i = 0; i < words; i++) {
160 *(sect_buf + i) = *(addr);
Mike Frysingerd4d77302008-02-04 19:26:55 -0500161 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800162 }
163
164 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500165 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800166}
167
168void 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;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500174 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800175
176 for (i = 0; i < words; i++) {
177 *(addr) = *(sect_buf + i);
Mike Frysingerd4d77302008-02-04 19:26:55 -0500178 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800179 }
180
181 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500182 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800183}
184#endif
185
Mike Frysinger23fd9592008-10-11 22:40:22 -0400186#ifdef CONFIG_SHOW_BOOT_PROGRESS
187
188#define STATUS_LED_OFF 0
189#define STATUS_LED_ON 1
190
191static void stamp_led_set(int LED1, int LED2, int LED3)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800192{
Mike Frysinger23fd9592008-10-11 22:40:22 -0400193 bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
194 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800195
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;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500208 SSYNC();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800209}
210
211void 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}
Mike Frysinger23fd9592008-10-11 22:40:22 -0400248#endif
249
250#ifdef CONFIG_STATUS_LED
251#include <status_led.h>
252
253static 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
262static 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
269void __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
275void __led_set(led_id_t mask, int state)
276{
277 set_leds(mask, state);
278}
279
280void __led_toggle(led_id_t mask)
281{
282 set_leds(mask, STATUS_LED_BLINKING);
283}
284
285#endif