]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/esd/pci405/cmd_pci405.c
esd PCI405 updated.
[karo-tx-uboot.git] / board / esd / pci405 / cmd_pci405.c
1 /*
2  * (C) Copyright 2002
3  * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <malloc.h>
26 #include <net.h>
27 #include <asm/io.h>
28 #include <pci.h>
29 #include <405gp_pci.h>
30 #include <cmd_bsp.h>
31
32 #include "pci405.h"
33
34
35 #if (CONFIG_COMMANDS & CFG_CMD_BSP)
36
37 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
38
39 #if 0 /* test-only */
40 #include "../common/fpga.c"
41 void error_print(void)
42 {
43         int i;
44         volatile unsigned char *ptr;
45         volatile unsigned long *ptr2;
46         
47         printf("\n 2nd SJA1000:\n");
48         ptr = 0xf0000100;
49         for (i=0; i<0x20; i++) {
50                 printf("%02x ", *ptr++);
51         }
52
53         ptr2 = 0xf0400008;
54         printf("\nTimestamp = %x\n", *ptr2);
55         udelay(1000);
56         printf("Timestamp = %x\n", *ptr2);
57         udelay(1000);
58         printf("Timestamp = %x\n", *ptr2);
59
60 #if 0 /* test-only */
61         /*
62          * Reset FPGA via FPGA_DATA pin
63          */
64         printf("Resetting FPGA...\n");
65         SET_FPGA(FPGA_PRG | FPGA_CLK);
66         udelay(1000); /* wait 1ms */
67         SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
68         udelay(1000); /* wait 1ms */
69
70         do_loadpci(NULL, 0,0, NULL);
71 #endif
72 }
73
74 void read_loop(void)
75 {
76         int i;
77         volatile unsigned char *ptr;
78         volatile unsigned char val;
79         volatile unsigned long *ptr2;
80
81         printf("\nread loop on 1st sja1000...");
82         while (1) {
83                 ptr = 0xf0000000;
84 /*              printf("\n1st SJA1000:\n");*/
85                 for (i=0; i<0x20; i++) {
86                         i = i;
87                         val = *ptr++;
88 /*                      printf("%02x ", val);*/
89                 }
90
91                 /* Abort if ctrl-c was pressed */
92                 if (ctrlc()) {
93                         puts("\nAbort\n");
94                         return 0;
95                 }
96         }
97 }
98 #endif
99 /*
100  * Command loadpci: wait for signal from host and boot image.
101  */
102 int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
103 {
104         unsigned int *ptr = 0;
105         int count = 0;
106         int count2 = 0;
107         int status;
108         int i;
109         char addr[16];
110         char str[] = "\\|/-";
111         char *local_args[2];
112
113 #if 0 /* test-only */
114         puts("\nStarting sja1000 test...");
115         {
116                 int count;
117                 volatile unsigned char *ptr;
118                 volatile unsigned char val;
119                 volatile unsigned char val2;
120
121 #if 1 /* write test */
122                 ptr = 0xf0000014;
123                 for (i=1; i<11; i++)
124                         *ptr++ = i;
125 #endif
126                 
127                 count = 0;
128                 while (1) {
129                         count++;
130 #if 0 /* write test */
131                         ptr = 0xf0000014;
132                         for (i=1; i<11; i++)
133                                 *ptr++ = i;
134 #endif
135 #if 1 /* read test */
136                         ptr = 0xf0000014;
137                         for (i=1; i<11; i++) {
138                                 val = *ptr++;
139 #if 1
140                                 if (val != i) {
141                                         ptr = 0xf0000100;
142                                         val = *ptr; /* trigger las */
143
144                                         ptr = 0xf0000014;
145                                         val2 = *ptr;
146
147                                         printf("\nERROR: count=%d: soll=%x ist=%x -> staring read loop on 1st sja1000...\n",    count, i, val);
148
149                                         printf("soll=%x ist=%x -> staring read loop on 1st sja1000...\n", 1, val2);
150
151                                         return 0; /* test-only */
152                                         udelay(1000);
153                                         error_print();
154                                         read_loop();
155                                         return 0;
156                                 }
157 #endif
158                         }
159 #endif
160
161                         /* Abort if ctrl-c was pressed */
162                         if (ctrlc()) {
163                                 puts("\nAbort\n");
164                                 return 0;
165                         }
166
167                         if (!(count % 100000)) {
168                                 printf(".");
169                         }
170                 }
171         }
172 #endif
173         /*
174          * Mark sync address
175          */
176         ptr = 0;
177         *ptr = 0xffffffff;
178         puts("\nWaiting for image from pci host -");
179
180         /*
181          * Wait for host to write the start address
182          */
183         while (*ptr == 0xffffffff) {
184                 count++;
185                 if (!(count % 100)) {
186                         count2++;
187                         putc(0x08); /* backspace */
188                         putc(str[count2 % 4]);
189                 }
190
191                 /* Abort if ctrl-c was pressed */
192                 if (ctrlc()) {
193                         puts("\nAbort\n");
194                         return 0;
195                 }
196
197                 udelay(1000);
198         }
199
200         if (*ptr == PCI_RECONFIG_MAGIC) {
201                 /*
202                  * Save own pci configuration in PRAM
203                  */
204                 memset((char *)PCI_REGS_ADDR, 0, PCI_REGS_LEN);
205                 ptr = (unsigned int *)PCI_REGS_ADDR + 1;
206                 for (i=0; i<0x40; i+=4) {
207                         pci_read_config_dword(PCIDEVID_405GP, i, ptr++);
208                 }
209                 ptr = (unsigned int *)PCI_REGS_ADDR;
210                 *ptr = crc32(0, (char *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4);
211
212                 printf("\nStoring PCI Configuration Regs...\n");
213         } else {
214                 sprintf(addr, "%08x", *ptr);
215                 
216                 /*
217                  * Boot image
218                  */
219                 printf("\nBooting image at addr 0x%s ...\n", addr);
220                 setenv("loadaddr", addr);
221                 
222                 local_args[0] = argv[0];
223                 local_args[1] = NULL;
224                 status = do_bootm (cmdtp, 0, 1, local_args);
225         }
226
227         return 0;
228 }
229
230 #endif