1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright: (C) 2018 Socionext Inc.
4 * Copyright: (C) 2015 Linaro Ltd.
7 #include <linux/cpu_pm.h>
8 #include <linux/irqchip/arm-gic.h>
9 #include <linux/of_address.h>
10 #include <linux/suspend.h>
12 #include <asm/cacheflush.h>
14 #include <asm/idmap.h>
15 #include <asm/smp_plat.h>
16 #include <asm/suspend.h>
18 #define M10V_MAX_CPU 4
19 #define KERNEL_UNBOOT_FLAG 0x12345678
21 static void __iomem *m10v_smp_base;
23 static int m10v_boot_secondary(unsigned int l_cpu, struct task_struct *idle)
25 unsigned int mpidr, cpu, cluster;
30 mpidr = cpu_logical_map(l_cpu);
31 cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
32 cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
34 if (cpu >= M10V_MAX_CPU)
37 pr_info("%s: cpu %u l_cpu %u cluster %u\n",
38 __func__, cpu, l_cpu, cluster);
40 writel(__pa_symbol(secondary_startup), m10v_smp_base + cpu * 4);
41 arch_send_wakeup_ipi_mask(cpumask_of(l_cpu));
46 static void m10v_smp_init(unsigned int max_cpus)
48 unsigned int mpidr, cpu, cluster;
49 struct device_node *np;
51 np = of_find_compatible_node(NULL, NULL, "socionext,milbeaut-smp-sram");
55 m10v_smp_base = of_iomap(np, 0);
59 mpidr = read_cpuid_mpidr();
60 cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
61 cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
62 pr_info("MCPM boot on cpu_%u cluster_%u\n", cpu, cluster);
64 for (cpu = 0; cpu < M10V_MAX_CPU; cpu++)
65 writel(KERNEL_UNBOOT_FLAG, m10v_smp_base + cpu * 4);
68 static void m10v_cpu_die(unsigned int l_cpu)
71 v7_exit_coherency_flush(louis);
75 static int m10v_cpu_kill(unsigned int l_cpu)
77 unsigned int mpidr, cpu;
79 mpidr = cpu_logical_map(l_cpu);
80 cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
82 writel(KERNEL_UNBOOT_FLAG, m10v_smp_base + cpu * 4);
87 static struct smp_operations m10v_smp_ops __initdata = {
88 .smp_prepare_cpus = m10v_smp_init,
89 .smp_boot_secondary = m10v_boot_secondary,
90 .cpu_die = m10v_cpu_die,
91 .cpu_kill = m10v_cpu_kill,
93 CPU_METHOD_OF_DECLARE(m10v_smp, "socionext,milbeaut-m10v-smp", &m10v_smp_ops);
95 static int m10v_pm_valid(suspend_state_t state)
97 return (state == PM_SUSPEND_STANDBY) || (state == PM_SUSPEND_MEM);
100 typedef void (*phys_reset_t)(unsigned long);
101 static phys_reset_t phys_reset;
103 static int m10v_die(unsigned long arg)
105 setup_mm_for_reboot();
107 /* Boot just like a secondary */
108 phys_reset = (phys_reset_t)(unsigned long)virt_to_phys(cpu_reset);
109 phys_reset(virt_to_phys(cpu_resume));
114 static int m10v_pm_enter(suspend_state_t state)
117 case PM_SUSPEND_STANDBY:
122 cpu_suspend(0, m10v_die);
129 static const struct platform_suspend_ops m10v_pm_ops = {
130 .valid = m10v_pm_valid,
131 .enter = m10v_pm_enter,
134 struct clk *m10v_clclk_register(struct device *cpu_dev);
136 static int __init m10v_pm_init(void)
138 if (of_machine_is_compatible("socionext,milbeaut-evb"))
139 suspend_set_ops(&m10v_pm_ops);
143 late_initcall(m10v_pm_init);