blob: 3fe0134d6816842d28eb93516d7efbff14888116 [file] [log] [blame]
Wolfgang Denk6cb142f2006-03-12 02:12:27 +01001/*
2 * U-boot - stamp.c STAMP board specific routines
3 *
4 * Copyright (c) 2005 blackfin.uclinux.org
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., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
29#include <asm/mem_init.h>
30#include "stamp.h"
31
32#define STATUS_LED_OFF 0
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010033#define STATUS_LED_ON 1
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010034
35#ifdef CONFIG_SHOW_BOOT_PROGRESS
36# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
37#else
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010038# define SHOW_BOOT_PROGRESS(arg)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010039#endif
40
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010041int checkboard (void)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010042{
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010043 printf ("CPU: ADSP BF533 Rev.: 0.%d\n", *pCHIPID >> 28);
44 printf ("Board: ADI BF533 Stamp board\n");
45 printf (" Support: http://blackfin.uclinux.org/\n");
46 printf (" Richard Klingler <richard@uclinux.net>\n");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010047 return 0;
48}
49
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010050long int initdram (int board_type)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010051{
52 DECLARE_GLOBAL_DATA_PTR;
53#ifdef DEBUG
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010054 printf ("SDRAM attributes:\n");
55 printf (" tRCD:%d Cycles; tRP:%d Cycles; tRAS:%d Cycles; tWR:%d Cycles; "
56 "CAS Latency:%d cycles\n",
57 (SDRAM_tRCD >> 15),
58 (SDRAM_tRP >> 11),
59 (SDRAM_tRAS >> 6),
60 (SDRAM_tWR >> 19),
61 (SDRAM_CL >> 2));
62 printf ("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
63 printf ("Bank size = %d MB\n", 128);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010064#endif
65 gd->bd->bi_memstart = CFG_SDRAM_BASE;
66 gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
67 return (gd->bd->bi_memsize);
68}
69
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010070void swap_to (int device_id)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010071{
72
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010073 if (device_id == ETHERNET) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010074 *pFIO_DIR = PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010075 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010076 *pFIO_FLAG_S = PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010077 asm ("ssync;");
78 } else if (device_id == FLASH) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010079 *pFIO_DIR = (PF4 | PF3 | PF2 | PF1 | PF0);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010080 *pFIO_FLAG_S = (PF4 | PF3 | PF2);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010081 *pFIO_MASKA_D = (PF8 | PF6 | PF5);
82 *pFIO_MASKB_D = (PF7);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010083 *pFIO_POLAR = (PF8 | PF6 | PF5);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010084 *pFIO_EDGE = (PF8 | PF7 | PF6 | PF5);
85 *pFIO_INEN = (PF8 | PF7 | PF6 | PF5);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010086 *pFIO_FLAG_D = (PF4 | PF3 | PF2);
87 asm ("ssync;");
88 } else {
89 printf ("Unknown bank to switch\n");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010090 }
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010091
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010092 return;
93}
94
95#if defined(CONFIG_MISC_INIT_R)
96/* miscellaneous platform dependent initialisations */
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010097int misc_init_r (void)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010098{
99 int i;
100 int cf_stat = 0;
101
102 /* Check whether CF card is inserted */
103 *pFIO_EDGE = FIO_EDGE_CF_BITS;
104 *pFIO_POLAR = FIO_POLAR_CF_BITS;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100105 for (i = 0; i < 0x300; i++)
106 asm ("nop;");
107
108 if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100109 cf_stat = 0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100110 } else {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100111 cf_stat = 1;
112 }
113
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100114 *pFIO_EDGE = FIO_EDGE_BITS;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100115 *pFIO_POLAR = FIO_POLAR_BITS;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100116
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100117
118 if (cf_stat) {
119 printf ("Booting from COMPACT flash\n");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100120
121 /* Set cycle time for CF */
122 *(volatile unsigned long *) ambctl1 = CF_AMBCTL1VAL;
123
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100124 for (i = 0; i < 0x1000; i++)
125 asm ("nop;");
126 for (i = 0; i < 0x1000; i++)
127 asm ("nop;");
128 for (i = 0; i < 0x1000; i++)
129 asm ("nop;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100130
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100131 serial_setbrg ();
132 ide_init ();
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100133
134 setenv ("bootargs", "");
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100135 setenv ("bootcmd",
136 "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
137 } else {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100138 printf ("Booting from FLASH\n");
139 }
140
141 return 1;
142}
143#endif
144
145#ifdef CONFIG_STAMP_CF
146
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100147void cf_outb (unsigned char val, volatile unsigned char *addr)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100148{
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100149 /*
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100150 * Set PF1 PF0 respectively to 0 1 to divert address
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100151 * to the expansion memory banks
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100152 */
153 *pFIO_FLAG_S = CF_PF0;
154 *pFIO_FLAG_C = CF_PF1;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100155 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100156
157 *(addr) = val;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100158 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100159
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100160 /* Setback PF1 PF0 to 0 0 to address external
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100161 * memory banks */
162 *(volatile unsigned short *) pFIO_FLAG_C = CF_PF1_PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100163 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100164}
165
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100166unsigned char cf_inb (volatile unsigned char *addr)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100167{
168 volatile unsigned char c;
169
170 *pFIO_FLAG_S = CF_PF0;
171 *pFIO_FLAG_C = CF_PF1;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100172 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100173
174 c = *(addr);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100175 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100176
177 *pFIO_FLAG_C = CF_PF1_PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100178 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100179
180 return c;
181}
182
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100183void cf_insw (unsigned short *sect_buf, unsigned short *addr, int words)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100184{
185 int i;
186
187 *pFIO_FLAG_S = CF_PF0;
188 *pFIO_FLAG_C = CF_PF1;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100189 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100190
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100191 for (i = 0; i < words; i++) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100192 *(sect_buf + i) = *(addr);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100193 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100194 }
195
196 *pFIO_FLAG_C = CF_PF1_PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100197 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100198}
199
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100200void cf_outsw (unsigned short *addr, unsigned short *sect_buf, int words)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100201{
202 int i;
203
204 *pFIO_FLAG_S = CF_PF0;
205 *pFIO_FLAG_C = CF_PF1;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100206 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100207
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100208 for (i = 0; i < words; i++) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100209 *(addr) = *(sect_buf + i);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100210 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100211 }
212
213 *pFIO_FLAG_C = CF_PF1_PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100214 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100215}
216#endif
217
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100218void stamp_led_set (int LED1, int LED2, int LED3)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100219{
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100220 *pFIO_INEN &= ~(PF2 | PF3 | PF4);
221 *pFIO_DIR |= (PF2 | PF3 | PF4);
222
223 if (LED1 == STATUS_LED_OFF)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100224 *pFIO_FLAG_S = PF2;
225 else
226 *pFIO_FLAG_C = PF2;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100227 if (LED2 == STATUS_LED_OFF)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100228 *pFIO_FLAG_S = PF3;
229 else
230 *pFIO_FLAG_C = PF3;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100231 if (LED3 == STATUS_LED_OFF)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100232 *pFIO_FLAG_S = PF4;
233 else
234 *pFIO_FLAG_C = PF4;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100235 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100236}
237
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100238void show_boot_progress (int status)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100239{
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100240 switch (status) {
241 case 1:
242 stamp_led_set (STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
243 break;
244 case 2:
245 stamp_led_set (STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
246 break;
247 case 3:
248 stamp_led_set (STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
249 break;
250 case 4:
251 stamp_led_set (STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
252 break;
253 case 5:
254 case 6:
255 stamp_led_set (STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
256 break;
257 case 7:
258 case 8:
259 stamp_led_set (STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
260 break;
261 case 9:
262 case 10:
263 case 11:
264 case 12:
265 case 13:
266 case 14:
267 case 15:
268 stamp_led_set (STATUS_LED_OFF, STATUS_LED_OFF,
269 STATUS_LED_OFF);
270 break;
271 default:
272 stamp_led_set (STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
273 break;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100274 }
275}