2 * arch/arm/mach-shmobile/board-ag5evm.c
4 * Copyright (C) 2010 Takashi Yoshii <yoshii.takashi.zj@renesas.com>
5 * Copyright (C) 2009 Yoshihiro Shimoda <shimoda.yoshihiro@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/kernel.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/irq.h>
26 #include <linux/pinctrl/machine.h>
27 #include <linux/pinctrl/pinconf-generic.h>
28 #include <linux/platform_device.h>
29 #include <linux/delay.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/regulator/fixed.h>
33 #include <linux/regulator/machine.h>
34 #include <linux/serial_sci.h>
35 #include <linux/smsc911x.h>
36 #include <linux/gpio.h>
37 #include <linux/videodev2.h>
38 #include <linux/input.h>
39 #include <linux/input/sh_keysc.h>
40 #include <linux/mmc/host.h>
41 #include <linux/mmc/sh_mmcif.h>
42 #include <linux/mmc/sh_mobile_sdhi.h>
43 #include <linux/mfd/tmio.h>
44 #include <linux/sh_clk.h>
45 #include <linux/irqchip/arm-gic.h>
46 #include <video/sh_mobile_lcdc.h>
47 #include <video/sh_mipi_dsi.h>
48 #include <sound/sh_fsi.h>
49 #include <mach/hardware.h>
50 #include <mach/irqs.h>
51 #include <mach/sh73a0.h>
52 #include <mach/common.h>
53 #include <asm/mach-types.h>
54 #include <asm/mach/arch.h>
55 #include <asm/hardware/cache-l2x0.h>
56 #include <asm/traps.h>
58 /* Dummy supplies, where voltage doesn't matter */
59 static struct regulator_consumer_supply dummy_supplies[] = {
60 REGULATOR_SUPPLY("vddvario", "smsc911x"),
61 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
64 static struct resource smsc9220_resources[] = {
67 .end = 0x14000000 + SZ_64K - 1,
68 .flags = IORESOURCE_MEM,
71 .start = SH73A0_PINT0_IRQ(2), /* PINTA2 */
72 .flags = IORESOURCE_IRQ,
76 static struct smsc911x_platform_config smsc9220_platdata = {
77 .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
78 .phy_interface = PHY_INTERFACE_MODE_MII,
79 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
80 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
83 static struct platform_device eth_device = {
87 .platform_data = &smsc9220_platdata,
89 .resource = smsc9220_resources,
90 .num_resources = ARRAY_SIZE(smsc9220_resources),
93 static struct sh_keysc_info keysc_platdata = {
94 .mode = SH_KEYSC_MODE_6,
98 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
99 KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N,
100 KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U,
101 KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP,
102 KEY_SPACE, KEY_9, KEY_6, KEY_3, KEY_WAKEUP, KEY_RIGHT, \
104 KEY_0, KEY_8, KEY_5, KEY_2, KEY_DOWN, KEY_ENTER, KEY_UP,
105 KEY_KPASTERISK, KEY_7, KEY_4, KEY_1, KEY_STOP, KEY_LEFT, \
110 static struct resource keysc_resources[] = {
114 .end = 0xe61b0098 - 1,
115 .flags = IORESOURCE_MEM,
118 .start = gic_spi(71),
119 .flags = IORESOURCE_IRQ,
123 static struct platform_device keysc_device = {
126 .num_resources = ARRAY_SIZE(keysc_resources),
127 .resource = keysc_resources,
129 .platform_data = &keysc_platdata,
134 static struct resource fsi_resources[] = {
138 .end = 0xEC230400 - 1,
139 .flags = IORESOURCE_MEM,
142 .start = gic_spi(146),
143 .flags = IORESOURCE_IRQ,
147 static struct platform_device fsi_device = {
150 .num_resources = ARRAY_SIZE(fsi_resources),
151 .resource = fsi_resources,
154 /* Fixed 1.8V regulator to be used by MMCIF */
155 static struct regulator_consumer_supply fixed1v8_power_consumers[] =
157 REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
158 REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
161 static struct resource sh_mmcif_resources[] = {
166 .flags = IORESOURCE_MEM,
169 .start = gic_spi(141),
170 .flags = IORESOURCE_IRQ,
173 .start = gic_spi(140),
174 .flags = IORESOURCE_IRQ,
178 static struct sh_mmcif_plat_data sh_mmcif_platdata = {
180 .ocr = MMC_VDD_165_195,
181 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
182 .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
183 .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
186 static struct platform_device mmc_device = {
191 .coherent_dma_mask = 0xffffffff,
192 .platform_data = &sh_mmcif_platdata,
194 .num_resources = ARRAY_SIZE(sh_mmcif_resources),
195 .resource = sh_mmcif_resources,
199 static struct resource irda_resources[] = {
202 .end = 0xE6D01FD4 - 1,
203 .flags = IORESOURCE_MEM,
206 .start = gic_spi(95),
207 .flags = IORESOURCE_IRQ,
211 static struct platform_device irda_device = {
214 .resource = irda_resources,
215 .num_resources = ARRAY_SIZE(irda_resources),
219 static struct resource mipidsi0_resources[] = {
224 .flags = IORESOURCE_MEM,
230 .flags = IORESOURCE_MEM,
234 static int sh_mipi_set_dot_clock(struct platform_device *pdev,
238 struct clk *pck, *phy;
241 pck = clk_get(&pdev->dev, "dsip_clk");
244 goto sh_mipi_set_dot_clock_pck_err;
247 phy = clk_get(&pdev->dev, "dsiphy_clk");
250 goto sh_mipi_set_dot_clock_phy_err;
254 clk_set_rate(pck, clk_round_rate(pck, 24000000));
255 clk_set_rate(phy, clk_round_rate(pck, 510000000));
266 sh_mipi_set_dot_clock_phy_err:
268 sh_mipi_set_dot_clock_pck_err:
272 static struct sh_mipi_dsi_info mipidsi0_info = {
273 .data_format = MIPI_RGB888,
274 .channel = LCDC_CHAN_MAINLCD,
278 .flags = SH_MIPI_DSI_HSABM |
279 SH_MIPI_DSI_SYNC_PULSES_MODE |
280 SH_MIPI_DSI_HSbyteCLK,
281 .set_dot_clock = sh_mipi_set_dot_clock,
284 static struct platform_device mipidsi0_device = {
285 .name = "sh-mipi-dsi",
286 .num_resources = ARRAY_SIZE(mipidsi0_resources),
287 .resource = mipidsi0_resources,
290 .platform_data = &mipidsi0_info,
294 static unsigned char lcd_backlight_seq[3][2] = {
300 static int lcd_backlight_set_brightness(int brightness)
302 struct i2c_adapter *adap;
307 if (brightness == 0) {
309 gpio_set_value(235, 0);
311 gpio_set_value(235, 1);
315 adap = i2c_get_adapter(1);
319 for (i = 0; i < ARRAY_SIZE(lcd_backlight_seq); i++) {
321 msg.buf = &lcd_backlight_seq[i][0];
325 ret = i2c_transfer(adap, &msg, 1);
330 i2c_put_adapter(adap);
331 return ret < 0 ? ret : 0;
335 static const struct fb_videomode lcdc0_modes[] = {
337 .name = "R63302(QHD)",
346 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
350 static struct sh_mobile_lcdc_info lcdc0_info = {
351 .clock_source = LCDC_CLK_PERIPHERAL,
353 .chan = LCDC_CHAN_MAINLCD,
354 .interface_type = RGB24,
356 .flags = LCDC_FLAGS_DWPOL,
357 .fourcc = V4L2_PIX_FMT_RGB565,
358 .lcd_modes = lcdc0_modes,
359 .num_modes = ARRAY_SIZE(lcdc0_modes),
365 .name = "sh_mobile_lcdc_bl",
367 .set_brightness = lcd_backlight_set_brightness,
369 .tx_dev = &mipidsi0_device,
373 static struct resource lcdc0_resources[] = {
376 .start = 0xfe940000, /* P4-only space */
378 .flags = IORESOURCE_MEM,
381 .start = intcs_evt2irq(0x580),
382 .flags = IORESOURCE_IRQ,
386 static struct platform_device lcdc0_device = {
387 .name = "sh_mobile_lcdc_fb",
388 .num_resources = ARRAY_SIZE(lcdc0_resources),
389 .resource = lcdc0_resources,
392 .platform_data = &lcdc0_info,
393 .coherent_dma_mask = ~0,
397 /* Fixed 2.8V regulators to be used by SDHI0 */
398 static struct regulator_consumer_supply fixed2v8_power_consumers[] =
400 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
401 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
405 static struct sh_mobile_sdhi_info sdhi0_info = {
406 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
407 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
408 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_USE_GPIO_CD,
409 .tmio_caps = MMC_CAP_SD_HIGHSPEED,
410 .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29,
414 static struct resource sdhi0_resources[] = {
419 .flags = IORESOURCE_MEM,
422 .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
423 .start = gic_spi(83),
424 .flags = IORESOURCE_IRQ,
427 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
428 .start = gic_spi(84),
429 .flags = IORESOURCE_IRQ,
432 .name = SH_MOBILE_SDHI_IRQ_SDIO,
433 .start = gic_spi(85),
434 .flags = IORESOURCE_IRQ,
438 static struct platform_device sdhi0_device = {
439 .name = "sh_mobile_sdhi",
441 .num_resources = ARRAY_SIZE(sdhi0_resources),
442 .resource = sdhi0_resources,
444 .platform_data = &sdhi0_info,
448 /* Fixed 3.3V regulator to be used by SDHI1 */
449 static struct regulator_consumer_supply cn4_power_consumers[] =
451 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
452 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
455 static struct regulator_init_data cn4_power_init_data = {
457 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
459 .num_consumer_supplies = ARRAY_SIZE(cn4_power_consumers),
460 .consumer_supplies = cn4_power_consumers,
463 static struct fixed_voltage_config cn4_power_info = {
464 .supply_name = "CN4 SD/MMC Vdd",
465 .microvolts = 3300000,
468 .init_data = &cn4_power_init_data,
471 static struct platform_device cn4_power = {
472 .name = "reg-fixed-voltage",
475 .platform_data = &cn4_power_info,
479 static void ag5evm_sdhi1_set_pwr(struct platform_device *pdev, int state)
481 static int power_gpio = -EINVAL;
483 if (power_gpio < 0) {
484 int ret = gpio_request_one(114, GPIOF_OUT_INIT_LOW,
491 * If requesting the GPIO above failed, it means, that the regulator got
492 * probed and grabbed the GPIO, but we don't know, whether the sdhi
493 * driver already uses the regulator. If it doesn't, we have to toggle
494 * the GPIO ourselves, even though it is now owned by the fixed
495 * regulator driver. We have to live with the race in case the driver
496 * gets unloaded and the GPIO freed between these two steps.
498 gpio_set_value(114, state);
501 static struct sh_mobile_sdhi_info sh_sdhi1_info = {
502 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_HAS_IDLE_WAIT,
503 .tmio_caps = MMC_CAP_NONREMOVABLE | MMC_CAP_SDIO_IRQ,
504 .tmio_ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
505 .set_pwr = ag5evm_sdhi1_set_pwr,
508 static struct resource sdhi1_resources[] = {
513 .flags = IORESOURCE_MEM,
516 .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
517 .start = gic_spi(87),
518 .flags = IORESOURCE_IRQ,
521 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
522 .start = gic_spi(88),
523 .flags = IORESOURCE_IRQ,
526 .name = SH_MOBILE_SDHI_IRQ_SDIO,
527 .start = gic_spi(89),
528 .flags = IORESOURCE_IRQ,
532 static struct platform_device sdhi1_device = {
533 .name = "sh_mobile_sdhi",
536 .platform_data = &sh_sdhi1_info,
538 .num_resources = ARRAY_SIZE(sdhi1_resources),
539 .resource = sdhi1_resources,
542 static struct platform_device *ag5evm_devices[] __initdata = {
555 static unsigned long pin_pullup_conf[] = {
556 PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_UP, 0),
559 static const struct pinctrl_map ag5evm_pinctrl_map[] = {
561 PIN_MAP_MUX_GROUP_DEFAULT("sh_fsi2.0", "pfc-sh73a0",
562 "fsia_mclk_in", "fsia"),
563 PIN_MAP_MUX_GROUP_DEFAULT("sh_fsi2.0", "pfc-sh73a0",
564 "fsia_sclk_in", "fsia"),
565 PIN_MAP_MUX_GROUP_DEFAULT("sh_fsi2.0", "pfc-sh73a0",
566 "fsia_data_in", "fsia"),
567 PIN_MAP_MUX_GROUP_DEFAULT("sh_fsi2.0", "pfc-sh73a0",
568 "fsia_data_out", "fsia"),
570 PIN_MAP_MUX_GROUP_DEFAULT("i2c-sh_mobile.2", "pfc-sh73a0",
572 PIN_MAP_MUX_GROUP_DEFAULT("i2c-sh_mobile.3", "pfc-sh73a0",
575 PIN_MAP_MUX_GROUP_DEFAULT("sh_keysc.0", "pfc-sh73a0",
576 "keysc_in8", "keysc"),
577 PIN_MAP_MUX_GROUP_DEFAULT("sh_keysc.0", "pfc-sh73a0",
578 "keysc_out04", "keysc"),
579 PIN_MAP_MUX_GROUP_DEFAULT("sh_keysc.0", "pfc-sh73a0",
580 "keysc_out5", "keysc"),
581 PIN_MAP_MUX_GROUP_DEFAULT("sh_keysc.0", "pfc-sh73a0",
582 "keysc_out6_0", "keysc"),
583 PIN_MAP_MUX_GROUP_DEFAULT("sh_keysc.0", "pfc-sh73a0",
584 "keysc_out7_0", "keysc"),
585 PIN_MAP_MUX_GROUP_DEFAULT("sh_keysc.0", "pfc-sh73a0",
586 "keysc_out8_0", "keysc"),
587 PIN_MAP_MUX_GROUP_DEFAULT("sh_keysc.0", "pfc-sh73a0",
588 "keysc_out9_2", "keysc"),
589 PIN_MAP_CONFIGS_GROUP_DEFAULT("sh_keysc.0", "pfc-sh73a0",
590 "keysc_in8", pin_pullup_conf),
592 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh73a0",
593 "mmc0_data8_0", "mmc0"),
594 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh73a0",
595 "mmc0_ctrl_0", "mmc0"),
596 PIN_MAP_CONFIGS_PIN_DEFAULT("sh_mmcif.0", "pfc-sh73a0",
597 "PORT279", pin_pullup_conf),
598 PIN_MAP_CONFIGS_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh73a0",
599 "mmc0_data8_0", pin_pullup_conf),
601 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-sh73a0",
602 "scifa2_data_0", "scifa2"),
603 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-sh73a0",
604 "scifa2_ctrl_0", "scifa2"),
605 /* SDHI0 (CN15 [SD I/F]) */
606 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh73a0",
607 "sdhi0_data4", "sdhi0"),
608 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh73a0",
609 "sdhi0_ctrl", "sdhi0"),
610 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh73a0",
611 "sdhi0_wp", "sdhi0"),
612 /* SDHI1 (CN4 [WLAN I/F]) */
613 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh73a0",
614 "sdhi1_data4", "sdhi1"),
615 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh73a0",
616 "sdhi1_ctrl", "sdhi1"),
617 PIN_MAP_CONFIGS_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh73a0",
618 "sdhi1_data4", pin_pullup_conf),
619 PIN_MAP_CONFIGS_PIN_DEFAULT("sh_mobile_sdhi.1", "pfc-sh73a0",
620 "PORT263", pin_pullup_conf),
623 static void __init ag5evm_init(void)
625 regulator_register_always_on(0, "fixed-1.8V", fixed1v8_power_consumers,
626 ARRAY_SIZE(fixed1v8_power_consumers), 1800000);
627 regulator_register_always_on(1, "fixed-2.8V", fixed2v8_power_consumers,
628 ARRAY_SIZE(fixed2v8_power_consumers), 3300000);
629 regulator_register_fixed(3, dummy_supplies, ARRAY_SIZE(dummy_supplies));
631 pinctrl_register_mappings(ag5evm_pinctrl_map,
632 ARRAY_SIZE(ag5evm_pinctrl_map));
633 sh73a0_pinmux_init();
636 gpio_request_one(208, GPIOF_OUT_INIT_HIGH, NULL); /* Reset */
638 /* enable SMSC911X */
639 gpio_request_one(144, GPIOF_IN, NULL); /* PINTA2 */
640 gpio_request_one(145, GPIOF_OUT_INIT_HIGH, NULL); /* RESET */
643 gpio_request(GPIO_FN_PORT241_IRDA_OUT, NULL);
644 gpio_request(GPIO_FN_PORT242_IRDA_IN, NULL);
645 gpio_request(GPIO_FN_PORT243_IRDA_FIRSEL, NULL);
648 gpio_request_one(217, GPIOF_OUT_INIT_LOW, NULL); /* RESET */
650 gpio_set_value(217, 1);
653 /* LCD backlight controller */
654 gpio_request_one(235, GPIOF_OUT_INIT_LOW, NULL); /* RESET */
655 lcd_backlight_set_brightness(0);
657 #ifdef CONFIG_CACHE_L2X0
658 /* Shared attribute override enable, 64K*8way */
659 l2x0_init(IOMEM(0xf0100000), 0x00460000, 0xc2000fff);
661 sh73a0_add_standard_devices();
662 platform_add_devices(ag5evm_devices, ARRAY_SIZE(ag5evm_devices));
665 MACHINE_START(AG5EVM, "ag5evm")
666 .smp = smp_ops(sh73a0_smp_ops),
667 .map_io = sh73a0_map_io,
668 .init_early = sh73a0_add_early_devices,
669 .nr_irqs = NR_IRQS_LEGACY,
670 .init_irq = sh73a0_init_irq,
671 .init_machine = ag5evm_init,
672 .init_late = shmobile_init_late,
673 .init_time = sh73a0_earlytimer_init,