diff options
author | Alistair Delva <adelva@google.com> | 2021-02-16 21:01:22 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-16 21:01:22 +0000 |
commit | efb2826bb8160e2d8e0fcec85133a7468484f9fd (patch) | |
tree | 37a21c69306801ee7cdda5167a30896c8740155b /plat/allwinner | |
parent | b00a71fc312c9781fa6f404dccfb55b062b2ccac (diff) | |
parent | faa476c0caaa598afa5a6109d17102db5fe35ec6 (diff) | |
download | platform_external_arm-trusted-firmware-master.tar.gz platform_external_arm-trusted-firmware-master.tar.bz2 platform_external_arm-trusted-firmware-master.zip |
Merge branch 'aosp/upstream-master' into HEAD am: faa476c0caHEADandroid-s-beta-5android-s-beta-4android-s-beta-3android-s-beta-2android-s-beta-1mastermain-cg-testing-releaseandroid-s-beta-5android-s-beta-4
Original change: https://android-review.googlesource.com/c/platform/external/arm-trusted-firmware/+/1589611
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I3a25534ceed4f8e188510641080d8b8ed49b8f62
Diffstat (limited to 'plat/allwinner')
-rw-r--r-- | plat/allwinner/common/allwinner-common.mk | 14 | ||||
-rw-r--r-- | plat/allwinner/common/include/platform_def.h | 17 | ||||
-rw-r--r-- | plat/allwinner/common/sunxi_bl31_setup.c | 9 | ||||
-rw-r--r-- | plat/allwinner/common/sunxi_common.c | 23 | ||||
-rw-r--r-- | plat/allwinner/common/sunxi_pm.c | 194 | ||||
-rw-r--r-- | plat/allwinner/common/sunxi_security.c | 21 | ||||
-rw-r--r-- | plat/allwinner/sun50i_a64/include/sunxi_ccu.h | 14 | ||||
-rw-r--r-- | plat/allwinner/sun50i_a64/include/sunxi_mmap.h | 7 | ||||
-rw-r--r-- | plat/allwinner/sun50i_a64/include/sunxi_spc.h | 16 | ||||
-rw-r--r-- | plat/allwinner/sun50i_a64/sunxi_power.c | 21 | ||||
-rw-r--r-- | plat/allwinner/sun50i_h6/include/sunxi_ccu.h | 14 | ||||
-rw-r--r-- | plat/allwinner/sun50i_h6/include/sunxi_mmap.h | 13 | ||||
-rw-r--r-- | plat/allwinner/sun50i_h6/include/sunxi_spc.h | 16 | ||||
-rw-r--r-- | plat/allwinner/sun50i_h6/platform.mk | 2 | ||||
-rw-r--r-- | plat/allwinner/sun50i_h6/sunxi_power.c | 74 |
15 files changed, 328 insertions, 127 deletions
diff --git a/plat/allwinner/common/allwinner-common.mk b/plat/allwinner/common/allwinner-common.mk index 98bcf3e22..901d88895 100644 --- a/plat/allwinner/common/allwinner-common.mk +++ b/plat/allwinner/common/allwinner-common.mk @@ -5,6 +5,8 @@ # include lib/xlat_tables_v2/xlat_tables.mk +include lib/libfdt/libfdt.mk +include drivers/arm/gic/v2/gicv2.mk AW_PLAT := plat/allwinner @@ -12,17 +14,15 @@ PLAT_INCLUDES := -Iinclude/plat/arm/common/aarch64 \ -I${AW_PLAT}/common/include \ -I${AW_PLAT}/${PLAT}/include -include lib/libfdt/libfdt.mk - PLAT_BL_COMMON_SOURCES := drivers/ti/uart/${ARCH}/16550_console.S \ ${XLAT_TABLES_LIB_SRCS} \ ${AW_PLAT}/common/plat_helpers.S \ ${AW_PLAT}/common/sunxi_common.c BL31_SOURCES += drivers/allwinner/axp/common.c \ - drivers/arm/gic/common/gic_common.c \ - drivers/arm/gic/v2/gicv2_helpers.c \ - drivers/arm/gic/v2/gicv2_main.c \ + drivers/allwinner/sunxi_msgbox.c \ + drivers/arm/css/scpi/css_scpi.c \ + ${GICV2_SOURCES} \ drivers/delay_timer/delay_timer.c \ drivers/delay_timer/generic_delay_timer.c \ lib/cpus/${ARCH}/cortex_a53.S \ @@ -48,6 +48,10 @@ ENABLE_SVE_FOR_NS := 0 ERRATA_A53_835769 := 1 ERRATA_A53_843419 := 1 ERRATA_A53_855873 := 1 +ERRATA_A53_1530924 := 1 + +# The traditional U-Boot load address is 160MB into DRAM. +PRELOADED_BL33_BASE ?= 0x4a000000 # The reset vector can be changed for each CPU. PROGRAMMABLE_RESET_ADDRESS := 1 diff --git a/plat/allwinner/common/include/platform_def.h b/plat/allwinner/common/include/platform_def.h index 32a7c0408..93720fff2 100644 --- a/plat/allwinner/common/include/platform_def.h +++ b/plat/allwinner/common/include/platform_def.h @@ -13,16 +13,18 @@ #include <sunxi_mmap.h> -#define BL31_BASE SUNXI_SRAM_A2_BASE -#define BL31_LIMIT (SUNXI_SRAM_A2_BASE + SUNXI_SRAM_A2_SIZE) +#define BL31_BASE (SUNXI_SRAM_A2_BASE + 0x4000) +#define BL31_LIMIT (SUNXI_SRAM_A2_BASE + \ + SUNXI_SRAM_A2_SIZE - SUNXI_SCP_SIZE) + +/* The SCP firmware is allocated the last 16KiB of SRAM A2. */ +#define SUNXI_SCP_BASE BL31_LIMIT +#define SUNXI_SCP_SIZE 0x4000 /* Overwrite U-Boot SPL, but reserve the first page for the SPL header. */ #define BL31_NOBITS_BASE (SUNXI_SRAM_A1_BASE + 0x1000) #define BL31_NOBITS_LIMIT (SUNXI_SRAM_A1_BASE + SUNXI_SRAM_A1_SIZE) -/* The traditional U-Boot load address is 160MB into DRAM, so at 0x4a000000 */ -#define PLAT_SUNXI_NS_IMAGE_OFFSET (SUNXI_DRAM_BASE + (160U << 20)) - /* How much memory to reserve as secure for BL32, if configured */ #define SUNXI_DRAM_SEC_SIZE (32U << 20) @@ -35,6 +37,9 @@ #define MAX_MMAP_REGIONS (3 + PLATFORM_MMAP_REGIONS) #define MAX_XLAT_TABLES 1 +#define PLAT_CSS_SCP_COM_SHARED_MEM_BASE \ + (SUNXI_SRAM_A2_BASE + SUNXI_SRAM_A2_SIZE - 0x200) + #define PLAT_MAX_PWR_LVL_STATES U(2) #define PLAT_MAX_RET_STATE U(1) #define PLAT_MAX_OFF_STATE U(2) @@ -51,7 +56,7 @@ #define PLATFORM_CORE_COUNT (PLATFORM_CLUSTER_COUNT * \ PLATFORM_MAX_CPUS_PER_CLUSTER) #define PLATFORM_MAX_CPUS_PER_CLUSTER U(4) -#define PLATFORM_MMAP_REGIONS 4 +#define PLATFORM_MMAP_REGIONS 5 #define PLATFORM_STACK_SIZE (0x1000 / PLATFORM_CORE_COUNT) #ifndef SPD_none diff --git a/plat/allwinner/common/sunxi_bl31_setup.c b/plat/allwinner/common/sunxi_bl31_setup.c index a24527c5d..b619b18ed 100644 --- a/plat/allwinner/common/sunxi_bl31_setup.c +++ b/plat/allwinner/common/sunxi_bl31_setup.c @@ -28,7 +28,7 @@ static entry_point_info_t bl32_image_ep_info; static entry_point_info_t bl33_image_ep_info; -static console_16550_t console; +static console_t console; static const gicv2_driver_data_t sunxi_gic_data = { .gicd_base = SUNXI_GICD_BASE, @@ -57,7 +57,7 @@ static void *sunxi_find_dtb(void) for (i = 0; i < 2048 / sizeof(uint64_t); i++) { uint32_t *dtb_base; - if (u_boot_base[i] != PLAT_SUNXI_NS_IMAGE_OFFSET) + if (u_boot_base[i] != PRELOADED_BL33_BASE) continue; /* Does the suspected U-Boot size look anyhow reasonable? */ @@ -96,13 +96,10 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, * Tell BL31 where the non-trusted software image * is located and the entry state information */ - bl33_image_ep_info.pc = plat_get_ns_image_entrypoint(); + bl33_image_ep_info.pc = PRELOADED_BL33_BASE; bl33_image_ep_info.spsr = SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE); - - /* Turn off all secondary CPUs */ - sunxi_disable_secondary_cpus(read_mpidr()); } void bl31_plat_arch_setup(void) diff --git a/plat/allwinner/common/sunxi_common.c b/plat/allwinner/common/sunxi_common.c index 3759c285e..5b536a043 100644 --- a/plat/allwinner/common/sunxi_common.c +++ b/plat/allwinner/common/sunxi_common.c @@ -21,11 +21,13 @@ static const mmap_region_t sunxi_mmap[PLATFORM_MMAP_REGIONS + 1] = { MAP_REGION_FLAT(SUNXI_SRAM_BASE, SUNXI_SRAM_SIZE, MT_RW_DATA | MT_SECURE), + MAP_REGION_FLAT(SUNXI_SCP_BASE, SUNXI_SCP_SIZE, + MT_DEVICE | MT_RW | MT_SECURE | MT_EXECUTE_NEVER), MAP_REGION_FLAT(SUNXI_DEV_BASE, SUNXI_DEV_SIZE, MT_DEVICE | MT_RW | MT_SECURE | MT_EXECUTE_NEVER), MAP_REGION(SUNXI_DRAM_BASE, SUNXI_DRAM_VIRT_BASE, SUNXI_DRAM_SEC_SIZE, MT_RW_DATA | MT_SECURE), - MAP_REGION(PLAT_SUNXI_NS_IMAGE_OFFSET, + MAP_REGION(PRELOADED_BL33_BASE, SUNXI_DRAM_VIRT_BASE + SUNXI_DRAM_SEC_SIZE, SUNXI_DRAM_MAP_SIZE, MT_RO_DATA | MT_NS), @@ -37,15 +39,6 @@ unsigned int plat_get_syscnt_freq2(void) return SUNXI_OSC24M_CLK_IN_HZ; } -uintptr_t plat_get_ns_image_entrypoint(void) -{ -#ifdef PRELOADED_BL33_BASE - return PRELOADED_BL33_BASE; -#else - return PLAT_SUNXI_NS_IMAGE_OFFSET; -#endif -} - void sunxi_configure_mmu_el3(int flags) { mmap_add_region(BL_CODE_BASE, BL_CODE_BASE, @@ -123,11 +116,9 @@ int sunxi_init_platform_r_twi(uint16_t socid, bool use_rsb) device_bit = BIT(6); break; case SUNXI_SOC_H6: - if (use_rsb) - return -ENODEV; - pin_func = 0x33; + pin_func = use_rsb ? 0x22 : 0x33; device_bit = BIT(16); - reset_offset = 0x19c; + reset_offset = use_rsb ? 0x1bc : 0x19c; break; case SUNXI_SOC_A64: pin_func = use_rsb ? 0x22 : 0x33; @@ -155,7 +146,7 @@ int sunxi_init_platform_r_twi(uint16_t socid, bool use_rsb) if (socid != SUNXI_SOC_H6) mmio_setbits_32(SUNXI_R_PRCM_BASE + 0x28, device_bit); else - mmio_setbits_32(SUNXI_R_PRCM_BASE + 0x19c, device_bit | BIT(0)); + mmio_setbits_32(SUNXI_R_PRCM_BASE + reset_offset, BIT(0)); /* assert, then de-assert reset of I2C/RSB controller */ mmio_clrbits_32(SUNXI_R_PRCM_BASE + reset_offset, device_bit); @@ -175,7 +166,7 @@ DEFINE_BAKERY_LOCK(arisc_lock); */ void sunxi_execute_arisc_code(uint32_t *code, size_t size, uint16_t param) { - uintptr_t arisc_reset_vec = SUNXI_SRAM_A2_BASE - 0x4000 + 0x100; + uintptr_t arisc_reset_vec = SUNXI_SRAM_A2_BASE + 0x100; do { bakery_lock_get(&arisc_lock); diff --git a/plat/allwinner/common/sunxi_pm.c b/plat/allwinner/common/sunxi_pm.c index 9b074d2ac..aa80c528b 100644 --- a/plat/allwinner/common/sunxi_pm.c +++ b/plat/allwinner/common/sunxi_pm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -10,6 +10,7 @@ #include <arch_helpers.h> #include <common/debug.h> +#include <drivers/arm/css/css_scpi.h> #include <drivers/arm/gicv2.h> #include <drivers/delay_timer.h> #include <lib/mmio.h> @@ -17,6 +18,7 @@ #include <plat/common/platform.h> #include <sunxi_cpucfg.h> +#include <sunxi_def.h> #include <sunxi_mmap.h> #include <sunxi_private.h> @@ -24,25 +26,83 @@ #define SUNXI_WDOG0_CFG_REG (SUNXI_R_WDOG_BASE + 0x0014) #define SUNXI_WDOG0_MODE_REG (SUNXI_R_WDOG_BASE + 0x0018) -#define mpidr_is_valid(mpidr) ( \ - MPIDR_AFFLVL3_VAL(mpidr) == 0 && \ - MPIDR_AFFLVL2_VAL(mpidr) == 0 && \ - MPIDR_AFFLVL1_VAL(mpidr) < PLATFORM_CLUSTER_COUNT && \ - MPIDR_AFFLVL0_VAL(mpidr) < PLATFORM_MAX_CPUS_PER_CLUSTER) +#define CPU_PWR_LVL MPIDR_AFFLVL0 +#define CLUSTER_PWR_LVL MPIDR_AFFLVL1 +#define SYSTEM_PWR_LVL MPIDR_AFFLVL2 -static int sunxi_pwr_domain_on(u_register_t mpidr) +#define CPU_PWR_STATE(state) \ + ((state)->pwr_domain_state[CPU_PWR_LVL]) +#define CLUSTER_PWR_STATE(state) \ + ((state)->pwr_domain_state[CLUSTER_PWR_LVL]) +#define SYSTEM_PWR_STATE(state) \ + ((state)->pwr_domain_state[SYSTEM_PWR_LVL]) + +/* + * The addresses for the SCP exception vectors are defined in the or1k + * architecture specification. + */ +#define OR1K_VEC_FIRST 0x01 +#define OR1K_VEC_LAST 0x0e +#define OR1K_VEC_ADDR(n) (0x100 * (n)) + +/* + * This magic value is the little-endian representation of the or1k + * instruction "l.mfspr r2, r0, 0x12", which is guaranteed to be the + * first instruction in the SCP firmware. + */ +#define SCP_FIRMWARE_MAGIC 0xb4400012 + +static bool scpi_available; + +static inline scpi_power_state_t scpi_map_state(plat_local_state_t psci_state) { - if (mpidr_is_valid(mpidr) == 0) - return PSCI_E_INTERN_FAIL; + if (is_local_state_run(psci_state)) + return scpi_power_on; + if (is_local_state_retn(psci_state)) + return scpi_power_retention; + return scpi_power_off; +} - sunxi_cpu_on(mpidr); +static void sunxi_cpu_standby(plat_local_state_t cpu_state) +{ + u_register_t scr = read_scr_el3(); + + assert(is_local_state_retn(cpu_state)); + + write_scr_el3(scr | SCR_IRQ_BIT); + wfi(); + write_scr_el3(scr); +} + +static int sunxi_pwr_domain_on(u_register_t mpidr) +{ + if (scpi_available) { + scpi_set_css_power_state(mpidr, + scpi_power_on, + scpi_power_on, + scpi_power_on); + } else { + sunxi_cpu_on(mpidr); + } return PSCI_E_SUCCESS; } static void sunxi_pwr_domain_off(const psci_power_state_t *target_state) { - gicv2_cpuif_disable(); + plat_local_state_t cpu_pwr_state = CPU_PWR_STATE(target_state); + plat_local_state_t cluster_pwr_state = CLUSTER_PWR_STATE(target_state); + plat_local_state_t system_pwr_state = SYSTEM_PWR_STATE(target_state); + + if (is_local_state_off(cpu_pwr_state)) + gicv2_cpuif_disable(); + + if (scpi_available) { + scpi_set_css_power_state(read_mpidr(), + scpi_map_state(cpu_pwr_state), + scpi_map_state(cluster_pwr_state), + scpi_map_state(system_pwr_state)); + } } static void __dead2 sunxi_pwr_down_wfi(const psci_power_state_t *target_state) @@ -55,12 +115,26 @@ static void __dead2 sunxi_pwr_down_wfi(const psci_power_state_t *target_state) static void sunxi_pwr_domain_on_finish(const psci_power_state_t *target_state) { - gicv2_pcpu_distif_init(); - gicv2_cpuif_enable(); + if (is_local_state_off(SYSTEM_PWR_STATE(target_state))) + gicv2_distif_init(); + if (is_local_state_off(CPU_PWR_STATE(target_state))) { + gicv2_pcpu_distif_init(); + gicv2_cpuif_enable(); + } } static void __dead2 sunxi_system_off(void) { + gicv2_cpuif_disable(); + + if (scpi_available) { + /* Send the power down request to the SCP */ + uint32_t ret = scpi_sys_power_state(scpi_system_shutdown); + + if (ret != SCP_OK) + ERROR("PSCI: SCPI %s failed: %d\n", "shutdown", ret); + } + /* Turn off all secondary CPUs */ sunxi_disable_secondary_cpus(read_mpidr()); @@ -74,6 +148,16 @@ static void __dead2 sunxi_system_off(void) static void __dead2 sunxi_system_reset(void) { + gicv2_cpuif_disable(); + + if (scpi_available) { + /* Send the system reset request to the SCP */ + uint32_t ret = scpi_sys_power_state(scpi_system_reboot); + + if (ret != SCP_OK) + ERROR("PSCI: SCPI %s failed: %d\n", "reboot", ret); + } + /* Reset the whole system when the watchdog times out */ mmio_write_32(SUNXI_WDOG0_CFG_REG, 1); /* Enable the watchdog with the shortest timeout (0.5 seconds) */ @@ -86,22 +170,66 @@ static void __dead2 sunxi_system_reset(void) panic(); } +static int sunxi_validate_power_state(unsigned int power_state, + psci_power_state_t *req_state) +{ + unsigned int power_level = psci_get_pstate_pwrlvl(power_state); + unsigned int type = psci_get_pstate_type(power_state); + + assert(req_state != NULL); + + if (power_level > PLAT_MAX_PWR_LVL) + return PSCI_E_INVALID_PARAMS; + + if (type == PSTATE_TYPE_STANDBY) { + /* Only one retention power state is supported. */ + if (psci_get_pstate_id(power_state) > 0) + return PSCI_E_INVALID_PARAMS; + /* The SoC cannot be suspended without losing state */ + if (power_level == SYSTEM_PWR_LVL) + return PSCI_E_INVALID_PARAMS; + for (unsigned int i = 0; i <= power_level; ++i) + req_state->pwr_domain_state[i] = PLAT_MAX_RET_STATE; + } else { + /* Only one off power state is supported. */ + if (psci_get_pstate_id(power_state) > 0) + return PSCI_E_INVALID_PARAMS; + for (unsigned int i = 0; i <= power_level; ++i) + req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE; + } + /* Higher power domain levels should all remain running */ + for (unsigned int i = power_level + 1; i <= PLAT_MAX_PWR_LVL; ++i) + req_state->pwr_domain_state[i] = PSCI_LOCAL_STATE_RUN; + + return PSCI_E_SUCCESS; +} + static int sunxi_validate_ns_entrypoint(uintptr_t ns_entrypoint) { /* The non-secure entry point must be in DRAM */ - if (ns_entrypoint >= SUNXI_DRAM_BASE) - return PSCI_E_SUCCESS; + if (ns_entrypoint < SUNXI_DRAM_BASE) { + return PSCI_E_INVALID_ADDRESS; + } - return PSCI_E_INVALID_ADDRESS; + return PSCI_E_SUCCESS; +} + +static void sunxi_get_sys_suspend_power_state(psci_power_state_t *req_state) +{ + assert(req_state); + + for (unsigned int i = 0; i <= PLAT_MAX_PWR_LVL; ++i) + req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE; } static plat_psci_ops_t sunxi_psci_ops = { + .cpu_standby = sunxi_cpu_standby, .pwr_domain_on = sunxi_pwr_domain_on, .pwr_domain_off = sunxi_pwr_domain_off, - .pwr_domain_pwr_down_wfi = sunxi_pwr_down_wfi, .pwr_domain_on_finish = sunxi_pwr_domain_on_finish, .system_off = sunxi_system_off, .system_reset = sunxi_system_reset, + .validate_power_state = sunxi_validate_power_state, .validate_ns_entrypoint = sunxi_validate_ns_entrypoint, }; @@ -110,13 +238,43 @@ int plat_setup_psci_ops(uintptr_t sec_entrypoint, { assert(psci_ops); - for (int cpu = 0; cpu < PLATFORM_CORE_COUNT; cpu += 1) { + /* Program all CPU entry points. */ + for (unsigned int cpu = 0; cpu < PLATFORM_CORE_COUNT; ++cpu) { mmio_write_32(SUNXI_CPUCFG_RVBAR_LO_REG(cpu), sec_entrypoint & 0xffffffff); mmio_write_32(SUNXI_CPUCFG_RVBAR_HI_REG(cpu), sec_entrypoint >> 32); } + /* Check for a valid SCP firmware, and boot the SCP if found. */ + if (mmio_read_32(SUNXI_SCP_BASE) == SCP_FIRMWARE_MAGIC) { + /* Program SCP exception vectors to the firmware entrypoint. */ + for (unsigned int i = OR1K_VEC_FIRST; i <= OR1K_VEC_LAST; ++i) { + uint32_t vector = SUNXI_SRAM_A2_BASE + OR1K_VEC_ADDR(i); + uint32_t offset = SUNXI_SCP_BASE - vector; + + mmio_write_32(vector, offset >> 2); + clean_dcache_range(vector, sizeof(uint32_t)); + } + /* Take the SCP out of reset. */ + mmio_setbits_32(SUNXI_R_CPUCFG_BASE, BIT(0)); + /* Wait for the SCP firmware to boot. */ + if (scpi_wait_ready() == 0) + scpi_available = true; + } + + NOTICE("PSCI: System suspend is %s\n", + scpi_available ? "available via SCPI" : "unavailable"); + if (scpi_available) { + /* Suspend is only available via SCPI. */ + sunxi_psci_ops.pwr_domain_suspend = sunxi_pwr_domain_off; + sunxi_psci_ops.pwr_domain_suspend_finish = sunxi_pwr_domain_on_finish; + sunxi_psci_ops.get_sys_suspend_power_state = sunxi_get_sys_suspend_power_state; + } else { + /* This is only needed when SCPI is unavailable. */ + sunxi_psci_ops.pwr_domain_pwr_down_wfi = sunxi_pwr_down_wfi; + } + *psci_ops = &sunxi_psci_ops; return 0; diff --git a/plat/allwinner/common/sunxi_security.c b/plat/allwinner/common/sunxi_security.c index 1f16a0b72..98b91c39f 100644 --- a/plat/allwinner/common/sunxi_security.c +++ b/plat/allwinner/common/sunxi_security.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -7,16 +7,11 @@ #include <common/debug.h> #include <lib/mmio.h> +#include <sunxi_ccu.h> #include <sunxi_mmap.h> #include <sunxi_private.h> +#include <sunxi_spc.h> -#ifdef SUNXI_SPC_BASE -#define SPC_DECPORT_STA_REG(p) (SUNXI_SPC_BASE + ((p) * 0x0c) + 0x4) -#define SPC_DECPORT_SET_REG(p) (SUNXI_SPC_BASE + ((p) * 0x0c) + 0x8) -#define SPC_DECPORT_CLR_REG(p) (SUNXI_SPC_BASE + ((p) * 0x0c) + 0xc) -#endif - -#define R_PRCM_SEC_SWITCH_REG 0x1d0 #define DMA_SEC_REG 0x20 /* @@ -27,20 +22,18 @@ */ void sunxi_security_setup(void) { -#ifdef SUNXI_SPC_BASE int i; INFO("Configuring SPC Controller\n"); /* SPC setup: set all devices to non-secure */ - for (i = 0; i < 6; i++) - mmio_write_32(SPC_DECPORT_SET_REG(i), 0xff); -#endif + for (i = 0; i < SUNXI_SPC_NUM_PORTS; i++) + mmio_write_32(SUNXI_SPC_DECPORT_SET_REG(i), 0xffffffff); /* set MBUS clocks, bus clocks (AXI/AHB/APB) and PLLs to non-secure */ mmio_write_32(SUNXI_CCU_SEC_SWITCH_REG, 0x7); - /* set R_PRCM clocks to non-secure */ - mmio_write_32(SUNXI_R_PRCM_BASE + R_PRCM_SEC_SWITCH_REG, 0x7); + /* Set R_PRCM bus clocks to non-secure */ + mmio_write_32(SUNXI_R_PRCM_SEC_SWITCH_REG, 0x1); /* Set all DMA channels (16 max.) to non-secure */ mmio_write_32(SUNXI_DMA_BASE + DMA_SEC_REG, 0xffff); diff --git a/plat/allwinner/sun50i_a64/include/sunxi_ccu.h b/plat/allwinner/sun50i_a64/include/sunxi_ccu.h new file mode 100644 index 000000000..2a2488621 --- /dev/null +++ b/plat/allwinner/sun50i_a64/include/sunxi_ccu.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef SUNXI_CCU_H +#define SUNXI_CCU_H + +#define SUNXI_CCU_SEC_SWITCH_REG (SUNXI_CCU_BASE + 0x02f0) + +#define SUNXI_R_PRCM_SEC_SWITCH_REG (SUNXI_R_PRCM_BASE + 0x01d0) + +#endif /* SUNXI_CCU_H */ diff --git a/plat/allwinner/sun50i_a64/include/sunxi_mmap.h b/plat/allwinner/sun50i_a64/include/sunxi_mmap.h index db4409118..6c847d39b 100644 --- a/plat/allwinner/sun50i_a64/include/sunxi_mmap.h +++ b/plat/allwinner/sun50i_a64/include/sunxi_mmap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -14,8 +14,8 @@ #define SUNXI_SRAM_SIZE 0x00044000 #define SUNXI_SRAM_A1_BASE 0x00010000 #define SUNXI_SRAM_A1_SIZE 0x00008000 -#define SUNXI_SRAM_A2_BASE 0x00044000 -#define SUNXI_SRAM_A2_SIZE 0x00010000 +#define SUNXI_SRAM_A2_BASE 0x00040000 +#define SUNXI_SRAM_A2_SIZE 0x00014000 #define SUNXI_SRAM_C_BASE 0x00018000 #define SUNXI_SRAM_C_SIZE 0x0001c000 #define SUNXI_DEV_BASE 0x01000000 @@ -36,7 +36,6 @@ #define SUNXI_MSGBOX_BASE 0x01c17000 #define SUNXI_SPINLOCK_BASE 0x01c18000 #define SUNXI_CCU_BASE 0x01c20000 -#define SUNXI_CCU_SEC_SWITCH_REG (SUNXI_CCU_BASE + 0x2f0) #define SUNXI_PIO_BASE 0x01c20800 #define SUNXI_TIMER_BASE 0x01c20c00 #define SUNXI_WDOG_BASE 0x01c20ca0 diff --git a/plat/allwinner/sun50i_a64/include/sunxi_spc.h b/plat/allwinner/sun50i_a64/include/sunxi_spc.h new file mode 100644 index 000000000..5ba7e18fe --- /dev/null +++ b/plat/allwinner/sun50i_a64/include/sunxi_spc.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef SUNXI_SPC_H +#define SUNXI_SPC_H + +#define SUNXI_SPC_NUM_PORTS 6 + +#define SUNXI_SPC_DECPORT_STA_REG(p) (SUNXI_SPC_BASE + 0x0004 + 0x0c * (p)) +#define SUNXI_SPC_DECPORT_SET_REG(p) (SUNXI_SPC_BASE + 0x0008 + 0x0c * (p)) +#define SUNXI_SPC_DECPORT_CLR_REG(p) (SUNXI_SPC_BASE + 0x000c + 0x0c * (p)) + +#endif /* SUNXI_SPC_H */ diff --git a/plat/allwinner/sun50i_a64/sunxi_power.c b/plat/allwinner/sun50i_a64/sunxi_power.c index 5b7d76ae9..80a69c340 100644 --- a/plat/allwinner/sun50i_a64/sunxi_power.c +++ b/plat/allwinner/sun50i_a64/sunxi_power.c @@ -92,21 +92,13 @@ static int rsb_init(void) if (ret) return ret; - /* Start with 400 KHz to issue the I2C->RSB switch command. */ - ret = rsb_set_bus_speed(SUNXI_OSC24M_CLK_IN_HZ, 400000); - if (ret) - return ret; - - /* - * Initiate an I2C transaction to write 0x7c into register 0x3e, - * switching the PMIC to RSB mode. - */ - ret = rsb_set_device_mode(0x7c3e00); + /* Switch to the recommended 3 MHz bus clock. */ + ret = rsb_set_bus_speed(SUNXI_OSC24M_CLK_IN_HZ, 3000000); if (ret) return ret; - /* Now in RSB mode, switch to the recommended 3 MHz. */ - ret = rsb_set_bus_speed(SUNXI_OSC24M_CLK_IN_HZ, 3000000); + /* Initiate an I2C transaction to switch the PMIC to RSB mode. */ + ret = rsb_set_device_mode(AXP20X_MODE_RSB << 16 | AXP20X_MODE_REG << 8); if (ret) return ret; @@ -156,6 +148,11 @@ int sunxi_pmic_setup(uint16_t socid, const void *fdt) pmic = AXP803_RSB; axp_setup_regulators(fdt); + /* Switch the PMIC back to I2C mode. */ + ret = axp_write(AXP20X_MODE_REG, AXP20X_MODE_I2C); + if (ret) + return ret; + break; default: return -ENODEV; diff --git a/plat/allwinner/sun50i_h6/include/sunxi_ccu.h b/plat/allwinner/sun50i_h6/include/sunxi_ccu.h new file mode 100644 index 000000000..85fbb9080 --- /dev/null +++ b/plat/allwinner/sun50i_h6/include/sunxi_ccu.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef SUNXI_CCU_H +#define SUNXI_CCU_H + +#define SUNXI_CCU_SEC_SWITCH_REG (SUNXI_CCU_BASE + 0x0f00) + +#define SUNXI_R_PRCM_SEC_SWITCH_REG (SUNXI_R_PRCM_BASE + 0x0290) + +#endif /* SUNXI_CCU_H */ diff --git a/plat/allwinner/sun50i_h6/include/sunxi_mmap.h b/plat/allwinner/sun50i_h6/include/sunxi_mmap.h index f36491a8a..2d7b09837 100644 --- a/plat/allwinner/sun50i_h6/include/sunxi_mmap.h +++ b/plat/allwinner/sun50i_h6/include/sunxi_mmap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -14,8 +14,8 @@ #define SUNXI_SRAM_SIZE 0x000f8000 #define SUNXI_SRAM_A1_BASE 0x00020000 #define SUNXI_SRAM_A1_SIZE 0x00008000 -#define SUNXI_SRAM_A2_BASE 0x00104000 -#define SUNXI_SRAM_A2_SIZE 0x00014000 +#define SUNXI_SRAM_A2_BASE 0x00100000 +#define SUNXI_SRAM_A2_SIZE 0x00018000 #define SUNXI_SRAM_C_BASE 0x00028000 #define SUNXI_SRAM_C_SIZE 0x0001e000 #define SUNXI_DEV_BASE 0x01000000 @@ -29,9 +29,9 @@ #define SUNXI_SID_BASE 0x03006000 #define SUNXI_DMA_BASE 0x03002000 #define SUNXI_MSGBOX_BASE 0x03003000 -#define SUNXI_CCU_BASE 0x03010000 -#define SUNXI_CCU_SEC_SWITCH_REG (SUNXI_CCU_BASE + 0xf00) -#define SUNXI_PIO_BASE 0x030b0000 +#define SUNXI_CCU_BASE 0x03001000 +#define SUNXI_PIO_BASE 0x0300b000 +#define SUNXI_SPC_BASE 0x03008000 #define SUNXI_TIMER_BASE 0x03009000 #define SUNXI_WDOG_BASE 0x030090a0 #define SUNXI_THS_BASE 0x05070400 @@ -55,6 +55,7 @@ #define SUNXI_R_TWD_BASE 0x07020800 #define SUNXI_R_CPUCFG_BASE 0x07000400 #define SUNXI_R_I2C_BASE 0x07081400 +#define SUNXI_R_RSB_BASE 0x07083000 #define SUNXI_R_UART_BASE 0x07080000 #define SUNXI_R_PIO_BASE 0x07022000 diff --git a/plat/allwinner/sun50i_h6/include/sunxi_spc.h b/plat/allwinner/sun50i_h6/include/sunxi_spc.h new file mode 100644 index 000000000..0f5965bee --- /dev/null +++ b/plat/allwinner/sun50i_h6/include/sunxi_spc.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef SUNXI_SPC_H +#define SUNXI_SPC_H + +#define SUNXI_SPC_NUM_PORTS 14 + +#define SUNXI_SPC_DECPORT_STA_REG(p) (SUNXI_SPC_BASE + 0x0000 + 0x10 * (p)) +#define SUNXI_SPC_DECPORT_SET_REG(p) (SUNXI_SPC_BASE + 0x0004 + 0x10 * (p)) +#define SUNXI_SPC_DECPORT_CLR_REG(p) (SUNXI_SPC_BASE + 0x0008 + 0x10 * (p)) + +#endif /* SUNXI_SPC_H */ diff --git a/plat/allwinner/sun50i_h6/platform.mk b/plat/allwinner/sun50i_h6/platform.mk index 4ecc57cf0..1c98919b1 100644 --- a/plat/allwinner/sun50i_h6/platform.mk +++ b/plat/allwinner/sun50i_h6/platform.mk @@ -8,4 +8,4 @@ include plat/allwinner/common/allwinner-common.mk BL31_SOURCES += drivers/allwinner/axp/axp805.c \ - drivers/mentor/i2c/mi2cv.c + drivers/allwinner/sunxi_rsb.c diff --git a/plat/allwinner/sun50i_h6/sunxi_power.c b/plat/allwinner/sun50i_h6/sunxi_power.c index 443015bac..a7865a5d4 100644 --- a/plat/allwinner/sun50i_h6/sunxi_power.c +++ b/plat/allwinner/sun50i_h6/sunxi_power.c @@ -6,20 +6,17 @@ */ #include <errno.h> -#include <string.h> -#include <arch_helpers.h> #include <common/debug.h> #include <drivers/allwinner/axp.h> -#include <drivers/delay_timer.h> -#include <drivers/mentor/mi2cv.h> -#include <lib/mmio.h> +#include <drivers/allwinner/sunxi_rsb.h> #include <sunxi_def.h> #include <sunxi_mmap.h> #include <sunxi_private.h> -#define AXP805_ADDR 0x36 +#define AXP805_HW_ADDR 0x745 +#define AXP805_RT_ADDR 0x3a static enum pmic_type { UNKNOWN, @@ -28,67 +25,67 @@ static enum pmic_type { int axp_read(uint8_t reg) { - uint8_t val; - int ret; - - ret = i2c_write(AXP805_ADDR, 0, 0, ®, 1); - if (ret == 0) - ret = i2c_read(AXP805_ADDR, 0, 0, &val, 1); - if (ret) { - ERROR("PMIC: Cannot read AXP805 register %02x\n", reg); - return ret; - } - - return val; + return rsb_read(AXP805_RT_ADDR, reg); } int axp_write(uint8_t reg, uint8_t val) { - int ret; - - ret = i2c_write(AXP805_ADDR, reg, 1, &val, 1); - if (ret) - ERROR("PMIC: Cannot write AXP805 register %02x\n", reg); - - return ret; + return rsb_write(AXP805_RT_ADDR, reg, val); } -static int axp805_probe(void) +static int rsb_init(void) { int ret; - /* Switch the AXP805 to master/single-PMIC mode. */ - ret = axp_write(0xff, 0x0); + ret = rsb_init_controller(); if (ret) return ret; - ret = axp_check_id(); + /* Switch to the recommended 3 MHz bus clock. */ + ret = rsb_set_bus_speed(SUNXI_OSC24M_CLK_IN_HZ, 3000000); if (ret) return ret; - return 0; + /* Initiate an I2C transaction to switch the PMIC to RSB mode. */ + ret = rsb_set_device_mode(AXP20X_MODE_RSB << 16 | AXP20X_MODE_REG << 8); + if (ret) + return ret; + + /* Associate the 8-bit runtime address with the 12-bit bus address. */ + ret = rsb_assign_runtime_address(AXP805_HW_ADDR, AXP805_RT_ADDR); + if (ret) + return ret; + + return axp_check_id(); } int sunxi_pmic_setup(uint16_t socid, const void *fdt) { int ret; - INFO("PMIC: Probing AXP805 on I2C\n"); + INFO("PMIC: Probing AXP805 on RSB\n"); - ret = sunxi_init_platform_r_twi(SUNXI_SOC_H6, false); + ret = sunxi_init_platform_r_twi(socid, true); if (ret) return ret; - /* initialise mi2cv driver */ - i2c_init((void *)SUNXI_R_I2C_BASE); + ret = rsb_init(); + if (ret) + return ret; - ret = axp805_probe(); + /* Switch the AXP805 to master/single-PMIC mode. */ + ret = axp_write(0xff, 0x0); if (ret) return ret; pmic = AXP805; axp_setup_regulators(fdt); + /* Switch the PMIC back to I2C mode. */ + ret = axp_write(AXP20X_MODE_REG, AXP20X_MODE_I2C); + if (ret) + return ret; + return 0; } @@ -96,10 +93,9 @@ void sunxi_power_down(void) { switch (pmic) { case AXP805: - /* Re-initialise after rich OS might have used it. */ - sunxi_init_platform_r_twi(SUNXI_SOC_H6, false); - /* initialise mi2cv driver */ - i2c_init((void *)SUNXI_R_I2C_BASE); + /* (Re-)init RSB in case the rich OS has disabled it. */ + sunxi_init_platform_r_twi(SUNXI_SOC_H6, true); + rsb_init(); axp_power_off(); break; default: |