2 * (C) Copyright 2011 CompuLab, Ltd. <www.compulab.co.il>
4 * Authors: Nikita Kiryanov <nikita@compulab.co.il>
5 * Igor Grinberg <grinberg@compulab.co.il>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
25 #define EEPROM_LAYOUT_VER_OFFSET 44
26 #define BOARD_SERIAL_OFFSET 20
27 #define BOARD_SERIAL_OFFSET_LEGACY 8
29 #define LAYOUT_INVALID 0
30 #define LAYOUT_LEGACY 0xff
32 static int eeprom_layout; /* Implicitly LAYOUT_INVALID */
34 static int cm_t3x_eeprom_read(uint offset, uchar *buf, int len)
36 return i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, offset,
37 CONFIG_SYS_I2C_EEPROM_ADDR_LEN, buf, len);
40 static int eeprom_setup_layout(void)
44 if (eeprom_layout != LAYOUT_INVALID)
47 res = cm_t3x_eeprom_read(EEPROM_LAYOUT_VER_OFFSET,
48 (uchar *)&eeprom_layout, 1);
50 eeprom_layout = LAYOUT_INVALID;
54 if (eeprom_layout == 0 || eeprom_layout >= 0x20)
55 eeprom_layout = LAYOUT_LEGACY;
60 void get_board_serial(struct tag_serialnr *serialnr)
65 memset(serialnr, 0, sizeof(*serialnr));
66 if (eeprom_setup_layout())
69 offset = (eeprom_layout != LAYOUT_LEGACY) ?
70 BOARD_SERIAL_OFFSET : BOARD_SERIAL_OFFSET_LEGACY;
71 if (cm_t3x_eeprom_read(offset, (uchar *)serial, 8))
74 if (serial[0] != 0xffffffff && serial[1] != 0xffffffff) {
75 serialnr->low = serial[0];
76 serialnr->high = serial[1];