1347863d4SKrzysztof Kozlowski // SPDX-License-Identifier: GPL-2.0
2347863d4SKrzysztof Kozlowski // Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
3347863d4SKrzysztof Kozlowski // http://www.samsung.com
4347863d4SKrzysztof Kozlowski //
5347863d4SKrzysztof Kozlowski // Cloned from linux/arch/arm/mach-vexpress/platsmp.c
6347863d4SKrzysztof Kozlowski //
7347863d4SKrzysztof Kozlowski // Copyright (C) 2002 ARM Ltd.
8347863d4SKrzysztof Kozlowski // All Rights Reserved
983014579SKukjin Kim
1083014579SKukjin Kim #include <linux/init.h>
1183014579SKukjin Kim #include <linux/errno.h>
1283014579SKukjin Kim #include <linux/delay.h>
1383014579SKukjin Kim #include <linux/jiffies.h>
1483014579SKukjin Kim #include <linux/smp.h>
1583014579SKukjin Kim #include <linux/io.h>
16b3205deaSSachin Kamat #include <linux/of_address.h>
172262d6efSPankaj Dubey #include <linux/soc/samsung/exynos-regs-pmu.h>
1883014579SKukjin Kim
1983014579SKukjin Kim #include <asm/cacheflush.h>
206f0b7c0cSKrzysztof Kozlowski #include <asm/cp15.h>
21eb50439bSWill Deacon #include <asm/smp_plat.h>
2283014579SKukjin Kim #include <asm/smp_scu.h>
23beddf63fSTomasz Figa #include <asm/firmware.h>
2483014579SKukjin Kim
2506853ae4SMarc Zyngier #include "common.h"
2606853ae4SMarc Zyngier
2783014579SKukjin Kim extern void exynos4_secondary_startup(void);
2883014579SKukjin Kim
296213f70eSRussell King /* XXX exynos_pen_release is cargo culted code - DO NOT COPY XXX */
306213f70eSRussell King volatile int exynos_pen_release = -1;
316213f70eSRussell King
326f0b7c0cSKrzysztof Kozlowski #ifdef CONFIG_HOTPLUG_CPU
cpu_leave_lowpower(u32 core_id)3313cfa6c4SKrzysztof Kozlowski static inline void cpu_leave_lowpower(u32 core_id)
346f0b7c0cSKrzysztof Kozlowski {
356f0b7c0cSKrzysztof Kozlowski unsigned int v;
366f0b7c0cSKrzysztof Kozlowski
376f0b7c0cSKrzysztof Kozlowski asm volatile(
386f0b7c0cSKrzysztof Kozlowski "mrc p15, 0, %0, c1, c0, 0\n"
396f0b7c0cSKrzysztof Kozlowski " orr %0, %0, %1\n"
406f0b7c0cSKrzysztof Kozlowski " mcr p15, 0, %0, c1, c0, 0\n"
416f0b7c0cSKrzysztof Kozlowski " mrc p15, 0, %0, c1, c0, 1\n"
426f0b7c0cSKrzysztof Kozlowski " orr %0, %0, %2\n"
436f0b7c0cSKrzysztof Kozlowski " mcr p15, 0, %0, c1, c0, 1\n"
446f0b7c0cSKrzysztof Kozlowski : "=&r" (v)
456f0b7c0cSKrzysztof Kozlowski : "Ir" (CR_C), "Ir" (0x40)
466f0b7c0cSKrzysztof Kozlowski : "cc");
476f0b7c0cSKrzysztof Kozlowski }
486f0b7c0cSKrzysztof Kozlowski
platform_do_lowpower(unsigned int cpu,int * spurious)496f0b7c0cSKrzysztof Kozlowski static inline void platform_do_lowpower(unsigned int cpu, int *spurious)
506f0b7c0cSKrzysztof Kozlowski {
516f0b7c0cSKrzysztof Kozlowski u32 mpidr = cpu_logical_map(cpu);
526f0b7c0cSKrzysztof Kozlowski u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
536f0b7c0cSKrzysztof Kozlowski
546f0b7c0cSKrzysztof Kozlowski for (;;) {
556f0b7c0cSKrzysztof Kozlowski
566f0b7c0cSKrzysztof Kozlowski /* Turn the CPU off on next WFI instruction. */
576f0b7c0cSKrzysztof Kozlowski exynos_cpu_power_down(core_id);
586f0b7c0cSKrzysztof Kozlowski
596f0b7c0cSKrzysztof Kozlowski wfi();
606f0b7c0cSKrzysztof Kozlowski
616213f70eSRussell King if (exynos_pen_release == core_id) {
626f0b7c0cSKrzysztof Kozlowski /*
636f0b7c0cSKrzysztof Kozlowski * OK, proper wakeup, we're done
646f0b7c0cSKrzysztof Kozlowski */
656f0b7c0cSKrzysztof Kozlowski break;
666f0b7c0cSKrzysztof Kozlowski }
676f0b7c0cSKrzysztof Kozlowski
686f0b7c0cSKrzysztof Kozlowski /*
696f0b7c0cSKrzysztof Kozlowski * Getting here, means that we have come out of WFI without
706f0b7c0cSKrzysztof Kozlowski * having been woken up - this shouldn't happen
716f0b7c0cSKrzysztof Kozlowski *
726f0b7c0cSKrzysztof Kozlowski * Just note it happening - when we're woken, we can report
736f0b7c0cSKrzysztof Kozlowski * its occurrence.
746f0b7c0cSKrzysztof Kozlowski */
756f0b7c0cSKrzysztof Kozlowski (*spurious)++;
766f0b7c0cSKrzysztof Kozlowski }
776f0b7c0cSKrzysztof Kozlowski }
786f0b7c0cSKrzysztof Kozlowski #endif /* CONFIG_HOTPLUG_CPU */
796f0b7c0cSKrzysztof Kozlowski
807310d99fSKrzysztof Kozlowski /**
81*60310087SKrzysztof Kozlowski * exynos_cpu_power_down() - power down the specified cpu
827310d99fSKrzysztof Kozlowski * @cpu: the cpu to power down
837310d99fSKrzysztof Kozlowski *
847310d99fSKrzysztof Kozlowski * Power down the specified cpu. The sequence must be finished by a
857310d99fSKrzysztof Kozlowski * call to cpu_do_idle()
867310d99fSKrzysztof Kozlowski */
exynos_cpu_power_down(int cpu)877310d99fSKrzysztof Kozlowski void exynos_cpu_power_down(int cpu)
887310d99fSKrzysztof Kozlowski {
89497ab3b3SBartlomiej Zolnierkiewicz u32 core_conf;
90497ab3b3SBartlomiej Zolnierkiewicz
91ca489c58SKrzysztof Kozlowski if (cpu == 0 && (soc_is_exynos5420() || soc_is_exynos5800())) {
92adc548d7SAbhilash Kesavan /*
93adc548d7SAbhilash Kesavan * Bypass power down for CPU0 during suspend. Check for
94adc548d7SAbhilash Kesavan * the SYS_PWR_REG value to decide if we are suspending
95adc548d7SAbhilash Kesavan * the system.
96adc548d7SAbhilash Kesavan */
97adc548d7SAbhilash Kesavan int val = pmu_raw_readl(EXYNOS5_ARM_CORE0_SYS_PWR_REG);
98adc548d7SAbhilash Kesavan
99adc548d7SAbhilash Kesavan if (!(val & S5P_CORE_LOCAL_PWR_EN))
100adc548d7SAbhilash Kesavan return;
101adc548d7SAbhilash Kesavan }
102497ab3b3SBartlomiej Zolnierkiewicz
103497ab3b3SBartlomiej Zolnierkiewicz core_conf = pmu_raw_readl(EXYNOS_ARM_CORE_CONFIGURATION(cpu));
104497ab3b3SBartlomiej Zolnierkiewicz core_conf &= ~S5P_CORE_LOCAL_PWR_EN;
105497ab3b3SBartlomiej Zolnierkiewicz pmu_raw_writel(core_conf, EXYNOS_ARM_CORE_CONFIGURATION(cpu));
1067310d99fSKrzysztof Kozlowski }
1077310d99fSKrzysztof Kozlowski
1087310d99fSKrzysztof Kozlowski /**
109*60310087SKrzysztof Kozlowski * exynos_cpu_power_up() - power up the specified cpu
1107310d99fSKrzysztof Kozlowski * @cpu: the cpu to power up
1117310d99fSKrzysztof Kozlowski *
1127310d99fSKrzysztof Kozlowski * Power up the specified cpu
1137310d99fSKrzysztof Kozlowski */
exynos_cpu_power_up(int cpu)1147310d99fSKrzysztof Kozlowski void exynos_cpu_power_up(int cpu)
1157310d99fSKrzysztof Kozlowski {
116497ab3b3SBartlomiej Zolnierkiewicz u32 core_conf = S5P_CORE_LOCAL_PWR_EN;
117497ab3b3SBartlomiej Zolnierkiewicz
118497ab3b3SBartlomiej Zolnierkiewicz if (soc_is_exynos3250())
119497ab3b3SBartlomiej Zolnierkiewicz core_conf |= S5P_CORE_AUTOWAKEUP_EN;
120497ab3b3SBartlomiej Zolnierkiewicz
121497ab3b3SBartlomiej Zolnierkiewicz pmu_raw_writel(core_conf,
1227310d99fSKrzysztof Kozlowski EXYNOS_ARM_CORE_CONFIGURATION(cpu));
1237310d99fSKrzysztof Kozlowski }
1247310d99fSKrzysztof Kozlowski
1257310d99fSKrzysztof Kozlowski /**
126*60310087SKrzysztof Kozlowski * exynos_cpu_power_state() - returns the power state of the cpu
1277310d99fSKrzysztof Kozlowski * @cpu: the cpu to retrieve the power state from
1287310d99fSKrzysztof Kozlowski */
exynos_cpu_power_state(int cpu)1297310d99fSKrzysztof Kozlowski int exynos_cpu_power_state(int cpu)
1307310d99fSKrzysztof Kozlowski {
131944483d0SArnd Bergmann return (pmu_raw_readl(EXYNOS_ARM_CORE_STATUS(cpu)) &
1327310d99fSKrzysztof Kozlowski S5P_CORE_LOCAL_PWR_EN);
1337310d99fSKrzysztof Kozlowski }
1347310d99fSKrzysztof Kozlowski
1357310d99fSKrzysztof Kozlowski /**
136*60310087SKrzysztof Kozlowski * exynos_cluster_power_down() - power down the specified cluster
1377310d99fSKrzysztof Kozlowski * @cluster: the cluster to power down
1387310d99fSKrzysztof Kozlowski */
exynos_cluster_power_down(int cluster)1397310d99fSKrzysztof Kozlowski void exynos_cluster_power_down(int cluster)
1407310d99fSKrzysztof Kozlowski {
141944483d0SArnd Bergmann pmu_raw_writel(0, EXYNOS_COMMON_CONFIGURATION(cluster));
1427310d99fSKrzysztof Kozlowski }
1437310d99fSKrzysztof Kozlowski
1447310d99fSKrzysztof Kozlowski /**
145*60310087SKrzysztof Kozlowski * exynos_cluster_power_up() - power up the specified cluster
1467310d99fSKrzysztof Kozlowski * @cluster: the cluster to power up
1477310d99fSKrzysztof Kozlowski */
exynos_cluster_power_up(int cluster)1487310d99fSKrzysztof Kozlowski void exynos_cluster_power_up(int cluster)
1497310d99fSKrzysztof Kozlowski {
150944483d0SArnd Bergmann pmu_raw_writel(S5P_CORE_LOCAL_PWR_EN,
1517310d99fSKrzysztof Kozlowski EXYNOS_COMMON_CONFIGURATION(cluster));
1527310d99fSKrzysztof Kozlowski }
1537310d99fSKrzysztof Kozlowski
1547310d99fSKrzysztof Kozlowski /**
155*60310087SKrzysztof Kozlowski * exynos_cluster_power_state() - returns the power state of the cluster
1567310d99fSKrzysztof Kozlowski * @cluster: the cluster to retrieve the power state from
1577310d99fSKrzysztof Kozlowski *
1587310d99fSKrzysztof Kozlowski */
exynos_cluster_power_state(int cluster)1597310d99fSKrzysztof Kozlowski int exynos_cluster_power_state(int cluster)
1607310d99fSKrzysztof Kozlowski {
161944483d0SArnd Bergmann return (pmu_raw_readl(EXYNOS_COMMON_STATUS(cluster)) &
1627310d99fSKrzysztof Kozlowski S5P_CORE_LOCAL_PWR_EN);
1637310d99fSKrzysztof Kozlowski }
1647310d99fSKrzysztof Kozlowski
1653c33710bSPankaj Dubey /**
166*60310087SKrzysztof Kozlowski * exynos_scu_enable() - enables SCU for Cortex-A9 based system
1673c33710bSPankaj Dubey */
exynos_scu_enable(void)1683c33710bSPankaj Dubey void exynos_scu_enable(void)
1693c33710bSPankaj Dubey {
1703c33710bSPankaj Dubey struct device_node *np;
1713c33710bSPankaj Dubey static void __iomem *scu_base;
1723c33710bSPankaj Dubey
1733c33710bSPankaj Dubey if (!scu_base) {
1743c33710bSPankaj Dubey np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
1753c33710bSPankaj Dubey if (np) {
1763c33710bSPankaj Dubey scu_base = of_iomap(np, 0);
1773c33710bSPankaj Dubey of_node_put(np);
1783c33710bSPankaj Dubey } else {
1793c33710bSPankaj Dubey scu_base = ioremap(scu_a9_get_base(), SZ_4K);
1803c33710bSPankaj Dubey }
1813c33710bSPankaj Dubey }
1823c33710bSPankaj Dubey scu_enable(scu_base);
1833c33710bSPankaj Dubey }
1843c33710bSPankaj Dubey
cpu_boot_reg_base(void)185af997114SBartlomiej Zolnierkiewicz static void __iomem *cpu_boot_reg_base(void)
1861f054f52STomasz Figa {
187edaff7e1SArnd Bergmann if (soc_is_exynos4210() && exynos_rev() == EXYNOS4210_REV_1_1)
1882e94ac42SPankaj Dubey return pmu_base_addr + S5P_INFORM5;
189b3205deaSSachin Kamat return sysram_base_addr;
1901f054f52STomasz Figa }
1911f054f52STomasz Figa
cpu_boot_reg(int cpu)1921f054f52STomasz Figa static inline void __iomem *cpu_boot_reg(int cpu)
1931f054f52STomasz Figa {
1941f054f52STomasz Figa void __iomem *boot_reg;
1951f054f52STomasz Figa
1961f054f52STomasz Figa boot_reg = cpu_boot_reg_base();
197b3205deaSSachin Kamat if (!boot_reg)
1982cc6b813SKrzysztof Kozlowski return IOMEM_ERR_PTR(-ENODEV);
1991f054f52STomasz Figa if (soc_is_exynos4412())
2001f054f52STomasz Figa boot_reg += 4*cpu;
20186c6f148SArun Kumar K else if (soc_is_exynos5420() || soc_is_exynos5800())
2021580be3dSChander Kashyap boot_reg += 4;
2031f054f52STomasz Figa return boot_reg;
2041f054f52STomasz Figa }
20583014579SKukjin Kim
20683014579SKukjin Kim /*
207b588aaecSKrzysztof Kozlowski * Set wake up by local power mode and execute software reset for given core.
208b588aaecSKrzysztof Kozlowski *
209b588aaecSKrzysztof Kozlowski * Currently this is needed only when booting secondary CPU on Exynos3250.
210b588aaecSKrzysztof Kozlowski */
exynos_core_restart(u32 core_id)211af997114SBartlomiej Zolnierkiewicz void exynos_core_restart(u32 core_id)
212b588aaecSKrzysztof Kozlowski {
21398a3308eSMarek Szyprowski unsigned int timeout = 16;
214b588aaecSKrzysztof Kozlowski u32 val;
215b588aaecSKrzysztof Kozlowski
216970f6cf2SMarek Szyprowski if (!soc_is_exynos3250())
217b588aaecSKrzysztof Kozlowski return;
218b588aaecSKrzysztof Kozlowski
21998a3308eSMarek Szyprowski while (timeout && !pmu_raw_readl(S5P_PMU_SPARE2)) {
22098a3308eSMarek Szyprowski timeout--;
221497ab3b3SBartlomiej Zolnierkiewicz udelay(10);
22298a3308eSMarek Szyprowski }
22398a3308eSMarek Szyprowski if (timeout == 0) {
22498a3308eSMarek Szyprowski pr_err("cpu core %u restart failed\n", core_id);
22598a3308eSMarek Szyprowski return;
22698a3308eSMarek Szyprowski }
227497ab3b3SBartlomiej Zolnierkiewicz udelay(10);
228497ab3b3SBartlomiej Zolnierkiewicz
229b588aaecSKrzysztof Kozlowski val = pmu_raw_readl(EXYNOS_ARM_CORE_STATUS(core_id));
230b588aaecSKrzysztof Kozlowski val |= S5P_CORE_WAKEUP_FROM_LOCAL_CFG;
231b588aaecSKrzysztof Kozlowski pmu_raw_writel(val, EXYNOS_ARM_CORE_STATUS(core_id));
232b588aaecSKrzysztof Kozlowski
233b588aaecSKrzysztof Kozlowski pmu_raw_writel(EXYNOS_CORE_PO_RESET(core_id), EXYNOS_SWRESET);
234b588aaecSKrzysztof Kozlowski }
235b588aaecSKrzysztof Kozlowski
236b588aaecSKrzysztof Kozlowski /*
2376213f70eSRussell King * XXX CARGO CULTED CODE - DO NOT COPY XXX
2386213f70eSRussell King *
2396213f70eSRussell King * Write exynos_pen_release in a way that is guaranteed to be visible to
2406213f70eSRussell King * all observers, irrespective of whether they're taking part in coherency
24183014579SKukjin Kim * or not. This is necessary for the hotplug code to work reliably.
24283014579SKukjin Kim */
exynos_write_pen_release(int val)2436213f70eSRussell King static void exynos_write_pen_release(int val)
24483014579SKukjin Kim {
2456213f70eSRussell King exynos_pen_release = val;
24683014579SKukjin Kim smp_wmb();
2476213f70eSRussell King sync_cache_w(&exynos_pen_release);
24883014579SKukjin Kim }
24983014579SKukjin Kim
25083014579SKukjin Kim static DEFINE_SPINLOCK(boot_lock);
25183014579SKukjin Kim
exynos_secondary_init(unsigned int cpu)2528bd26e3aSPaul Gortmaker static void exynos_secondary_init(unsigned int cpu)
25383014579SKukjin Kim {
25483014579SKukjin Kim /*
25583014579SKukjin Kim * let the primary processor know we're out of the
25683014579SKukjin Kim * pen, then head off into the C entry point
25783014579SKukjin Kim */
2586213f70eSRussell King exynos_write_pen_release(-1);
25983014579SKukjin Kim
26083014579SKukjin Kim /*
26183014579SKukjin Kim * Synchronise with the boot thread.
26283014579SKukjin Kim */
26383014579SKukjin Kim spin_lock(&boot_lock);
26483014579SKukjin Kim spin_unlock(&boot_lock);
26583014579SKukjin Kim }
26683014579SKukjin Kim
exynos_set_boot_addr(u32 core_id,unsigned long boot_addr)267af997114SBartlomiej Zolnierkiewicz int exynos_set_boot_addr(u32 core_id, unsigned long boot_addr)
268955d4cf8SBartlomiej Zolnierkiewicz {
269955d4cf8SBartlomiej Zolnierkiewicz int ret;
270955d4cf8SBartlomiej Zolnierkiewicz
271955d4cf8SBartlomiej Zolnierkiewicz /*
272955d4cf8SBartlomiej Zolnierkiewicz * Try to set boot address using firmware first
273955d4cf8SBartlomiej Zolnierkiewicz * and fall back to boot register if it fails.
274955d4cf8SBartlomiej Zolnierkiewicz */
275955d4cf8SBartlomiej Zolnierkiewicz ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
276955d4cf8SBartlomiej Zolnierkiewicz if (ret && ret != -ENOSYS)
277955d4cf8SBartlomiej Zolnierkiewicz goto fail;
278955d4cf8SBartlomiej Zolnierkiewicz if (ret == -ENOSYS) {
279955d4cf8SBartlomiej Zolnierkiewicz void __iomem *boot_reg = cpu_boot_reg(core_id);
280955d4cf8SBartlomiej Zolnierkiewicz
281955d4cf8SBartlomiej Zolnierkiewicz if (IS_ERR(boot_reg)) {
282955d4cf8SBartlomiej Zolnierkiewicz ret = PTR_ERR(boot_reg);
283955d4cf8SBartlomiej Zolnierkiewicz goto fail;
284955d4cf8SBartlomiej Zolnierkiewicz }
285458ad21dSBen Dooks writel_relaxed(boot_addr, boot_reg);
286955d4cf8SBartlomiej Zolnierkiewicz ret = 0;
287955d4cf8SBartlomiej Zolnierkiewicz }
288955d4cf8SBartlomiej Zolnierkiewicz fail:
289955d4cf8SBartlomiej Zolnierkiewicz return ret;
290955d4cf8SBartlomiej Zolnierkiewicz }
291955d4cf8SBartlomiej Zolnierkiewicz
exynos_get_boot_addr(u32 core_id,unsigned long * boot_addr)292af997114SBartlomiej Zolnierkiewicz int exynos_get_boot_addr(u32 core_id, unsigned long *boot_addr)
2931225ad72SBartlomiej Zolnierkiewicz {
2941225ad72SBartlomiej Zolnierkiewicz int ret;
2951225ad72SBartlomiej Zolnierkiewicz
2961225ad72SBartlomiej Zolnierkiewicz /*
2971225ad72SBartlomiej Zolnierkiewicz * Try to get boot address using firmware first
2981225ad72SBartlomiej Zolnierkiewicz * and fall back to boot register if it fails.
2991225ad72SBartlomiej Zolnierkiewicz */
3001225ad72SBartlomiej Zolnierkiewicz ret = call_firmware_op(get_cpu_boot_addr, core_id, boot_addr);
3011225ad72SBartlomiej Zolnierkiewicz if (ret && ret != -ENOSYS)
3021225ad72SBartlomiej Zolnierkiewicz goto fail;
3031225ad72SBartlomiej Zolnierkiewicz if (ret == -ENOSYS) {
3041225ad72SBartlomiej Zolnierkiewicz void __iomem *boot_reg = cpu_boot_reg(core_id);
3051225ad72SBartlomiej Zolnierkiewicz
3061225ad72SBartlomiej Zolnierkiewicz if (IS_ERR(boot_reg)) {
3071225ad72SBartlomiej Zolnierkiewicz ret = PTR_ERR(boot_reg);
3081225ad72SBartlomiej Zolnierkiewicz goto fail;
3091225ad72SBartlomiej Zolnierkiewicz }
310458ad21dSBen Dooks *boot_addr = readl_relaxed(boot_reg);
3111225ad72SBartlomiej Zolnierkiewicz ret = 0;
3121225ad72SBartlomiej Zolnierkiewicz }
3131225ad72SBartlomiej Zolnierkiewicz fail:
3141225ad72SBartlomiej Zolnierkiewicz return ret;
3151225ad72SBartlomiej Zolnierkiewicz }
3161225ad72SBartlomiej Zolnierkiewicz
exynos_boot_secondary(unsigned int cpu,struct task_struct * idle)3178bd26e3aSPaul Gortmaker static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
31883014579SKukjin Kim {
31983014579SKukjin Kim unsigned long timeout;
3209637f30eSTomasz Figa u32 mpidr = cpu_logical_map(cpu);
3219637f30eSTomasz Figa u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
322b3205deaSSachin Kamat int ret = -ENOSYS;
32383014579SKukjin Kim
32483014579SKukjin Kim /*
32583014579SKukjin Kim * Set synchronisation state between this boot processor
32683014579SKukjin Kim * and the secondary one
32783014579SKukjin Kim */
32883014579SKukjin Kim spin_lock(&boot_lock);
32983014579SKukjin Kim
33083014579SKukjin Kim /*
33183014579SKukjin Kim * The secondary processor is waiting to be released from
33283014579SKukjin Kim * the holding pen - release it, then wait for it to flag
3336213f70eSRussell King * that it has been released by resetting exynos_pen_release.
33483014579SKukjin Kim *
3356213f70eSRussell King * Note that "exynos_pen_release" is the hardware CPU core ID, whereas
33683014579SKukjin Kim * "cpu" is Linux's internal ID.
33783014579SKukjin Kim */
3386213f70eSRussell King exynos_write_pen_release(core_id);
33983014579SKukjin Kim
3409637f30eSTomasz Figa if (!exynos_cpu_power_state(core_id)) {
3419637f30eSTomasz Figa exynos_cpu_power_up(core_id);
34283014579SKukjin Kim timeout = 10;
34383014579SKukjin Kim
34483014579SKukjin Kim /* wait max 10 ms until cpu1 is on */
3459637f30eSTomasz Figa while (exynos_cpu_power_state(core_id)
3469637f30eSTomasz Figa != S5P_CORE_LOCAL_PWR_EN) {
3474bdf2f3fSStuart Menefy if (timeout == 0)
34883014579SKukjin Kim break;
3494bdf2f3fSStuart Menefy timeout--;
35083014579SKukjin Kim mdelay(1);
35183014579SKukjin Kim }
35283014579SKukjin Kim
35383014579SKukjin Kim if (timeout == 0) {
35483014579SKukjin Kim printk(KERN_ERR "cpu1 power enable failed");
35583014579SKukjin Kim spin_unlock(&boot_lock);
35683014579SKukjin Kim return -ETIMEDOUT;
35783014579SKukjin Kim }
35883014579SKukjin Kim }
359b588aaecSKrzysztof Kozlowski
360b588aaecSKrzysztof Kozlowski exynos_core_restart(core_id);
361b588aaecSKrzysztof Kozlowski
36283014579SKukjin Kim /*
36383014579SKukjin Kim * Send the secondary CPU a soft interrupt, thereby causing
36483014579SKukjin Kim * the boot monitor to read the system wide flags register,
36583014579SKukjin Kim * and branch to the address found there.
36683014579SKukjin Kim */
36783014579SKukjin Kim
36883014579SKukjin Kim timeout = jiffies + (1 * HZ);
36983014579SKukjin Kim while (time_before(jiffies, timeout)) {
370beddf63fSTomasz Figa unsigned long boot_addr;
371beddf63fSTomasz Figa
37283014579SKukjin Kim smp_rmb();
37383014579SKukjin Kim
37464fc2a94SFlorian Fainelli boot_addr = __pa_symbol(exynos4_secondary_startup);
375beddf63fSTomasz Figa
376955d4cf8SBartlomiej Zolnierkiewicz ret = exynos_set_boot_addr(core_id, boot_addr);
377955d4cf8SBartlomiej Zolnierkiewicz if (ret)
378b3205deaSSachin Kamat goto fail;
379beddf63fSTomasz Figa
3809637f30eSTomasz Figa call_firmware_op(cpu_boot, core_id);
381beddf63fSTomasz Figa
382497ab3b3SBartlomiej Zolnierkiewicz if (soc_is_exynos3250())
383497ab3b3SBartlomiej Zolnierkiewicz dsb_sev();
384497ab3b3SBartlomiej Zolnierkiewicz else
385b1cffebfSRob Herring arch_send_wakeup_ipi_mask(cpumask_of(cpu));
38683014579SKukjin Kim
3876213f70eSRussell King if (exynos_pen_release == -1)
38883014579SKukjin Kim break;
38983014579SKukjin Kim
39083014579SKukjin Kim udelay(10);
39183014579SKukjin Kim }
39283014579SKukjin Kim
3936213f70eSRussell King if (exynos_pen_release != -1)
3949f294c17SBartlomiej Zolnierkiewicz ret = -ETIMEDOUT;
3959f294c17SBartlomiej Zolnierkiewicz
39683014579SKukjin Kim /*
39783014579SKukjin Kim * now the secondary core is starting up let it run its
39883014579SKukjin Kim * calibrations, then wait for it to finish
39983014579SKukjin Kim */
400b3205deaSSachin Kamat fail:
40183014579SKukjin Kim spin_unlock(&boot_lock);
40283014579SKukjin Kim
4036213f70eSRussell King return exynos_pen_release != -1 ? ret : 0;
40483014579SKukjin Kim }
40583014579SKukjin Kim
exynos_smp_prepare_cpus(unsigned int max_cpus)40606853ae4SMarc Zyngier static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
40783014579SKukjin Kim {
4081754c42eSOlof Johansson exynos_sysram_init();
4091754c42eSOlof Johansson
4106f024978SKrzysztof Kozlowski exynos_set_delayed_reset_assertion(true);
4116f024978SKrzysztof Kozlowski
412af040ffcSRussell King if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
4133c33710bSPankaj Dubey exynos_scu_enable();
414b3205deaSSachin Kamat }
41506853ae4SMarc Zyngier
4166f0b7c0cSKrzysztof Kozlowski #ifdef CONFIG_HOTPLUG_CPU
4176f0b7c0cSKrzysztof Kozlowski /*
4186f0b7c0cSKrzysztof Kozlowski * platform-specific code to shutdown a CPU
4196f0b7c0cSKrzysztof Kozlowski *
4206f0b7c0cSKrzysztof Kozlowski * Called with IRQs disabled
4216f0b7c0cSKrzysztof Kozlowski */
exynos_cpu_die(unsigned int cpu)42227b9ee85SKrzysztof Kozlowski static void exynos_cpu_die(unsigned int cpu)
4236f0b7c0cSKrzysztof Kozlowski {
4246f0b7c0cSKrzysztof Kozlowski int spurious = 0;
42513cfa6c4SKrzysztof Kozlowski u32 mpidr = cpu_logical_map(cpu);
42613cfa6c4SKrzysztof Kozlowski u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
4276f0b7c0cSKrzysztof Kozlowski
4286f0b7c0cSKrzysztof Kozlowski v7_exit_coherency_flush(louis);
4296f0b7c0cSKrzysztof Kozlowski
4306f0b7c0cSKrzysztof Kozlowski platform_do_lowpower(cpu, &spurious);
4316f0b7c0cSKrzysztof Kozlowski
4326f0b7c0cSKrzysztof Kozlowski /*
4336f0b7c0cSKrzysztof Kozlowski * bring this CPU back into the world of cache
4346f0b7c0cSKrzysztof Kozlowski * coherency, and then restore interrupts
4356f0b7c0cSKrzysztof Kozlowski */
43613cfa6c4SKrzysztof Kozlowski cpu_leave_lowpower(core_id);
4376f0b7c0cSKrzysztof Kozlowski
4386f0b7c0cSKrzysztof Kozlowski if (spurious)
4396f0b7c0cSKrzysztof Kozlowski pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious);
4406f0b7c0cSKrzysztof Kozlowski }
4416f0b7c0cSKrzysztof Kozlowski #endif /* CONFIG_HOTPLUG_CPU */
4426f0b7c0cSKrzysztof Kozlowski
44375305275SMasahiro Yamada const struct smp_operations exynos_smp_ops __initconst = {
44406853ae4SMarc Zyngier .smp_prepare_cpus = exynos_smp_prepare_cpus,
44506853ae4SMarc Zyngier .smp_secondary_init = exynos_secondary_init,
44606853ae4SMarc Zyngier .smp_boot_secondary = exynos_boot_secondary,
44706853ae4SMarc Zyngier #ifdef CONFIG_HOTPLUG_CPU
44806853ae4SMarc Zyngier .cpu_die = exynos_cpu_die,
44906853ae4SMarc Zyngier #endif
45006853ae4SMarc Zyngier };
451