1340848b1SWang Dongsheng/* 2340848b1SWang Dongsheng * Copyright 2015 Freescale Semiconductor, Inc. 3340848b1SWang Dongsheng * Author: Wang Dongsheng <dongsheng.wang@freescale.com> 4340848b1SWang Dongsheng * 5340848b1SWang Dongsheng * SPDX-License-Identifier: GPL-2.0+ 6340848b1SWang Dongsheng */ 7340848b1SWang Dongsheng 8340848b1SWang Dongsheng#include <config.h> 9340848b1SWang Dongsheng#include <linux/linkage.h> 10340848b1SWang Dongsheng 11340848b1SWang Dongsheng#include <asm/armv7.h> 12340848b1SWang Dongsheng#include <asm/arch-armv7/generictimer.h> 13340848b1SWang Dongsheng#include <asm/psci.h> 14340848b1SWang Dongsheng 15aeb901f2SHongbo Zhang#define RCPM_TWAITSR 0x04C 16aeb901f2SHongbo Zhang 17340848b1SWang Dongsheng#define SCFG_CORE0_SFT_RST 0x130 18340848b1SWang Dongsheng#define SCFG_CORESRENCR 0x204 19340848b1SWang Dongsheng 20aeb901f2SHongbo Zhang#define DCFG_CCSR_RSTCR 0x0B0 21aeb901f2SHongbo Zhang#define DCFG_CCSR_RSTCR_RESET_REQ 0x2 22340848b1SWang Dongsheng#define DCFG_CCSR_BRR 0x0E4 23340848b1SWang Dongsheng#define DCFG_CCSR_SCRATCHRW1 0x200 24340848b1SWang Dongsheng 25aeb901f2SHongbo Zhang#define PSCI_FN_PSCI_VERSION_FEATURE_MASK 0x0 26aeb901f2SHongbo Zhang#define PSCI_FN_CPU_SUSPEND_FEATURE_MASK 0x0 27aeb901f2SHongbo Zhang#define PSCI_FN_CPU_OFF_FEATURE_MASK 0x0 28aeb901f2SHongbo Zhang#define PSCI_FN_CPU_ON_FEATURE_MASK 0x0 29aeb901f2SHongbo Zhang#define PSCI_FN_AFFINITY_INFO_FEATURE_MASK 0x0 30aeb901f2SHongbo Zhang#define PSCI_FN_SYSTEM_OFF_FEATURE_MASK 0x0 31aeb901f2SHongbo Zhang#define PSCI_FN_SYSTEM_RESET_FEATURE_MASK 0x0 32214ffae0SHongbo Zhang#define PSCI_FN_SYSTEM_SUSPEND_FEATURE_MASK 0x0 33aeb901f2SHongbo Zhang 34340848b1SWang Dongsheng .pushsection ._secure.text, "ax" 35340848b1SWang Dongsheng 36340848b1SWang Dongsheng .arch_extension sec 37340848b1SWang Dongsheng 38aeb901f2SHongbo Zhang .align 5 39aeb901f2SHongbo Zhang 40*4d24e5f1SAndre Przywara#define ONE_MS (COUNTER_FREQUENCY / 1000) 41340848b1SWang Dongsheng#define RESET_WAIT (30 * ONE_MS) 42340848b1SWang Dongsheng 43aeb901f2SHongbo Zhang.globl psci_version 44aeb901f2SHongbo Zhangpsci_version: 45aeb901f2SHongbo Zhang movw r0, #0 46aeb901f2SHongbo Zhang movt r0, #1 47aeb901f2SHongbo Zhang 48aeb901f2SHongbo Zhang bx lr 49aeb901f2SHongbo Zhang 50aeb901f2SHongbo Zhang_ls102x_psci_supported_table: 51aeb901f2SHongbo Zhang .word ARM_PSCI_0_2_FN_PSCI_VERSION 52aeb901f2SHongbo Zhang .word PSCI_FN_PSCI_VERSION_FEATURE_MASK 53aeb901f2SHongbo Zhang .word ARM_PSCI_0_2_FN_CPU_SUSPEND 54aeb901f2SHongbo Zhang .word PSCI_FN_CPU_SUSPEND_FEATURE_MASK 55aeb901f2SHongbo Zhang .word ARM_PSCI_0_2_FN_CPU_OFF 56aeb901f2SHongbo Zhang .word PSCI_FN_CPU_OFF_FEATURE_MASK 57aeb901f2SHongbo Zhang .word ARM_PSCI_0_2_FN_CPU_ON 58aeb901f2SHongbo Zhang .word PSCI_FN_CPU_ON_FEATURE_MASK 59aeb901f2SHongbo Zhang .word ARM_PSCI_0_2_FN_AFFINITY_INFO 60aeb901f2SHongbo Zhang .word PSCI_FN_AFFINITY_INFO_FEATURE_MASK 61aeb901f2SHongbo Zhang .word ARM_PSCI_0_2_FN_SYSTEM_OFF 62aeb901f2SHongbo Zhang .word PSCI_FN_SYSTEM_OFF_FEATURE_MASK 63aeb901f2SHongbo Zhang .word ARM_PSCI_0_2_FN_SYSTEM_RESET 64aeb901f2SHongbo Zhang .word PSCI_FN_SYSTEM_RESET_FEATURE_MASK 65214ffae0SHongbo Zhang .word ARM_PSCI_1_0_FN_SYSTEM_SUSPEND 66214ffae0SHongbo Zhang .word PSCI_FN_SYSTEM_SUSPEND_FEATURE_MASK 67aeb901f2SHongbo Zhang .word 0 68aeb901f2SHongbo Zhang .word ARM_PSCI_RET_NI 69aeb901f2SHongbo Zhang 70aeb901f2SHongbo Zhang.globl psci_features 71aeb901f2SHongbo Zhangpsci_features: 72aeb901f2SHongbo Zhang adr r2, _ls102x_psci_supported_table 73aeb901f2SHongbo Zhang1: ldr r3, [r2] 74aeb901f2SHongbo Zhang cmp r3, #0 75aeb901f2SHongbo Zhang beq out_psci_features 76aeb901f2SHongbo Zhang cmp r1, r3 77aeb901f2SHongbo Zhang addne r2, r2, #8 78aeb901f2SHongbo Zhang bne 1b 79aeb901f2SHongbo Zhang 80aeb901f2SHongbo Zhangout_psci_features: 81aeb901f2SHongbo Zhang ldr r0, [r2, #4] 82aeb901f2SHongbo Zhang bx lr 83aeb901f2SHongbo Zhang 847e742c27SHongbo Zhang@ r0: return value ARM_PSCI_RET_SUCCESS or ARM_PSCI_RET_INVAL 857e742c27SHongbo Zhang@ r1: input target CPU ID in MPIDR format, original value in r1 may be dropped 867e742c27SHongbo Zhang@ r4: output validated CPU ID if ARM_PSCI_RET_SUCCESS returns, meaningless for 877e742c27SHongbo Zhang@ ARM_PSCI_RET_INVAL,suppose caller saves r4 before calling 887e742c27SHongbo ZhangLENTRY(psci_check_target_cpu_id) 897e742c27SHongbo Zhang @ Get the real CPU number 907e742c27SHongbo Zhang and r4, r1, #0xff 917e742c27SHongbo Zhang mov r0, #ARM_PSCI_RET_INVAL 927e742c27SHongbo Zhang 937e742c27SHongbo Zhang @ Bit[31:24], bits must be zero. 947e742c27SHongbo Zhang tst r1, #0xff000000 957e742c27SHongbo Zhang bxne lr 967e742c27SHongbo Zhang 977e742c27SHongbo Zhang @ Affinity level 2 - Cluster: only one cluster in LS1021xa. 987e742c27SHongbo Zhang tst r1, #0xff0000 997e742c27SHongbo Zhang bxne lr 1007e742c27SHongbo Zhang 1017e742c27SHongbo Zhang @ Affinity level 1 - Processors: should be in 0xf00 format. 1027e742c27SHongbo Zhang lsr r1, r1, #8 1037e742c27SHongbo Zhang teq r1, #0xf 1047e742c27SHongbo Zhang bxne lr 1057e742c27SHongbo Zhang 1067e742c27SHongbo Zhang @ Affinity level 0 - CPU: only 0, 1 are valid in LS1021xa. 1077e742c27SHongbo Zhang cmp r4, #2 1087e742c27SHongbo Zhang bxge lr 1097e742c27SHongbo Zhang 1107e742c27SHongbo Zhang mov r0, #ARM_PSCI_RET_SUCCESS 1117e742c27SHongbo Zhang bx lr 1127e742c27SHongbo ZhangENDPROC(psci_check_target_cpu_id) 1137e742c27SHongbo Zhang 114340848b1SWang Dongsheng @ r1 = target CPU 115340848b1SWang Dongsheng @ r2 = target PC 116340848b1SWang Dongsheng.globl psci_cpu_on 117340848b1SWang Dongshengpsci_cpu_on: 1186e6622deSChen-Yu Tsai push {r4, r5, r6, lr} 119340848b1SWang Dongsheng 120340848b1SWang Dongsheng @ Clear and Get the correct CPU number 121340848b1SWang Dongsheng @ r1 = 0xf01 1227e742c27SHongbo Zhang bl psci_check_target_cpu_id 1237e742c27SHongbo Zhang cmp r0, #ARM_PSCI_RET_INVAL 1247e742c27SHongbo Zhang beq out_psci_cpu_on 125340848b1SWang Dongsheng 1266e6622deSChen-Yu Tsai mov r0, r4 1276e6622deSChen-Yu Tsai mov r1, r2 1286e6622deSChen-Yu Tsai bl psci_save_target_pc 1296e6622deSChen-Yu Tsai mov r1, r4 130340848b1SWang Dongsheng 131340848b1SWang Dongsheng @ Get DCFG base address 132340848b1SWang Dongsheng movw r4, #(CONFIG_SYS_FSL_GUTS_ADDR & 0xffff) 133340848b1SWang Dongsheng movt r4, #(CONFIG_SYS_FSL_GUTS_ADDR >> 16) 134340848b1SWang Dongsheng 135340848b1SWang Dongsheng @ Detect target CPU state 136340848b1SWang Dongsheng ldr r2, [r4, #DCFG_CCSR_BRR] 137340848b1SWang Dongsheng rev r2, r2 138340848b1SWang Dongsheng lsr r2, r2, r1 139340848b1SWang Dongsheng ands r2, r2, #1 140340848b1SWang Dongsheng beq holdoff_release 141340848b1SWang Dongsheng 142340848b1SWang Dongsheng @ Reset target CPU 143340848b1SWang Dongsheng @ Get SCFG base address 144340848b1SWang Dongsheng movw r0, #(CONFIG_SYS_FSL_SCFG_ADDR & 0xffff) 145340848b1SWang Dongsheng movt r0, #(CONFIG_SYS_FSL_SCFG_ADDR >> 16) 146340848b1SWang Dongsheng 147340848b1SWang Dongsheng @ Enable CORE Soft Reset 148340848b1SWang Dongsheng movw r5, #0 149340848b1SWang Dongsheng movt r5, #(1 << 15) 150340848b1SWang Dongsheng rev r5, r5 151340848b1SWang Dongsheng str r5, [r0, #SCFG_CORESRENCR] 152340848b1SWang Dongsheng 153340848b1SWang Dongsheng @ Get CPUx offset register 154340848b1SWang Dongsheng mov r6, #0x4 155340848b1SWang Dongsheng mul r6, r6, r1 156340848b1SWang Dongsheng add r2, r0, r6 157340848b1SWang Dongsheng 158340848b1SWang Dongsheng @ Do reset on target CPU 159340848b1SWang Dongsheng movw r5, #0 160340848b1SWang Dongsheng movt r5, #(1 << 15) 161340848b1SWang Dongsheng rev r5, r5 162340848b1SWang Dongsheng str r5, [r2, #SCFG_CORE0_SFT_RST] 163340848b1SWang Dongsheng 164340848b1SWang Dongsheng @ Wait target CPU up 165340848b1SWang Dongsheng timer_wait r2, RESET_WAIT 166340848b1SWang Dongsheng 167340848b1SWang Dongsheng @ Disable CORE soft reset 168340848b1SWang Dongsheng mov r5, #0 169340848b1SWang Dongsheng str r5, [r0, #SCFG_CORESRENCR] 170340848b1SWang Dongsheng 171340848b1SWang Dongshengholdoff_release: 172340848b1SWang Dongsheng @ Release on target CPU 173340848b1SWang Dongsheng ldr r2, [r4, #DCFG_CCSR_BRR] 174340848b1SWang Dongsheng mov r6, #1 175340848b1SWang Dongsheng lsl r6, r6, r1 @ 32 bytes per CPU 176340848b1SWang Dongsheng 177340848b1SWang Dongsheng rev r6, r6 178340848b1SWang Dongsheng orr r2, r2, r6 179340848b1SWang Dongsheng str r2, [r4, #DCFG_CCSR_BRR] 180340848b1SWang Dongsheng 181340848b1SWang Dongsheng @ Set secondary boot entry 182340848b1SWang Dongsheng ldr r6, =psci_cpu_entry 183340848b1SWang Dongsheng rev r6, r6 184340848b1SWang Dongsheng str r6, [r4, #DCFG_CCSR_SCRATCHRW1] 185340848b1SWang Dongsheng 186340848b1SWang Dongsheng isb 187340848b1SWang Dongsheng dsb 188340848b1SWang Dongsheng 189340848b1SWang Dongsheng @ Return 190340848b1SWang Dongsheng mov r0, #ARM_PSCI_RET_SUCCESS 191340848b1SWang Dongsheng 1927e742c27SHongbo Zhangout_psci_cpu_on: 1936e6622deSChen-Yu Tsai pop {r4, r5, r6, lr} 194340848b1SWang Dongsheng bx lr 195340848b1SWang Dongsheng 196340848b1SWang Dongsheng.globl psci_cpu_off 197340848b1SWang Dongshengpsci_cpu_off: 198340848b1SWang Dongsheng bl psci_cpu_off_common 199340848b1SWang Dongsheng 200340848b1SWang Dongsheng1: wfi 201340848b1SWang Dongsheng b 1b 202340848b1SWang Dongsheng 203aeb901f2SHongbo Zhang.globl psci_affinity_info 204aeb901f2SHongbo Zhangpsci_affinity_info: 205aeb901f2SHongbo Zhang push {lr} 206aeb901f2SHongbo Zhang 207aeb901f2SHongbo Zhang mov r0, #ARM_PSCI_RET_INVAL 208aeb901f2SHongbo Zhang 209aeb901f2SHongbo Zhang @ Verify Affinity level 210aeb901f2SHongbo Zhang cmp r2, #0 211aeb901f2SHongbo Zhang bne out_affinity_info 212aeb901f2SHongbo Zhang 213aeb901f2SHongbo Zhang bl psci_check_target_cpu_id 214aeb901f2SHongbo Zhang cmp r0, #ARM_PSCI_RET_INVAL 215aeb901f2SHongbo Zhang beq out_affinity_info 216aeb901f2SHongbo Zhang mov r1, r4 217aeb901f2SHongbo Zhang 218aeb901f2SHongbo Zhang @ Get RCPM base address 219aeb901f2SHongbo Zhang movw r4, #(CONFIG_SYS_FSL_RCPM_ADDR & 0xffff) 220aeb901f2SHongbo Zhang movt r4, #(CONFIG_SYS_FSL_RCPM_ADDR >> 16) 221aeb901f2SHongbo Zhang 222aeb901f2SHongbo Zhang mov r0, #PSCI_AFFINITY_LEVEL_ON 223aeb901f2SHongbo Zhang 224aeb901f2SHongbo Zhang @ Detect target CPU state 225aeb901f2SHongbo Zhang ldr r2, [r4, #RCPM_TWAITSR] 226aeb901f2SHongbo Zhang rev r2, r2 227aeb901f2SHongbo Zhang lsr r2, r2, r1 228aeb901f2SHongbo Zhang ands r2, r2, #1 229aeb901f2SHongbo Zhang beq out_affinity_info 230aeb901f2SHongbo Zhang 231aeb901f2SHongbo Zhang mov r0, #PSCI_AFFINITY_LEVEL_OFF 232aeb901f2SHongbo Zhang 233aeb901f2SHongbo Zhangout_affinity_info: 234aeb901f2SHongbo Zhang pop {pc} 235aeb901f2SHongbo Zhang 236aeb901f2SHongbo Zhang.globl psci_system_reset 237aeb901f2SHongbo Zhangpsci_system_reset: 238aeb901f2SHongbo Zhang @ Get DCFG base address 239aeb901f2SHongbo Zhang movw r1, #(CONFIG_SYS_FSL_GUTS_ADDR & 0xffff) 240aeb901f2SHongbo Zhang movt r1, #(CONFIG_SYS_FSL_GUTS_ADDR >> 16) 241aeb901f2SHongbo Zhang 242aeb901f2SHongbo Zhang mov r2, #DCFG_CCSR_RSTCR_RESET_REQ 243aeb901f2SHongbo Zhang rev r2, r2 244aeb901f2SHongbo Zhang str r2, [r1, #DCFG_CCSR_RSTCR] 245aeb901f2SHongbo Zhang 246aeb901f2SHongbo Zhang1: wfi 247aeb901f2SHongbo Zhang b 1b 248aeb901f2SHongbo Zhang 249214ffae0SHongbo Zhang.globl psci_system_suspend 250214ffae0SHongbo Zhangpsci_system_suspend: 251214ffae0SHongbo Zhang push {lr} 252214ffae0SHongbo Zhang 253214ffae0SHongbo Zhang bl ls1_system_suspend 254214ffae0SHongbo Zhang 255214ffae0SHongbo Zhang pop {pc} 256214ffae0SHongbo Zhang 257340848b1SWang Dongsheng .popsection 258