1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2020 Toradex
7 #include <i2c_eeprom.h>
8 #include <asm/global_data.h>
9 #include <linux/errno.h>
11 DECLARE_GLOBAL_DATA_PTR;
13 static int get_tdx_eeprom(u32 eeprom_id, struct udevice **devp)
22 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
26 node = fdt_path_offset(gd->fdt_blob, "/aliases");
30 sprintf(eeprom_str, "eeprom%d", eeprom_id);
32 path = fdt_getprop(gd->fdt_blob, node, eeprom_str, NULL);
34 printf("%s: no alias for %s\n", __func__, eeprom_str);
38 eeprom = ofnode_path(path);
39 if (!ofnode_valid(eeprom)) {
40 printf("%s: invalid hardware path to EEPROM\n", __func__);
44 ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, devp);
46 printf("%s: cannot find EEPROM by node\n", __func__);
53 int read_tdx_eeprom_data(u32 eeprom_id, int offset, u8 *buf,
59 ret = get_tdx_eeprom(eeprom_id, &dev);
63 ret = i2c_eeprom_read(dev, 0x0, buf, size);
65 printf("%s: error reading data from EEPROM id: %d!, ret = %d\n",
66 __func__, eeprom_id, ret);
73 int write_tdx_eeprom_data(u32 eeprom_id, int offset, u8 *buf,
79 ret = get_tdx_eeprom(eeprom_id, &dev);
83 ret = i2c_eeprom_write(dev, 0x0, buf, size);
85 printf("%s: error writing data to EEPROM id: %d, ret = %d\n",
86 __func__, eeprom_id, ret);