]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
sunxi: Add support for the I2C controller which is part of the PRCM
authorJelle van der Waa <jelle@vdwaa.nl>
Thu, 14 Jan 2016 13:06:26 +0000 (14:06 +0100)
committerHeiko Schocher <hs@denx.de>
Thu, 21 Jan 2016 06:30:01 +0000 (07:30 +0100)
Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
[hdegoede@redhat.com: Minor cleanups]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
applied with fixing 2 checkpatch warnings:
WARNING: please, no space before tabs

Signed-off-by: Heiko Schocher <hs@denx.de>
arch/arm/cpu/armv7/sunxi/clock_sun6i.c
arch/arm/cpu/armv7/sunxi/prcm.c
arch/arm/include/asm/arch-sunxi/cpu_sun4i.h
arch/arm/include/asm/arch-sunxi/gpio.h
arch/arm/include/asm/arch-sunxi/i2c.h
arch/arm/include/asm/arch-sunxi/prcm.h
board/sunxi/Kconfig
board/sunxi/board.c
configs/orangepi_pc_defconfig
drivers/i2c/mvtwsi.c
include/configs/sunxi-common.h

index 4501884e1c2a7e7770885038d5b141b89f315160..1da5455c9ad3bf4666c8892af02afaffab9dea74 100644 (file)
@@ -77,6 +77,16 @@ int clock_twi_onoff(int port, int state)
        struct sunxi_ccm_reg *const ccm =
                (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
 
+       if (port == 5) {
+               if (state)
+                       prcm_apb0_enable(
+                               PRCM_APB0_GATE_PIO | PRCM_APB0_GATE_I2C);
+               else
+                       prcm_apb0_disable(
+                               PRCM_APB0_GATE_PIO | PRCM_APB0_GATE_I2C);
+               return 0;
+       }
+
        /* set the apb clock gate for twi */
        if (state)
                setbits_le32(&ccm->apb2_gate,
index 19b4938dc9742c0ed453529838821bc17eb8747c..e1d091fd577152ed57b42f51a80064fe3a438dc3 100644 (file)
@@ -33,3 +33,15 @@ void prcm_apb0_enable(u32 flags)
        /* deassert reset for module */
        setbits_le32(&prcm->apb0_reset, flags);
 }
+
+void prcm_apb0_disable(u32 flags)
+{
+       struct sunxi_prcm_reg *prcm =
+               (struct sunxi_prcm_reg *)SUNXI_PRCM_BASE;
+
+       /* assert reset for module */
+       clrbits_le32(&prcm->apb0_reset, flags);
+
+       /* close the clock for module */
+       clrbits_le32(&prcm->apb0_gate, flags);
+}
index 63b161ab032635335165e66c0f36d0f6557d5d29..0cdefdcdf4a66cafe5a174254c9d35c37baacc17 100644 (file)
 #define SUNXI_RTC_BASE                 0x01f00000
 #define SUNXI_PRCM_BASE                        0x01f01400
 #define SUN6I_CPUCFG_BASE              0x01f01c00
+#define SUNXI_R_TWI_BASE               0x01f02400
 #define SUNXI_R_UART_BASE              0x01f02800
 #define SUNXI_R_PIO_BASE               0x01f02c00
 #define SUN6I_P2WI_BASE                        0x01f03400
index a2a9a38dbe7e5ff6adc35394f1ebb32409eed774..649f6cd840f8194e7fecc47b9cfe85aeed63d2fa 100644 (file)
@@ -199,6 +199,8 @@ enum sunxi_gpio_number {
 #define SUN6I_GPL1_R_P2WI_SDA  3
 
 #define SUN8I_GPL_R_RSB                2
+#define SUN8I_H3_GPL_R_TWI     2
+#define SUN8I_A23_GPL_R_TWI    3
 #define SUN8I_GPL_R_UART       2
 
 #define SUN9I_GPN_R_RSB                3
index 561cd2be164d544fb4842a2c66ada4d226c2cad3..4dfd313f1ad59e0e40571a49afe9833269cabc78 100644 (file)
@@ -23,6 +23,9 @@
 #ifdef CONFIG_I2C4_ENABLE
 #define CONFIG_I2C_MVTWSI_BASE4        SUNXI_TWI4_BASE
 #endif
+#ifdef CONFIG_R_I2C_ENABLE
+#define CONFIG_I2C_MVTWSI_BASE5 SUNXI_R_TWI_BASE
+#endif
 
 /* This is abp0-clk on sun4i/5i/7i / abp1-clk on sun6i/sun8i which is 24MHz */
 #define CONFIG_SYS_TCLK                24000000
index 82ed541e91e4789535e236963afd9b2f232daa25..556c1af60058e5c470182cd16e0ad44e2cf17500 100644 (file)
@@ -236,5 +236,7 @@ struct sunxi_prcm_reg {
 };
 
 void prcm_apb0_enable(u32 flags);
+void prcm_apb0_disable(u32 flags);
+
 #endif /* __ASSEMBLY__ */
 #endif /* _PRCM_H */
index 9d67847850f9115317df5d0f934168d6208eef8a..7c69be918f16d7e90a765bf29958140dee13d15e 100644 (file)
@@ -363,6 +363,12 @@ config I2C3_ENABLE
        See I2C0_ENABLE help text.
 endif
 
+config R_I2C_ENABLE
+       bool "Enable the PRCM I2C/TWI controller"
+       default n
+       ---help---
+       Set this to y to enable the I2C controller which is part of the PRCM.
+
 if MACH_SUN7I
 config I2C4_ENABLE
        bool "Enable I2C/TWI controller 4"
index 386e2e04c219bdf4ffe07b2178f1f708c84744e2..1cc39e4d1840e8f0a98ae61269b0a5d3bd11d926 100644 (file)
@@ -422,6 +422,12 @@ void i2c_init_board(void)
        clock_twi_onoff(4, 1);
 #endif
 #endif
+
+#ifdef CONFIG_R_I2C_ENABLE
+       clock_twi_onoff(5, 1);
+       sunxi_gpio_set_cfgpin(SUNXI_GPL(0), SUN8I_H3_GPL_R_TWI);
+       sunxi_gpio_set_cfgpin(SUNXI_GPL(1), SUN8I_H3_GPL_R_TWI);
+#endif
 }
 
 #ifdef CONFIG_SPL_BUILD
index 358caa51e7f96350d32e825ab771679075f3c6ab..ea9ed874e8f968fb58e01943305da8a9b609271e 100644 (file)
@@ -12,3 +12,4 @@ CONFIG_SPL=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_FPGA is not set
 CONFIG_CMD_GPIO=y
+CONFIG_R_I2C_ENABLE=y
index 30a5b11f9f3dc59b2f86bf6d44bb2330f911e21e..5f993b99052360b406860bc2098b67e68cfeb57c 100644 (file)
@@ -127,6 +127,10 @@ static struct mvtwsi_registers *twsi_get_base(struct i2c_adapter *adap)
 #ifdef CONFIG_I2C_MVTWSI_BASE4
        case 4:
                return (struct mvtwsi_registers *) CONFIG_I2C_MVTWSI_BASE4;
+#endif
+#ifdef CONFIG_I2C_MVTWSI_BASE5
+       case 5:
+               return (struct mvtwsi_registers *) CONFIG_I2C_MVTWSI_BASE5;
 #endif
        default:
                printf("Missing mvtwsi controller %d base\n", adap->hwadapnr);
@@ -487,3 +491,10 @@ U_BOOT_I2C_ADAP_COMPLETE(twsi4, twsi_i2c_init, twsi_i2c_probe,
                         CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE, 4)
 
 #endif
+#ifdef CONFIG_I2C_MVTWSI_BASE5
+U_BOOT_I2C_ADAP_COMPLETE(twsi5, twsi_i2c_init, twsi_i2c_probe,
+                        twsi_i2c_read, twsi_i2c_write,
+                        twsi_i2c_set_bus_speed,
+                        CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE, 5)
+
+#endif
index 790e7047d1524742c61fc3714ee3f8891225c66d..b4dfb3cc47c7d9f29c2d005de17a7f494db87202 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_I2C4_ENABLE || defined CONFIG_R_I2C_ENABLE
 #define CONFIG_SYS_I2C
 #define CONFIG_SYS_I2C_MVTWSI
 #define CONFIG_SYS_I2C_SPEED           400000