Merge branch 'pm-cpuidle'
[linux-block.git] / arch / arm / mach-mvebu / platsmp.c
CommitLineData
45f5984a
GC
1/*
2 * Symmetric Multi Processing (SMP) support for Armada XP
3 *
4 * Copyright (C) 2012 Marvell
5 *
6 * Lior Amsalem <alior@marvell.com>
7 * Yehuda Yitschak <yehuday@marvell.com>
8 * Gregory CLEMENT <gregory.clement@free-electrons.com>
9 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
10 *
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.
14 *
15 * The Armada XP SoC has 4 ARMv7 PJ4B CPUs running in full HW coherency
16 * This file implements the routines for preparing the SMP infrastructure
17 * and waking up the secondary CPUs
18 */
19
20#include <linux/init.h>
21#include <linux/smp.h>
22#include <linux/clk.h>
23#include <linux/of.h>
87e1bed4 24#include <linux/mbus.h>
45f5984a
GC
25#include <asm/cacheflush.h>
26#include <asm/smp_plat.h>
27#include "common.h"
28#include "armada-370-xp.h"
29#include "pmsu.h"
30#include "coherency.h"
31
f6cec7cd
SK
32static struct clk *__init get_cpu_clk(int cpu)
33{
34 struct clk *cpu_clk;
35 struct device_node *np = of_get_cpu_node(cpu, NULL);
36
37 if (WARN(!np, "missing cpu node\n"))
38 return NULL;
39 cpu_clk = of_clk_get(np, 0);
40 if (WARN_ON(IS_ERR(cpu_clk)))
41 return NULL;
42 return cpu_clk;
43}
44
45f5984a
GC
45void __init set_secondary_cpus_clock(void)
46{
f6cec7cd 47 int thiscpu, cpu;
45f5984a 48 unsigned long rate;
f6cec7cd 49 struct clk *cpu_clk;
45f5984a
GC
50
51 thiscpu = smp_processor_id();
f6cec7cd
SK
52 cpu_clk = get_cpu_clk(thiscpu);
53 if (!cpu_clk)
45f5984a
GC
54 return;
55 clk_prepare_enable(cpu_clk);
56 rate = clk_get_rate(cpu_clk);
57
58 /* set all the other CPU clk to the same rate than the boot CPU */
f6cec7cd
SK
59 for_each_possible_cpu(cpu) {
60 if (cpu == thiscpu)
61 continue;
62 cpu_clk = get_cpu_clk(cpu);
63 if (!cpu_clk)
45f5984a 64 return;
f6cec7cd 65 clk_set_rate(cpu_clk, rate);
45f5984a
GC
66 }
67}
68
8bd26e3a 69static void armada_xp_secondary_init(unsigned int cpu)
45f5984a
GC
70{
71 armada_xp_mpic_smp_cpu_init();
72}
73
8bd26e3a 74static int armada_xp_boot_secondary(unsigned int cpu, struct task_struct *idle)
45f5984a
GC
75{
76 pr_info("Booting CPU %d\n", cpu);
77
78 armada_xp_boot_cpu(cpu, armada_xp_secondary_startup);
79
80 return 0;
81}
82
83static void __init armada_xp_smp_init_cpus(void)
84{
b21dcafe 85 struct device_node *np;
45f5984a 86 unsigned int i, ncores;
b21dcafe
TP
87
88 np = of_find_node_by_name(NULL, "cpus");
89 if (!np)
90 panic("No 'cpus' node found\n");
91
92 ncores = of_get_child_count(np);
93 if (ncores == 0 || ncores > ARMADA_XP_MAX_CPUS)
94 panic("Invalid number of CPUs in DT\n");
45f5984a
GC
95
96 /* Limit possible CPUs to defconfig */
97 if (ncores > nr_cpu_ids) {
98 pr_warn("SMP: %d CPUs physically present. Only %d configured.",
99 ncores, nr_cpu_ids);
100 pr_warn("Clipping CPU count to %d\n", nr_cpu_ids);
101 ncores = nr_cpu_ids;
102 }
103
104 for (i = 0; i < ncores; i++)
105 set_cpu_possible(i, true);
106
107 set_smp_cross_call(armada_mpic_send_doorbell);
108}
109
110void __init armada_xp_smp_prepare_cpus(unsigned int max_cpus)
111{
112 set_secondary_cpus_clock();
113 flush_cache_all();
114 set_cpu_coherent(cpu_logical_map(smp_processor_id()), 0);
87e1bed4 115 mvebu_mbus_add_window("bootrom", 0xfff00000, SZ_1M);
45f5984a
GC
116}
117
118struct smp_operations armada_xp_smp_ops __initdata = {
119 .smp_init_cpus = armada_xp_smp_init_cpus,
120 .smp_prepare_cpus = armada_xp_smp_prepare_cpus,
121 .smp_secondary_init = armada_xp_secondary_init,
122 .smp_boot_secondary = armada_xp_boot_secondary,
123#ifdef CONFIG_HOTPLUG_CPU
124 .cpu_die = armada_xp_cpu_die,
125#endif
126};