blob: b26be89c787b4f7578f416fb50f988cb291ddbfb [file] [log] [blame]
Peng Fand8c75bc2017-08-17 17:48:50 +08001/*
2 * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
3 * Copyright 2017 NXP
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
Peng Fanfcd53ce2015-10-23 10:13:04 +08008#include <asm/io.h>
9#include <asm/psci.h>
Chen-Yu Tsai7ca14502016-06-19 12:38:41 +080010#include <asm/secure.h>
Peng Fanfcd53ce2015-10-23 10:13:04 +080011#include <asm/arch/imx-regs.h>
12#include <common.h>
Anson Huangf20bc132018-01-07 14:34:31 +080013#include <fsl_wdog.h>
Peng Fanfcd53ce2015-10-23 10:13:04 +080014
15#define GPC_CPU_PGC_SW_PDN_REQ 0xfc
16#define GPC_CPU_PGC_SW_PUP_REQ 0xf0
17#define GPC_PGC_C1 0x840
18
19#define BM_CPU_PGC_SW_PDN_PUP_REQ_CORE1_A7 0x2
20
21/* below is for i.MX7D */
22#define SRC_GPR1_MX7D 0x074
23#define SRC_A7RCR0 0x004
24#define SRC_A7RCR1 0x008
25
26#define BP_SRC_A7RCR0_A7_CORE_RESET0 0
27#define BP_SRC_A7RCR1_A7_CORE1_ENABLE 1
28
Anson Huangf20bc132018-01-07 14:34:31 +080029#define CCM_ROOT_WDOG 0xbb80
30#define CCM_CCGR_WDOG1 0x49c0
31
Peng Fanfcd53ce2015-10-23 10:13:04 +080032static inline void imx_gpcv2_set_m_core_pgc(bool enable, u32 offset)
33{
34 writel(enable, GPC_IPS_BASE_ADDR + offset);
35}
36
37__secure void imx_gpcv2_set_core1_power(bool pdn)
38{
39 u32 reg = pdn ? GPC_CPU_PGC_SW_PUP_REQ : GPC_CPU_PGC_SW_PDN_REQ;
40 u32 val;
41
42 imx_gpcv2_set_m_core_pgc(true, GPC_PGC_C1);
43
44 val = readl(GPC_IPS_BASE_ADDR + reg);
45 val |= BM_CPU_PGC_SW_PDN_PUP_REQ_CORE1_A7;
46 writel(val, GPC_IPS_BASE_ADDR + reg);
47
48 while ((readl(GPC_IPS_BASE_ADDR + reg) &
49 BM_CPU_PGC_SW_PDN_PUP_REQ_CORE1_A7) != 0)
50 ;
51
52 imx_gpcv2_set_m_core_pgc(false, GPC_PGC_C1);
53}
54
55__secure void imx_enable_cpu_ca7(int cpu, bool enable)
56{
57 u32 mask, val;
58
59 mask = 1 << (BP_SRC_A7RCR1_A7_CORE1_ENABLE + cpu - 1);
60 val = readl(SRC_BASE_ADDR + SRC_A7RCR1);
61 val = enable ? val | mask : val & ~mask;
62 writel(val, SRC_BASE_ADDR + SRC_A7RCR1);
63}
64
65__secure int imx_cpu_on(int fn, int cpu, int pc)
66{
67 writel(pc, SRC_BASE_ADDR + cpu * 8 + SRC_GPR1_MX7D);
68 imx_gpcv2_set_core1_power(true);
69 imx_enable_cpu_ca7(cpu, true);
70 return 0;
71}
72
73__secure int imx_cpu_off(int cpu)
74{
75 imx_enable_cpu_ca7(cpu, false);
76 imx_gpcv2_set_core1_power(false);
77 writel(0, SRC_BASE_ADDR + cpu * 8 + SRC_GPR1_MX7D + 4);
78 return 0;
79}
Anson Huangf20bc132018-01-07 14:34:31 +080080
81__secure void imx_system_reset(void)
82{
83 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
84
85 /* make sure WDOG1 clock is enabled */
86 writel(0x1 << 28, CCM_BASE_ADDR + CCM_ROOT_WDOG);
87 writel(0x3, CCM_BASE_ADDR + CCM_CCGR_WDOG1);
88 writew(WCR_WDE, &wdog->wcr);
89}