blob: 689ce67920d8c7bcfde8762003b1d006b0926838 [file] [log] [blame]
Magnus Dammf411fad2011-12-14 01:36:12 +09001/*
2 * r8a7779 processor support
3 *
Sergei Shtylyovdace48d2013-04-04 18:53:50 +00004 * Copyright (C) 2011, 2013 Renesas Solutions Corp.
Magnus Dammf411fad2011-12-14 01:36:12 +09005 * Copyright (C) 2011 Magnus Damm
Sergei Shtylyovdace48d2013-04-04 18:53:50 +00006 * Copyright (C) 2013 Cogent Embedded, Inc.
Magnus Dammf411fad2011-12-14 01:36:12 +09007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/interrupt.h>
24#include <linux/irq.h>
Simon Horman10e8d4f2012-11-21 22:00:15 +090025#include <linux/of_platform.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090026#include <linux/platform_device.h>
27#include <linux/delay.h>
28#include <linux/input.h>
29#include <linux/io.h>
30#include <linux/serial_sci.h>
31#include <linux/sh_intc.h>
32#include <linux/sh_timer.h>
Vladimir Barinova7b98372013-02-27 23:39:14 +030033#include <linux/dma-mapping.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090034#include <mach/hardware.h>
Rob Herring250a2722012-01-03 16:57:33 -060035#include <mach/irqs.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090036#include <mach/r8a7779.h>
Magnus Damma662c082012-01-10 15:50:01 +090037#include <mach/common.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090038#include <asm/mach-types.h>
39#include <asm/mach/arch.h>
Magnus Dammdf27a2d2012-03-06 17:37:01 +090040#include <asm/mach/time.h>
Magnus Damm3e353b872012-02-29 21:37:43 +090041#include <asm/mach/map.h>
Magnus Damm8bac13f2012-03-01 12:48:03 +090042#include <asm/hardware/cache-l2x0.h>
Magnus Damm3e353b872012-02-29 21:37:43 +090043
44static struct map_desc r8a7779_io_desc[] __initdata = {
45 /* 2M entity map for 0xf0000000 (MPCORE) */
46 {
47 .virtual = 0xf0000000,
48 .pfn = __phys_to_pfn(0xf0000000),
49 .length = SZ_2M,
50 .type = MT_DEVICE_NONSHARED
51 },
52 /* 16M entity map for 0xfexxxxxx (DMAC-S/HPBREG/INTC2/LRAM/DBSC) */
53 {
54 .virtual = 0xfe000000,
55 .pfn = __phys_to_pfn(0xfe000000),
56 .length = SZ_16M,
57 .type = MT_DEVICE_NONSHARED
58 },
59};
60
61void __init r8a7779_map_io(void)
62{
63 iotable_init(r8a7779_io_desc, ARRAY_SIZE(r8a7779_io_desc));
64}
Magnus Dammf411fad2011-12-14 01:36:12 +090065
Laurent Pinchart8b6edf32012-12-15 23:51:26 +010066static struct resource r8a7779_pfc_resources[] = {
67 [0] = {
68 .start = 0xfffc0000,
69 .end = 0xfffc023b,
70 .flags = IORESOURCE_MEM,
71 },
72 [1] = {
73 .start = 0xffc40000,
74 .end = 0xffc46fff,
75 .flags = IORESOURCE_MEM,
76 }
77};
78
79static struct platform_device r8a7779_pfc_device = {
80 .name = "pfc-r8a7779",
81 .id = -1,
82 .resource = r8a7779_pfc_resources,
83 .num_resources = ARRAY_SIZE(r8a7779_pfc_resources),
84};
85
86void __init r8a7779_pinmux_init(void)
87{
88 platform_device_register(&r8a7779_pfc_device);
89}
90
Magnus Dammf411fad2011-12-14 01:36:12 +090091static struct plat_sci_port scif0_platform_data = {
92 .mapbase = 0xffe40000,
93 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
94 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
95 .scbrr_algo_id = SCBRR_ALGO_2,
96 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -080097 .irqs = SCIx_IRQ_MUXED(gic_iid(0x78)),
Magnus Dammf411fad2011-12-14 01:36:12 +090098};
99
100static struct platform_device scif0_device = {
101 .name = "sh-sci",
102 .id = 0,
103 .dev = {
104 .platform_data = &scif0_platform_data,
105 },
106};
107
108static struct plat_sci_port scif1_platform_data = {
109 .mapbase = 0xffe41000,
110 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
111 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
112 .scbrr_algo_id = SCBRR_ALGO_2,
113 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800114 .irqs = SCIx_IRQ_MUXED(gic_iid(0x79)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900115};
116
117static struct platform_device scif1_device = {
118 .name = "sh-sci",
119 .id = 1,
120 .dev = {
121 .platform_data = &scif1_platform_data,
122 },
123};
124
125static struct plat_sci_port scif2_platform_data = {
126 .mapbase = 0xffe42000,
127 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
128 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
129 .scbrr_algo_id = SCBRR_ALGO_2,
130 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800131 .irqs = SCIx_IRQ_MUXED(gic_iid(0x7a)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900132};
133
134static struct platform_device scif2_device = {
135 .name = "sh-sci",
136 .id = 2,
137 .dev = {
138 .platform_data = &scif2_platform_data,
139 },
140};
141
142static struct plat_sci_port scif3_platform_data = {
143 .mapbase = 0xffe43000,
144 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
145 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
146 .scbrr_algo_id = SCBRR_ALGO_2,
147 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800148 .irqs = SCIx_IRQ_MUXED(gic_iid(0x7b)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900149};
150
151static struct platform_device scif3_device = {
152 .name = "sh-sci",
153 .id = 3,
154 .dev = {
155 .platform_data = &scif3_platform_data,
156 },
157};
158
159static struct plat_sci_port scif4_platform_data = {
160 .mapbase = 0xffe44000,
161 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
162 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
163 .scbrr_algo_id = SCBRR_ALGO_2,
164 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800165 .irqs = SCIx_IRQ_MUXED(gic_iid(0x7c)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900166};
167
168static struct platform_device scif4_device = {
169 .name = "sh-sci",
170 .id = 4,
171 .dev = {
172 .platform_data = &scif4_platform_data,
173 },
174};
175
176static struct plat_sci_port scif5_platform_data = {
177 .mapbase = 0xffe45000,
178 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
179 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
180 .scbrr_algo_id = SCBRR_ALGO_2,
181 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800182 .irqs = SCIx_IRQ_MUXED(gic_iid(0x7d)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900183};
184
185static struct platform_device scif5_device = {
186 .name = "sh-sci",
187 .id = 5,
188 .dev = {
189 .platform_data = &scif5_platform_data,
190 },
191};
192
193/* TMU */
194static struct sh_timer_config tmu00_platform_data = {
195 .name = "TMU00",
196 .channel_offset = 0x4,
197 .timer_bit = 0,
198 .clockevent_rating = 200,
199};
200
201static struct resource tmu00_resources[] = {
202 [0] = {
203 .name = "TMU00",
204 .start = 0xffd80008,
205 .end = 0xffd80013,
206 .flags = IORESOURCE_MEM,
207 },
208 [1] = {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800209 .start = gic_iid(0x40),
Magnus Dammf411fad2011-12-14 01:36:12 +0900210 .flags = IORESOURCE_IRQ,
211 },
212};
213
214static struct platform_device tmu00_device = {
215 .name = "sh_tmu",
216 .id = 0,
217 .dev = {
218 .platform_data = &tmu00_platform_data,
219 },
220 .resource = tmu00_resources,
221 .num_resources = ARRAY_SIZE(tmu00_resources),
222};
223
224static struct sh_timer_config tmu01_platform_data = {
225 .name = "TMU01",
226 .channel_offset = 0x10,
227 .timer_bit = 1,
228 .clocksource_rating = 200,
229};
230
231static struct resource tmu01_resources[] = {
232 [0] = {
233 .name = "TMU01",
234 .start = 0xffd80014,
235 .end = 0xffd8001f,
236 .flags = IORESOURCE_MEM,
237 },
238 [1] = {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800239 .start = gic_iid(0x41),
Magnus Dammf411fad2011-12-14 01:36:12 +0900240 .flags = IORESOURCE_IRQ,
241 },
242};
243
244static struct platform_device tmu01_device = {
245 .name = "sh_tmu",
246 .id = 1,
247 .dev = {
248 .platform_data = &tmu01_platform_data,
249 },
250 .resource = tmu01_resources,
251 .num_resources = ARRAY_SIZE(tmu01_resources),
252};
253
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700254/* I2C */
255static struct resource rcar_i2c0_res[] = {
256 {
257 .start = 0xffc70000,
258 .end = 0xffc70fff,
259 .flags = IORESOURCE_MEM,
260 }, {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800261 .start = gic_iid(0x6f),
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700262 .flags = IORESOURCE_IRQ,
263 },
264};
265
266static struct platform_device i2c0_device = {
267 .name = "i2c-rcar",
268 .id = 0,
269 .resource = rcar_i2c0_res,
270 .num_resources = ARRAY_SIZE(rcar_i2c0_res),
271};
272
273static struct resource rcar_i2c1_res[] = {
274 {
275 .start = 0xffc71000,
276 .end = 0xffc71fff,
277 .flags = IORESOURCE_MEM,
278 }, {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800279 .start = gic_iid(0x72),
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700280 .flags = IORESOURCE_IRQ,
281 },
282};
283
284static struct platform_device i2c1_device = {
285 .name = "i2c-rcar",
286 .id = 1,
287 .resource = rcar_i2c1_res,
288 .num_resources = ARRAY_SIZE(rcar_i2c1_res),
289};
290
291static struct resource rcar_i2c2_res[] = {
292 {
293 .start = 0xffc72000,
294 .end = 0xffc72fff,
295 .flags = IORESOURCE_MEM,
296 }, {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800297 .start = gic_iid(0x70),
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700298 .flags = IORESOURCE_IRQ,
299 },
300};
301
302static struct platform_device i2c2_device = {
303 .name = "i2c-rcar",
304 .id = 2,
305 .resource = rcar_i2c2_res,
306 .num_resources = ARRAY_SIZE(rcar_i2c2_res),
307};
308
309static struct resource rcar_i2c3_res[] = {
310 {
311 .start = 0xffc73000,
312 .end = 0xffc73fff,
313 .flags = IORESOURCE_MEM,
314 }, {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800315 .start = gic_iid(0x71),
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700316 .flags = IORESOURCE_IRQ,
317 },
318};
319
320static struct platform_device i2c3_device = {
321 .name = "i2c-rcar",
322 .id = 3,
323 .resource = rcar_i2c3_res,
324 .num_resources = ARRAY_SIZE(rcar_i2c3_res),
325};
326
Vladimir Barinova7b98372013-02-27 23:39:14 +0300327static struct resource sata_resources[] = {
328 [0] = {
329 .name = "rcar-sata",
330 .start = 0xfc600000,
331 .end = 0xfc601fff,
332 .flags = IORESOURCE_MEM,
333 },
334 [1] = {
Sergei Shtylyovd60cd5f2013-03-08 02:31:03 +0300335 .start = gic_iid(0x84),
Vladimir Barinova7b98372013-02-27 23:39:14 +0300336 .flags = IORESOURCE_IRQ,
337 },
338};
339
340static struct platform_device sata_device = {
341 .name = "sata_rcar",
342 .id = -1,
343 .resource = sata_resources,
344 .num_resources = ARRAY_SIZE(sata_resources),
345 .dev = {
346 .dma_mask = &sata_device.dev.coherent_dma_mask,
347 .coherent_dma_mask = DMA_BIT_MASK(32),
348 },
349};
350
Sergei Shtylyovdace48d2013-04-04 18:53:50 +0000351/* Ether */
352static struct resource ether_resources[] = {
353 {
354 .start = 0xfde00000,
355 .end = 0xfde003ff,
356 .flags = IORESOURCE_MEM,
357 }, {
358 .start = gic_iid(0xb4),
359 .flags = IORESOURCE_IRQ,
360 },
361};
362
Simon Horman916ddc32013-02-19 10:53:05 +0900363static struct platform_device *r8a7779_devices_dt[] __initdata = {
Magnus Dammf411fad2011-12-14 01:36:12 +0900364 &scif0_device,
365 &scif1_device,
366 &scif2_device,
367 &scif3_device,
368 &scif4_device,
369 &scif5_device,
370 &tmu00_device,
371 &tmu01_device,
Simon Horman10e8d4f2012-11-21 22:00:15 +0900372};
373
Simon Hormane7921202013-02-19 10:53:05 +0900374static struct platform_device *r8a7779_late_devices[] __initdata = {
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700375 &i2c0_device,
376 &i2c1_device,
377 &i2c2_device,
378 &i2c3_device,
Vladimir Barinova7b98372013-02-27 23:39:14 +0300379 &sata_device,
Magnus Dammf411fad2011-12-14 01:36:12 +0900380};
381
Magnus Dammf411fad2011-12-14 01:36:12 +0900382void __init r8a7779_add_standard_devices(void)
383{
Magnus Damm8bac13f2012-03-01 12:48:03 +0900384#ifdef CONFIG_CACHE_L2X0
385 /* Early BRESP enable, Shared attribute override enable, 64K*16way */
Kuninori Morimotoed7d1322012-10-14 23:35:24 -0700386 l2x0_init(IOMEM(0xf0100000), 0x40470000, 0x82000fff);
Magnus Damm8bac13f2012-03-01 12:48:03 +0900387#endif
Magnus Damma662c082012-01-10 15:50:01 +0900388 r8a7779_pm_init();
389
Rafael J. Wysocki45e5ca52012-08-07 01:14:14 +0200390 r8a7779_init_pm_domains();
Magnus Damma662c082012-01-10 15:50:01 +0900391
Simon Horman916ddc32013-02-19 10:53:05 +0900392 platform_add_devices(r8a7779_devices_dt,
393 ARRAY_SIZE(r8a7779_devices_dt));
Simon Hormane7921202013-02-19 10:53:05 +0900394 platform_add_devices(r8a7779_late_devices,
395 ARRAY_SIZE(r8a7779_late_devices));
Magnus Dammf411fad2011-12-14 01:36:12 +0900396}
397
Sergei Shtylyovdace48d2013-04-04 18:53:50 +0000398void __init r8a7779_add_ether_device(struct sh_eth_plat_data *pdata)
399{
400 platform_device_register_resndata(&platform_bus, "sh_eth", -1,
401 ether_resources,
402 ARRAY_SIZE(ether_resources),
403 pdata, sizeof(*pdata));
404}
405
Magnus Dammb759bd12012-05-10 14:57:22 +0900406/* do nothing for !CONFIG_SMP or !CONFIG_HAVE_TWD */
407void __init __weak r8a7779_register_twd(void) { }
408
Stephen Warren6bb27d72012-11-08 12:40:59 -0700409void __init r8a7779_earlytimer_init(void)
Magnus Dammdf27a2d2012-03-06 17:37:01 +0900410{
411 r8a7779_clock_init();
412 shmobile_earlytimer_init();
Magnus Dammb759bd12012-05-10 14:57:22 +0900413 r8a7779_register_twd();
Magnus Dammdf27a2d2012-03-06 17:37:01 +0900414}
415
Magnus Dammf411fad2011-12-14 01:36:12 +0900416void __init r8a7779_add_early_devices(void)
417{
Simon Horman916ddc32013-02-19 10:53:05 +0900418 early_platform_add_devices(r8a7779_devices_dt,
419 ARRAY_SIZE(r8a7779_devices_dt));
Magnus Damm3e353b872012-02-29 21:37:43 +0900420
421 /* Early serial console setup is not included here due to
422 * memory map collisions. The SCIF serial ports in r8a7779
423 * are difficult to entity map 1:1 due to collision with the
424 * virtual memory range used by the coherent DMA code on ARM.
425 *
426 * Anyone wanting to debug early can remove UPF_IOREMAP from
427 * the sh-sci serial console platform data, adjust mapbase
428 * to a static M:N virt:phys mapping that needs to be added to
429 * the mappings passed with iotable_init() above.
430 *
431 * Then add a call to shmobile_setup_console() from this function.
432 *
433 * As a final step pass earlyprint=sh-sci.2,115200 on the kernel
434 * command line in case of the marzen board.
435 */
Magnus Dammf411fad2011-12-14 01:36:12 +0900436}
Simon Horman10e8d4f2012-11-21 22:00:15 +0900437
438#ifdef CONFIG_USE_OF
Simon Horman916ddc32013-02-19 10:53:05 +0900439void __init r8a7779_init_delay(void)
Simon Horman10e8d4f2012-11-21 22:00:15 +0900440{
441 shmobile_setup_delay(1000, 2, 4); /* Cortex-A9 @ 1000MHz */
Simon Horman10e8d4f2012-11-21 22:00:15 +0900442}
443
444static const struct of_dev_auxdata r8a7779_auxdata_lookup[] __initconst = {
445 {},
446};
447
448void __init r8a7779_add_standard_devices_dt(void)
449{
450 /* clocks are setup late during boot in the case of DT */
451 r8a7779_clock_init();
452
Simon Horman916ddc32013-02-19 10:53:05 +0900453 platform_add_devices(r8a7779_devices_dt,
454 ARRAY_SIZE(r8a7779_devices_dt));
Simon Horman10e8d4f2012-11-21 22:00:15 +0900455 of_platform_populate(NULL, of_default_bus_match_table,
456 r8a7779_auxdata_lookup, NULL);
457}
458
459static const char *r8a7779_compat_dt[] __initdata = {
460 "renesas,r8a7779",
461 NULL,
462};
463
Kuninori Morimotoabe0e142013-03-03 23:11:20 -0800464DT_MACHINE_START(R8A7779_DT, "Generic R8A7779 (Flattened Device Tree)")
Simon Horman10e8d4f2012-11-21 22:00:15 +0900465 .map_io = r8a7779_map_io,
Simon Horman916ddc32013-02-19 10:53:05 +0900466 .init_early = r8a7779_init_delay,
Simon Horman10e8d4f2012-11-21 22:00:15 +0900467 .nr_irqs = NR_IRQS_LEGACY,
468 .init_irq = r8a7779_init_irq_dt,
469 .init_machine = r8a7779_add_standard_devices_dt,
470 .init_time = shmobile_timer_init,
471 .dt_compat = r8a7779_compat_dt,
472MACHINE_END
473#endif /* CONFIG_USE_OF */