Merge branch 'master' of git://git.denx.de/u-boot
[platform/kernel/u-boot.git] / drivers / i2c / mv_i2c.c
index dcbe1ae..e65cce0 100644 (file)
  * (C) Copyright 2011 Marvell Inc.
  * Lei Wen <leiwen@marvell.com>
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  *
  * Back ported to the 8xx platform (from the 8260 platform) by
  * Murray.Jensen@cmst.csiro.au, 27-Jan-01.
@@ -47,7 +31,7 @@
 #endif
 
 /* All transfers are described by this data structure */
-struct i2c_msg {
+struct mv_i2c_msg {
        u8 condition;
        u8 acknack;
        u8 direction;
@@ -67,6 +51,27 @@ struct mv_i2c {
 };
 
 static struct mv_i2c *base;
+static void i2c_board_init(struct mv_i2c *base)
+{
+#ifdef CONFIG_SYS_I2C_INIT_BOARD
+       u32 icr;
+       /*
+        * call board specific i2c bus reset routine before accessing the
+        * environment, which might be in a chip on that bus. For details
+        * about this problem see doc/I2C_Edge_Conditions.
+        *
+        * disable I2C controller first, otherwhise it thinks we want to
+        * talk to the slave port...
+        */
+       icr = readl(&base->icr);
+       writel(readl(&base->icr) & ~(ICR_SCLE | ICR_IUE), &base->icr);
+
+       i2c_init_board();
+
+       writel(icr, &base->icr);
+#endif
+}
+
 #ifdef CONFIG_I2C_MULTI_BUS
 static u32 i2c_regs[CONFIG_MV_I2C_NUM] = CONFIG_MV_I2C_REG;
 static unsigned int bus_initialized[CONFIG_MV_I2C_NUM];
@@ -83,7 +88,7 @@ int i2c_set_bus_num(unsigned int bus)
        current_bus = bus;
 
        if (!bus_initialized[current_bus]) {
-               i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+               i2c_board_init(base);
                bus_initialized[current_bus] = 1;
        }
 
@@ -152,7 +157,7 @@ static int i2c_isr_set_cleared(unsigned long set_mask,
  *          -5: illegal parameters
  *          -6: bus is busy and couldn't be aquired
  */
-int i2c_transfer(struct i2c_msg *msg)
+int i2c_transfer(struct mv_i2c_msg *msg)
 {
        int ret;
 
@@ -253,7 +258,7 @@ transfer_error_bus_busy:
                ret = -6; goto i2c_transfer_finish;
 
 i2c_transfer_finish:
-               PRINTD(("i2c_transfer: ISR: 0x%04x\n", ISR));
+               PRINTD(("i2c_transfer: ISR: 0x%04x\n", readl(&base->isr)));
                i2c_reset();
                return ret;
 }
@@ -264,28 +269,13 @@ i2c_transfer_finish:
 void i2c_init(int speed, int slaveaddr)
 {
 #ifdef CONFIG_I2C_MULTI_BUS
+       current_bus = 0;
        base = (struct mv_i2c *)i2c_regs[current_bus];
 #else
        base = (struct mv_i2c *)CONFIG_MV_I2C_REG;
 #endif
 
-#ifdef CONFIG_SYS_I2C_INIT_BOARD
-       u32 icr;
-       /*
-        * call board specific i2c bus reset routine before accessing the
-        * environment, which might be in a chip on that bus. For details
-        * about this problem see doc/I2C_Edge_Conditions.
-        *
-        * disable I2C controller first, otherwhise it thinks we want to
-        * talk to the slave port...
-        */
-       icr = readl(&base->icr);
-       writel(readl(&base->icr) & ~(ICR_SCLE | ICR_IUE), &base->icr);
-
-       i2c_init_board();
-
-       writel(icr, &base->icr);
-#endif
+       i2c_board_init(base);
 }
 
 /*
@@ -296,7 +286,7 @@ void i2c_init(int speed, int slaveaddr)
  */
 int i2c_probe(uchar chip)
 {
-       struct i2c_msg msg;
+       struct mv_i2c_msg msg;
 
        i2c_reset();
 
@@ -332,7 +322,7 @@ int i2c_probe(uchar chip)
  */
 int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
 {
-       struct i2c_msg msg;
+       struct mv_i2c_msg msg;
        u8 addr_bytes[3]; /* lowest...highest byte of data address */
 
        PRINTD(("i2c_read(chip=0x%02x, addr=0x%02x, alen=0x%02x, "
@@ -420,7 +410,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
  */
 int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
 {
-       struct i2c_msg msg;
+       struct mv_i2c_msg msg;
        u8 addr_bytes[3]; /* lowest...highest byte of data address */
 
        PRINTD(("i2c_write(chip=0x%02x, addr=0x%02x, alen=0x%02x, "