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/serial_sci.h>
27 #include <linux/sh_dma.h>
28 #include <linux/sh_timer.h>
29 #include <linux/dma-mapping.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));
70 * DMA memory at 0xff200000 - 0xffdfffff. The default 2MB size isn't
71 * enough to allocate the frame buffer memory.
73 init_consistent_dma_size(12 << 20);
77 static struct plat_sci_port scif0_platform_data = {
78 .mapbase = 0xe6c40000,
79 .flags = UPF_BOOT_AUTOCONF,
80 .scscr = SCSCR_RE | SCSCR_TE,
81 .scbrr_algo_id = SCBRR_ALGO_4,
83 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
86 static struct platform_device scif0_device = {
90 .platform_data = &scif0_platform_data,
95 static struct plat_sci_port scif1_platform_data = {
96 .mapbase = 0xe6c50000,
97 .flags = UPF_BOOT_AUTOCONF,
98 .scscr = SCSCR_RE | SCSCR_TE,
99 .scbrr_algo_id = SCBRR_ALGO_4,
101 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
104 static struct platform_device scif1_device = {
108 .platform_data = &scif1_platform_data,
113 static struct plat_sci_port scif2_platform_data = {
114 .mapbase = 0xe6c60000,
115 .flags = UPF_BOOT_AUTOCONF,
116 .scscr = SCSCR_RE | SCSCR_TE,
117 .scbrr_algo_id = SCBRR_ALGO_4,
119 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
122 static struct platform_device scif2_device = {
126 .platform_data = &scif2_platform_data,
131 static struct plat_sci_port scif3_platform_data = {
132 .mapbase = 0xe6c70000,
133 .flags = UPF_BOOT_AUTOCONF,
134 .scscr = SCSCR_RE | SCSCR_TE,
135 .scbrr_algo_id = SCBRR_ALGO_4,
137 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
140 static struct platform_device scif3_device = {
144 .platform_data = &scif3_platform_data,
149 static struct plat_sci_port scif4_platform_data = {
150 .mapbase = 0xe6c80000,
151 .flags = UPF_BOOT_AUTOCONF,
152 .scscr = SCSCR_RE | SCSCR_TE,
153 .scbrr_algo_id = SCBRR_ALGO_4,
155 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
158 static struct platform_device scif4_device = {
162 .platform_data = &scif4_platform_data,
167 static struct plat_sci_port scif5_platform_data = {
168 .mapbase = 0xe6cb0000,
169 .flags = UPF_BOOT_AUTOCONF,
170 .scscr = SCSCR_RE | SCSCR_TE,
171 .scbrr_algo_id = SCBRR_ALGO_4,
173 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
176 static struct platform_device scif5_device = {
180 .platform_data = &scif5_platform_data,
185 static struct plat_sci_port scif6_platform_data = {
186 .mapbase = 0xe6cc0000,
187 .flags = UPF_BOOT_AUTOCONF,
188 .scscr = SCSCR_RE | SCSCR_TE,
189 .scbrr_algo_id = SCBRR_ALGO_4,
191 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
194 static struct platform_device scif6_device = {
198 .platform_data = &scif6_platform_data,
203 static struct plat_sci_port scif7_platform_data = {
204 .mapbase = 0xe6cd0000,
205 .flags = UPF_BOOT_AUTOCONF,
206 .scscr = SCSCR_RE | SCSCR_TE,
207 .scbrr_algo_id = SCBRR_ALGO_4,
209 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
212 static struct platform_device scif7_device = {
216 .platform_data = &scif7_platform_data,
221 static struct plat_sci_port scifb_platform_data = {
222 .mapbase = 0xe6c30000,
223 .flags = UPF_BOOT_AUTOCONF,
224 .scscr = SCSCR_RE | SCSCR_TE,
225 .scbrr_algo_id = SCBRR_ALGO_4,
227 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
230 static struct platform_device scifb_device = {
234 .platform_data = &scifb_platform_data,
239 static struct sh_timer_config cmt10_platform_data = {
241 .channel_offset = 0x10,
243 .clockevent_rating = 125,
244 .clocksource_rating = 125,
247 static struct resource cmt10_resources[] = {
252 .flags = IORESOURCE_MEM,
255 .start = evt2irq(0x0b00),
256 .flags = IORESOURCE_IRQ,
260 static struct platform_device cmt10_device = {
264 .platform_data = &cmt10_platform_data,
266 .resource = cmt10_resources,
267 .num_resources = ARRAY_SIZE(cmt10_resources),
270 static struct platform_device *r8a7740_early_devices[] __initdata = {
284 static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
286 .slave_id = SHDMA_SLAVE_SDHI0_TX,
288 .chcr = CHCR_TX(XMIT_SZ_16BIT),
291 .slave_id = SHDMA_SLAVE_SDHI0_RX,
293 .chcr = CHCR_RX(XMIT_SZ_16BIT),
296 .slave_id = SHDMA_SLAVE_SDHI1_TX,
298 .chcr = CHCR_TX(XMIT_SZ_16BIT),
301 .slave_id = SHDMA_SLAVE_SDHI1_RX,
303 .chcr = CHCR_RX(XMIT_SZ_16BIT),
306 .slave_id = SHDMA_SLAVE_SDHI2_TX,
308 .chcr = CHCR_TX(XMIT_SZ_16BIT),
311 .slave_id = SHDMA_SLAVE_SDHI2_RX,
313 .chcr = CHCR_RX(XMIT_SZ_16BIT),
316 .slave_id = SHDMA_SLAVE_FSIA_TX,
318 .chcr = CHCR_TX(XMIT_SZ_32BIT),
321 .slave_id = SHDMA_SLAVE_FSIA_RX,
323 .chcr = CHCR_RX(XMIT_SZ_32BIT),
326 .slave_id = SHDMA_SLAVE_FSIB_TX,
328 .chcr = CHCR_TX(XMIT_SZ_32BIT),
333 #define DMA_CHANNEL(a, b, c) \
338 .chclr_offset = (0x220 - 0x20) + a \
341 static const struct sh_dmae_channel r8a7740_dmae_channels[] = {
342 DMA_CHANNEL(0x00, 0, 0),
343 DMA_CHANNEL(0x10, 0, 8),
344 DMA_CHANNEL(0x20, 4, 0),
345 DMA_CHANNEL(0x30, 4, 8),
346 DMA_CHANNEL(0x50, 8, 0),
347 DMA_CHANNEL(0x60, 8, 8),
350 static struct sh_dmae_pdata dma_platform_data = {
351 .slave = r8a7740_dmae_slaves,
352 .slave_num = ARRAY_SIZE(r8a7740_dmae_slaves),
353 .channel = r8a7740_dmae_channels,
354 .channel_num = ARRAY_SIZE(r8a7740_dmae_channels),
355 .ts_low_shift = TS_LOW_SHIFT,
356 .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
357 .ts_high_shift = TS_HI_SHIFT,
358 .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
359 .ts_shift = dma_ts_shift,
360 .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
361 .dmaor_init = DMAOR_DME,
365 /* Resource order important! */
366 static struct resource r8a7740_dmae0_resources[] = {
368 /* Channel registers and DMAOR */
371 .flags = IORESOURCE_MEM,
377 .flags = IORESOURCE_MEM,
381 .start = evt2irq(0x20c0),
382 .end = evt2irq(0x20c0),
383 .flags = IORESOURCE_IRQ,
386 /* IRQ for channels 0-5 */
387 .start = evt2irq(0x2000),
388 .end = evt2irq(0x20a0),
389 .flags = IORESOURCE_IRQ,
393 /* Resource order important! */
394 static struct resource r8a7740_dmae1_resources[] = {
396 /* Channel registers and DMAOR */
399 .flags = IORESOURCE_MEM,
405 .flags = IORESOURCE_MEM,
409 .start = evt2irq(0x21c0),
410 .end = evt2irq(0x21c0),
411 .flags = IORESOURCE_IRQ,
414 /* IRQ for channels 0-5 */
415 .start = evt2irq(0x2100),
416 .end = evt2irq(0x21a0),
417 .flags = IORESOURCE_IRQ,
421 /* Resource order important! */
422 static struct resource r8a7740_dmae2_resources[] = {
424 /* Channel registers and DMAOR */
427 .flags = IORESOURCE_MEM,
433 .flags = IORESOURCE_MEM,
437 .start = evt2irq(0x22c0),
438 .end = evt2irq(0x22c0),
439 .flags = IORESOURCE_IRQ,
442 /* IRQ for channels 0-5 */
443 .start = evt2irq(0x2200),
444 .end = evt2irq(0x22a0),
445 .flags = IORESOURCE_IRQ,
449 static struct platform_device dma0_device = {
450 .name = "sh-dma-engine",
452 .resource = r8a7740_dmae0_resources,
453 .num_resources = ARRAY_SIZE(r8a7740_dmae0_resources),
455 .platform_data = &dma_platform_data,
459 static struct platform_device dma1_device = {
460 .name = "sh-dma-engine",
462 .resource = r8a7740_dmae1_resources,
463 .num_resources = ARRAY_SIZE(r8a7740_dmae1_resources),
465 .platform_data = &dma_platform_data,
469 static struct platform_device dma2_device = {
470 .name = "sh-dma-engine",
472 .resource = r8a7740_dmae2_resources,
473 .num_resources = ARRAY_SIZE(r8a7740_dmae2_resources),
475 .platform_data = &dma_platform_data,
480 static const struct sh_dmae_channel r8a7740_usb_dma_channels[] = {
488 static const struct sh_dmae_slave_config r8a7740_usb_dma_slaves[] = {
490 .slave_id = SHDMA_SLAVE_USBHS_TX,
491 .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
493 .slave_id = SHDMA_SLAVE_USBHS_RX,
494 .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
498 static struct sh_dmae_pdata usb_dma_platform_data = {
499 .slave = r8a7740_usb_dma_slaves,
500 .slave_num = ARRAY_SIZE(r8a7740_usb_dma_slaves),
501 .channel = r8a7740_usb_dma_channels,
502 .channel_num = ARRAY_SIZE(r8a7740_usb_dma_channels),
503 .ts_low_shift = USBTS_LOW_SHIFT,
504 .ts_low_mask = USBTS_LOW_BIT << USBTS_LOW_SHIFT,
505 .ts_high_shift = USBTS_HI_SHIFT,
506 .ts_high_mask = USBTS_HI_BIT << USBTS_HI_SHIFT,
507 .ts_shift = dma_usbts_shift,
508 .ts_shift_num = ARRAY_SIZE(dma_usbts_shift),
509 .dmaor_init = DMAOR_DME,
511 .chcr_ie_bit = 1 << 5,
518 static struct resource r8a7740_usb_dma_resources[] = {
520 /* Channel registers and DMAOR */
522 .end = 0xe68a0064 - 1,
523 .flags = IORESOURCE_MEM,
528 .end = 0xe68a0014 - 1,
529 .flags = IORESOURCE_MEM,
532 /* IRQ for channels */
533 .start = evt2irq(0x0a00),
534 .end = evt2irq(0x0a00),
535 .flags = IORESOURCE_IRQ,
539 static struct platform_device usb_dma_device = {
540 .name = "sh-dma-engine",
542 .resource = r8a7740_usb_dma_resources,
543 .num_resources = ARRAY_SIZE(r8a7740_usb_dma_resources),
545 .platform_data = &usb_dma_platform_data,
550 static struct resource i2c0_resources[] = {
554 .end = 0xfff20425 - 1,
555 .flags = IORESOURCE_MEM,
558 .start = intcs_evt2irq(0xe00),
559 .end = intcs_evt2irq(0xe60),
560 .flags = IORESOURCE_IRQ,
564 static struct resource i2c1_resources[] = {
568 .end = 0xe6c20425 - 1,
569 .flags = IORESOURCE_MEM,
572 .start = evt2irq(0x780), /* IIC1_ALI1 */
573 .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
574 .flags = IORESOURCE_IRQ,
578 static struct platform_device i2c0_device = {
579 .name = "i2c-sh_mobile",
581 .resource = i2c0_resources,
582 .num_resources = ARRAY_SIZE(i2c0_resources),
585 static struct platform_device i2c1_device = {
586 .name = "i2c-sh_mobile",
588 .resource = i2c1_resources,
589 .num_resources = ARRAY_SIZE(i2c1_resources),
592 static struct platform_device *r8a7740_late_devices[] __initdata = {
602 * r8a7740 chip has lasting errata on MERAM buffer.
603 * this is work-around for it.
605 * "Media RAM (MERAM)" on r8a7740 documentation
607 #define MEBUFCNTR 0xFE950098
608 void r8a7740_meram_workaround(void)
612 reg = ioremap_nocache(MEBUFCNTR, 4);
614 iowrite32(0x01600164, reg);
620 #define ICSTART 0x0070
622 #define i2c_read(reg, offset) ioread8(reg + offset)
623 #define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
626 * r8a7740 chip has lasting errata on I2C I/O pad reset.
627 * this is work-around for it.
629 static void r8a7740_i2c_workaround(struct platform_device *pdev)
631 struct resource *res;
634 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
635 if (unlikely(!res)) {
636 pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
640 reg = ioremap(res->start, resource_size(res));
641 if (unlikely(!reg)) {
642 pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
646 i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
647 i2c_read(reg, ICCR); /* dummy read */
649 i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
650 i2c_read(reg, ICSTART); /* dummy read */
654 i2c_write(reg, ICCR, 0x01);
655 i2c_write(reg, ICSTART, 0x00);
659 i2c_write(reg, ICCR, 0x10);
661 i2c_write(reg, ICCR, 0x00);
663 i2c_write(reg, ICCR, 0x10);
669 void __init r8a7740_add_standard_devices(void)
671 /* I2C work-around */
672 r8a7740_i2c_workaround(&i2c0_device);
673 r8a7740_i2c_workaround(&i2c1_device);
676 rmobile_init_pm_domain(&r8a7740_pd_a4s);
677 rmobile_init_pm_domain(&r8a7740_pd_a3sp);
679 rmobile_pm_add_subdomain(&r8a7740_pd_a4s, &r8a7740_pd_a3sp);
682 platform_add_devices(r8a7740_early_devices,
683 ARRAY_SIZE(r8a7740_early_devices));
684 platform_add_devices(r8a7740_late_devices,
685 ARRAY_SIZE(r8a7740_late_devices));
687 /* add devices to PM domain */
689 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &scif0_device);
690 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &scif1_device);
691 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &scif2_device);
692 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &scif3_device);
693 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &scif4_device);
694 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &scif5_device);
695 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &scif6_device);
696 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &scif7_device);
697 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &scifb_device);
698 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, &i2c1_device);
701 static void __init r8a7740_earlytimer_init(void)
703 r8a7740_clock_init(0);
704 shmobile_earlytimer_init();
707 void __init r8a7740_add_early_devices(void)
709 early_platform_add_devices(r8a7740_early_devices,
710 ARRAY_SIZE(r8a7740_early_devices));
712 /* setup early console here as well */
713 shmobile_setup_console();
715 /* override timer setup with soc-specific code */
716 shmobile_timer.init = r8a7740_earlytimer_init;