2 * R8A7740 processor support
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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.
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.
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
20 #include <linux/delay.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
25 #include <linux/platform_device.h>
26 #include <linux/of_platform.h>
27 #include <linux/serial_sci.h>
28 #include <linux/sh_dma.h>
29 #include <linux/sh_timer.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/platform_data/sh_ipmmu.h>
32 #include <mach/dma-register.h>
33 #include <mach/r8a7740.h>
34 #include <mach/pm-rmobile.h>
35 #include <mach/common.h>
36 #include <mach/irqs.h>
37 #include <asm/mach-types.h>
38 #include <asm/mach/map.h>
39 #include <asm/mach/arch.h>
40 #include <asm/mach/time.h>
42 static struct map_desc r8a7740_io_desc[] __initdata = {
45 * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
48 .virtual = 0xe6000000,
49 .pfn = __phys_to_pfn(0xe6000000),
51 .type = MT_DEVICE_NONSHARED
53 #ifdef CONFIG_CACHE_L2X0
56 * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
59 .virtual = 0xf0002000,
60 .pfn = __phys_to_pfn(0xf0100000),
62 .type = MT_DEVICE_NONSHARED
67 void __init r8a7740_map_io(void)
69 iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
73 static struct plat_sci_port scif0_platform_data = {
74 .mapbase = 0xe6c40000,
75 .flags = UPF_BOOT_AUTOCONF,
76 .scscr = SCSCR_RE | SCSCR_TE,
77 .scbrr_algo_id = SCBRR_ALGO_4,
79 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
82 static struct platform_device scif0_device = {
86 .platform_data = &scif0_platform_data,
91 static struct plat_sci_port scif1_platform_data = {
92 .mapbase = 0xe6c50000,
93 .flags = UPF_BOOT_AUTOCONF,
94 .scscr = SCSCR_RE | SCSCR_TE,
95 .scbrr_algo_id = SCBRR_ALGO_4,
97 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
100 static struct platform_device scif1_device = {
104 .platform_data = &scif1_platform_data,
109 static struct plat_sci_port scif2_platform_data = {
110 .mapbase = 0xe6c60000,
111 .flags = UPF_BOOT_AUTOCONF,
112 .scscr = SCSCR_RE | SCSCR_TE,
113 .scbrr_algo_id = SCBRR_ALGO_4,
115 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
118 static struct platform_device scif2_device = {
122 .platform_data = &scif2_platform_data,
127 static struct plat_sci_port scif3_platform_data = {
128 .mapbase = 0xe6c70000,
129 .flags = UPF_BOOT_AUTOCONF,
130 .scscr = SCSCR_RE | SCSCR_TE,
131 .scbrr_algo_id = SCBRR_ALGO_4,
133 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
136 static struct platform_device scif3_device = {
140 .platform_data = &scif3_platform_data,
145 static struct plat_sci_port scif4_platform_data = {
146 .mapbase = 0xe6c80000,
147 .flags = UPF_BOOT_AUTOCONF,
148 .scscr = SCSCR_RE | SCSCR_TE,
149 .scbrr_algo_id = SCBRR_ALGO_4,
151 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
154 static struct platform_device scif4_device = {
158 .platform_data = &scif4_platform_data,
163 static struct plat_sci_port scif5_platform_data = {
164 .mapbase = 0xe6cb0000,
165 .flags = UPF_BOOT_AUTOCONF,
166 .scscr = SCSCR_RE | SCSCR_TE,
167 .scbrr_algo_id = SCBRR_ALGO_4,
169 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
172 static struct platform_device scif5_device = {
176 .platform_data = &scif5_platform_data,
181 static struct plat_sci_port scif6_platform_data = {
182 .mapbase = 0xe6cc0000,
183 .flags = UPF_BOOT_AUTOCONF,
184 .scscr = SCSCR_RE | SCSCR_TE,
185 .scbrr_algo_id = SCBRR_ALGO_4,
187 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
190 static struct platform_device scif6_device = {
194 .platform_data = &scif6_platform_data,
199 static struct plat_sci_port scif7_platform_data = {
200 .mapbase = 0xe6cd0000,
201 .flags = UPF_BOOT_AUTOCONF,
202 .scscr = SCSCR_RE | SCSCR_TE,
203 .scbrr_algo_id = SCBRR_ALGO_4,
205 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
208 static struct platform_device scif7_device = {
212 .platform_data = &scif7_platform_data,
217 static struct plat_sci_port scifb_platform_data = {
218 .mapbase = 0xe6c30000,
219 .flags = UPF_BOOT_AUTOCONF,
220 .scscr = SCSCR_RE | SCSCR_TE,
221 .scbrr_algo_id = SCBRR_ALGO_4,
223 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
226 static struct platform_device scifb_device = {
230 .platform_data = &scifb_platform_data,
235 static struct sh_timer_config cmt10_platform_data = {
237 .channel_offset = 0x10,
239 .clockevent_rating = 125,
240 .clocksource_rating = 125,
243 static struct resource cmt10_resources[] = {
248 .flags = IORESOURCE_MEM,
251 .start = evt2irq(0x0b00),
252 .flags = IORESOURCE_IRQ,
256 static struct platform_device cmt10_device = {
260 .platform_data = &cmt10_platform_data,
262 .resource = cmt10_resources,
263 .num_resources = ARRAY_SIZE(cmt10_resources),
266 /* IPMMUI (an IPMMU module for ICB/LMB) */
267 static struct resource ipmmu_resources[] = {
272 .flags = IORESOURCE_MEM,
276 static const char * const ipmmu_dev_names[] = {
277 "sh_mobile_lcdc_fb.0",
278 "sh_mobile_lcdc_fb.1",
282 static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
283 .dev_names = ipmmu_dev_names,
284 .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
287 static struct platform_device ipmmu_device = {
291 .platform_data = &ipmmu_platform_data,
293 .resource = ipmmu_resources,
294 .num_resources = ARRAY_SIZE(ipmmu_resources),
297 static struct platform_device *r8a7740_early_devices[] __initdata = {
312 static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
314 .slave_id = SHDMA_SLAVE_SDHI0_TX,
316 .chcr = CHCR_TX(XMIT_SZ_16BIT),
319 .slave_id = SHDMA_SLAVE_SDHI0_RX,
321 .chcr = CHCR_RX(XMIT_SZ_16BIT),
324 .slave_id = SHDMA_SLAVE_SDHI1_TX,
326 .chcr = CHCR_TX(XMIT_SZ_16BIT),
329 .slave_id = SHDMA_SLAVE_SDHI1_RX,
331 .chcr = CHCR_RX(XMIT_SZ_16BIT),
334 .slave_id = SHDMA_SLAVE_SDHI2_TX,
336 .chcr = CHCR_TX(XMIT_SZ_16BIT),
339 .slave_id = SHDMA_SLAVE_SDHI2_RX,
341 .chcr = CHCR_RX(XMIT_SZ_16BIT),
344 .slave_id = SHDMA_SLAVE_FSIA_TX,
346 .chcr = CHCR_TX(XMIT_SZ_32BIT),
349 .slave_id = SHDMA_SLAVE_FSIA_RX,
351 .chcr = CHCR_RX(XMIT_SZ_32BIT),
354 .slave_id = SHDMA_SLAVE_FSIB_TX,
356 .chcr = CHCR_TX(XMIT_SZ_32BIT),
361 #define DMA_CHANNEL(a, b, c) \
366 .chclr_offset = (0x220 - 0x20) + a \
369 static const struct sh_dmae_channel r8a7740_dmae_channels[] = {
370 DMA_CHANNEL(0x00, 0, 0),
371 DMA_CHANNEL(0x10, 0, 8),
372 DMA_CHANNEL(0x20, 4, 0),
373 DMA_CHANNEL(0x30, 4, 8),
374 DMA_CHANNEL(0x50, 8, 0),
375 DMA_CHANNEL(0x60, 8, 8),
378 static struct sh_dmae_pdata dma_platform_data = {
379 .slave = r8a7740_dmae_slaves,
380 .slave_num = ARRAY_SIZE(r8a7740_dmae_slaves),
381 .channel = r8a7740_dmae_channels,
382 .channel_num = ARRAY_SIZE(r8a7740_dmae_channels),
383 .ts_low_shift = TS_LOW_SHIFT,
384 .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
385 .ts_high_shift = TS_HI_SHIFT,
386 .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
387 .ts_shift = dma_ts_shift,
388 .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
389 .dmaor_init = DMAOR_DME,
393 /* Resource order important! */
394 static struct resource r8a7740_dmae0_resources[] = {
396 /* Channel registers and DMAOR */
399 .flags = IORESOURCE_MEM,
405 .flags = IORESOURCE_MEM,
409 .start = evt2irq(0x20c0),
410 .end = evt2irq(0x20c0),
411 .flags = IORESOURCE_IRQ,
414 /* IRQ for channels 0-5 */
415 .start = evt2irq(0x2000),
416 .end = evt2irq(0x20a0),
417 .flags = IORESOURCE_IRQ,
421 /* Resource order important! */
422 static struct resource r8a7740_dmae1_resources[] = {
424 /* Channel registers and DMAOR */
427 .flags = IORESOURCE_MEM,
433 .flags = IORESOURCE_MEM,
437 .start = evt2irq(0x21c0),
438 .end = evt2irq(0x21c0),
439 .flags = IORESOURCE_IRQ,
442 /* IRQ for channels 0-5 */
443 .start = evt2irq(0x2100),
444 .end = evt2irq(0x21a0),
445 .flags = IORESOURCE_IRQ,
449 /* Resource order important! */
450 static struct resource r8a7740_dmae2_resources[] = {
452 /* Channel registers and DMAOR */
455 .flags = IORESOURCE_MEM,
461 .flags = IORESOURCE_MEM,
465 .start = evt2irq(0x22c0),
466 .end = evt2irq(0x22c0),
467 .flags = IORESOURCE_IRQ,
470 /* IRQ for channels 0-5 */
471 .start = evt2irq(0x2200),
472 .end = evt2irq(0x22a0),
473 .flags = IORESOURCE_IRQ,
477 static struct platform_device dma0_device = {
478 .name = "sh-dma-engine",
480 .resource = r8a7740_dmae0_resources,
481 .num_resources = ARRAY_SIZE(r8a7740_dmae0_resources),
483 .platform_data = &dma_platform_data,
487 static struct platform_device dma1_device = {
488 .name = "sh-dma-engine",
490 .resource = r8a7740_dmae1_resources,
491 .num_resources = ARRAY_SIZE(r8a7740_dmae1_resources),
493 .platform_data = &dma_platform_data,
497 static struct platform_device dma2_device = {
498 .name = "sh-dma-engine",
500 .resource = r8a7740_dmae2_resources,
501 .num_resources = ARRAY_SIZE(r8a7740_dmae2_resources),
503 .platform_data = &dma_platform_data,
508 static const struct sh_dmae_channel r8a7740_usb_dma_channels[] = {
516 static const struct sh_dmae_slave_config r8a7740_usb_dma_slaves[] = {
518 .slave_id = SHDMA_SLAVE_USBHS_TX,
519 .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
521 .slave_id = SHDMA_SLAVE_USBHS_RX,
522 .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
526 static struct sh_dmae_pdata usb_dma_platform_data = {
527 .slave = r8a7740_usb_dma_slaves,
528 .slave_num = ARRAY_SIZE(r8a7740_usb_dma_slaves),
529 .channel = r8a7740_usb_dma_channels,
530 .channel_num = ARRAY_SIZE(r8a7740_usb_dma_channels),
531 .ts_low_shift = USBTS_LOW_SHIFT,
532 .ts_low_mask = USBTS_LOW_BIT << USBTS_LOW_SHIFT,
533 .ts_high_shift = USBTS_HI_SHIFT,
534 .ts_high_mask = USBTS_HI_BIT << USBTS_HI_SHIFT,
535 .ts_shift = dma_usbts_shift,
536 .ts_shift_num = ARRAY_SIZE(dma_usbts_shift),
537 .dmaor_init = DMAOR_DME,
539 .chcr_ie_bit = 1 << 5,
546 static struct resource r8a7740_usb_dma_resources[] = {
548 /* Channel registers and DMAOR */
550 .end = 0xe68a0064 - 1,
551 .flags = IORESOURCE_MEM,
556 .end = 0xe68a0014 - 1,
557 .flags = IORESOURCE_MEM,
560 /* IRQ for channels */
561 .start = evt2irq(0x0a00),
562 .end = evt2irq(0x0a00),
563 .flags = IORESOURCE_IRQ,
567 static struct platform_device usb_dma_device = {
568 .name = "sh-dma-engine",
570 .resource = r8a7740_usb_dma_resources,
571 .num_resources = ARRAY_SIZE(r8a7740_usb_dma_resources),
573 .platform_data = &usb_dma_platform_data,
578 static struct resource i2c0_resources[] = {
582 .end = 0xfff20425 - 1,
583 .flags = IORESOURCE_MEM,
586 .start = intcs_evt2irq(0xe00),
587 .end = intcs_evt2irq(0xe60),
588 .flags = IORESOURCE_IRQ,
592 static struct resource i2c1_resources[] = {
596 .end = 0xe6c20425 - 1,
597 .flags = IORESOURCE_MEM,
600 .start = evt2irq(0x780), /* IIC1_ALI1 */
601 .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
602 .flags = IORESOURCE_IRQ,
606 static struct platform_device i2c0_device = {
607 .name = "i2c-sh_mobile",
609 .resource = i2c0_resources,
610 .num_resources = ARRAY_SIZE(i2c0_resources),
613 static struct platform_device i2c1_device = {
614 .name = "i2c-sh_mobile",
616 .resource = i2c1_resources,
617 .num_resources = ARRAY_SIZE(i2c1_resources),
620 static struct resource pmu_resources[] = {
622 .start = evt2irq(0x19a0),
623 .end = evt2irq(0x19a0),
624 .flags = IORESOURCE_IRQ,
628 static struct platform_device pmu_device = {
631 .num_resources = ARRAY_SIZE(pmu_resources),
632 .resource = pmu_resources,
635 static struct platform_device *r8a7740_late_devices[] __initdata = {
646 * r8a7740 chip has lasting errata on MERAM buffer.
647 * this is work-around for it.
649 * "Media RAM (MERAM)" on r8a7740 documentation
651 #define MEBUFCNTR 0xFE950098
652 void r8a7740_meram_workaround(void)
656 reg = ioremap_nocache(MEBUFCNTR, 4);
658 iowrite32(0x01600164, reg);
664 #define ICSTART 0x0070
666 #define i2c_read(reg, offset) ioread8(reg + offset)
667 #define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
670 * r8a7740 chip has lasting errata on I2C I/O pad reset.
671 * this is work-around for it.
673 static void r8a7740_i2c_workaround(struct platform_device *pdev)
675 struct resource *res;
678 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
679 if (unlikely(!res)) {
680 pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
684 reg = ioremap(res->start, resource_size(res));
685 if (unlikely(!reg)) {
686 pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
690 i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
691 i2c_read(reg, ICCR); /* dummy read */
693 i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
694 i2c_read(reg, ICSTART); /* dummy read */
698 i2c_write(reg, ICCR, 0x01);
699 i2c_write(reg, ICSTART, 0x00);
703 i2c_write(reg, ICCR, 0x10);
705 i2c_write(reg, ICCR, 0x00);
707 i2c_write(reg, ICCR, 0x10);
713 void __init r8a7740_add_standard_devices(void)
715 /* I2C work-around */
716 r8a7740_i2c_workaround(&i2c0_device);
717 r8a7740_i2c_workaround(&i2c1_device);
719 r8a7740_init_pm_domains();
722 platform_add_devices(r8a7740_early_devices,
723 ARRAY_SIZE(r8a7740_early_devices));
724 platform_add_devices(r8a7740_late_devices,
725 ARRAY_SIZE(r8a7740_late_devices));
727 /* add devices to PM domain */
729 rmobile_add_device_to_domain("A3SP", &scif0_device);
730 rmobile_add_device_to_domain("A3SP", &scif1_device);
731 rmobile_add_device_to_domain("A3SP", &scif2_device);
732 rmobile_add_device_to_domain("A3SP", &scif3_device);
733 rmobile_add_device_to_domain("A3SP", &scif4_device);
734 rmobile_add_device_to_domain("A3SP", &scif5_device);
735 rmobile_add_device_to_domain("A3SP", &scif6_device);
736 rmobile_add_device_to_domain("A3SP", &scif7_device);
737 rmobile_add_device_to_domain("A3SP", &scifb_device);
738 rmobile_add_device_to_domain("A3SP", &i2c1_device);
741 static void __init r8a7740_earlytimer_init(void)
743 r8a7740_clock_init(0);
744 shmobile_earlytimer_init();
747 void __init r8a7740_add_early_devices(void)
749 early_platform_add_devices(r8a7740_early_devices,
750 ARRAY_SIZE(r8a7740_early_devices));
752 /* setup early console here as well */
753 shmobile_setup_console();
755 /* override timer setup with soc-specific code */
756 shmobile_timer.init = r8a7740_earlytimer_init;
761 void __init r8a7740_add_early_devices_dt(void)
763 shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
765 early_platform_add_devices(r8a7740_early_devices,
766 ARRAY_SIZE(r8a7740_early_devices));
768 /* setup early console here as well */
769 shmobile_setup_console();
772 static const struct of_dev_auxdata r8a7740_auxdata_lookup[] __initconst = {
776 void __init r8a7740_add_standard_devices_dt(void)
778 /* clocks are setup late during boot in the case of DT */
779 r8a7740_clock_init(0);
781 platform_add_devices(r8a7740_early_devices,
782 ARRAY_SIZE(r8a7740_early_devices));
784 of_platform_populate(NULL, of_default_bus_match_table,
785 r8a7740_auxdata_lookup, NULL);
788 static const char *r8a7740_boards_compat_dt[] __initdata = {
793 DT_MACHINE_START(R8A7740_DT, "Generic R8A7740 (Flattened Device Tree)")
794 .map_io = r8a7740_map_io,
795 .init_early = r8a7740_add_early_devices_dt,
796 .init_irq = r8a7740_init_irq,
797 .handle_irq = shmobile_handle_irq_intc,
798 .init_machine = r8a7740_add_standard_devices_dt,
799 .timer = &shmobile_timer,
800 .dt_compat = r8a7740_boards_compat_dt,
803 #endif /* CONFIG_USE_OF */