blob: 922dd4db21a0898b591a7ced5c2b70585ee96f58 [file] [log] [blame]
Magnus Dammf411fad2011-12-14 01:36:12 +09001/*
2 * r8a7779 processor support
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Copyright (C) 2011 Magnus Damm
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/irq.h>
Simon Horman10e8d4f2012-11-21 22:00:15 +090024#include <linux/of_platform.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090025#include <linux/platform_device.h>
26#include <linux/delay.h>
27#include <linux/input.h>
28#include <linux/io.h>
29#include <linux/serial_sci.h>
30#include <linux/sh_intc.h>
31#include <linux/sh_timer.h>
32#include <mach/hardware.h>
Rob Herring250a2722012-01-03 16:57:33 -060033#include <mach/irqs.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090034#include <mach/r8a7779.h>
Magnus Damma662c082012-01-10 15:50:01 +090035#include <mach/common.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090036#include <asm/mach-types.h>
37#include <asm/mach/arch.h>
Magnus Dammdf27a2d2012-03-06 17:37:01 +090038#include <asm/mach/time.h>
Magnus Damm3e353b872012-02-29 21:37:43 +090039#include <asm/mach/map.h>
Magnus Damm8bac13f2012-03-01 12:48:03 +090040#include <asm/hardware/cache-l2x0.h>
Magnus Damm3e353b872012-02-29 21:37:43 +090041
42static struct map_desc r8a7779_io_desc[] __initdata = {
43 /* 2M entity map for 0xf0000000 (MPCORE) */
44 {
45 .virtual = 0xf0000000,
46 .pfn = __phys_to_pfn(0xf0000000),
47 .length = SZ_2M,
48 .type = MT_DEVICE_NONSHARED
49 },
50 /* 16M entity map for 0xfexxxxxx (DMAC-S/HPBREG/INTC2/LRAM/DBSC) */
51 {
52 .virtual = 0xfe000000,
53 .pfn = __phys_to_pfn(0xfe000000),
54 .length = SZ_16M,
55 .type = MT_DEVICE_NONSHARED
56 },
57};
58
59void __init r8a7779_map_io(void)
60{
61 iotable_init(r8a7779_io_desc, ARRAY_SIZE(r8a7779_io_desc));
62}
Magnus Dammf411fad2011-12-14 01:36:12 +090063
Laurent Pinchart8b6edf32012-12-15 23:51:26 +010064static struct resource r8a7779_pfc_resources[] = {
65 [0] = {
66 .start = 0xfffc0000,
67 .end = 0xfffc023b,
68 .flags = IORESOURCE_MEM,
69 },
70 [1] = {
71 .start = 0xffc40000,
72 .end = 0xffc46fff,
73 .flags = IORESOURCE_MEM,
74 }
75};
76
77static struct platform_device r8a7779_pfc_device = {
78 .name = "pfc-r8a7779",
79 .id = -1,
80 .resource = r8a7779_pfc_resources,
81 .num_resources = ARRAY_SIZE(r8a7779_pfc_resources),
82};
83
84void __init r8a7779_pinmux_init(void)
85{
86 platform_device_register(&r8a7779_pfc_device);
87}
88
Magnus Dammf411fad2011-12-14 01:36:12 +090089static struct plat_sci_port scif0_platform_data = {
90 .mapbase = 0xffe40000,
91 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
92 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
93 .scbrr_algo_id = SCBRR_ALGO_2,
94 .type = PORT_SCIF,
Kuninori Morimotoff8de982013-01-18 01:40:42 -080095 .irqs = SCIx_IRQ_MUXED(gic_spi(88)),
Magnus Dammf411fad2011-12-14 01:36:12 +090096};
97
98static struct platform_device scif0_device = {
99 .name = "sh-sci",
100 .id = 0,
101 .dev = {
102 .platform_data = &scif0_platform_data,
103 },
104};
105
106static struct plat_sci_port scif1_platform_data = {
107 .mapbase = 0xffe41000,
108 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
109 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
110 .scbrr_algo_id = SCBRR_ALGO_2,
111 .type = PORT_SCIF,
Kuninori Morimotoff8de982013-01-18 01:40:42 -0800112 .irqs = SCIx_IRQ_MUXED(gic_spi(89)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900113};
114
115static struct platform_device scif1_device = {
116 .name = "sh-sci",
117 .id = 1,
118 .dev = {
119 .platform_data = &scif1_platform_data,
120 },
121};
122
123static struct plat_sci_port scif2_platform_data = {
124 .mapbase = 0xffe42000,
125 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
126 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
127 .scbrr_algo_id = SCBRR_ALGO_2,
128 .type = PORT_SCIF,
Kuninori Morimotoff8de982013-01-18 01:40:42 -0800129 .irqs = SCIx_IRQ_MUXED(gic_spi(90)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900130};
131
132static struct platform_device scif2_device = {
133 .name = "sh-sci",
134 .id = 2,
135 .dev = {
136 .platform_data = &scif2_platform_data,
137 },
138};
139
140static struct plat_sci_port scif3_platform_data = {
141 .mapbase = 0xffe43000,
142 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
143 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
144 .scbrr_algo_id = SCBRR_ALGO_2,
145 .type = PORT_SCIF,
Kuninori Morimotoff8de982013-01-18 01:40:42 -0800146 .irqs = SCIx_IRQ_MUXED(gic_spi(91)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900147};
148
149static struct platform_device scif3_device = {
150 .name = "sh-sci",
151 .id = 3,
152 .dev = {
153 .platform_data = &scif3_platform_data,
154 },
155};
156
157static struct plat_sci_port scif4_platform_data = {
158 .mapbase = 0xffe44000,
159 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
160 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
161 .scbrr_algo_id = SCBRR_ALGO_2,
162 .type = PORT_SCIF,
Kuninori Morimotoff8de982013-01-18 01:40:42 -0800163 .irqs = SCIx_IRQ_MUXED(gic_spi(92)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900164};
165
166static struct platform_device scif4_device = {
167 .name = "sh-sci",
168 .id = 4,
169 .dev = {
170 .platform_data = &scif4_platform_data,
171 },
172};
173
174static struct plat_sci_port scif5_platform_data = {
175 .mapbase = 0xffe45000,
176 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
177 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
178 .scbrr_algo_id = SCBRR_ALGO_2,
179 .type = PORT_SCIF,
Kuninori Morimotoff8de982013-01-18 01:40:42 -0800180 .irqs = SCIx_IRQ_MUXED(gic_spi(93)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900181};
182
183static struct platform_device scif5_device = {
184 .name = "sh-sci",
185 .id = 5,
186 .dev = {
187 .platform_data = &scif5_platform_data,
188 },
189};
190
191/* TMU */
192static struct sh_timer_config tmu00_platform_data = {
193 .name = "TMU00",
194 .channel_offset = 0x4,
195 .timer_bit = 0,
196 .clockevent_rating = 200,
197};
198
199static struct resource tmu00_resources[] = {
200 [0] = {
201 .name = "TMU00",
202 .start = 0xffd80008,
203 .end = 0xffd80013,
204 .flags = IORESOURCE_MEM,
205 },
206 [1] = {
207 .start = gic_spi(32),
208 .flags = IORESOURCE_IRQ,
209 },
210};
211
212static struct platform_device tmu00_device = {
213 .name = "sh_tmu",
214 .id = 0,
215 .dev = {
216 .platform_data = &tmu00_platform_data,
217 },
218 .resource = tmu00_resources,
219 .num_resources = ARRAY_SIZE(tmu00_resources),
220};
221
222static struct sh_timer_config tmu01_platform_data = {
223 .name = "TMU01",
224 .channel_offset = 0x10,
225 .timer_bit = 1,
226 .clocksource_rating = 200,
227};
228
229static struct resource tmu01_resources[] = {
230 [0] = {
231 .name = "TMU01",
232 .start = 0xffd80014,
233 .end = 0xffd8001f,
234 .flags = IORESOURCE_MEM,
235 },
236 [1] = {
237 .start = gic_spi(33),
238 .flags = IORESOURCE_IRQ,
239 },
240};
241
242static struct platform_device tmu01_device = {
243 .name = "sh_tmu",
244 .id = 1,
245 .dev = {
246 .platform_data = &tmu01_platform_data,
247 },
248 .resource = tmu01_resources,
249 .num_resources = ARRAY_SIZE(tmu01_resources),
250};
251
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700252/* I2C */
253static struct resource rcar_i2c0_res[] = {
254 {
255 .start = 0xffc70000,
256 .end = 0xffc70fff,
257 .flags = IORESOURCE_MEM,
258 }, {
259 .start = gic_spi(79),
260 .flags = IORESOURCE_IRQ,
261 },
262};
263
264static struct platform_device i2c0_device = {
265 .name = "i2c-rcar",
266 .id = 0,
267 .resource = rcar_i2c0_res,
268 .num_resources = ARRAY_SIZE(rcar_i2c0_res),
269};
270
271static struct resource rcar_i2c1_res[] = {
272 {
273 .start = 0xffc71000,
274 .end = 0xffc71fff,
275 .flags = IORESOURCE_MEM,
276 }, {
277 .start = gic_spi(82),
278 .flags = IORESOURCE_IRQ,
279 },
280};
281
282static struct platform_device i2c1_device = {
283 .name = "i2c-rcar",
284 .id = 1,
285 .resource = rcar_i2c1_res,
286 .num_resources = ARRAY_SIZE(rcar_i2c1_res),
287};
288
289static struct resource rcar_i2c2_res[] = {
290 {
291 .start = 0xffc72000,
292 .end = 0xffc72fff,
293 .flags = IORESOURCE_MEM,
294 }, {
295 .start = gic_spi(80),
296 .flags = IORESOURCE_IRQ,
297 },
298};
299
300static struct platform_device i2c2_device = {
301 .name = "i2c-rcar",
302 .id = 2,
303 .resource = rcar_i2c2_res,
304 .num_resources = ARRAY_SIZE(rcar_i2c2_res),
305};
306
307static struct resource rcar_i2c3_res[] = {
308 {
309 .start = 0xffc73000,
310 .end = 0xffc73fff,
311 .flags = IORESOURCE_MEM,
312 }, {
313 .start = gic_spi(81),
314 .flags = IORESOURCE_IRQ,
315 },
316};
317
318static struct platform_device i2c3_device = {
319 .name = "i2c-rcar",
320 .id = 3,
321 .resource = rcar_i2c3_res,
322 .num_resources = ARRAY_SIZE(rcar_i2c3_res),
323};
324
Simon Horman10e8d4f2012-11-21 22:00:15 +0900325static struct platform_device *r8a7779_early_devices_dt[] __initdata = {
Magnus Dammf411fad2011-12-14 01:36:12 +0900326 &scif0_device,
327 &scif1_device,
328 &scif2_device,
329 &scif3_device,
330 &scif4_device,
331 &scif5_device,
332 &tmu00_device,
333 &tmu01_device,
Simon Horman10e8d4f2012-11-21 22:00:15 +0900334};
335
336static struct platform_device *r8a7779_early_devices[] __initdata = {
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700337 &i2c0_device,
338 &i2c1_device,
339 &i2c2_device,
340 &i2c3_device,
Magnus Dammf411fad2011-12-14 01:36:12 +0900341};
342
Magnus Dammf411fad2011-12-14 01:36:12 +0900343void __init r8a7779_add_standard_devices(void)
344{
Magnus Damm8bac13f2012-03-01 12:48:03 +0900345#ifdef CONFIG_CACHE_L2X0
346 /* Early BRESP enable, Shared attribute override enable, 64K*16way */
Kuninori Morimotoed7d1322012-10-14 23:35:24 -0700347 l2x0_init(IOMEM(0xf0100000), 0x40470000, 0x82000fff);
Magnus Damm8bac13f2012-03-01 12:48:03 +0900348#endif
Magnus Damma662c082012-01-10 15:50:01 +0900349 r8a7779_pm_init();
350
Rafael J. Wysocki45e5ca52012-08-07 01:14:14 +0200351 r8a7779_init_pm_domains();
Magnus Damma662c082012-01-10 15:50:01 +0900352
Simon Horman10e8d4f2012-11-21 22:00:15 +0900353 platform_add_devices(r8a7779_early_devices_dt,
354 ARRAY_SIZE(r8a7779_early_devices_dt));
Magnus Dammf411fad2011-12-14 01:36:12 +0900355 platform_add_devices(r8a7779_early_devices,
356 ARRAY_SIZE(r8a7779_early_devices));
Magnus Dammf411fad2011-12-14 01:36:12 +0900357}
358
Magnus Dammb759bd12012-05-10 14:57:22 +0900359/* do nothing for !CONFIG_SMP or !CONFIG_HAVE_TWD */
360void __init __weak r8a7779_register_twd(void) { }
361
Stephen Warren6bb27d72012-11-08 12:40:59 -0700362void __init r8a7779_earlytimer_init(void)
Magnus Dammdf27a2d2012-03-06 17:37:01 +0900363{
364 r8a7779_clock_init();
365 shmobile_earlytimer_init();
Magnus Dammb759bd12012-05-10 14:57:22 +0900366 r8a7779_register_twd();
Magnus Dammdf27a2d2012-03-06 17:37:01 +0900367}
368
Magnus Dammf411fad2011-12-14 01:36:12 +0900369void __init r8a7779_add_early_devices(void)
370{
Simon Horman10e8d4f2012-11-21 22:00:15 +0900371 early_platform_add_devices(r8a7779_early_devices_dt,
372 ARRAY_SIZE(r8a7779_early_devices_dt));
Magnus Dammf411fad2011-12-14 01:36:12 +0900373 early_platform_add_devices(r8a7779_early_devices,
374 ARRAY_SIZE(r8a7779_early_devices));
Magnus Damm3e353b872012-02-29 21:37:43 +0900375
376 /* Early serial console setup is not included here due to
377 * memory map collisions. The SCIF serial ports in r8a7779
378 * are difficult to entity map 1:1 due to collision with the
379 * virtual memory range used by the coherent DMA code on ARM.
380 *
381 * Anyone wanting to debug early can remove UPF_IOREMAP from
382 * the sh-sci serial console platform data, adjust mapbase
383 * to a static M:N virt:phys mapping that needs to be added to
384 * the mappings passed with iotable_init() above.
385 *
386 * Then add a call to shmobile_setup_console() from this function.
387 *
388 * As a final step pass earlyprint=sh-sci.2,115200 on the kernel
389 * command line in case of the marzen board.
390 */
Magnus Dammf411fad2011-12-14 01:36:12 +0900391}
Simon Horman10e8d4f2012-11-21 22:00:15 +0900392
393#ifdef CONFIG_USE_OF
394void __init r8a7779_add_early_devices_dt(void)
395{
396 shmobile_setup_delay(1000, 2, 4); /* Cortex-A9 @ 1000MHz */
397
398 early_platform_add_devices(r8a7779_early_devices_dt,
399 ARRAY_SIZE(r8a7779_early_devices_dt));
400
401 /* Early serial console setup is not included here.
402 * See comment in r8a7779_add_early_devices().
403 */
404}
405
406static const struct of_dev_auxdata r8a7779_auxdata_lookup[] __initconst = {
407 {},
408};
409
410void __init r8a7779_add_standard_devices_dt(void)
411{
412 /* clocks are setup late during boot in the case of DT */
413 r8a7779_clock_init();
414
415 platform_add_devices(r8a7779_early_devices_dt,
416 ARRAY_SIZE(r8a7779_early_devices_dt));
417 of_platform_populate(NULL, of_default_bus_match_table,
418 r8a7779_auxdata_lookup, NULL);
419}
420
421static const char *r8a7779_compat_dt[] __initdata = {
422 "renesas,r8a7779",
423 NULL,
424};
425
426DT_MACHINE_START(SH73A0_DT, "Generic R8A7779 (Flattened Device Tree)")
427 .map_io = r8a7779_map_io,
428 .init_early = r8a7779_add_early_devices_dt,
429 .nr_irqs = NR_IRQS_LEGACY,
430 .init_irq = r8a7779_init_irq_dt,
431 .init_machine = r8a7779_add_standard_devices_dt,
432 .init_time = shmobile_timer_init,
433 .dt_compat = r8a7779_compat_dt,
434MACHINE_END
435#endif /* CONFIG_USE_OF */