]>
Commit | Line | Data |
---|---|---|
82309250 NK |
1 | /* |
2 | * (C) Copyright 2011 CompuLab, Ltd. <www.compulab.co.il> | |
3 | * | |
4 | * Authors: Nikita Kiryanov <[email protected]> | |
5 | * Igor Grinberg <[email protected]> | |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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 | |
19 | * Foundation, Inc. | |
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 | |
7d3c97d7 NK |
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 | |
82309250 NK |
32 | |
33 | #define LAYOUT_INVALID 0 | |
34 | #define LAYOUT_LEGACY 0xff | |
35 | ||
36 | static int eeprom_layout; /* Implicitly LAYOUT_INVALID */ | |
37 | ||
38 | static int cm_t3x_eeprom_read(uint offset, uchar *buf, int len) | |
39 | { | |
40 | return i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, offset, | |
41 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, buf, len); | |
42 | } | |
43 | ||
44 | static int eeprom_setup_layout(void) | |
45 | { | |
46 | int res; | |
47 | ||
48 | if (eeprom_layout != LAYOUT_INVALID) | |
49 | return 0; | |
50 | ||
51 | res = cm_t3x_eeprom_read(EEPROM_LAYOUT_VER_OFFSET, | |
52 | (uchar *)&eeprom_layout, 1); | |
53 | if (res) { | |
54 | eeprom_layout = LAYOUT_INVALID; | |
55 | return res; | |
56 | } | |
57 | ||
58 | if (eeprom_layout == 0 || eeprom_layout >= 0x20) | |
59 | eeprom_layout = LAYOUT_LEGACY; | |
60 | ||
61 | return 0; | |
62 | } | |
63 | ||
64 | void get_board_serial(struct tag_serialnr *serialnr) | |
65 | { | |
66 | u32 serial[2]; | |
67 | uint offset; | |
68 | ||
69 | memset(serialnr, 0, sizeof(*serialnr)); | |
70 | if (eeprom_setup_layout()) | |
71 | return; | |
72 | ||
73 | offset = (eeprom_layout != LAYOUT_LEGACY) ? | |
74 | BOARD_SERIAL_OFFSET : BOARD_SERIAL_OFFSET_LEGACY; | |
75 | if (cm_t3x_eeprom_read(offset, (uchar *)serial, 8)) | |
76 | return; | |
77 | ||
78 | if (serial[0] != 0xffffffff && serial[1] != 0xffffffff) { | |
79 | serialnr->low = serial[0]; | |
80 | serialnr->high = serial[1]; | |
81 | } | |
82 | } | |
7d3c97d7 NK |
83 | |
84 | /* | |
85 | * Routine: get_board_rev | |
86 | * Description: read system revision | |
87 | */ | |
88 | u32 get_board_rev(void) | |
89 | { | |
90 | u32 rev = 0; | |
91 | uint offset = BOARD_REV_OFFSET_LEGACY; | |
92 | int len = BOARD_REV_SIZE_LEGACY; | |
93 | ||
94 | if (eeprom_setup_layout()) | |
95 | return 0; | |
96 | ||
97 | if (eeprom_layout != LAYOUT_LEGACY) { | |
98 | offset = BOARD_REV_OFFSET; | |
99 | len = BOARD_REV_SIZE; | |
100 | } | |
101 | ||
102 | if (cm_t3x_eeprom_read(offset, (uchar *)&rev, len)) | |
103 | return 0; | |
104 | ||
105 | return rev; | |
106 | }; |