]> git.ipfire.org Git - u-boot.git/blob - board/eltec/elppc/misc.c
* Code cleanup:
[u-boot.git] / board / eltec / elppc / misc.c
1 /*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
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 /* includes */
25 #include <common.h>
26 #include <linux/ctype.h>
27 #include <pci.h>
28 #include <net.h>
29 #include "srom.h"
30
31 /* imports */
32 extern char console_buffer[CFG_CBSIZE];
33 extern int l2_cache_enable (int l2control);
34 extern int eepro100_write_eeprom (struct eth_device* dev, int location,
35 int addr_len, unsigned short data);
36 extern int read_eeprom (struct eth_device* dev, int location, int addr_len);
37
38 /*----------------------------------------------------------------------------*/
39 /*
40 * read/write to nvram is only byte access
41 */
42 void *nvram_read(void *dest, const long src, size_t count)
43 {
44 uchar *d = (uchar *) dest;
45 uchar *s = (uchar *) (CFG_ENV_MAP_ADRS + src);
46
47 while (count--)
48 *d++ = *s++;
49
50 return dest;
51 }
52
53 void nvram_write(long dest, const void *src, size_t count)
54 {
55 uchar *d = (uchar *) (CFG_ENV_MAP_ADRS + dest);
56 uchar *s = (uchar *) src;
57
58 while (count--)
59 *d++ = *s++;
60 }
61
62 /*----------------------------------------------------------------------------*/
63 /*
64 * handle sroms on ELPPC
65 * fix ether address
66 * set serial console as default
67 */
68 int misc_init_r (void)
69 {
70 revinfo eerev;
71 u_char *ptr;
72 u_int i, l, initSrom, copyNv;
73 char buf[256];
74 char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
75 0, 0, 0, 0, 10, 11, 12, 13, 14, 15 };
76
77 /* Clock setting for MPC107 i2c */
78 mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b);
79
80 /* Reset the EPIC */
81 out32r (MPC107_EUMB_GCR, 0xa0000000);
82 while (in32r (MPC107_EUMB_GCR) & 0x80000000); /* Wait for reset to complete */
83 out32r (MPC107_EUMB_GCR, 0x20000000); /* Put into into mixed mode */
84 while (in32r (MPC107_EUMB_IACKR) != 0xff); /* Clear all pending interrupts */
85
86 /*
87 * Check/Remake revision info
88 */
89 initSrom = 0;
90 copyNv = 0;
91
92 /* read out current revision srom contens */
93 mpc107_srom_load (0x0000, (u_char*)&eerev, sizeof(revinfo),
94 SECOND_DEVICE, FIRST_BLOCK);
95
96 /* read out current nvram shadow image */
97 nvram_read (buf, CFG_NV_SROM_COPY_ADDR, CFG_SROM_SIZE);
98
99 if (strcmp (eerev.magic, "ELTEC") != 0)
100 {
101 /* srom is not initialized -> create a default revision info */
102 for (i = 0, ptr = (u_char *)&eerev; i < sizeof(revinfo); i++)
103 *ptr++ = 0x00;
104 strcpy(eerev.magic, "ELTEC");
105 eerev.revrev[0] = 1;
106 eerev.revrev[1] = 0;
107 eerev.size = 0x00E0;
108 eerev.category[0] = 0x01;
109
110 /* node id from dead e128 as default */
111 eerev.etheraddr[0] = 0x00;
112 eerev.etheraddr[1] = 0x00;
113 eerev.etheraddr[2] = 0x5B;
114 eerev.etheraddr[3] = 0x00;
115 eerev.etheraddr[4] = 0x2E;
116 eerev.etheraddr[5] = 0x4D;
117
118 /* cache config word for ELPPC */
119 *(int*)&eerev.res[0] = 0;
120
121 initSrom = 1; /* force dialog */
122 copyNv = 1; /* copy to nvram */
123 }
124
125 if ((copyNv == 0) && (el_srom_checksum((u_char*)&eerev, CFG_SROM_SIZE) !=
126 el_srom_checksum((u_char*)buf, CFG_SROM_SIZE)))
127 {
128 printf ("Invalid revision info copy in nvram !\n");
129 printf ("Press key:\n <c> to copy current revision info to nvram.\n");
130 printf (" <r> to reenter revision info.\n");
131 printf ("=> ");
132 if (0 != readline (NULL))
133 {
134 switch ((char)toupper(console_buffer[0]))
135 {
136 case 'C':
137 copyNv = 1;
138 break;
139 case 'R':
140 copyNv = 1;
141 initSrom = 1;
142 break;
143 }
144 }
145 }
146
147 if (initSrom)
148 {
149 memcpy (buf, &eerev.revision[0][0], 14); /* save all revision info */
150 printf ("Enter revision number (0-9): %c ", eerev.revision[0][0]);
151 if (0 != readline (NULL))
152 {
153 eerev.revision[0][0] = (char)toupper(console_buffer[0]);
154 memcpy (&eerev.revision[1][0], buf, 12); /* shift rest of rev info */
155 }
156
157 printf ("Enter revision character (A-Z): %c ", eerev.revision[0][1]);
158 if (1 == readline (NULL))
159 {
160 eerev.revision[0][1] = (char)toupper(console_buffer[0]);
161 }
162
163 printf ("Enter board name (V-XXXX-XXXX): %s ", (char *)&eerev.board);
164 if (11 == readline (NULL))
165 {
166 for (i=0; i<11; i++)
167 eerev.board[i] = (char)toupper(console_buffer[i]);
168 eerev.board[11] = '\0';
169 }
170
171 printf ("Enter serial number: %s ", (char *)&eerev.serial );
172 if (6 == readline (NULL))
173 {
174 for (i=0; i<6; i++)
175 eerev.serial[i] = console_buffer[i];
176 eerev.serial[6] = '\0';
177 }
178
179 printf ("Enter ether node ID with leading zero (HEX): %02x%02x%02x%02x%02x%02x ",
180 eerev.etheraddr[0], eerev.etheraddr[1],
181 eerev.etheraddr[2], eerev.etheraddr[3],
182 eerev.etheraddr[4], eerev.etheraddr[5]);
183 if (12 == readline (NULL))
184 {
185 for (i=0; i<12; i+=2)
186 eerev.etheraddr[i>>1] = (char)(16*hex[toupper(console_buffer[i])-'0'] +
187 hex[toupper(console_buffer[i+1])-'0']);
188 }
189
190 l = strlen ((char *)&eerev.text);
191 printf("Add to text section (max 64 chr): %s ", (char *)&eerev.text );
192 if (0 != readline (NULL))
193 {
194 for (i = l; i<63; i++)
195 eerev.text[i] = console_buffer[i-l];
196 eerev.text[63] = '\0';
197 }
198
199 /* prepare network eeprom */
200 memset (buf, 0, 128);
201
202 buf[0] = eerev.etheraddr[1];
203 buf[1] = eerev.etheraddr[0];
204 buf[2] = eerev.etheraddr[3];
205 buf[3] = eerev.etheraddr[2];
206 buf[4] = eerev.etheraddr[5];
207 buf[5] = eerev.etheraddr[4];
208
209 *(unsigned short *)&buf[20] = 0x48B2;
210 *(unsigned short *)&buf[22] = 0x0004;
211 *(unsigned short *)&buf[24] = 0x1433;
212
213 printf("\nSRom: Writing i82559 info ........ ");
214 if (eepro100_srom_store ((unsigned short *)buf) == -1)
215 printf("FAILED\n");
216 else
217 printf("OK\n");
218
219 /* update CRC */
220 eerev.crc = el_srom_checksum((u_char *)eerev.board, eerev.size);
221
222 /* write new values */
223 printf("\nSRom: Writing revision info ...... ");
224 if (mpc107_srom_store((BLOCK_SIZE-sizeof(revinfo)), (u_char *)&eerev,
225 sizeof(revinfo), SECOND_DEVICE, FIRST_BLOCK) == -1)
226 printf("FAILED\n\n");
227 else
228 printf("OK\n\n");
229
230 /* write new values as shadow image to nvram */
231 nvram_write (CFG_NV_SROM_COPY_ADDR, (void *)&eerev, CFG_SROM_SIZE);
232
233 } /*if (initSrom) */
234
235 /* copy current values as shadow image to nvram */
236 if (initSrom == 0 && copyNv == 1)
237 nvram_write (CFG_NV_SROM_COPY_ADDR, (void *)&eerev, CFG_SROM_SIZE);
238
239 /* update environment */
240 sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x",
241 eerev.etheraddr[0], eerev.etheraddr[1],
242 eerev.etheraddr[2], eerev.etheraddr[3],
243 eerev.etheraddr[4], eerev.etheraddr[5]);
244 setenv ("ethaddr", buf);
245
246 /* set serial console as default */
247 if ((ptr = getenv ("console")) == NULL)
248 setenv ("console", "serial");
249
250 /* print actual board identification */
251 printf("Ident: %s Ser %s Rev %c%c\n",
252 eerev.board, (char *)&eerev.serial,
253 eerev.revision[0][0], eerev.revision[0][1]);
254
255 return (0);
256 }
257
258 /*----------------------------------------------------------------------------*/