summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Tomsich <philipp.tomsich@theobroma-systems.com>2017-02-21 19:46:39 +0100
committerPhilipp Tomsich <philipp.tomsich@theobroma-systems.com>2017-03-09 01:40:20 +0100
commit18014e0243f327158aec28e1f31adecce54b189c (patch)
treec3be23acab14ad40bb92334e5620fec8eeff4741
parent62b8c218905dca1ce530de4d4a91edfaf46c1eb7 (diff)
i2c: sunxi: add device-model support for i2c
The I2C block in sunxi (Allwinner SoCs) is based on Designware and uses the same driver as the Marvell Orion 5x and Kirkwood families. This change adds a compatible id matching the binding for sunxi devices, supports configuring the clocks and to release the module reset on sunxi platforms as directed by the device tree. As we enable DT control of this driver, we need to make sure the common config header (sunxi-common.h) does try to turn on support for the legacy I2C support. Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
-rw-r--r--drivers/i2c/mvtwsi.c42
-rw-r--r--include/configs/sunxi-common.h9
2 files changed, 48 insertions, 3 deletions
diff --git a/drivers/i2c/mvtwsi.c b/drivers/i2c/mvtwsi.c
index 648a96eeb4..475131b65e 100644
--- a/drivers/i2c/mvtwsi.c
+++ b/drivers/i2c/mvtwsi.c
@@ -16,6 +16,12 @@
#ifdef CONFIG_DM_I2C
#include <dm.h>
#endif
+#if defined(CONFIG_CLK)
+#include <clk.h>
+#endif
+#if defined(CONFIG_DM_RESET)
+#include <reset.h>
+#endif
DECLARE_GLOBAL_DATA_PTR;
@@ -36,6 +42,12 @@ 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
*/
@@ -81,6 +93,14 @@ struct mvtwsi_i2c_dev {
uint speed;
/* The current length of a clock period (depending on speed) */
uint tick;
+#if defined(CONFIG_DM_RESET)
+ bool reset_valid;
+ struct reset_ctl reset;
+#endif
+#if defined(CONFIG_CLK)
+ bool clk_gate_valid;
+ struct clk clk_gate;
+#endif
};
#endif /* CONFIG_DM_I2C */
@@ -781,6 +801,14 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)
"u-boot,i2c-slave-addr", 0x0);
dev->speed = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
"clock-frequency", 100000);
+#if defined(CONFIG_DM_RESET)
+ if (reset_get_by_index(bus, 0, &dev->reset) == 0)
+ dev->reset_valid = true;
+#endif
+#if defined(CONFIG_CLK)
+ if (clk_get_by_index(bus, 0, &dev->clk_gate) == 0)
+ dev->clk_gate_valid = true;
+#endif
return 0;
}
@@ -789,6 +817,17 @@ static int mvtwsi_i2c_probe(struct udevice *bus)
struct mvtwsi_i2c_dev *dev = dev_get_priv(bus);
uint actual_speed;
+#if defined(CONFIG_DM_RESET)
+ /* Enable the controller */
+ if (dev->reset_valid)
+ reset_deassert(&dev->reset);
+#endif
+#if defined(CONFIG_CLK)
+ /* Open the clock-gate */
+ if (dev->clk_gate_valid)
+ clk_enable(&dev->clk_gate);
+#endif
+
__twsi_i2c_init(dev->base, dev->speed, dev->slaveadd, &actual_speed);
dev->speed = actual_speed;
dev->tick = calc_tick(dev->speed);
@@ -831,6 +870,9 @@ 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", },
+#if defined(CONFIG_ARCH_SUNXI)
+ { .compatible = "allwinner,sun6i-a31-i2c", },
+#endif
{ /* sentinel */ }
};
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index 4f566fa4ce..aaab809453 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -262,11 +262,14 @@
defined CONFIG_SY8106A_POWER
#endif
-#if defined CONFIG_I2C0_ENABLE || defined CONFIG_I2C1_ENABLE || \
- defined CONFIG_I2C2_ENABLE || defined CONFIG_I2C3_ENABLE || \
- defined CONFIG_I2C4_ENABLE || defined CONFIG_R_I2C_ENABLE
+#if !defined(CONFIG_DM_I2C) && \
+ (defined CONFIG_I2C0_ENABLE || defined CONFIG_I2C1_ENABLE || \
+ defined CONFIG_I2C2_ENABLE || defined CONFIG_I2C3_ENABLE || \
+ defined CONFIG_I2C4_ENABLE || defined CONFIG_R_I2C_ENABLE)
#define CONFIG_SYS_I2C
+#if !defined(CONFIG_SYS_I2C_MVTWSI)
#define CONFIG_SYS_I2C_MVTWSI
+#endif
#define CONFIG_SYS_I2C_SPEED 400000
#define CONFIG_SYS_I2C_SLAVE 0x7f
#endif