1 /*
2 * Copyright (C) 2005 Nokia Corporation
3 * Author: Paul Mundt <paul.mundt@nokia.com>
4 *
5 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
6 *
7 * Modified from the original mach-omap/omap2/board-generic.c did by Paul
8 * to support the OMAP2+ device tree boards with an unique board file.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14 #include <linux/io.h>
15 #include <linux/of_irq.h>
16 #include <linux/of_platform.h>
17 #include <linux/irqdomain.h>
18 #include <linux/clk.h>
19 #include <linux/string.h>
20 #include <linux/slab.h>
22 #include <asm/hardware/gic.h>
23 #include <asm/mach/arch.h>
25 #include <plat/sata.h>
27 #include "common.h"
28 #include "common-board-devices.h"
29 #include "dss-common.h"
31 #if !(defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3))
32 #define intc_of_init NULL
33 #endif
34 #ifndef CONFIG_ARCH_OMAP4
35 #define gic_of_init NULL
36 #endif
38 static struct of_device_id omap_dt_match_table[] __initdata = {
39 { .compatible = "simple-bus", },
40 { .compatible = "ti,omap-infra", },
41 { }
42 };
44 static int __init omap_create_clk_alias(struct device_node *np)
45 {
46 int ret = 0;
47 const char *s, *alias;
48 char *clk_id;
49 struct device_node *dev_np;
50 struct platform_device *pdev;
52 of_property_read_string(np, "clock-name", &s);
53 if (!s) {
54 pr_err("%s: couldn't find clock-name property in node %s\n",
55 __func__, np->name);
56 return -ENODEV;
57 }
59 clk_id = kstrdup(s, GFP_KERNEL);
60 if (!clk_id)
61 return -ENOMEM;
63 dev_np = of_parse_phandle(np, "device", 0);
64 if (!dev_np) {
65 pr_err("%s: couldn't find device phandle for \'%s\'\n",
66 __func__, clk_id);
67 ret = -ENODEV;
68 goto exit;
69 }
71 pdev = of_find_device_by_node(dev_np);
72 if (!pdev) {
73 pr_err("%s: couldn't find device for clock \'%s\'\n",
74 __func__, clk_id);
75 ret = -ENODEV;
76 goto exit;
77 }
79 ret = of_property_read_string(np, "clock-alias", &alias);
80 if (ret) {
81 pr_err("%s: couldn't find alias for clock \'%s\'\n",
82 __func__, clk_id);
83 ret = -ENODEV;
84 goto exit;
85 }
87 ret = clk_add_alias(alias, dev_name(&pdev->dev), clk_id, NULL);
88 if (ret) {
89 pr_err("%s: couldn't add alias \'%s\' to clock \'%s\'\n",
90 __func__, alias, clk_id);
91 ret = -ENODEV;
92 goto exit;
93 }
95 exit:
96 kfree(clk_id);
97 return ret;
98 }
100 static void __init omap_generic_init(void)
101 {
102 struct device_node *np;
104 omap_sdrc_init(NULL, NULL);
106 of_platform_populate(NULL, omap_dt_match_table, NULL, NULL);
108 /* create clock aliases based on 'clock_alias' nodes */
109 for_each_node_by_name(np, "clock_alias") {
110 omap_create_clk_alias(np);
111 of_node_put(np);
112 }
114 /*
115 * HACK: call display setup code for selected boards to enable omapdss.
116 * This will be removed when omapdss supports DT.
117 */
118 if (of_machine_is_compatible("ti,omap4-panda"))
119 omap4_panda_display_init_of();
120 else if (of_machine_is_compatible("ti,omap4-sdp"))
121 omap_4430sdp_display_init_of();
122 else if (of_machine_is_compatible("ti,omap5"))
123 omap_sata_init();
124 }
126 #ifdef CONFIG_SOC_OMAP2420
127 static const char *omap242x_boards_compat[] __initdata = {
128 "ti,omap2420",
129 NULL,
130 };
132 DT_MACHINE_START(OMAP242X_DT, "Generic OMAP2420 (Flattened Device Tree)")
133 .reserve = omap_reserve,
134 .map_io = omap242x_map_io,
135 .init_early = omap2420_init_early,
136 .init_irq = omap_intc_of_init,
137 .handle_irq = omap2_intc_handle_irq,
138 .init_machine = omap_generic_init,
139 .timer = &omap2_timer,
140 .dt_compat = omap242x_boards_compat,
141 .restart = omap2xxx_restart,
142 MACHINE_END
143 #endif
145 #ifdef CONFIG_SOC_OMAP2430
146 static const char *omap243x_boards_compat[] __initdata = {
147 "ti,omap2430",
148 NULL,
149 };
151 DT_MACHINE_START(OMAP243X_DT, "Generic OMAP2430 (Flattened Device Tree)")
152 .reserve = omap_reserve,
153 .map_io = omap243x_map_io,
154 .init_early = omap2430_init_early,
155 .init_irq = omap_intc_of_init,
156 .handle_irq = omap2_intc_handle_irq,
157 .init_machine = omap_generic_init,
158 .timer = &omap2_timer,
159 .dt_compat = omap243x_boards_compat,
160 .restart = omap2xxx_restart,
161 MACHINE_END
162 #endif
164 #ifdef CONFIG_ARCH_OMAP3
165 static const char *omap3_boards_compat[] __initdata = {
166 "ti,omap3",
167 NULL,
168 };
170 DT_MACHINE_START(OMAP3_DT, "Generic OMAP3 (Flattened Device Tree)")
171 .reserve = omap_reserve,
172 .map_io = omap3_map_io,
173 .init_early = omap3430_init_early,
174 .init_irq = omap_intc_of_init,
175 .handle_irq = omap3_intc_handle_irq,
176 .init_machine = omap_generic_init,
177 .timer = &omap3_timer,
178 .dt_compat = omap3_boards_compat,
179 .restart = omap3xxx_restart,
180 MACHINE_END
182 static const char *omap3_gp_boards_compat[] __initdata = {
183 "ti,omap3-beagle",
184 NULL,
185 };
187 DT_MACHINE_START(OMAP3_GP_DT, "Generic OMAP3-GP (Flattened Device Tree)")
188 .reserve = omap_reserve,
189 .map_io = omap3_map_io,
190 .init_early = omap3430_init_early,
191 .init_irq = omap_intc_of_init,
192 .handle_irq = omap3_intc_handle_irq,
193 .init_machine = omap_generic_init,
194 .timer = &omap3_secure_timer,
195 .dt_compat = omap3_gp_boards_compat,
196 .restart = omap3xxx_restart,
197 MACHINE_END
198 #endif
200 #ifdef CONFIG_SOC_AM33XX
201 static const char *am33xx_boards_compat[] __initdata = {
202 "ti,am33xx",
203 NULL,
204 };
206 DT_MACHINE_START(AM33XX_DT, "Generic AM33XX (Flattened Device Tree)")
207 .reserve = omap_reserve,
208 .map_io = am33xx_map_io,
209 .init_early = am33xx_init_early,
210 .init_irq = omap_intc_of_init,
211 .handle_irq = omap3_intc_handle_irq,
212 .init_machine = omap_generic_init,
213 .timer = &omap3_am33xx_timer,
214 .dt_compat = am33xx_boards_compat,
215 .restart = am33xx_restart,
216 MACHINE_END
217 #endif
219 #ifdef CONFIG_ARCH_OMAP4
220 static const char *omap4_boards_compat[] __initdata = {
221 "ti,omap4",
222 NULL,
223 };
225 DT_MACHINE_START(OMAP4_DT, "Generic OMAP4 (Flattened Device Tree)")
226 .reserve = omap_reserve,
227 .smp = smp_ops(omap4_smp_ops),
228 .map_io = omap4_map_io,
229 .init_early = omap4430_init_early,
230 .init_irq = omap_gic_of_init,
231 .handle_irq = gic_handle_irq,
232 .init_machine = omap_generic_init,
233 .init_late = omap4430_init_late,
234 .timer = &omap4_timer,
235 .dt_compat = omap4_boards_compat,
236 .restart = omap44xx_restart,
237 MACHINE_END
238 #endif
240 #ifdef CONFIG_SOC_OMAP5
241 static const char *omap5_boards_compat[] __initdata = {
242 "ti,omap5",
243 NULL,
244 };
246 DT_MACHINE_START(OMAP5_DT, "Generic OMAP5 (Flattened Device Tree)")
247 .reserve = omap_reserve,
248 .smp = smp_ops(omap4_smp_ops),
249 .map_io = omap5_map_io,
250 .init_early = omap5_init_early,
251 .init_irq = omap_gic_of_init,
252 .handle_irq = gic_handle_irq,
253 .init_machine = omap_generic_init,
254 .init_late = omap5_init_late,
255 .timer = &omap5_timer,
256 .dt_compat = omap5_boards_compat,
257 .restart = omap44xx_restart,
258 MACHINE_END
259 #endif