create branch for barrier breaker (from trunk r41863)
[14.07/openwrt.git] / target / linux / sunxi / patches-3.13 / 108-sun6i-add-smp-support.patch
1 From 6f5002c91f35f6b171bc608b87b3f2b55451f32b Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime.ripard@free-electrons.com>
3 Date: Sun, 3 Nov 2013 10:30:13 +0100
4 Subject: [PATCH] ARM: sun6i: Add SMP support for the Allwinner A31
5
6 The A31 is a quad Cortex-A7. Add the logic to use the IPs used to
7 control the CPU configuration and the CPU power so that we can bring up
8 secondary CPUs at boot.
9
10 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
11 ---
12  arch/arm/mach-sunxi/Makefile  |   1 +
13  arch/arm/mach-sunxi/common.h  |  19 +++++++
14  arch/arm/mach-sunxi/headsmp.S |   9 +++
15  arch/arm/mach-sunxi/platsmp.c | 124 ++++++++++++++++++++++++++++++++++++++++++
16  arch/arm/mach-sunxi/sunxi.c   |   3 +
17  5 files changed, 156 insertions(+)
18  create mode 100644 arch/arm/mach-sunxi/common.h
19  create mode 100644 arch/arm/mach-sunxi/headsmp.S
20  create mode 100644 arch/arm/mach-sunxi/platsmp.c
21
22 --- a/arch/arm/mach-sunxi/Makefile
23 +++ b/arch/arm/mach-sunxi/Makefile
24 @@ -1 +1,2 @@
25  obj-$(CONFIG_ARCH_SUNXI) += sunxi.o
26 +obj-$(CONFIG_SMP) += platsmp.o headsmp.o
27 --- /dev/null
28 +++ b/arch/arm/mach-sunxi/common.h
29 @@ -0,0 +1,19 @@
30 +/*
31 + * Core functions for Allwinner SoCs
32 + *
33 + * Copyright (C) 2013 Maxime Ripard
34 + *
35 + * Maxime Ripard <maxime.ripard@free-electrons.com>
36 + *
37 + * This file is licensed under the terms of the GNU General Public
38 + * License version 2.  This program is licensed "as is" without any
39 + * warranty of any kind, whether express or implied.
40 + */
41 +
42 +#ifndef __ARCH_SUNXI_COMMON_H_
43 +#define __ARCH_SUNXI_COMMON_H_
44 +
45 +void sun6i_secondary_startup(void);
46 +extern struct smp_operations sun6i_smp_ops;
47 +
48 +#endif /* __ARCH_SUNXI_COMMON_H_ */
49 --- /dev/null
50 +++ b/arch/arm/mach-sunxi/headsmp.S
51 @@ -0,0 +1,9 @@
52 +#include <linux/linkage.h>
53 +#include <linux/init.h>
54 +
55 +        .section ".text.head", "ax"
56 +
57 +ENTRY(sun6i_secondary_startup)
58 +       msr     cpsr_fsxc, #0xd3
59 +       b       secondary_startup
60 +ENDPROC(sun6i_secondary_startup)
61 --- /dev/null
62 +++ b/arch/arm/mach-sunxi/platsmp.c
63 @@ -0,0 +1,124 @@
64 +/*
65 + * SMP support for Allwinner SoCs
66 + *
67 + * Copyright (C) 2013 Maxime Ripard
68 + *
69 + * Maxime Ripard <maxime.ripard@free-electrons.com>
70 + *
71 + * Based on code
72 + *  Copyright (C) 2012-2013 Allwinner Ltd.
73 + *
74 + * This file is licensed under the terms of the GNU General Public
75 + * License version 2.  This program is licensed "as is" without any
76 + * warranty of any kind, whether express or implied.
77 + */
78 +
79 +#include <linux/delay.h>
80 +#include <linux/init.h>
81 +#include <linux/io.h>
82 +#include <linux/memory.h>
83 +#include <linux/of.h>
84 +#include <linux/of_address.h>
85 +#include <linux/smp.h>
86 +
87 +#include "common.h"
88 +
89 +#define CPUCFG_CPU_PWR_CLAMP_STATUS_REG(cpu)   ((cpu) * 0x40 + 0x64)
90 +#define CPUCFG_CPU_RST_CTRL_REG(cpu)           (((cpu) + 1) * 0x40)
91 +#define CPUCFG_CPU_CTRL_REG(cpu)               (((cpu) + 1) * 0x40 + 0x04)
92 +#define CPUCFG_CPU_STATUS_REG(cpu)             (((cpu) + 1) * 0x40 + 0x08)
93 +#define CPUCFG_GEN_CTRL_REG                    0x184
94 +#define CPUCFG_PRIVATE0_REG                    0x1a4
95 +#define CPUCFG_PRIVATE1_REG                    0x1a8
96 +#define CPUCFG_DBG_CTL0_REG                    0x1e0
97 +#define CPUCFG_DBG_CTL1_REG                    0x1e4
98 +
99 +#define PRCM_CPU_PWROFF_REG                    0x100
100 +#define PRCM_CPU_PWR_CLAMP_REG(cpu)            (((cpu) * 4) + 0x140)
101 +
102 +static void __iomem *cpucfg_membase;
103 +static void __iomem *prcm_membase;
104 +
105 +static DEFINE_SPINLOCK(cpu_lock);
106 +
107 +static void __init sun6i_smp_prepare_cpus(unsigned int max_cpus)
108 +{
109 +       struct device_node *node;
110 +
111 +       node = of_find_compatible_node(NULL, NULL, "allwinner,sun6i-a31-prcm");
112 +       if (!node) {
113 +               pr_err("Missing A31 PRCM node in the device tree\n");
114 +               return;
115 +       }
116 +
117 +       prcm_membase = of_iomap(node, 0);
118 +       if (!prcm_membase) {
119 +               pr_err("Couldn't map A31 PRCM registers\n");
120 +               return;
121 +       }
122 +
123 +       node = of_find_compatible_node(NULL, NULL,
124 +                                      "allwinner,sun6i-a31-cpuconfig");
125 +       if (!node) {
126 +               pr_err("Missing A31 CPU config node in the device tree\n");
127 +               return;
128 +       }
129 +
130 +       cpucfg_membase = of_iomap(node, 0);
131 +       if (!cpucfg_membase)
132 +               pr_err("Couldn't map A31 CPU config registers\n");
133 +
134 +}
135 +
136 +static int sun6i_smp_boot_secondary(unsigned int cpu,
137 +                                   struct task_struct *idle)
138 +{
139 +       u32 reg;
140 +       int i;
141 +
142 +       if (!(prcm_membase && cpucfg_membase))
143 +               return -EFAULT;
144 +
145 +       spin_lock(&cpu_lock);
146 +
147 +       /* Set CPU boot address */
148 +       writel(virt_to_phys(sun6i_secondary_startup),
149 +              cpucfg_membase + CPUCFG_PRIVATE0_REG);
150 +
151 +       /* Assert the CPU core in reset */
152 +       writel(0, cpucfg_membase + CPUCFG_CPU_RST_CTRL_REG(cpu));
153 +
154 +       /* Assert the L1 cache in reset */
155 +       reg = readl(cpucfg_membase + CPUCFG_GEN_CTRL_REG);
156 +       writel(reg & ~BIT(cpu), cpucfg_membase + CPUCFG_GEN_CTRL_REG);
157 +
158 +       /* Disable external debug access */
159 +       reg = readl(cpucfg_membase + CPUCFG_DBG_CTL1_REG);
160 +       writel(reg & ~BIT(cpu), cpucfg_membase + CPUCFG_DBG_CTL1_REG);
161 +
162 +       /* Power up the CPU */
163 +       for (i = 0; i <= 8; i++)
164 +               writel(0xff >> i, prcm_membase + PRCM_CPU_PWR_CLAMP_REG(cpu));
165 +       mdelay(10);
166 +
167 +       /* Clear CPU power-off gating */
168 +       reg = readl(prcm_membase + PRCM_CPU_PWROFF_REG);
169 +       writel(reg & ~BIT(cpu), prcm_membase + PRCM_CPU_PWROFF_REG);
170 +       mdelay(1);
171 +
172 +       /* Deassert the CPU core reset */
173 +       writel(3, cpucfg_membase + CPUCFG_CPU_RST_CTRL_REG(cpu));
174 +
175 +       /* Enable back the external debug accesses */
176 +       reg = readl(cpucfg_membase + CPUCFG_DBG_CTL1_REG);
177 +       writel(reg | BIT(cpu), cpucfg_membase + CPUCFG_DBG_CTL1_REG);
178 +
179 +       spin_unlock(&cpu_lock);
180 +
181 +       return 0;
182 +}
183 +
184 +struct smp_operations sun6i_smp_ops __initdata = {
185 +       .smp_prepare_cpus       = sun6i_smp_prepare_cpus,
186 +       .smp_boot_secondary     = sun6i_smp_boot_secondary,
187 +};
188 --- a/arch/arm/mach-sunxi/sunxi.c
189 +++ b/arch/arm/mach-sunxi/sunxi.c
190 @@ -25,6 +25,8 @@
191  #include <asm/mach/map.h>
192  #include <asm/system_misc.h>
193  
194 +#include "common.h"
195 +
196  #define SUN4I_WATCHDOG_CTRL_REG                0x00
197  #define SUN4I_WATCHDOG_CTRL_RESTART            BIT(0)
198  #define SUN4I_WATCHDOG_MODE_REG                0x04
199 @@ -147,6 +149,7 @@ DT_MACHINE_START(SUN6I_DT, "Allwinner su
200         .init_time      = sun6i_timer_init,
201         .dt_compat      = sun6i_board_dt_compat,
202         .restart        = sun6i_restart,
203 +       .smp            = smp_ops(sun6i_smp_ops),
204  MACHINE_END
205  
206  static const char * const sun7i_board_dt_compat[] = {