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 static unsigned char led_pos[] = { 0, 1, 2, 3 };
44 static struct heartbeat_data heartbeat_data = {
50 static struct resource heartbeat_resources[] = {
52 .start = 0xA405012C, /* PTG */
53 .end = 0xA405012E - 1,
54 .flags = IORESOURCE_MEM,
58 static struct platform_device heartbeat_device = {
62 .platform_data = &heartbeat_data,
64 .num_resources = ARRAY_SIZE(heartbeat_resources),
65 .resource = heartbeat_resources,
69 static struct mtd_partition nor_flash_partitions[] = {
71 .name = "boot loader",
73 .size = (5 * 1024 * 1024),
74 .mask_flags = MTD_CAP_ROM,
77 .offset = MTDPART_OFS_APPEND,
78 .size = MTDPART_SIZ_FULL,
82 static struct physmap_flash_data nor_flash_data = {
84 .parts = nor_flash_partitions,
85 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
88 static struct resource nor_flash_resources[] = {
93 .flags = IORESOURCE_MEM,
97 static struct platform_device nor_flash_device = {
98 .name = "physmap-flash",
99 .resource = nor_flash_resources,
100 .num_resources = ARRAY_SIZE(nor_flash_resources),
102 .platform_data = &nor_flash_data,
107 #define SH_ETH_ADDR (0xA4600000)
108 #define SH_ETH_MAHR (SH_ETH_ADDR + 0x1C0)
109 #define SH_ETH_MALR (SH_ETH_ADDR + 0x1C8)
110 static struct resource sh_eth_resources[] = {
112 .start = SH_ETH_ADDR,
113 .end = SH_ETH_ADDR + 0x1FC,
114 .flags = IORESOURCE_MEM,
118 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
122 struct sh_eth_plat_data sh_eth_plat = {
123 .phy = 0x1f, /* SMSC LAN8700 */
124 .edmac_endian = EDMAC_LITTLE_ENDIAN,
125 .ether_link_active_low = 1
128 static struct platform_device sh_eth_device = {
132 .platform_data = &sh_eth_plat,
134 .num_resources = ARRAY_SIZE(sh_eth_resources),
135 .resource = sh_eth_resources,
139 void usb0_port_power(int port, int power)
141 gpio_set_value(GPIO_PTB4, power);
144 static struct r8a66597_platdata usb0_host_data = {
146 .port_power = usb0_port_power,
149 static struct resource usb0_host_resources[] = {
152 .end = 0xa4d80124 - 1,
153 .flags = IORESOURCE_MEM,
158 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
162 static struct platform_device usb0_host_device = {
163 .name = "r8a66597_hcd",
166 .dma_mask = NULL, /* not use dma */
167 .coherent_dma_mask = 0xffffffff,
168 .platform_data = &usb0_host_data,
170 .num_resources = ARRAY_SIZE(usb0_host_resources),
171 .resource = usb0_host_resources,
177 * CN5 can use both host/function,
178 * and we can determine it by checking PTB[3]
180 * This time only USB1 host is supported.
182 void usb1_port_power(int port, int power)
184 if (!gpio_get_value(GPIO_PTB3)) {
185 printk(KERN_ERR "USB1 function is not supported\n");
189 gpio_set_value(GPIO_PTB5, power);
192 static struct r8a66597_platdata usb1_host_data = {
194 .port_power = usb1_port_power,
197 static struct resource usb1_host_resources[] = {
200 .end = 0xa4d90124 - 1,
201 .flags = IORESOURCE_MEM,
206 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
210 static struct platform_device usb1_host_device = {
211 .name = "r8a66597_hcd",
214 .dma_mask = NULL, /* not use dma */
215 .coherent_dma_mask = 0xffffffff,
216 .platform_data = &usb1_host_data,
218 .num_resources = ARRAY_SIZE(usb1_host_resources),
219 .resource = usb1_host_resources,
223 static struct sh_mobile_lcdc_info lcdc_info = {
225 .interface_type = RGB18,
226 .chan = LCDC_CHAN_MAINLCD,
229 .sync = 0, /* hsync and vsync are active low */
231 .lcd_size_cfg = { /* 7.0 inch */
240 static struct resource lcdc_resources[] = {
245 .flags = IORESOURCE_MEM,
249 .flags = IORESOURCE_IRQ,
253 static struct platform_device lcdc_device = {
254 .name = "sh_mobile_lcdc_fb",
255 .num_resources = ARRAY_SIZE(lcdc_resources),
256 .resource = lcdc_resources,
258 .platform_data = &lcdc_info,
261 .hwblk_id = HWBLK_LCDC,
266 static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
267 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
270 static struct resource ceu0_resources[] = {
275 .flags = IORESOURCE_MEM,
279 .flags = IORESOURCE_IRQ,
282 /* place holder for contiguous memory */
286 static struct platform_device ceu0_device = {
287 .name = "sh_mobile_ceu",
288 .id = 0, /* "ceu0" clock */
289 .num_resources = ARRAY_SIZE(ceu0_resources),
290 .resource = ceu0_resources,
292 .platform_data = &sh_mobile_ceu0_info,
295 .hwblk_id = HWBLK_CEU0,
300 static struct sh_mobile_ceu_info sh_mobile_ceu1_info = {
301 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
304 static struct resource ceu1_resources[] = {
309 .flags = IORESOURCE_MEM,
313 .flags = IORESOURCE_IRQ,
316 /* place holder for contiguous memory */
320 static struct platform_device ceu1_device = {
321 .name = "sh_mobile_ceu",
322 .id = 1, /* "ceu1" clock */
323 .num_resources = ARRAY_SIZE(ceu1_resources),
324 .resource = ceu1_resources,
326 .platform_data = &sh_mobile_ceu1_info,
329 .hwblk_id = HWBLK_CEU1,
334 static struct i2c_board_info i2c1_devices[] = {
336 I2C_BOARD_INFO("r2025sd", 0x32),
341 static struct sh_keysc_info keysc_info = {
342 .mode = SH_KEYSC_MODE_1,
346 .keycodes = { KEY_1, 0, 0, 0, 0,
351 KEY_6, 0, 0, 0, 0, },
354 static struct resource keysc_resources[] = {
359 .flags = IORESOURCE_MEM,
363 .flags = IORESOURCE_IRQ,
367 static struct platform_device keysc_device = {
369 .id = 0, /* keysc0 clock */
370 .num_resources = ARRAY_SIZE(keysc_resources),
371 .resource = keysc_resources,
373 .platform_data = &keysc_info,
376 .hwblk_id = HWBLK_KEYSC,
382 static int ts_get_pendown_state(void)
385 gpio_free(GPIO_FN_INTC_IRQ0);
386 gpio_request(GPIO_PTZ0, NULL);
387 gpio_direction_input(GPIO_PTZ0);
389 val = gpio_get_value(GPIO_PTZ0);
391 gpio_free(GPIO_PTZ0);
392 gpio_request(GPIO_FN_INTC_IRQ0, NULL);
397 static int ts_init(void)
399 gpio_request(GPIO_FN_INTC_IRQ0, NULL);
403 struct tsc2007_platform_data tsc2007_info = {
406 .get_pendown_state = ts_get_pendown_state,
407 .init_platform_hw = ts_init,
410 static struct i2c_board_info ts_i2c_clients = {
411 I2C_BOARD_INFO("tsc2007", 0x48),
413 .platform_data = &tsc2007_info,
417 static struct platform_device *ecovec_devices[] __initdata = {
422 &usb1_host_device, /* USB1 host support */
429 #define EEPROM_ADDR 0x50
430 static u8 mac_read(struct i2c_adapter *a, u8 command)
432 struct i2c_msg msg[2];
436 msg[0].addr = EEPROM_ADDR;
439 msg[0].buf = &command;
441 msg[1].addr = EEPROM_ADDR;
442 msg[1].flags = I2C_M_RD;
446 ret = i2c_transfer(a, msg, 2);
448 printk(KERN_ERR "error %d\n", ret);
456 static void __init sh_eth_init(void)
458 struct i2c_adapter *a = i2c_get_adapter(1);
464 pr_err("can not get I2C 1\n");
468 eth_clk = clk_get(NULL, "eth0");
470 pr_err("can not get eth0 clk\n");
474 /* read MAC address frome EEPROM */
475 for (i = 0; i < MAC_LEN; i++) {
476 mac[i] = mac_read(a, 0x10 + i);
484 ctrl_outl(0x1, SH_ETH_ADDR + 0x0);
487 ctrl_outl((mac[0] << 24) |
490 (mac[3] << 0), SH_ETH_MAHR);
491 ctrl_outl((mac[4] << 8) |
492 (mac[5] << 0), SH_ETH_MALR);
497 #define PORT_HIZA 0xA4050158
498 #define IODRIVEA 0xA405018A
499 static int __init arch_setup(void)
502 gpio_request(GPIO_FN_SCIF0_TXD, NULL);
503 gpio_request(GPIO_FN_SCIF0_RXD, NULL);
505 /* enable debug LED */
506 gpio_request(GPIO_PTG0, NULL);
507 gpio_request(GPIO_PTG1, NULL);
508 gpio_request(GPIO_PTG2, NULL);
509 gpio_request(GPIO_PTG3, NULL);
510 gpio_direction_output(GPIO_PTG0, 0);
511 gpio_direction_output(GPIO_PTG1, 0);
512 gpio_direction_output(GPIO_PTG2, 0);
513 gpio_direction_output(GPIO_PTG3, 0);
514 ctrl_outw((ctrl_inw(PORT_HIZA) & ~(0x1 << 1)) , PORT_HIZA);
517 gpio_request(GPIO_PTA1, NULL);
518 gpio_direction_output(GPIO_PTA1, 1);
521 gpio_request(GPIO_FN_RMII_RXD0, NULL);
522 gpio_request(GPIO_FN_RMII_RXD1, NULL);
523 gpio_request(GPIO_FN_RMII_TXD0, NULL);
524 gpio_request(GPIO_FN_RMII_TXD1, NULL);
525 gpio_request(GPIO_FN_RMII_REF_CLK, NULL);
526 gpio_request(GPIO_FN_RMII_TX_EN, NULL);
527 gpio_request(GPIO_FN_RMII_RX_ER, NULL);
528 gpio_request(GPIO_FN_RMII_CRS_DV, NULL);
529 gpio_request(GPIO_FN_MDIO, NULL);
530 gpio_request(GPIO_FN_MDC, NULL);
531 gpio_request(GPIO_FN_LNKSTA, NULL);
534 ctrl_outw(0x0000, 0xA4D80000);
535 ctrl_outw(0x0000, 0xA4D90000);
536 gpio_request(GPIO_PTB3, NULL);
537 gpio_request(GPIO_PTB4, NULL);
538 gpio_request(GPIO_PTB5, NULL);
539 gpio_direction_input(GPIO_PTB3);
540 gpio_direction_output(GPIO_PTB4, 0);
541 gpio_direction_output(GPIO_PTB5, 0);
542 ctrl_outw(0x0600, 0xa40501d4);
543 ctrl_outw(0x0600, 0xa4050192);
546 gpio_request(GPIO_FN_LCDD23, NULL);
547 gpio_request(GPIO_FN_LCDD22, NULL);
548 gpio_request(GPIO_FN_LCDD21, NULL);
549 gpio_request(GPIO_FN_LCDD20, NULL);
550 gpio_request(GPIO_FN_LCDD19, NULL);
551 gpio_request(GPIO_FN_LCDD18, NULL);
552 gpio_request(GPIO_FN_LCDD17, NULL);
553 gpio_request(GPIO_FN_LCDD16, NULL);
554 gpio_request(GPIO_FN_LCDD15, NULL);
555 gpio_request(GPIO_FN_LCDD14, NULL);
556 gpio_request(GPIO_FN_LCDD13, NULL);
557 gpio_request(GPIO_FN_LCDD12, NULL);
558 gpio_request(GPIO_FN_LCDD11, NULL);
559 gpio_request(GPIO_FN_LCDD10, NULL);
560 gpio_request(GPIO_FN_LCDD9, NULL);
561 gpio_request(GPIO_FN_LCDD8, NULL);
562 gpio_request(GPIO_FN_LCDD7, NULL);
563 gpio_request(GPIO_FN_LCDD6, NULL);
564 gpio_request(GPIO_FN_LCDD5, NULL);
565 gpio_request(GPIO_FN_LCDD4, NULL);
566 gpio_request(GPIO_FN_LCDD3, NULL);
567 gpio_request(GPIO_FN_LCDD2, NULL);
568 gpio_request(GPIO_FN_LCDD1, NULL);
569 gpio_request(GPIO_FN_LCDD0, NULL);
570 gpio_request(GPIO_FN_LCDDISP, NULL);
571 gpio_request(GPIO_FN_LCDHSYN, NULL);
572 gpio_request(GPIO_FN_LCDDCK, NULL);
573 gpio_request(GPIO_FN_LCDVSYN, NULL);
574 gpio_request(GPIO_FN_LCDDON, NULL);
575 gpio_request(GPIO_FN_LCDLCLK, NULL);
576 ctrl_outw((ctrl_inw(PORT_HIZA) & ~0x0001), PORT_HIZA);
578 gpio_request(GPIO_PTE6, NULL);
579 gpio_request(GPIO_PTU1, NULL);
580 gpio_request(GPIO_PTR1, NULL);
581 gpio_request(GPIO_PTA2, NULL);
582 gpio_direction_input(GPIO_PTE6);
583 gpio_direction_output(GPIO_PTU1, 0);
584 gpio_direction_output(GPIO_PTR1, 0);
585 gpio_direction_output(GPIO_PTA2, 0);
587 /* I/O buffer drive ability is low */
588 ctrl_outw((ctrl_inw(IODRIVEA) & ~0x00c0) | 0x0040 , IODRIVEA);
590 if (gpio_get_value(GPIO_PTE6)) {
592 lcdc_info.clock_source = LCDC_CLK_EXTERNAL;
593 lcdc_info.ch[0].clock_divider = 1,
594 lcdc_info.ch[0].lcd_cfg.name = "DVI";
595 lcdc_info.ch[0].lcd_cfg.xres = 1280;
596 lcdc_info.ch[0].lcd_cfg.yres = 720;
597 lcdc_info.ch[0].lcd_cfg.left_margin = 220;
598 lcdc_info.ch[0].lcd_cfg.right_margin = 110;
599 lcdc_info.ch[0].lcd_cfg.hsync_len = 40;
600 lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
601 lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
602 lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
604 gpio_set_value(GPIO_PTA2, 1);
605 gpio_set_value(GPIO_PTU1, 1);
609 lcdc_info.clock_source = LCDC_CLK_PERIPHERAL;
610 lcdc_info.ch[0].clock_divider = 2,
611 lcdc_info.ch[0].lcd_cfg.name = "Panel";
612 lcdc_info.ch[0].lcd_cfg.xres = 800;
613 lcdc_info.ch[0].lcd_cfg.yres = 480;
614 lcdc_info.ch[0].lcd_cfg.left_margin = 220;
615 lcdc_info.ch[0].lcd_cfg.right_margin = 110;
616 lcdc_info.ch[0].lcd_cfg.hsync_len = 70;
617 lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
618 lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
619 lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
621 gpio_set_value(GPIO_PTR1, 1);
625 * LCDDON control is needed for Panel,
626 * but current sh_mobile_lcdc driver doesn't control it.
627 * It is temporary correspondence
629 gpio_request(GPIO_PTF4, NULL);
630 gpio_direction_output(GPIO_PTF4, 1);
632 /* enable TouchScreen */
633 i2c_register_board_info(0, &ts_i2c_clients, 1);
634 set_irq_type(IRQ0, IRQ_TYPE_LEVEL_LOW);
638 gpio_request(GPIO_FN_VIO0_D15, NULL);
639 gpio_request(GPIO_FN_VIO0_D14, NULL);
640 gpio_request(GPIO_FN_VIO0_D13, NULL);
641 gpio_request(GPIO_FN_VIO0_D12, NULL);
642 gpio_request(GPIO_FN_VIO0_D11, NULL);
643 gpio_request(GPIO_FN_VIO0_D10, NULL);
644 gpio_request(GPIO_FN_VIO0_D9, NULL);
645 gpio_request(GPIO_FN_VIO0_D8, NULL);
646 gpio_request(GPIO_FN_VIO0_D7, NULL);
647 gpio_request(GPIO_FN_VIO0_D6, NULL);
648 gpio_request(GPIO_FN_VIO0_D5, NULL);
649 gpio_request(GPIO_FN_VIO0_D4, NULL);
650 gpio_request(GPIO_FN_VIO0_D3, NULL);
651 gpio_request(GPIO_FN_VIO0_D2, NULL);
652 gpio_request(GPIO_FN_VIO0_D1, NULL);
653 gpio_request(GPIO_FN_VIO0_D0, NULL);
654 gpio_request(GPIO_FN_VIO0_VD, NULL);
655 gpio_request(GPIO_FN_VIO0_CLK, NULL);
656 gpio_request(GPIO_FN_VIO0_FLD, NULL);
657 gpio_request(GPIO_FN_VIO0_HD, NULL);
658 platform_resource_setup_memory(&ceu0_device, "ceu0", 4 << 20);
661 gpio_request(GPIO_FN_VIO1_D7, NULL);
662 gpio_request(GPIO_FN_VIO1_D6, NULL);
663 gpio_request(GPIO_FN_VIO1_D5, NULL);
664 gpio_request(GPIO_FN_VIO1_D4, NULL);
665 gpio_request(GPIO_FN_VIO1_D3, NULL);
666 gpio_request(GPIO_FN_VIO1_D2, NULL);
667 gpio_request(GPIO_FN_VIO1_D1, NULL);
668 gpio_request(GPIO_FN_VIO1_D0, NULL);
669 gpio_request(GPIO_FN_VIO1_FLD, NULL);
670 gpio_request(GPIO_FN_VIO1_HD, NULL);
671 gpio_request(GPIO_FN_VIO1_VD, NULL);
672 gpio_request(GPIO_FN_VIO1_CLK, NULL);
673 platform_resource_setup_memory(&ceu1_device, "ceu1", 4 << 20);
676 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
677 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
678 gpio_request(GPIO_FN_KEYOUT3, NULL);
679 gpio_request(GPIO_FN_KEYOUT2, NULL);
680 gpio_request(GPIO_FN_KEYOUT1, NULL);
681 gpio_request(GPIO_FN_KEYOUT0, NULL);
682 gpio_request(GPIO_FN_KEYIN0, NULL);
684 /* enable user debug switch */
685 gpio_request(GPIO_PTR0, NULL);
686 gpio_request(GPIO_PTR4, NULL);
687 gpio_request(GPIO_PTR5, NULL);
688 gpio_request(GPIO_PTR6, NULL);
689 gpio_direction_input(GPIO_PTR0);
690 gpio_direction_input(GPIO_PTR4);
691 gpio_direction_input(GPIO_PTR5);
692 gpio_direction_input(GPIO_PTR6);
694 /* enable I2C device */
695 i2c_register_board_info(1, i2c1_devices,
696 ARRAY_SIZE(i2c1_devices));
698 return platform_add_devices(ecovec_devices,
699 ARRAY_SIZE(ecovec_devices));
701 arch_initcall(arch_setup);
703 static int __init devices_setup(void)
708 device_initcall(devices_setup);
711 static struct sh_machine_vector mv_ecovec __initmv = {
712 .mv_name = "R0P7724 (EcoVec)",