]> Git Repo - u-boot.git/blobdiff - drivers/misc/i2c_eeprom.c
dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET()
[u-boot.git] / drivers / misc / i2c_eeprom.c
index ef5f103c98ef3947f795b61ece35b2dd70bd5b7e..5926c91a2ec9c777e053ee76a0aff25aed233b59 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <eeprom.h>
+#include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
 #include <dm.h>
@@ -17,6 +18,7 @@ struct i2c_eeprom_drv_data {
        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)
@@ -91,7 +93,7 @@ static const struct i2c_eeprom_ops i2c_eeprom_std_ops = {
        .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 =
@@ -129,8 +131,8 @@ static int i2c_eeprom_std_bind(struct udevice *dev)
                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;
@@ -147,7 +149,11 @@ static int i2c_eeprom_std_probe(struct udevice *dev)
        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;
 
@@ -215,6 +221,7 @@ static const struct i2c_eeprom_drv_data atmel24mac402_data = {
        .pagesize = 16,
        .addr_offset_mask = 0,
        .offset_len = 1,
+       .start_offset = 0x80,
 };
 
 static const struct i2c_eeprom_drv_data atmel24c32_data = {
@@ -276,8 +283,8 @@ U_BOOT_DRIVER(i2c_eeprom_std) = {
        .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,
 };
 
@@ -291,22 +298,23 @@ static int i2c_eeprom_partition_probe(struct udevice *dev)
        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;
 }
@@ -357,8 +365,8 @@ U_BOOT_DRIVER(i2c_eeprom_partition) = {
        .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,
 };
 
This page took 0.029359 seconds and 4 git commands to generate.