blob: dbb13f289e797a2a0679ae5bc08fbd9cc297089f [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>
Laurent Pinchart37a72d02013-03-10 03:31:51 +010026#include <linux/platform_data/gpio-rcar.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090027#include <linux/platform_device.h>
28#include <linux/delay.h>
29#include <linux/input.h>
30#include <linux/io.h>
31#include <linux/serial_sci.h>
32#include <linux/sh_intc.h>
33#include <linux/sh_timer.h>
Vladimir Barinova7b98372013-02-27 23:39:14 +030034#include <linux/dma-mapping.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090035#include <mach/hardware.h>
Rob Herring250a2722012-01-03 16:57:33 -060036#include <mach/irqs.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090037#include <mach/r8a7779.h>
Magnus Damma662c082012-01-10 15:50:01 +090038#include <mach/common.h>
Magnus Dammf411fad2011-12-14 01:36:12 +090039#include <asm/mach-types.h>
40#include <asm/mach/arch.h>
Magnus Dammdf27a2d2012-03-06 17:37:01 +090041#include <asm/mach/time.h>
Magnus Damm3e353b872012-02-29 21:37:43 +090042#include <asm/mach/map.h>
Magnus Damm8bac13f2012-03-01 12:48:03 +090043#include <asm/hardware/cache-l2x0.h>
Magnus Damm3e353b872012-02-29 21:37:43 +090044
45static struct map_desc r8a7779_io_desc[] __initdata = {
46 /* 2M entity map for 0xf0000000 (MPCORE) */
47 {
48 .virtual = 0xf0000000,
49 .pfn = __phys_to_pfn(0xf0000000),
50 .length = SZ_2M,
51 .type = MT_DEVICE_NONSHARED
52 },
53 /* 16M entity map for 0xfexxxxxx (DMAC-S/HPBREG/INTC2/LRAM/DBSC) */
54 {
55 .virtual = 0xfe000000,
56 .pfn = __phys_to_pfn(0xfe000000),
57 .length = SZ_16M,
58 .type = MT_DEVICE_NONSHARED
59 },
60};
61
62void __init r8a7779_map_io(void)
63{
64 iotable_init(r8a7779_io_desc, ARRAY_SIZE(r8a7779_io_desc));
65}
Magnus Dammf411fad2011-12-14 01:36:12 +090066
Laurent Pinchart8b6edf32012-12-15 23:51:26 +010067static struct resource r8a7779_pfc_resources[] = {
Magnus Damm0ccaf5b2013-04-12 14:21:29 +020068 DEFINE_RES_MEM(0xfffc0000, 0x023c),
Laurent Pinchart8b6edf32012-12-15 23:51:26 +010069};
70
71static struct platform_device r8a7779_pfc_device = {
72 .name = "pfc-r8a7779",
73 .id = -1,
74 .resource = r8a7779_pfc_resources,
75 .num_resources = ARRAY_SIZE(r8a7779_pfc_resources),
76};
77
Laurent Pinchart37a72d02013-03-10 03:31:51 +010078#define R8A7779_GPIO(idx, npins) \
79static struct resource r8a7779_gpio##idx##_resources[] = { \
Magnus Damm0ccaf5b2013-04-12 14:21:29 +020080 DEFINE_RES_MEM(0xffc40000 + (0x1000 * (idx)), 0x002c), \
81 DEFINE_RES_IRQ(gic_iid(0xad + (idx))), \
Laurent Pinchart37a72d02013-03-10 03:31:51 +010082}; \
83 \
84static struct gpio_rcar_config r8a7779_gpio##idx##_platform_data = { \
85 .gpio_base = 32 * (idx), \
86 .irq_base = 0, \
87 .number_of_pins = npins, \
88 .pctl_name = "pfc-r8a7779", \
89}; \
90 \
91static struct platform_device r8a7779_gpio##idx##_device = { \
92 .name = "gpio_rcar", \
93 .id = idx, \
94 .resource = r8a7779_gpio##idx##_resources, \
95 .num_resources = ARRAY_SIZE(r8a7779_gpio##idx##_resources), \
96 .dev = { \
97 .platform_data = &r8a7779_gpio##idx##_platform_data, \
98 }, \
99}
100
101R8A7779_GPIO(0, 32);
102R8A7779_GPIO(1, 32);
103R8A7779_GPIO(2, 32);
104R8A7779_GPIO(3, 32);
105R8A7779_GPIO(4, 32);
106R8A7779_GPIO(5, 32);
107R8A7779_GPIO(6, 9);
108
109static struct platform_device *r8a7779_pinctrl_devices[] __initdata = {
110 &r8a7779_pfc_device,
111 &r8a7779_gpio0_device,
112 &r8a7779_gpio1_device,
113 &r8a7779_gpio2_device,
114 &r8a7779_gpio3_device,
115 &r8a7779_gpio4_device,
116 &r8a7779_gpio5_device,
117 &r8a7779_gpio6_device,
118};
119
Laurent Pinchart8b6edf32012-12-15 23:51:26 +0100120void __init r8a7779_pinmux_init(void)
121{
Laurent Pinchart37a72d02013-03-10 03:31:51 +0100122 platform_add_devices(r8a7779_pinctrl_devices,
123 ARRAY_SIZE(r8a7779_pinctrl_devices));
Laurent Pinchart8b6edf32012-12-15 23:51:26 +0100124}
125
Magnus Dammf411fad2011-12-14 01:36:12 +0900126static struct plat_sci_port scif0_platform_data = {
127 .mapbase = 0xffe40000,
128 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
129 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
130 .scbrr_algo_id = SCBRR_ALGO_2,
131 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800132 .irqs = SCIx_IRQ_MUXED(gic_iid(0x78)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900133};
134
135static struct platform_device scif0_device = {
136 .name = "sh-sci",
137 .id = 0,
138 .dev = {
139 .platform_data = &scif0_platform_data,
140 },
141};
142
143static struct plat_sci_port scif1_platform_data = {
144 .mapbase = 0xffe41000,
145 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
146 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
147 .scbrr_algo_id = SCBRR_ALGO_2,
148 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800149 .irqs = SCIx_IRQ_MUXED(gic_iid(0x79)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900150};
151
152static struct platform_device scif1_device = {
153 .name = "sh-sci",
154 .id = 1,
155 .dev = {
156 .platform_data = &scif1_platform_data,
157 },
158};
159
160static struct plat_sci_port scif2_platform_data = {
161 .mapbase = 0xffe42000,
162 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
163 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
164 .scbrr_algo_id = SCBRR_ALGO_2,
165 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800166 .irqs = SCIx_IRQ_MUXED(gic_iid(0x7a)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900167};
168
169static struct platform_device scif2_device = {
170 .name = "sh-sci",
171 .id = 2,
172 .dev = {
173 .platform_data = &scif2_platform_data,
174 },
175};
176
177static struct plat_sci_port scif3_platform_data = {
178 .mapbase = 0xffe43000,
179 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
180 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
181 .scbrr_algo_id = SCBRR_ALGO_2,
182 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800183 .irqs = SCIx_IRQ_MUXED(gic_iid(0x7b)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900184};
185
186static struct platform_device scif3_device = {
187 .name = "sh-sci",
188 .id = 3,
189 .dev = {
190 .platform_data = &scif3_platform_data,
191 },
192};
193
194static struct plat_sci_port scif4_platform_data = {
195 .mapbase = 0xffe44000,
196 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
197 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
198 .scbrr_algo_id = SCBRR_ALGO_2,
199 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800200 .irqs = SCIx_IRQ_MUXED(gic_iid(0x7c)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900201};
202
203static struct platform_device scif4_device = {
204 .name = "sh-sci",
205 .id = 4,
206 .dev = {
207 .platform_data = &scif4_platform_data,
208 },
209};
210
211static struct plat_sci_port scif5_platform_data = {
212 .mapbase = 0xffe45000,
213 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
214 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
215 .scbrr_algo_id = SCBRR_ALGO_2,
216 .type = PORT_SCIF,
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800217 .irqs = SCIx_IRQ_MUXED(gic_iid(0x7d)),
Magnus Dammf411fad2011-12-14 01:36:12 +0900218};
219
220static struct platform_device scif5_device = {
221 .name = "sh-sci",
222 .id = 5,
223 .dev = {
224 .platform_data = &scif5_platform_data,
225 },
226};
227
228/* TMU */
229static struct sh_timer_config tmu00_platform_data = {
230 .name = "TMU00",
231 .channel_offset = 0x4,
232 .timer_bit = 0,
233 .clockevent_rating = 200,
234};
235
236static struct resource tmu00_resources[] = {
237 [0] = {
238 .name = "TMU00",
239 .start = 0xffd80008,
240 .end = 0xffd80013,
241 .flags = IORESOURCE_MEM,
242 },
243 [1] = {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800244 .start = gic_iid(0x40),
Magnus Dammf411fad2011-12-14 01:36:12 +0900245 .flags = IORESOURCE_IRQ,
246 },
247};
248
249static struct platform_device tmu00_device = {
250 .name = "sh_tmu",
251 .id = 0,
252 .dev = {
253 .platform_data = &tmu00_platform_data,
254 },
255 .resource = tmu00_resources,
256 .num_resources = ARRAY_SIZE(tmu00_resources),
257};
258
259static struct sh_timer_config tmu01_platform_data = {
260 .name = "TMU01",
261 .channel_offset = 0x10,
262 .timer_bit = 1,
263 .clocksource_rating = 200,
264};
265
266static struct resource tmu01_resources[] = {
267 [0] = {
268 .name = "TMU01",
269 .start = 0xffd80014,
270 .end = 0xffd8001f,
271 .flags = IORESOURCE_MEM,
272 },
273 [1] = {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800274 .start = gic_iid(0x41),
Magnus Dammf411fad2011-12-14 01:36:12 +0900275 .flags = IORESOURCE_IRQ,
276 },
277};
278
279static struct platform_device tmu01_device = {
280 .name = "sh_tmu",
281 .id = 1,
282 .dev = {
283 .platform_data = &tmu01_platform_data,
284 },
285 .resource = tmu01_resources,
286 .num_resources = ARRAY_SIZE(tmu01_resources),
287};
288
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700289/* I2C */
290static struct resource rcar_i2c0_res[] = {
291 {
292 .start = 0xffc70000,
293 .end = 0xffc70fff,
294 .flags = IORESOURCE_MEM,
295 }, {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800296 .start = gic_iid(0x6f),
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700297 .flags = IORESOURCE_IRQ,
298 },
299};
300
301static struct platform_device i2c0_device = {
302 .name = "i2c-rcar",
303 .id = 0,
304 .resource = rcar_i2c0_res,
305 .num_resources = ARRAY_SIZE(rcar_i2c0_res),
306};
307
308static struct resource rcar_i2c1_res[] = {
309 {
310 .start = 0xffc71000,
311 .end = 0xffc71fff,
312 .flags = IORESOURCE_MEM,
313 }, {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800314 .start = gic_iid(0x72),
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700315 .flags = IORESOURCE_IRQ,
316 },
317};
318
319static struct platform_device i2c1_device = {
320 .name = "i2c-rcar",
321 .id = 1,
322 .resource = rcar_i2c1_res,
323 .num_resources = ARRAY_SIZE(rcar_i2c1_res),
324};
325
326static struct resource rcar_i2c2_res[] = {
327 {
328 .start = 0xffc72000,
329 .end = 0xffc72fff,
330 .flags = IORESOURCE_MEM,
331 }, {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800332 .start = gic_iid(0x70),
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700333 .flags = IORESOURCE_IRQ,
334 },
335};
336
337static struct platform_device i2c2_device = {
338 .name = "i2c-rcar",
339 .id = 2,
340 .resource = rcar_i2c2_res,
341 .num_resources = ARRAY_SIZE(rcar_i2c2_res),
342};
343
344static struct resource rcar_i2c3_res[] = {
345 {
346 .start = 0xffc73000,
347 .end = 0xffc73fff,
348 .flags = IORESOURCE_MEM,
349 }, {
Kuninori Morimotodbe95ad2013-03-03 23:11:41 -0800350 .start = gic_iid(0x71),
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700351 .flags = IORESOURCE_IRQ,
352 },
353};
354
355static struct platform_device i2c3_device = {
356 .name = "i2c-rcar",
357 .id = 3,
358 .resource = rcar_i2c3_res,
359 .num_resources = ARRAY_SIZE(rcar_i2c3_res),
360};
361
Vladimir Barinova7b98372013-02-27 23:39:14 +0300362static struct resource sata_resources[] = {
363 [0] = {
364 .name = "rcar-sata",
365 .start = 0xfc600000,
366 .end = 0xfc601fff,
367 .flags = IORESOURCE_MEM,
368 },
369 [1] = {
Sergei Shtylyovd60cd5f2013-03-08 02:31:03 +0300370 .start = gic_iid(0x84),
Vladimir Barinova7b98372013-02-27 23:39:14 +0300371 .flags = IORESOURCE_IRQ,
372 },
373};
374
375static struct platform_device sata_device = {
376 .name = "sata_rcar",
377 .id = -1,
378 .resource = sata_resources,
379 .num_resources = ARRAY_SIZE(sata_resources),
380 .dev = {
381 .dma_mask = &sata_device.dev.coherent_dma_mask,
382 .coherent_dma_mask = DMA_BIT_MASK(32),
383 },
384};
385
Sergei Shtylyovdace48d2013-04-04 18:53:50 +0000386/* Ether */
387static struct resource ether_resources[] = {
388 {
389 .start = 0xfde00000,
390 .end = 0xfde003ff,
391 .flags = IORESOURCE_MEM,
392 }, {
393 .start = gic_iid(0xb4),
394 .flags = IORESOURCE_IRQ,
395 },
396};
397
Simon Horman916ddc32013-02-19 10:53:05 +0900398static struct platform_device *r8a7779_devices_dt[] __initdata = {
Magnus Dammf411fad2011-12-14 01:36:12 +0900399 &scif0_device,
400 &scif1_device,
401 &scif2_device,
402 &scif3_device,
403 &scif4_device,
404 &scif5_device,
405 &tmu00_device,
406 &tmu01_device,
Simon Horman10e8d4f2012-11-21 22:00:15 +0900407};
408
Simon Hormane7921202013-02-19 10:53:05 +0900409static struct platform_device *r8a7779_late_devices[] __initdata = {
Kuninori Morimotoccc2a272012-10-10 19:56:51 -0700410 &i2c0_device,
411 &i2c1_device,
412 &i2c2_device,
413 &i2c3_device,
Vladimir Barinova7b98372013-02-27 23:39:14 +0300414 &sata_device,
Magnus Dammf411fad2011-12-14 01:36:12 +0900415};
416
Magnus Dammf411fad2011-12-14 01:36:12 +0900417void __init r8a7779_add_standard_devices(void)
418{
Magnus Damm8bac13f2012-03-01 12:48:03 +0900419#ifdef CONFIG_CACHE_L2X0
420 /* Early BRESP enable, Shared attribute override enable, 64K*16way */
Kuninori Morimotoed7d1322012-10-14 23:35:24 -0700421 l2x0_init(IOMEM(0xf0100000), 0x40470000, 0x82000fff);
Magnus Damm8bac13f2012-03-01 12:48:03 +0900422#endif
Magnus Damma662c082012-01-10 15:50:01 +0900423 r8a7779_pm_init();
424
Rafael J. Wysocki45e5ca52012-08-07 01:14:14 +0200425 r8a7779_init_pm_domains();
Magnus Damma662c082012-01-10 15:50:01 +0900426
Simon Horman916ddc32013-02-19 10:53:05 +0900427 platform_add_devices(r8a7779_devices_dt,
428 ARRAY_SIZE(r8a7779_devices_dt));
Simon Hormane7921202013-02-19 10:53:05 +0900429 platform_add_devices(r8a7779_late_devices,
430 ARRAY_SIZE(r8a7779_late_devices));
Magnus Dammf411fad2011-12-14 01:36:12 +0900431}
432
Sergei Shtylyovdace48d2013-04-04 18:53:50 +0000433void __init r8a7779_add_ether_device(struct sh_eth_plat_data *pdata)
434{
435 platform_device_register_resndata(&platform_bus, "sh_eth", -1,
436 ether_resources,
437 ARRAY_SIZE(ether_resources),
438 pdata, sizeof(*pdata));
439}
440
Magnus Dammb759bd12012-05-10 14:57:22 +0900441/* do nothing for !CONFIG_SMP or !CONFIG_HAVE_TWD */
442void __init __weak r8a7779_register_twd(void) { }
443
Stephen Warren6bb27d72012-11-08 12:40:59 -0700444void __init r8a7779_earlytimer_init(void)
Magnus Dammdf27a2d2012-03-06 17:37:01 +0900445{
446 r8a7779_clock_init();
447 shmobile_earlytimer_init();
Magnus Dammb759bd12012-05-10 14:57:22 +0900448 r8a7779_register_twd();
Magnus Dammdf27a2d2012-03-06 17:37:01 +0900449}
450
Magnus Dammf411fad2011-12-14 01:36:12 +0900451void __init r8a7779_add_early_devices(void)
452{
Simon Horman916ddc32013-02-19 10:53:05 +0900453 early_platform_add_devices(r8a7779_devices_dt,
454 ARRAY_SIZE(r8a7779_devices_dt));
Magnus Damm3e353b872012-02-29 21:37:43 +0900455
456 /* Early serial console setup is not included here due to
457 * memory map collisions. The SCIF serial ports in r8a7779
458 * are difficult to entity map 1:1 due to collision with the
459 * virtual memory range used by the coherent DMA code on ARM.
460 *
461 * Anyone wanting to debug early can remove UPF_IOREMAP from
462 * the sh-sci serial console platform data, adjust mapbase
463 * to a static M:N virt:phys mapping that needs to be added to
464 * the mappings passed with iotable_init() above.
465 *
466 * Then add a call to shmobile_setup_console() from this function.
467 *
468 * As a final step pass earlyprint=sh-sci.2,115200 on the kernel
469 * command line in case of the marzen board.
470 */
Magnus Dammf411fad2011-12-14 01:36:12 +0900471}
Simon Horman10e8d4f2012-11-21 22:00:15 +0900472
473#ifdef CONFIG_USE_OF
Simon Horman916ddc32013-02-19 10:53:05 +0900474void __init r8a7779_init_delay(void)
Simon Horman10e8d4f2012-11-21 22:00:15 +0900475{
476 shmobile_setup_delay(1000, 2, 4); /* Cortex-A9 @ 1000MHz */
Simon Horman10e8d4f2012-11-21 22:00:15 +0900477}
478
479static const struct of_dev_auxdata r8a7779_auxdata_lookup[] __initconst = {
480 {},
481};
482
483void __init r8a7779_add_standard_devices_dt(void)
484{
485 /* clocks are setup late during boot in the case of DT */
486 r8a7779_clock_init();
487
Simon Horman916ddc32013-02-19 10:53:05 +0900488 platform_add_devices(r8a7779_devices_dt,
489 ARRAY_SIZE(r8a7779_devices_dt));
Simon Horman10e8d4f2012-11-21 22:00:15 +0900490 of_platform_populate(NULL, of_default_bus_match_table,
491 r8a7779_auxdata_lookup, NULL);
492}
493
494static const char *r8a7779_compat_dt[] __initdata = {
495 "renesas,r8a7779",
496 NULL,
497};
498
Kuninori Morimotoabe0e142013-03-03 23:11:20 -0800499DT_MACHINE_START(R8A7779_DT, "Generic R8A7779 (Flattened Device Tree)")
Simon Horman10e8d4f2012-11-21 22:00:15 +0900500 .map_io = r8a7779_map_io,
Simon Horman916ddc32013-02-19 10:53:05 +0900501 .init_early = r8a7779_init_delay,
Simon Horman10e8d4f2012-11-21 22:00:15 +0900502 .nr_irqs = NR_IRQS_LEGACY,
503 .init_irq = r8a7779_init_irq_dt,
504 .init_machine = r8a7779_add_standard_devices_dt,
505 .init_time = shmobile_timer_init,
506 .dt_compat = r8a7779_compat_dt,
507MACHINE_END
508#endif /* CONFIG_USE_OF */