blob: 968601201fb5b33ff58c96d97fabbb1044195379 [file] [log] [blame]
Magnus Damm2b7eda62010-02-05 11:14:58 +00001/*
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 */
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +000020#include <linux/clk.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000021#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>
Guennadi Liakhovetski69bf6f452010-05-04 14:07:15 +000027#include <linux/mfd/sh_mobile_sdhi.h>
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +000028#include <linux/mmc/host.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000029#include <linux/mtd/mtd.h>
30#include <linux/mtd/partitions.h>
31#include <linux/mtd/physmap.h>
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +000032#include <linux/mmc/host.h>
33#include <linux/mmc/sh_mmcif.h>
Kuninori Morimoto91cf5082010-03-11 10:42:52 +000034#include <linux/i2c.h>
35#include <linux/i2c/tsc2007.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000036#include <linux/io.h>
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +000037#include <linux/smsc911x.h>
Kuninori Morimotocb9215e2010-05-24 06:50:44 +000038#include <linux/sh_intc.h>
39#include <linux/sh_clk.h>
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +000040#include <linux/gpio.h>
Kuninori Morimoto17ccb832010-02-23 07:07:01 +000041#include <linux/input.h>
42#include <linux/input/sh_keysc.h>
Kuninori Morimotofb54d262010-04-13 06:16:32 +000043#include <linux/usb/r8a66597.h>
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +000044
Kuninori Morimotocb9215e2010-05-24 06:50:44 +000045#include <sound/sh_fsi.h>
46
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +000047#include <video/sh_mobile_lcdc.h>
48#include <video/sh_mipi_dsi.h>
49
Magnus Damm2b7eda62010-02-05 11:14:58 +000050#include <mach/common.h>
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +000051#include <mach/irqs.h>
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +000052#include <mach/sh7372.h>
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +000053
Magnus Damm2b7eda62010-02-05 11:14:58 +000054#include <asm/mach-types.h>
55#include <asm/mach/arch.h>
56#include <asm/mach/map.h>
Magnus Damm495b3ce2010-05-12 14:21:34 +000057#include <asm/mach/time.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000058
Kuninori Morimoto02624a12010-02-18 17:58:19 +090059/*
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
Kuninori Morimoto17ccb832010-02-23 07:07:01 +0000101/*
Kuninori Morimotodda128d2010-03-12 10:07:55 +0000102 * LCD / IRQ / KEYSC / IrDA
Kuninori Morimoto17ccb832010-02-23 07:07:01 +0000103 *
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000104 * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (QHD-TouchScreen)
105 * LCD = 2nd LCDC (WVGA)
Kuninori Morimotodda128d2010-03-12 10:07:55 +0000106 *
107 * | SW43 |
108 * SW3 | ON | OFF |
109 * -------------+-----------------------+---------------+
110 * ON | KEY / IrDA | LCD |
111 * OFF | KEY / IrDA / IRQ | IRQ |
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000112 *
113 *
114 * QHD / WVGA display
115 *
116 * You can choice display type on menuconfig.
117 * Then, check above dip-switch.
Kuninori Morimoto17ccb832010-02-23 07:07:01 +0000118 */
119
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000120/*
121 * USB
122 *
123 * J7 : 1-2 MAX3355E VBUS
124 * 2-3 DC 5.0V
125 *
126 * S39: bit2: off
127 */
128
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000129/*
130 * FSI/FSMI
131 *
132 * SW41 : ON : SH-Mobile AP4 Audio Mode
133 * : OFF : Bluetooth Audio Mode
134 */
135
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000136/*
Kuninori Morimotod3d03e42010-06-01 04:31:29 +0000137 * MMC0/SDHI1 (CN7)
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000138 *
Kuninori Morimotod3d03e42010-06-01 04:31:29 +0000139 * 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
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000152 */
153
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000154/* MTD */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000155static 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
184static 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
190static struct resource nor_flash_resources[] = {
191 [0] = {
192 .start = 0x00000000,
193 .end = 0x08000000 - 1,
194 .flags = IORESOURCE_MEM,
195 }
196};
197
198static 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
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000207/* SMSC 9220 */
208static struct resource smc911x_resources[] = {
209 {
210 .start = 0x14000000,
211 .end = 0x16000000 - 1,
212 .flags = IORESOURCE_MEM,
213 }, {
Magnus Damm33c96072010-05-20 14:41:00 +0000214 .start = evt2irq(0x02c0) /* IRQ6A */,
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000215 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
216 },
217};
218
219static 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
225static 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};
Magnus Damm2b7eda62010-02-05 11:14:58 +0000234
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000235/* SH_MMCIF */
236static 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 */
Kuninori Morimoto8d569342010-06-01 02:40:05 +0000245 .start = evt2irq(0x1ac0),
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000246 .flags = IORESOURCE_IRQ,
247 },
248 [2] = {
249 /* MMC NOR */
Kuninori Morimoto8d569342010-06-01 02:40:05 +0000250 .start = evt2irq(0x1ae0),
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000251 .flags = IORESOURCE_IRQ,
252 },
253};
254
Kuninori Morimotobb04e192010-06-02 00:25:03 +0000255static struct sh_mmcif_plat_data sh_mmcif_plat = {
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000256 .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
263static 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
Magnus Damm3a14d032010-03-10 09:26:44 +0000275/* SDHI0 */
Guennadi Liakhovetski69bf6f452010-05-04 14:07:15 +0000276static struct sh_mobile_sdhi_info sdhi0_info = {
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +0000277 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
278 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
Guennadi Liakhovetski69bf6f452010-05-04 14:07:15 +0000279};
280
Magnus Damm3a14d032010-03-10 09:26:44 +0000281static struct resource sdhi0_resources[] = {
282 [0] = {
283 .name = "SDHI0",
284 .start = 0xe6850000,
285 .end = 0xe68501ff,
286 .flags = IORESOURCE_MEM,
287 },
288 [1] = {
Magnus Damm33c96072010-05-20 14:41:00 +0000289 .start = evt2irq(0x0e00) /* SDHI0 */,
Magnus Damm3a14d032010-03-10 09:26:44 +0000290 .flags = IORESOURCE_IRQ,
291 },
292};
293
294static struct platform_device sdhi0_device = {
295 .name = "sh_mobile_sdhi",
296 .num_resources = ARRAY_SIZE(sdhi0_resources),
297 .resource = sdhi0_resources,
298 .id = 0,
Guennadi Liakhovetski69bf6f452010-05-04 14:07:15 +0000299 .dev = {
300 .platform_data = &sdhi0_info,
301 },
Magnus Damm3a14d032010-03-10 09:26:44 +0000302};
303
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +0000304/* SDHI1 */
305static 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
311static 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
324static 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
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000334/* USB1 */
Kuninori Morimotobb04e192010-06-02 00:25:03 +0000335static void usb1_host_port_power(int port, int power)
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000336{
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
344static struct r8a66597_platdata usb1_host_data = {
345 .on_chip = 1,
346 .port_power = usb1_host_port_power,
347};
348
349static struct resource usb1_host_resources[] = {
350 [0] = {
351 .name = "USBHS",
352 .start = 0xE68B0000,
353 .end = 0xE68B00E6 - 1,
354 .flags = IORESOURCE_MEM,
355 },
356 [1] = {
Magnus Damm33c96072010-05-20 14:41:00 +0000357 .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000358 .flags = IORESOURCE_IRQ,
359 },
360};
361
362static 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
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000374static struct sh_mobile_lcdc_info lcdc_info = {
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000375 .ch[0] = {
376 .chan = LCDC_CHAN_MAINLCD,
377 .bpp = 16,
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000378 }
379};
380
381static 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
394static struct platform_device lcdc_device = {
395 .name = "sh_mobile_lcdc_fb",
396 .num_resources = ARRAY_SIZE(lcdc_resources),
397 .resource = lcdc_resources,
398 .dev = {
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000399 .platform_data = &lcdc_info,
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000400 .coherent_dma_mask = ~0,
401 },
402};
403
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000404/*
405 * QHD display
406 */
407#ifdef CONFIG_AP4EVB_QHD
408
409/* KEYSC (Needs SW43 set to ON) */
410static 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
423static 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
436static 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 */
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000447static struct resource mipidsi0_resources[] = {
448 [0] = {
449 .start = 0xffc60000,
450 .end = 0xffc68fff,
451 .flags = IORESOURCE_MEM,
452 },
453};
454
455static struct sh_mipi_dsi_info mipidsi0_info = {
456 .data_format = MIPI_RGB888,
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000457 .lcd_chan = &lcdc_info.ch[0],
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000458};
459
460static 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
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000470/* This function will disappear when we switch to (runtime) PM */
471static 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
497eclkdsitxon:
498 clk_disable(lcdc_clk);
499eclklcdcon:
500 clk_put(dsitx_clk);
501eclkdsitxget:
502 clk_put(lcdc_clk);
503
504 return ret;
505}
506device_initcall(ap4evb_init_display_clk);
507
508static struct platform_device *qhd_devices[] __initdata = {
509 &mipidsi0_device,
510 &keysc_device,
511};
512#endif /* CONFIG_AP4EVB_QHD */
513
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000514/* FSI */
515#define IRQ_FSI evt2irq(0x1840)
516#define FSIACKCR 0xE6150018
517static 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
527static struct clk_ops fsiackcr_clk_ops = {
528 .init = fsiackcr_init,
529};
530
531static struct clk fsiackcr_clk = {
532 .ops = &fsiackcr_clk_ops,
533 .enable_reg = (void __iomem *)FSIACKCR,
534 .rate = 0, /* unknown */
535};
536
Kuninori Morimotobb04e192010-06-02 00:25:03 +0000537static struct sh_fsi_platform_info fsi_info = {
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000538 .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
545static 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
558static 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
Magnus Damm2b7eda62010-02-05 11:14:58 +0000568static struct platform_device *ap4evb_devices[] __initdata = {
569 &nor_flash_device,
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000570 &smc911x_device,
Magnus Damm3a14d032010-03-10 09:26:44 +0000571 &sdhi0_device,
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +0000572 &sdhi1_device,
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000573 &usb1_host_device,
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000574 &lcdc_device,
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000575 &fsi_device,
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000576 &sh_mmcif_device
Magnus Damm2b7eda62010-02-05 11:14:58 +0000577};
578
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +0000579/*
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 */
590static void __init gpio_no_direction(u32 addr)
591{
592 __raw_writeb(0x00, addr);
593}
594
595static 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
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000604/* TouchScreen */
Magnus Damm33c96072010-05-20 14:41:00 +0000605#define IRQ28 evt2irq(0x3380) /* IRQ28A */
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000606#define IRQ7 evt2irq(0x02e0) /* IRQ7A */
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +0000607static 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
631static 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
Kuninori Morimotobb04e192010-06-02 00:25:03 +0000642static struct tsc2007_platform_data tsc2007_info = {
Kuninori Morimoto91cf5082010-03-11 10:42:52 +0000643 .model = 2007,
644 .x_plate_ohms = 180,
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +0000645 .get_pendown_state = ts_get_pendown_state,
646 .init_platform_hw = ts_init,
Kuninori Morimoto91cf5082010-03-11 10:42:52 +0000647};
648
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000649static 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
Kuninori Morimoto91cf5082010-03-11 10:42:52 +0000656/* I2C */
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000657static struct i2c_board_info i2c0_devices[] = {
658 {
659 I2C_BOARD_INFO("ak4643", 0x13),
660 },
661};
662
Kuninori Morimoto91cf5082010-03-11 10:42:52 +0000663static struct i2c_board_info i2c1_devices[] = {
664 {
Kuninori Morimoto8fc883c2010-03-11 07:34:37 +0000665 I2C_BOARD_INFO("r2025sd", 0x32),
666 },
Kuninori Morimoto91cf5082010-03-11 10:42:52 +0000667};
668
Magnus Damm2b7eda62010-02-05 11:14:58 +0000669static 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
681static void __init ap4evb_map_io(void)
682{
683 iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
684
Magnus Damm495b3ce2010-05-12 14:21:34 +0000685 /* setup early devices and console here as well */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000686 sh7372_add_early_devices();
Magnus Damm4ae04ac2010-02-08 11:02:54 +0000687 shmobile_setup_console();
Magnus Damm2b7eda62010-02-05 11:14:58 +0000688}
689
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000690#define GPIO_PORT9CR 0xE6051009
691#define GPIO_PORT10CR 0xE605100A
692
Magnus Damm2b7eda62010-02-05 11:14:58 +0000693static void __init ap4evb_init(void)
694{
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000695 struct clk *clk;
696
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000697 sh7372_pinmux_init();
698
Kuninori Morimotob228b482010-02-18 16:44:41 +0900699 /* enable SCIFA0 */
700 gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
701 gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
702
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000703 /* enable SMSC911X */
704 gpio_request(GPIO_FN_CS5A, NULL);
705 gpio_request(GPIO_FN_IRQ6_39, NULL);
706
Kuninori Morimoto50982802010-02-22 09:20:39 +0000707 /* 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
Kuninori Morimoto8cb3a2e2010-02-22 09:30:12 +0000721 /* 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
Magnus Damm3a14d032010-03-10 09:26:44 +0000735 /* 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
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000745 /* 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);
Kuninori Morimoto91cf5082010-03-11 10:42:52 +0000752
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000753 /* 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
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000765 /* 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
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000776 /* 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");
Paul Mundt2ae2b762010-05-31 14:25:57 +0900791 if (!IS_ERR(clk)) {
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000792 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");
Paul Mundt2ae2b762010-05-31 14:25:57 +0900798 if (!IS_ERR(clk)) {
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000799 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
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000817#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 */
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000835 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 */
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000910 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 */
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +0000915
Magnus Damm2b7eda62010-02-05 11:14:58 +0000916 sh7372_add_standard_devices();
917
918 platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
919}
920
Magnus Damm495b3ce2010-05-12 14:21:34 +0000921static void __init ap4evb_timer_init(void)
922{
923 sh7372_clock_init();
924 shmobile_timer.init();
925}
926
927static struct sys_timer ap4evb_timer = {
928 .init = ap4evb_timer_init,
929};
930
Magnus Damm2b7eda62010-02-05 11:14:58 +0000931MACHINE_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,
Magnus Damm495b3ce2010-05-12 14:21:34 +0000937 .timer = &ap4evb_timer,
Magnus Damm2b7eda62010-02-05 11:14:58 +0000938MACHINE_END