sunxi: i2c: Add support for DM I2C
authorJernej Skrabec <jernej.skrabec@siol.net>
Wed, 26 Apr 2017 22:03:36 +0000 (00:03 +0200)
committerMaxime Ripard <maxime.ripard@free-electrons.com>
Fri, 28 Apr 2017 07:19:03 +0000 (09:19 +0200)
This commit adds support for DM I2C on sunxi platform. It can coexist
with old style sunxi I2C driver, because it is still used in SPL and
by some SoCs.

Because sunxi platform doesn't yet support DM clk, reset and pinctrl
driver, workaround is needed to enable clocks and set resets and
pinctrls. This is done by calling i2c_init_board() in board_init().
This means that CONFIG_I2Cx_ENABLE options needs to be correctly set
in order to use needed I2C controller.

Commit is based on the previous patch made by Philipp Tomsich

Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net>
Reviewed-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
arch/arm/mach-sunxi/board.c
board/sunxi/board.c
drivers/i2c/mvtwsi.c
include/configs/sunxi-common.h

index 4507279cc55fc1129e3bc91d017e81740dade9ba..65b1ebd837871bccb2c0b73f52541da5bc6c192f 100644 (file)
@@ -204,7 +204,9 @@ void s_init(void)
        clock_init();
        timer_init();
        gpio_init();
+#ifndef CONFIG_DM_I2C
        i2c_init_board();
+#endif
        eth_init_board();
 }
 
index f903a5d0a028fb627807572f39aed052f06e0f5b..01de42d0318628645653331839715a7449a8ca58 100644 (file)
@@ -222,6 +222,14 @@ int board_init(void)
        gpio_direction_output(macpwr_pin, 1);
 #endif
 
+#ifdef CONFIG_DM_I2C
+       /*
+        * Temporary workaround for enabling I2C clocks until proper sunxi DM
+        * clk, reset and pinctrl drivers land.
+        */
+       i2c_init_board();
+#endif
+
        /* Uses dm gpio code so do this here and not in i2c_init_board() */
        return soft_i2c_board_init();
 }
index 648a96eeb4e88cd0ab9b753b31c8d85b9b33d4e5..3703519aa52dc8409285da7e9694682e689847ef 100644 (file)
@@ -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
  */
@@ -831,6 +839,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 */ }
 };
 
index 64a190059ac3f989725d6ef6030e3b2e5e6fcd35..b794e427bb80987fa91244ff187577effe819597 100644 (file)
 #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
-#define CONFIG_SYS_I2C
 #define CONFIG_SYS_I2C_MVTWSI
+#ifndef CONFIG_DM_I2C
+#define CONFIG_SYS_I2C
 #define CONFIG_SYS_I2C_SPEED           400000
 #define CONFIG_SYS_I2C_SLAVE           0x7f
 #endif
+#endif
 
 #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
 #define CONFIG_SYS_I2C_SOFT