2 * SMP support for Allwinner SoCs
4 * Copyright (C) 2013 Maxime Ripard
6 * Maxime Ripard <maxime.ripard@free-electrons.com>
9 * Copyright (C) 2012-2013 Allwinner Ltd.
11 * This file is licensed under the terms of the GNU General Public
12 * License version 2. This program is licensed "as is" without any
13 * warranty of any kind, whether express or implied.
16 #include <linux/delay.h>
17 #include <linux/init.h>
19 #include <linux/memory.h>
21 #include <linux/of_address.h>
22 #include <linux/smp.h>
26 #define CPUCFG_CPU_PWR_CLAMP_STATUS_REG(cpu) ((cpu) * 0x40 + 0x64)
27 #define CPUCFG_CPU_RST_CTRL_REG(cpu) (((cpu) + 1) * 0x40)
28 #define CPUCFG_CPU_CTRL_REG(cpu) (((cpu) + 1) * 0x40 + 0x04)
29 #define CPUCFG_CPU_STATUS_REG(cpu) (((cpu) + 1) * 0x40 + 0x08)
30 #define CPUCFG_GEN_CTRL_REG 0x184
31 #define CPUCFG_PRIVATE0_REG 0x1a4
32 #define CPUCFG_PRIVATE1_REG 0x1a8
33 #define CPUCFG_DBG_CTL0_REG 0x1e0
34 #define CPUCFG_DBG_CTL1_REG 0x1e4
36 #define PRCM_CPU_PWROFF_REG 0x100
37 #define PRCM_CPU_PWR_CLAMP_REG(cpu) (((cpu) * 4) + 0x140)
39 static void __iomem
*cpucfg_membase
;
40 static void __iomem
*prcm_membase
;
42 static DEFINE_SPINLOCK(cpu_lock
);
44 static void __init
sun6i_smp_prepare_cpus(unsigned int max_cpus
)
46 struct device_node
*node
;
48 node
= of_find_compatible_node(NULL
, NULL
, "allwinner,sun6i-a31-prcm");
50 pr_err("Missing A31 PRCM node in the device tree\n");
54 prcm_membase
= of_iomap(node
, 0);
56 pr_err("Couldn't map A31 PRCM registers\n");
60 node
= of_find_compatible_node(NULL
, NULL
,
61 "allwinner,sun6i-a31-cpuconfig");
63 pr_err("Missing A31 CPU config node in the device tree\n");
67 cpucfg_membase
= of_iomap(node
, 0);
69 pr_err("Couldn't map A31 CPU config registers\n");
73 static int sun6i_smp_boot_secondary(unsigned int cpu
,
74 struct task_struct
*idle
)
79 if (!(prcm_membase
&& cpucfg_membase
))
84 /* Set CPU boot address */
85 writel(virt_to_phys(sun6i_secondary_startup
),
86 cpucfg_membase
+ CPUCFG_PRIVATE0_REG
);
88 /* Assert the CPU core in reset */
89 writel(0, cpucfg_membase
+ CPUCFG_CPU_RST_CTRL_REG(cpu
));
91 /* Assert the L1 cache in reset */
92 reg
= readl(cpucfg_membase
+ CPUCFG_GEN_CTRL_REG
);
93 writel(reg
& ~BIT(cpu
), cpucfg_membase
+ CPUCFG_GEN_CTRL_REG
);
95 /* Disable external debug access */
96 reg
= readl(cpucfg_membase
+ CPUCFG_DBG_CTL1_REG
);
97 writel(reg
& ~BIT(cpu
), cpucfg_membase
+ CPUCFG_DBG_CTL1_REG
);
99 /* Power up the CPU */
100 for (i
= 0; i
<= 8; i
++)
101 writel(0xff >> i
, prcm_membase
+ PRCM_CPU_PWR_CLAMP_REG(cpu
));
104 /* Clear CPU power-off gating */
105 reg
= readl(prcm_membase
+ PRCM_CPU_PWROFF_REG
);
106 writel(reg
& ~BIT(cpu
), prcm_membase
+ PRCM_CPU_PWROFF_REG
);
109 /* Deassert the CPU core reset */
110 writel(3, cpucfg_membase
+ CPUCFG_CPU_RST_CTRL_REG(cpu
));
112 /* Enable back the external debug accesses */
113 reg
= readl(cpucfg_membase
+ CPUCFG_DBG_CTL1_REG
);
114 writel(reg
| BIT(cpu
), cpucfg_membase
+ CPUCFG_DBG_CTL1_REG
);
116 spin_unlock(&cpu_lock
);
121 struct smp_operations sun6i_smp_ops __initdata
= {
122 .smp_prepare_cpus
= sun6i_smp_prepare_cpus
,
123 .smp_boot_secondary
= sun6i_smp_boot_secondary
,