blob: ae5304a9b45ed42ec1e038374fef7941f3e11ba8 [file] [log] [blame]
Haiying Wang34c68782006-07-12 10:48:05 -04001/*
Haiying Wange5607542009-06-04 16:12:40 -04002 * Copyright 2006, 2008-2009 Freescale Semiconductor
Haiying Wang34c68782006-07-12 10:48:05 -04003 * York Sun (yorksun@freescale.com)
4 * Haiying Wang (haiying.wang@freescale.com)
Timur Tabibdea8372008-06-19 17:56:11 -05005 * Timur Tabi (timur@freescale.com)
Haiying Wang34c68782006-07-12 10:48:05 -04006 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <command.h>
28#include <i2c.h>
29#include <linux/ctype.h>
30
Timur Tabibdea8372008-06-19 17:56:11 -050031#include "../common/eeprom.h"
Haiying Wang34c68782006-07-12 10:48:05 -040032
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033#if !defined(CONFIG_SYS_I2C_EEPROM_CCID) && !defined(CONFIG_SYS_I2C_EEPROM_NXID)
34#error "Please define either CONFIG_SYS_I2C_EEPROM_CCID or CONFIG_SYS_I2C_EEPROM_NXID"
Timur Tabibdea8372008-06-19 17:56:11 -050035#endif
Haiying Wang34c68782006-07-12 10:48:05 -040036
Haiying Wange5607542009-06-04 16:12:40 -040037#define MAX_NUM_PORTS 8 /* This value must be 8 as defined in doc */
38
Timur Tabibdea8372008-06-19 17:56:11 -050039/**
40 * static eeprom: EEPROM layout for CCID or NXID formats
41 *
42 * See application note AN3638 for details.
43 */
44static struct __attribute__ ((__packed__)) eeprom {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045#ifdef CONFIG_SYS_I2C_EEPROM_CCID
Timur Tabibdea8372008-06-19 17:56:11 -050046 u8 id[4]; /* 0x00 - 0x03 EEPROM Tag 'CCID' */
47 u8 major; /* 0x04 Board revision, major */
48 u8 minor; /* 0x05 Board revision, minor */
49 u8 sn[10]; /* 0x06 - 0x0F Serial Number*/
50 u8 errata[2]; /* 0x10 - 0x11 Errata Level */
51 u8 date[6]; /* 0x12 - 0x17 Build Date */
52 u8 res_0[40]; /* 0x18 - 0x3f Reserved */
53 u8 mac_count; /* 0x40 Number of MAC addresses */
54 u8 mac_flag; /* 0x41 MAC table flags */
Haiying Wange5607542009-06-04 16:12:40 -040055 u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - 0x71 MAC addresses */
Timur Tabibdea8372008-06-19 17:56:11 -050056 u32 crc; /* 0x72 CRC32 checksum */
57#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020058#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -050059 u8 id[4]; /* 0x00 - 0x03 EEPROM Tag 'NXID' */
60 u8 sn[12]; /* 0x04 - 0x0F Serial Number */
61 u8 errata[5]; /* 0x10 - 0x14 Errata Level */
62 u8 date[6]; /* 0x15 - 0x1a Build Date */
63 u8 res_0; /* 0x1b Reserved */
64 u32 version; /* 0x1c - 0x1f NXID Version */
65 u8 tempcal[8]; /* 0x20 - 0x27 Temperature Calibration Factors */
66 u8 tempcalsys[2]; /* 0x28 - 0x29 System Temperature Calibration Factors */
67 u8 tempcalflags; /* 0x2a Temperature Calibration Flags */
68 u8 res_1[21]; /* 0x2b - 0x3f Reserved */
69 u8 mac_count; /* 0x40 Number of MAC addresses */
70 u8 mac_flag; /* 0x41 MAC table flags */
Haiying Wange5607542009-06-04 16:12:40 -040071 u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - 0x71 MAC addresses */
Timur Tabibdea8372008-06-19 17:56:11 -050072 u32 crc; /* 0x72 CRC32 checksum */
73#endif
74} e;
75
76/* Set to 1 if we've read EEPROM into memory */
77static int has_been_read = 0;
78
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020079#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -050080/* Is this a valid NXID EEPROM? */
81#define is_valid (*((u32 *)e.id) == (('N' << 24) | ('X' << 16) | ('I' << 8) | 'D'))
82#endif
83
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020084#ifdef CONFIG_SYS_I2C_EEPROM_CCID
Timur Tabibdea8372008-06-19 17:56:11 -050085/* Is this a valid CCID EEPROM? */
86#define is_valid (*((u32 *)e.id) == (('C' << 24) | ('C' << 16) | ('I' << 8) | 'D'))
87#endif
88
89/**
90 * show_eeprom - display the contents of the EEPROM
91 */
92static void show_eeprom(void)
Haiying Wang34c68782006-07-12 10:48:05 -040093{
94 int i;
Timur Tabibdea8372008-06-19 17:56:11 -050095 unsigned int crc;
Haiying Wang34c68782006-07-12 10:48:05 -040096
Timur Tabibdea8372008-06-19 17:56:11 -050097 /* EEPROM tag ID, either CCID or NXID */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -050099 printf("ID: %c%c%c%c v%u\n", e.id[0], e.id[1], e.id[2], e.id[3],
100 be32_to_cpu(e.version));
101#else
102 printf("ID: %c%c%c%c\n", e.id[0], e.id[1], e.id[2], e.id[3]);
103#endif
Haiying Wang34cf9592008-01-16 17:12:12 -0500104
Timur Tabibdea8372008-06-19 17:56:11 -0500105 /* Serial number */
106 printf("SN: %s\n", e.sn);
Haiying Wang34cf9592008-01-16 17:12:12 -0500107
Timur Tabibdea8372008-06-19 17:56:11 -0500108 /* Errata level. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200109#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -0500110 printf("Errata: %s\n", e.errata);
111#else
112 printf("Errata: %c%c\n",
113 e.errata[0] ? e.errata[0] : '.',
114 e.errata[1] ? e.errata[1] : '.');
115#endif
Haiying Wang34cf9592008-01-16 17:12:12 -0500116
Timur Tabibdea8372008-06-19 17:56:11 -0500117 /* Build date, BCD date values, as YYMMDDhhmmss */
118 printf("Build date: 20%02x/%02x/%02x %02x:%02x:%02x %s\n",
119 e.date[0], e.date[1], e.date[2],
120 e.date[3] & 0x7F, e.date[4], e.date[5],
121 e.date[3] & 0x80 ? "PM" : "");
Haiying Wang34cf9592008-01-16 17:12:12 -0500122
Timur Tabibdea8372008-06-19 17:56:11 -0500123 /* Show MAC addresses */
Haiying Wange5607542009-06-04 16:12:40 -0400124 for (i = 0; i < min(e.mac_count, MAX_NUM_PORTS); i++) {
125
Timur Tabibdea8372008-06-19 17:56:11 -0500126 u8 *p = e.mac[i];
Haiying Wang34cf9592008-01-16 17:12:12 -0500127
Timur Tabibdea8372008-06-19 17:56:11 -0500128 printf("Eth%u: %02x:%02x:%02x:%02x:%02x:%02x\n", i,
129 p[0], p[1], p[2], p[3], p[4], p[5]);
130 }
Haiying Wang34cf9592008-01-16 17:12:12 -0500131
Timur Tabibdea8372008-06-19 17:56:11 -0500132 crc = crc32(0, (void *)&e, sizeof(e) - 4);
Haiying Wang34c68782006-07-12 10:48:05 -0400133
Timur Tabibdea8372008-06-19 17:56:11 -0500134 if (crc == be32_to_cpu(e.crc))
135 printf("CRC: %08x\n", be32_to_cpu(e.crc));
136 else
137 printf("CRC: %08x (should be %08x)\n",
138 be32_to_cpu(e.crc), crc);
Haiying Wang34c68782006-07-12 10:48:05 -0400139
Timur Tabibdea8372008-06-19 17:56:11 -0500140#ifdef DEBUG
141 printf("EEPROM dump: (0x%x bytes)\n", sizeof(e));
142 for (i = 0; i < sizeof(e); i++) {
143 if ((i % 16) == 0)
144 printf("%02X: ", i);
145 printf("%02X ", ((u8 *)&e)[i]);
146 if (((i % 16) == 15) || (i == sizeof(e) - 1))
147 printf("\n");
148 }
149#endif
Haiying Wang34c68782006-07-12 10:48:05 -0400150}
151
Timur Tabibdea8372008-06-19 17:56:11 -0500152/**
153 * read_eeprom - read the EEPROM into memory
154 */
155static int read_eeprom(void)
Haiying Wang34c68782006-07-12 10:48:05 -0400156{
Timur Tabibdea8372008-06-19 17:56:11 -0500157 int ret;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200158#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500159 unsigned int bus;
160#endif
Haiying Wang34c68782006-07-12 10:48:05 -0400161
Timur Tabibdea8372008-06-19 17:56:11 -0500162 if (has_been_read)
163 return 0;
Haiying Wang34c68782006-07-12 10:48:05 -0400164
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200165#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500166 bus = i2c_get_bus_num();
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200167 i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
Timur Tabibdea8372008-06-19 17:56:11 -0500168#endif
169
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200170 ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
Timur Tabibdea8372008-06-19 17:56:11 -0500171 (void *)&e, sizeof(e));
172
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200173#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500174 i2c_set_bus_num(bus);
175#endif
176
177#ifdef DEBUG
178 show_eeprom();
179#endif
180
181 has_been_read = (ret == 0) ? 1 : 0;
182
183 return ret;
Haiying Wang34c68782006-07-12 10:48:05 -0400184}
185
Timur Tabibdea8372008-06-19 17:56:11 -0500186/**
187 * prog_eeprom - write the EEPROM from memory
188 */
189static int prog_eeprom(void)
Haiying Wang34c68782006-07-12 10:48:05 -0400190{
191 int ret, i, length;
Timur Tabibdea8372008-06-19 17:56:11 -0500192 unsigned int crc;
193 void *p;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200194#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500195 unsigned int bus;
196#endif
Haiying Wang34c68782006-07-12 10:48:05 -0400197
Timur Tabibdea8372008-06-19 17:56:11 -0500198 /* Set the reserved values to 0xFF */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200199#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -0500200 e.res_0 = 0xFF;
201 memset(e.res_1, 0xFF, sizeof(e.res_1));
202#else
203 memset(e.res_0, 0xFF, sizeof(e.res_0));
204#endif
Haiying Wang34cf9592008-01-16 17:12:12 -0500205
Timur Tabibdea8372008-06-19 17:56:11 -0500206 length = sizeof(e);
207 crc = crc32(0, (void *)&e, length - 4);
208 e.crc = cpu_to_be32(crc);
209
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200210#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500211 bus = i2c_get_bus_num();
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200212 i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
Timur Tabibdea8372008-06-19 17:56:11 -0500213#endif
214
215 for (i = 0, p = &e; i < length; i += 8, p += 8) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200216 ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
Timur Tabibdea8372008-06-19 17:56:11 -0500217 p, min((length - i), 8));
Haiying Wang34c68782006-07-12 10:48:05 -0400218 if (ret)
219 break;
Timur Tabibdea8372008-06-19 17:56:11 -0500220 udelay(5000); /* 5ms write cycle timing */
Haiying Wang34c68782006-07-12 10:48:05 -0400221 }
Timur Tabibdea8372008-06-19 17:56:11 -0500222
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200223#ifdef CONFIG_SYS_EEPROM_BUS_NUM
Timur Tabibdea8372008-06-19 17:56:11 -0500224 i2c_set_bus_num(bus);
225#endif
226
Haiying Wang34c68782006-07-12 10:48:05 -0400227 if (ret) {
228 printf("Programming failed.\n");
229 return -1;
Haiying Wang34c68782006-07-12 10:48:05 -0400230 }
Timur Tabibdea8372008-06-19 17:56:11 -0500231
232 printf("Programming passed.\n");
Haiying Wang34c68782006-07-12 10:48:05 -0400233 return 0;
234}
235
Timur Tabibdea8372008-06-19 17:56:11 -0500236/**
237 * h2i - converts hex character into a number
238 *
239 * This function takes a hexadecimal character (e.g. '7' or 'C') and returns
240 * the integer equivalent.
241 */
242static inline u8 h2i(char p)
243{
244 if ((p >= '0') && (p <= '9'))
245 return p - '0';
246
247 if ((p >= 'A') && (p <= 'F'))
248 return (p - 'A') + 10;
249
250 if ((p >= 'a') && (p <= 'f'))
251 return (p - 'a') + 10;
252
253 return 0;
254}
255
256/**
257 * set_date - stores the build date into the EEPROM
258 *
259 * This function takes a pointer to a string in the format "YYMMDDhhmmss"
260 * (2-digit year, 2-digit month, etc), converts it to a 6-byte BCD string,
261 * and stores it in the build date field of the EEPROM local copy.
262 */
263static void set_date(const char *string)
264{
265 unsigned int i;
266
267 if (strlen(string) != 12) {
268 printf("Usage: mac date YYMMDDhhmmss\n");
269 return;
270 }
271
272 for (i = 0; i < 6; i++)
273 e.date[i] = h2i(string[2 * i]) << 4 | h2i(string[2 * i + 1]);
274}
275
276/**
277 * set_mac_address - stores a MAC address into the EEPROM
278 *
279 * This function takes a pointer to MAC address string
280 * (i.e."XX:XX:XX:XX:XX:XX", where "XX" is a two-digit hex number) and
281 * stores it in one of the MAC address fields of the EEPROM local copy.
282 */
283static void set_mac_address(unsigned int index, const char *string)
284{
285 char *p = (char *) string;
286 unsigned int i;
287
288 if (!string) {
289 printf("Usage: mac <n> XX:XX:XX:XX:XX:XX\n");
290 return;
291 }
292
293 for (i = 0; *p && (i < 6); i++) {
294 e.mac[index][i] = simple_strtoul(p, &p, 16);
295 if (*p == ':')
296 p++;
297 }
298}
299
300int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
Haiying Wang34c68782006-07-12 10:48:05 -0400301{
302 int i;
Timur Tabibdea8372008-06-19 17:56:11 -0500303 char cmd;
Haiying Wang34c68782006-07-12 10:48:05 -0400304
Timur Tabibdea8372008-06-19 17:56:11 -0500305 if (argc == 1) {
306 show_eeprom();
307 return 0;
308 }
309
310 cmd = argv[1][0];
311
312 if (cmd == 'r') {
313 read_eeprom();
314 return 0;
315 }
Haiying Wang34c68782006-07-12 10:48:05 -0400316
Timur Tabibdea8372008-06-19 17:56:11 -0500317 if ((cmd == 'i') && (argc > 2)) {
318 for (i = 0; i < 4; i++)
319 e.id[i] = argv[2][i];
320 return 0;
321 }
322
323 if (!is_valid) {
324 printf("Please read the EEPROM ('r') and/or set the ID ('i') first.\n");
325 return 0;
326 }
327
328 if (argc == 2) {
Haiying Wang34c68782006-07-12 10:48:05 -0400329 switch (cmd) {
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500330 case 's': /* save */
Timur Tabibdea8372008-06-19 17:56:11 -0500331 prog_eeprom();
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500332 break;
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500333 default:
Peter Tyserddb3af92009-01-27 18:03:10 -0600334 cmd_usage(cmdtp);
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500335 break;
Haiying Wang34c68782006-07-12 10:48:05 -0400336 }
Timur Tabibdea8372008-06-19 17:56:11 -0500337
338 return 0;
339 }
340
341 /* We know we have at least one parameter */
342
343 switch (cmd) {
344 case 'n': /* serial number */
345 memset(e.sn, 0, sizeof(e.sn));
346 strncpy((char *)e.sn, argv[2], sizeof(e.sn) - 1);
347 break;
348 case 'e': /* errata */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200349#ifdef CONFIG_SYS_I2C_EEPROM_NXID
Timur Tabibdea8372008-06-19 17:56:11 -0500350 memset(e.errata, 0, 5);
351 strncpy((char *)e.errata, argv[2], 4);
352#else
353 e.errata[0] = argv[2][0];
354 e.errata[1] = argv[2][1];
355#endif
356 break;
357 case 'd': /* date BCD format YYMMDDhhmmss */
358 set_date(argv[2]);
359 break;
360 case 'p': /* MAC table size */
361 e.mac_count = simple_strtoul(argv[2], NULL, 16);
362 break;
363 case '0' ... '7': /* "mac 0" through "mac 7" */
364 set_mac_address(cmd - '0', argv[2]);
365 break;
366 case 'h': /* help */
367 default:
Peter Tyserddb3af92009-01-27 18:03:10 -0600368 cmd_usage(cmdtp);
Timur Tabibdea8372008-06-19 17:56:11 -0500369 break;
Haiying Wang34c68782006-07-12 10:48:05 -0400370 }
Timur Tabibdea8372008-06-19 17:56:11 -0500371
Haiying Wang34c68782006-07-12 10:48:05 -0400372 return 0;
373}
374
Timur Tabibdea8372008-06-19 17:56:11 -0500375/**
376 * mac_read_from_eeprom - read the MAC addresses from EEPROM
377 *
378 * This function reads the MAC addresses from EEPROM and sets the
379 * appropriate environment variables for each one read.
380 *
381 * The environment variables are only set if they haven't been set already.
382 * This ensures that any user-saved variables are never overwritten.
383 *
384 * This function must be called after relocation.
385 */
Haiying Wang34c68782006-07-12 10:48:05 -0400386int mac_read_from_eeprom(void)
387{
Timur Tabibdea8372008-06-19 17:56:11 -0500388 unsigned int i;
Haiying Wang34c68782006-07-12 10:48:05 -0400389
Timur Tabibdea8372008-06-19 17:56:11 -0500390 if (read_eeprom()) {
Haiying Wang34c68782006-07-12 10:48:05 -0400391 printf("Read failed.\n");
392 return -1;
393 }
394
Timur Tabibdea8372008-06-19 17:56:11 -0500395 if (!is_valid) {
396 printf("Invalid ID (%02x %02x %02x %02x)\n", e.id[0], e.id[1], e.id[2], e.id[3]);
Haiying Wang34c68782006-07-12 10:48:05 -0400397 return -1;
Timur Tabibdea8372008-06-19 17:56:11 -0500398 }
399
400 if (be32_to_cpu(e.crc) != 0xFFFFFFFF) {
401 u32 crc = crc32(0, (void *)&e, sizeof(e) - 4);
402
403 if (crc != be32_to_cpu(e.crc)) {
404 printf("CRC mismatch (%08x != %08x).\n", crc,
405 be32_to_cpu(e.crc));
406 return -1;
Haiying Wang34c68782006-07-12 10:48:05 -0400407 }
408 }
Timur Tabibdea8372008-06-19 17:56:11 -0500409
Haiying Wange5607542009-06-04 16:12:40 -0400410 /* Check the number of MAC addresses which is limited to
411 * MAX_NUM_PORTS.
412 */
413 if (e.mac_count > MAX_NUM_PORTS) {
414 printf("Warning: The number of MAC addresses is greater"
415 " than %u, force it to %u.\n", MAX_NUM_PORTS,
416 MAX_NUM_PORTS);
417 e.mac_count = MAX_NUM_PORTS;
418 }
419
420 for (i = 0; i < e.mac_count; i++) {
Timur Tabibdea8372008-06-19 17:56:11 -0500421 if (memcmp(&e.mac[i], "\0\0\0\0\0\0", 6) &&
422 memcmp(&e.mac[i], "\xFF\xFF\xFF\xFF\xFF\xFF", 6)) {
423 char ethaddr[18];
424 char enetvar[9];
425
426 sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
427 e.mac[i][0],
428 e.mac[i][1],
429 e.mac[i][2],
430 e.mac[i][3],
431 e.mac[i][4],
432 e.mac[i][5]);
433 sprintf(enetvar, i ? "eth%daddr" : "ethaddr", i);
434 /* Only initialize environment variables that are blank
435 * (i.e. have not yet been set)
436 */
437 if (!getenv(enetvar))
438 setenv(enetvar, ethaddr);
439 }
440 }
441
Haiying Wang34c68782006-07-12 10:48:05 -0400442 return 0;
443}
Timur Tabibdea8372008-06-19 17:56:11 -0500444
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200445#ifdef CONFIG_SYS_I2C_EEPROM_CCID
Timur Tabibdea8372008-06-19 17:56:11 -0500446
447/**
448 * get_cpu_board_revision - get the CPU board revision on 85xx boards
449 *
450 * Read the EEPROM to determine the board revision.
451 *
452 * This function is called before relocation, so we need to read a private
453 * copy of the EEPROM into a local variable on the stack.
454 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200455 * Also, we assume that CONFIG_SYS_EEPROM_BUS_NUM == CONFIG_SYS_SPD_BUS_NUM. The global
456 * variable i2c_bus_num must be compile-time initialized to CONFIG_SYS_SPD_BUS_NUM,
Timur Tabibdea8372008-06-19 17:56:11 -0500457 * so that the SPD code will work. This means that all pre-relocation I2C
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200458 * operations can only occur on the CONFIG_SYS_SPD_BUS_NUM bus. So if
459 * CONFIG_SYS_EEPROM_BUS_NUM != CONFIG_SYS_SPD_BUS_NUM, then we can't read the EEPROM when
Timur Tabibdea8372008-06-19 17:56:11 -0500460 * this function is called. Oh well.
461 */
462unsigned int get_cpu_board_revision(void)
463{
464 struct board_eeprom {
465 u32 id; /* 0x00 - 0x03 EEPROM Tag 'CCID' */
466 u8 major; /* 0x04 Board revision, major */
467 u8 minor; /* 0x05 Board revision, minor */
468 } be;
469
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200470 i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
Timur Tabibdea8372008-06-19 17:56:11 -0500471 (void *)&be, sizeof(be));
472
473 if (be.id != (('C' << 24) | ('C' << 16) | ('I' << 8) | 'D'))
474 return MPC85XX_CPU_BOARD_REV(0, 0);
475
476 if ((be.major == 0xff) && (be.minor == 0xff))
477 return MPC85XX_CPU_BOARD_REV(0, 0);
478
Rafal Czubak5c50d142008-10-08 13:41:30 +0200479 return MPC85XX_CPU_BOARD_REV(be.major, be.minor);
Timur Tabibdea8372008-06-19 17:56:11 -0500480}
Timur Tabibdea8372008-06-19 17:56:11 -0500481#endif