2 * armadillo 800 eva board support
4 * Copyright (C) 2012 Renesas Solutions Corp.
5 * Copyright (C) 2012 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
22 #include <linux/clk.h>
23 #include <linux/delay.h>
24 #include <linux/err.h>
25 #include <linux/kernel.h>
26 #include <linux/input.h>
27 #include <linux/irq.h>
28 #include <linux/platform_device.h>
29 #include <linux/gpio.h>
30 #include <linux/gpio_keys.h>
31 #include <linux/sh_eth.h>
32 #include <linux/videodev2.h>
33 #include <linux/usb/renesas_usbhs.h>
34 #include <linux/mfd/tmio.h>
35 #include <linux/mmc/host.h>
36 #include <linux/mmc/sh_mobile_sdhi.h>
37 #include <mach/common.h>
38 #include <mach/irqs.h>
40 #include <asm/mach-types.h>
41 #include <asm/mach/arch.h>
42 #include <asm/mach/map.h>
43 #include <asm/mach/time.h>
44 #include <asm/hardware/cache-l2x0.h>
45 #include <mach/r8a7740.h>
46 #include <video/sh_mobile_lcdc.h>
52 * CON4 Composite Video Output
58 * CON10 Monaural Mic Input
59 * CON11 Stereo Headphone Output
60 * CON12 Audio Line Output(L)
61 * CON13 Audio Line Output(R)
72 * LED1 Camera LED(Yellow)
73 * LED2 Power LED (Green)
74 * ED3-LED6 User LED(Yellow)
75 * LED7 LAN link LED(Green)
76 * LED8 LAN activity LED(Yellow)
84 * -12345678-+---------------+----------------------------
86 * 0 | boot | OS auto boot
87 * -12345678-+---------------+----------------------------
88 * 00 | boot device | eMMC
89 * 10 | boot device | SDHI0 (CON7)
90 * 01 | boot device | -
91 * 11 | boot device | Extension Buss (CS0)
92 * -12345678-+---------------+----------------------------
93 * 0 | Extension Bus | D8-D15 disable, eMMC enable
94 * 1 | Extension Bus | D8-D15 enable, eMMC disable
95 * -12345678-+---------------+----------------------------
96 * 0 | SDHI1 | COM8 disable, COM14 enable
97 * 1 | SDHI1 | COM8 enable, COM14 disable
98 * -12345678-+---------------+----------------------------
99 * 0 | USB0 | COM20 enable, COM24 disable
100 * 1 | USB0 | COM20 disable, COM24 enable
101 * -12345678-+---------------+----------------------------
105 * 11 | JTAG | Boundary Scan
106 *-----------+---------------+----------------------------
112 * When you use USB Function,
113 * set SW1.6 ON, and connect cable to CN24.
115 * USBF needs workaround on R8A7740 chip.
116 * These are a little bit complex.
118 * usbhsf_power_ctrl()
122 * It uses autonomy mode for USB hotplug at this point
123 * (= usbhs_private.platform_callback.get_vbus is NULL),
124 * since we don't know what's happen on PM control
125 * on this workaround.
127 #define USBCR1 0xe605810a
128 #define USBH 0xC6700000
129 #define USBH_USBCTR 0x10834
131 struct usbhsf_private {
137 void __iomem *usbh_base;
138 struct renesas_usbhs_platform_info info;
141 #define usbhsf_get_priv(pdev) \
142 container_of(renesas_usbhs_get_info(pdev), \
143 struct usbhsf_private, info)
145 static int usbhsf_get_id(struct platform_device *pdev)
150 static void usbhsf_power_ctrl(struct platform_device *pdev,
151 void __iomem *base, int enable)
153 struct usbhsf_private *priv = usbhsf_get_priv(pdev);
156 * Work around for USB Function.
157 * It needs USB host clock, and settings
161 * enable all the related usb clocks
164 clk_enable(priv->usb24);
165 clk_enable(priv->pci);
166 clk_enable(priv->host);
167 clk_enable(priv->func);
168 clk_enable(priv->phy);
173 * Port1 is driven by USB function,
174 * Port2 is driven by USB HOST
175 * One HOST (Port1 or Port2 is HOST)
176 * USB PLL input clock = 24MHz
178 __raw_writew(0xd750, USBCR1);
184 __raw_writel(0x0000000c, priv->usbh_base + USBH_USBCTR);
185 __raw_writel(0x00000008, priv->usbh_base + USBH_USBCTR);
191 __raw_writew(0xd770, USBCR1);
192 __raw_writew(0x4000, base + 0x102); /* USBF :: SUSPMODE */
195 __raw_writel(0x0000010f, priv->usbh_base + USBH_USBCTR);
196 __raw_writew(0xd7c0, USBCR1); /* GPIO */
198 clk_disable(priv->phy);
199 clk_disable(priv->func); /* usb work around */
200 clk_disable(priv->host); /* usb work around */
201 clk_disable(priv->pci); /* usb work around */
202 clk_disable(priv->usb24); /* usb work around */
206 static void usbhsf_hardware_exit(struct platform_device *pdev)
208 struct usbhsf_private *priv = usbhsf_get_priv(pdev);
210 if (!IS_ERR(priv->phy))
212 if (!IS_ERR(priv->usb24))
213 clk_put(priv->usb24);
214 if (!IS_ERR(priv->pci))
216 if (!IS_ERR(priv->host))
218 if (!IS_ERR(priv->func))
221 iounmap(priv->usbh_base);
228 priv->usbh_base = NULL;
231 static int usbhsf_hardware_init(struct platform_device *pdev)
233 struct usbhsf_private *priv = usbhsf_get_priv(pdev);
235 priv->phy = clk_get(&pdev->dev, "phy");
236 priv->usb24 = clk_get(&pdev->dev, "usb24");
237 priv->pci = clk_get(&pdev->dev, "pci");
238 priv->func = clk_get(&pdev->dev, "func");
239 priv->host = clk_get(&pdev->dev, "host");
240 priv->usbh_base = ioremap_nocache(USBH, 0x20000);
242 if (IS_ERR(priv->phy) ||
243 IS_ERR(priv->usb24) ||
245 IS_ERR(priv->host) ||
246 IS_ERR(priv->func) ||
248 dev_err(&pdev->dev, "USB clock setting failed\n");
249 usbhsf_hardware_exit(pdev);
253 /* usb24 use 1/1 of parent clock (= usb24s = 24MHz) */
254 clk_set_rate(priv->usb24,
255 clk_get_rate(clk_get_parent(priv->usb24)));
260 static struct usbhsf_private usbhsf_private = {
262 .platform_callback = {
263 .get_id = usbhsf_get_id,
264 .hardware_init = usbhsf_hardware_init,
265 .hardware_exit = usbhsf_hardware_exit,
266 .power_ctrl = usbhsf_power_ctrl,
270 .detection_delay = 5,
275 static struct resource usbhsf_resources[] = {
279 .end = 0xe6890104 - 1,
280 .flags = IORESOURCE_MEM,
283 .start = evt2irq(0x0A20),
284 .flags = IORESOURCE_IRQ,
288 static struct platform_device usbhsf_device = {
289 .name = "renesas_usbhs",
291 .platform_data = &usbhsf_private.info,
294 .num_resources = ARRAY_SIZE(usbhsf_resources),
295 .resource = usbhsf_resources,
299 static struct sh_eth_plat_data sh_eth_platdata = {
300 .phy = 0x00, /* LAN8710A */
301 .edmac_endian = EDMAC_LITTLE_ENDIAN,
302 .register_type = SH_ETH_REG_GIGABIT,
303 .phy_interface = PHY_INTERFACE_MODE_MII,
306 static struct resource sh_eth_resources[] = {
309 .end = 0xe9a00800 - 1,
310 .flags = IORESOURCE_MEM,
313 .end = 0xe9a02000 - 1,
314 .flags = IORESOURCE_MEM,
316 .start = evt2irq(0x0500),
317 .flags = IORESOURCE_IRQ,
321 static struct platform_device sh_eth_device = {
324 .platform_data = &sh_eth_platdata,
326 .resource = sh_eth_resources,
327 .num_resources = ARRAY_SIZE(sh_eth_resources),
331 static struct fb_videomode lcdc0_mode = {
332 .name = "AMPIER/AM-800480",
344 static struct sh_mobile_lcdc_info lcdc0_info = {
345 .clock_source = LCDC_CLK_BUS,
347 .chan = LCDC_CHAN_MAINLCD,
348 .fourcc = V4L2_PIX_FMT_RGB565,
349 .interface_type = RGB24,
352 .lcd_modes = &lcdc0_mode,
361 static struct resource lcdc0_resources[] = {
366 .flags = IORESOURCE_MEM,
369 .start = intcs_evt2irq(0x580),
370 .flags = IORESOURCE_IRQ,
374 static struct platform_device lcdc0_device = {
375 .name = "sh_mobile_lcdc_fb",
376 .num_resources = ARRAY_SIZE(lcdc0_resources),
377 .resource = lcdc0_resources,
380 .platform_data = &lcdc0_info,
381 .coherent_dma_mask = ~0,
386 #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
388 static struct gpio_keys_button gpio_buttons[] = {
389 GPIO_KEY(KEY_POWER, GPIO_PORT99, "SW1"),
390 GPIO_KEY(KEY_BACK, GPIO_PORT100, "SW2"),
391 GPIO_KEY(KEY_MENU, GPIO_PORT97, "SW3"),
392 GPIO_KEY(KEY_HOME, GPIO_PORT98, "SW4"),
395 static struct gpio_keys_platform_data gpio_key_info = {
396 .buttons = gpio_buttons,
397 .nbuttons = ARRAY_SIZE(gpio_buttons),
400 static struct platform_device gpio_keys_device = {
404 .platform_data = &gpio_key_info,
412 * It use polling mode here, since
413 * CD (= Card Detect) pin is not connected to SDHI0_CD.
414 * We can use IRQ31 as card detect irq,
415 * but it needs chattering removal operation
417 #define IRQ31 evt2irq(0x33E0)
418 static struct sh_mobile_sdhi_info sdhi0_info = {
419 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |\
421 .tmio_ocr_mask = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
422 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
425 static struct resource sdhi0_resources[] = {
429 .end = 0xe6850100 - 1,
430 .flags = IORESOURCE_MEM,
433 * no SH_MOBILE_SDHI_IRQ_CARD_DETECT here
436 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
437 .start = evt2irq(0x0E20),
438 .flags = IORESOURCE_IRQ,
441 .name = SH_MOBILE_SDHI_IRQ_SDIO,
442 .start = evt2irq(0x0E40),
443 .flags = IORESOURCE_IRQ,
447 static struct platform_device sdhi0_device = {
448 .name = "sh_mobile_sdhi",
451 .platform_data = &sdhi0_info,
453 .num_resources = ARRAY_SIZE(sdhi0_resources),
454 .resource = sdhi0_resources,
458 static struct sh_mobile_sdhi_info sdhi1_info = {
459 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
460 .tmio_ocr_mask = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
461 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
464 static struct resource sdhi1_resources[] = {
468 .end = 0xe6860100 - 1,
469 .flags = IORESOURCE_MEM,
472 .start = evt2irq(0x0E80),
473 .flags = IORESOURCE_IRQ,
476 .start = evt2irq(0x0EA0),
477 .flags = IORESOURCE_IRQ,
480 .start = evt2irq(0x0EC0),
481 .flags = IORESOURCE_IRQ,
485 static struct platform_device sdhi1_device = {
486 .name = "sh_mobile_sdhi",
489 .platform_data = &sdhi1_info,
491 .num_resources = ARRAY_SIZE(sdhi1_resources),
492 .resource = sdhi1_resources,
496 static struct i2c_board_info i2c0_devices[] = {
498 I2C_BOARD_INFO("st1232-ts", 0x55),
499 .irq = evt2irq(0x0340),
506 static struct platform_device *eva_devices[] __initdata = {
513 static void __init eva_clock_init(void)
515 struct clk *system = clk_get(NULL, "system_clk");
516 struct clk *xtal1 = clk_get(NULL, "extal1");
517 struct clk *usb24s = clk_get(NULL, "usb24s");
519 if (IS_ERR(system) ||
522 pr_err("armadillo800eva board clock init failed\n");
526 /* armadillo 800 eva extal1 is 24MHz */
527 clk_set_rate(xtal1, 24000000);
529 /* usb24s use extal1 (= system) clock (= 24MHz) */
530 clk_set_parent(usb24s, system);
544 static void __init eva_init(void)
548 r8a7740_pinmux_init();
551 gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
552 gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
555 gpio_request(GPIO_FN_LCDC0_SELECT, NULL);
556 gpio_request(GPIO_FN_LCD0_D0, NULL);
557 gpio_request(GPIO_FN_LCD0_D1, NULL);
558 gpio_request(GPIO_FN_LCD0_D2, NULL);
559 gpio_request(GPIO_FN_LCD0_D3, NULL);
560 gpio_request(GPIO_FN_LCD0_D4, NULL);
561 gpio_request(GPIO_FN_LCD0_D5, NULL);
562 gpio_request(GPIO_FN_LCD0_D6, NULL);
563 gpio_request(GPIO_FN_LCD0_D7, NULL);
564 gpio_request(GPIO_FN_LCD0_D8, NULL);
565 gpio_request(GPIO_FN_LCD0_D9, NULL);
566 gpio_request(GPIO_FN_LCD0_D10, NULL);
567 gpio_request(GPIO_FN_LCD0_D11, NULL);
568 gpio_request(GPIO_FN_LCD0_D12, NULL);
569 gpio_request(GPIO_FN_LCD0_D13, NULL);
570 gpio_request(GPIO_FN_LCD0_D14, NULL);
571 gpio_request(GPIO_FN_LCD0_D15, NULL);
572 gpio_request(GPIO_FN_LCD0_D16, NULL);
573 gpio_request(GPIO_FN_LCD0_D17, NULL);
574 gpio_request(GPIO_FN_LCD0_D18_PORT40, NULL);
575 gpio_request(GPIO_FN_LCD0_D19_PORT4, NULL);
576 gpio_request(GPIO_FN_LCD0_D20_PORT3, NULL);
577 gpio_request(GPIO_FN_LCD0_D21_PORT2, NULL);
578 gpio_request(GPIO_FN_LCD0_D22_PORT0, NULL);
579 gpio_request(GPIO_FN_LCD0_D23_PORT1, NULL);
580 gpio_request(GPIO_FN_LCD0_DCK, NULL);
581 gpio_request(GPIO_FN_LCD0_VSYN, NULL);
582 gpio_request(GPIO_FN_LCD0_HSYN, NULL);
583 gpio_request(GPIO_FN_LCD0_DISP, NULL);
584 gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL);
586 gpio_request(GPIO_PORT61, NULL); /* LCDDON */
587 gpio_direction_output(GPIO_PORT61, 1);
589 gpio_request(GPIO_PORT202, NULL); /* LCD0_LED_CONT */
590 gpio_direction_output(GPIO_PORT202, 0);
593 gpio_request(GPIO_FN_IRQ10, NULL); /* TP_INT */
594 gpio_request(GPIO_PORT166, NULL); /* TP_RST_B */
595 gpio_direction_output(GPIO_PORT166, 1);
598 gpio_request(GPIO_FN_ET_CRS, NULL);
599 gpio_request(GPIO_FN_ET_MDC, NULL);
600 gpio_request(GPIO_FN_ET_MDIO, NULL);
601 gpio_request(GPIO_FN_ET_TX_ER, NULL);
602 gpio_request(GPIO_FN_ET_RX_ER, NULL);
603 gpio_request(GPIO_FN_ET_ERXD0, NULL);
604 gpio_request(GPIO_FN_ET_ERXD1, NULL);
605 gpio_request(GPIO_FN_ET_ERXD2, NULL);
606 gpio_request(GPIO_FN_ET_ERXD3, NULL);
607 gpio_request(GPIO_FN_ET_TX_CLK, NULL);
608 gpio_request(GPIO_FN_ET_TX_EN, NULL);
609 gpio_request(GPIO_FN_ET_ETXD0, NULL);
610 gpio_request(GPIO_FN_ET_ETXD1, NULL);
611 gpio_request(GPIO_FN_ET_ETXD2, NULL);
612 gpio_request(GPIO_FN_ET_ETXD3, NULL);
613 gpio_request(GPIO_FN_ET_PHY_INT, NULL);
614 gpio_request(GPIO_FN_ET_COL, NULL);
615 gpio_request(GPIO_FN_ET_RX_DV, NULL);
616 gpio_request(GPIO_FN_ET_RX_CLK, NULL);
618 gpio_request(GPIO_PORT18, NULL); /* PHY_RST */
619 gpio_direction_output(GPIO_PORT18, 1);
622 gpio_request(GPIO_PORT159, NULL); /* USB_DEVICE_MODE */
623 gpio_direction_input(GPIO_PORT159);
625 if (gpio_get_value(GPIO_PORT159)) {
629 gpio_request(GPIO_FN_VBUS, NULL);
630 platform_device_register(&usbhsf_device);
634 gpio_request(GPIO_FN_SDHI0_CMD, NULL);
635 gpio_request(GPIO_FN_SDHI0_CLK, NULL);
636 gpio_request(GPIO_FN_SDHI0_D0, NULL);
637 gpio_request(GPIO_FN_SDHI0_D1, NULL);
638 gpio_request(GPIO_FN_SDHI0_D2, NULL);
639 gpio_request(GPIO_FN_SDHI0_D3, NULL);
640 gpio_request(GPIO_FN_SDHI0_WP, NULL);
642 gpio_request(GPIO_PORT17, NULL); /* SDHI0_18/33_B */
643 gpio_request(GPIO_PORT74, NULL); /* SDHI0_PON */
644 gpio_request(GPIO_PORT75, NULL); /* SDSLOT1_PON */
645 gpio_direction_output(GPIO_PORT17, 0);
646 gpio_direction_output(GPIO_PORT74, 1);
647 gpio_direction_output(GPIO_PORT75, 1);
649 /* we can use GPIO_FN_IRQ31_PORT167 here for SDHI0 CD irq */
654 * DBGMD/LCDC0/FSIA MUX
655 * DBGMD_SELECT_B should be set after setting PFC Function.
657 gpio_request(GPIO_PORT176, NULL);
658 gpio_direction_output(GPIO_PORT176, 1);
661 * We can switch CON8/CON14 by SW1.5,
662 * but it needs after DBGMD_SELECT_B
664 gpio_request(GPIO_PORT6, NULL);
665 gpio_direction_input(GPIO_PORT6);
666 if (gpio_get_value(GPIO_PORT6)) {
669 /* CON8 (SDHI1) enable */
670 gpio_request(GPIO_FN_SDHI1_CLK, NULL);
671 gpio_request(GPIO_FN_SDHI1_CMD, NULL);
672 gpio_request(GPIO_FN_SDHI1_D0, NULL);
673 gpio_request(GPIO_FN_SDHI1_D1, NULL);
674 gpio_request(GPIO_FN_SDHI1_D2, NULL);
675 gpio_request(GPIO_FN_SDHI1_D3, NULL);
676 gpio_request(GPIO_FN_SDHI1_CD, NULL);
677 gpio_request(GPIO_FN_SDHI1_WP, NULL);
679 gpio_request(GPIO_PORT16, NULL); /* SDSLOT2_PON */
680 gpio_direction_output(GPIO_PORT16, 1);
682 platform_device_register(&sdhi1_device);
686 #ifdef CONFIG_CACHE_L2X0
687 /* Early BRESP enable, Shared attribute override enable, 32K*8way */
688 l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
691 i2c_register_board_info(0, i2c0_devices, ARRAY_SIZE(i2c0_devices));
693 r8a7740_add_standard_devices();
695 platform_add_devices(eva_devices,
696 ARRAY_SIZE(eva_devices));
699 static void __init eva_earlytimer_init(void)
701 r8a7740_clock_init(MD_CK0 | MD_CK2);
702 shmobile_earlytimer_init();
705 static void __init eva_add_early_devices(void)
707 r8a7740_add_early_devices();
709 /* override timer setup with board-specific code */
710 shmobile_timer.init = eva_earlytimer_init;
713 MACHINE_START(ARMADILLO800EVA, "armadillo800eva")
714 .map_io = r8a7740_map_io,
715 .init_early = eva_add_early_devices,
716 .init_irq = r8a7740_init_irq,
717 .handle_irq = shmobile_handle_irq_intc,
718 .init_machine = eva_init,
719 .timer = &shmobile_timer,