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/input.h>
22 #include <video/sh_mobile_lcdc.h>
23 #include <media/sh_mobile_ceu.h>
24 #include <asm/heartbeat.h>
25 #include <asm/sh_eth.h>
26 #include <asm/sh_keysc.h>
27 #include <cpu/sh7724.h>
30 * Address Interface BusWidth
31 *-----------------------------------------
32 * 0x0000_0000 uboot 16bit
33 * 0x0004_0000 Linux romImage 16bit
34 * 0x0014_0000 MTD for Linux 16bit
35 * 0x0400_0000 Internal I/O 16/32bit
36 * 0x0800_0000 DRAM 32bit
37 * 0x1800_0000 MFI 16bit
41 static unsigned char led_pos[] = { 0, 1, 2, 3 };
42 static struct heartbeat_data heartbeat_data = {
48 static struct resource heartbeat_resources[] = {
50 .start = 0xA405012C, /* PTG */
51 .end = 0xA405012E - 1,
52 .flags = IORESOURCE_MEM,
56 static struct platform_device heartbeat_device = {
60 .platform_data = &heartbeat_data,
62 .num_resources = ARRAY_SIZE(heartbeat_resources),
63 .resource = heartbeat_resources,
67 static struct mtd_partition nor_flash_partitions[] = {
69 .name = "boot loader",
71 .size = (5 * 1024 * 1024),
72 .mask_flags = MTD_CAP_ROM,
75 .offset = MTDPART_OFS_APPEND,
76 .size = MTDPART_SIZ_FULL,
80 static struct physmap_flash_data nor_flash_data = {
82 .parts = nor_flash_partitions,
83 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
86 static struct resource nor_flash_resources[] = {
91 .flags = IORESOURCE_MEM,
95 static struct platform_device nor_flash_device = {
96 .name = "physmap-flash",
97 .resource = nor_flash_resources,
98 .num_resources = ARRAY_SIZE(nor_flash_resources),
100 .platform_data = &nor_flash_data,
105 #define SH_ETH_ADDR (0xA4600000)
106 #define SH_ETH_MAHR (SH_ETH_ADDR + 0x1C0)
107 #define SH_ETH_MALR (SH_ETH_ADDR + 0x1C8)
108 static struct resource sh_eth_resources[] = {
110 .start = SH_ETH_ADDR,
111 .end = SH_ETH_ADDR + 0x1FC,
112 .flags = IORESOURCE_MEM,
116 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
120 struct sh_eth_plat_data sh_eth_plat = {
121 .phy = 0x1f, /* SMSC LAN8700 */
122 .edmac_endian = EDMAC_LITTLE_ENDIAN,
125 static struct platform_device sh_eth_device = {
129 .platform_data = &sh_eth_plat,
131 .num_resources = ARRAY_SIZE(sh_eth_resources),
132 .resource = sh_eth_resources,
136 void usb0_port_power(int port, int power)
138 gpio_set_value(GPIO_PTB4, power);
141 static struct r8a66597_platdata usb0_host_data = {
143 .port_power = usb0_port_power,
146 static struct resource usb0_host_resources[] = {
149 .end = 0xa4d80124 - 1,
150 .flags = IORESOURCE_MEM,
155 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
159 static struct platform_device usb0_host_device = {
160 .name = "r8a66597_hcd",
163 .dma_mask = NULL, /* not use dma */
164 .coherent_dma_mask = 0xffffffff,
165 .platform_data = &usb0_host_data,
167 .num_resources = ARRAY_SIZE(usb0_host_resources),
168 .resource = usb0_host_resources,
174 * CN5 can use both host/function,
175 * and we can determine it by checking PTB[3]
177 * This time only USB1 host is supported.
179 void usb1_port_power(int port, int power)
181 if (!gpio_get_value(GPIO_PTB3)) {
182 printk(KERN_ERR "USB1 function is not supported\n");
186 gpio_set_value(GPIO_PTB5, power);
189 static struct r8a66597_platdata usb1_host_data = {
191 .port_power = usb1_port_power,
194 static struct resource usb1_host_resources[] = {
197 .end = 0xa4d90124 - 1,
198 .flags = IORESOURCE_MEM,
203 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
207 static struct platform_device usb1_host_device = {
208 .name = "r8a66597_hcd",
211 .dma_mask = NULL, /* not use dma */
212 .coherent_dma_mask = 0xffffffff,
213 .platform_data = &usb1_host_data,
215 .num_resources = ARRAY_SIZE(usb1_host_resources),
216 .resource = usb1_host_resources,
220 static struct sh_mobile_lcdc_info lcdc_info = {
222 .interface_type = RGB18,
223 .chan = LCDC_CHAN_MAINLCD,
226 .sync = 0, /* hsync and vsync are active low */
228 .lcd_size_cfg = { /* 7.0 inch */
237 static struct resource lcdc_resources[] = {
242 .flags = IORESOURCE_MEM,
246 .flags = IORESOURCE_IRQ,
250 static struct platform_device lcdc_device = {
251 .name = "sh_mobile_lcdc_fb",
252 .num_resources = ARRAY_SIZE(lcdc_resources),
253 .resource = lcdc_resources,
255 .platform_data = &lcdc_info,
258 .hwblk_id = HWBLK_LCDC,
263 static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
264 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
267 static struct resource ceu0_resources[] = {
272 .flags = IORESOURCE_MEM,
276 .flags = IORESOURCE_IRQ,
279 /* place holder for contiguous memory */
283 static struct platform_device ceu0_device = {
284 .name = "sh_mobile_ceu",
285 .id = 0, /* "ceu0" clock */
286 .num_resources = ARRAY_SIZE(ceu0_resources),
287 .resource = ceu0_resources,
289 .platform_data = &sh_mobile_ceu0_info,
292 .hwblk_id = HWBLK_CEU0,
297 static struct sh_mobile_ceu_info sh_mobile_ceu1_info = {
298 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
301 static struct resource ceu1_resources[] = {
306 .flags = IORESOURCE_MEM,
310 .flags = IORESOURCE_IRQ,
313 /* place holder for contiguous memory */
317 static struct platform_device ceu1_device = {
318 .name = "sh_mobile_ceu",
319 .id = 1, /* "ceu1" clock */
320 .num_resources = ARRAY_SIZE(ceu1_resources),
321 .resource = ceu1_resources,
323 .platform_data = &sh_mobile_ceu1_info,
326 .hwblk_id = HWBLK_CEU1,
331 static struct i2c_board_info i2c1_devices[] = {
333 I2C_BOARD_INFO("r2025sd", 0x32),
338 static struct sh_keysc_info keysc_info = {
339 .mode = SH_KEYSC_MODE_1,
343 .keycodes = { KEY_1, 0, 0, 0, 0,
348 KEY_6, 0, 0, 0, 0, },
351 static struct resource keysc_resources[] = {
356 .flags = IORESOURCE_MEM,
360 .flags = IORESOURCE_IRQ,
364 static struct platform_device keysc_device = {
366 .id = 0, /* keysc0 clock */
367 .num_resources = ARRAY_SIZE(keysc_resources),
368 .resource = keysc_resources,
370 .platform_data = &keysc_info,
373 .hwblk_id = HWBLK_KEYSC,
377 static struct platform_device *ecovec_devices[] __initdata = {
382 &usb1_host_device, /* USB1 host support */
389 #define EEPROM_ADDR 0x50
390 static u8 mac_read(struct i2c_adapter *a, u8 command)
392 struct i2c_msg msg[2];
396 msg[0].addr = EEPROM_ADDR;
399 msg[0].buf = &command;
401 msg[1].addr = EEPROM_ADDR;
402 msg[1].flags = I2C_M_RD;
406 ret = i2c_transfer(a, msg, 2);
408 printk(KERN_ERR "error %d\n", ret);
416 static void __init sh_eth_init(void)
418 struct i2c_adapter *a = i2c_get_adapter(1);
424 pr_err("can not get I2C 1\n");
428 eth_clk = clk_get(NULL, "eth0");
430 pr_err("can not get eth0 clk\n");
434 /* read MAC address frome EEPROM */
435 for (i = 0; i < MAC_LEN; i++) {
436 mac[i] = mac_read(a, 0x10 + i);
444 ctrl_outl(0x1, SH_ETH_ADDR + 0x0);
447 ctrl_outl((mac[0] << 24) |
450 (mac[3] << 0), SH_ETH_MAHR);
451 ctrl_outl((mac[4] << 8) |
452 (mac[5] << 0), SH_ETH_MALR);
457 #define PORT_HIZA 0xA4050158
458 #define IODRIVEA 0xA405018A
459 static int __init arch_setup(void)
462 gpio_request(GPIO_FN_SCIF0_TXD, NULL);
463 gpio_request(GPIO_FN_SCIF0_RXD, NULL);
465 /* enable debug LED */
466 gpio_request(GPIO_PTG0, NULL);
467 gpio_request(GPIO_PTG1, NULL);
468 gpio_request(GPIO_PTG2, NULL);
469 gpio_request(GPIO_PTG3, NULL);
470 gpio_direction_output(GPIO_PTG0, 0);
471 gpio_direction_output(GPIO_PTG1, 0);
472 gpio_direction_output(GPIO_PTG2, 0);
473 gpio_direction_output(GPIO_PTG3, 0);
474 ctrl_outw((ctrl_inw(PORT_HIZA) & ~(0x1 << 1)) , PORT_HIZA);
477 gpio_request(GPIO_PTA1, NULL);
478 gpio_direction_output(GPIO_PTA1, 1);
481 gpio_request(GPIO_FN_RMII_RXD0, NULL);
482 gpio_request(GPIO_FN_RMII_RXD1, NULL);
483 gpio_request(GPIO_FN_RMII_TXD0, NULL);
484 gpio_request(GPIO_FN_RMII_TXD1, NULL);
485 gpio_request(GPIO_FN_RMII_REF_CLK, NULL);
486 gpio_request(GPIO_FN_RMII_TX_EN, NULL);
487 gpio_request(GPIO_FN_RMII_RX_ER, NULL);
488 gpio_request(GPIO_FN_RMII_CRS_DV, NULL);
489 gpio_request(GPIO_FN_MDIO, NULL);
490 gpio_request(GPIO_FN_MDC, NULL);
491 gpio_request(GPIO_FN_LNKSTA, NULL);
494 ctrl_outw(0x0000, 0xA4D80000);
495 ctrl_outw(0x0000, 0xA4D90000);
496 gpio_request(GPIO_PTB3, NULL);
497 gpio_request(GPIO_PTB4, NULL);
498 gpio_request(GPIO_PTB5, NULL);
499 gpio_direction_input(GPIO_PTB3);
500 gpio_direction_output(GPIO_PTB4, 0);
501 gpio_direction_output(GPIO_PTB5, 0);
502 ctrl_outw(0x0600, 0xa40501d4);
503 ctrl_outw(0x0600, 0xa4050192);
506 gpio_request(GPIO_FN_LCDD23, NULL);
507 gpio_request(GPIO_FN_LCDD22, NULL);
508 gpio_request(GPIO_FN_LCDD21, NULL);
509 gpio_request(GPIO_FN_LCDD20, NULL);
510 gpio_request(GPIO_FN_LCDD19, NULL);
511 gpio_request(GPIO_FN_LCDD18, NULL);
512 gpio_request(GPIO_FN_LCDD17, NULL);
513 gpio_request(GPIO_FN_LCDD16, NULL);
514 gpio_request(GPIO_FN_LCDD15, NULL);
515 gpio_request(GPIO_FN_LCDD14, NULL);
516 gpio_request(GPIO_FN_LCDD13, NULL);
517 gpio_request(GPIO_FN_LCDD12, NULL);
518 gpio_request(GPIO_FN_LCDD11, NULL);
519 gpio_request(GPIO_FN_LCDD10, NULL);
520 gpio_request(GPIO_FN_LCDD9, NULL);
521 gpio_request(GPIO_FN_LCDD8, NULL);
522 gpio_request(GPIO_FN_LCDD7, NULL);
523 gpio_request(GPIO_FN_LCDD6, NULL);
524 gpio_request(GPIO_FN_LCDD5, NULL);
525 gpio_request(GPIO_FN_LCDD4, NULL);
526 gpio_request(GPIO_FN_LCDD3, NULL);
527 gpio_request(GPIO_FN_LCDD2, NULL);
528 gpio_request(GPIO_FN_LCDD1, NULL);
529 gpio_request(GPIO_FN_LCDD0, NULL);
530 gpio_request(GPIO_FN_LCDDISP, NULL);
531 gpio_request(GPIO_FN_LCDHSYN, NULL);
532 gpio_request(GPIO_FN_LCDDCK, NULL);
533 gpio_request(GPIO_FN_LCDVSYN, NULL);
534 gpio_request(GPIO_FN_LCDDON, NULL);
535 gpio_request(GPIO_FN_LCDLCLK, NULL);
536 ctrl_outw((ctrl_inw(PORT_HIZA) & ~0x0001), PORT_HIZA);
538 gpio_request(GPIO_PTE6, NULL);
539 gpio_request(GPIO_PTU1, NULL);
540 gpio_request(GPIO_PTR1, NULL);
541 gpio_request(GPIO_PTA2, NULL);
542 gpio_direction_input(GPIO_PTE6);
543 gpio_direction_output(GPIO_PTU1, 0);
544 gpio_direction_output(GPIO_PTR1, 0);
545 gpio_direction_output(GPIO_PTA2, 0);
547 /* I/O buffer drive ability is low */
548 ctrl_outw((ctrl_inw(IODRIVEA) & ~0x00c0) | 0x0040 , IODRIVEA);
550 if (gpio_get_value(GPIO_PTE6)) {
552 lcdc_info.clock_source = LCDC_CLK_EXTERNAL;
553 lcdc_info.ch[0].clock_divider = 1,
554 lcdc_info.ch[0].lcd_cfg.name = "DVI";
555 lcdc_info.ch[0].lcd_cfg.xres = 1280;
556 lcdc_info.ch[0].lcd_cfg.yres = 720;
557 lcdc_info.ch[0].lcd_cfg.left_margin = 220;
558 lcdc_info.ch[0].lcd_cfg.right_margin = 110;
559 lcdc_info.ch[0].lcd_cfg.hsync_len = 40;
560 lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
561 lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
562 lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
564 gpio_set_value(GPIO_PTA2, 1);
565 gpio_set_value(GPIO_PTU1, 1);
569 lcdc_info.clock_source = LCDC_CLK_PERIPHERAL;
570 lcdc_info.ch[0].clock_divider = 2,
571 lcdc_info.ch[0].lcd_cfg.name = "Panel";
572 lcdc_info.ch[0].lcd_cfg.xres = 800;
573 lcdc_info.ch[0].lcd_cfg.yres = 480;
574 lcdc_info.ch[0].lcd_cfg.left_margin = 220;
575 lcdc_info.ch[0].lcd_cfg.right_margin = 110;
576 lcdc_info.ch[0].lcd_cfg.hsync_len = 70;
577 lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
578 lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
579 lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
581 gpio_set_value(GPIO_PTR1, 1);
585 * LCDDON control is needed for Panel,
586 * but current sh_mobile_lcdc driver doesn't control it.
587 * It is temporary correspondence
589 gpio_request(GPIO_PTF4, NULL);
590 gpio_direction_output(GPIO_PTF4, 1);
594 gpio_request(GPIO_FN_VIO0_D15, NULL);
595 gpio_request(GPIO_FN_VIO0_D14, NULL);
596 gpio_request(GPIO_FN_VIO0_D13, NULL);
597 gpio_request(GPIO_FN_VIO0_D12, NULL);
598 gpio_request(GPIO_FN_VIO0_D11, NULL);
599 gpio_request(GPIO_FN_VIO0_D10, NULL);
600 gpio_request(GPIO_FN_VIO0_D9, NULL);
601 gpio_request(GPIO_FN_VIO0_D8, NULL);
602 gpio_request(GPIO_FN_VIO0_D7, NULL);
603 gpio_request(GPIO_FN_VIO0_D6, NULL);
604 gpio_request(GPIO_FN_VIO0_D5, NULL);
605 gpio_request(GPIO_FN_VIO0_D4, NULL);
606 gpio_request(GPIO_FN_VIO0_D3, NULL);
607 gpio_request(GPIO_FN_VIO0_D2, NULL);
608 gpio_request(GPIO_FN_VIO0_D1, NULL);
609 gpio_request(GPIO_FN_VIO0_D0, NULL);
610 gpio_request(GPIO_FN_VIO0_VD, NULL);
611 gpio_request(GPIO_FN_VIO0_CLK, NULL);
612 gpio_request(GPIO_FN_VIO0_FLD, NULL);
613 gpio_request(GPIO_FN_VIO0_HD, NULL);
614 platform_resource_setup_memory(&ceu0_device, "ceu0", 4 << 20);
617 gpio_request(GPIO_FN_VIO1_D7, NULL);
618 gpio_request(GPIO_FN_VIO1_D6, NULL);
619 gpio_request(GPIO_FN_VIO1_D5, NULL);
620 gpio_request(GPIO_FN_VIO1_D4, NULL);
621 gpio_request(GPIO_FN_VIO1_D3, NULL);
622 gpio_request(GPIO_FN_VIO1_D2, NULL);
623 gpio_request(GPIO_FN_VIO1_D1, NULL);
624 gpio_request(GPIO_FN_VIO1_D0, NULL);
625 gpio_request(GPIO_FN_VIO1_FLD, NULL);
626 gpio_request(GPIO_FN_VIO1_HD, NULL);
627 gpio_request(GPIO_FN_VIO1_VD, NULL);
628 gpio_request(GPIO_FN_VIO1_CLK, NULL);
629 platform_resource_setup_memory(&ceu1_device, "ceu1", 4 << 20);
632 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
633 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
634 gpio_request(GPIO_FN_KEYOUT3, NULL);
635 gpio_request(GPIO_FN_KEYOUT2, NULL);
636 gpio_request(GPIO_FN_KEYOUT1, NULL);
637 gpio_request(GPIO_FN_KEYOUT0, NULL);
638 gpio_request(GPIO_FN_KEYIN0, NULL);
640 /* enable I2C device */
641 i2c_register_board_info(1, i2c1_devices,
642 ARRAY_SIZE(i2c1_devices));
644 return platform_add_devices(ecovec_devices,
645 ARRAY_SIZE(ecovec_devices));
647 arch_initcall(arch_setup);
649 static int __init devices_setup(void)
654 device_initcall(devices_setup);
657 static struct sh_machine_vector mv_ecovec __initmv = {
658 .mv_name = "R0P7724 (EcoVec)",