]> git.sur5r.net Git - u-boot/blobdiff - drivers/i2c/mvtwsi.c
Merge branch 'master' of git://git.denx.de/u-boot-uniphier
[u-boot] / drivers / i2c / mvtwsi.c
index 648a96eeb4e88cd0ab9b753b31c8d85b9b33d4e5..74ac0a4aa78976487f8314ec7c531a7f781d9299 100644 (file)
@@ -1,17 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Driver for the TWSI (i2c) controller found on the Marvell
  * orion5x and kirkwood SoC families.
  *
  * Author: Albert Aribaud <albert.u.boot@aribaud.net>
  * Copyright (c) 2010 Albert Aribaud.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <i2c.h>
 #include <linux/errno.h>
 #include <asm/io.h>
+#include <linux/bitops.h>
 #include <linux/compat.h>
 #ifdef CONFIG_DM_I2C
 #include <dm.h>
@@ -36,6 +36,14 @@ DECLARE_GLOBAL_DATA_PTR;
 #endif
 #endif /* CONFIG_DM_I2C */
 
+/*
+ * On SUNXI, we get CONFIG_SYS_TCLK from this include, so we want to
+ * always have it.
+ */
+#if defined(CONFIG_DM_I2C) && defined(CONFIG_ARCH_SUNXI)
+#include <asm/arch/i2c.h>
+#endif
+
 /*
  * TWSI register structure
  */
@@ -50,6 +58,7 @@ struct  mvtwsi_registers {
        u32 status;
        u32 baudrate;
        u32 soft_reset;
+       u32 debug; /* Dummy field for build compatibility with mvebu */
 };
 
 #else
@@ -63,8 +72,10 @@ struct  mvtwsi_registers {
                u32 baudrate;   /* When writing */
        };
        u32 xtnd_slave_addr;
-       u32 reserved[2];
+       u32 reserved0[2];
        u32 soft_reset;
+       u32 reserved1[27];
+       u32 debug;
 };
 
 #endif
@@ -479,10 +490,14 @@ static uint __twsi_i2c_set_bus_speed(struct mvtwsi_registers *twsi,
 static void __twsi_i2c_init(struct mvtwsi_registers *twsi, int speed,
                            int slaveadd, uint *actual_speed)
 {
+       uint tmp_speed;
+
        /* Reset controller */
        twsi_reset(twsi);
        /* Set speed */
-       *actual_speed = __twsi_i2c_set_bus_speed(twsi, speed);
+       tmp_speed = __twsi_i2c_set_bus_speed(twsi, speed);
+       if (actual_speed)
+               *actual_speed = tmp_speed;
        /* Set slave address; even though we don't use it */
        writel(slaveadd, &twsi->slave_address);
        writel(0, &twsi->xtnd_slave_addr);
@@ -770,7 +785,7 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)
 {
        struct mvtwsi_i2c_dev *dev = dev_get_priv(bus);
 
-       dev->base = dev_get_addr_ptr(bus);
+       dev->base = devfdt_get_addr_ptr(bus);
 
        if (!dev->base)
                return -ENOMEM;
@@ -784,6 +799,23 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)
        return 0;
 }
 
+static void twsi_disable_i2c_slave(struct mvtwsi_registers *twsi)
+{
+       clrbits_le32(&twsi->debug, BIT(18));
+}
+
+static int mvtwsi_i2c_bind(struct udevice *bus)
+{
+       struct mvtwsi_registers *twsi = devfdt_get_addr_ptr(bus);
+
+       /* Disable the hidden slave in i2c0 of these platforms */
+       if ((IS_ENABLED(CONFIG_ARMADA_38X) || IS_ENABLED(CONFIG_KIRKWOOD))
+                       && bus->req_seq == 0)
+               twsi_disable_i2c_slave(twsi);
+
+       return 0;
+}
+
 static int mvtwsi_i2c_probe(struct udevice *bus)
 {
        struct mvtwsi_i2c_dev *dev = dev_get_priv(bus);
@@ -831,6 +863,7 @@ static const struct dm_i2c_ops mvtwsi_i2c_ops = {
 static const struct udevice_id mvtwsi_i2c_ids[] = {
        { .compatible = "marvell,mv64xxx-i2c", },
        { .compatible = "marvell,mv78230-i2c", },
+       { .compatible = "allwinner,sun6i-a31-i2c", },
        { /* sentinel */ }
 };
 
@@ -838,6 +871,7 @@ U_BOOT_DRIVER(i2c_mvtwsi) = {
        .name = "i2c_mvtwsi",
        .id = UCLASS_I2C,
        .of_match = mvtwsi_i2c_ids,
+       .bind = mvtwsi_i2c_bind,
        .probe = mvtwsi_i2c_probe,
        .ofdata_to_platdata = mvtwsi_i2c_ofdata_to_platdata,
        .priv_auto_alloc_size = sizeof(struct mvtwsi_i2c_dev),