2 * Copyright (C) 2009 Renesas Solutions Corp.
4 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
11 #include <linux/init.h>
12 #include <linux/device.h>
13 #include <linux/platform_device.h>
14 #include <linux/mtd/physmap.h>
15 #include <linux/gpio.h>
16 #include <linux/interrupt.h>
18 #include <linux/delay.h>
19 #include <linux/usb/r8a66597.h>
20 #include <linux/i2c.h>
21 #include <linux/i2c/tsc2007.h>
22 #include <linux/input.h>
23 #include <video/sh_mobile_lcdc.h>
24 #include <media/sh_mobile_ceu.h>
25 #include <asm/heartbeat.h>
26 #include <asm/sh_eth.h>
27 #include <asm/sh_keysc.h>
28 #include <asm/clock.h>
29 #include <cpu/sh7724.h>
32 * Address Interface BusWidth
33 *-----------------------------------------
34 * 0x0000_0000 uboot 16bit
35 * 0x0004_0000 Linux romImage 16bit
36 * 0x0014_0000 MTD for Linux 16bit
37 * 0x0400_0000 Internal I/O 16/32bit
38 * 0x0800_0000 DRAM 32bit
39 * 0x1800_0000 MFI 16bit
43 *------------------------------
44 * DS2[1] = FlashROM write protect ON : write protect
45 * OFF : No write protect
46 * DS2[2] = RMII / TS, SCIF ON : RMII
48 * DS2[3] = Camera / Video ON : Camera
50 * DS2[5] = NTSC_OUT Clock ON : On board OSC
52 * DS2[6-7] = MMC / SD ON-OFF : SD
57 static unsigned char led_pos[] = { 0, 1, 2, 3 };
58 static struct heartbeat_data heartbeat_data = {
64 static struct resource heartbeat_resources[] = {
66 .start = 0xA405012C, /* PTG */
67 .end = 0xA405012E - 1,
68 .flags = IORESOURCE_MEM,
72 static struct platform_device heartbeat_device = {
76 .platform_data = &heartbeat_data,
78 .num_resources = ARRAY_SIZE(heartbeat_resources),
79 .resource = heartbeat_resources,
83 static struct mtd_partition nor_flash_partitions[] = {
85 .name = "boot loader",
87 .size = (5 * 1024 * 1024),
88 .mask_flags = MTD_WRITEABLE, /* force read-only */
91 .offset = MTDPART_OFS_APPEND,
92 .size = MTDPART_SIZ_FULL,
96 static struct physmap_flash_data nor_flash_data = {
98 .parts = nor_flash_partitions,
99 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
102 static struct resource nor_flash_resources[] = {
107 .flags = IORESOURCE_MEM,
111 static struct platform_device nor_flash_device = {
112 .name = "physmap-flash",
113 .resource = nor_flash_resources,
114 .num_resources = ARRAY_SIZE(nor_flash_resources),
116 .platform_data = &nor_flash_data,
121 #define SH_ETH_ADDR (0xA4600000)
122 #define SH_ETH_MAHR (SH_ETH_ADDR + 0x1C0)
123 #define SH_ETH_MALR (SH_ETH_ADDR + 0x1C8)
124 static struct resource sh_eth_resources[] = {
126 .start = SH_ETH_ADDR,
127 .end = SH_ETH_ADDR + 0x1FC,
128 .flags = IORESOURCE_MEM,
132 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
136 struct sh_eth_plat_data sh_eth_plat = {
137 .phy = 0x1f, /* SMSC LAN8700 */
138 .edmac_endian = EDMAC_LITTLE_ENDIAN,
139 .ether_link_active_low = 1
142 static struct platform_device sh_eth_device = {
146 .platform_data = &sh_eth_plat,
148 .num_resources = ARRAY_SIZE(sh_eth_resources),
149 .resource = sh_eth_resources,
151 .hwblk_id = HWBLK_ETHER,
156 void usb0_port_power(int port, int power)
158 gpio_set_value(GPIO_PTB4, power);
161 static struct r8a66597_platdata usb0_host_data = {
163 .port_power = usb0_port_power,
166 static struct resource usb0_host_resources[] = {
169 .end = 0xa4d80124 - 1,
170 .flags = IORESOURCE_MEM,
175 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
179 static struct platform_device usb0_host_device = {
180 .name = "r8a66597_hcd",
183 .dma_mask = NULL, /* not use dma */
184 .coherent_dma_mask = 0xffffffff,
185 .platform_data = &usb0_host_data,
187 .num_resources = ARRAY_SIZE(usb0_host_resources),
188 .resource = usb0_host_resources,
194 * CN5 can use both host/function,
195 * and we can determine it by checking PTB[3]
197 * This time only USB1 host is supported.
199 void usb1_port_power(int port, int power)
201 if (!gpio_get_value(GPIO_PTB3)) {
202 printk(KERN_ERR "USB1 function is not supported\n");
206 gpio_set_value(GPIO_PTB5, power);
209 static struct r8a66597_platdata usb1_host_data = {
211 .port_power = usb1_port_power,
214 static struct resource usb1_host_resources[] = {
217 .end = 0xa4d90124 - 1,
218 .flags = IORESOURCE_MEM,
223 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
227 static struct platform_device usb1_host_device = {
228 .name = "r8a66597_hcd",
231 .dma_mask = NULL, /* not use dma */
232 .coherent_dma_mask = 0xffffffff,
233 .platform_data = &usb1_host_data,
235 .num_resources = ARRAY_SIZE(usb1_host_resources),
236 .resource = usb1_host_resources,
240 static struct sh_mobile_lcdc_info lcdc_info = {
242 .interface_type = RGB18,
243 .chan = LCDC_CHAN_MAINLCD,
246 .sync = 0, /* hsync and vsync are active low */
248 .lcd_size_cfg = { /* 7.0 inch */
257 static struct resource lcdc_resources[] = {
262 .flags = IORESOURCE_MEM,
266 .flags = IORESOURCE_IRQ,
270 static struct platform_device lcdc_device = {
271 .name = "sh_mobile_lcdc_fb",
272 .num_resources = ARRAY_SIZE(lcdc_resources),
273 .resource = lcdc_resources,
275 .platform_data = &lcdc_info,
278 .hwblk_id = HWBLK_LCDC,
283 static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
284 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
287 static struct resource ceu0_resources[] = {
292 .flags = IORESOURCE_MEM,
296 .flags = IORESOURCE_IRQ,
299 /* place holder for contiguous memory */
303 static struct platform_device ceu0_device = {
304 .name = "sh_mobile_ceu",
305 .id = 0, /* "ceu0" clock */
306 .num_resources = ARRAY_SIZE(ceu0_resources),
307 .resource = ceu0_resources,
309 .platform_data = &sh_mobile_ceu0_info,
312 .hwblk_id = HWBLK_CEU0,
317 static struct sh_mobile_ceu_info sh_mobile_ceu1_info = {
318 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
321 static struct resource ceu1_resources[] = {
326 .flags = IORESOURCE_MEM,
330 .flags = IORESOURCE_IRQ,
333 /* place holder for contiguous memory */
337 static struct platform_device ceu1_device = {
338 .name = "sh_mobile_ceu",
339 .id = 1, /* "ceu1" clock */
340 .num_resources = ARRAY_SIZE(ceu1_resources),
341 .resource = ceu1_resources,
343 .platform_data = &sh_mobile_ceu1_info,
346 .hwblk_id = HWBLK_CEU1,
351 static struct i2c_board_info i2c1_devices[] = {
353 I2C_BOARD_INFO("r2025sd", 0x32),
358 static struct sh_keysc_info keysc_info = {
359 .mode = SH_KEYSC_MODE_1,
363 .keycodes = { KEY_1, 0, 0, 0, 0,
368 KEY_6, 0, 0, 0, 0, },
371 static struct resource keysc_resources[] = {
376 .flags = IORESOURCE_MEM,
380 .flags = IORESOURCE_IRQ,
384 static struct platform_device keysc_device = {
386 .id = 0, /* keysc0 clock */
387 .num_resources = ARRAY_SIZE(keysc_resources),
388 .resource = keysc_resources,
390 .platform_data = &keysc_info,
393 .hwblk_id = HWBLK_KEYSC,
399 static int ts_get_pendown_state(void)
402 gpio_free(GPIO_FN_INTC_IRQ0);
403 gpio_request(GPIO_PTZ0, NULL);
404 gpio_direction_input(GPIO_PTZ0);
406 val = gpio_get_value(GPIO_PTZ0);
408 gpio_free(GPIO_PTZ0);
409 gpio_request(GPIO_FN_INTC_IRQ0, NULL);
414 static int ts_init(void)
416 gpio_request(GPIO_FN_INTC_IRQ0, NULL);
420 struct tsc2007_platform_data tsc2007_info = {
423 .get_pendown_state = ts_get_pendown_state,
424 .init_platform_hw = ts_init,
427 static struct i2c_board_info ts_i2c_clients = {
428 I2C_BOARD_INFO("tsc2007", 0x48),
430 .platform_data = &tsc2007_info,
435 static struct resource sdhi0_resources[] = {
440 .flags = IORESOURCE_MEM,
444 .flags = IORESOURCE_IRQ,
448 static struct platform_device sdhi0_device = {
449 .name = "sh_mobile_sdhi",
450 .num_resources = ARRAY_SIZE(sdhi0_resources),
451 .resource = sdhi0_resources,
454 .hwblk_id = HWBLK_SDHI0,
459 static struct resource sdhi1_resources[] = {
464 .flags = IORESOURCE_MEM,
468 .flags = IORESOURCE_IRQ,
472 static struct platform_device sdhi1_device = {
473 .name = "sh_mobile_sdhi",
474 .num_resources = ARRAY_SIZE(sdhi1_resources),
475 .resource = sdhi1_resources,
478 .hwblk_id = HWBLK_SDHI1,
482 static struct platform_device *ecovec_devices[] __initdata = {
487 &usb1_host_device, /* USB1 host support */
496 #define EEPROM_ADDR 0x50
497 static u8 mac_read(struct i2c_adapter *a, u8 command)
499 struct i2c_msg msg[2];
503 msg[0].addr = EEPROM_ADDR;
506 msg[0].buf = &command;
508 msg[1].addr = EEPROM_ADDR;
509 msg[1].flags = I2C_M_RD;
513 ret = i2c_transfer(a, msg, 2);
515 printk(KERN_ERR "error %d\n", ret);
522 static void __init sh_eth_init(struct sh_eth_plat_data *pd)
524 struct i2c_adapter *a = i2c_get_adapter(1);
528 pr_err("can not get I2C 1\n");
532 /* read MAC address frome EEPROM */
533 for (i = 0; i < sizeof(pd->mac_addr); i++) {
534 pd->mac_addr[i] = mac_read(a, 0x10 + i);
539 #define PORT_HIZA 0xA4050158
540 #define IODRIVEA 0xA405018A
541 static int __init arch_setup(void)
543 /* enable STATUS0, STATUS2 and PDSTATUS */
544 gpio_request(GPIO_FN_STATUS0, NULL);
545 gpio_request(GPIO_FN_STATUS2, NULL);
546 gpio_request(GPIO_FN_PDSTATUS, NULL);
549 gpio_request(GPIO_FN_SCIF0_TXD, NULL);
550 gpio_request(GPIO_FN_SCIF0_RXD, NULL);
552 /* enable debug LED */
553 gpio_request(GPIO_PTG0, NULL);
554 gpio_request(GPIO_PTG1, NULL);
555 gpio_request(GPIO_PTG2, NULL);
556 gpio_request(GPIO_PTG3, NULL);
557 gpio_direction_output(GPIO_PTG0, 0);
558 gpio_direction_output(GPIO_PTG1, 0);
559 gpio_direction_output(GPIO_PTG2, 0);
560 gpio_direction_output(GPIO_PTG3, 0);
561 ctrl_outw((ctrl_inw(PORT_HIZA) & ~(0x1 << 1)) , PORT_HIZA);
564 gpio_request(GPIO_PTA1, NULL);
565 gpio_direction_output(GPIO_PTA1, 1);
568 gpio_request(GPIO_FN_RMII_RXD0, NULL);
569 gpio_request(GPIO_FN_RMII_RXD1, NULL);
570 gpio_request(GPIO_FN_RMII_TXD0, NULL);
571 gpio_request(GPIO_FN_RMII_TXD1, NULL);
572 gpio_request(GPIO_FN_RMII_REF_CLK, NULL);
573 gpio_request(GPIO_FN_RMII_TX_EN, NULL);
574 gpio_request(GPIO_FN_RMII_RX_ER, NULL);
575 gpio_request(GPIO_FN_RMII_CRS_DV, NULL);
576 gpio_request(GPIO_FN_MDIO, NULL);
577 gpio_request(GPIO_FN_MDC, NULL);
578 gpio_request(GPIO_FN_LNKSTA, NULL);
581 ctrl_outw(0x0000, 0xA4D80000);
582 ctrl_outw(0x0000, 0xA4D90000);
583 gpio_request(GPIO_PTB3, NULL);
584 gpio_request(GPIO_PTB4, NULL);
585 gpio_request(GPIO_PTB5, NULL);
586 gpio_direction_input(GPIO_PTB3);
587 gpio_direction_output(GPIO_PTB4, 0);
588 gpio_direction_output(GPIO_PTB5, 0);
589 ctrl_outw(0x0600, 0xa40501d4);
590 ctrl_outw(0x0600, 0xa4050192);
593 gpio_request(GPIO_FN_LCDD23, NULL);
594 gpio_request(GPIO_FN_LCDD22, NULL);
595 gpio_request(GPIO_FN_LCDD21, NULL);
596 gpio_request(GPIO_FN_LCDD20, NULL);
597 gpio_request(GPIO_FN_LCDD19, NULL);
598 gpio_request(GPIO_FN_LCDD18, NULL);
599 gpio_request(GPIO_FN_LCDD17, NULL);
600 gpio_request(GPIO_FN_LCDD16, NULL);
601 gpio_request(GPIO_FN_LCDD15, NULL);
602 gpio_request(GPIO_FN_LCDD14, NULL);
603 gpio_request(GPIO_FN_LCDD13, NULL);
604 gpio_request(GPIO_FN_LCDD12, NULL);
605 gpio_request(GPIO_FN_LCDD11, NULL);
606 gpio_request(GPIO_FN_LCDD10, NULL);
607 gpio_request(GPIO_FN_LCDD9, NULL);
608 gpio_request(GPIO_FN_LCDD8, NULL);
609 gpio_request(GPIO_FN_LCDD7, NULL);
610 gpio_request(GPIO_FN_LCDD6, NULL);
611 gpio_request(GPIO_FN_LCDD5, NULL);
612 gpio_request(GPIO_FN_LCDD4, NULL);
613 gpio_request(GPIO_FN_LCDD3, NULL);
614 gpio_request(GPIO_FN_LCDD2, NULL);
615 gpio_request(GPIO_FN_LCDD1, NULL);
616 gpio_request(GPIO_FN_LCDD0, NULL);
617 gpio_request(GPIO_FN_LCDDISP, NULL);
618 gpio_request(GPIO_FN_LCDHSYN, NULL);
619 gpio_request(GPIO_FN_LCDDCK, NULL);
620 gpio_request(GPIO_FN_LCDVSYN, NULL);
621 gpio_request(GPIO_FN_LCDDON, NULL);
622 gpio_request(GPIO_FN_LCDLCLK, NULL);
623 ctrl_outw((ctrl_inw(PORT_HIZA) & ~0x0001), PORT_HIZA);
625 gpio_request(GPIO_PTE6, NULL);
626 gpio_request(GPIO_PTU1, NULL);
627 gpio_request(GPIO_PTR1, NULL);
628 gpio_request(GPIO_PTA2, NULL);
629 gpio_direction_input(GPIO_PTE6);
630 gpio_direction_output(GPIO_PTU1, 0);
631 gpio_direction_output(GPIO_PTR1, 0);
632 gpio_direction_output(GPIO_PTA2, 0);
634 /* I/O buffer drive ability is low */
635 ctrl_outw((ctrl_inw(IODRIVEA) & ~0x00c0) | 0x0040 , IODRIVEA);
637 if (gpio_get_value(GPIO_PTE6)) {
639 lcdc_info.clock_source = LCDC_CLK_EXTERNAL;
640 lcdc_info.ch[0].clock_divider = 1,
641 lcdc_info.ch[0].lcd_cfg.name = "DVI";
642 lcdc_info.ch[0].lcd_cfg.xres = 1280;
643 lcdc_info.ch[0].lcd_cfg.yres = 720;
644 lcdc_info.ch[0].lcd_cfg.left_margin = 220;
645 lcdc_info.ch[0].lcd_cfg.right_margin = 110;
646 lcdc_info.ch[0].lcd_cfg.hsync_len = 40;
647 lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
648 lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
649 lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
651 gpio_set_value(GPIO_PTA2, 1);
652 gpio_set_value(GPIO_PTU1, 1);
656 lcdc_info.clock_source = LCDC_CLK_PERIPHERAL;
657 lcdc_info.ch[0].clock_divider = 2,
658 lcdc_info.ch[0].lcd_cfg.name = "Panel";
659 lcdc_info.ch[0].lcd_cfg.xres = 800;
660 lcdc_info.ch[0].lcd_cfg.yres = 480;
661 lcdc_info.ch[0].lcd_cfg.left_margin = 220;
662 lcdc_info.ch[0].lcd_cfg.right_margin = 110;
663 lcdc_info.ch[0].lcd_cfg.hsync_len = 70;
664 lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
665 lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
666 lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
668 gpio_set_value(GPIO_PTR1, 1);
672 * LCDDON control is needed for Panel,
673 * but current sh_mobile_lcdc driver doesn't control it.
674 * It is temporary correspondence
676 gpio_request(GPIO_PTF4, NULL);
677 gpio_direction_output(GPIO_PTF4, 1);
679 /* enable TouchScreen */
680 i2c_register_board_info(0, &ts_i2c_clients, 1);
681 set_irq_type(IRQ0, IRQ_TYPE_LEVEL_LOW);
685 gpio_request(GPIO_FN_VIO0_D15, NULL);
686 gpio_request(GPIO_FN_VIO0_D14, NULL);
687 gpio_request(GPIO_FN_VIO0_D13, NULL);
688 gpio_request(GPIO_FN_VIO0_D12, NULL);
689 gpio_request(GPIO_FN_VIO0_D11, NULL);
690 gpio_request(GPIO_FN_VIO0_D10, NULL);
691 gpio_request(GPIO_FN_VIO0_D9, NULL);
692 gpio_request(GPIO_FN_VIO0_D8, NULL);
693 gpio_request(GPIO_FN_VIO0_D7, NULL);
694 gpio_request(GPIO_FN_VIO0_D6, NULL);
695 gpio_request(GPIO_FN_VIO0_D5, NULL);
696 gpio_request(GPIO_FN_VIO0_D4, NULL);
697 gpio_request(GPIO_FN_VIO0_D3, NULL);
698 gpio_request(GPIO_FN_VIO0_D2, NULL);
699 gpio_request(GPIO_FN_VIO0_D1, NULL);
700 gpio_request(GPIO_FN_VIO0_D0, NULL);
701 gpio_request(GPIO_FN_VIO0_VD, NULL);
702 gpio_request(GPIO_FN_VIO0_CLK, NULL);
703 gpio_request(GPIO_FN_VIO0_FLD, NULL);
704 gpio_request(GPIO_FN_VIO0_HD, NULL);
705 platform_resource_setup_memory(&ceu0_device, "ceu0", 4 << 20);
708 gpio_request(GPIO_FN_VIO1_D7, NULL);
709 gpio_request(GPIO_FN_VIO1_D6, NULL);
710 gpio_request(GPIO_FN_VIO1_D5, NULL);
711 gpio_request(GPIO_FN_VIO1_D4, NULL);
712 gpio_request(GPIO_FN_VIO1_D3, NULL);
713 gpio_request(GPIO_FN_VIO1_D2, NULL);
714 gpio_request(GPIO_FN_VIO1_D1, NULL);
715 gpio_request(GPIO_FN_VIO1_D0, NULL);
716 gpio_request(GPIO_FN_VIO1_FLD, NULL);
717 gpio_request(GPIO_FN_VIO1_HD, NULL);
718 gpio_request(GPIO_FN_VIO1_VD, NULL);
719 gpio_request(GPIO_FN_VIO1_CLK, NULL);
720 platform_resource_setup_memory(&ceu1_device, "ceu1", 4 << 20);
723 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
724 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
725 gpio_request(GPIO_FN_KEYOUT3, NULL);
726 gpio_request(GPIO_FN_KEYOUT2, NULL);
727 gpio_request(GPIO_FN_KEYOUT1, NULL);
728 gpio_request(GPIO_FN_KEYOUT0, NULL);
729 gpio_request(GPIO_FN_KEYIN0, NULL);
731 /* enable user debug switch */
732 gpio_request(GPIO_PTR0, NULL);
733 gpio_request(GPIO_PTR4, NULL);
734 gpio_request(GPIO_PTR5, NULL);
735 gpio_request(GPIO_PTR6, NULL);
736 gpio_direction_input(GPIO_PTR0);
737 gpio_direction_input(GPIO_PTR4);
738 gpio_direction_input(GPIO_PTR5);
739 gpio_direction_input(GPIO_PTR6);
742 gpio_request(GPIO_FN_SDHI0CD, NULL);
743 gpio_request(GPIO_FN_SDHI0WP, NULL);
744 gpio_request(GPIO_FN_SDHI0CMD, NULL);
745 gpio_request(GPIO_FN_SDHI0CLK, NULL);
746 gpio_request(GPIO_FN_SDHI0D3, NULL);
747 gpio_request(GPIO_FN_SDHI0D2, NULL);
748 gpio_request(GPIO_FN_SDHI0D1, NULL);
749 gpio_request(GPIO_FN_SDHI0D0, NULL);
752 gpio_request(GPIO_FN_SDHI1CD, NULL);
753 gpio_request(GPIO_FN_SDHI1WP, NULL);
754 gpio_request(GPIO_FN_SDHI1CMD, NULL);
755 gpio_request(GPIO_FN_SDHI1CLK, NULL);
756 gpio_request(GPIO_FN_SDHI1D3, NULL);
757 gpio_request(GPIO_FN_SDHI1D2, NULL);
758 gpio_request(GPIO_FN_SDHI1D1, NULL);
759 gpio_request(GPIO_FN_SDHI1D0, NULL);
761 gpio_request(GPIO_PTB6, NULL);
762 gpio_request(GPIO_PTB7, NULL);
763 gpio_direction_output(GPIO_PTB6, 1);
764 gpio_direction_output(GPIO_PTB7, 1);
766 /* I/O buffer drive ability is high for SDHI1 */
767 ctrl_outw((ctrl_inw(IODRIVEA) & ~0x3000) | 0x2000 , IODRIVEA);
769 /* enable I2C device */
770 i2c_register_board_info(1, i2c1_devices,
771 ARRAY_SIZE(i2c1_devices));
773 return platform_add_devices(ecovec_devices,
774 ARRAY_SIZE(ecovec_devices));
776 arch_initcall(arch_setup);
778 static int __init devices_setup(void)
780 sh_eth_init(&sh_eth_plat);
783 device_initcall(devices_setup);
785 static struct sh_machine_vector mv_ecovec __initmv = {
786 .mv_name = "R0P7724 (EcoVec)",