summaryrefslogtreecommitdiff
path: root/board/compulab/common
diff options
context:
space:
mode:
authorNikita Kiryanov <nikita@compulab.co.il>2015-01-14 10:42:43 +0200
committerStefano Babic <sbabic@denx.de>2015-01-29 17:42:28 +0100
commite7a2447ba2d8483b7d029e77c59b0ee26eeabe88 (patch)
tree77691bf8d48ef3fe74a395523104a52c7f39e5a7 /board/compulab/common
parentcc67f4a63ff3c6ed0b8fab35ce4af6e683296e47 (diff)
downloadu-boot-imx-e7a2447ba2d8483b7d029e77c59b0ee26eeabe88.zip
u-boot-imx-e7a2447ba2d8483b7d029e77c59b0ee26eeabe88.tar.gz
u-boot-imx-e7a2447ba2d8483b7d029e77c59b0ee26eeabe88.tar.bz2
compulab: eeprom: allow reading mac address from multiple eeproms
Implement the option to select the eeprom i2c bus when reading mac address. Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il> Cc: Stefano Babic <sbabic@denx.de> Cc: Igor Grinberg <grinberg@compulab.co.il> Cc: Ilya Ledvich <ilya@compulab.co.il> Cc: Dmitry Lifshitz <lifshitz@compulab.co.il> Acked-by: Igor Grinberg <grinberg@compulab.co.il>
Diffstat (limited to 'board/compulab/common')
-rw-r--r--board/compulab/common/eeprom.c20
-rw-r--r--board/compulab/common/eeprom.h4
2 files changed, 15 insertions, 9 deletions
diff --git a/board/compulab/common/eeprom.c b/board/compulab/common/eeprom.c
index a45e7be..77bcea4 100644
--- a/board/compulab/common/eeprom.c
+++ b/board/compulab/common/eeprom.c
@@ -31,6 +31,7 @@
#define LAYOUT_INVALID 0
#define LAYOUT_LEGACY 0xff
+static int cl_eeprom_bus;
static int cl_eeprom_layout; /* Implicitly LAYOUT_INVALID */
static int cl_eeprom_read(uint offset, uchar *buf, int len)
@@ -38,7 +39,7 @@ static int cl_eeprom_read(uint offset, uchar *buf, int len)
int res;
unsigned int current_i2c_bus = i2c_get_bus_num();
- res = i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
+ res = i2c_set_bus_num(cl_eeprom_bus);
if (res < 0)
return res;
@@ -50,13 +51,18 @@ static int cl_eeprom_read(uint offset, uchar *buf, int len)
return res;
}
-static int cl_eeprom_setup_layout(void)
+static int cl_eeprom_setup(uint eeprom_bus)
{
int res;
- if (cl_eeprom_layout != LAYOUT_INVALID)
+ /*
+ * We know the setup was already done when the layout is set to a valid
+ * value and we're using the same bus as before.
+ */
+ if (cl_eeprom_layout != LAYOUT_INVALID && eeprom_bus == cl_eeprom_bus)
return 0;
+ cl_eeprom_bus = eeprom_bus;
res = cl_eeprom_read(EEPROM_LAYOUT_VER_OFFSET,
(uchar *)&cl_eeprom_layout, 1);
if (res) {
@@ -77,7 +83,7 @@ void get_board_serial(struct tag_serialnr *serialnr)
memset(serialnr, 0, sizeof(*serialnr));
- if (cl_eeprom_setup_layout())
+ if (cl_eeprom_setup(CONFIG_SYS_I2C_EEPROM_BUS))
return;
offset = (cl_eeprom_layout != LAYOUT_LEGACY) ?
@@ -96,11 +102,11 @@ void get_board_serial(struct tag_serialnr *serialnr)
* Routine: cl_eeprom_read_mac_addr
* Description: read mac address and store it in buf.
*/
-int cl_eeprom_read_mac_addr(uchar *buf)
+int cl_eeprom_read_mac_addr(uchar *buf, uint eeprom_bus)
{
uint offset;
- if (cl_eeprom_setup_layout())
+ if (cl_eeprom_setup(eeprom_bus))
return 0;
offset = (cl_eeprom_layout != LAYOUT_LEGACY) ?
@@ -123,7 +129,7 @@ u32 cl_eeprom_get_board_rev(void)
if (board_rev)
return board_rev;
- if (cl_eeprom_setup_layout())
+ if (cl_eeprom_setup(CONFIG_SYS_I2C_EEPROM_BUS))
return 0;
if (cl_eeprom_layout != LAYOUT_LEGACY)
diff --git a/board/compulab/common/eeprom.h b/board/compulab/common/eeprom.h
index 85d5bf0..50c6b02 100644
--- a/board/compulab/common/eeprom.h
+++ b/board/compulab/common/eeprom.h
@@ -11,10 +11,10 @@
#define _EEPROM_
#ifdef CONFIG_SYS_I2C
-int cl_eeprom_read_mac_addr(uchar *buf);
+int cl_eeprom_read_mac_addr(uchar *buf, uint eeprom_bus);
u32 cl_eeprom_get_board_rev(void);
#else
-static inline int cl_eeprom_read_mac_addr(uchar *buf)
+static inline int cl_eeprom_read_mac_addr(uchar *buf, uint eeprom_bus)
{
return 1;
}