Initial revision
[oweals/u-boot.git] / board / esd / dasa_sim / cmd_dasa_sim.c
1 /*
2  * (C) Copyright 2001
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
25 #include <common.h>
26 #include <command.h>
27 #include <pci.h>
28
29 #define OK 0
30 #define ERROR (-1)
31
32 #define TRUE 1
33 #define FALSE 0
34
35
36 extern u_long pci9054_iobase;
37
38
39 /***************************************************************************
40  *
41  * Routines for PLX PCI9054 eeprom access
42  *
43  */
44
45 static unsigned int PciEepromReadLongVPD(int offs)
46 {
47   unsigned int value;
48   unsigned int ret;
49   int count;
50
51   pci_write_config_dword(CFG_PCI9054_DEV_FN, 0x4c, (offs<<16) | 0x0003);
52   count = 0;
53
54   for (;;)
55     {
56       udelay(10 * 1000);
57       pci_read_config_dword(CFG_PCI9054_DEV_FN, 0x4c, &ret);
58       if ((ret & 0x80000000) != 0)
59         {
60           break;
61         }
62       else
63         {
64           count++;
65           if (count > 10)
66             {
67               printf("\nTimeout: ret=%08x - Please try again!\n", ret);
68               break;
69             }
70         }
71     }
72
73   pci_read_config_dword(CFG_PCI9054_DEV_FN, 0x50, &value);
74
75   return value;
76 }
77
78
79 static int PciEepromWriteLongVPD(int offs, unsigned int value)
80 {
81   unsigned int ret;
82   int count;
83
84   pci_write_config_dword(CFG_PCI9054_DEV_FN, 0x50, value);
85   pci_write_config_dword(CFG_PCI9054_DEV_FN, 0x4c, (offs<<16) | 0x80000003);
86   count = 0;
87
88   for (;;)
89     {
90       udelay(10 * 1000);
91       pci_read_config_dword(CFG_PCI9054_DEV_FN, 0x4c, &ret);
92       if ((ret & 0x80000000) == 0)
93         {
94           break;
95         }
96       else
97         {
98           count++;
99           if (count > 10)
100             {
101               printf("\nTimeout: ret=%08x - Please try again!\n", ret);
102               break;
103             }
104         }
105     }
106
107   return TRUE;
108 }
109
110
111 static void showPci9054(void)
112 {
113   int val;
114   int l, i;
115
116   /* read 9054-values */
117   for (l=0; l<6; l++)
118     {
119       printf("%02x: ", l*0x10);
120       for (i=0; i<4; i++)
121         {
122           pci_read_config_dword(CFG_PCI9054_DEV_FN, l*16+i*4, &val);
123           printf("%08x ", val);
124         }
125       printf("\n");
126     }
127   printf("\n");
128
129   for (l=0; l<7; l++)
130     {
131       printf("%02x: ", l*0x10);
132       for (i=0; i<4; i++)
133         printf("%08x ", PciEepromReadLongVPD((i+l*4)*4));
134       printf("\n");
135     }
136   printf("\n");
137 }
138
139
140 static void updatePci9054(void)
141 {
142   int val;
143
144   /*
145    * Set EEPROM write-protect register to 0
146    */
147   out32(pci9054_iobase+0x0c, in32(pci9054_iobase+0x0c) & 0xffff00ff);
148
149   /* Long Serial EEPROM Load Registers... */
150   val = PciEepromWriteLongVPD(0x00, 0x905410b5);
151   val = PciEepromWriteLongVPD(0x04, 0x09800001); /* other input controller */
152   val = PciEepromWriteLongVPD(0x08, 0x28140100);
153
154   val = PciEepromWriteLongVPD(0x0c, 0x00000000); /* MBOX0... */
155   val = PciEepromWriteLongVPD(0x10, 0x00000000);
156
157   /* las0: fpga access (0x0000.0000 ... 0x0003.ffff) */
158   val = PciEepromWriteLongVPD(0x14, 0xfffc0000); /* LAS0RR... */
159   val = PciEepromWriteLongVPD(0x18, 0x00000001); /* LAS0BA */
160
161   val = PciEepromWriteLongVPD(0x1c, 0x00200000); /* MARBR... */
162   val = PciEepromWriteLongVPD(0x20, 0x00300500); /* LMISC/BIGEND */
163
164   val = PciEepromWriteLongVPD(0x24, 0x00000000); /* EROMRR... */
165   val = PciEepromWriteLongVPD(0x28, 0x00000000); /* EROMBA */
166
167   val = PciEepromWriteLongVPD(0x2c, 0x43030000); /* LBRD0... */
168
169   val = PciEepromWriteLongVPD(0x30, 0x00000000); /* DMRR... */
170   val = PciEepromWriteLongVPD(0x34, 0x00000000);
171   val = PciEepromWriteLongVPD(0x38, 0x00000000);
172
173   val = PciEepromWriteLongVPD(0x3c, 0x00000000); /* DMPBAM... */
174   val = PciEepromWriteLongVPD(0x40, 0x00000000);
175
176   /* Extra Long Serial EEPROM Load Registers... */
177   val = PciEepromWriteLongVPD(0x44, 0x010212fe); /* PCISID... */
178
179   /* las1: 505-sram access (0x0004.0000 ... 0x001f.ffff) */
180   /* Offset to LAS1: Group 1: 0x00040000                 */
181   /*                 Group 2: 0x00080000                 */
182   /*                 Group 3: 0x000c0000                 */
183   val = PciEepromWriteLongVPD(0x48, 0xffe00000); /* LAS1RR */
184   val = PciEepromWriteLongVPD(0x4c, 0x00040001); /* LAS1BA */
185   val = PciEepromWriteLongVPD(0x50, 0x00000208); /* LBRD1 */ /* so wars bisher */
186
187   val = PciEepromWriteLongVPD(0x54, 0x00004c06); /* HotSwap... */
188
189   printf("Finished writing defaults into PLX PCI9054 EEPROM!\n");
190 }
191
192
193 static void clearPci9054(void)
194 {
195   int val;
196
197   /*
198    * Set EEPROM write-protect register to 0
199    */
200   out32(pci9054_iobase+0x0c, in32(pci9054_iobase+0x0c) & 0xffff00ff);
201
202   /* Long Serial EEPROM Load Registers... */
203   val = PciEepromWriteLongVPD(0x00, 0xffffffff);
204   val = PciEepromWriteLongVPD(0x04, 0xffffffff); /* other input controller */
205
206   printf("Finished clearing PLX PCI9054 EEPROM!\n");
207 }
208
209
210 /* ------------------------------------------------------------------------- */
211 int do_pci9054(cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
212 {
213   if (strcmp(argv[1], "info") == 0)
214     {
215       showPci9054();
216       return 0;
217     }
218
219   if (strcmp(argv[1], "update") == 0)
220     {
221       updatePci9054();
222       return 0;
223     }
224
225   if (strcmp(argv[1], "clear") == 0)
226     {
227       clearPci9054();
228       return 0;
229     }
230
231   printf("Usage:\n%s\n", cmdtp->usage);
232   return 1;
233
234 }
235
236 /* ------------------------------------------------------------------------- */