1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <common.h>
23#include <i2c.h>
24
25#define EEPROM_LAYOUT_VER_OFFSET 44
26#define BOARD_SERIAL_OFFSET 20
27#define BOARD_SERIAL_OFFSET_LEGACY 8
28#define BOARD_REV_OFFSET 0
29#define BOARD_REV_OFFSET_LEGACY 6
30#define BOARD_REV_SIZE 4
31#define BOARD_REV_SIZE_LEGACY 2
32#define MAC_ADDR_OFFSET 4
33#define MAC_ADDR_OFFSET_LEGACY 0
34
35#define LAYOUT_INVALID 0
36#define LAYOUT_LEGACY 0xff
37
38static int eeprom_layout;
39
40static int cm_t3x_eeprom_read(uint offset, uchar *buf, int len)
41{
42 return i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, offset,
43 CONFIG_SYS_I2C_EEPROM_ADDR_LEN, buf, len);
44}
45
46static int eeprom_setup_layout(void)
47{
48 int res;
49
50 if (eeprom_layout != LAYOUT_INVALID)
51 return 0;
52
53 res = cm_t3x_eeprom_read(EEPROM_LAYOUT_VER_OFFSET,
54 (uchar *)&eeprom_layout, 1);
55 if (res) {
56 eeprom_layout = LAYOUT_INVALID;
57 return res;
58 }
59
60 if (eeprom_layout == 0 || eeprom_layout >= 0x20)
61 eeprom_layout = LAYOUT_LEGACY;
62
63 return 0;
64}
65
66void get_board_serial(struct tag_serialnr *serialnr)
67{
68 u32 serial[2];
69 uint offset;
70
71 memset(serialnr, 0, sizeof(*serialnr));
72 if (eeprom_setup_layout())
73 return;
74
75 offset = (eeprom_layout != LAYOUT_LEGACY) ?
76 BOARD_SERIAL_OFFSET : BOARD_SERIAL_OFFSET_LEGACY;
77 if (cm_t3x_eeprom_read(offset, (uchar *)serial, 8))
78 return;
79
80 if (serial[0] != 0xffffffff && serial[1] != 0xffffffff) {
81 serialnr->low = serial[0];
82 serialnr->high = serial[1];
83 }
84}
85
86
87
88
89
90int cm_t3x_eeprom_read_mac_addr(uchar *buf)
91{
92 uint offset;
93
94 if (eeprom_setup_layout())
95 return 0;
96
97 offset = (eeprom_layout != LAYOUT_LEGACY) ?
98 MAC_ADDR_OFFSET : MAC_ADDR_OFFSET_LEGACY;
99 return cm_t3x_eeprom_read(offset, buf, 6);
100}
101
102
103
104
105
106u32 get_board_rev(void)
107{
108 u32 rev = 0;
109 uint offset = BOARD_REV_OFFSET_LEGACY;
110 int len = BOARD_REV_SIZE_LEGACY;
111
112 if (eeprom_setup_layout())
113 return 0;
114
115 if (eeprom_layout != LAYOUT_LEGACY) {
116 offset = BOARD_REV_OFFSET;
117 len = BOARD_REV_SIZE;
118 }
119
120 if (cm_t3x_eeprom_read(offset, (uchar *)&rev, len))
121 return 0;
122
123 return rev;
124};
125