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