spi-topcliff-pch: supports a spi mode setup and bit order setup by IO control
[zen-stable.git] / arch / arm / mach-shmobile / board-ag5evm.c
blob8aea3a2dd889ef73bb0be3a961497bd3ad8bbc7e
1 /*
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/platform_device.h>
27 #include <linux/delay.h>
28 #include <linux/io.h>
29 #include <linux/dma-mapping.h>
30 #include <linux/serial_sci.h>
31 #include <linux/smsc911x.h>
32 #include <linux/gpio.h>
33 #include <linux/videodev2.h>
34 #include <linux/input.h>
35 #include <linux/input/sh_keysc.h>
36 #include <linux/mmc/host.h>
37 #include <linux/mmc/sh_mmcif.h>
38 #include <linux/mmc/sh_mobile_sdhi.h>
39 #include <linux/mfd/tmio.h>
40 #include <linux/sh_clk.h>
41 #include <linux/videodev2.h>
42 #include <video/sh_mobile_lcdc.h>
43 #include <video/sh_mipi_dsi.h>
44 #include <sound/sh_fsi.h>
45 #include <mach/hardware.h>
46 #include <mach/sh73a0.h>
47 #include <mach/common.h>
48 #include <asm/mach-types.h>
49 #include <asm/mach/arch.h>
50 #include <asm/mach/map.h>
51 #include <asm/mach/time.h>
52 #include <asm/hardware/gic.h>
53 #include <asm/hardware/cache-l2x0.h>
54 #include <asm/traps.h>
56 static struct resource smsc9220_resources[] = {
57 [0] = {
58 .start = 0x14000000,
59 .end = 0x14000000 + SZ_64K - 1,
60 .flags = IORESOURCE_MEM,
62 [1] = {
63 .start = SH73A0_PINT0_IRQ(2), /* PINTA2 */
64 .flags = IORESOURCE_IRQ,
68 static struct smsc911x_platform_config smsc9220_platdata = {
69 .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
70 .phy_interface = PHY_INTERFACE_MODE_MII,
71 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
72 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
75 static struct platform_device eth_device = {
76 .name = "smsc911x",
77 .id = 0,
78 .dev = {
79 .platform_data = &smsc9220_platdata,
81 .resource = smsc9220_resources,
82 .num_resources = ARRAY_SIZE(smsc9220_resources),
85 static struct sh_keysc_info keysc_platdata = {
86 .mode = SH_KEYSC_MODE_6,
87 .scan_timing = 3,
88 .delay = 100,
89 .keycodes = {
90 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
91 KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N,
92 KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U,
93 KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP,
94 KEY_SPACE, KEY_9, KEY_6, KEY_3, KEY_WAKEUP, KEY_RIGHT, \
95 KEY_COFFEE,
96 KEY_0, KEY_8, KEY_5, KEY_2, KEY_DOWN, KEY_ENTER, KEY_UP,
97 KEY_KPASTERISK, KEY_7, KEY_4, KEY_1, KEY_STOP, KEY_LEFT, \
98 KEY_COMPUTER,
102 static struct resource keysc_resources[] = {
103 [0] = {
104 .name = "KEYSC",
105 .start = 0xe61b0000,
106 .end = 0xe61b0098 - 1,
107 .flags = IORESOURCE_MEM,
109 [1] = {
110 .start = gic_spi(71),
111 .flags = IORESOURCE_IRQ,
115 static struct platform_device keysc_device = {
116 .name = "sh_keysc",
117 .id = 0,
118 .num_resources = ARRAY_SIZE(keysc_resources),
119 .resource = keysc_resources,
120 .dev = {
121 .platform_data = &keysc_platdata,
125 /* FSI A */
126 static struct resource fsi_resources[] = {
127 [0] = {
128 .name = "FSI",
129 .start = 0xEC230000,
130 .end = 0xEC230400 - 1,
131 .flags = IORESOURCE_MEM,
133 [1] = {
134 .start = gic_spi(146),
135 .flags = IORESOURCE_IRQ,
139 static struct platform_device fsi_device = {
140 .name = "sh_fsi2",
141 .id = -1,
142 .num_resources = ARRAY_SIZE(fsi_resources),
143 .resource = fsi_resources,
146 static struct resource sh_mmcif_resources[] = {
147 [0] = {
148 .name = "MMCIF",
149 .start = 0xe6bd0000,
150 .end = 0xe6bd00ff,
151 .flags = IORESOURCE_MEM,
153 [1] = {
154 .start = gic_spi(141),
155 .flags = IORESOURCE_IRQ,
157 [2] = {
158 .start = gic_spi(140),
159 .flags = IORESOURCE_IRQ,
163 static struct sh_mmcif_plat_data sh_mmcif_platdata = {
164 .sup_pclk = 0,
165 .ocr = MMC_VDD_165_195,
166 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
167 .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
168 .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
171 static struct platform_device mmc_device = {
172 .name = "sh_mmcif",
173 .id = 0,
174 .dev = {
175 .dma_mask = NULL,
176 .coherent_dma_mask = 0xffffffff,
177 .platform_data = &sh_mmcif_platdata,
179 .num_resources = ARRAY_SIZE(sh_mmcif_resources),
180 .resource = sh_mmcif_resources,
183 /* IrDA */
184 static struct resource irda_resources[] = {
185 [0] = {
186 .start = 0xE6D00000,
187 .end = 0xE6D01FD4 - 1,
188 .flags = IORESOURCE_MEM,
190 [1] = {
191 .start = gic_spi(95),
192 .flags = IORESOURCE_IRQ,
196 static struct platform_device irda_device = {
197 .name = "sh_irda",
198 .id = 0,
199 .resource = irda_resources,
200 .num_resources = ARRAY_SIZE(irda_resources),
203 static unsigned char lcd_backlight_seq[3][2] = {
204 { 0x04, 0x07 },
205 { 0x23, 0x80 },
206 { 0x03, 0x01 },
209 static void lcd_backlight_on(void)
211 struct i2c_adapter *a;
212 struct i2c_msg msg;
213 int k;
215 a = i2c_get_adapter(1);
216 for (k = 0; a && k < 3; k++) {
217 msg.addr = 0x6d;
218 msg.buf = &lcd_backlight_seq[k][0];
219 msg.len = 2;
220 msg.flags = 0;
221 if (i2c_transfer(a, &msg, 1) != 1)
222 break;
226 static void lcd_backlight_reset(void)
228 gpio_set_value(GPIO_PORT235, 0);
229 mdelay(24);
230 gpio_set_value(GPIO_PORT235, 1);
233 static void lcd_on(void *board_data, struct fb_info *info)
235 lcd_backlight_on();
238 static void lcd_off(void *board_data)
240 lcd_backlight_reset();
243 /* LCDC0 */
244 static const struct fb_videomode lcdc0_modes[] = {
246 .name = "R63302(QHD)",
247 .xres = 544,
248 .yres = 961,
249 .left_margin = 72,
250 .right_margin = 600,
251 .hsync_len = 16,
252 .upper_margin = 8,
253 .lower_margin = 8,
254 .vsync_len = 2,
255 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
259 static struct sh_mobile_lcdc_info lcdc0_info = {
260 .clock_source = LCDC_CLK_PERIPHERAL,
261 .ch[0] = {
262 .chan = LCDC_CHAN_MAINLCD,
263 .interface_type = RGB24,
264 .clock_divider = 1,
265 .flags = LCDC_FLAGS_DWPOL,
266 .lcd_size_cfg.width = 44,
267 .lcd_size_cfg.height = 79,
268 .fourcc = V4L2_PIX_FMT_RGB565,
269 .lcd_cfg = lcdc0_modes,
270 .num_cfg = ARRAY_SIZE(lcdc0_modes),
271 .board_cfg = {
272 .display_on = lcd_on,
273 .display_off = lcd_off,
278 static struct resource lcdc0_resources[] = {
279 [0] = {
280 .name = "LCDC0",
281 .start = 0xfe940000, /* P4-only space */
282 .end = 0xfe943fff,
283 .flags = IORESOURCE_MEM,
285 [1] = {
286 .start = intcs_evt2irq(0x580),
287 .flags = IORESOURCE_IRQ,
291 static struct platform_device lcdc0_device = {
292 .name = "sh_mobile_lcdc_fb",
293 .num_resources = ARRAY_SIZE(lcdc0_resources),
294 .resource = lcdc0_resources,
295 .id = 0,
296 .dev = {
297 .platform_data = &lcdc0_info,
298 .coherent_dma_mask = ~0,
302 /* MIPI-DSI */
303 static struct resource mipidsi0_resources[] = {
304 [0] = {
305 .name = "DSI0",
306 .start = 0xfeab0000,
307 .end = 0xfeab3fff,
308 .flags = IORESOURCE_MEM,
310 [1] = {
311 .name = "DSI0",
312 .start = 0xfeab4000,
313 .end = 0xfeab7fff,
314 .flags = IORESOURCE_MEM,
318 static int sh_mipi_set_dot_clock(struct platform_device *pdev,
319 void __iomem *base,
320 int enable)
322 struct clk *pck, *phy;
323 int ret;
325 pck = clk_get(&pdev->dev, "dsip_clk");
326 if (IS_ERR(pck)) {
327 ret = PTR_ERR(pck);
328 goto sh_mipi_set_dot_clock_pck_err;
331 phy = clk_get(&pdev->dev, "dsiphy_clk");
332 if (IS_ERR(phy)) {
333 ret = PTR_ERR(phy);
334 goto sh_mipi_set_dot_clock_phy_err;
337 if (enable) {
338 clk_set_rate(pck, clk_round_rate(pck, 24000000));
339 clk_set_rate(phy, clk_round_rate(pck, 510000000));
340 clk_enable(pck);
341 clk_enable(phy);
342 } else {
343 clk_disable(pck);
344 clk_disable(phy);
347 ret = 0;
349 clk_put(phy);
350 sh_mipi_set_dot_clock_phy_err:
351 clk_put(pck);
352 sh_mipi_set_dot_clock_pck_err:
353 return ret;
356 static struct sh_mipi_dsi_info mipidsi0_info = {
357 .data_format = MIPI_RGB888,
358 .lcd_chan = &lcdc0_info.ch[0],
359 .lane = 2,
360 .vsynw_offset = 20,
361 .clksrc = 1,
362 .flags = SH_MIPI_DSI_HSABM |
363 SH_MIPI_DSI_SYNC_PULSES_MODE |
364 SH_MIPI_DSI_HSbyteCLK,
365 .set_dot_clock = sh_mipi_set_dot_clock,
368 static struct platform_device mipidsi0_device = {
369 .name = "sh-mipi-dsi",
370 .num_resources = ARRAY_SIZE(mipidsi0_resources),
371 .resource = mipidsi0_resources,
372 .id = 0,
373 .dev = {
374 .platform_data = &mipidsi0_info,
378 /* SDHI0 */
379 static irqreturn_t ag5evm_sdhi0_gpio_cd(int irq, void *arg)
381 struct device *dev = arg;
382 struct sh_mobile_sdhi_info *info = dev->platform_data;
383 struct tmio_mmc_data *pdata = info->pdata;
385 tmio_mmc_cd_wakeup(pdata);
387 return IRQ_HANDLED;
390 static struct sh_mobile_sdhi_info sdhi0_info = {
391 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
392 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
393 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
394 .tmio_caps = MMC_CAP_SD_HIGHSPEED,
395 .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29,
398 static struct resource sdhi0_resources[] = {
399 [0] = {
400 .name = "SDHI0",
401 .start = 0xee100000,
402 .end = 0xee1000ff,
403 .flags = IORESOURCE_MEM,
405 [1] = {
406 .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
407 .start = gic_spi(83),
408 .flags = IORESOURCE_IRQ,
410 [2] = {
411 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
412 .start = gic_spi(84),
413 .flags = IORESOURCE_IRQ,
415 [3] = {
416 .name = SH_MOBILE_SDHI_IRQ_SDIO,
417 .start = gic_spi(85),
418 .flags = IORESOURCE_IRQ,
422 static struct platform_device sdhi0_device = {
423 .name = "sh_mobile_sdhi",
424 .id = 0,
425 .num_resources = ARRAY_SIZE(sdhi0_resources),
426 .resource = sdhi0_resources,
427 .dev = {
428 .platform_data = &sdhi0_info,
432 void ag5evm_sdhi1_set_pwr(struct platform_device *pdev, int state)
434 gpio_set_value(GPIO_PORT114, state);
437 static struct sh_mobile_sdhi_info sh_sdhi1_info = {
438 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_HAS_IDLE_WAIT,
439 .tmio_caps = MMC_CAP_NONREMOVABLE | MMC_CAP_SDIO_IRQ,
440 .tmio_ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
441 .set_pwr = ag5evm_sdhi1_set_pwr,
444 static struct resource sdhi1_resources[] = {
445 [0] = {
446 .name = "SDHI1",
447 .start = 0xee120000,
448 .end = 0xee1200ff,
449 .flags = IORESOURCE_MEM,
451 [1] = {
452 .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
453 .start = gic_spi(87),
454 .flags = IORESOURCE_IRQ,
456 [2] = {
457 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
458 .start = gic_spi(88),
459 .flags = IORESOURCE_IRQ,
461 [3] = {
462 .name = SH_MOBILE_SDHI_IRQ_SDIO,
463 .start = gic_spi(89),
464 .flags = IORESOURCE_IRQ,
468 static struct platform_device sdhi1_device = {
469 .name = "sh_mobile_sdhi",
470 .id = 1,
471 .dev = {
472 .platform_data = &sh_sdhi1_info,
474 .num_resources = ARRAY_SIZE(sdhi1_resources),
475 .resource = sdhi1_resources,
478 static struct platform_device *ag5evm_devices[] __initdata = {
479 &eth_device,
480 &keysc_device,
481 &fsi_device,
482 &mmc_device,
483 &irda_device,
484 &lcdc0_device,
485 &mipidsi0_device,
486 &sdhi0_device,
487 &sdhi1_device,
490 static struct map_desc ag5evm_io_desc[] __initdata = {
491 /* create a 1:1 entity map for 0xe6xxxxxx
492 * used by CPGA, INTC and PFC.
495 .virtual = 0xe6000000,
496 .pfn = __phys_to_pfn(0xe6000000),
497 .length = 256 << 20,
498 .type = MT_DEVICE_NONSHARED
502 static void __init ag5evm_map_io(void)
504 iotable_init(ag5evm_io_desc, ARRAY_SIZE(ag5evm_io_desc));
506 /* setup early devices and console here as well */
507 sh73a0_add_early_devices();
508 shmobile_setup_console();
511 static void __init ag5evm_init(void)
513 sh73a0_pinmux_init();
515 /* enable SCIFA2 */
516 gpio_request(GPIO_FN_SCIFA2_TXD1, NULL);
517 gpio_request(GPIO_FN_SCIFA2_RXD1, NULL);
518 gpio_request(GPIO_FN_SCIFA2_RTS1_, NULL);
519 gpio_request(GPIO_FN_SCIFA2_CTS1_, NULL);
521 /* enable KEYSC */
522 gpio_request(GPIO_FN_KEYIN0_PU, NULL);
523 gpio_request(GPIO_FN_KEYIN1_PU, NULL);
524 gpio_request(GPIO_FN_KEYIN2_PU, NULL);
525 gpio_request(GPIO_FN_KEYIN3_PU, NULL);
526 gpio_request(GPIO_FN_KEYIN4_PU, NULL);
527 gpio_request(GPIO_FN_KEYIN5_PU, NULL);
528 gpio_request(GPIO_FN_KEYIN6_PU, NULL);
529 gpio_request(GPIO_FN_KEYIN7_PU, NULL);
530 gpio_request(GPIO_FN_KEYOUT0, NULL);
531 gpio_request(GPIO_FN_KEYOUT1, NULL);
532 gpio_request(GPIO_FN_KEYOUT2, NULL);
533 gpio_request(GPIO_FN_KEYOUT3, NULL);
534 gpio_request(GPIO_FN_KEYOUT4, NULL);
535 gpio_request(GPIO_FN_KEYOUT5, NULL);
536 gpio_request(GPIO_FN_PORT59_KEYOUT6, NULL);
537 gpio_request(GPIO_FN_PORT58_KEYOUT7, NULL);
538 gpio_request(GPIO_FN_KEYOUT8, NULL);
539 gpio_request(GPIO_FN_PORT149_KEYOUT9, NULL);
541 /* enable I2C channel 2 and 3 */
542 gpio_request(GPIO_FN_PORT236_I2C_SDA2, NULL);
543 gpio_request(GPIO_FN_PORT237_I2C_SCL2, NULL);
544 gpio_request(GPIO_FN_PORT248_I2C_SCL3, NULL);
545 gpio_request(GPIO_FN_PORT249_I2C_SDA3, NULL);
547 /* enable MMCIF */
548 gpio_request(GPIO_FN_MMCCLK0, NULL);
549 gpio_request(GPIO_FN_MMCCMD0_PU, NULL);
550 gpio_request(GPIO_FN_MMCD0_0_PU, NULL);
551 gpio_request(GPIO_FN_MMCD0_1_PU, NULL);
552 gpio_request(GPIO_FN_MMCD0_2_PU, NULL);
553 gpio_request(GPIO_FN_MMCD0_3_PU, NULL);
554 gpio_request(GPIO_FN_MMCD0_4_PU, NULL);
555 gpio_request(GPIO_FN_MMCD0_5_PU, NULL);
556 gpio_request(GPIO_FN_MMCD0_6_PU, NULL);
557 gpio_request(GPIO_FN_MMCD0_7_PU, NULL);
558 gpio_request(GPIO_PORT208, NULL); /* Reset */
559 gpio_direction_output(GPIO_PORT208, 1);
561 /* enable SMSC911X */
562 gpio_request(GPIO_PORT144, NULL); /* PINTA2 */
563 gpio_direction_input(GPIO_PORT144);
564 gpio_request(GPIO_PORT145, NULL); /* RESET */
565 gpio_direction_output(GPIO_PORT145, 1);
567 /* FSI A */
568 gpio_request(GPIO_FN_FSIACK, NULL);
569 gpio_request(GPIO_FN_FSIAILR, NULL);
570 gpio_request(GPIO_FN_FSIAIBT, NULL);
571 gpio_request(GPIO_FN_FSIAISLD, NULL);
572 gpio_request(GPIO_FN_FSIAOSLD, NULL);
574 /* IrDA */
575 gpio_request(GPIO_FN_PORT241_IRDA_OUT, NULL);
576 gpio_request(GPIO_FN_PORT242_IRDA_IN, NULL);
577 gpio_request(GPIO_FN_PORT243_IRDA_FIRSEL, NULL);
579 /* LCD panel */
580 gpio_request(GPIO_PORT217, NULL); /* RESET */
581 gpio_direction_output(GPIO_PORT217, 0);
582 mdelay(1);
583 gpio_set_value(GPIO_PORT217, 1);
584 mdelay(100);
586 /* LCD backlight controller */
587 gpio_request(GPIO_PORT235, NULL); /* RESET */
588 gpio_direction_output(GPIO_PORT235, 0);
589 lcd_backlight_reset();
591 /* enable SDHI0 on CN15 [SD I/F] */
592 gpio_request(GPIO_FN_SDHICD0, NULL);
593 gpio_request(GPIO_FN_SDHIWP0, NULL);
594 gpio_request(GPIO_FN_SDHICMD0, NULL);
595 gpio_request(GPIO_FN_SDHICLK0, NULL);
596 gpio_request(GPIO_FN_SDHID0_3, NULL);
597 gpio_request(GPIO_FN_SDHID0_2, NULL);
598 gpio_request(GPIO_FN_SDHID0_1, NULL);
599 gpio_request(GPIO_FN_SDHID0_0, NULL);
601 if (!request_irq(intcs_evt2irq(0x3c0), ag5evm_sdhi0_gpio_cd,
602 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
603 "sdhi0 cd", &sdhi0_device.dev))
604 sdhi0_info.tmio_flags |= TMIO_MMC_HAS_COLD_CD;
605 else
606 pr_warn("Unable to setup SDHI0 GPIO IRQ\n");
608 /* enable SDHI1 on CN4 [WLAN I/F] */
609 gpio_request(GPIO_FN_SDHICLK1, NULL);
610 gpio_request(GPIO_FN_SDHICMD1_PU, NULL);
611 gpio_request(GPIO_FN_SDHID1_3_PU, NULL);
612 gpio_request(GPIO_FN_SDHID1_2_PU, NULL);
613 gpio_request(GPIO_FN_SDHID1_1_PU, NULL);
614 gpio_request(GPIO_FN_SDHID1_0_PU, NULL);
615 gpio_request(GPIO_PORT114, "sdhi1_power");
616 gpio_direction_output(GPIO_PORT114, 0);
618 #ifdef CONFIG_CACHE_L2X0
619 /* Shared attribute override enable, 64K*8way */
620 l2x0_init(__io(0xf0100000), 0x00460000, 0xc2000fff);
621 #endif
622 sh73a0_add_standard_devices();
623 platform_add_devices(ag5evm_devices, ARRAY_SIZE(ag5evm_devices));
626 static void __init ag5evm_timer_init(void)
628 sh73a0_clock_init();
629 shmobile_timer.init();
630 return;
633 struct sys_timer ag5evm_timer = {
634 .init = ag5evm_timer_init,
637 MACHINE_START(AG5EVM, "ag5evm")
638 .map_io = ag5evm_map_io,
639 .nr_irqs = NR_IRQS_LEGACY,
640 .init_irq = sh73a0_init_irq,
641 .handle_irq = gic_handle_irq,
642 .init_machine = ag5evm_init,
643 .timer = &ag5evm_timer,
644 MACHINE_END