blob: b4d4313af6f1a6647326eb8ef121b60127cc713f [file] [log] [blame]
Rich Felker7480e0a2016-01-23 00:45:41 +00001/*
2 * SH generic board support, using device tree
3 *
4 * Copyright (C) 2015-2016 Smart Energy Instruments, Inc.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/of.h>
12#include <linux/of_platform.h>
13#include <linux/of_fdt.h>
Rich Felker7480e0a2016-01-23 00:45:41 +000014#include <linux/clocksource.h>
15#include <linux/irqchip.h>
16#include <linux/clk-provider.h>
17#include <asm/machvec.h>
18#include <asm/rtc.h>
19
Rich Felker044b81f2016-02-15 18:30:50 +000020#ifdef CONFIG_SMP
21
22static void dummy_smp_setup(void)
23{
24}
25
26static void dummy_prepare_cpus(unsigned int max_cpus)
27{
28}
29
30static void dummy_start_cpu(unsigned int cpu, unsigned long entry_point)
31{
32}
33
34static unsigned int dummy_smp_processor_id(void)
35{
36 return 0;
37}
38
39static void dummy_send_ipi(unsigned int cpu, unsigned int message)
40{
41}
42
43static struct plat_smp_ops dummy_smp_ops = {
44 .smp_setup = dummy_smp_setup,
45 .prepare_cpus = dummy_prepare_cpus,
46 .start_cpu = dummy_start_cpu,
47 .smp_processor_id = dummy_smp_processor_id,
48 .send_ipi = dummy_send_ipi,
49 .cpu_die = native_cpu_die,
50 .cpu_disable = native_cpu_disable,
51 .play_dead = native_play_dead,
52};
53
54extern const struct of_cpu_method __cpu_method_of_table[];
55const struct of_cpu_method __cpu_method_of_table_sentinel
56 __section(__cpu_method_of_table_end);
57
58static void sh_of_smp_probe(void)
59{
60 struct device_node *np = 0;
61 const char *method = 0;
62 const struct of_cpu_method *m = __cpu_method_of_table;
63
64 pr_info("SH generic board support: scanning for cpus\n");
65
66 init_cpu_possible(cpumask_of(0));
67
68 while ((np = of_find_node_by_type(np, "cpu"))) {
69 const __be32 *cell = of_get_property(np, "reg", NULL);
70 u64 id = -1;
71 if (cell) id = of_read_number(cell, of_n_addr_cells(np));
72 if (id < NR_CPUS) {
73 if (!method)
74 of_property_read_string(np, "enable-method", &method);
75 set_cpu_possible(id, true);
76 set_cpu_present(id, true);
77 __cpu_number_map[id] = id;
78 __cpu_logical_map[id] = id;
79 }
80 }
81 if (!method) {
82 np = of_find_node_by_name(NULL, "cpus");
83 of_property_read_string(np, "enable-method", &method);
84 }
85
86 pr_info("CPU enable method: %s\n", method);
87 if (method)
88 for (; m->method; m++)
89 if (!strcmp(m->method, method)) {
90 register_smp_ops(m->ops);
91 return;
92 }
93
94 register_smp_ops(&dummy_smp_ops);
95}
96
97#else
98
99static void sh_of_smp_probe(void)
100{
101}
102
103#endif
104
Rich Felker7480e0a2016-01-23 00:45:41 +0000105static void noop(void)
106{
107}
108
109static int noopi(void)
110{
111 return 0;
112}
113
114static void __init sh_of_mem_reserve(void)
115{
116 early_init_fdt_reserve_self();
117 early_init_fdt_scan_reserved_mem();
118}
119
120static void __init sh_of_time_init(void)
121{
122 pr_info("SH generic board support: scanning for clocksource devices\n");
123 clocksource_probe();
124}
125
126static void __init sh_of_setup(char **cmdline_p)
127{
128 unflatten_device_tree();
129
130 board_time_init = sh_of_time_init;
131
132 sh_mv.mv_name = of_flat_dt_get_machine_name();
133 if (!sh_mv.mv_name)
134 sh_mv.mv_name = "Unknown SH model";
135
Rich Felker044b81f2016-02-15 18:30:50 +0000136 sh_of_smp_probe();
Rich Felker7480e0a2016-01-23 00:45:41 +0000137}
138
139static int sh_of_irq_demux(int irq)
140{
141 /* FIXME: eventually this should not be used at all;
142 * the interrupt controller should set_handle_irq(). */
143 return irq;
144}
145
146static void __init sh_of_init_irq(void)
147{
148 pr_info("SH generic board support: scanning for interrupt controllers\n");
149 irqchip_init();
150}
151
152static int __init sh_of_clk_init(void)
153{
154#ifdef CONFIG_COMMON_CLK
155 /* Disabled pending move to COMMON_CLK framework. */
156 pr_info("SH generic board support: scanning for clk providers\n");
157 of_clk_init(NULL);
158#endif
159 return 0;
160}
161
162static struct sh_machine_vector __initmv sh_of_generic_mv = {
163 .mv_setup = sh_of_setup,
164 .mv_name = "devicetree", /* replaced by DT root's model */
165 .mv_irq_demux = sh_of_irq_demux,
166 .mv_init_irq = sh_of_init_irq,
167 .mv_clk_init = sh_of_clk_init,
168 .mv_mode_pins = noopi,
169 .mv_mem_init = noop,
170 .mv_mem_reserve = sh_of_mem_reserve,
171};
172
173struct sh_clk_ops;
174
175void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
176{
177}
178
179void __init plat_irq_setup(void)
180{
181}
182
183static int __init sh_of_device_init(void)
184{
185 pr_info("SH generic board support: populating platform devices\n");
186 if (of_have_populated_dt()) {
Rich Felker7480e0a2016-01-23 00:45:41 +0000187 of_platform_populate(NULL, of_default_bus_match_table,
188 NULL, NULL);
189 } else {
190 pr_crit("Device tree not populated\n");
191 }
192 return 0;
193}
194arch_initcall_sync(sh_of_device_init);