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 <mach/dma-register.h>
31 #include <mach/r8a7740.h>
32 #include <mach/pm-rmobile.h>
33 #include <mach/common.h>
34 #include <mach/irqs.h>
35 #include <asm/mach-types.h>
36 #include <asm/mach/map.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/time.h>
40 static struct map_desc r8a7740_io_desc[] __initdata = {
43 * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
46 .virtual = 0xe6000000,
47 .pfn = __phys_to_pfn(0xe6000000),
49 .type = MT_DEVICE_NONSHARED
51 #ifdef CONFIG_CACHE_L2X0
54 * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
57 .virtual = 0xf0002000,
58 .pfn = __phys_to_pfn(0xf0100000),
60 .type = MT_DEVICE_NONSHARED
65 void __init r8a7740_map_io(void)
67 iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
71 static struct resource r8a7740_pfc_resources[] = {
75 .flags = IORESOURCE_MEM,
80 .flags = IORESOURCE_MEM,
84 static struct platform_device r8a7740_pfc_device = {
85 .name = "pfc-r8a7740",
87 .resource = r8a7740_pfc_resources,
88 .num_resources = ARRAY_SIZE(r8a7740_pfc_resources),
91 void __init r8a7740_pinmux_init(void)
93 platform_device_register(&r8a7740_pfc_device);
97 static struct plat_sci_port scif0_platform_data = {
98 .mapbase = 0xe6c40000,
99 .flags = UPF_BOOT_AUTOCONF,
100 .scscr = SCSCR_RE | SCSCR_TE,
101 .scbrr_algo_id = SCBRR_ALGO_4,
103 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
106 static struct platform_device scif0_device = {
110 .platform_data = &scif0_platform_data,
115 static struct plat_sci_port scif1_platform_data = {
116 .mapbase = 0xe6c50000,
117 .flags = UPF_BOOT_AUTOCONF,
118 .scscr = SCSCR_RE | SCSCR_TE,
119 .scbrr_algo_id = SCBRR_ALGO_4,
121 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
124 static struct platform_device scif1_device = {
128 .platform_data = &scif1_platform_data,
133 static struct plat_sci_port scif2_platform_data = {
134 .mapbase = 0xe6c60000,
135 .flags = UPF_BOOT_AUTOCONF,
136 .scscr = SCSCR_RE | SCSCR_TE,
137 .scbrr_algo_id = SCBRR_ALGO_4,
139 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
142 static struct platform_device scif2_device = {
146 .platform_data = &scif2_platform_data,
151 static struct plat_sci_port scif3_platform_data = {
152 .mapbase = 0xe6c70000,
153 .flags = UPF_BOOT_AUTOCONF,
154 .scscr = SCSCR_RE | SCSCR_TE,
155 .scbrr_algo_id = SCBRR_ALGO_4,
157 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
160 static struct platform_device scif3_device = {
164 .platform_data = &scif3_platform_data,
169 static struct plat_sci_port scif4_platform_data = {
170 .mapbase = 0xe6c80000,
171 .flags = UPF_BOOT_AUTOCONF,
172 .scscr = SCSCR_RE | SCSCR_TE,
173 .scbrr_algo_id = SCBRR_ALGO_4,
175 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
178 static struct platform_device scif4_device = {
182 .platform_data = &scif4_platform_data,
187 static struct plat_sci_port scif5_platform_data = {
188 .mapbase = 0xe6cb0000,
189 .flags = UPF_BOOT_AUTOCONF,
190 .scscr = SCSCR_RE | SCSCR_TE,
191 .scbrr_algo_id = SCBRR_ALGO_4,
193 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
196 static struct platform_device scif5_device = {
200 .platform_data = &scif5_platform_data,
205 static struct plat_sci_port scif6_platform_data = {
206 .mapbase = 0xe6cc0000,
207 .flags = UPF_BOOT_AUTOCONF,
208 .scscr = SCSCR_RE | SCSCR_TE,
209 .scbrr_algo_id = SCBRR_ALGO_4,
211 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
214 static struct platform_device scif6_device = {
218 .platform_data = &scif6_platform_data,
223 static struct plat_sci_port scif7_platform_data = {
224 .mapbase = 0xe6cd0000,
225 .flags = UPF_BOOT_AUTOCONF,
226 .scscr = SCSCR_RE | SCSCR_TE,
227 .scbrr_algo_id = SCBRR_ALGO_4,
229 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
232 static struct platform_device scif7_device = {
236 .platform_data = &scif7_platform_data,
241 static struct plat_sci_port scifb_platform_data = {
242 .mapbase = 0xe6c30000,
243 .flags = UPF_BOOT_AUTOCONF,
244 .scscr = SCSCR_RE | SCSCR_TE,
245 .scbrr_algo_id = SCBRR_ALGO_4,
247 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
250 static struct platform_device scifb_device = {
254 .platform_data = &scifb_platform_data,
259 static struct sh_timer_config cmt10_platform_data = {
261 .channel_offset = 0x10,
263 .clockevent_rating = 125,
264 .clocksource_rating = 125,
267 static struct resource cmt10_resources[] = {
272 .flags = IORESOURCE_MEM,
275 .start = evt2irq(0x0b00),
276 .flags = IORESOURCE_IRQ,
280 static struct platform_device cmt10_device = {
284 .platform_data = &cmt10_platform_data,
286 .resource = cmt10_resources,
287 .num_resources = ARRAY_SIZE(cmt10_resources),
291 static struct sh_timer_config tmu00_platform_data = {
293 .channel_offset = 0x4,
295 .clockevent_rating = 200,
298 static struct resource tmu00_resources[] = {
302 .end = 0xfff80014 - 1,
303 .flags = IORESOURCE_MEM,
306 .start = intcs_evt2irq(0xe80),
307 .flags = IORESOURCE_IRQ,
311 static struct platform_device tmu00_device = {
315 .platform_data = &tmu00_platform_data,
317 .resource = tmu00_resources,
318 .num_resources = ARRAY_SIZE(tmu00_resources),
321 static struct sh_timer_config tmu01_platform_data = {
323 .channel_offset = 0x10,
325 .clocksource_rating = 200,
328 static struct resource tmu01_resources[] = {
332 .end = 0xfff80020 - 1,
333 .flags = IORESOURCE_MEM,
336 .start = intcs_evt2irq(0xea0),
337 .flags = IORESOURCE_IRQ,
341 static struct platform_device tmu01_device = {
345 .platform_data = &tmu01_platform_data,
347 .resource = tmu01_resources,
348 .num_resources = ARRAY_SIZE(tmu01_resources),
351 static struct sh_timer_config tmu02_platform_data = {
353 .channel_offset = 0x1C,
355 .clocksource_rating = 200,
358 static struct resource tmu02_resources[] = {
362 .end = 0xfff8002C - 1,
363 .flags = IORESOURCE_MEM,
366 .start = intcs_evt2irq(0xec0),
367 .flags = IORESOURCE_IRQ,
371 static struct platform_device tmu02_device = {
375 .platform_data = &tmu02_platform_data,
377 .resource = tmu02_resources,
378 .num_resources = ARRAY_SIZE(tmu02_resources),
381 static struct platform_device *r8a7740_early_devices[] __initdata = {
398 static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
400 .slave_id = SHDMA_SLAVE_SDHI0_TX,
402 .chcr = CHCR_TX(XMIT_SZ_16BIT),
405 .slave_id = SHDMA_SLAVE_SDHI0_RX,
407 .chcr = CHCR_RX(XMIT_SZ_16BIT),
410 .slave_id = SHDMA_SLAVE_SDHI1_TX,
412 .chcr = CHCR_TX(XMIT_SZ_16BIT),
415 .slave_id = SHDMA_SLAVE_SDHI1_RX,
417 .chcr = CHCR_RX(XMIT_SZ_16BIT),
420 .slave_id = SHDMA_SLAVE_SDHI2_TX,
422 .chcr = CHCR_TX(XMIT_SZ_16BIT),
425 .slave_id = SHDMA_SLAVE_SDHI2_RX,
427 .chcr = CHCR_RX(XMIT_SZ_16BIT),
430 .slave_id = SHDMA_SLAVE_FSIA_TX,
432 .chcr = CHCR_TX(XMIT_SZ_32BIT),
435 .slave_id = SHDMA_SLAVE_FSIA_RX,
437 .chcr = CHCR_RX(XMIT_SZ_32BIT),
440 .slave_id = SHDMA_SLAVE_FSIB_TX,
442 .chcr = CHCR_TX(XMIT_SZ_32BIT),
447 #define DMA_CHANNEL(a, b, c) \
452 .chclr_offset = (0x220 - 0x20) + a \
455 static const struct sh_dmae_channel r8a7740_dmae_channels[] = {
456 DMA_CHANNEL(0x00, 0, 0),
457 DMA_CHANNEL(0x10, 0, 8),
458 DMA_CHANNEL(0x20, 4, 0),
459 DMA_CHANNEL(0x30, 4, 8),
460 DMA_CHANNEL(0x50, 8, 0),
461 DMA_CHANNEL(0x60, 8, 8),
464 static struct sh_dmae_pdata dma_platform_data = {
465 .slave = r8a7740_dmae_slaves,
466 .slave_num = ARRAY_SIZE(r8a7740_dmae_slaves),
467 .channel = r8a7740_dmae_channels,
468 .channel_num = ARRAY_SIZE(r8a7740_dmae_channels),
469 .ts_low_shift = TS_LOW_SHIFT,
470 .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
471 .ts_high_shift = TS_HI_SHIFT,
472 .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
473 .ts_shift = dma_ts_shift,
474 .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
475 .dmaor_init = DMAOR_DME,
479 /* Resource order important! */
480 static struct resource r8a7740_dmae0_resources[] = {
482 /* Channel registers and DMAOR */
485 .flags = IORESOURCE_MEM,
491 .flags = IORESOURCE_MEM,
495 .start = evt2irq(0x20c0),
496 .end = evt2irq(0x20c0),
497 .flags = IORESOURCE_IRQ,
500 /* IRQ for channels 0-5 */
501 .start = evt2irq(0x2000),
502 .end = evt2irq(0x20a0),
503 .flags = IORESOURCE_IRQ,
507 /* Resource order important! */
508 static struct resource r8a7740_dmae1_resources[] = {
510 /* Channel registers and DMAOR */
513 .flags = IORESOURCE_MEM,
519 .flags = IORESOURCE_MEM,
523 .start = evt2irq(0x21c0),
524 .end = evt2irq(0x21c0),
525 .flags = IORESOURCE_IRQ,
528 /* IRQ for channels 0-5 */
529 .start = evt2irq(0x2100),
530 .end = evt2irq(0x21a0),
531 .flags = IORESOURCE_IRQ,
535 /* Resource order important! */
536 static struct resource r8a7740_dmae2_resources[] = {
538 /* Channel registers and DMAOR */
541 .flags = IORESOURCE_MEM,
547 .flags = IORESOURCE_MEM,
551 .start = evt2irq(0x22c0),
552 .end = evt2irq(0x22c0),
553 .flags = IORESOURCE_IRQ,
556 /* IRQ for channels 0-5 */
557 .start = evt2irq(0x2200),
558 .end = evt2irq(0x22a0),
559 .flags = IORESOURCE_IRQ,
563 static struct platform_device dma0_device = {
564 .name = "sh-dma-engine",
566 .resource = r8a7740_dmae0_resources,
567 .num_resources = ARRAY_SIZE(r8a7740_dmae0_resources),
569 .platform_data = &dma_platform_data,
573 static struct platform_device dma1_device = {
574 .name = "sh-dma-engine",
576 .resource = r8a7740_dmae1_resources,
577 .num_resources = ARRAY_SIZE(r8a7740_dmae1_resources),
579 .platform_data = &dma_platform_data,
583 static struct platform_device dma2_device = {
584 .name = "sh-dma-engine",
586 .resource = r8a7740_dmae2_resources,
587 .num_resources = ARRAY_SIZE(r8a7740_dmae2_resources),
589 .platform_data = &dma_platform_data,
594 static const struct sh_dmae_channel r8a7740_usb_dma_channels[] = {
602 static const struct sh_dmae_slave_config r8a7740_usb_dma_slaves[] = {
604 .slave_id = SHDMA_SLAVE_USBHS_TX,
605 .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
607 .slave_id = SHDMA_SLAVE_USBHS_RX,
608 .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
612 static struct sh_dmae_pdata usb_dma_platform_data = {
613 .slave = r8a7740_usb_dma_slaves,
614 .slave_num = ARRAY_SIZE(r8a7740_usb_dma_slaves),
615 .channel = r8a7740_usb_dma_channels,
616 .channel_num = ARRAY_SIZE(r8a7740_usb_dma_channels),
617 .ts_low_shift = USBTS_LOW_SHIFT,
618 .ts_low_mask = USBTS_LOW_BIT << USBTS_LOW_SHIFT,
619 .ts_high_shift = USBTS_HI_SHIFT,
620 .ts_high_mask = USBTS_HI_BIT << USBTS_HI_SHIFT,
621 .ts_shift = dma_usbts_shift,
622 .ts_shift_num = ARRAY_SIZE(dma_usbts_shift),
623 .dmaor_init = DMAOR_DME,
625 .chcr_ie_bit = 1 << 5,
632 static struct resource r8a7740_usb_dma_resources[] = {
634 /* Channel registers and DMAOR */
636 .end = 0xe68a0064 - 1,
637 .flags = IORESOURCE_MEM,
642 .end = 0xe68a0014 - 1,
643 .flags = IORESOURCE_MEM,
646 /* IRQ for channels */
647 .start = evt2irq(0x0a00),
648 .end = evt2irq(0x0a00),
649 .flags = IORESOURCE_IRQ,
653 static struct platform_device usb_dma_device = {
654 .name = "sh-dma-engine",
656 .resource = r8a7740_usb_dma_resources,
657 .num_resources = ARRAY_SIZE(r8a7740_usb_dma_resources),
659 .platform_data = &usb_dma_platform_data,
664 static struct resource i2c0_resources[] = {
668 .end = 0xfff20425 - 1,
669 .flags = IORESOURCE_MEM,
672 .start = intcs_evt2irq(0xe00),
673 .end = intcs_evt2irq(0xe60),
674 .flags = IORESOURCE_IRQ,
678 static struct resource i2c1_resources[] = {
682 .end = 0xe6c20425 - 1,
683 .flags = IORESOURCE_MEM,
686 .start = evt2irq(0x780), /* IIC1_ALI1 */
687 .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
688 .flags = IORESOURCE_IRQ,
692 static struct platform_device i2c0_device = {
693 .name = "i2c-sh_mobile",
695 .resource = i2c0_resources,
696 .num_resources = ARRAY_SIZE(i2c0_resources),
699 static struct platform_device i2c1_device = {
700 .name = "i2c-sh_mobile",
702 .resource = i2c1_resources,
703 .num_resources = ARRAY_SIZE(i2c1_resources),
706 static struct resource pmu_resources[] = {
708 .start = evt2irq(0x19a0),
709 .end = evt2irq(0x19a0),
710 .flags = IORESOURCE_IRQ,
714 static struct platform_device pmu_device = {
717 .num_resources = ARRAY_SIZE(pmu_resources),
718 .resource = pmu_resources,
721 static struct platform_device *r8a7740_late_devices[] __initdata = {
732 * r8a7740 chip has lasting errata on MERAM buffer.
733 * this is work-around for it.
735 * "Media RAM (MERAM)" on r8a7740 documentation
737 #define MEBUFCNTR 0xFE950098
738 void r8a7740_meram_workaround(void)
742 reg = ioremap_nocache(MEBUFCNTR, 4);
744 iowrite32(0x01600164, reg);
750 #define ICSTART 0x0070
752 #define i2c_read(reg, offset) ioread8(reg + offset)
753 #define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
756 * r8a7740 chip has lasting errata on I2C I/O pad reset.
757 * this is work-around for it.
759 static void r8a7740_i2c_workaround(struct platform_device *pdev)
761 struct resource *res;
764 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
765 if (unlikely(!res)) {
766 pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
770 reg = ioremap(res->start, resource_size(res));
771 if (unlikely(!reg)) {
772 pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
776 i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
777 i2c_read(reg, ICCR); /* dummy read */
779 i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
780 i2c_read(reg, ICSTART); /* dummy read */
784 i2c_write(reg, ICCR, 0x01);
785 i2c_write(reg, ICSTART, 0x00);
789 i2c_write(reg, ICCR, 0x10);
791 i2c_write(reg, ICCR, 0x00);
793 i2c_write(reg, ICCR, 0x10);
799 void __init r8a7740_add_standard_devices(void)
801 /* I2C work-around */
802 r8a7740_i2c_workaround(&i2c0_device);
803 r8a7740_i2c_workaround(&i2c1_device);
805 r8a7740_init_pm_domains();
808 platform_add_devices(r8a7740_early_devices,
809 ARRAY_SIZE(r8a7740_early_devices));
810 platform_add_devices(r8a7740_late_devices,
811 ARRAY_SIZE(r8a7740_late_devices));
813 /* add devices to PM domain */
815 rmobile_add_device_to_domain("A3SP", &scif0_device);
816 rmobile_add_device_to_domain("A3SP", &scif1_device);
817 rmobile_add_device_to_domain("A3SP", &scif2_device);
818 rmobile_add_device_to_domain("A3SP", &scif3_device);
819 rmobile_add_device_to_domain("A3SP", &scif4_device);
820 rmobile_add_device_to_domain("A3SP", &scif5_device);
821 rmobile_add_device_to_domain("A3SP", &scif6_device);
822 rmobile_add_device_to_domain("A3SP", &scif7_device);
823 rmobile_add_device_to_domain("A3SP", &scifb_device);
824 rmobile_add_device_to_domain("A3SP", &i2c1_device);
827 void __init r8a7740_add_early_devices(void)
829 early_platform_add_devices(r8a7740_early_devices,
830 ARRAY_SIZE(r8a7740_early_devices));
832 /* setup early console here as well */
833 shmobile_setup_console();
838 void __init r8a7740_add_early_devices_dt(void)
840 shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
842 early_platform_add_devices(r8a7740_early_devices,
843 ARRAY_SIZE(r8a7740_early_devices));
845 /* setup early console here as well */
846 shmobile_setup_console();
849 static const struct of_dev_auxdata r8a7740_auxdata_lookup[] __initconst = {
853 void __init r8a7740_add_standard_devices_dt(void)
855 /* clocks are setup late during boot in the case of DT */
856 r8a7740_clock_init(0);
858 platform_add_devices(r8a7740_early_devices,
859 ARRAY_SIZE(r8a7740_early_devices));
861 of_platform_populate(NULL, of_default_bus_match_table,
862 r8a7740_auxdata_lookup, NULL);
865 static const char *r8a7740_boards_compat_dt[] __initdata = {
870 DT_MACHINE_START(R8A7740_DT, "Generic R8A7740 (Flattened Device Tree)")
871 .map_io = r8a7740_map_io,
872 .init_early = r8a7740_add_early_devices_dt,
873 .init_irq = r8a7740_init_irq,
874 .handle_irq = shmobile_handle_irq_intc,
875 .init_machine = r8a7740_add_standard_devices_dt,
876 .init_time = shmobile_timer_init,
877 .dt_compat = r8a7740_boards_compat_dt,
880 #endif /* CONFIG_USE_OF */