]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
compulab: eeprom: allow reading mac address from multiple eeproms
authorNikita Kiryanov <nikita@compulab.co.il>
Wed, 14 Jan 2015 08:42:43 +0000 (10:42 +0200)
committerStefano Babic <sbabic@denx.de>
Thu, 29 Jan 2015 16:42:28 +0000 (17:42 +0100)
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>
board/compulab/cm_fx6/cm_fx6.c
board/compulab/cm_t335/cm_t335.c
board/compulab/cm_t35/cm_t35.c
board/compulab/cm_t3517/cm_t3517.c
board/compulab/cm_t54/cm_t54.c
board/compulab/common/eeprom.c
board/compulab/common/eeprom.h

index 5ddf8c6688096ab8c3e7e43e42f12db50ea4f106..32f4434b6582ebe01dfaadecf803714f05cafa39 100644 (file)
@@ -354,7 +354,7 @@ static int handle_mac_address(void)
        if (rc)
                return 0;
 
-       rc = cl_eeprom_read_mac_addr(enetaddr);
+       rc = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
        if (rc)
                return rc;
 
index 9583149bed61bd315dcea3c6abdfa1b1c9226a49..592ef3d30fcd01f4bc0c3241b418095e2d1fc2ea 100644 (file)
@@ -110,7 +110,7 @@ static int handle_mac_address(void)
        if (rv)
                return 0;
 
-       rv = cl_eeprom_read_mac_addr(enetaddr);
+       rv = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
        if (rv)
                get_efuse_mac_addr(enetaddr);
 
index 43463d5b4701cf0220049e3f82e34f47d40e608e..9a3b2ee72fed905b567d46928bdf6fbda1af8b7f 100644 (file)
@@ -429,7 +429,7 @@ static int handle_mac_address(void)
        if (rc)
                return 0;
 
-       rc = cl_eeprom_read_mac_addr(enetaddr);
+       rc = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
        if (rc)
                return rc;
 
index cac1ad9ef11d1ca5be5c100c6677a4795bac0b5e..624cf4c03463f472b2a3b164cec1c92c0f20c63c 100644 (file)
@@ -163,7 +163,7 @@ static int cm_t3517_handle_mac_address(void)
        if (ret)
                return 0;
 
-       ret = cl_eeprom_read_mac_addr(enetaddr);
+       ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
        if (ret) {
                ret = am3517_get_efuse_enetaddr(enetaddr);
                if (ret)
index 2c2530ab3fd1e6ce5c3e200276bebaac51daea43..fdea909ff74a0109ac42282c11a1130e468033d8 100644 (file)
@@ -165,7 +165,7 @@ static int handle_mac_address(void)
        if (ret)
                return 0;
 
-       ret = cl_eeprom_read_mac_addr(enetaddr);
+       ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
        if (ret || !is_valid_ether_addr(enetaddr))
                generate_mac_addr(enetaddr);
 
index a45e7be11f76a0ba2f3548bef62f41198c641974..77bcea44b41cf5a5c653f1ffa2621c37ed5ea1ec 100644 (file)
@@ -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)
index 85d5bf03d69171c81f57dcaee0e05f7af509399d..50c6b0226fc0ee2a39102f40e92e7288c823ca87 100644 (file)
 #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;
 }