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