diff options
author | Denis Zalevskiy <denis.zalevskiy@ge.com> | 2018-10-17 10:33:30 +0200 |
---|---|---|
committer | Stefano Babic <sbabic@denx.de> | 2019-01-01 14:12:18 +0100 |
commit | 4dcbccf794a330895ee2aeba6964a94b33c60eda (patch) | |
tree | e6df99bc24071ed9cf066063a3a033dd29bd3269 /board/ge/bx50v3/bx50v3.c | |
parent | 4c552083503f49f37412972a3b4ea895cffd948e (diff) |
board: ge: Move VPD reading to the vpd_reader
Merge functionality duplicated in bx50v3 and mx53ppd: the logic
is the same except that process_vpd is called at different phases.
Also read_vpd could end up in error, so there is no VPD data in this
case - it shouldn't be processed.
Signed-off-by: Denis Zalevskiy <denis.zalevskiy@ge.com>
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Diffstat (limited to 'board/ge/bx50v3/bx50v3.c')
-rw-r--r-- | board/ge/bx50v3/bx50v3.c | 48 |
1 files changed, 11 insertions, 37 deletions
diff --git a/board/ge/bx50v3/bx50v3.c b/board/ge/bx50v3/bx50v3.c index 13cc4c1ad7..079d302fbe 100644 --- a/board/ge/bx50v3/bx50v3.c +++ b/board/ge/bx50v3/bx50v3.c @@ -33,8 +33,6 @@ #include "../../../drivers/net/e1000.h" DECLARE_GLOBAL_DATA_PTR; -struct vpd_cache; - static int confidx = 3; /* Default to b850v3. */ static struct vpd_cache vpd; @@ -560,6 +558,7 @@ int overwrite_console(void) #define VPD_MAC_ADDRESS_LENGTH 6 struct vpd_cache { + bool is_read; u8 product_id; u8 has; unsigned char mac1[VPD_MAC_ADDRESS_LENGTH]; @@ -569,11 +568,9 @@ struct vpd_cache { /* * Extracts MAC and product information from the VPD. */ -static int vpd_callback(void *userdata, u8 id, u8 version, u8 type, +static int vpd_callback(struct vpd_cache *vpd, u8 id, u8 version, u8 type, size_t size, u8 const *data) { - struct vpd_cache *vpd = (struct vpd_cache *)userdata; - if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID && size >= 1) { vpd->product_id = data[0]; @@ -597,6 +594,11 @@ static void process_vpd(struct vpd_cache *vpd) int fec_index = -1; int i210_index = -1; + if (!vpd->is_read) { + printf("VPD wasn't read"); + return; + } + switch (vpd->product_id) { case VPD_PRODUCT_B450: env_set("confidx", "1"); @@ -622,35 +624,6 @@ static void process_vpd(struct vpd_cache *vpd) eth_env_set_enetaddr_by_index("eth", i210_index, vpd->mac2); } -static int read_vpd(void) -{ - int res; - static const int size = CONFIG_SYS_VPD_EEPROM_SIZE; - uint8_t *data; - unsigned int current_i2c_bus = i2c_get_bus_num(); - - res = i2c_set_bus_num(CONFIG_SYS_VPD_EEPROM_I2C_BUS); - if (res < 0) - return res; - - data = (uint8_t *)malloc(size); - if (!data) - return -ENOMEM; - - res = i2c_read(CONFIG_SYS_VPD_EEPROM_I2C_ADDR, 0, - CONFIG_SYS_VPD_EEPROM_I2C_ADDR_LEN, data, size); - - if (res == 0) { - memset(&vpd, 0, sizeof(vpd)); - vpd_reader(size, data, &vpd, vpd_callback); - } - - free(data); - - i2c_set_bus_num(current_i2c_bus); - return res; -} - int board_eth_init(bd_t *bis) { setup_iomux_enet(); @@ -709,9 +682,10 @@ int board_init(void) setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2); setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info3); - read_vpd(); - - set_confidx(&vpd); + if (!read_vpd(&vpd, vpd_callback)) { + vpd.is_read = true; + set_confidx(&vpd); + } gpio_direction_output(SUS_S3_OUT, 1); gpio_direction_output(WIFI_EN, 1); |