3e074e3a1b23f56f058980bdb61fc8e0895e8bb6
[oweals/u-boot.git] / board / bf533-stamp / bf533-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 "bf533-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 #if (BFIN_CPU == ADSP_BF531)
44         printf("CPU:   ADSP BF531 Rev.: 0.%d\n", *pCHIPID >> 28);
45 #elif (BFIN_CPU == ADSP_BF532)
46         printf("CPU:   ADSP BF532 Rev.: 0.%d\n", *pCHIPID >> 28);
47 #else
48         printf("CPU:   ADSP BF533 Rev.: 0.%d\n", *pCHIPID >> 28);
49 #endif
50         printf("Board: ADI BF533 Stamp board\n");
51         printf("       Support: http://blackfin.uclinux.org/\n");
52         return 0;
53 }
54
55 long int initdram(int board_type)
56 {
57         DECLARE_GLOBAL_DATA_PTR;
58 #ifdef DEBUG
59         printf("SDRAM attributes:\n");
60         printf
61             ("  tRCD:%d Cycles; tRP:%d Cycles; tRAS:%d Cycles; tWR:%d Cycles; "
62              "CAS Latency:%d cycles\n", (SDRAM_tRCD >> 15), (SDRAM_tRP >> 11),
63              (SDRAM_tRAS >> 6), (SDRAM_tWR >> 19), (SDRAM_CL >> 2));
64         printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
65         printf("Bank size = %d MB\n", 128);
66 #endif
67         gd->bd->bi_memstart = CFG_SDRAM_BASE;
68         gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
69         return (gd->bd->bi_memsize);
70 }
71
72 void swap_to(int device_id)
73 {
74
75         if (device_id == ETHERNET) {
76                 *pFIO_DIR = PF0;
77                 __builtin_bfin_ssync();
78                 *pFIO_FLAG_S = PF0;
79                 __builtin_bfin_ssync();
80         } else if (device_id == FLASH) {
81                 *pFIO_DIR = (PF4 | PF3 | PF2 | PF1 | PF0);
82                 *pFIO_FLAG_S = (PF4 | PF3 | PF2);
83                 *pFIO_MASKA_D = (PF8 | PF6 | PF5);
84                 *pFIO_MASKB_D = (PF7);
85                 *pFIO_POLAR = (PF8 | PF6 | PF5);
86                 *pFIO_EDGE = (PF8 | PF7 | PF6 | PF5);
87                 *pFIO_INEN = (PF8 | PF7 | PF6 | PF5);
88                 *pFIO_FLAG_D = (PF4 | PF3 | PF2);
89                 __builtin_bfin_ssync();
90         } else {
91                 printf("Unknown bank to switch\n");
92         }
93
94         return;
95 }
96
97 #if defined(CONFIG_MISC_INIT_R)
98 /* miscellaneous platform dependent initialisations */
99 int misc_init_r(void)
100 {
101         int i;
102         int cf_stat = 0;
103
104         /* Check whether CF card is inserted */
105         *pFIO_EDGE = FIO_EDGE_CF_BITS;
106         *pFIO_POLAR = FIO_POLAR_CF_BITS;
107         for (i = 0; i < 0x300; i++)
108                 asm("nop;");
109
110         if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
111                 cf_stat = 0;
112         } else {
113                 cf_stat = 1;
114         }
115
116         *pFIO_EDGE = FIO_EDGE_BITS;
117         *pFIO_POLAR = FIO_POLAR_BITS;
118
119         if (cf_stat) {
120                 printf("Booting from COMPACT flash\n");
121
122                 /* Set cycle time for CF */
123                 *(volatile unsigned long *)ambctl1 = CF_AMBCTL1VAL;
124
125                 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;");
131
132                 serial_setbrg();
133                 ide_init();
134
135                 setenv("bootargs", "");
136                 setenv("bootcmd",
137                        "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
138         } else {
139                 printf("Booting from FLASH\n");
140         }
141
142         return 0;
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         __builtin_bfin_ssync();
157
158         *(addr) = val;
159         __builtin_bfin_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         __builtin_bfin_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         __builtin_bfin_ssync();
174
175         c = *(addr);
176         __builtin_bfin_ssync();
177
178         *pFIO_FLAG_C = CF_PF1_PF0;
179         __builtin_bfin_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         __builtin_bfin_ssync();
191
192         for (i = 0; i < words; i++) {
193                 *(sect_buf + i) = *(addr);
194                 __builtin_bfin_ssync();
195         }
196
197         *pFIO_FLAG_C = CF_PF1_PF0;
198         __builtin_bfin_ssync();
199 }
200
201 void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
202 {
203         int i;
204
205         *pFIO_FLAG_S = CF_PF0;
206         *pFIO_FLAG_C = CF_PF1;
207         __builtin_bfin_ssync();
208
209         for (i = 0; i < words; i++) {
210                 *(addr) = *(sect_buf + i);
211                 __builtin_bfin_ssync();
212         }
213
214         *pFIO_FLAG_C = CF_PF1_PF0;
215         __builtin_bfin_ssync();
216 }
217 #endif
218
219 void stamp_led_set(int LED1, int LED2, int LED3)
220 {
221         *pFIO_INEN &= ~(PF2 | PF3 | PF4);
222         *pFIO_DIR |= (PF2 | PF3 | PF4);
223
224         if (LED1 == STATUS_LED_OFF)
225                 *pFIO_FLAG_S = PF2;
226         else
227                 *pFIO_FLAG_C = PF2;
228         if (LED2 == STATUS_LED_OFF)
229                 *pFIO_FLAG_S = PF3;
230         else
231                 *pFIO_FLAG_C = PF3;
232         if (LED3 == STATUS_LED_OFF)
233                 *pFIO_FLAG_S = PF4;
234         else
235                 *pFIO_FLAG_C = PF4;
236         __builtin_bfin_ssync();
237 }
238
239 void show_boot_progress(int status)
240 {
241         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, STATUS_LED_OFF);
270                 break;
271         default:
272                 stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
273                 break;
274         }
275 }