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/common | |
parent | 4c552083503f49f37412972a3b4ea895cffd948e (diff) | |
download | u-boot-4dcbccf794a330895ee2aeba6964a94b33c60eda.tar.gz u-boot-4dcbccf794a330895ee2aeba6964a94b33c60eda.tar.xz u-boot-4dcbccf794a330895ee2aeba6964a94b33c60eda.zip |
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/common')
-rw-r--r-- | board/ge/common/vpd_reader.c | 37 | ||||
-rw-r--r-- | board/ge/common/vpd_reader.h | 16 |
2 files changed, 45 insertions, 8 deletions
diff --git a/board/ge/common/vpd_reader.c b/board/ge/common/vpd_reader.c index c471583be8..12410d9b71 100644 --- a/board/ge/common/vpd_reader.c +++ b/board/ge/common/vpd_reader.c @@ -5,6 +5,7 @@ #include "vpd_reader.h" +#include <i2c.h> #include <linux/bch.h> #include <stdlib.h> @@ -105,9 +106,9 @@ static const size_t HEADER_BLOCK_ECC_LEN = 4; static const u8 ECC_BLOCK_ID = 0xFF; -int vpd_reader(size_t size, u8 *data, void *userdata, - int (*fn)(void *userdata, u8 id, u8 version, u8 type, - size_t size, u8 const *data)) +static int vpd_reader(size_t size, u8 *data, struct vpd_cache *userdata, + int (*fn)(struct vpd_cache *, u8 id, u8 version, u8 type, + size_t size, u8 const *data)) { if (size < HEADER_BLOCK_LEN || !data || !fn) return -EINVAL; @@ -194,3 +195,33 @@ int vpd_reader(size_t size, u8 *data, void *userdata, return ret; } } + +int read_vpd(struct vpd_cache *cache, + int (*process_block)(struct vpd_cache *, u8 id, u8 version, + u8 type, size_t size, u8 const *data)) +{ + static const size_t size = CONFIG_SYS_VPD_EEPROM_SIZE; + + int res; + u8 *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 = 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) + res = vpd_reader(size, data, cache, process_block); + + free(data); + + i2c_set_bus_num(current_i2c_bus); + return res; +} diff --git a/board/ge/common/vpd_reader.h b/board/ge/common/vpd_reader.h index e60acf3d07..3045b7e21e 100644 --- a/board/ge/common/vpd_reader.h +++ b/board/ge/common/vpd_reader.h @@ -5,12 +5,18 @@ #include "common.h" +struct vpd_cache; + /* - * Read VPD from given data, verify content, and call callback - * for each vital product data block. + * Read VPD from given data, verify content, call callback for each vital + * product data block. + * + * cache: structure used by process block to store VPD information + * process_block: callback called for each VPD data block * * Returns Non-zero on error. Negative numbers encode errno. */ -int vpd_reader(size_t size, u8 *data, void *userdata, - int (*fn)(void *userdata, u8 id, u8 version, u8 type, - size_t size, u8 const *data)); +int read_vpd(struct vpd_cache *cache, + int (*process_block)(struct vpd_cache *, + u8 id, u8 version, u8 type, + size_t size, u8 const *data)); |