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 enable, COM14 disable
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 i2c_board_info i2c0_devices
[] = {
460 I2C_BOARD_INFO("st1232-ts", 0x55),
461 .irq
= evt2irq(0x0340),
468 static struct platform_device
*eva_devices
[] __initdata
= {
475 static void __init
eva_clock_init(void)
477 struct clk
*system
= clk_get(NULL
, "system_clk");
478 struct clk
*xtal1
= clk_get(NULL
, "extal1");
479 struct clk
*usb24s
= clk_get(NULL
, "usb24s");
481 if (IS_ERR(system
) ||
484 pr_err("armadillo800eva board clock init failed\n");
488 /* armadillo 800 eva extal1 is 24MHz */
489 clk_set_rate(xtal1
, 24000000);
491 /* usb24s use extal1 (= system) clock (= 24MHz) */
492 clk_set_parent(usb24s
, system
);
506 static void __init
eva_init(void)
510 r8a7740_pinmux_init();
513 gpio_request(GPIO_FN_SCIFA1_RXD
, NULL
);
514 gpio_request(GPIO_FN_SCIFA1_TXD
, NULL
);
517 gpio_request(GPIO_FN_LCDC0_SELECT
, NULL
);
518 gpio_request(GPIO_FN_LCD0_D0
, NULL
);
519 gpio_request(GPIO_FN_LCD0_D1
, NULL
);
520 gpio_request(GPIO_FN_LCD0_D2
, NULL
);
521 gpio_request(GPIO_FN_LCD0_D3
, NULL
);
522 gpio_request(GPIO_FN_LCD0_D4
, NULL
);
523 gpio_request(GPIO_FN_LCD0_D5
, NULL
);
524 gpio_request(GPIO_FN_LCD0_D6
, NULL
);
525 gpio_request(GPIO_FN_LCD0_D7
, NULL
);
526 gpio_request(GPIO_FN_LCD0_D8
, NULL
);
527 gpio_request(GPIO_FN_LCD0_D9
, NULL
);
528 gpio_request(GPIO_FN_LCD0_D10
, NULL
);
529 gpio_request(GPIO_FN_LCD0_D11
, NULL
);
530 gpio_request(GPIO_FN_LCD0_D12
, NULL
);
531 gpio_request(GPIO_FN_LCD0_D13
, NULL
);
532 gpio_request(GPIO_FN_LCD0_D14
, NULL
);
533 gpio_request(GPIO_FN_LCD0_D15
, NULL
);
534 gpio_request(GPIO_FN_LCD0_D16
, NULL
);
535 gpio_request(GPIO_FN_LCD0_D17
, NULL
);
536 gpio_request(GPIO_FN_LCD0_D18_PORT40
, NULL
);
537 gpio_request(GPIO_FN_LCD0_D19_PORT4
, NULL
);
538 gpio_request(GPIO_FN_LCD0_D20_PORT3
, NULL
);
539 gpio_request(GPIO_FN_LCD0_D21_PORT2
, NULL
);
540 gpio_request(GPIO_FN_LCD0_D22_PORT0
, NULL
);
541 gpio_request(GPIO_FN_LCD0_D23_PORT1
, NULL
);
542 gpio_request(GPIO_FN_LCD0_DCK
, NULL
);
543 gpio_request(GPIO_FN_LCD0_VSYN
, NULL
);
544 gpio_request(GPIO_FN_LCD0_HSYN
, NULL
);
545 gpio_request(GPIO_FN_LCD0_DISP
, NULL
);
546 gpio_request(GPIO_FN_LCD0_LCLK_PORT165
, NULL
);
548 gpio_request(GPIO_PORT61
, NULL
); /* LCDDON */
549 gpio_direction_output(GPIO_PORT61
, 1);
551 gpio_request(GPIO_PORT202
, NULL
); /* LCD0_LED_CONT */
552 gpio_direction_output(GPIO_PORT202
, 0);
555 gpio_request(GPIO_FN_IRQ10
, NULL
); /* TP_INT */
556 gpio_request(GPIO_PORT166
, NULL
); /* TP_RST_B */
557 gpio_direction_output(GPIO_PORT166
, 1);
560 gpio_request(GPIO_FN_ET_CRS
, NULL
);
561 gpio_request(GPIO_FN_ET_MDC
, NULL
);
562 gpio_request(GPIO_FN_ET_MDIO
, NULL
);
563 gpio_request(GPIO_FN_ET_TX_ER
, NULL
);
564 gpio_request(GPIO_FN_ET_RX_ER
, NULL
);
565 gpio_request(GPIO_FN_ET_ERXD0
, NULL
);
566 gpio_request(GPIO_FN_ET_ERXD1
, NULL
);
567 gpio_request(GPIO_FN_ET_ERXD2
, NULL
);
568 gpio_request(GPIO_FN_ET_ERXD3
, NULL
);
569 gpio_request(GPIO_FN_ET_TX_CLK
, NULL
);
570 gpio_request(GPIO_FN_ET_TX_EN
, NULL
);
571 gpio_request(GPIO_FN_ET_ETXD0
, NULL
);
572 gpio_request(GPIO_FN_ET_ETXD1
, NULL
);
573 gpio_request(GPIO_FN_ET_ETXD2
, NULL
);
574 gpio_request(GPIO_FN_ET_ETXD3
, NULL
);
575 gpio_request(GPIO_FN_ET_PHY_INT
, NULL
);
576 gpio_request(GPIO_FN_ET_COL
, NULL
);
577 gpio_request(GPIO_FN_ET_RX_DV
, NULL
);
578 gpio_request(GPIO_FN_ET_RX_CLK
, NULL
);
580 gpio_request(GPIO_PORT18
, NULL
); /* PHY_RST */
581 gpio_direction_output(GPIO_PORT18
, 1);
584 gpio_request(GPIO_PORT159
, NULL
); /* USB_DEVICE_MODE */
585 gpio_direction_input(GPIO_PORT159
);
587 if (gpio_get_value(GPIO_PORT159
)) {
591 gpio_request(GPIO_FN_VBUS
, NULL
);
592 platform_device_register(&usbhsf_device
);
596 gpio_request(GPIO_FN_SDHI0_CMD
, NULL
);
597 gpio_request(GPIO_FN_SDHI0_CLK
, NULL
);
598 gpio_request(GPIO_FN_SDHI0_D0
, NULL
);
599 gpio_request(GPIO_FN_SDHI0_D1
, NULL
);
600 gpio_request(GPIO_FN_SDHI0_D2
, NULL
);
601 gpio_request(GPIO_FN_SDHI0_D3
, NULL
);
602 gpio_request(GPIO_FN_SDHI0_WP
, NULL
);
604 gpio_request(GPIO_PORT17
, NULL
); /* SDHI0_18/33_B */
605 gpio_request(GPIO_PORT74
, NULL
); /* SDHI0_PON */
606 gpio_request(GPIO_PORT75
, NULL
); /* SDSLOT1_PON */
607 gpio_direction_output(GPIO_PORT17
, 0);
608 gpio_direction_output(GPIO_PORT74
, 1);
609 gpio_direction_output(GPIO_PORT75
, 1);
611 /* we can use GPIO_FN_IRQ31_PORT167 here for SDHI0 CD irq */
616 * DBGMD/LCDC0/FSIA MUX
617 * DBGMD_SELECT_B should be set after setting PFC Function.
619 gpio_request(GPIO_PORT176
, NULL
);
620 gpio_direction_output(GPIO_PORT176
, 1);
622 #ifdef CONFIG_CACHE_L2X0
623 /* Early BRESP enable, Shared attribute override enable, 32K*8way */
624 l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
627 i2c_register_board_info(0, i2c0_devices
, ARRAY_SIZE(i2c0_devices
));
629 r8a7740_add_standard_devices();
631 platform_add_devices(eva_devices
,
632 ARRAY_SIZE(eva_devices
));
635 static void __init
eva_earlytimer_init(void)
637 r8a7740_clock_init(MD_CK0
| MD_CK2
);
638 shmobile_earlytimer_init();
641 static void __init
eva_add_early_devices(void)
643 r8a7740_add_early_devices();
645 /* override timer setup with board-specific code */
646 shmobile_timer
.init
= eva_earlytimer_init
;
649 MACHINE_START(ARMADILLO800EVA
, "armadillo800eva")
650 .map_io
= r8a7740_map_io
,
651 .init_early
= eva_add_early_devices
,
652 .init_irq
= r8a7740_init_irq
,
653 .handle_irq
= shmobile_handle_irq_intc
,
654 .init_machine
= eva_init
,
655 .timer
= &shmobile_timer
,