#include <common.h>
#include <eeprom.h>
+#include <linux/delay.h>
#include <linux/err.h>
#include <linux/kernel.h>
#include <dm.h>
u32 pagesize; /* page size in bytes */
u32 addr_offset_mask; /* bits in addr used for offset overflow */
u32 offset_len; /* size in bytes of offset */
+ u32 start_offset; /* valid start offset inside memory, by default 0 */
};
int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf, int size)
.size = i2c_eeprom_std_size,
};
-static int i2c_eeprom_std_ofdata_to_platdata(struct udevice *dev)
+static int i2c_eeprom_std_of_to_plat(struct udevice *dev)
{
struct i2c_eeprom *priv = dev_get_priv(dev);
struct i2c_eeprom_drv_data *data =
if (!name)
continue;
- device_bind_ofnode(dev, DM_GET_DRIVER(i2c_eeprom_partition),
- name, NULL, partition, NULL);
+ device_bind(dev, DM_DRIVER_GET(i2c_eeprom_partition), name,
+ NULL, partition, NULL);
}
return 0;
i2c_set_chip_addr_offset_mask(dev, data->addr_offset_mask);
/* Verify that the chip is functional */
- ret = i2c_eeprom_read(dev, 0, &test_byte, 1);
+ /*
+ * Not all eeproms start from offset 0. Valid offset is available
+ * in the platform data struct.
+ */
+ ret = i2c_eeprom_read(dev, data->start_offset, &test_byte, 1);
if (ret)
return -ENODEV;
.pagesize = 16,
.addr_offset_mask = 0,
.offset_len = 1,
+ .start_offset = 0x80,
};
static const struct i2c_eeprom_drv_data atmel24c32_data = {
.of_match = i2c_eeprom_std_ids,
.bind = i2c_eeprom_std_bind,
.probe = i2c_eeprom_std_probe,
- .ofdata_to_platdata = i2c_eeprom_std_ofdata_to_platdata,
- .priv_auto_alloc_size = sizeof(struct i2c_eeprom),
+ .of_to_plat = i2c_eeprom_std_of_to_plat,
+ .priv_auto = sizeof(struct i2c_eeprom),
.ops = &i2c_eeprom_std_ops,
};
return 0;
}
-static int i2c_eeprom_partition_ofdata_to_platdata(struct udevice *dev)
+static int i2c_eeprom_partition_of_to_plat(struct udevice *dev)
{
struct i2c_eeprom_partition *priv = dev_get_priv(dev);
- u32 offset, size;
+ u32 reg[2];
int ret;
- ret = dev_read_u32(dev, "offset", &offset);
+ ret = dev_read_u32_array(dev, "reg", reg, 2);
if (ret)
return ret;
- ret = dev_read_u32(dev, "size", &size);
- if (ret)
- return ret;
+ if (!reg[1])
+ return -EINVAL;
+
+ priv->offset = reg[0];
+ priv->size = reg[1];
- priv->offset = offset;
- priv->size = size;
+ debug("%s: base %x, size %x\n", __func__, priv->offset, priv->size);
return 0;
}
.name = "i2c_eeprom_partition",
.id = UCLASS_I2C_EEPROM,
.probe = i2c_eeprom_partition_probe,
- .ofdata_to_platdata = i2c_eeprom_partition_ofdata_to_platdata,
- .priv_auto_alloc_size = sizeof(struct i2c_eeprom_partition),
+ .of_to_plat = i2c_eeprom_partition_of_to_plat,
+ .priv_auto = sizeof(struct i2c_eeprom_partition),
.ops = &i2c_eeprom_partition_ops,
};