2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <linux/ctype.h>
16 extern int l2_cache_enable (int l2control
);
17 extern int eepro100_write_eeprom (struct eth_device
*dev
, int location
,
18 int addr_len
, unsigned short data
);
19 extern int read_eeprom (struct eth_device
*dev
, int location
, int addr_len
);
21 /*----------------------------------------------------------------------------*/
23 * read/write to nvram is only byte access
25 void *nvram_read (void *dest
, const long src
, size_t count
)
27 uchar
*d
= (uchar
*) dest
;
28 uchar
*s
= (uchar
*) (CONFIG_ENV_MAP_ADRS
+ src
);
36 void nvram_write (long dest
, const void *src
, size_t count
)
38 uchar
*d
= (uchar
*) (CONFIG_ENV_MAP_ADRS
+ dest
);
39 uchar
*s
= (uchar
*) src
;
45 /*----------------------------------------------------------------------------*/
47 * handle sroms on ELPPC
49 * set serial console as default
51 int misc_init_r (void)
55 u_int i
, l
, initSrom
, copyNv
;
57 char hex
[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
58 0, 0, 0, 0, 10, 11, 12, 13, 14, 15
61 /* Clock setting for MPC107 i2c */
62 mpc107_i2c_init (MPC107_EUMB_ADDR
, 0x2b);
65 out32r (MPC107_EUMB_GCR
, 0xa0000000);
66 while (in32r (MPC107_EUMB_GCR
) & 0x80000000); /* Wait for reset to complete */
67 out32r (MPC107_EUMB_GCR
, 0x20000000); /* Put into into mixed mode */
68 while (in32r (MPC107_EUMB_IACKR
) != 0xff); /* Clear all pending interrupts */
71 * Check/Remake revision info
76 /* read out current revision srom contens */
77 mpc107_srom_load (0x0000, (u_char
*) & eerev
, sizeof (revinfo
),
78 SECOND_DEVICE
, FIRST_BLOCK
);
80 /* read out current nvram shadow image */
81 nvram_read (buf
, CONFIG_SYS_NV_SROM_COPY_ADDR
, CONFIG_SYS_SROM_SIZE
);
83 if (strcmp (eerev
.magic
, "ELTEC") != 0) {
84 /* srom is not initialized -> create a default revision info */
85 for (i
= 0, ptr
= (u_char
*) & eerev
; i
< sizeof (revinfo
);
88 strcpy (eerev
.magic
, "ELTEC");
92 eerev
.category
[0] = 0x01;
94 /* node id from dead e128 as default */
95 eerev
.etheraddr
[0] = 0x00;
96 eerev
.etheraddr
[1] = 0x00;
97 eerev
.etheraddr
[2] = 0x5B;
98 eerev
.etheraddr
[3] = 0x00;
99 eerev
.etheraddr
[4] = 0x2E;
100 eerev
.etheraddr
[5] = 0x4D;
102 /* cache config word for ELPPC */
103 memset(&eerev
.res
[0], 0, 4);
105 initSrom
= 1; /* force dialog */
106 copyNv
= 1; /* copy to nvram */
110 && (el_srom_checksum ((u_char
*) & eerev
, CONFIG_SYS_SROM_SIZE
) !=
111 el_srom_checksum ((u_char
*) buf
, CONFIG_SYS_SROM_SIZE
))) {
112 printf ("Invalid revision info copy in nvram !\n");
113 printf ("Press key:\n <c> to copy current revision info to nvram.\n");
114 printf (" <r> to reenter revision info.\n");
116 if (0 != readline (NULL
)) {
117 switch ((char) toupper (console_buffer
[0])) {
130 memcpy (buf
, &eerev
.revision
[0][0], 14); /* save all revision info */
131 printf ("Enter revision number (0-9): %c ",
132 eerev
.revision
[0][0]);
133 if (0 != readline (NULL
)) {
134 eerev
.revision
[0][0] =
135 (char) toupper (console_buffer
[0]);
136 memcpy (&eerev
.revision
[1][0], buf
, 12); /* shift rest of rev info */
139 printf ("Enter revision character (A-Z): %c ",
140 eerev
.revision
[0][1]);
141 if (1 == readline (NULL
)) {
142 eerev
.revision
[0][1] =
143 (char) toupper (console_buffer
[0]);
146 printf ("Enter board name (V-XXXX-XXXX): %s ",
147 (char *) &eerev
.board
);
148 if (11 == readline (NULL
)) {
149 for (i
= 0; i
< 11; i
++)
151 (char) toupper (console_buffer
[i
]);
152 eerev
.board
[11] = '\0';
155 printf ("Enter serial number: %s ", (char *) &eerev
.serial
);
156 if (6 == readline (NULL
)) {
157 for (i
= 0; i
< 6; i
++)
158 eerev
.serial
[i
] = console_buffer
[i
];
159 eerev
.serial
[6] = '\0';
162 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]);
163 if (12 == readline (NULL
)) {
164 for (i
= 0; i
< 12; i
+= 2)
165 eerev
.etheraddr
[i
>> 1] =
168 (console_buffer
[i
]) -
171 (console_buffer
[i
+ 1]) -
175 l
= strlen ((char *) &eerev
.text
);
176 printf ("Add to text section (max 64 chr): %s ",
177 (char *) &eerev
.text
);
178 if (0 != readline (NULL
)) {
179 for (i
= l
; i
< 63; i
++)
180 eerev
.text
[i
] = console_buffer
[i
- l
];
181 eerev
.text
[63] = '\0';
184 /* prepare network eeprom */
185 memset (buf
, 0, 128);
187 buf
[0] = eerev
.etheraddr
[1];
188 buf
[1] = eerev
.etheraddr
[0];
189 buf
[2] = eerev
.etheraddr
[3];
190 buf
[3] = eerev
.etheraddr
[2];
191 buf
[4] = eerev
.etheraddr
[5];
192 buf
[5] = eerev
.etheraddr
[4];
203 printf ("\nSRom: Writing i82559 info ........ ");
204 if (eepro100_srom_store ((unsigned short *) buf
) == -1)
211 el_srom_checksum ((u_char
*) eerev
.board
, eerev
.size
);
213 /* write new values */
214 printf ("\nSRom: Writing revision info ...... ");
215 if (mpc107_srom_store
216 ((BLOCK_SIZE
- sizeof (revinfo
)), (u_char
*) & eerev
,
217 sizeof (revinfo
), SECOND_DEVICE
, FIRST_BLOCK
) == -1)
218 printf ("FAILED\n\n");
222 /* write new values as shadow image to nvram */
223 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR
, (void *) &eerev
,
224 CONFIG_SYS_SROM_SIZE
);
229 /* copy current values as shadow image to nvram */
230 if (initSrom
== 0 && copyNv
== 1)
231 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR
, (void *) &eerev
,
232 CONFIG_SYS_SROM_SIZE
);
234 /* update environment */
235 sprintf (buf
, "%02x:%02x:%02x:%02x:%02x:%02x",
236 eerev
.etheraddr
[0], eerev
.etheraddr
[1],
237 eerev
.etheraddr
[2], eerev
.etheraddr
[3],
238 eerev
.etheraddr
[4], eerev
.etheraddr
[5]);
239 setenv ("ethaddr", buf
);
241 /* print actual board identification */
242 printf ("Ident: %s Ser %s Rev %c%c\n",
243 eerev
.board
, (char *) &eerev
.serial
,
244 eerev
.revision
[0][0], eerev
.revision
[0][1]);
249 /*----------------------------------------------------------------------------*/