blob: 0c6324b4b673a8bd75d4a5d68cee7d87f6bb13a1 [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{
Aubrey.Li9da597f2007-03-09 13:38:44 +080052#ifdef DEBUG
53 printf("SDRAM attributes:\n");
54 printf
55 (" tRCD:%d Cycles; tRP:%d Cycles; tRAS:%d Cycles; tWR:%d Cycles; "
56 "CAS Latency:%d cycles\n", (SDRAM_tRCD >> 15), (SDRAM_tRP >> 11),
57 (SDRAM_tRAS >> 6), (SDRAM_tWR >> 19), (SDRAM_CL >> 2));
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020058 printf("SDRAM Begin: 0x%x\n", CONFIG_SYS_SDRAM_BASE);
Aubrey.Li9da597f2007-03-09 13:38:44 +080059 printf("Bank size = %d MB\n", 128);
60#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020061 gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
62 gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
Aubrey.Li9da597f2007-03-09 13:38:44 +080063 return (gd->bd->bi_memsize);
64}
65
66void swap_to(int device_id)
67{
68
69 if (device_id == ETHERNET) {
70 *pFIO_DIR = PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -050071 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +080072 *pFIO_FLAG_S = PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -050073 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +080074 } else if (device_id == FLASH) {
75 *pFIO_DIR = (PF4 | PF3 | PF2 | PF1 | PF0);
76 *pFIO_FLAG_S = (PF4 | PF3 | PF2);
77 *pFIO_MASKA_D = (PF8 | PF6 | PF5);
78 *pFIO_MASKB_D = (PF7);
79 *pFIO_POLAR = (PF8 | PF6 | PF5);
80 *pFIO_EDGE = (PF8 | PF7 | PF6 | PF5);
81 *pFIO_INEN = (PF8 | PF7 | PF6 | PF5);
82 *pFIO_FLAG_D = (PF4 | PF3 | PF2);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050083 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +080084 } else {
85 printf("Unknown bank to switch\n");
86 }
87
88 return;
89}
90
91#if defined(CONFIG_MISC_INIT_R)
92/* miscellaneous platform dependent initialisations */
93int misc_init_r(void)
94{
95 int i;
96 int cf_stat = 0;
97
98 /* Check whether CF card is inserted */
99 *pFIO_EDGE = FIO_EDGE_CF_BITS;
100 *pFIO_POLAR = FIO_POLAR_CF_BITS;
101 for (i = 0; i < 0x300; i++)
102 asm("nop;");
103
104 if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
105 cf_stat = 0;
106 } else {
107 cf_stat = 1;
108 }
109
110 *pFIO_EDGE = FIO_EDGE_BITS;
111 *pFIO_POLAR = FIO_POLAR_BITS;
112
113 if (cf_stat) {
114 printf("Booting from COMPACT flash\n");
115
116 /* Set cycle time for CF */
117 *(volatile unsigned long *)ambctl1 = CF_AMBCTL1VAL;
118
119 for (i = 0; i < 0x1000; i++)
120 asm("nop;");
121 for (i = 0; i < 0x1000; i++)
122 asm("nop;");
123 for (i = 0; i < 0x1000; i++)
124 asm("nop;");
125
126 serial_setbrg();
127 ide_init();
128
129 setenv("bootargs", "");
130 setenv("bootcmd",
131 "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
132 } else {
133 printf("Booting from FLASH\n");
134 }
135
136 return 0;
137}
138#endif
139
140#ifdef CONFIG_STAMP_CF
141
142void cf_outb(unsigned char val, volatile unsigned char *addr)
143{
144 /*
145 * Set PF1 PF0 respectively to 0 1 to divert address
146 * to the expansion memory banks
147 */
148 *pFIO_FLAG_S = CF_PF0;
149 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500150 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800151
152 *(addr) = val;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500153 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800154
155 /* Setback PF1 PF0 to 0 0 to address external
156 * memory banks */
157 *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500158 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800159}
160
161unsigned char cf_inb(volatile unsigned char *addr)
162{
163 volatile unsigned char c;
164
165 *pFIO_FLAG_S = CF_PF0;
166 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500167 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800168
169 c = *(addr);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500170 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800171
172 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500173 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800174
175 return c;
176}
177
178void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
179{
180 int i;
181
182 *pFIO_FLAG_S = CF_PF0;
183 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500184 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800185
186 for (i = 0; i < words; i++) {
187 *(sect_buf + i) = *(addr);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500188 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800189 }
190
191 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500192 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800193}
194
195void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
196{
197 int i;
198
199 *pFIO_FLAG_S = CF_PF0;
200 *pFIO_FLAG_C = CF_PF1;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500201 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800202
203 for (i = 0; i < words; i++) {
204 *(addr) = *(sect_buf + i);
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500205 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800206 }
207
208 *pFIO_FLAG_C = CF_PF1_PF0;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500209 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800210}
211#endif
212
213void stamp_led_set(int LED1, int LED2, int LED3)
214{
215 *pFIO_INEN &= ~(PF2 | PF3 | PF4);
216 *pFIO_DIR |= (PF2 | PF3 | PF4);
217
218 if (LED1 == STATUS_LED_OFF)
219 *pFIO_FLAG_S = PF2;
220 else
221 *pFIO_FLAG_C = PF2;
222 if (LED2 == STATUS_LED_OFF)
223 *pFIO_FLAG_S = PF3;
224 else
225 *pFIO_FLAG_C = PF3;
226 if (LED3 == STATUS_LED_OFF)
227 *pFIO_FLAG_S = PF4;
228 else
229 *pFIO_FLAG_C = PF4;
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500230 SSYNC();
Aubrey.Li9da597f2007-03-09 13:38:44 +0800231}
232
233void show_boot_progress(int status)
234{
235 switch (status) {
236 case 1:
237 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
238 break;
239 case 2:
240 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
241 break;
242 case 3:
243 stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
244 break;
245 case 4:
246 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
247 break;
248 case 5:
249 case 6:
250 stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
251 break;
252 case 7:
253 case 8:
254 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
255 break;
256 case 9:
257 case 10:
258 case 11:
259 case 12:
260 case 13:
261 case 14:
262 case 15:
263 stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF);
264 break;
265 default:
266 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
267 break;
268 }
269}