]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/eltec/elppc/misc.c
Merge remote-tracking branch 'u-boot-samsung/master'
[karo-tx-uboot.git] / board / eltec / elppc / misc.c
1 /*
2  * (C) Copyright 2002 ELTEC Elektronik AG
3  * Frank Gottschling <fgottschling@eltec.de>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 /* includes */
9 #include <common.h>
10 #include <cli.h>
11 #include <linux/ctype.h>
12 #include <pci.h>
13 #include <net.h>
14 #include "srom.h"
15
16 /* imports  */
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);
21
22 /*----------------------------------------------------------------------------*/
23 /*
24  * read/write to nvram is only byte access
25  */
26 void *nvram_read (void *dest, const long src, size_t count)
27 {
28         uchar *d = (uchar *) dest;
29         uchar *s = (uchar *) (CONFIG_ENV_MAP_ADRS + src);
30
31         while (count--)
32                 *d++ = *s++;
33
34         return dest;
35 }
36
37 void nvram_write (long dest, const void *src, size_t count)
38 {
39         uchar *d = (uchar *) (CONFIG_ENV_MAP_ADRS + dest);
40         uchar *s = (uchar *) src;
41
42         while (count--)
43                 *d++ = *s++;
44 }
45
46 /*----------------------------------------------------------------------------*/
47 /*
48  * handle sroms on ELPPC
49  * fix ether address
50  * set serial console as default
51  */
52 int misc_init_r (void)
53 {
54         revinfo eerev;
55         u_char *ptr;
56         u_int i, l, initSrom, copyNv;
57         char buf[256];
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
60         };
61
62         /* Clock setting for MPC107 i2c */
63         mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b);
64
65         /* Reset the EPIC */
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 */
70
71         /*
72          * Check/Remake revision info
73          */
74         initSrom = 0;
75         copyNv = 0;
76
77         /* read out current revision srom contens */
78         mpc107_srom_load (0x0000, (u_char *) & eerev, sizeof (revinfo),
79                           SECOND_DEVICE, FIRST_BLOCK);
80
81         /* read out current nvram shadow image */
82         nvram_read (buf, CONFIG_SYS_NV_SROM_COPY_ADDR, CONFIG_SYS_SROM_SIZE);
83
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);
87                      i++)
88                         *ptr++ = 0x00;
89                 strcpy (eerev.magic, "ELTEC");
90                 eerev.revrev[0] = 1;
91                 eerev.revrev[1] = 0;
92                 eerev.size = 0x00E0;
93                 eerev.category[0] = 0x01;
94
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;
102
103                 /* cache config word for ELPPC */
104                 memset(&eerev.res[0], 0, 4);
105
106                 initSrom = 1;   /* force dialog */
107                 copyNv = 1;     /* copy to nvram */
108         }
109
110         if ((copyNv == 0)
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");
116                 printf ("=> ");
117                 if (0 != cli_readline(NULL)) {
118                         switch ((char) toupper (console_buffer[0])) {
119                         case 'C':
120                                 copyNv = 1;
121                                 break;
122                         case 'R':
123                                 copyNv = 1;
124                                 initSrom = 1;
125                                 break;
126                         }
127                 }
128         }
129
130         if (initSrom) {
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 != cli_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 */
138                 }
139
140                 printf ("Enter revision character (A-Z): %c  ",
141                         eerev.revision[0][1]);
142                 if (1 == cli_readline(NULL)) {
143                         eerev.revision[0][1] =
144                                 (char) toupper (console_buffer[0]);
145                 }
146
147                 printf ("Enter board name (V-XXXX-XXXX): %s  ",
148                         (char *) &eerev.board);
149                 if (11 == cli_readline(NULL)) {
150                         for (i = 0; i < 11; i++)
151                                 eerev.board[i] =
152                                         (char) toupper (console_buffer[i]);
153                         eerev.board[11] = '\0';
154                 }
155
156                 printf ("Enter serial number: %s ", (char *) &eerev.serial);
157                 if (6 == cli_readline(NULL)) {
158                         for (i = 0; i < 6; i++)
159                                 eerev.serial[i] = console_buffer[i];
160                         eerev.serial[6] = '\0';
161                 }
162
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 == cli_readline(NULL)) {
165                         for (i = 0; i < 12; i += 2)
166                                 eerev.etheraddr[i >> 1] =
167                                         (char) (16 *
168                                                 hex[toupper
169                                                     (console_buffer[i]) -
170                                                     '0'] +
171                                                 hex[toupper
172                                                     (console_buffer[i + 1]) -
173                                                     '0']);
174                 }
175
176                 l = strlen ((char *) &eerev.text);
177                 printf ("Add to text section (max 64 chr): %s ",
178                         (char *) &eerev.text);
179                 if (0 != cli_readline(NULL)) {
180                         for (i = l; i < 63; i++)
181                                 eerev.text[i] = console_buffer[i - l];
182                         eerev.text[63] = '\0';
183                 }
184
185                 /* prepare network eeprom */
186                 memset (buf, 0, 128);
187
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];
194
195                 buf[20] = 0x48;
196                 buf[21] = 0xB2;
197
198                 buf[22] = 0x00;
199                 buf[23] = 0x04;
200
201                 buf[24] = 0x14;
202                 buf[25] = 0x33;
203
204                 printf ("\nSRom:  Writing i82559 info ........ ");
205                 if (eepro100_srom_store ((unsigned short *) buf) == -1)
206                         printf ("FAILED\n");
207                 else
208                         printf ("OK\n");
209
210                 /* update CRC */
211                 eerev.crc =
212                         el_srom_checksum ((u_char *) eerev.board, eerev.size);
213
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");
220                 else
221                         printf ("OK\n\n");
222
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);
226
227         }
228
229         /*if (initSrom) */
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);
234
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);
241
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]);
246
247         return (0);
248 }
249
250 /*----------------------------------------------------------------------------*/