Merge git://git.denx.de/u-boot-mpc85xx
[platform/kernel/u-boot.git] / drivers / i2c / mv_i2c.c
index 291b2d7..913721b 100644 (file)
@@ -243,6 +243,11 @@ static int __i2c_read(struct mv_i2c *base, uchar chip, u8 *addr, int alen,
        debug("i2c_read(chip=0x%02x, addr=0x%02x, alen=0x%02x, "
              "len=0x%02x)\n", chip, *addr, alen, len);
 
+       if (len == 0) {
+               printf("reading zero byte is invalid\n");
+               return -EINVAL;
+       }
+
        i2c_reset(base);
 
        /* dummy chip address write */
@@ -265,7 +270,7 @@ static int __i2c_read(struct mv_i2c *base, uchar chip, u8 *addr, int alen,
                msg.condition = I2C_COND_NORMAL;
                msg.acknack   = I2C_ACKNAK_WAITACK;
                msg.direction = I2C_WRITE;
-               msg.data      = *(addr++);
+               msg.data      = addr[alen];
                if (i2c_transfer(base, &msg))
                        return -1;
        }
@@ -336,7 +341,7 @@ static int __i2c_write(struct mv_i2c *base, uchar chip, u8 *addr, int alen,
                msg.condition = I2C_COND_NORMAL;
                msg.acknack   = I2C_ACKNAK_WAITACK;
                msg.direction = I2C_WRITE;
-               msg.data      = *(addr++);
+               msg.data      = addr[alen];
                if (i2c_transfer(base, &msg))
                        return -1;
        }
@@ -574,7 +579,7 @@ static int mv_i2c_probe(struct udevice *bus)
 {
        struct mv_i2c_priv *priv = dev_get_priv(bus);
 
-       priv->base = (void *)dev_get_addr_ptr(bus);
+       priv->base = (void *)devfdt_get_addr_ptr(bus);
 
        return 0;
 }