18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2010-2013, NVIDIA Corporation. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __MACH_TEGRA_SLEEP_H 78c2ecf20Sopenharmony_ci#define __MACH_TEGRA_SLEEP_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include "iomap.h" 108c2ecf20Sopenharmony_ci#include "irammap.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define TEGRA_ARM_PERIF_VIRT (TEGRA_ARM_PERIF_BASE - IO_CPU_PHYS \ 138c2ecf20Sopenharmony_ci + IO_CPU_VIRT) 148c2ecf20Sopenharmony_ci#define TEGRA_FLOW_CTRL_VIRT (TEGRA_FLOW_CTRL_BASE - IO_PPSB_PHYS \ 158c2ecf20Sopenharmony_ci + IO_PPSB_VIRT) 168c2ecf20Sopenharmony_ci#define TEGRA_CLK_RESET_VIRT (TEGRA_CLK_RESET_BASE - IO_PPSB_PHYS \ 178c2ecf20Sopenharmony_ci + IO_PPSB_VIRT) 188c2ecf20Sopenharmony_ci#define TEGRA_APB_MISC_VIRT (TEGRA_APB_MISC_BASE - IO_APB_PHYS \ 198c2ecf20Sopenharmony_ci + IO_APB_VIRT) 208c2ecf20Sopenharmony_ci#define TEGRA_PMC_VIRT (TEGRA_PMC_BASE - IO_APB_PHYS + IO_APB_VIRT) 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define TEGRA_IRAM_RESET_BASE_VIRT (IO_IRAM_VIRT + \ 238c2ecf20Sopenharmony_ci TEGRA_IRAM_RESET_HANDLER_OFFSET) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* PMC_SCRATCH37-39 and 41 are used for tegra_pen_lock and idle */ 268c2ecf20Sopenharmony_ci#define PMC_SCRATCH37 0x130 278c2ecf20Sopenharmony_ci#define PMC_SCRATCH38 0x134 288c2ecf20Sopenharmony_ci#define PMC_SCRATCH39 0x138 298c2ecf20Sopenharmony_ci#define PMC_SCRATCH41 0x140 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_2x_SOC 328c2ecf20Sopenharmony_ci#define CPU_RESETTABLE 2 338c2ecf20Sopenharmony_ci#define CPU_RESETTABLE_SOON 1 348c2ecf20Sopenharmony_ci#define CPU_NOT_RESETTABLE 0 358c2ecf20Sopenharmony_ci#endif 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* flag of tegra_disable_clean_inv_dcache to do LoUIS or all */ 388c2ecf20Sopenharmony_ci#define TEGRA_FLUSH_CACHE_LOUIS 0 398c2ecf20Sopenharmony_ci#define TEGRA_FLUSH_CACHE_ALL 1 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#ifdef __ASSEMBLY__ 428c2ecf20Sopenharmony_ci/* waits until the microsecond counter (base) is > rn */ 438c2ecf20Sopenharmony_ci.macro wait_until, rn, base, tmp 448c2ecf20Sopenharmony_ci add \rn, \rn, #1 458c2ecf20Sopenharmony_ci1001: ldr \tmp, [\base] 468c2ecf20Sopenharmony_ci cmp \tmp, \rn 478c2ecf20Sopenharmony_ci bmi 1001b 488c2ecf20Sopenharmony_ci.endm 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* returns the offset of the flow controller halt register for a cpu */ 518c2ecf20Sopenharmony_ci.macro cpu_to_halt_reg rd, rcpu 528c2ecf20Sopenharmony_ci cmp \rcpu, #0 538c2ecf20Sopenharmony_ci subne \rd, \rcpu, #1 548c2ecf20Sopenharmony_ci movne \rd, \rd, lsl #3 558c2ecf20Sopenharmony_ci addne \rd, \rd, #0x14 568c2ecf20Sopenharmony_ci moveq \rd, #0 578c2ecf20Sopenharmony_ci.endm 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* returns the offset of the flow controller csr register for a cpu */ 608c2ecf20Sopenharmony_ci.macro cpu_to_csr_reg rd, rcpu 618c2ecf20Sopenharmony_ci cmp \rcpu, #0 628c2ecf20Sopenharmony_ci subne \rd, \rcpu, #1 638c2ecf20Sopenharmony_ci movne \rd, \rd, lsl #3 648c2ecf20Sopenharmony_ci addne \rd, \rd, #0x18 658c2ecf20Sopenharmony_ci moveq \rd, #8 668c2ecf20Sopenharmony_ci.endm 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* returns the ID of the current processor */ 698c2ecf20Sopenharmony_ci.macro cpu_id, rd 708c2ecf20Sopenharmony_ci mrc p15, 0, \rd, c0, c0, 5 718c2ecf20Sopenharmony_ci and \rd, \rd, #0xF 728c2ecf20Sopenharmony_ci.endm 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* loads a 32-bit value into a register without a data access */ 758c2ecf20Sopenharmony_ci.macro mov32, reg, val 768c2ecf20Sopenharmony_ci movw \reg, #:lower16:\val 778c2ecf20Sopenharmony_ci movt \reg, #:upper16:\val 788c2ecf20Sopenharmony_ci.endm 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* Marco to check CPU part num */ 818c2ecf20Sopenharmony_ci.macro check_cpu_part_num part_num, tmp1, tmp2 828c2ecf20Sopenharmony_ci mrc p15, 0, \tmp1, c0, c0, 0 838c2ecf20Sopenharmony_ci ubfx \tmp1, \tmp1, #4, #12 848c2ecf20Sopenharmony_ci mov32 \tmp2, \part_num 858c2ecf20Sopenharmony_ci cmp \tmp1, \tmp2 868c2ecf20Sopenharmony_ci.endm 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* Macro to exit SMP coherency. */ 898c2ecf20Sopenharmony_ci.macro exit_smp, tmp1, tmp2 908c2ecf20Sopenharmony_ci mrc p15, 0, \tmp1, c1, c0, 1 @ ACTLR 918c2ecf20Sopenharmony_ci bic \tmp1, \tmp1, #(1<<6) | (1<<0) @ clear ACTLR.SMP | ACTLR.FW 928c2ecf20Sopenharmony_ci mcr p15, 0, \tmp1, c1, c0, 1 @ ACTLR 938c2ecf20Sopenharmony_ci isb 948c2ecf20Sopenharmony_ci#ifdef CONFIG_HAVE_ARM_SCU 958c2ecf20Sopenharmony_ci check_cpu_part_num 0xc09, \tmp1, \tmp2 968c2ecf20Sopenharmony_ci mrceq p15, 0, \tmp1, c0, c0, 5 978c2ecf20Sopenharmony_ci andeq \tmp1, \tmp1, #0xF 988c2ecf20Sopenharmony_ci moveq \tmp1, \tmp1, lsl #2 998c2ecf20Sopenharmony_ci moveq \tmp2, #0xf 1008c2ecf20Sopenharmony_ci moveq \tmp2, \tmp2, lsl \tmp1 1018c2ecf20Sopenharmony_ci ldreq \tmp1, =(TEGRA_ARM_PERIF_VIRT + 0xC) 1028c2ecf20Sopenharmony_ci streq \tmp2, [\tmp1] @ invalidate SCU tags for CPU 1038c2ecf20Sopenharmony_ci dsb 1048c2ecf20Sopenharmony_ci#endif 1058c2ecf20Sopenharmony_ci.endm 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/* Macro to check Tegra revision */ 1088c2ecf20Sopenharmony_ci#define APB_MISC_GP_HIDREV 0x804 1098c2ecf20Sopenharmony_ci.macro tegra_get_soc_id base, tmp1 1108c2ecf20Sopenharmony_ci mov32 \tmp1, \base 1118c2ecf20Sopenharmony_ci ldr \tmp1, [\tmp1, #APB_MISC_GP_HIDREV] 1128c2ecf20Sopenharmony_ci and \tmp1, \tmp1, #0xff00 1138c2ecf20Sopenharmony_ci mov \tmp1, \tmp1, lsr #8 1148c2ecf20Sopenharmony_ci.endm 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci#else 1178c2ecf20Sopenharmony_civoid tegra_resume(void); 1188c2ecf20Sopenharmony_ciint tegra_sleep_cpu_finish(unsigned long); 1198c2ecf20Sopenharmony_civoid tegra_disable_clean_inv_dcache(u32 flag); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_civoid tegra20_hotplug_shutdown(void); 1228c2ecf20Sopenharmony_civoid tegra30_hotplug_shutdown(void); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_civoid tegra20_tear_down_cpu(void); 1258c2ecf20Sopenharmony_civoid tegra30_tear_down_cpu(void); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#endif 1288c2ecf20Sopenharmony_ci#endif 129