blob: 1a073a659c3b9932d2a87c52cde8a537dee411ba [file] [log] [blame]
Aubrey.Li9da597f2007-03-09 13:38:44 +08001/*
2 * U-boot - stamp.c STAMP board specific routines
3 *
Aubrey Li314d22f2007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Aubrey.Li9da597f2007-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 Li314d22f2007-04-05 18:31:18 +080024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 * MA 02110-1301 USA
Aubrey.Li9da597f2007-03-09 13:38:44 +080026 */
27
28#include <common.h>
Aubrey Li3c569952007-03-12 00:25:14 +080029#include <asm/io.h>
Aubrey.Li9da597f2007-03-09 13:38:44 +080030#include "bf533-stamp.h"
31
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020032DECLARE_GLOBAL_DATA_PTR;
33
Aubrey.Li9da597f2007-03-09 13:38:44 +080034#define STATUS_LED_OFF 0
35#define STATUS_LED_ON 1
36
37#ifdef CONFIG_SHOW_BOOT_PROGRESS
38# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
39#else
40# define SHOW_BOOT_PROGRESS(arg)
41#endif
42
43int checkboard(void)
44{
Aubrey.Li9da597f2007-03-09 13:38:44 +080045 printf("Board: ADI BF533 Stamp board\n");
46 printf(" Support: http://blackfin.uclinux.org/\n");
47 return 0;
48}
49
Becky Brucebd99ae72008-06-09 16:03:40 -050050phys_size_t initdram(int board_type)
Aubrey.Li9da597f2007-03-09 13:38:44 +080051{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020052 gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
53 gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
Mike Frysinger9036bf92008-10-11 20:31:17 -040054 return gd->bd->bi_memsize;
Aubrey.Li9da597f2007-03-09 13:38:44 +080055}
56
57void swap_to(int device_id)
58{
59
60 if (device_id == ETHERNET) {
61 *pFIO_DIR = PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -050062 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +080063 *pFIO_FLAG_S = PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -050064 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +080065 } else if (device_id == FLASH) {
66 *pFIO_DIR = (PF4 | PF3 | PF2 | PF1 | PF0);
67 *pFIO_FLAG_S = (PF4 | PF3 | PF2);
68 *pFIO_MASKA_D = (PF8 | PF6 | PF5);
69 *pFIO_MASKB_D = (PF7);
70 *pFIO_POLAR = (PF8 | PF6 | PF5);
71 *pFIO_EDGE = (PF8 | PF7 | PF6 | PF5);
72 *pFIO_INEN = (PF8 | PF7 | PF6 | PF5);
73 *pFIO_FLAG_D = (PF4 | PF3 | PF2);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050074 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +080075 } else {
76 printf("Unknown bank to switch\n");
77 }
78
79 return;
80}
81
82#if defined(CONFIG_MISC_INIT_R)
83/* miscellaneous platform dependent initialisations */
84int misc_init_r(void)
85{
86 int i;
87 int cf_stat = 0;
88
89 /* Check whether CF card is inserted */
90 *pFIO_EDGE = FIO_EDGE_CF_BITS;
91 *pFIO_POLAR = FIO_POLAR_CF_BITS;
92 for (i = 0; i < 0x300; i++)
93 asm("nop;");
94
95 if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
96 cf_stat = 0;
97 } else {
98 cf_stat = 1;
99 }
100
101 *pFIO_EDGE = FIO_EDGE_BITS;
102 *pFIO_POLAR = FIO_POLAR_BITS;
103
104 if (cf_stat) {
105 printf("Booting from COMPACT flash\n");
106
107 /* Set cycle time for CF */
108 *(volatile unsigned long *)ambctl1 = CF_AMBCTL1VAL;
109
110 for (i = 0; i < 0x1000; i++)
111 asm("nop;");
112 for (i = 0; i < 0x1000; i++)
113 asm("nop;");
114 for (i = 0; i < 0x1000; i++)
115 asm("nop;");
116
117 serial_setbrg();
118 ide_init();
119
120 setenv("bootargs", "");
121 setenv("bootcmd",
122 "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
123 } else {
124 printf("Booting from FLASH\n");
125 }
126
127 return 0;
128}
129#endif
130
131#ifdef CONFIG_STAMP_CF
132
133void cf_outb(unsigned char val, volatile unsigned char *addr)
134{
135 /*
136 * Set PF1 PF0 respectively to 0 1 to divert address
137 * to the expansion memory banks
138 */
139 *pFIO_FLAG_S = CF_PF0;
140 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500141 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800142
143 *(addr) = val;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500144 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800145
146 /* Setback PF1 PF0 to 0 0 to address external
147 * memory banks */
148 *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500149 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800150}
151
152unsigned char cf_inb(volatile unsigned char *addr)
153{
154 volatile unsigned char c;
155
156 *pFIO_FLAG_S = CF_PF0;
157 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500158 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800159
160 c = *(addr);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500161 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800162
163 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500164 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800165
166 return c;
167}
168
169void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
170{
171 int i;
172
173 *pFIO_FLAG_S = CF_PF0;
174 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500175 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800176
177 for (i = 0; i < words; i++) {
178 *(sect_buf + i) = *(addr);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500179 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800180 }
181
182 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500183 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800184}
185
186void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
187{
188 int i;
189
190 *pFIO_FLAG_S = CF_PF0;
191 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500192 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800193
194 for (i = 0; i < words; i++) {
195 *(addr) = *(sect_buf + i);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500196 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800197 }
198
199 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500200 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800201}
202#endif
203
204void stamp_led_set(int LED1, int LED2, int LED3)
205{
206 *pFIO_INEN &= ~(PF2 | PF3 | PF4);
207 *pFIO_DIR |= (PF2 | PF3 | PF4);
208
209 if (LED1 == STATUS_LED_OFF)
210 *pFIO_FLAG_S = PF2;
211 else
212 *pFIO_FLAG_C = PF2;
213 if (LED2 == STATUS_LED_OFF)
214 *pFIO_FLAG_S = PF3;
215 else
216 *pFIO_FLAG_C = PF3;
217 if (LED3 == STATUS_LED_OFF)
218 *pFIO_FLAG_S = PF4;
219 else
220 *pFIO_FLAG_C = PF4;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500221 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800222}
223
224void show_boot_progress(int status)
225{
226 switch (status) {
227 case 1:
228 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
229 break;
230 case 2:
231 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
232 break;
233 case 3:
234 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
235 break;
236 case 4:
237 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
238 break;
239 case 5:
240 case 6:
241 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
242 break;
243 case 7:
244 case 8:
245 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
246 break;
247 case 9:
248 case 10:
249 case 11:
250 case 12:
251 case 13:
252 case 14:
253 case 15:
254 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF);
255 break;
256 default:
257 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
258 break;
259 }
260}