aboutsummaryrefslogtreecommitdiff
path: root/arch/arm/mach-hs/hotplug.c
blob: c67f8a22a890fdf38d56c4e9b27d3af45dc24280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
78
79
80
81
82
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Copyright (c) 2013 Linaro Ltd.
 * Copyright (c) 2013 Hisilicon Limited.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 */
#include <linux/cpu.h>
#include <linux/io.h>
#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <asm/cacheflush.h>
#include <asm/smp_plat.h>
#include "core.h"

enum {
	HI3620_CTRL,
	HI3716_CTRL,
};

static void __iomem *ctrl_base;
static int id;

void hs_set_cpu(int cpu, bool enable)
{
	u32 val = 0;

	if (!ctrl_base)
		return;

	if (id == HI3620_CTRL) {
		if (enable) {
			/* MTCMOS */
			writel_relaxed((0x01 << (cpu + 3)), ctrl_base + 0xD0);
			writel_relaxed((0x1011 << cpu), ctrl_base + 0x414);
			writel_relaxed((0x401011 << cpu), ctrl_base + 0x410);

			/* ISO disable */
			writel((0x01 << (cpu + 3)), ctrl_base + 0x0C4);

			/* WFI Mask */
			val = readl(ctrl_base + 0x200);
			val &= ~(0x1 << (cpu+28));
			writel(val, ctrl_base + 0x200);

			/* Enable core */
			writel_relaxed((0x01 << cpu), ctrl_base + 0xf4);
			/* Unreset */
			writel_relaxed((0x401011 << cpu), ctrl_base + 0x414);
		} else {
			/* iso enable */
			writel_relaxed((0x01 << (cpu + 3)), ctrl_base + 0xC0);

			/* MTCMOS */
			writel_relaxed((0x01 << (cpu + 3)), ctrl_base + 0xD4);

			/* wfi mask */
			val = readl_relaxed(ctrl_base + 0x200);
			val |= (0x1 << (cpu+28));
			writel_relaxed(val, ctrl_base + 0x200);

			/* disable core*/
			writel_relaxed((0x01 << cpu), ctrl_base + 0xf8);
			/* Reset */
			writel_relaxed((0x401011 << cpu), ctrl_base + 0x410);
		}
	} else if (id == HI3716_CTRL) {
		if (enable) {
			/* power on cpu1 */
			val = readl_relaxed(ctrl_base + 0x1000);
			val &=  ~(0x1 << 8);
			val |= (0x1 << 7);
			val &= ~(0x1 << 3);
			writel_relaxed(val, ctrl_base + 0x1000);

			/* unreset */
			val = readl_relaxed(ctrl_base + 0x50);
			val &= ~(0x1 << 17);
			writel_relaxed(val, ctrl_base + 0x50);
		} else {
			/* power down cpu1 */
			val = readl_relaxed(ctrl_base + 0x1000);
			val &=  ~(0x1 << 8);
			val |= (0x1 << 7);
			val |= (0x1 << 3);
			writel_relaxed(val, ctrl_base + 0x1000);

			/* reset */
			val = readl_relaxed(ctrl_base + 0x50);
			val |= (0x1 << 17);
			writel_relaxed(val, ctrl_base + 0x50);
		}
	}
}

void __init hs_hotplug_init(void)
{
	struct device_node *node;

	node = of_find_compatible_node(NULL, NULL, "hisilicon,cpuctrl");
	if (node) {
		ctrl_base = of_iomap(node, 0);
		id = HI3716_CTRL;
		return;
	}
	node = of_find_compatible_node(NULL, NULL, "hisilicon,sctrl");
	if (node) {
		ctrl_base = of_iomap(node, 0);
		id = HI3620_CTRL;
		return;
	}
}

static inline void cpu_enter_lowpower(void)
{
	unsigned int v;

	flush_cache_all();
	asm volatile(
	/*
	 * Turn off coherency and L1 D-cache
	 */
	"	mrc	p15, 0, %0, c1, c0, 1\n"
	"	bic	%0, %0, #0x40\n"
	"	mcr	p15, 0, %0, c1, c0, 1\n"
	"	mrc	p15, 0, %0, c1, c0, 0\n"
	"	bic	%0, %0, #0x04\n"
	"	mcr	p15, 0, %0, c1, c0, 0\n"
	  : "=&r" (v)
	  : "r" (0)
	  : "cc");
}

void hs_cpu_die(unsigned int cpu)
{
	cpu_enter_lowpower();
	hs_set_cpu_jump(cpu, phys_to_virt(0));
	cpu_do_idle();

	/* We should have never returned from idle */
	panic("cpu %d unexpectedly exit from shutdown\n", cpu);
}

int hs_cpu_kill(unsigned int cpu)
{
	unsigned long timeout = jiffies + msecs_to_jiffies(50);

	while (hs_get_cpu_jump(cpu))
		if (time_after(jiffies, timeout))
			return 0;
	hs_set_cpu(cpu, false);
	return 1;
}