ARM: mach-shmobile: ap4evb: Add ts_get_pendown_state for tsc2007
[pandora-kernel.git] / arch / arm / mach-shmobile / board-ap4evb.c
1 /*
2  * AP4EVB board support
3  *
4  * Copyright (C) 2010  Magnus Damm
5  * Copyright (C) 2008  Yoshihiro Shimoda
6  *
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.
10  *
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.
15  *
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
19  */
20 #include <linux/clk.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/irq.h>
25 #include <linux/platform_device.h>
26 #include <linux/delay.h>
27 #include <linux/mfd/sh_mobile_sdhi.h>
28 #include <linux/mmc/host.h>
29 #include <linux/mtd/mtd.h>
30 #include <linux/mtd/partitions.h>
31 #include <linux/mtd/physmap.h>
32 #include <linux/mmc/host.h>
33 #include <linux/mmc/sh_mmcif.h>
34 #include <linux/i2c.h>
35 #include <linux/i2c/tsc2007.h>
36 #include <linux/io.h>
37 #include <linux/smsc911x.h>
38 #include <linux/sh_intc.h>
39 #include <linux/sh_clk.h>
40 #include <linux/gpio.h>
41 #include <linux/input.h>
42 #include <linux/input/sh_keysc.h>
43 #include <linux/usb/r8a66597.h>
44
45 #include <sound/sh_fsi.h>
46
47 #include <video/sh_mobile_lcdc.h>
48 #include <video/sh_mipi_dsi.h>
49
50 #include <mach/common.h>
51 #include <mach/irqs.h>
52 #include <mach/sh7372.h>
53
54 #include <asm/mach-types.h>
55 #include <asm/mach/arch.h>
56 #include <asm/mach/map.h>
57 #include <asm/mach/time.h>
58
59 /*
60  * Address      Interface               BusWidth        note
61  * ------------------------------------------------------------------
62  * 0x0000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = ON
63  * 0x0800_0000  user area               -
64  * 0x1000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = OFF
65  * 0x1400_0000  Ether (LAN9220)         16bit
66  * 0x1600_0000  user area               -               cannot use with NAND
67  * 0x1800_0000  user area               -
68  * 0x1A00_0000  -
69  * 0x4000_0000  LPDDR2-SDRAM (POP)      32bit
70  */
71
72 /*
73  * NOR Flash ROM
74  *
75  *  SW1  |     SW2    | SW7  | NOR Flash ROM
76  *  bit1 | bit1  bit2 | bit1 | Memory allocation
77  * ------+------------+------+------------------
78  *  OFF  | ON     OFF | ON   |    Area 0
79  *  OFF  | ON     OFF | OFF  |    Area 4
80  */
81
82 /*
83  * NAND Flash ROM
84  *
85  *  SW1  |     SW2    | SW7  | NAND Flash ROM
86  *  bit1 | bit1  bit2 | bit2 | Memory allocation
87  * ------+------------+------+------------------
88  *  OFF  | ON     OFF | ON   |    FCE 0
89  *  OFF  | ON     OFF | OFF  |    FCE 1
90  */
91
92 /*
93  * SMSC 9220
94  *
95  *  SW1         SMSC 9220
96  * -----------------------
97  *  ON          access disable
98  *  OFF         access enable
99  */
100
101 /*
102  * LCD / IRQ / KEYSC / IrDA
103  *
104  * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (QHD-TouchScreen)
105  * LCD = 2nd LCDC (WVGA)
106  *
107  *              |               SW43                    |
108  * SW3          |       ON              |       OFF     |
109  * -------------+-----------------------+---------------+
110  * ON           | KEY / IrDA            | LCD           |
111  * OFF          | KEY / IrDA / IRQ      | IRQ           |
112  *
113  *
114  * QHD / WVGA display
115  *
116  * You can choice display type on menuconfig.
117  * Then, check above dip-switch.
118  */
119
120 /*
121  * USB
122  *
123  * J7 : 1-2  MAX3355E VBUS
124  *      2-3  DC 5.0V
125  *
126  * S39: bit2: off
127  */
128
129 /*
130  * FSI/FSMI
131  *
132  * SW41 :  ON : SH-Mobile AP4 Audio Mode
133  *      : OFF : Bluetooth Audio Mode
134  */
135
136 /*
137  * MMC0/SDHI1 (CN7)
138  *
139  * J22 : select card voltage
140  *       1-2 pin : 1.8v
141  *       2-3 pin : 3.3v
142  *
143  *        SW1  |             SW33
144  *             | bit1 | bit2 | bit3 | bit4
145  * ------------+------+------+------+-------
146  * MMC0   OFF  |  OFF |  ON  |  ON  |  X
147  * SDHI1  OFF  |  ON  |   X  |  OFF | ON
148  *
149  * voltage lebel
150  * CN7 : 1.8v
151  * CN12: 3.3v
152  */
153
154 /* MTD */
155 static struct mtd_partition nor_flash_partitions[] = {
156         {
157                 .name           = "loader",
158                 .offset         = 0x00000000,
159                 .size           = 512 * 1024,
160         },
161         {
162                 .name           = "bootenv",
163                 .offset         = MTDPART_OFS_APPEND,
164                 .size           = 512 * 1024,
165         },
166         {
167                 .name           = "kernel_ro",
168                 .offset         = MTDPART_OFS_APPEND,
169                 .size           = 8 * 1024 * 1024,
170                 .mask_flags     = MTD_WRITEABLE,
171         },
172         {
173                 .name           = "kernel",
174                 .offset         = MTDPART_OFS_APPEND,
175                 .size           = 8 * 1024 * 1024,
176         },
177         {
178                 .name           = "data",
179                 .offset         = MTDPART_OFS_APPEND,
180                 .size           = MTDPART_SIZ_FULL,
181         },
182 };
183
184 static struct physmap_flash_data nor_flash_data = {
185         .width          = 2,
186         .parts          = nor_flash_partitions,
187         .nr_parts       = ARRAY_SIZE(nor_flash_partitions),
188 };
189
190 static struct resource nor_flash_resources[] = {
191         [0]     = {
192                 .start  = 0x00000000,
193                 .end    = 0x08000000 - 1,
194                 .flags  = IORESOURCE_MEM,
195         }
196 };
197
198 static struct platform_device nor_flash_device = {
199         .name           = "physmap-flash",
200         .dev            = {
201                 .platform_data  = &nor_flash_data,
202         },
203         .num_resources  = ARRAY_SIZE(nor_flash_resources),
204         .resource       = nor_flash_resources,
205 };
206
207 /* SMSC 9220 */
208 static struct resource smc911x_resources[] = {
209         {
210                 .start  = 0x14000000,
211                 .end    = 0x16000000 - 1,
212                 .flags  = IORESOURCE_MEM,
213         }, {
214                 .start  = evt2irq(0x02c0) /* IRQ6A */,
215                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
216         },
217 };
218
219 static struct smsc911x_platform_config smsc911x_info = {
220         .flags          = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
221         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
222         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
223 };
224
225 static struct platform_device smc911x_device = {
226         .name           = "smsc911x",
227         .id             = -1,
228         .num_resources  = ARRAY_SIZE(smc911x_resources),
229         .resource       = smc911x_resources,
230         .dev            = {
231                 .platform_data = &smsc911x_info,
232         },
233 };
234
235 /* SH_MMCIF */
236 static struct resource sh_mmcif_resources[] = {
237         [0] = {
238                 .name   = "SH_MMCIF",
239                 .start  = 0xE6BD0000,
240                 .end    = 0xE6BD00FF,
241                 .flags  = IORESOURCE_MEM,
242         },
243         [1] = {
244                 /* MMC ERR */
245                 .start  = evt2irq(0x1ac0),
246                 .flags  = IORESOURCE_IRQ,
247         },
248         [2] = {
249                 /* MMC NOR */
250                 .start  = evt2irq(0x1ae0),
251                 .flags  = IORESOURCE_IRQ,
252         },
253 };
254
255 static struct sh_mmcif_plat_data sh_mmcif_plat = {
256         .sup_pclk       = 0,
257         .ocr            = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
258         .caps           = MMC_CAP_4_BIT_DATA |
259                           MMC_CAP_8_BIT_DATA |
260                           MMC_CAP_NEEDS_POLL,
261 };
262
263 static struct platform_device sh_mmcif_device = {
264         .name           = "sh_mmcif",
265         .id             = 0,
266         .dev            = {
267                 .dma_mask               = NULL,
268                 .coherent_dma_mask      = 0xffffffff,
269                 .platform_data          = &sh_mmcif_plat,
270         },
271         .num_resources  = ARRAY_SIZE(sh_mmcif_resources),
272         .resource       = sh_mmcif_resources,
273 };
274
275 /* SDHI0 */
276 static struct sh_mobile_sdhi_info sdhi0_info = {
277         .dma_slave_tx   = SHDMA_SLAVE_SDHI0_TX,
278         .dma_slave_rx   = SHDMA_SLAVE_SDHI0_RX,
279 };
280
281 static struct resource sdhi0_resources[] = {
282         [0] = {
283                 .name   = "SDHI0",
284                 .start  = 0xe6850000,
285                 .end    = 0xe68501ff,
286                 .flags  = IORESOURCE_MEM,
287         },
288         [1] = {
289                 .start  = evt2irq(0x0e00) /* SDHI0 */,
290                 .flags  = IORESOURCE_IRQ,
291         },
292 };
293
294 static struct platform_device sdhi0_device = {
295         .name           = "sh_mobile_sdhi",
296         .num_resources  = ARRAY_SIZE(sdhi0_resources),
297         .resource       = sdhi0_resources,
298         .id             = 0,
299         .dev    = {
300                 .platform_data  = &sdhi0_info,
301         },
302 };
303
304 /* SDHI1 */
305 static struct sh_mobile_sdhi_info sdhi1_info = {
306         .dma_slave_tx   = SHDMA_SLAVE_SDHI1_TX,
307         .dma_slave_rx   = SHDMA_SLAVE_SDHI1_RX,
308         .tmio_ocr_mask  = MMC_VDD_165_195,
309 };
310
311 static struct resource sdhi1_resources[] = {
312         [0] = {
313                 .name   = "SDHI1",
314                 .start  = 0xe6860000,
315                 .end    = 0xe68601ff,
316                 .flags  = IORESOURCE_MEM,
317         },
318         [1] = {
319                 .start  = evt2irq(0x0e80),
320                 .flags  = IORESOURCE_IRQ,
321         },
322 };
323
324 static struct platform_device sdhi1_device = {
325         .name           = "sh_mobile_sdhi",
326         .num_resources  = ARRAY_SIZE(sdhi1_resources),
327         .resource       = sdhi1_resources,
328         .id             = 1,
329         .dev    = {
330                 .platform_data  = &sdhi1_info,
331         },
332 };
333
334 /* USB1 */
335 static void usb1_host_port_power(int port, int power)
336 {
337         if (!power) /* only power-on supported for now */
338                 return;
339
340         /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
341         __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
342 }
343
344 static struct r8a66597_platdata usb1_host_data = {
345         .on_chip        = 1,
346         .port_power     = usb1_host_port_power,
347 };
348
349 static struct resource usb1_host_resources[] = {
350         [0] = {
351                 .name   = "USBHS",
352                 .start  = 0xE68B0000,
353                 .end    = 0xE68B00E6 - 1,
354                 .flags  = IORESOURCE_MEM,
355         },
356         [1] = {
357                 .start  = evt2irq(0x1ce0) /* USB1_USB1I0 */,
358                 .flags  = IORESOURCE_IRQ,
359         },
360 };
361
362 static struct platform_device usb1_host_device = {
363         .name   = "r8a66597_hcd",
364         .id     = 1,
365         .dev = {
366                 .dma_mask               = NULL,         /*  not use dma */
367                 .coherent_dma_mask      = 0xffffffff,
368                 .platform_data          = &usb1_host_data,
369         },
370         .num_resources  = ARRAY_SIZE(usb1_host_resources),
371         .resource       = usb1_host_resources,
372 };
373
374 static struct sh_mobile_lcdc_info lcdc_info = {
375         .ch[0] = {
376                 .chan = LCDC_CHAN_MAINLCD,
377                 .bpp = 16,
378         }
379 };
380
381 static struct resource lcdc_resources[] = {
382         [0] = {
383                 .name   = "LCDC",
384                 .start  = 0xfe940000, /* P4-only space */
385                 .end    = 0xfe943fff,
386                 .flags  = IORESOURCE_MEM,
387         },
388         [1] = {
389                 .start  = intcs_evt2irq(0x580),
390                 .flags  = IORESOURCE_IRQ,
391         },
392 };
393
394 static struct platform_device lcdc_device = {
395         .name           = "sh_mobile_lcdc_fb",
396         .num_resources  = ARRAY_SIZE(lcdc_resources),
397         .resource       = lcdc_resources,
398         .dev    = {
399                 .platform_data  = &lcdc_info,
400                 .coherent_dma_mask = ~0,
401         },
402 };
403
404 /*
405  * QHD display
406  */
407 #ifdef CONFIG_AP4EVB_QHD
408
409 /* KEYSC (Needs SW43 set to ON) */
410 static struct sh_keysc_info keysc_info = {
411         .mode           = SH_KEYSC_MODE_1,
412         .scan_timing    = 3,
413         .delay          = 2500,
414         .keycodes = {
415                 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
416                 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
417                 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
418                 KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
419                 KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
420         },
421 };
422
423 static struct resource keysc_resources[] = {
424         [0] = {
425                 .name   = "KEYSC",
426                 .start  = 0xe61b0000,
427                 .end    = 0xe61b0063,
428                 .flags  = IORESOURCE_MEM,
429         },
430         [1] = {
431                 .start  = evt2irq(0x0be0), /* KEYSC_KEY */
432                 .flags  = IORESOURCE_IRQ,
433         },
434 };
435
436 static struct platform_device keysc_device = {
437         .name           = "sh_keysc",
438         .id             = 0, /* "keysc0" clock */
439         .num_resources  = ARRAY_SIZE(keysc_resources),
440         .resource       = keysc_resources,
441         .dev    = {
442                 .platform_data  = &keysc_info,
443         },
444 };
445
446 /* MIPI-DSI */
447 static struct resource mipidsi0_resources[] = {
448         [0] = {
449                 .start  = 0xffc60000,
450                 .end    = 0xffc68fff,
451                 .flags  = IORESOURCE_MEM,
452         },
453 };
454
455 static struct sh_mipi_dsi_info mipidsi0_info = {
456         .data_format    = MIPI_RGB888,
457         .lcd_chan       = &lcdc_info.ch[0],
458 };
459
460 static struct platform_device mipidsi0_device = {
461         .name           = "sh-mipi-dsi",
462         .num_resources  = ARRAY_SIZE(mipidsi0_resources),
463         .resource       = mipidsi0_resources,
464         .id             = 0,
465         .dev    = {
466                 .platform_data  = &mipidsi0_info,
467         },
468 };
469
470 /* This function will disappear when we switch to (runtime) PM */
471 static int __init ap4evb_init_display_clk(void)
472 {
473         struct clk *lcdc_clk;
474         struct clk *dsitx_clk;
475         int ret;
476
477         lcdc_clk = clk_get(&lcdc_device.dev, "sh_mobile_lcdc_fb.0");
478         if (IS_ERR(lcdc_clk))
479                 return PTR_ERR(lcdc_clk);
480
481         dsitx_clk = clk_get(&mipidsi0_device.dev, "sh-mipi-dsi.0");
482         if (IS_ERR(dsitx_clk)) {
483                 ret = PTR_ERR(dsitx_clk);
484                 goto eclkdsitxget;
485         }
486
487         ret = clk_enable(lcdc_clk);
488         if (ret < 0)
489                 goto eclklcdcon;
490
491         ret = clk_enable(dsitx_clk);
492         if (ret < 0)
493                 goto eclkdsitxon;
494
495         return 0;
496
497 eclkdsitxon:
498         clk_disable(lcdc_clk);
499 eclklcdcon:
500         clk_put(dsitx_clk);
501 eclkdsitxget:
502         clk_put(lcdc_clk);
503
504         return ret;
505 }
506 device_initcall(ap4evb_init_display_clk);
507
508 static struct platform_device *qhd_devices[] __initdata = {
509         &mipidsi0_device,
510         &keysc_device,
511 };
512 #endif /* CONFIG_AP4EVB_QHD */
513
514 /* FSI */
515 #define IRQ_FSI         evt2irq(0x1840)
516 #define FSIACKCR        0xE6150018
517 static void fsiackcr_init(struct clk *clk)
518 {
519         u32 status = __raw_readl(clk->enable_reg);
520
521         /* use external clock */
522         status &= ~0x000000ff;
523         status |= 0x00000080;
524         __raw_writel(status, clk->enable_reg);
525 }
526
527 static struct clk_ops fsiackcr_clk_ops = {
528         .init = fsiackcr_init,
529 };
530
531 static struct clk fsiackcr_clk = {
532         .ops            = &fsiackcr_clk_ops,
533         .enable_reg     = (void __iomem *)FSIACKCR,
534         .rate           = 0, /* unknown */
535 };
536
537 static struct sh_fsi_platform_info fsi_info = {
538         .porta_flags = SH_FSI_BRS_INV |
539                        SH_FSI_OUT_SLAVE_MODE |
540                        SH_FSI_IN_SLAVE_MODE |
541                        SH_FSI_OFMT(PCM) |
542                        SH_FSI_IFMT(PCM),
543 };
544
545 static struct resource fsi_resources[] = {
546         [0] = {
547                 .name   = "FSI",
548                 .start  = 0xFE3C0000,
549                 .end    = 0xFE3C0400 - 1,
550                 .flags  = IORESOURCE_MEM,
551         },
552         [1] = {
553                 .start  = IRQ_FSI,
554                 .flags  = IORESOURCE_IRQ,
555         },
556 };
557
558 static struct platform_device fsi_device = {
559         .name           = "sh_fsi2",
560         .id             = 0,
561         .num_resources  = ARRAY_SIZE(fsi_resources),
562         .resource       = fsi_resources,
563         .dev    = {
564                 .platform_data  = &fsi_info,
565         },
566 };
567
568 static struct platform_device *ap4evb_devices[] __initdata = {
569         &nor_flash_device,
570         &smc911x_device,
571         &sdhi0_device,
572         &sdhi1_device,
573         &usb1_host_device,
574         &lcdc_device,
575         &fsi_device,
576         &sh_mmcif_device
577 };
578
579 /*
580  * FIXME !!
581  *
582  * gpio_no_direction
583  * gpio_pull_up
584  * are quick_hack.
585  *
586  * current gpio frame work doesn't have
587  * the method to control only pull up/down/free.
588  * this function should be replaced by correct gpio function
589  */
590 static void __init gpio_no_direction(u32 addr)
591 {
592         __raw_writeb(0x00, addr);
593 }
594
595 static void __init gpio_pull_up(u32 addr)
596 {
597         u8 data = __raw_readb(addr);
598
599         data &= 0x0F;
600         data |= 0xC0;
601         __raw_writeb(data, addr);
602 }
603
604 /* TouchScreen */
605 #define IRQ28   evt2irq(0x3380) /* IRQ28A */
606 #define IRQ7    evt2irq(0x02e0) /* IRQ7A */
607 static int ts_get_pendown_state(void)
608 {
609         int val1, val2;
610
611         gpio_free(GPIO_FN_IRQ28_123);
612         gpio_free(GPIO_FN_IRQ7_40);
613
614         gpio_request(GPIO_PORT123, NULL);
615         gpio_request(GPIO_PORT40, NULL);
616
617         gpio_direction_input(GPIO_PORT123);
618         gpio_direction_input(GPIO_PORT40);
619
620         val1 = gpio_get_value(GPIO_PORT123);
621         val2 = gpio_get_value(GPIO_PORT40);
622
623         gpio_request(GPIO_FN_IRQ28_123, NULL);  /* for QHD */
624         gpio_request(GPIO_FN_IRQ7_40, NULL);    /* for WVGA */
625
626         return val1 ^ val2;
627 }
628
629 #define PORT40CR        0xE6051028
630 #define PORT123CR       0xE605007B
631 static int ts_init(void)
632 {
633         gpio_request(GPIO_FN_IRQ28_123, NULL);  /* for QHD */
634         gpio_request(GPIO_FN_IRQ7_40, NULL);    /* for WVGA */
635
636         gpio_pull_up(PORT40CR);
637         gpio_pull_up(PORT123CR);
638
639         return 0;
640 }
641
642 static struct tsc2007_platform_data tsc2007_info = {
643         .model                  = 2007,
644         .x_plate_ohms           = 180,
645         .get_pendown_state      = ts_get_pendown_state,
646         .init_platform_hw       = ts_init,
647 };
648
649 static struct i2c_board_info tsc_device = {
650         I2C_BOARD_INFO("tsc2007", 0x48),
651         .type           = "tsc2007",
652         .platform_data  = &tsc2007_info,
653         /*.irq is selected on ap4evb_init */
654 };
655
656 /* I2C */
657 static struct i2c_board_info i2c0_devices[] = {
658         {
659                 I2C_BOARD_INFO("ak4643", 0x13),
660         },
661 };
662
663 static struct i2c_board_info i2c1_devices[] = {
664         {
665                 I2C_BOARD_INFO("r2025sd", 0x32),
666         },
667 };
668
669 static struct map_desc ap4evb_io_desc[] __initdata = {
670         /* create a 1:1 entity map for 0xe6xxxxxx
671          * used by CPGA, INTC and PFC.
672          */
673         {
674                 .virtual        = 0xe6000000,
675                 .pfn            = __phys_to_pfn(0xe6000000),
676                 .length         = 256 << 20,
677                 .type           = MT_DEVICE_NONSHARED
678         },
679 };
680
681 static void __init ap4evb_map_io(void)
682 {
683         iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
684
685         /* setup early devices and console here as well */
686         sh7372_add_early_devices();
687         shmobile_setup_console();
688 }
689
690 #define GPIO_PORT9CR    0xE6051009
691 #define GPIO_PORT10CR   0xE605100A
692
693 static void __init ap4evb_init(void)
694 {
695         struct clk *clk;
696
697         sh7372_pinmux_init();
698
699         /* enable SCIFA0 */
700         gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
701         gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
702
703         /* enable SMSC911X */
704         gpio_request(GPIO_FN_CS5A,      NULL);
705         gpio_request(GPIO_FN_IRQ6_39,   NULL);
706
707         /* enable LED 1 - 4 */
708         gpio_request(GPIO_PORT185, NULL);
709         gpio_request(GPIO_PORT186, NULL);
710         gpio_request(GPIO_PORT187, NULL);
711         gpio_request(GPIO_PORT188, NULL);
712         gpio_direction_output(GPIO_PORT185, 1);
713         gpio_direction_output(GPIO_PORT186, 1);
714         gpio_direction_output(GPIO_PORT187, 1);
715         gpio_direction_output(GPIO_PORT188, 1);
716         gpio_export(GPIO_PORT185, 0);
717         gpio_export(GPIO_PORT186, 0);
718         gpio_export(GPIO_PORT187, 0);
719         gpio_export(GPIO_PORT188, 0);
720
721         /* enable Debug switch (S6) */
722         gpio_request(GPIO_PORT32, NULL);
723         gpio_request(GPIO_PORT33, NULL);
724         gpio_request(GPIO_PORT34, NULL);
725         gpio_request(GPIO_PORT35, NULL);
726         gpio_direction_input(GPIO_PORT32);
727         gpio_direction_input(GPIO_PORT33);
728         gpio_direction_input(GPIO_PORT34);
729         gpio_direction_input(GPIO_PORT35);
730         gpio_export(GPIO_PORT32, 0);
731         gpio_export(GPIO_PORT33, 0);
732         gpio_export(GPIO_PORT34, 0);
733         gpio_export(GPIO_PORT35, 0);
734
735         /* SDHI0 */
736         gpio_request(GPIO_FN_SDHICD0, NULL);
737         gpio_request(GPIO_FN_SDHIWP0, NULL);
738         gpio_request(GPIO_FN_SDHICMD0, NULL);
739         gpio_request(GPIO_FN_SDHICLK0, NULL);
740         gpio_request(GPIO_FN_SDHID0_3, NULL);
741         gpio_request(GPIO_FN_SDHID0_2, NULL);
742         gpio_request(GPIO_FN_SDHID0_1, NULL);
743         gpio_request(GPIO_FN_SDHID0_0, NULL);
744
745         /* SDHI1 */
746         gpio_request(GPIO_FN_SDHICMD1, NULL);
747         gpio_request(GPIO_FN_SDHICLK1, NULL);
748         gpio_request(GPIO_FN_SDHID1_3, NULL);
749         gpio_request(GPIO_FN_SDHID1_2, NULL);
750         gpio_request(GPIO_FN_SDHID1_1, NULL);
751         gpio_request(GPIO_FN_SDHID1_0, NULL);
752
753         /* MMCIF */
754         gpio_request(GPIO_FN_MMCD0_0, NULL);
755         gpio_request(GPIO_FN_MMCD0_1, NULL);
756         gpio_request(GPIO_FN_MMCD0_2, NULL);
757         gpio_request(GPIO_FN_MMCD0_3, NULL);
758         gpio_request(GPIO_FN_MMCD0_4, NULL);
759         gpio_request(GPIO_FN_MMCD0_5, NULL);
760         gpio_request(GPIO_FN_MMCD0_6, NULL);
761         gpio_request(GPIO_FN_MMCD0_7, NULL);
762         gpio_request(GPIO_FN_MMCCMD0, NULL);
763         gpio_request(GPIO_FN_MMCCLK0, NULL);
764
765         /* USB enable */
766         gpio_request(GPIO_FN_VBUS0_1,    NULL);
767         gpio_request(GPIO_FN_IDIN_1_18,  NULL);
768         gpio_request(GPIO_FN_PWEN_1_115, NULL);
769         gpio_request(GPIO_FN_OVCN_1_114, NULL);
770         gpio_request(GPIO_FN_EXTLP_1,    NULL);
771         gpio_request(GPIO_FN_OVCN2_1,    NULL);
772
773         /* setup USB phy */
774         __raw_writew(0x8a0a, 0xE6058130);       /* USBCR2 */
775
776         /* enable FSI2 */
777         gpio_request(GPIO_FN_FSIAIBT,   NULL);
778         gpio_request(GPIO_FN_FSIAILR,   NULL);
779         gpio_request(GPIO_FN_FSIAISLD,  NULL);
780         gpio_request(GPIO_FN_FSIAOSLD,  NULL);
781         gpio_request(GPIO_PORT161,      NULL);
782         gpio_direction_output(GPIO_PORT161, 0); /* slave */
783
784         gpio_request(GPIO_PORT9, NULL);
785         gpio_request(GPIO_PORT10, NULL);
786         gpio_no_direction(GPIO_PORT9CR);  /* FSIAOBT needs no direction */
787         gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
788
789         /* set SPU2 clock to 119.6 MHz */
790         clk = clk_get(NULL, "spu_clk");
791         if (!IS_ERR(clk)) {
792                 clk_set_rate(clk, clk_round_rate(clk, 119600000));
793                 clk_put(clk);
794         }
795
796         /* change parent of FSI A */
797         clk = clk_get(NULL, "fsia_clk");
798         if (!IS_ERR(clk)) {
799                 clk_register(&fsiackcr_clk);
800                 clk_set_parent(clk, &fsiackcr_clk);
801                 clk_put(clk);
802         }
803
804         /*
805          * set irq priority, to avoid sound chopping
806          * when NFS rootfs is used
807          *  FSI(3) > SMSC911X(2)
808          */
809         intc_set_priority(IRQ_FSI, 3);
810
811         i2c_register_board_info(0, i2c0_devices,
812                                 ARRAY_SIZE(i2c0_devices));
813
814         i2c_register_board_info(1, i2c1_devices,
815                                 ARRAY_SIZE(i2c1_devices));
816
817 #ifdef CONFIG_AP4EVB_QHD
818         /*
819          * QHD
820          */
821
822         /* enable KEYSC */
823         gpio_request(GPIO_FN_KEYOUT0, NULL);
824         gpio_request(GPIO_FN_KEYOUT1, NULL);
825         gpio_request(GPIO_FN_KEYOUT2, NULL);
826         gpio_request(GPIO_FN_KEYOUT3, NULL);
827         gpio_request(GPIO_FN_KEYOUT4, NULL);
828         gpio_request(GPIO_FN_KEYIN0_136, NULL);
829         gpio_request(GPIO_FN_KEYIN1_135, NULL);
830         gpio_request(GPIO_FN_KEYIN2_134, NULL);
831         gpio_request(GPIO_FN_KEYIN3_133, NULL);
832         gpio_request(GPIO_FN_KEYIN4,     NULL);
833
834         /* enable TouchScreen */
835         set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
836
837         tsc_device.irq = IRQ28;
838         i2c_register_board_info(1, &tsc_device, 1);
839
840         /* LCDC0 */
841         lcdc_info.clock_source                  = LCDC_CLK_PERIPHERAL;
842         lcdc_info.ch[0].interface_type          = RGB24;
843         lcdc_info.ch[0].clock_divider           = 1;
844         lcdc_info.ch[0].flags                   = LCDC_FLAGS_DWPOL;
845         lcdc_info.ch[0].lcd_cfg.name            = "R63302(QHD)";
846         lcdc_info.ch[0].lcd_cfg.xres            = 544;
847         lcdc_info.ch[0].lcd_cfg.yres            = 961;
848         lcdc_info.ch[0].lcd_cfg.left_margin     = 72;
849         lcdc_info.ch[0].lcd_cfg.right_margin    = 600;
850         lcdc_info.ch[0].lcd_cfg.hsync_len       = 16;
851         lcdc_info.ch[0].lcd_cfg.upper_margin    = 8;
852         lcdc_info.ch[0].lcd_cfg.lower_margin    = 8;
853         lcdc_info.ch[0].lcd_cfg.vsync_len       = 2;
854         lcdc_info.ch[0].lcd_cfg.sync            = FB_SYNC_VERT_HIGH_ACT |
855                                                   FB_SYNC_HOR_HIGH_ACT;
856         lcdc_info.ch[0].lcd_size_cfg.width      = 44;
857         lcdc_info.ch[0].lcd_size_cfg.height     = 79;
858
859         platform_add_devices(qhd_devices, ARRAY_SIZE(qhd_devices));
860
861 #else
862         /*
863          * WVGA
864          */
865         gpio_request(GPIO_FN_LCDD17,   NULL);
866         gpio_request(GPIO_FN_LCDD16,   NULL);
867         gpio_request(GPIO_FN_LCDD15,   NULL);
868         gpio_request(GPIO_FN_LCDD14,   NULL);
869         gpio_request(GPIO_FN_LCDD13,   NULL);
870         gpio_request(GPIO_FN_LCDD12,   NULL);
871         gpio_request(GPIO_FN_LCDD11,   NULL);
872         gpio_request(GPIO_FN_LCDD10,   NULL);
873         gpio_request(GPIO_FN_LCDD9,    NULL);
874         gpio_request(GPIO_FN_LCDD8,    NULL);
875         gpio_request(GPIO_FN_LCDD7,    NULL);
876         gpio_request(GPIO_FN_LCDD6,    NULL);
877         gpio_request(GPIO_FN_LCDD5,    NULL);
878         gpio_request(GPIO_FN_LCDD4,    NULL);
879         gpio_request(GPIO_FN_LCDD3,    NULL);
880         gpio_request(GPIO_FN_LCDD2,    NULL);
881         gpio_request(GPIO_FN_LCDD1,    NULL);
882         gpio_request(GPIO_FN_LCDD0,    NULL);
883         gpio_request(GPIO_FN_LCDDISP,  NULL);
884         gpio_request(GPIO_FN_LCDDCK,   NULL);
885
886         gpio_request(GPIO_PORT189, NULL); /* backlight */
887         gpio_direction_output(GPIO_PORT189, 1);
888
889         gpio_request(GPIO_PORT151, NULL); /* LCDDON */
890         gpio_direction_output(GPIO_PORT151, 1);
891
892         lcdc_info.clock_source                  = LCDC_CLK_BUS;
893         lcdc_info.ch[0].interface_type          = RGB18;
894         lcdc_info.ch[0].clock_divider           = 2;
895         lcdc_info.ch[0].flags                   = 0;
896         lcdc_info.ch[0].lcd_cfg.name            = "WVGA Panel";
897         lcdc_info.ch[0].lcd_cfg.xres            = 800;
898         lcdc_info.ch[0].lcd_cfg.yres            = 480;
899         lcdc_info.ch[0].lcd_cfg.left_margin     = 220;
900         lcdc_info.ch[0].lcd_cfg.right_margin    = 110;
901         lcdc_info.ch[0].lcd_cfg.hsync_len       = 70;
902         lcdc_info.ch[0].lcd_cfg.upper_margin    = 20;
903         lcdc_info.ch[0].lcd_cfg.lower_margin    = 5;
904         lcdc_info.ch[0].lcd_cfg.vsync_len       = 5;
905         lcdc_info.ch[0].lcd_cfg.sync            = 0;
906         lcdc_info.ch[0].lcd_size_cfg.width      = 152;
907         lcdc_info.ch[0].lcd_size_cfg.height     = 91;
908
909         /* enable TouchScreen */
910         set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
911
912         tsc_device.irq = IRQ7;
913         i2c_register_board_info(0, &tsc_device, 1);
914 #endif /* CONFIG_AP4EVB_QHD */
915
916         sh7372_add_standard_devices();
917
918         platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
919 }
920
921 static void __init ap4evb_timer_init(void)
922 {
923         sh7372_clock_init();
924         shmobile_timer.init();
925 }
926
927 static struct sys_timer ap4evb_timer = {
928         .init           = ap4evb_timer_init,
929 };
930
931 MACHINE_START(AP4EVB, "ap4evb")
932         .phys_io        = 0xe6000000,
933         .io_pg_offst    = ((0xe6000000) >> 18) & 0xfffc,
934         .map_io         = ap4evb_map_io,
935         .init_irq       = sh7372_init_irq,
936         .init_machine   = ap4evb_init,
937         .timer          = &ap4evb_timer,
938 MACHINE_END