Commit 8230925049c164908f3936428e73e240830752f5
Committed by
Albert ARIBAUD
1 parent
ce15ec9f69
Exists in
master
and in
54 other branches
cm-t35: add EEPROM module and pass Linux a serial number
Add board specific EEPROM handling module, read the serial number from the EEPROM and pass it to Linux. Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il> Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>
Showing 4 changed files with 95 additions and 1 deletions Side-by-side Diff
board/cm_t35/Makefile
board/cm_t35/cm_t35.c
... | ... | @@ -33,6 +33,7 @@ |
33 | 33 | #include <net.h> |
34 | 34 | #include <i2c.h> |
35 | 35 | #include <twl4030.h> |
36 | +#include <linux/compiler.h> | |
36 | 37 | |
37 | 38 | #include <asm/io.h> |
38 | 39 | #include <asm/arch/mem.h> |
... | ... | @@ -421,4 +422,14 @@ |
421 | 422 | return rc; |
422 | 423 | } |
423 | 424 | #endif |
425 | + | |
426 | +void __weak get_board_serial(struct tag_serialnr *serialnr) | |
427 | +{ | |
428 | + /* | |
429 | + * This corresponds to what happens when we can communicate with the | |
430 | + * eeprom but don't get a valid board serial value. | |
431 | + */ | |
432 | + serialnr->low = 0; | |
433 | + serialnr->high = 0; | |
434 | +}; |
board/cm_t35/eeprom.c
1 | +/* | |
2 | + * (C) Copyright 2011 CompuLab, Ltd. <www.compulab.co.il> | |
3 | + * | |
4 | + * Authors: Nikita Kiryanov <nikita@compulab.co.il> | |
5 | + * Igor Grinberg <grinberg@compulab.co.il> | |
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 | |
28 | + | |
29 | +#define LAYOUT_INVALID 0 | |
30 | +#define LAYOUT_LEGACY 0xff | |
31 | + | |
32 | +static int eeprom_layout; /* Implicitly LAYOUT_INVALID */ | |
33 | + | |
34 | +static int cm_t3x_eeprom_read(uint offset, uchar *buf, int len) | |
35 | +{ | |
36 | + return i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, offset, | |
37 | + CONFIG_SYS_I2C_EEPROM_ADDR_LEN, buf, len); | |
38 | +} | |
39 | + | |
40 | +static int eeprom_setup_layout(void) | |
41 | +{ | |
42 | + int res; | |
43 | + | |
44 | + if (eeprom_layout != LAYOUT_INVALID) | |
45 | + return 0; | |
46 | + | |
47 | + res = cm_t3x_eeprom_read(EEPROM_LAYOUT_VER_OFFSET, | |
48 | + (uchar *)&eeprom_layout, 1); | |
49 | + if (res) { | |
50 | + eeprom_layout = LAYOUT_INVALID; | |
51 | + return res; | |
52 | + } | |
53 | + | |
54 | + if (eeprom_layout == 0 || eeprom_layout >= 0x20) | |
55 | + eeprom_layout = LAYOUT_LEGACY; | |
56 | + | |
57 | + return 0; | |
58 | +} | |
59 | + | |
60 | +void get_board_serial(struct tag_serialnr *serialnr) | |
61 | +{ | |
62 | + u32 serial[2]; | |
63 | + uint offset; | |
64 | + | |
65 | + memset(serialnr, 0, sizeof(*serialnr)); | |
66 | + if (eeprom_setup_layout()) | |
67 | + return; | |
68 | + | |
69 | + offset = (eeprom_layout != LAYOUT_LEGACY) ? | |
70 | + BOARD_SERIAL_OFFSET : BOARD_SERIAL_OFFSET_LEGACY; | |
71 | + if (cm_t3x_eeprom_read(offset, (uchar *)serial, 8)) | |
72 | + return; | |
73 | + | |
74 | + if (serial[0] != 0xffffffff && serial[1] != 0xffffffff) { | |
75 | + serialnr->low = serial[0]; | |
76 | + serialnr->high = serial[1]; | |
77 | + } | |
78 | +} |
include/configs/cm_t35.h
... | ... | @@ -72,6 +72,7 @@ |
72 | 72 | #define CONFIG_SETUP_MEMORY_TAGS |
73 | 73 | #define CONFIG_INITRD_TAG |
74 | 74 | #define CONFIG_REVISION_TAG |
75 | +#define CONFIG_SERIAL_TAG | |
75 | 76 | |
76 | 77 | /* |
77 | 78 | * Size of malloc() pool |
... | ... | @@ -153,6 +154,8 @@ |
153 | 154 | #define CONFIG_SYS_I2C_BUS 0 |
154 | 155 | #define CONFIG_SYS_I2C_BUS_SELECT 1 |
155 | 156 | #define CONFIG_DRIVER_OMAP34XX_I2C |
157 | +#define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 | |
158 | +#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1 | |
156 | 159 | |
157 | 160 | /* |
158 | 161 | * TWL4030 |