Add missing Blackfin files.
[platform/kernel/u-boot.git] / board / stamp / stamp.c
1 /*
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
33 #define STATUS_LED_ON  1        
34
35 #ifdef CONFIG_SHOW_BOOT_PROGRESS
36 # define SHOW_BOOT_PROGRESS(arg)        show_boot_progress(arg)
37 #else
38 # define SHOW_BOOT_PROGRESS(arg)        
39 #endif
40
41 int checkboard(void)
42 {
43         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");
47         return 0;
48 }
49
50 long int initdram(int board_type)
51 {
52         DECLARE_GLOBAL_DATA_PTR;
53 #ifdef DEBUG
54         printf("SDRAM attributes:\n");
55         printf("  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 ));
58         printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
59         printf("Bank size = %d MB\n", 128);
60 #endif
61         gd->bd->bi_memstart = CFG_SDRAM_BASE;
62         gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
63         return (gd->bd->bi_memsize);
64 }
65
66 void swap_to(int device_id)
67 {
68
69         if (device_id == ETHERNET)
70         {
71                 *pFIO_DIR = PF0;
72                 asm("ssync;");
73                 *pFIO_FLAG_S = PF0;
74                 asm("ssync;");
75         }
76         else if (device_id == FLASH)
77         {
78                 *pFIO_DIR = (PF4 | PF3 | PF2 | PF1 | PF0);
79                 *pFIO_FLAG_S = (PF4 | PF3 | PF2 );
80                 *pFIO_MASKA_D = (PF8 | PF6 | PF5);
81                 *pFIO_MASKB_D = (PF7);
82                 *pFIO_POLAR = (PF8 | PF6 | PF5 );
83                 *pFIO_EDGE = (PF8 | PF7 | PF6 | PF5);
84                 *pFIO_INEN = (PF8 | PF7 | PF6 | PF5);
85                 *pFIO_FLAG_D = (PF4 | PF3 | PF2 );
86                 asm("ssync;");
87         }
88         else {
89                 printf("Unknown bank to switch\n");
90         }       
91         
92         return;
93 }
94
95 #if defined(CONFIG_MISC_INIT_R)
96 /* miscellaneous platform dependent initialisations */
97 int misc_init_r(void)
98 {
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;
105         for (i=0; i < 0x300 ; i++) asm("nop;");
106                         
107         if ( (*pFIO_FLAG_S) & CF_STAT_BITS)
108         {
109                 cf_stat = 0;
110         }
111         else
112         {
113                 cf_stat = 1;
114         }
115
116         *pFIO_EDGE  = FIO_EDGE_BITS;
117         *pFIO_POLAR = FIO_POLAR_BITS;
118         
119
120         if (cf_stat)
121         {
122                 printf ("Booting from COMPACT flash\n");
123
124                 /* Set cycle time for CF */
125                 *(volatile unsigned long *) ambctl1 = CF_AMBCTL1VAL;
126
127                 for (i=0; i < 0x1000 ; i++) asm("nop;");
128                 for (i=0; i < 0x1000 ; i++) asm("nop;");
129                 for (i=0; i < 0x1000 ; i++) asm("nop;");
130
131                 serial_setbrg();
132                 ide_init();
133
134                 setenv ("bootargs", "");
135                 setenv ("bootcmd", "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000" );
136         }
137         else
138         {
139                 printf ("Booting from FLASH\n");
140         }
141
142         return 1;
143 }
144 #endif
145
146 #ifdef CONFIG_STAMP_CF
147
148 void cf_outb(unsigned char val, volatile unsigned char* addr)
149 {
150         /* 
151          * Set PF1 PF0 respectively to 0 1 to divert address
152          * to the expansion memory banks  
153          */
154         *pFIO_FLAG_S = CF_PF0;
155         *pFIO_FLAG_C = CF_PF1;
156         asm("ssync;");
157
158         *(addr) = val;
159         asm("ssync;");
160
161         /* Setback PF1 PF0 to 0 0 to address external 
162          * memory banks  */
163         *(volatile unsigned short *) pFIO_FLAG_C = CF_PF1_PF0;
164         asm("ssync;");
165 }
166
167 unsigned char cf_inb(volatile unsigned char *addr)
168 {
169         volatile unsigned char c;
170
171         *pFIO_FLAG_S = CF_PF0;
172         *pFIO_FLAG_C = CF_PF1;
173         asm("ssync;");
174
175         c = *(addr);
176         asm("ssync;");
177
178         *pFIO_FLAG_C = CF_PF1_PF0;
179         asm("ssync;");
180
181         return c;
182 }
183
184 void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
185 {
186         int i;
187
188         *pFIO_FLAG_S = CF_PF0;
189         *pFIO_FLAG_C = CF_PF1;
190         asm("ssync;");
191
192         for (i = 0;i < words; i++)
193         {
194                 *(sect_buf + i) = *(addr);
195                 asm("ssync;");
196         }
197
198         *pFIO_FLAG_C = CF_PF1_PF0;
199         asm("ssync;");
200 }
201
202 void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
203 {
204         int i;
205
206         *pFIO_FLAG_S = CF_PF0;
207         *pFIO_FLAG_C = CF_PF1;
208         asm("ssync;");
209
210         for (i = 0;i < words; i++)
211         {
212                 *(addr) = *(sect_buf + i);
213                 asm("ssync;");
214         }
215
216         *pFIO_FLAG_C = CF_PF1_PF0;
217         asm("ssync;");
218 }
219 #endif
220
221 void stamp_led_set(int LED1, int LED2, int LED3)
222 {
223         *pFIO_INEN  &= ~( PF2 | PF3 | PF4);
224         *pFIO_DIR   |=  ( PF2 | PF3 | PF4);
225         
226         if(LED1 == STATUS_LED_OFF)
227                 *pFIO_FLAG_S = PF2;
228         else
229                 *pFIO_FLAG_C = PF2;
230         if(LED2 == STATUS_LED_OFF)
231                 *pFIO_FLAG_S = PF3;
232         else
233                 *pFIO_FLAG_C = PF3;
234         if(LED3 == STATUS_LED_OFF)
235                 *pFIO_FLAG_S = PF4;
236         else
237                 *pFIO_FLAG_C = PF4;
238         asm("ssync;");
239 }
240
241 void show_boot_progress(int status)
242 {
243         switch(status){
244                 case 1: 
245                         stamp_led_set(STATUS_LED_OFF,STATUS_LED_OFF,STATUS_LED_ON);
246                         break;
247                 case 2:
248                         stamp_led_set(STATUS_LED_OFF,STATUS_LED_ON,STATUS_LED_OFF);
249                         break;
250                 case 3:
251                         stamp_led_set(STATUS_LED_OFF,STATUS_LED_ON,STATUS_LED_ON);
252                         break;  
253                 case 4:
254                         stamp_led_set(STATUS_LED_ON,STATUS_LED_OFF,STATUS_LED_OFF);                     
255                         break;
256                 case 5:
257                 case 6:
258                         stamp_led_set(STATUS_LED_ON,STATUS_LED_OFF,STATUS_LED_ON);                      
259                         break;
260                 case 7:
261                 case 8:
262                         stamp_led_set(STATUS_LED_ON,STATUS_LED_ON,STATUS_LED_OFF);                      
263                         break;
264                 case 9:
265                 case 10:
266                 case 11:
267                 case 12:
268                 case 13:
269                 case 14:
270                 case 15:
271                         stamp_led_set(STATUS_LED_OFF,STATUS_LED_OFF,STATUS_LED_OFF);                    
272                         break;
273                 default:
274                         stamp_led_set(STATUS_LED_ON,STATUS_LED_ON,STATUS_LED_ON);                       
275                         break;
276         }
277 }
278