blob: 420b507abe014a16f05d542471e38ed1419cd948 [file] [log] [blame]
Samuel Holland321c0ab2017-08-12 04:07:39 -05001/*
Samuel Holland91bcab92021-01-24 06:37:29 -06002 * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved.
Samuel Holland321c0ab2017-08-12 04:07:39 -05003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Andre Przywara6d0b81b2018-09-28 00:43:32 +01007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Samuel Holland321c0ab2017-08-12 04:07:39 -05009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <arch_helpers.h>
12#include <common/debug.h>
13#include <drivers/delay_timer.h>
14#include <lib/mmio.h>
15#include <lib/utils_def.h>
16#include <plat/common/platform.h>
17
Samuel Holland321c0ab2017-08-12 04:07:39 -050018#include <sunxi_cpucfg.h>
Andre Przywara6d0b81b2018-09-28 00:43:32 +010019#include <sunxi_mmap.h>
Andre Przywara456208a2018-10-14 12:02:02 +010020#include <sunxi_private.h>
Samuel Holland321c0ab2017-08-12 04:07:39 -050021
Samuel Holland321c0ab2017-08-12 04:07:39 -050022static void sunxi_cpu_disable_power(unsigned int cluster, unsigned int core)
23{
24 if (mmio_read_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core)) == 0xff)
25 return;
26
Andre Przywara8501d092018-06-22 01:33:34 +010027 VERBOSE("PSCI: Disabling power to cluster %d core %d\n", cluster, core);
Samuel Holland321c0ab2017-08-12 04:07:39 -050028
29 mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xff);
30}
31
32static void sunxi_cpu_enable_power(unsigned int cluster, unsigned int core)
33{
34 if (mmio_read_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core)) == 0)
35 return;
36
Andre Przywara8501d092018-06-22 01:33:34 +010037 VERBOSE("PSCI: Enabling power to cluster %d core %d\n", cluster, core);
Samuel Holland321c0ab2017-08-12 04:07:39 -050038
39 /* Power enable sequence from original Allwinner sources */
40 mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xfe);
41 mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xf8);
42 mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xe0);
43 mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0x80);
44 mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0x00);
45}
46
Samuel Holland91bcab92021-01-24 06:37:29 -060047/* We can't turn ourself off like this, but it works for other cores. */
48static void sunxi_cpu_off(u_register_t mpidr)
Samuel Holland321c0ab2017-08-12 04:07:39 -050049{
Samuel Hollandc629daf2019-02-17 15:33:33 -060050 unsigned int cluster = MPIDR_AFFLVL1_VAL(mpidr);
51 unsigned int core = MPIDR_AFFLVL0_VAL(mpidr);
Andre Przywara6d0b81b2018-09-28 00:43:32 +010052
Andre Przywara8501d092018-06-22 01:33:34 +010053 VERBOSE("PSCI: Powering off cluster %d core %d\n", cluster, core);
Samuel Holland321c0ab2017-08-12 04:07:39 -050054
55 /* Deassert DBGPWRDUP */
56 mmio_clrbits_32(SUNXI_CPUCFG_DBG_REG0, BIT(core));
Samuel Holland91bcab92021-01-24 06:37:29 -060057 /* Activate the core output clamps, but not for core 0. */
58 if (core != 0)
59 mmio_setbits_32(SUNXI_POWEROFF_GATING_REG(cluster), BIT(core));
60 /* Assert CPU power-on reset */
61 mmio_clrbits_32(SUNXI_POWERON_RST_REG(cluster), BIT(core));
62 /* Remove power from the CPU */
63 sunxi_cpu_disable_power(cluster, core);
64}
Andre Przywara6d0b81b2018-09-28 00:43:32 +010065
Samuel Hollandc629daf2019-02-17 15:33:33 -060066void sunxi_cpu_on(u_register_t mpidr)
Samuel Holland321c0ab2017-08-12 04:07:39 -050067{
Samuel Hollandc629daf2019-02-17 15:33:33 -060068 unsigned int cluster = MPIDR_AFFLVL1_VAL(mpidr);
69 unsigned int core = MPIDR_AFFLVL0_VAL(mpidr);
70
Andre Przywara8501d092018-06-22 01:33:34 +010071 VERBOSE("PSCI: Powering on cluster %d core %d\n", cluster, core);
Samuel Holland321c0ab2017-08-12 04:07:39 -050072
73 /* Assert CPU core reset */
74 mmio_clrbits_32(SUNXI_CPUCFG_RST_CTRL_REG(cluster), BIT(core));
75 /* Assert CPU power-on reset */
76 mmio_clrbits_32(SUNXI_POWERON_RST_REG(cluster), BIT(core));
77 /* Set CPU to start in AArch64 mode */
78 mmio_setbits_32(SUNXI_CPUCFG_CLS_CTRL_REG0(cluster), BIT(24 + core));
79 /* Apply power to the CPU */
80 sunxi_cpu_enable_power(cluster, core);
81 /* Release the core output clamps */
82 mmio_clrbits_32(SUNXI_POWEROFF_GATING_REG(cluster), BIT(core));
83 /* Deassert CPU power-on reset */
84 mmio_setbits_32(SUNXI_POWERON_RST_REG(cluster), BIT(core));
85 /* Deassert CPU core reset */
86 mmio_setbits_32(SUNXI_CPUCFG_RST_CTRL_REG(cluster), BIT(core));
87 /* Assert DBGPWRDUP */
88 mmio_setbits_32(SUNXI_CPUCFG_DBG_REG0, BIT(core));
89}
90
Samuel Holland91bcab92021-01-24 06:37:29 -060091void sunxi_cpu_power_off_others(void)
Samuel Holland321c0ab2017-08-12 04:07:39 -050092{
Samuel Holland91bcab92021-01-24 06:37:29 -060093 u_register_t self = read_mpidr();
Samuel Hollandc629daf2019-02-17 15:33:33 -060094 unsigned int cluster;
95 unsigned int core;
96
97 for (cluster = 0; cluster < PLATFORM_CLUSTER_COUNT; ++cluster) {
98 for (core = 0; core < PLATFORM_MAX_CPUS_PER_CLUSTER; ++core) {
99 u_register_t mpidr = (cluster << MPIDR_AFF1_SHIFT) |
100 (core << MPIDR_AFF0_SHIFT) |
101 BIT(31);
Samuel Holland91bcab92021-01-24 06:37:29 -0600102 if (mpidr != self)
Samuel Hollandc629daf2019-02-17 15:33:33 -0600103 sunxi_cpu_off(mpidr);
104 }
Samuel Holland321c0ab2017-08-12 04:07:39 -0500105 }
106}