+// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2016 General Electric Company
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
#include "vpd_reader.h"
+#include <malloc.h>
+#include <i2c.h>
#include <linux/bch.h>
#include <stdlib.h>
+#include <dm/uclass.h>
+#include <i2c_eeprom.h>
+#include <hexdump.h>
/* BCH configuration */
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,
+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 ret;
}
}
+
+int read_i2c_vpd(struct vpd_cache *cache,
+ int (*process_block)(struct vpd_cache *, u8 id, u8 version,
+ u8 type, size_t size, u8 const *data))
+{
+ struct udevice *dev;
+ int ret;
+ u8 *data;
+ int size;
+
+ ret = uclass_get_device_by_name(UCLASS_I2C_EEPROM, "vpd@0", &dev);
+ if (ret)
+ return ret;
+
+ size = i2c_eeprom_size(dev);
+ if (size < 0) {
+ printf("Unable to get size of eeprom: %d\n", ret);
+ return ret;
+ }
+
+ data = malloc(size);
+ if (!data)
+ return -ENOMEM;
+
+ ret = i2c_eeprom_read(dev, 0, data, size);
+ if (ret) {
+ free(data);
+ return ret;
+ }
+
+ ret = vpd_reader(size, data, cache, process_block);
+
+ free(data);
+
+ return ret;
+}