Merge git://git.denx.de/u-boot-mpc85xx
[platform/kernel/u-boot.git] / drivers / i2c / fti2c010.c
index eccc1da..4da959f 100644 (file)
@@ -5,6 +5,9 @@
  * Dante Su <dantesu@faraday-tech.com>
  *
  * SPDX-License-Identifier:    GPL-2.0+
+ *
+ * NOTE: This driver should be converted to driver model before June 2017.
+ * Please see doc/driver-model/i2c-howto.txt for instructions.
  */
 
 #include <common.h>
@@ -143,15 +146,6 @@ static void fti2c010_init(struct i2c_adapter *adap, int speed, int slaveaddr)
        set_i2c_bus_speed(chip, speed);
 
        /* slave init, don't care */
-
-#ifdef CONFIG_SYS_I2C_BOARD_LATE_INIT
-       /* Call board specific i2c bus reset routine AFTER the bus has been
-        * initialized. Use either this callpoint or i2c_init_board;
-        * which is called before fti2c010_init operations.
-        * For details about this problem see doc/I2C_Edge_Conditions.
-       */
-       i2c_board_late_init();
-#endif
 }
 
 /*
@@ -179,18 +173,31 @@ static int fti2c010_probe(struct i2c_adapter *adap, u8 dev)
        return ret;
 }
 
+static void to_i2c_addr(u8 *buf, uint32_t addr, int alen)
+{
+       int i, shift;
+
+       if (!buf || alen <= 0)
+               return;
+
+       /* MSB first */
+       i = 0;
+       shift = (alen - 1) * 8;
+       while (alen-- > 0) {
+               buf[i] = (u8)(addr >> shift);
+               shift -= 8;
+       }
+}
+
 static int fti2c010_read(struct i2c_adapter *adap,
                        u8 dev, uint addr, int alen, uchar *buf, int len)
 {
        struct fti2c010_chip *chip = chip_list + adap->hwadapnr;
        struct fti2c010_regs *regs = chip->regs;
        int ret, pos;
-       uchar paddr[4];
+       uchar paddr[4] = { 0 };
 
-       paddr[0] = (addr >> 0)  & 0xFF;
-       paddr[1] = (addr >> 8)  & 0xFF;
-       paddr[2] = (addr >> 16) & 0xFF;
-       paddr[3] = (addr >> 24) & 0xFF;
+       to_i2c_addr(paddr, addr, alen);
 
        /*
         * Phase A. Set register address
@@ -250,12 +257,9 @@ static int fti2c010_write(struct i2c_adapter *adap,
        struct fti2c010_chip *chip = chip_list + adap->hwadapnr;
        struct fti2c010_regs *regs = chip->regs;
        int ret, pos;
-       uchar paddr[4];
+       uchar paddr[4] = { 0 };
 
-       paddr[0] = (addr >> 0)  & 0xFF;
-       paddr[1] = (addr >> 8)  & 0xFF;
-       paddr[2] = (addr >> 16) & 0xFF;
-       paddr[3] = (addr >> 24) & 0xFF;
+       to_i2c_addr(paddr, addr, alen);
 
        /*
         * Phase A. Set register address