blob: f26618b435145d255655b711874e48f9b2851eb0 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Andreas Färber172067e2017-02-26 17:25:21 +01002/*
3 * Actions Semi Leopard
4 *
5 * This file is based on arm realview smp platform.
6 *
7 * Copyright 2012 Actions Semi Inc.
8 * Author: Actions Semi, Inc.
9 *
10 * Copyright (c) 2017 Andreas Färber
Andreas Färber172067e2017-02-26 17:25:21 +010011 */
12
13#include <linux/delay.h>
14#include <linux/io.h>
15#include <linux/of.h>
16#include <linux/of_address.h>
17#include <linux/smp.h>
Andreas Färberb6a0e182017-02-28 01:08:37 +010018#include <linux/soc/actions/owl-sps.h>
Andreas Färber172067e2017-02-26 17:25:21 +010019#include <asm/cacheflush.h>
20#include <asm/smp_plat.h>
21#include <asm/smp_scu.h>
22
23#define OWL_CPU1_ADDR 0x50
24#define OWL_CPU1_FLAG 0x5c
25
26#define OWL_CPUx_FLAG_BOOT 0x55aa
27
Andreas Färberb6a0e182017-02-28 01:08:37 +010028#define OWL_SPS_PG_CTL_PWR_CPU2 BIT(5)
29#define OWL_SPS_PG_CTL_PWR_CPU3 BIT(6)
30#define OWL_SPS_PG_CTL_ACK_CPU2 BIT(21)
31#define OWL_SPS_PG_CTL_ACK_CPU3 BIT(22)
32
Andreas Färber172067e2017-02-26 17:25:21 +010033static void __iomem *scu_base_addr;
Andreas Färberb6a0e182017-02-28 01:08:37 +010034static void __iomem *sps_base_addr;
Andreas Färber172067e2017-02-26 17:25:21 +010035static void __iomem *timer_base_addr;
36static int ncores;
37
Andreas Färber172067e2017-02-26 17:25:21 +010038static int s500_wakeup_secondary(unsigned int cpu)
39{
Andreas Färberb6a0e182017-02-28 01:08:37 +010040 int ret;
41
Andreas Färber172067e2017-02-26 17:25:21 +010042 if (cpu > 3)
43 return -EINVAL;
44
Andreas Färberb6a0e182017-02-28 01:08:37 +010045 /* The generic PM domain driver is not available this early. */
Andreas Färber172067e2017-02-26 17:25:21 +010046 switch (cpu) {
47 case 2:
Andreas Färberb6a0e182017-02-28 01:08:37 +010048 ret = owl_sps_set_pg(sps_base_addr,
49 OWL_SPS_PG_CTL_PWR_CPU2,
50 OWL_SPS_PG_CTL_ACK_CPU2, true);
51 if (ret)
52 return ret;
53 break;
Andreas Färber172067e2017-02-26 17:25:21 +010054 case 3:
Andreas Färberb6a0e182017-02-28 01:08:37 +010055 ret = owl_sps_set_pg(sps_base_addr,
56 OWL_SPS_PG_CTL_PWR_CPU3,
57 OWL_SPS_PG_CTL_ACK_CPU3, true);
58 if (ret)
59 return ret;
60 break;
Andreas Färber172067e2017-02-26 17:25:21 +010061 }
62
63 /* wait for CPUx to run to WFE instruction */
64 udelay(200);
65
Andreas Färber6c2eb3e72017-07-03 19:18:04 +020066 writel(__pa_symbol(secondary_startup),
Andreas Färber172067e2017-02-26 17:25:21 +010067 timer_base_addr + OWL_CPU1_ADDR + (cpu - 1) * 4);
68 writel(OWL_CPUx_FLAG_BOOT,
69 timer_base_addr + OWL_CPU1_FLAG + (cpu - 1) * 4);
70
71 dsb_sev();
72 mb();
73
74 return 0;
75}
76
77static int s500_smp_boot_secondary(unsigned int cpu, struct task_struct *idle)
78{
Andreas Färber172067e2017-02-26 17:25:21 +010079 int ret;
80
81 ret = s500_wakeup_secondary(cpu);
82 if (ret)
83 return ret;
84
85 udelay(10);
86
Andreas Färber172067e2017-02-26 17:25:21 +010087 smp_send_reschedule(cpu);
88
Andreas Färber172067e2017-02-26 17:25:21 +010089 writel(0, timer_base_addr + OWL_CPU1_ADDR + (cpu - 1) * 4);
90 writel(0, timer_base_addr + OWL_CPU1_FLAG + (cpu - 1) * 4);
91
Andreas Färber18cfd942017-07-01 23:29:30 +020092 return 0;
Andreas Färber172067e2017-02-26 17:25:21 +010093}
94
95static void __init s500_smp_prepare_cpus(unsigned int max_cpus)
96{
97 struct device_node *node;
98
99 node = of_find_compatible_node(NULL, NULL, "actions,s500-timer");
100 if (!node) {
101 pr_err("%s: missing timer\n", __func__);
102 return;
103 }
104
105 timer_base_addr = of_iomap(node, 0);
106 if (!timer_base_addr) {
107 pr_err("%s: could not map timer registers\n", __func__);
108 return;
109 }
110
Andreas Färberb6a0e182017-02-28 01:08:37 +0100111 node = of_find_compatible_node(NULL, NULL, "actions,s500-sps");
112 if (!node) {
113 pr_err("%s: missing sps\n", __func__);
114 return;
115 }
116
117 sps_base_addr = of_iomap(node, 0);
118 if (!sps_base_addr) {
119 pr_err("%s: could not map sps registers\n", __func__);
120 return;
121 }
122
Andreas Färber172067e2017-02-26 17:25:21 +0100123 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9) {
124 node = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
125 if (!node) {
126 pr_err("%s: missing scu\n", __func__);
127 return;
128 }
129
130 scu_base_addr = of_iomap(node, 0);
131 if (!scu_base_addr) {
132 pr_err("%s: could not map scu registers\n", __func__);
133 return;
134 }
135
136 /*
137 * While the number of cpus is gathered from dt, also get the
138 * number of cores from the scu to verify this value when
139 * booting the cores.
140 */
141 ncores = scu_get_core_count(scu_base_addr);
142 pr_debug("%s: ncores %d\n", __func__, ncores);
143
144 scu_enable(scu_base_addr);
145 }
146}
147
148static const struct smp_operations s500_smp_ops __initconst = {
149 .smp_prepare_cpus = s500_smp_prepare_cpus,
Andreas Färber172067e2017-02-26 17:25:21 +0100150 .smp_boot_secondary = s500_smp_boot_secondary,
151};
152CPU_METHOD_OF_DECLARE(s500_smp, "actions,s500-smp", &s500_smp_ops);