2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/ctype.h>
17 extern int l2_cache_enable (int l2control);
18 extern int eepro100_write_eeprom (struct eth_device *dev, int location,
19 int addr_len, unsigned short data);
20 extern int read_eeprom (struct eth_device *dev, int location, int addr_len);
22 /*----------------------------------------------------------------------------*/
24 * read/write to nvram is only byte access
26 void *nvram_read (void *dest, const long src, size_t count)
28 uchar *d = (uchar *) dest;
29 uchar *s = (uchar *) (CONFIG_ENV_MAP_ADRS + src);
37 void nvram_write (long dest, const void *src, size_t count)
39 uchar *d = (uchar *) (CONFIG_ENV_MAP_ADRS + dest);
40 uchar *s = (uchar *) src;
46 /*----------------------------------------------------------------------------*/
48 * handle sroms on ELPPC
50 * set serial console as default
52 int misc_init_r (void)
56 u_int i, l, initSrom, copyNv;
58 char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
59 0, 0, 0, 0, 10, 11, 12, 13, 14, 15
62 /* Clock setting for MPC107 i2c */
63 mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b);
66 out32r (MPC107_EUMB_GCR, 0xa0000000);
67 while (in32r (MPC107_EUMB_GCR) & 0x80000000); /* Wait for reset to complete */
68 out32r (MPC107_EUMB_GCR, 0x20000000); /* Put into into mixed mode */
69 while (in32r (MPC107_EUMB_IACKR) != 0xff); /* Clear all pending interrupts */
72 * Check/Remake revision info
77 /* read out current revision srom contens */
78 mpc107_srom_load (0x0000, (u_char *) & eerev, sizeof (revinfo),
79 SECOND_DEVICE, FIRST_BLOCK);
81 /* read out current nvram shadow image */
82 nvram_read (buf, CONFIG_SYS_NV_SROM_COPY_ADDR, CONFIG_SYS_SROM_SIZE);
84 if (strcmp (eerev.magic, "ELTEC") != 0) {
85 /* srom is not initialized -> create a default revision info */
86 for (i = 0, ptr = (u_char *) & eerev; i < sizeof (revinfo);
89 strcpy (eerev.magic, "ELTEC");
93 eerev.category[0] = 0x01;
95 /* node id from dead e128 as default */
96 eerev.etheraddr[0] = 0x00;
97 eerev.etheraddr[1] = 0x00;
98 eerev.etheraddr[2] = 0x5B;
99 eerev.etheraddr[3] = 0x00;
100 eerev.etheraddr[4] = 0x2E;
101 eerev.etheraddr[5] = 0x4D;
103 /* cache config word for ELPPC */
104 memset(&eerev.res[0], 0, 4);
106 initSrom = 1; /* force dialog */
107 copyNv = 1; /* copy to nvram */
111 && (el_srom_checksum ((u_char *) & eerev, CONFIG_SYS_SROM_SIZE) !=
112 el_srom_checksum ((u_char *) buf, CONFIG_SYS_SROM_SIZE))) {
113 printf ("Invalid revision info copy in nvram !\n");
114 printf ("Press key:\n <c> to copy current revision info to nvram.\n");
115 printf (" <r> to reenter revision info.\n");
117 if (0 != readline (NULL)) {
118 switch ((char) toupper (console_buffer[0])) {
131 memcpy (buf, &eerev.revision[0][0], 14); /* save all revision info */
132 printf ("Enter revision number (0-9): %c ",
133 eerev.revision[0][0]);
134 if (0 != readline (NULL)) {
135 eerev.revision[0][0] =
136 (char) toupper (console_buffer[0]);
137 memcpy (&eerev.revision[1][0], buf, 12); /* shift rest of rev info */
140 printf ("Enter revision character (A-Z): %c ",
141 eerev.revision[0][1]);
142 if (1 == readline (NULL)) {
143 eerev.revision[0][1] =
144 (char) toupper (console_buffer[0]);
147 printf ("Enter board name (V-XXXX-XXXX): %s ",
148 (char *) &eerev.board);
149 if (11 == readline (NULL)) {
150 for (i = 0; i < 11; i++)
152 (char) toupper (console_buffer[i]);
153 eerev.board[11] = '\0';
156 printf ("Enter serial number: %s ", (char *) &eerev.serial);
157 if (6 == readline (NULL)) {
158 for (i = 0; i < 6; i++)
159 eerev.serial[i] = console_buffer[i];
160 eerev.serial[6] = '\0';
163 printf ("Enter ether node ID with leading zero (HEX): %02x%02x%02x%02x%02x%02x ", eerev.etheraddr[0], eerev.etheraddr[1], eerev.etheraddr[2], eerev.etheraddr[3], eerev.etheraddr[4], eerev.etheraddr[5]);
164 if (12 == readline (NULL)) {
165 for (i = 0; i < 12; i += 2)
166 eerev.etheraddr[i >> 1] =
169 (console_buffer[i]) -
172 (console_buffer[i + 1]) -
176 l = strlen ((char *) &eerev.text);
177 printf ("Add to text section (max 64 chr): %s ",
178 (char *) &eerev.text);
179 if (0 != readline (NULL)) {
180 for (i = l; i < 63; i++)
181 eerev.text[i] = console_buffer[i - l];
182 eerev.text[63] = '\0';
185 /* prepare network eeprom */
186 memset (buf, 0, 128);
188 buf[0] = eerev.etheraddr[1];
189 buf[1] = eerev.etheraddr[0];
190 buf[2] = eerev.etheraddr[3];
191 buf[3] = eerev.etheraddr[2];
192 buf[4] = eerev.etheraddr[5];
193 buf[5] = eerev.etheraddr[4];
204 printf ("\nSRom: Writing i82559 info ........ ");
205 if (eepro100_srom_store ((unsigned short *) buf) == -1)
212 el_srom_checksum ((u_char *) eerev.board, eerev.size);
214 /* write new values */
215 printf ("\nSRom: Writing revision info ...... ");
216 if (mpc107_srom_store
217 ((BLOCK_SIZE - sizeof (revinfo)), (u_char *) & eerev,
218 sizeof (revinfo), SECOND_DEVICE, FIRST_BLOCK) == -1)
219 printf ("FAILED\n\n");
223 /* write new values as shadow image to nvram */
224 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
225 CONFIG_SYS_SROM_SIZE);
230 /* copy current values as shadow image to nvram */
231 if (initSrom == 0 && copyNv == 1)
232 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
233 CONFIG_SYS_SROM_SIZE);
235 /* update environment */
236 sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x",
237 eerev.etheraddr[0], eerev.etheraddr[1],
238 eerev.etheraddr[2], eerev.etheraddr[3],
239 eerev.etheraddr[4], eerev.etheraddr[5]);
240 setenv ("ethaddr", buf);
242 /* print actual board identification */
243 printf ("Ident: %s Ser %s Rev %c%c\n",
244 eerev.board, (char *) &eerev.serial,
245 eerev.revision[0][0], eerev.revision[0][1]);
250 /*----------------------------------------------------------------------------*/