sunxi_cpu_ops.c 3.48 KB
Newer Older
1
2
3
4
5
6
/*
 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

7
8
9
#include <arch_helpers.h>
#include <assert.h>
#include <core_off_arisc.h>
10
#include <debug.h>
11
#include <delay_timer.h>
12
#include <mmio.h>
13
#include <platform.h>
14
15
#include <platform_def.h>
#include <sunxi_cpucfg.h>
16
#include <sunxi_mmap.h>
17
#include <sunxi_private.h>
18
19
20
21
22
23
24
#include <utils_def.h>

static void sunxi_cpu_disable_power(unsigned int cluster, unsigned int core)
{
	if (mmio_read_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core)) == 0xff)
		return;

25
	VERBOSE("PSCI: Disabling power to cluster %d core %d\n", cluster, core);
26
27
28
29
30
31
32
33
34

	mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xff);
}

static void sunxi_cpu_enable_power(unsigned int cluster, unsigned int core)
{
	if (mmio_read_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core)) == 0)
		return;

35
	VERBOSE("PSCI: Enabling power to cluster %d core %d\n", cluster, core);
36
37
38
39
40
41
42
43
44
45
46

	/* Power enable sequence from original Allwinner sources */
	mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xfe);
	mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xf8);
	mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xe0);
	mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0x80);
	mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0x00);
}

void sunxi_cpu_off(unsigned int cluster, unsigned int core)
{
47
48
	int corenr = cluster * PLATFORM_MAX_CPUS_PER_CLUSTER + core;

49
	VERBOSE("PSCI: Powering off cluster %d core %d\n", cluster, core);
50
51
52

	/* Deassert DBGPWRDUP */
	mmio_clrbits_32(SUNXI_CPUCFG_DBG_REG0, BIT(core));
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

	/* We can't turn ourself off like this, but it works for other cores. */
	if (plat_my_core_pos() != corenr) {
		/* Activate the core output clamps, but not for core 0. */
		if (corenr != 0)
			mmio_setbits_32(SUNXI_POWEROFF_GATING_REG(cluster),
					BIT(core));
		/* Assert CPU power-on reset */
		mmio_clrbits_32(SUNXI_POWERON_RST_REG(cluster), BIT(core));
		/* Remove power from the CPU */
		sunxi_cpu_disable_power(cluster, core);

		return;
	}

	/* Simplifies assembly, all SoCs so far are single cluster anyway. */
	assert(cluster == 0);

	/*
	 * If we are supposed to turn ourself off, tell the arisc SCP
	 * to do that work for us. The code expects the core mask to be
	 * patched into the first instruction.
	 */
	sunxi_execute_arisc_code(arisc_core_off, sizeof(arisc_core_off),
				 0, BIT_32(core));
78
79
80
81
}

void sunxi_cpu_on(unsigned int cluster, unsigned int core)
{
82
	VERBOSE("PSCI: Powering on cluster %d core %d\n", cluster, core);
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

	/* Assert CPU core reset */
	mmio_clrbits_32(SUNXI_CPUCFG_RST_CTRL_REG(cluster), BIT(core));
	/* Assert CPU power-on reset */
	mmio_clrbits_32(SUNXI_POWERON_RST_REG(cluster), BIT(core));
	/* Set CPU to start in AArch64 mode */
	mmio_setbits_32(SUNXI_CPUCFG_CLS_CTRL_REG0(cluster), BIT(24 + core));
	/* Apply power to the CPU */
	sunxi_cpu_enable_power(cluster, core);
	/* Release the core output clamps */
	mmio_clrbits_32(SUNXI_POWEROFF_GATING_REG(cluster), BIT(core));
	/* Deassert CPU power-on reset */
	mmio_setbits_32(SUNXI_POWERON_RST_REG(cluster), BIT(core));
	/* Deassert CPU core reset */
	mmio_setbits_32(SUNXI_CPUCFG_RST_CTRL_REG(cluster), BIT(core));
	/* Assert DBGPWRDUP */
	mmio_setbits_32(SUNXI_CPUCFG_DBG_REG0, BIT(core));
}

void sunxi_disable_secondary_cpus(unsigned int primary_cpu)
{
	for (unsigned int cpu = 0; cpu < PLATFORM_CORE_COUNT; cpu += 1) {
		if (cpu == primary_cpu)
			continue;
		sunxi_cpu_off(cpu / PLATFORM_MAX_CPUS_PER_CLUSTER,
			       cpu % PLATFORM_MAX_CPUS_PER_CLUSTER);
	}
}