From 1a910bcee2444842de58a3b748a942fe0f183d67 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Sun, 9 Sep 2018 00:38:19 +0100 Subject: allwinner: sun50i_h6: improve I2C setup Drop the unnecessary check for the I2C pins being already configured as I2C pins (we actually don't care). Also avoid resetting *every* peripheral that is covered by the PRCM reset controller, instead just clear the one line connected to the I2C controller. Signed-off-by: Andre Przywara --- plat/allwinner/sun50i_h6/sunxi_power.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/plat/allwinner/sun50i_h6/sunxi_power.c b/plat/allwinner/sun50i_h6/sunxi_power.c index f109ccec..b6e07a24 100644 --- a/plat/allwinner/sun50i_h6/sunxi_power.c +++ b/plat/allwinner/sun50i_h6/sunxi_power.c @@ -28,13 +28,8 @@ static int sunxi_init_r_i2c(void) { uint32_t reg; - /* get currently configured function for pins PL0 and PL1 */ - reg = mmio_read_32(SUNXI_R_PIO_BASE + 0x00); - if ((reg & 0xff) == 0x33) { - NOTICE("PMIC: already configured for TWI\n"); - } - /* switch pins PL0 and PL1 to I2C */ + reg = mmio_read_32(SUNXI_R_PIO_BASE + 0x00); mmio_write_32(SUNXI_R_PIO_BASE + 0x00, (reg & ~0xff) | 0x33); /* level 2 drive strength */ @@ -47,13 +42,11 @@ static int sunxi_init_r_i2c(void) /* assert & de-assert reset of R_I2C */ reg = mmio_read_32(SUNXI_R_PRCM_BASE + 0x19c); - mmio_write_32(SUNXI_R_PRCM_BASE + 0x19c, 0); - reg = mmio_read_32(SUNXI_R_PRCM_BASE + 0x19c); - mmio_write_32(SUNXI_R_PRCM_BASE + 0x19c, reg | 0x00010000); + mmio_write_32(SUNXI_R_PRCM_BASE + 0x19c, reg & ~BIT(16)); + mmio_write_32(SUNXI_R_PRCM_BASE + 0x19c, reg | BIT(16)); /* un-gate R_I2C clock */ - reg = mmio_read_32(SUNXI_R_PRCM_BASE + 0x19c); - mmio_write_32(SUNXI_R_PRCM_BASE + 0x19c, reg | 0x00000001); + mmio_write_32(SUNXI_R_PRCM_BASE + 0x19c, reg | BIT(16) | BIT(0)); /* call mi2cv driver */ i2c_init((void *)SUNXI_R_I2C_BASE); -- cgit v1.2.3 From 159c52491af33ff8014ee2fa708804bb75540419 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Sun, 9 Sep 2018 00:38:58 +0100 Subject: allwinner: sun50i_h6: initialise I2C just before powering down Even though we initialise the platform part and the I2C controller itself at boot time, we actually only access the bus on power down. Meanwhile a rich OS might have configured the I2C pins differently or even disabled the controller. So repeat the platform setup and controller initialisation just before we actually access the bus to power off the system. This is safe, because at this point the rich OS should no longer be running. Signed-off-by: Andre Przywara --- plat/allwinner/sun50i_h6/sunxi_power.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plat/allwinner/sun50i_h6/sunxi_power.c b/plat/allwinner/sun50i_h6/sunxi_power.c index b6e07a24..12438b33 100644 --- a/plat/allwinner/sun50i_h6/sunxi_power.c +++ b/plat/allwinner/sun50i_h6/sunxi_power.c @@ -120,10 +120,9 @@ void __dead2 sunxi_power_down(void) switch (pmic) { case AXP805: - val = 0x26; /* Default value for REG 32H */ + sunxi_init_r_i2c(); axp_i2c_read(AXP805_ADDR, 0x32, &val); - val |= 0x80; - axp_i2c_write(AXP805_ADDR, 0x32, val); + axp_i2c_write(AXP805_ADDR, 0x32, val | 0x80); break; default: break; -- cgit v1.2.3 From dfc0fb272554ea5829fa74c6b75b9e656f55d0b3 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Sun, 9 Sep 2018 01:39:57 +0100 Subject: drivers: i2c: mentor: move platform code into header files At the moment we have two I2C stub drivers (for the Allwinner and the Marvell platform), which #include the actual .c driver file. Change this into the more usual design, by renaming and moving the stub drivers into platform specific header files and including these from the actual driver file. The platform specific include directories make sure the driver picks up the right header automatically. Signed-off-by: Andre Przywara --- drivers/allwinner/sunxi_i2c.c | 28 ------------------- drivers/marvell/i2c/a8k_i2c.c | 33 ----------------------- drivers/mentor/i2c/mi2cv.c | 1 + plat/allwinner/common/include/mentor_i2c_plat.h | 28 +++++++++++++++++++ plat/allwinner/sun50i_h6/platform.mk | 2 +- plat/marvell/a8k/common/a8k_common.mk | 4 +-- plat/marvell/a8k/common/include/mentor_i2c_plat.h | 33 +++++++++++++++++++++++ 7 files changed, 65 insertions(+), 64 deletions(-) delete mode 100644 drivers/allwinner/sunxi_i2c.c delete mode 100644 drivers/marvell/i2c/a8k_i2c.c create mode 100644 plat/allwinner/common/include/mentor_i2c_plat.h create mode 100644 plat/marvell/a8k/common/include/mentor_i2c_plat.h diff --git a/drivers/allwinner/sunxi_i2c.c b/drivers/allwinner/sunxi_i2c.c deleted file mode 100644 index cc91ca58..00000000 --- a/drivers/allwinner/sunxi_i2c.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2018 Icenowy Zheng - * - * SPDX-License-Identifier: BSD-3-Clause - * https://spdx.org/licenses - */ - -/* This driver provides I2C support for Allwinner sunXi SoCs */ - -#include - -#define CONFIG_SYS_TCLK 24000000 -#define CONFIG_SYS_I2C_SPEED 100000 -#define CONFIG_SYS_I2C_SLAVE 0 - -#define I2C_INTERRUPT_CLEAR_INVERTED - -struct mentor_i2c_regs { - uint32_t slave_address; - uint32_t xtnd_slave_addr; - uint32_t data; - uint32_t control; - uint32_t status; - uint32_t baudrate; - uint32_t soft_reset; -}; - -#include "../mentor/i2c/mi2cv.c" diff --git a/drivers/marvell/i2c/a8k_i2c.c b/drivers/marvell/i2c/a8k_i2c.c deleted file mode 100644 index 1c0f922c..00000000 --- a/drivers/marvell/i2c/a8k_i2c.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2018 Marvell International Ltd. - * - * SPDX-License-Identifier: BSD-3-Clause - * https://spdx.org/licenses - */ - -/* This driver provides I2C support for Marvell A8K and compatible SoCs */ - -#include - -#define CONFIG_SYS_TCLK 250000000 -#define CONFIG_SYS_I2C_SPEED 100000 -#define CONFIG_SYS_I2C_SLAVE 0x0 - -#define I2C_CAN_UNSTUCK - -struct mentor_i2c_regs { - uint32_t slave_address; - uint32_t data; - uint32_t control; - union { - uint32_t status; /* when reading */ - uint32_t baudrate; /* when writing */ - }; - uint32_t xtnd_slave_addr; - uint32_t reserved[2]; - uint32_t soft_reset; - uint8_t reserved2[0xa0 - 0x20]; - uint32_t unstuck; -}; - -#include "../../mentor/i2c/mi2cv.c" diff --git a/drivers/mentor/i2c/mi2cv.c b/drivers/mentor/i2c/mi2cv.c index 1b73e6f1..8ebd9662 100644 --- a/drivers/mentor/i2c/mi2cv.c +++ b/drivers/mentor/i2c/mi2cv.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #if LOG_LEVEL >= LOG_LEVEL_VERBOSE diff --git a/plat/allwinner/common/include/mentor_i2c_plat.h b/plat/allwinner/common/include/mentor_i2c_plat.h new file mode 100644 index 00000000..f547f9a4 --- /dev/null +++ b/plat/allwinner/common/include/mentor_i2c_plat.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2018 Icenowy Zheng + * + * SPDX-License-Identifier: BSD-3-Clause + * https://spdx.org/licenses + */ +/* This driver provides I2C support for Allwinner sunXi SoCs */ + +#ifndef SUNXI_I2C_H +#define SUNXI_I2C_H + +#define CONFIG_SYS_TCLK 24000000 +#define CONFIG_SYS_I2C_SPEED 100000 +#define CONFIG_SYS_I2C_SLAVE 0 + +#define I2C_INTERRUPT_CLEAR_INVERTED + +struct mentor_i2c_regs { + uint32_t slave_address; + uint32_t xtnd_slave_addr; + uint32_t data; + uint32_t control; + uint32_t status; + uint32_t baudrate; + uint32_t soft_reset; +}; + +#endif diff --git a/plat/allwinner/sun50i_h6/platform.mk b/plat/allwinner/sun50i_h6/platform.mk index c3901d01..90987020 100644 --- a/plat/allwinner/sun50i_h6/platform.mk +++ b/plat/allwinner/sun50i_h6/platform.mk @@ -15,8 +15,8 @@ PLAT_INCLUDES := -Iinclude/plat/arm/common \ -I${AW_PLAT}/${PLAT}/include PLAT_BL_COMMON_SOURCES := drivers/console/${ARCH}/console.S \ + drivers/mentor/i2c/mi2cv.c \ drivers/ti/uart/${ARCH}/16550_console.S \ - ${AW_DRIVERS}/sunxi_i2c.c \ ${XLAT_TABLES_LIB_SRCS} \ ${AW_PLAT}/common/plat_helpers.S \ ${AW_PLAT}/common/sunxi_common.c diff --git a/plat/marvell/a8k/common/a8k_common.mk b/plat/marvell/a8k/common/a8k_common.mk index 5956737d..be2ff1e3 100644 --- a/plat/marvell/a8k/common/a8k_common.mk +++ b/plat/marvell/a8k/common/a8k_common.mk @@ -57,9 +57,9 @@ BLE_PORTING_SOURCES := $(PLAT_FAMILY_BASE)/$(PLAT)/board/dram_port.c \ MARVELL_MOCHI_DRV += $(MARVELL_DRV_BASE)/mochi/cp110_setup.c -BLE_SOURCES := $(PLAT_COMMON_BASE)/plat_ble_setup.c \ +BLE_SOURCES := drivers/mentor/i2c/mi2cv.c \ + $(PLAT_COMMON_BASE)/plat_ble_setup.c \ $(MARVELL_MOCHI_DRV) \ - $(MARVELL_DRV_BASE)/i2c/a8k_i2c.c \ $(PLAT_COMMON_BASE)/plat_pm.c \ $(MARVELL_DRV_BASE)/thermal.c \ $(PLAT_COMMON_BASE)/plat_thermal.c \ diff --git a/plat/marvell/a8k/common/include/mentor_i2c_plat.h b/plat/marvell/a8k/common/include/mentor_i2c_plat.h new file mode 100644 index 00000000..8829a922 --- /dev/null +++ b/plat/marvell/a8k/common/include/mentor_i2c_plat.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2018 Marvell International Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + * https://spdx.org/licenses + */ +/* This driver provides I2C support for Marvell A8K and compatible SoCs */ + +#ifndef A8K_I2C_H +#define A8K_I2C_H + +#define CONFIG_SYS_TCLK 250000000 +#define CONFIG_SYS_I2C_SPEED 100000 +#define CONFIG_SYS_I2C_SLAVE 0x0 + +#define I2C_CAN_UNSTUCK + +struct mentor_i2c_regs { + uint32_t slave_address; + uint32_t data; + uint32_t control; + union { + uint32_t status; /* when reading */ + uint32_t baudrate; /* when writing */ + }; + uint32_t xtnd_slave_addr; + uint32_t reserved[2]; + uint32_t soft_reset; + uint8_t reserved2[0xa0 - 0x20]; + uint32_t unstuck; +}; + +#endif -- cgit v1.2.3