blob: 7e3af20eab2a554d87e8f79070039ff076d2ffe1 [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
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
33
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010034#define STATUS_LED_OFF 0
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010035#define STATUS_LED_ON 1
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010036
37#ifdef CONFIG_SHOW_BOOT_PROGRESS
38# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
39#else
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010040# define SHOW_BOOT_PROGRESS(arg)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010041#endif
42
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010043int checkboard (void)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010044{
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010045 printf ("CPU: ADSP BF533 Rev.: 0.%d\n", *pCHIPID >> 28);
46 printf ("Board: ADI BF533 Stamp board\n");
47 printf (" Support: http://blackfin.uclinux.org/\n");
48 printf (" Richard Klingler <richard@uclinux.net>\n");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010049 return 0;
50}
51
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010052long int initdram (int board_type)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010053{
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010054#ifdef DEBUG
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010055 printf ("SDRAM attributes:\n");
56 printf (" tRCD:%d Cycles; tRP:%d Cycles; tRAS:%d Cycles; tWR:%d Cycles; "
57 "CAS Latency:%d cycles\n",
58 (SDRAM_tRCD >> 15),
59 (SDRAM_tRP >> 11),
60 (SDRAM_tRAS >> 6),
61 (SDRAM_tWR >> 19),
62 (SDRAM_CL >> 2));
63 printf ("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
64 printf ("Bank size = %d MB\n", 128);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010065#endif
66 gd->bd->bi_memstart = CFG_SDRAM_BASE;
67 gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
68 return (gd->bd->bi_memsize);
69}
70
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010071void swap_to (int device_id)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010072{
73
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010074 if (device_id == ETHERNET) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010075 *pFIO_DIR = PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010076 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010077 *pFIO_FLAG_S = PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010078 asm ("ssync;");
79 } else if (device_id == FLASH) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010080 *pFIO_DIR = (PF4 | PF3 | PF2 | PF1 | PF0);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010081 *pFIO_FLAG_S = (PF4 | PF3 | PF2);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010082 *pFIO_MASKA_D = (PF8 | PF6 | PF5);
83 *pFIO_MASKB_D = (PF7);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010084 *pFIO_POLAR = (PF8 | PF6 | PF5);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010085 *pFIO_EDGE = (PF8 | PF7 | PF6 | PF5);
86 *pFIO_INEN = (PF8 | PF7 | PF6 | PF5);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010087 *pFIO_FLAG_D = (PF4 | PF3 | PF2);
88 asm ("ssync;");
89 } else {
90 printf ("Unknown bank to switch\n");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010091 }
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010092
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010093 return;
94}
95
96#if defined(CONFIG_MISC_INIT_R)
97/* miscellaneous platform dependent initialisations */
Wolfgang Denk8e7b7032006-03-12 02:55:22 +010098int misc_init_r (void)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010099{
100 int i;
101 int cf_stat = 0;
102
103 /* Check whether CF card is inserted */
104 *pFIO_EDGE = FIO_EDGE_CF_BITS;
105 *pFIO_POLAR = FIO_POLAR_CF_BITS;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100106 for (i = 0; i < 0x300; i++)
107 asm ("nop;");
108
109 if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100110 cf_stat = 0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100111 } else {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100112 cf_stat = 1;
113 }
114
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100115 *pFIO_EDGE = FIO_EDGE_BITS;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100116 *pFIO_POLAR = FIO_POLAR_BITS;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100117
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100118
119 if (cf_stat) {
120 printf ("Booting from COMPACT flash\n");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100121
122 /* Set cycle time for CF */
123 *(volatile unsigned long *) ambctl1 = CF_AMBCTL1VAL;
124
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100125 for (i = 0; i < 0x1000; i++)
126 asm ("nop;");
127 for (i = 0; i < 0x1000; i++)
128 asm ("nop;");
129 for (i = 0; i < 0x1000; i++)
130 asm ("nop;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100131
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100132 serial_setbrg ();
133 ide_init ();
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100134
135 setenv ("bootargs", "");
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100136 setenv ("bootcmd",
137 "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
138 } else {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100139 printf ("Booting from FLASH\n");
140 }
141
142 return 1;
143}
144#endif
145
146#ifdef CONFIG_STAMP_CF
147
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100148void cf_outb (unsigned char val, volatile unsigned char *addr)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100149{
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100150 /*
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100151 * Set PF1 PF0 respectively to 0 1 to divert address
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100152 * to the expansion memory banks
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100153 */
154 *pFIO_FLAG_S = CF_PF0;
155 *pFIO_FLAG_C = CF_PF1;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100156 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100157
158 *(addr) = val;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100159 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100160
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100161 /* Setback PF1 PF0 to 0 0 to address external
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100162 * memory banks */
163 *(volatile unsigned short *) pFIO_FLAG_C = CF_PF1_PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100164 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100165}
166
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100167unsigned char cf_inb (volatile unsigned char *addr)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100168{
169 volatile unsigned char c;
170
171 *pFIO_FLAG_S = CF_PF0;
172 *pFIO_FLAG_C = CF_PF1;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100173 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100174
175 c = *(addr);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100176 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100177
178 *pFIO_FLAG_C = CF_PF1_PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100179 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100180
181 return c;
182}
183
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100184void cf_insw (unsigned short *sect_buf, unsigned short *addr, int words)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100185{
186 int i;
187
188 *pFIO_FLAG_S = CF_PF0;
189 *pFIO_FLAG_C = CF_PF1;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100190 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100191
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100192 for (i = 0; i < words; i++) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100193 *(sect_buf + i) = *(addr);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100194 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100195 }
196
197 *pFIO_FLAG_C = CF_PF1_PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100198 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100199}
200
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100201void cf_outsw (unsigned short *addr, unsigned short *sect_buf, int words)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100202{
203 int i;
204
205 *pFIO_FLAG_S = CF_PF0;
206 *pFIO_FLAG_C = CF_PF1;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100207 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100208
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100209 for (i = 0; i < words; i++) {
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100210 *(addr) = *(sect_buf + i);
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100211 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100212 }
213
214 *pFIO_FLAG_C = CF_PF1_PF0;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100215 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100216}
217#endif
218
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100219void stamp_led_set (int LED1, int LED2, int LED3)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100220{
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100221 *pFIO_INEN &= ~(PF2 | PF3 | PF4);
222 *pFIO_DIR |= (PF2 | PF3 | PF4);
223
224 if (LED1 == STATUS_LED_OFF)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100225 *pFIO_FLAG_S = PF2;
226 else
227 *pFIO_FLAG_C = PF2;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100228 if (LED2 == STATUS_LED_OFF)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100229 *pFIO_FLAG_S = PF3;
230 else
231 *pFIO_FLAG_C = PF3;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100232 if (LED3 == STATUS_LED_OFF)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100233 *pFIO_FLAG_S = PF4;
234 else
235 *pFIO_FLAG_C = PF4;
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100236 asm ("ssync;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100237}
238
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100239void show_boot_progress (int status)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100240{
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100241 switch (status) {
242 case 1:
243 stamp_led_set (STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
244 break;
245 case 2:
246 stamp_led_set (STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
247 break;
248 case 3:
249 stamp_led_set (STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
250 break;
251 case 4:
252 stamp_led_set (STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
253 break;
254 case 5:
255 case 6:
256 stamp_led_set (STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
257 break;
258 case 7:
259 case 8:
260 stamp_led_set (STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
261 break;
262 case 9:
263 case 10:
264 case 11:
265 case 12:
266 case 13:
267 case 14:
268 case 15:
269 stamp_led_set (STATUS_LED_OFF, STATUS_LED_OFF,
270 STATUS_LED_OFF);
271 break;
272 default:
273 stamp_led_set (STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
274 break;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100275 }
276}