]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/barco/barco.c
2fb370098a3191f34233350ba0c1e735e8f5277c
[people/ms/u-boot.git] / board / barco / barco.c
1 /********************************************************************
2 *
3 * Unless otherwise specified, Copyright (C) 2004-2005 Barco Control Rooms
4 *
5 * $Source: /home/services/cvs/firmware/ppc/u-boot-1.1.2/board/barco/barco.c,v $
6 * $Revision: 1.4 $
7 * $Author: mleeman $
8 * $Date: 2005/03/02 16:40:20 $
9 *
10 * Last ChangeLog Entry
11 * $Log: barco.c,v $
12 * Revision 1.4 2005/03/02 16:40:20 mleeman
13 * remove empty labels (3.4 complains)
14 *
15 * Revision 1.3 2005/02/21 12:48:58 mleeman
16 * update of copyright years (feedback wd)
17 *
18 * Revision 1.2 2005/02/21 10:10:53 mleeman
19 * - split up switch statement to a function call (Linux kernel coding guidelines)
20 * ( feedback wd)
21 *
22 * Revision 1.1 2005/02/14 09:31:07 mleeman
23 * renaming of files
24 *
25 * Revision 1.1 2005/02/14 09:23:46 mleeman
26 * - moved 'barcohydra' directory to a more generic barco; since we will be
27 * supporting and adding multiple boards
28 *
29 * Revision 1.3 2005/02/10 13:57:32 mleeman
30 * fixed flash corruption: I should exit from the moment I find the correct value
31 *
32 * Revision 1.2 2005/02/09 12:56:23 mleeman
33 * add generic header to track changes in sources
34 *
35 *
36 *******************************************************************/
37
38 /*
39 * (C) Copyright 2004
40 * Marc Leeman <marc.leeman@barco.com>
41 *
42 * This program is free software; you can redistribute it and/or
43 * modify it under the terms of the GNU General Public License as
44 * published by the Free Software Foundation; either version 2 of
45 * the License, or (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License
53 * along with this program; if not, write to the Free Software
54 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
55 * MA 02111-1307 USA
56 */
57
58 #include <common.h>
59 #include <mpc824x.h>
60 #include <pci.h>
61 #include <malloc.h>
62 #include <command.h>
63
64 #include "config.h"
65 #include "barco_svc.h"
66
67 #define TRY_WORKING (3)
68 #define BOOT_DEFAULT (2)
69 #define BOOT_WORKING (1)
70
71 int checkboard (void)
72 {
73 /*TODO: Check processor type */
74
75 puts ( "Board: Streaming Video Card for Hydra systems "
76 #ifdef CONFIG_MPC8240
77 "8240"
78 #endif
79 #ifdef CONFIG_MPC8245
80 "8245"
81 #endif
82 " Unity ##Test not implemented yet##\n");
83 return 0;
84 }
85
86 long int initdram (int board_type)
87 {
88 long size;
89 long new_bank0_end;
90 long mear1;
91 long emear1;
92
93 size = get_ram_size(CFG_SDRAM_BASE, CFG_MAX_RAM_SIZE);
94
95 new_bank0_end = size - 1;
96 mear1 = mpc824x_mpc107_getreg(MEAR1);
97 emear1 = mpc824x_mpc107_getreg(EMEAR1);
98 mear1 = (mear1 & 0xFFFFFF00) |
99 ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
100 emear1 = (emear1 & 0xFFFFFF00) |
101 ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
102 mpc824x_mpc107_setreg(MEAR1, mear1);
103 mpc824x_mpc107_setreg(EMEAR1, emear1);
104
105 return (size);
106 }
107
108 /*
109 * Initialize PCI Devices, report devices found.
110 */
111 #ifndef CONFIG_PCI_PNP
112 static struct pci_config_table pci_barcohydra_config_table[] = {
113 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0f, PCI_ANY_ID,
114 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
115 PCI_ENET0_MEMADDR,
116 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
117 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x10, PCI_ANY_ID,
118 pci_cfgfunc_config_device, { PCI_ENET1_IOADDR,
119 PCI_ENET1_MEMADDR,
120 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
121 { }
122 };
123 #endif
124
125 struct pci_controller hose = {
126 #ifndef CONFIG_PCI_PNP
127 config_table: pci_barcohydra_config_table,
128 #endif
129 };
130
131 void pci_init_board(void)
132 {
133 pci_mpc824x_init(&hose);
134 }
135
136 int write_flash(char *addr, char value)
137 {
138 char *adr = (char *)0xFF800000;
139 int cnt = 0;
140 char status,oldstatus;
141 *(adr+0x55) = 0xAA;
142
143 udelay(1);
144 *(adr+0xAA) = 0x55;
145 udelay(1);
146 *(adr+0x55) = 0xA0;
147 udelay(1);
148 *addr = value;
149
150 status = *addr;
151 do{
152
153 oldstatus = status;
154 status = *addr;
155
156 if ((oldstatus & 0x40) == (status & 0x40)){
157 return 4;
158 }
159 cnt++;
160 if (cnt > 10000){
161 return 2;
162 }
163 }while( (status & 0x20) == 0 );
164
165 oldstatus = *addr;
166 status = *addr;
167
168 if ((oldstatus & 0x40) == (status & 0x40)) return 0;
169 else {
170 *(adr+0x55) = 0xF0;
171 return 1;
172 }
173 }
174
175 unsigned update_flash(unsigned char* buf){
176 switch((*buf) & 0x3){
177 case TRY_WORKING:
178 printf("found 3 and converted it to 2\n");
179 write_flash(buf, (*buf) & 0xFE);
180 *((unsigned char *)0xFF800000) = 0xF0;
181 udelay(100);
182 printf("buf [%#010x] %#010x\n",buf,(*buf));
183 case BOOT_WORKING :
184 return BOOT_WORKING;
185 }
186 return BOOT_DEFAULT;
187 }
188
189 unsigned scan_flash(void)
190 {
191 char section[] = "kernel";
192 ulong sp;
193 int cfgFileLen = (CFG_FLASH_ERASE_SECTOR_LENGTH >> 1);
194 int sectionPtr = 0;
195 int foundItem = 0; /* 0: None, 1: section found, 2: "=" found */
196 int bufPtr;
197 unsigned char *buf;
198
199 buf = (unsigned char*)(CFG_FLASH_RANGE_BASE + CFG_FLASH_RANGE_SIZE \
200 - CFG_FLASH_ERASE_SECTOR_LENGTH);
201 for(bufPtr = 0; bufPtr < cfgFileLen; ++bufPtr){
202 if ((buf[bufPtr]==0xFF) && (*(int*)(buf+bufPtr)==0xFFFFFFFF)) {
203 return BOOT_DEFAULT;
204 }
205 switch(foundItem)
206 {
207 /* This is the scanning loop, we try to find a particular
208 * quoted value
209 */
210 case 0:
211 if((section[sectionPtr] == 0)){
212 ++foundItem;
213 }
214 else if(buf[bufPtr] == section[sectionPtr]){
215 ++sectionPtr;
216 }
217 else {
218 sectionPtr = 0;
219 }
220 break;
221 case 1:
222 ++foundItem;
223 break;
224 case 2:
225 ++foundItem;
226 break;
227 case 3:
228 default:
229 return update_flash(buf[bufPtr - 1]);
230 }
231 }
232
233 printf("Failed to read %s\n",section);
234 return BOOT_DEFAULT;
235 }
236
237 TSBootInfo* find_boot_info(void)
238 {
239 unsigned bootimage = scan_flash();
240 TSBootInfo* info = (TSBootInfo*)malloc(sizeof(TSBootInfo));
241
242 switch(bootimage){
243 case TRY_WORKING:
244 info->address = CFG_WORKING_KERNEL_ADDRESS;
245 break;
246 case BOOT_WORKING :
247 info->address = CFG_WORKING_KERNEL_ADDRESS;
248 break;
249 case BOOT_DEFAULT:
250 default:
251 info->address= CFG_DEFAULT_KERNEL_ADDRESS;
252
253 }
254 info->size = *((unsigned int *)(info->address ));
255
256 return info;
257 }
258
259 void barcobcd_boot(void)
260 {
261 TSBootInfo* start;
262 char *bootm_args[2];
263 char *buf;
264 int cnt;
265
266 buf = (char *)(0x00800000);
267 /* make certain there are enough chars to print the command line here!
268 */
269 bootm_args[0]=(char *)malloc(16*sizeof(char));
270 bootm_args[1]=(char *)malloc(16*sizeof(char));
271
272 start = find_boot_info();
273
274 printf("Booting kernel at address %#10x with size %#10x\n",
275 start->address, start->size);
276
277 /* give length of the kernel image to bootm */
278 sprintf(bootm_args[0],"%x",start->size);
279 /* give address of the kernel image to bootm */
280 sprintf(bootm_args[1],"%x",buf);
281
282 printf("flash address: %#10x\n",start->address+8);
283 printf("buf address: %#10x\n",buf);
284
285 /* aha, we reserve 8 bytes here... */
286 for (cnt = 0; cnt < start->size ; cnt++){
287 buf[cnt] = ((char *)start->address)[cnt+8];
288 }
289
290 /* initialise RAM memory */
291 *((unsigned int *)0xFEC00000) = 0x00141A98;
292 do_bootm(NULL,0,2,bootm_args);
293 }
294
295 int barcobcd_boot_image(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
296 {
297 #if 0
298 if (argc > 1) {
299 printf ("Usage:\n (%d) %s\n", argc, cmdtp->usage);
300 return 1;
301 }
302 #endif
303 barcobcd_boot();
304
305 return 0;
306 }
307
308 /* Currently, boot_working and boot_default are the same command. This is
309 * left in here to see what we'll do in the future */
310
311 U_BOOT_CMD(
312 try_working, 1, 1, barcobcd_boot_image,
313 " try_working - check flash value and boot the appropriate image\n",
314 "\n"
315 );
316
317 U_BOOT_CMD(
318 boot_working, 1, 1, barcobcd_boot_image,
319 " boot_working - check flash value and boot the appropriate image\n",
320 "\n"
321 );
322
323 U_BOOT_CMD(
324 boot_default, 1, 1, barcobcd_boot_image,
325 " boot_default - check flash value and boot the appropriate image\n",
326 "\n"
327 );
328 /*
329 * We are not using serial communication, so just provide empty functions
330 */
331 int serial_init(void){return 0;}
332 void serial_setbrg(void){}
333 void serial_putc(const char c){}
334 void serial_puts(const char *c){}
335 void serial_addr(unsigned int i){}
336 int serial_getc(void){return 0;}
337 int serial_tstc(void){return 0;}
338
339 unsigned long post_word_load(void){return 0l;};
340 void post_word_store(unsigned long val){}