blob: c9aad5eefcccfad60a642cada4f911a984a25658 [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>
Arnd Hannemann410d8782010-08-18 16:24:13 +000027#include <linux/mfd/tmio.h>
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +000028#include <linux/mmc/host.h>
Guennadi Liakhovetski17e75d82011-03-09 11:27:56 +010029#include <linux/mmc/sh_mobile_sdhi.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000030#include <linux/mtd/mtd.h>
31#include <linux/mtd/partitions.h>
32#include <linux/mtd/physmap.h>
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +000033#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>
Arnd Hannemann2863e932010-08-14 19:45:21 +000042#include <linux/leds.h>
Kuninori Morimoto17ccb832010-02-23 07:07:01 +000043#include <linux/input/sh_keysc.h>
Kuninori Morimotofb54d262010-04-13 06:16:32 +000044#include <linux/usb/r8a66597.h>
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +000045
Guennadi Liakhovetski1a0b1ea2010-10-20 15:15:49 +020046#include <media/sh_mobile_ceu.h>
47#include <media/sh_mobile_csi2.h>
48#include <media/soc_camera.h>
49
Kuninori Morimotocb9215e2010-05-24 06:50:44 +000050#include <sound/sh_fsi.h>
51
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +000052#include <video/sh_mobile_hdmi.h>
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +000053#include <video/sh_mobile_lcdc.h>
54#include <video/sh_mipi_dsi.h>
55
Magnus Damm2b7eda62010-02-05 11:14:58 +000056#include <mach/common.h>
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +000057#include <mach/irqs.h>
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +000058#include <mach/sh7372.h>
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +000059
Magnus Damm2b7eda62010-02-05 11:14:58 +000060#include <asm/mach-types.h>
61#include <asm/mach/arch.h>
62#include <asm/mach/map.h>
Magnus Damm495b3ce2010-05-12 14:21:34 +000063#include <asm/mach/time.h>
Kuninori Morimoto3d09fbc2010-12-01 07:40:16 +010064#include <asm/setup.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000065
Kuninori Morimoto02624a12010-02-18 17:58:19 +090066/*
67 * Address Interface BusWidth note
68 * ------------------------------------------------------------------
69 * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
70 * 0x0800_0000 user area -
71 * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
72 * 0x1400_0000 Ether (LAN9220) 16bit
73 * 0x1600_0000 user area - cannot use with NAND
74 * 0x1800_0000 user area -
75 * 0x1A00_0000 -
76 * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
77 */
78
79/*
80 * NOR Flash ROM
81 *
82 * SW1 | SW2 | SW7 | NOR Flash ROM
83 * bit1 | bit1 bit2 | bit1 | Memory allocation
84 * ------+------------+------+------------------
85 * OFF | ON OFF | ON | Area 0
86 * OFF | ON OFF | OFF | Area 4
87 */
88
89/*
90 * NAND Flash ROM
91 *
92 * SW1 | SW2 | SW7 | NAND Flash ROM
93 * bit1 | bit1 bit2 | bit2 | Memory allocation
94 * ------+------------+------+------------------
95 * OFF | ON OFF | ON | FCE 0
96 * OFF | ON OFF | OFF | FCE 1
97 */
98
99/*
100 * SMSC 9220
101 *
102 * SW1 SMSC 9220
103 * -----------------------
104 * ON access disable
105 * OFF access enable
106 */
107
Kuninori Morimoto17ccb832010-02-23 07:07:01 +0000108/*
Kuninori Morimotodda128d2010-03-12 10:07:55 +0000109 * LCD / IRQ / KEYSC / IrDA
Kuninori Morimoto17ccb832010-02-23 07:07:01 +0000110 *
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000111 * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (QHD-TouchScreen)
112 * LCD = 2nd LCDC (WVGA)
Kuninori Morimotodda128d2010-03-12 10:07:55 +0000113 *
114 * | SW43 |
115 * SW3 | ON | OFF |
116 * -------------+-----------------------+---------------+
117 * ON | KEY / IrDA | LCD |
118 * OFF | KEY / IrDA / IRQ | IRQ |
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000119 *
120 *
121 * QHD / WVGA display
122 *
123 * You can choice display type on menuconfig.
124 * Then, check above dip-switch.
Kuninori Morimoto17ccb832010-02-23 07:07:01 +0000125 */
126
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000127/*
128 * USB
129 *
130 * J7 : 1-2 MAX3355E VBUS
131 * 2-3 DC 5.0V
132 *
133 * S39: bit2: off
134 */
135
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000136/*
137 * FSI/FSMI
138 *
139 * SW41 : ON : SH-Mobile AP4 Audio Mode
140 * : OFF : Bluetooth Audio Mode
141 */
142
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000143/*
Kuninori Morimotod3d03e42010-06-01 04:31:29 +0000144 * MMC0/SDHI1 (CN7)
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000145 *
Kuninori Morimotod3d03e42010-06-01 04:31:29 +0000146 * J22 : select card voltage
147 * 1-2 pin : 1.8v
148 * 2-3 pin : 3.3v
149 *
150 * SW1 | SW33
151 * | bit1 | bit2 | bit3 | bit4
152 * ------------+------+------+------+-------
153 * MMC0 OFF | OFF | ON | ON | X
154 * SDHI1 OFF | ON | X | OFF | ON
155 *
156 * voltage lebel
157 * CN7 : 1.8v
158 * CN12: 3.3v
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000159 */
160
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000161/* MTD */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000162static struct mtd_partition nor_flash_partitions[] = {
163 {
164 .name = "loader",
165 .offset = 0x00000000,
166 .size = 512 * 1024,
Yusuke Goda2e351ec2010-11-08 05:45:09 +0000167 .mask_flags = MTD_WRITEABLE,
Magnus Damm2b7eda62010-02-05 11:14:58 +0000168 },
169 {
170 .name = "bootenv",
171 .offset = MTDPART_OFS_APPEND,
172 .size = 512 * 1024,
Yusuke Goda2e351ec2010-11-08 05:45:09 +0000173 .mask_flags = MTD_WRITEABLE,
Magnus Damm2b7eda62010-02-05 11:14:58 +0000174 },
175 {
176 .name = "kernel_ro",
177 .offset = MTDPART_OFS_APPEND,
178 .size = 8 * 1024 * 1024,
179 .mask_flags = MTD_WRITEABLE,
180 },
181 {
182 .name = "kernel",
183 .offset = MTDPART_OFS_APPEND,
184 .size = 8 * 1024 * 1024,
185 },
186 {
187 .name = "data",
188 .offset = MTDPART_OFS_APPEND,
189 .size = MTDPART_SIZ_FULL,
190 },
191};
192
193static struct physmap_flash_data nor_flash_data = {
194 .width = 2,
195 .parts = nor_flash_partitions,
196 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
197};
198
199static struct resource nor_flash_resources[] = {
200 [0] = {
201 .start = 0x00000000,
202 .end = 0x08000000 - 1,
203 .flags = IORESOURCE_MEM,
204 }
205};
206
207static struct platform_device nor_flash_device = {
208 .name = "physmap-flash",
209 .dev = {
210 .platform_data = &nor_flash_data,
211 },
212 .num_resources = ARRAY_SIZE(nor_flash_resources),
213 .resource = nor_flash_resources,
214};
215
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000216/* SMSC 9220 */
217static struct resource smc911x_resources[] = {
218 {
219 .start = 0x14000000,
220 .end = 0x16000000 - 1,
221 .flags = IORESOURCE_MEM,
222 }, {
Magnus Damm33c96072010-05-20 14:41:00 +0000223 .start = evt2irq(0x02c0) /* IRQ6A */,
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000224 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
225 },
226};
227
228static struct smsc911x_platform_config smsc911x_info = {
229 .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
230 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
231 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
232};
233
234static struct platform_device smc911x_device = {
235 .name = "smsc911x",
236 .id = -1,
237 .num_resources = ARRAY_SIZE(smc911x_resources),
238 .resource = smc911x_resources,
239 .dev = {
240 .platform_data = &smsc911x_info,
241 },
242};
Magnus Damm2b7eda62010-02-05 11:14:58 +0000243
Arnd Hannemann68accd72010-09-10 18:54:20 +0200244/*
245 * The card detect pin of the top SD/MMC slot (CN7) is active low and is
246 * connected to GPIO A22 of SH7372 (GPIO_PORT41).
247 */
248static int slot_cn7_get_cd(struct platform_device *pdev)
249{
Magnus Dammceb50f32011-01-12 10:43:07 +0000250 return !gpio_get_value(GPIO_PORT41);
Arnd Hannemann68accd72010-09-10 18:54:20 +0200251}
Damian1c7fcbe2011-05-24 07:01:22 +0000252/* MERAM */
253static struct sh_mobile_meram_info meram_info = {
254 .addr_mode = SH_MOBILE_MERAM_MODE1,
255};
256
257static struct resource meram_resources[] = {
258 [0] = {
259 .name = "MERAM",
260 .start = 0xe8000000,
261 .end = 0xe81fffff,
262 .flags = IORESOURCE_MEM,
263 },
264};
265
266static struct platform_device meram_device = {
267 .name = "sh_mobile_meram",
268 .id = 0,
269 .num_resources = ARRAY_SIZE(meram_resources),
270 .resource = meram_resources,
271 .dev = {
272 .platform_data = &meram_info,
273 },
274};
Arnd Hannemann68accd72010-09-10 18:54:20 +0200275
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000276/* SH_MMCIF */
277static struct resource sh_mmcif_resources[] = {
278 [0] = {
Magnus Damm0fb08342010-10-13 07:39:18 +0000279 .name = "MMCIF",
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000280 .start = 0xE6BD0000,
281 .end = 0xE6BD00FF,
282 .flags = IORESOURCE_MEM,
283 },
284 [1] = {
285 /* MMC ERR */
Kuninori Morimoto8d569342010-06-01 02:40:05 +0000286 .start = evt2irq(0x1ac0),
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000287 .flags = IORESOURCE_IRQ,
288 },
289 [2] = {
290 /* MMC NOR */
Kuninori Morimoto8d569342010-06-01 02:40:05 +0000291 .start = evt2irq(0x1ae0),
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000292 .flags = IORESOURCE_IRQ,
293 },
294};
295
Guennadi Liakhovetskidf73af82010-11-24 10:05:26 +0000296static struct sh_mmcif_dma sh_mmcif_dma = {
297 .chan_priv_rx = {
298 .slave_id = SHDMA_SLAVE_MMCIF_RX,
299 },
300 .chan_priv_tx = {
301 .slave_id = SHDMA_SLAVE_MMCIF_TX,
302 },
303};
304
Kuninori Morimotobb04e192010-06-02 00:25:03 +0000305static struct sh_mmcif_plat_data sh_mmcif_plat = {
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000306 .sup_pclk = 0,
307 .ocr = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
308 .caps = MMC_CAP_4_BIT_DATA |
309 MMC_CAP_8_BIT_DATA |
310 MMC_CAP_NEEDS_POLL,
Arnd Hannemann68accd72010-09-10 18:54:20 +0200311 .get_cd = slot_cn7_get_cd,
Guennadi Liakhovetskidf73af82010-11-24 10:05:26 +0000312 .dma = &sh_mmcif_dma,
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +0000313};
314
315static struct platform_device sh_mmcif_device = {
316 .name = "sh_mmcif",
317 .id = 0,
318 .dev = {
319 .dma_mask = NULL,
320 .coherent_dma_mask = 0xffffffff,
321 .platform_data = &sh_mmcif_plat,
322 },
323 .num_resources = ARRAY_SIZE(sh_mmcif_resources),
324 .resource = sh_mmcif_resources,
325};
326
Magnus Damm3a14d032010-03-10 09:26:44 +0000327/* SDHI0 */
Guennadi Liakhovetski69bf6f42010-05-04 14:07:15 +0000328static struct sh_mobile_sdhi_info sdhi0_info = {
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +0000329 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
330 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
Arnd Hannemann330e4e72010-12-28 22:22:33 +0000331 .tmio_caps = MMC_CAP_SDIO_IRQ,
Guennadi Liakhovetski69bf6f42010-05-04 14:07:15 +0000332};
333
Magnus Damm3a14d032010-03-10 09:26:44 +0000334static struct resource sdhi0_resources[] = {
335 [0] = {
336 .name = "SDHI0",
337 .start = 0xe6850000,
Guennadi Liakhovetski31d31fe72011-03-09 13:09:27 +0100338 .end = 0xe68500ff,
Magnus Damm3a14d032010-03-10 09:26:44 +0000339 .flags = IORESOURCE_MEM,
340 },
341 [1] = {
Magnus Damm33c96072010-05-20 14:41:00 +0000342 .start = evt2irq(0x0e00) /* SDHI0 */,
Magnus Damm3a14d032010-03-10 09:26:44 +0000343 .flags = IORESOURCE_IRQ,
344 },
345};
346
347static struct platform_device sdhi0_device = {
348 .name = "sh_mobile_sdhi",
349 .num_resources = ARRAY_SIZE(sdhi0_resources),
350 .resource = sdhi0_resources,
351 .id = 0,
Guennadi Liakhovetski69bf6f42010-05-04 14:07:15 +0000352 .dev = {
353 .platform_data = &sdhi0_info,
354 },
Magnus Damm3a14d032010-03-10 09:26:44 +0000355};
356
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +0000357/* SDHI1 */
358static struct sh_mobile_sdhi_info sdhi1_info = {
359 .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
360 .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
361 .tmio_ocr_mask = MMC_VDD_165_195,
Arnd Hannemann410d8782010-08-18 16:24:13 +0000362 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE,
Arnd Hannemann330e4e72010-12-28 22:22:33 +0000363 .tmio_caps = MMC_CAP_NEEDS_POLL | MMC_CAP_SDIO_IRQ,
Arnd Hannemann68accd72010-09-10 18:54:20 +0200364 .get_cd = slot_cn7_get_cd,
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +0000365};
366
367static struct resource sdhi1_resources[] = {
368 [0] = {
369 .name = "SDHI1",
370 .start = 0xe6860000,
Guennadi Liakhovetski31d31fe72011-03-09 13:09:27 +0100371 .end = 0xe68600ff,
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +0000372 .flags = IORESOURCE_MEM,
373 },
374 [1] = {
375 .start = evt2irq(0x0e80),
376 .flags = IORESOURCE_IRQ,
377 },
378};
379
380static struct platform_device sdhi1_device = {
381 .name = "sh_mobile_sdhi",
382 .num_resources = ARRAY_SIZE(sdhi1_resources),
383 .resource = sdhi1_resources,
384 .id = 1,
385 .dev = {
386 .platform_data = &sdhi1_info,
387 },
388};
389
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000390/* USB1 */
Kuninori Morimotobb04e192010-06-02 00:25:03 +0000391static void usb1_host_port_power(int port, int power)
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000392{
393 if (!power) /* only power-on supported for now */
394 return;
395
396 /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
397 __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
398}
399
400static struct r8a66597_platdata usb1_host_data = {
401 .on_chip = 1,
402 .port_power = usb1_host_port_power,
403};
404
405static struct resource usb1_host_resources[] = {
406 [0] = {
407 .name = "USBHS",
408 .start = 0xE68B0000,
409 .end = 0xE68B00E6 - 1,
410 .flags = IORESOURCE_MEM,
411 },
412 [1] = {
Magnus Damm33c96072010-05-20 14:41:00 +0000413 .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000414 .flags = IORESOURCE_IRQ,
415 },
416};
417
418static struct platform_device usb1_host_device = {
419 .name = "r8a66597_hcd",
420 .id = 1,
421 .dev = {
422 .dma_mask = NULL, /* not use dma */
423 .coherent_dma_mask = 0xffffffff,
424 .platform_data = &usb1_host_data,
425 },
426 .num_resources = ARRAY_SIZE(usb1_host_resources),
427 .resource = usb1_host_resources,
428};
429
Guennadi Liakhovetski44432402010-09-03 07:20:04 +0000430const static struct fb_videomode ap4evb_lcdc_modes[] = {
431 {
432#ifdef CONFIG_AP4EVB_QHD
433 .name = "R63302(QHD)",
434 .xres = 544,
435 .yres = 961,
436 .left_margin = 72,
437 .right_margin = 600,
438 .hsync_len = 16,
439 .upper_margin = 8,
440 .lower_margin = 8,
441 .vsync_len = 2,
442 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
443#else
444 .name = "WVGA Panel",
445 .xres = 800,
446 .yres = 480,
447 .left_margin = 220,
448 .right_margin = 110,
449 .hsync_len = 70,
450 .upper_margin = 20,
451 .lower_margin = 5,
452 .vsync_len = 5,
453 .sync = 0,
454#endif
455 },
456};
Damian1c7fcbe2011-05-24 07:01:22 +0000457static struct sh_mobile_meram_cfg lcd_meram_cfg = {
458 .icb[0] = {
459 .marker_icb = 28,
460 .cache_icb = 24,
461 .meram_offset = 0x0,
462 .meram_size = 0x40,
463 },
464 .icb[1] = {
465 .marker_icb = 29,
466 .cache_icb = 25,
467 .meram_offset = 0x40,
468 .meram_size = 0x40,
469 },
470};
Guennadi Liakhovetski44432402010-09-03 07:20:04 +0000471
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000472static struct sh_mobile_lcdc_info lcdc_info = {
Damian1c7fcbe2011-05-24 07:01:22 +0000473 .meram_dev = &meram_info,
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000474 .ch[0] = {
475 .chan = LCDC_CHAN_MAINLCD,
476 .bpp = 16,
Guennadi Liakhovetski44432402010-09-03 07:20:04 +0000477 .lcd_cfg = ap4evb_lcdc_modes,
478 .num_cfg = ARRAY_SIZE(ap4evb_lcdc_modes),
Damian1c7fcbe2011-05-24 07:01:22 +0000479 .meram_cfg = &lcd_meram_cfg,
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000480 }
481};
482
483static struct resource lcdc_resources[] = {
484 [0] = {
485 .name = "LCDC",
486 .start = 0xfe940000, /* P4-only space */
487 .end = 0xfe943fff,
488 .flags = IORESOURCE_MEM,
489 },
490 [1] = {
491 .start = intcs_evt2irq(0x580),
492 .flags = IORESOURCE_IRQ,
493 },
494};
495
496static struct platform_device lcdc_device = {
497 .name = "sh_mobile_lcdc_fb",
498 .num_resources = ARRAY_SIZE(lcdc_resources),
499 .resource = lcdc_resources,
500 .dev = {
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000501 .platform_data = &lcdc_info,
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000502 .coherent_dma_mask = ~0,
503 },
504};
505
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000506/*
507 * QHD display
508 */
509#ifdef CONFIG_AP4EVB_QHD
510
511/* KEYSC (Needs SW43 set to ON) */
512static struct sh_keysc_info keysc_info = {
513 .mode = SH_KEYSC_MODE_1,
514 .scan_timing = 3,
515 .delay = 2500,
516 .keycodes = {
517 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
518 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
519 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
520 KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
521 KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
522 },
523};
524
525static struct resource keysc_resources[] = {
526 [0] = {
527 .name = "KEYSC",
528 .start = 0xe61b0000,
529 .end = 0xe61b0063,
530 .flags = IORESOURCE_MEM,
531 },
532 [1] = {
533 .start = evt2irq(0x0be0), /* KEYSC_KEY */
534 .flags = IORESOURCE_IRQ,
535 },
536};
537
538static struct platform_device keysc_device = {
539 .name = "sh_keysc",
540 .id = 0, /* "keysc0" clock */
541 .num_resources = ARRAY_SIZE(keysc_resources),
542 .resource = keysc_resources,
543 .dev = {
544 .platform_data = &keysc_info,
545 },
546};
547
548/* MIPI-DSI */
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000549static struct resource mipidsi0_resources[] = {
550 [0] = {
551 .start = 0xffc60000,
Magnus Damm5958d582010-11-17 06:44:35 +0000552 .end = 0xffc63073,
553 .flags = IORESOURCE_MEM,
554 },
555 [1] = {
556 .start = 0xffc68000,
557 .end = 0xffc680ef,
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000558 .flags = IORESOURCE_MEM,
559 },
560};
561
562static struct sh_mipi_dsi_info mipidsi0_info = {
563 .data_format = MIPI_RGB888,
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000564 .lcd_chan = &lcdc_info.ch[0],
Guennadi Liakhovetski6fd46592010-12-29 08:12:26 +0000565 .vsynw_offset = 17,
Guennadi Liakhovetski8eda2f22010-05-23 14:04:03 +0000566};
567
568static struct platform_device mipidsi0_device = {
569 .name = "sh-mipi-dsi",
570 .num_resources = ARRAY_SIZE(mipidsi0_resources),
571 .resource = mipidsi0_resources,
572 .id = 0,
573 .dev = {
574 .platform_data = &mipidsi0_info,
575 },
576};
577
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +0000578static struct platform_device *qhd_devices[] __initdata = {
579 &mipidsi0_device,
580 &keysc_device,
581};
582#endif /* CONFIG_AP4EVB_QHD */
583
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000584/* FSI */
585#define IRQ_FSI evt2irq(0x1840)
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000586static int __fsi_set_rate(struct clk *clk, long rate, int enable)
587{
588 int ret = 0;
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400589
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000590 if (rate <= 0)
591 return ret;
592
593 if (enable) {
Kuninori Morimoto22de4e12010-11-19 07:23:17 +0000594 ret = clk_set_rate(clk, rate);
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000595 if (0 == ret)
596 ret = clk_enable(clk);
597 } else {
598 clk_disable(clk);
599 }
600
601 return ret;
602}
603
Kuninori Morimoto22de4e12010-11-19 07:23:17 +0000604static int __fsi_set_round_rate(struct clk *clk, long rate, int enable)
605{
606 return __fsi_set_rate(clk, clk_round_rate(clk, rate), enable);
607}
608
609static int fsi_ak4642_set_rate(struct device *dev, int rate, int enable)
610{
611 struct clk *fsia_ick;
612 struct clk *fsiack;
613 int ret = -EIO;
614
615 fsia_ick = clk_get(dev, "icka");
616 if (IS_ERR(fsia_ick))
617 return PTR_ERR(fsia_ick);
618
619 /*
620 * FSIACK is connected to AK4642,
621 * and use external clock pin from it.
622 * it is parent of fsia_ick now.
623 */
624 fsiack = clk_get_parent(fsia_ick);
625 if (!fsiack)
626 goto fsia_ick_out;
627
628 /*
629 * we get 1/1 divided clock by setting same rate to fsiack and fsia_ick
630 *
631 ** FIXME **
632 * Because the freq_table of external clk (fsiack) are all 0,
633 * the return value of clk_round_rate became 0.
634 * So, it use __fsi_set_rate here.
635 */
636 ret = __fsi_set_rate(fsiack, rate, enable);
637 if (ret < 0)
638 goto fsiack_out;
639
640 ret = __fsi_set_round_rate(fsia_ick, rate, enable);
641 if ((ret < 0) && enable)
642 __fsi_set_round_rate(fsiack, rate, 0); /* disable FSI ACK */
643
644fsiack_out:
645 clk_put(fsiack);
646
647fsia_ick_out:
648 clk_put(fsia_ick);
649
650 return 0;
651}
652
653static int fsi_hdmi_set_rate(struct device *dev, int rate, int enable)
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400654{
655 struct clk *fsib_clk;
656 struct clk *fdiv_clk = &sh7372_fsidivb_clk;
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000657 long fsib_rate = 0;
658 long fdiv_rate = 0;
659 int ackmd_bpfmd;
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400660 int ret;
661
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400662 switch (rate) {
Kuninori Morimoto574490e2010-11-15 03:11:09 +0000663 case 44100:
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000664 fsib_rate = rate * 256;
665 ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
Kuninori Morimoto574490e2010-11-15 03:11:09 +0000666 break;
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400667 case 48000:
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000668 fsib_rate = 85428000; /* around 48kHz x 256 x 7 */
669 fdiv_rate = rate * 256;
670 ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400671 break;
672 default:
673 pr_err("unsupported rate in FSI2 port B\n");
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000674 return -EINVAL;
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400675 }
676
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000677 /* FSI B setting */
678 fsib_clk = clk_get(dev, "ickb");
679 if (IS_ERR(fsib_clk))
680 return -EIO;
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400681
Kuninori Morimoto22de4e12010-11-19 07:23:17 +0000682 ret = __fsi_set_round_rate(fsib_clk, fsib_rate, enable);
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000683 if (ret < 0)
Kuninori Morimoto73674642011-01-06 02:43:00 +0000684 goto fsi_set_rate_end;
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000685
686 /* FSI DIV setting */
Kuninori Morimoto22de4e12010-11-19 07:23:17 +0000687 ret = __fsi_set_round_rate(fdiv_clk, fdiv_rate, enable);
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000688 if (ret < 0) {
689 /* disable FSI B */
690 if (enable)
Kuninori Morimoto22de4e12010-11-19 07:23:17 +0000691 __fsi_set_round_rate(fsib_clk, fsib_rate, 0);
Kuninori Morimoto73674642011-01-06 02:43:00 +0000692 goto fsi_set_rate_end;
Kuninori Morimotod4bc99b2010-11-24 02:44:06 +0000693 }
694
Kuninori Morimoto73674642011-01-06 02:43:00 +0000695 ret = ackmd_bpfmd;
696
697fsi_set_rate_end:
698 clk_put(fsib_clk);
699 return ret;
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400700}
701
Kuninori Morimoto22de4e12010-11-19 07:23:17 +0000702static int fsi_set_rate(struct device *dev, int is_porta, int rate, int enable)
703{
704 int ret;
705
706 if (is_porta)
707 ret = fsi_ak4642_set_rate(dev, rate, enable);
708 else
709 ret = fsi_hdmi_set_rate(dev, rate, enable);
710
711 return ret;
712}
713
Kuninori Morimotobb04e192010-06-02 00:25:03 +0000714static struct sh_fsi_platform_info fsi_info = {
Kuninori Morimotof17c13c2011-01-24 10:43:19 +0900715 .porta_flags = SH_FSI_BRS_INV,
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400716
717 .portb_flags = SH_FSI_BRS_INV |
718 SH_FSI_BRM_INV |
719 SH_FSI_LRS_INV |
Kuninori Morimotof17c13c2011-01-24 10:43:19 +0900720 SH_FSI_FMT_SPDIF,
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400721 .set_rate = fsi_set_rate,
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000722};
723
724static struct resource fsi_resources[] = {
725 [0] = {
726 .name = "FSI",
727 .start = 0xFE3C0000,
728 .end = 0xFE3C0400 - 1,
729 .flags = IORESOURCE_MEM,
730 },
731 [1] = {
732 .start = IRQ_FSI,
733 .flags = IORESOURCE_IRQ,
734 },
735};
736
737static struct platform_device fsi_device = {
738 .name = "sh_fsi2",
Kuninori Morimoto9f6f11b2010-08-18 03:37:19 +0000739 .id = -1,
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000740 .num_resources = ARRAY_SIZE(fsi_resources),
741 .resource = fsi_resources,
742 .dev = {
743 .platform_data = &fsi_info,
744 },
745};
746
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900747static struct platform_device fsi_ak4643_device = {
748 .name = "sh_fsi2_a_ak4643",
749};
Damian1c7fcbe2011-05-24 07:01:22 +0000750static struct sh_mobile_meram_cfg hdmi_meram_cfg = {
751 .icb[0] = {
752 .marker_icb = 30,
753 .cache_icb = 26,
754 .meram_offset = 0x80,
755 .meram_size = 0x100,
756 },
757 .icb[1] = {
758 .marker_icb = 31,
759 .cache_icb = 27,
760 .meram_offset = 0x180,
761 .meram_size = 0x100,
762 },
763};
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900764
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +0000765static struct sh_mobile_lcdc_info sh_mobile_lcdc1_info = {
766 .clock_source = LCDC_CLK_EXTERNAL,
Damian1c7fcbe2011-05-24 07:01:22 +0000767 .meram_dev = &meram_info,
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +0000768 .ch[0] = {
769 .chan = LCDC_CHAN_MAINLCD,
770 .bpp = 16,
771 .interface_type = RGB24,
772 .clock_divider = 1,
773 .flags = LCDC_FLAGS_DWPOL,
Damian1c7fcbe2011-05-24 07:01:22 +0000774 .meram_cfg = &hdmi_meram_cfg,
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +0000775 }
776};
777
778static struct resource lcdc1_resources[] = {
779 [0] = {
780 .name = "LCDC1",
781 .start = 0xfe944000,
782 .end = 0xfe947fff,
783 .flags = IORESOURCE_MEM,
784 },
785 [1] = {
TAKEI Mitsuharu88c759a2010-10-20 11:53:17 +0900786 .start = intcs_evt2irq(0x1780),
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +0000787 .flags = IORESOURCE_IRQ,
788 },
789};
790
791static struct platform_device lcdc1_device = {
792 .name = "sh_mobile_lcdc_fb",
793 .num_resources = ARRAY_SIZE(lcdc1_resources),
794 .resource = lcdc1_resources,
795 .id = 1,
796 .dev = {
797 .platform_data = &sh_mobile_lcdc1_info,
798 .coherent_dma_mask = ~0,
799 },
800};
801
Guennadi Liakhovetski640dcfa2010-11-02 11:27:34 +0000802static long ap4evb_clk_optimize(unsigned long target, unsigned long *best_freq,
803 unsigned long *parent_freq);
804
805
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +0000806static struct sh_mobile_hdmi_info hdmi_info = {
807 .lcd_chan = &sh_mobile_lcdc1_info.ch[0],
808 .lcd_dev = &lcdc1_device.dev,
Kuninori Morimoto2669efe2010-10-31 10:43:14 -0400809 .flags = HDMI_SND_SRC_SPDIF,
Guennadi Liakhovetski640dcfa2010-11-02 11:27:34 +0000810 .clk_optimize_parent = ap4evb_clk_optimize,
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +0000811};
812
813static struct resource hdmi_resources[] = {
814 [0] = {
815 .name = "HDMI",
816 .start = 0xe6be0000,
817 .end = 0xe6be00ff,
818 .flags = IORESOURCE_MEM,
819 },
820 [1] = {
821 /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
822 .start = evt2irq(0x17e0),
823 .flags = IORESOURCE_IRQ,
824 },
825};
826
827static struct platform_device hdmi_device = {
828 .name = "sh-mobile-hdmi",
829 .num_resources = ARRAY_SIZE(hdmi_resources),
830 .resource = hdmi_resources,
831 .id = -1,
832 .dev = {
833 .platform_data = &hdmi_info,
834 },
835};
836
Kuninori Morimoto3f25c9c2011-01-24 10:09:02 +0900837static struct platform_device fsi_hdmi_device = {
838 .name = "sh_fsi2_b_hdmi",
839};
840
Guennadi Liakhovetski640dcfa2010-11-02 11:27:34 +0000841static long ap4evb_clk_optimize(unsigned long target, unsigned long *best_freq,
842 unsigned long *parent_freq)
843{
844 struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
845 long error;
846
847 if (IS_ERR(hdmi_ick)) {
848 int ret = PTR_ERR(hdmi_ick);
849 pr_err("Cannot get HDMI ICK: %d\n", ret);
850 return ret;
851 }
852
853 error = clk_round_parent(hdmi_ick, target, best_freq, parent_freq, 1, 64);
854
855 clk_put(hdmi_ick);
856
857 return error;
858}
859
Arnd Hannemann2863e932010-08-14 19:45:21 +0000860static struct gpio_led ap4evb_leds[] = {
861 {
862 .name = "led4",
863 .gpio = GPIO_PORT185,
864 .default_state = LEDS_GPIO_DEFSTATE_ON,
865 },
866 {
867 .name = "led2",
868 .gpio = GPIO_PORT186,
869 .default_state = LEDS_GPIO_DEFSTATE_ON,
870 },
871 {
872 .name = "led3",
873 .gpio = GPIO_PORT187,
874 .default_state = LEDS_GPIO_DEFSTATE_ON,
875 },
876 {
877 .name = "led1",
878 .gpio = GPIO_PORT188,
879 .default_state = LEDS_GPIO_DEFSTATE_ON,
880 }
881};
882
883static struct gpio_led_platform_data ap4evb_leds_pdata = {
884 .num_leds = ARRAY_SIZE(ap4evb_leds),
Paul Mundt8050fbf2010-08-16 14:54:35 +0900885 .leds = ap4evb_leds,
Arnd Hannemann2863e932010-08-14 19:45:21 +0000886};
887
888static struct platform_device leds_device = {
889 .name = "leds-gpio",
890 .id = 0,
891 .dev = {
892 .platform_data = &ap4evb_leds_pdata,
893 },
894};
895
Guennadi Liakhovetski1a0b1ea2010-10-20 15:15:49 +0200896static struct i2c_board_info imx074_info = {
897 I2C_BOARD_INFO("imx074", 0x1a),
898};
899
900struct soc_camera_link imx074_link = {
901 .bus_id = 0,
902 .board_info = &imx074_info,
903 .i2c_adapter_id = 0,
904 .module_name = "imx074",
905};
906
907static struct platform_device ap4evb_camera = {
908 .name = "soc-camera-pdrv",
909 .id = 0,
910 .dev = {
911 .platform_data = &imx074_link,
912 },
913};
914
915static struct sh_csi2_client_config csi2_clients[] = {
916 {
917 .phy = SH_CSI2_PHY_MAIN,
918 .lanes = 3,
919 .channel = 0,
920 .pdev = &ap4evb_camera,
921 },
922};
923
924static struct sh_csi2_pdata csi2_info = {
925 .type = SH_CSI2C,
926 .clients = csi2_clients,
927 .num_clients = ARRAY_SIZE(csi2_clients),
928 .flags = SH_CSI2_ECC | SH_CSI2_CRC,
929};
930
931static struct resource csi2_resources[] = {
932 [0] = {
933 .name = "CSI2",
934 .start = 0xffc90000,
935 .end = 0xffc90fff,
936 .flags = IORESOURCE_MEM,
937 },
938 [1] = {
939 .start = intcs_evt2irq(0x17a0),
940 .flags = IORESOURCE_IRQ,
941 },
942};
943
944static struct platform_device csi2_device = {
945 .name = "sh-mobile-csi2",
946 .id = 0,
947 .num_resources = ARRAY_SIZE(csi2_resources),
948 .resource = csi2_resources,
949 .dev = {
950 .platform_data = &csi2_info,
951 },
952};
953
954static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
955 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
956 .csi2_dev = &csi2_device.dev,
957};
958
959static struct resource ceu_resources[] = {
960 [0] = {
961 .name = "CEU",
962 .start = 0xfe910000,
963 .end = 0xfe91009f,
964 .flags = IORESOURCE_MEM,
965 },
966 [1] = {
967 .start = intcs_evt2irq(0x880),
968 .flags = IORESOURCE_IRQ,
969 },
970 [2] = {
971 /* place holder for contiguous memory */
972 },
973};
974
975static struct platform_device ceu_device = {
976 .name = "sh_mobile_ceu",
977 .id = 0, /* "ceu0" clock */
978 .num_resources = ARRAY_SIZE(ceu_resources),
979 .resource = ceu_resources,
980 .dev = {
Guennadi Liakhovetski05a5f012011-03-23 09:29:16 +0000981 .platform_data = &sh_mobile_ceu_info,
982 .coherent_dma_mask = 0xffffffff,
Guennadi Liakhovetski1a0b1ea2010-10-20 15:15:49 +0200983 },
984};
985
Magnus Damm2b7eda62010-02-05 11:14:58 +0000986static struct platform_device *ap4evb_devices[] __initdata = {
Arnd Hannemann2863e932010-08-14 19:45:21 +0000987 &leds_device,
Magnus Damm2b7eda62010-02-05 11:14:58 +0000988 &nor_flash_device,
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000989 &smc911x_device,
Magnus Damm3a14d032010-03-10 09:26:44 +0000990 &sdhi0_device,
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +0000991 &sdhi1_device,
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000992 &usb1_host_device,
Kuninori Morimotocb9215e2010-05-24 06:50:44 +0000993 &fsi_device,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900994 &fsi_ak4643_device,
Kuninori Morimoto3f25c9c2011-01-24 10:09:02 +0900995 &fsi_hdmi_device,
Paul Mundtbeccb122010-08-04 16:47:37 +0900996 &sh_mmcif_device,
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +0000997 &lcdc1_device,
998 &lcdc_device,
999 &hdmi_device,
Guennadi Liakhovetski1a0b1ea2010-10-20 15:15:49 +02001000 &csi2_device,
1001 &ceu_device,
1002 &ap4evb_camera,
Damian1c7fcbe2011-05-24 07:01:22 +00001003 &meram_device,
Magnus Damm2b7eda62010-02-05 11:14:58 +00001004};
1005
Guennadi Liakhovetski2ce51f82011-04-04 17:08:05 +02001006static void __init hdmi_init_pm_clock(void)
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001007{
1008 struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
1009 int ret;
1010 long rate;
1011
1012 if (IS_ERR(hdmi_ick)) {
1013 ret = PTR_ERR(hdmi_ick);
1014 pr_err("Cannot get HDMI ICK: %d\n", ret);
1015 goto out;
1016 }
1017
Kuninori Morimoto685e4082010-10-15 05:14:54 +00001018 ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001019 if (ret < 0) {
Kuninori Morimoto685e4082010-10-15 05:14:54 +00001020 pr_err("Cannot set PLLC2 parent: %d, %d users\n", ret, sh7372_pllc2_clk.usecount);
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001021 goto out;
1022 }
1023
Kuninori Morimoto685e4082010-10-15 05:14:54 +00001024 pr_debug("PLLC2 initial frequency %lu\n", clk_get_rate(&sh7372_pllc2_clk));
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001025
Kuninori Morimoto685e4082010-10-15 05:14:54 +00001026 rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001027 if (rate < 0) {
1028 pr_err("Cannot get suitable rate: %ld\n", rate);
1029 ret = rate;
1030 goto out;
1031 }
1032
Kuninori Morimoto685e4082010-10-15 05:14:54 +00001033 ret = clk_set_rate(&sh7372_pllc2_clk, rate);
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001034 if (ret < 0) {
1035 pr_err("Cannot set rate %ld: %d\n", rate, ret);
1036 goto out;
1037 }
1038
Kuninori Morimoto421b4462010-11-19 07:23:52 +00001039 ret = clk_enable(&sh7372_pllc2_clk);
1040 if (ret < 0) {
1041 pr_err("Cannot enable pllc2 clock\n");
1042 goto out;
1043 }
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001044 pr_debug("PLLC2 set frequency %lu\n", rate);
1045
Kuninori Morimoto685e4082010-10-15 05:14:54 +00001046 ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
Guennadi Liakhovetski2ce51f82011-04-04 17:08:05 +02001047 if (ret < 0)
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001048 pr_err("Cannot set HDMI parent: %d\n", ret);
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001049
1050out:
1051 if (!IS_ERR(hdmi_ick))
1052 clk_put(hdmi_ick);
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001053}
1054
Kuninori Morimoto6084c812011-04-05 01:22:33 +00001055static void __init fsi_init_pm_clock(void)
Kuninori Morimoto69ce8aa2010-10-15 05:15:05 +00001056{
1057 struct clk *fsia_ick;
1058 int ret;
1059
Kuninori Morimoto69ce8aa2010-10-15 05:15:05 +00001060 fsia_ick = clk_get(&fsi_device.dev, "icka");
1061 if (IS_ERR(fsia_ick)) {
1062 ret = PTR_ERR(fsia_ick);
1063 pr_err("Cannot get FSI ICK: %d\n", ret);
Kuninori Morimoto6084c812011-04-05 01:22:33 +00001064 return;
Kuninori Morimoto69ce8aa2010-10-15 05:15:05 +00001065 }
1066
1067 ret = clk_set_parent(fsia_ick, &sh7372_fsiack_clk);
Kuninori Morimoto69ce8aa2010-10-15 05:15:05 +00001068 if (ret < 0)
Kuninori Morimoto22de4e12010-11-19 07:23:17 +00001069 pr_err("Cannot set FSI-A parent: %d\n", ret);
Kuninori Morimoto69ce8aa2010-10-15 05:15:05 +00001070
Kuninori Morimoto69ce8aa2010-10-15 05:15:05 +00001071 clk_put(fsia_ick);
Kuninori Morimoto69ce8aa2010-10-15 05:15:05 +00001072}
Kuninori Morimoto69ce8aa2010-10-15 05:15:05 +00001073
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001074/*
1075 * FIXME !!
1076 *
1077 * gpio_no_direction
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001078 * are quick_hack.
1079 *
1080 * current gpio frame work doesn't have
1081 * the method to control only pull up/down/free.
1082 * this function should be replaced by correct gpio function
1083 */
1084static void __init gpio_no_direction(u32 addr)
1085{
1086 __raw_writeb(0x00, addr);
1087}
1088
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001089/* TouchScreen */
Kuninori Morimoto52d5ac02010-09-14 17:28:55 +09001090#ifdef CONFIG_AP4EVB_QHD
1091# define GPIO_TSC_IRQ GPIO_FN_IRQ28_123
1092# define GPIO_TSC_PORT GPIO_PORT123
1093#else /* WVGA */
1094# define GPIO_TSC_IRQ GPIO_FN_IRQ7_40
1095# define GPIO_TSC_PORT GPIO_PORT40
1096#endif
1097
Magnus Damm33c96072010-05-20 14:41:00 +00001098#define IRQ28 evt2irq(0x3380) /* IRQ28A */
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001099#define IRQ7 evt2irq(0x02e0) /* IRQ7A */
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001100static int ts_get_pendown_state(void)
1101{
Kuninori Morimoto52d5ac02010-09-14 17:28:55 +09001102 int val;
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001103
Kuninori Morimoto52d5ac02010-09-14 17:28:55 +09001104 gpio_free(GPIO_TSC_IRQ);
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001105
Kuninori Morimoto52d5ac02010-09-14 17:28:55 +09001106 gpio_request(GPIO_TSC_PORT, NULL);
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001107
Kuninori Morimoto52d5ac02010-09-14 17:28:55 +09001108 gpio_direction_input(GPIO_TSC_PORT);
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001109
Kuninori Morimoto52d5ac02010-09-14 17:28:55 +09001110 val = gpio_get_value(GPIO_TSC_PORT);
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001111
Kuninori Morimoto52d5ac02010-09-14 17:28:55 +09001112 gpio_request(GPIO_TSC_IRQ, NULL);
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001113
Kuninori Morimoto52d5ac02010-09-14 17:28:55 +09001114 return !val;
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001115}
1116
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001117static int ts_init(void)
1118{
Kuninori Morimoto52d5ac02010-09-14 17:28:55 +09001119 gpio_request(GPIO_TSC_IRQ, NULL);
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001120
1121 return 0;
1122}
1123
Kuninori Morimotobb04e192010-06-02 00:25:03 +00001124static struct tsc2007_platform_data tsc2007_info = {
Kuninori Morimoto91cf5082010-03-11 10:42:52 +00001125 .model = 2007,
1126 .x_plate_ohms = 180,
Kuninori Morimoto71c3ba92010-07-14 07:01:16 +00001127 .get_pendown_state = ts_get_pendown_state,
1128 .init_platform_hw = ts_init,
Kuninori Morimoto91cf5082010-03-11 10:42:52 +00001129};
1130
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001131static struct i2c_board_info tsc_device = {
1132 I2C_BOARD_INFO("tsc2007", 0x48),
1133 .type = "tsc2007",
1134 .platform_data = &tsc2007_info,
1135 /*.irq is selected on ap4evb_init */
1136};
1137
Kuninori Morimoto91cf5082010-03-11 10:42:52 +00001138/* I2C */
Kuninori Morimotocb9215e2010-05-24 06:50:44 +00001139static struct i2c_board_info i2c0_devices[] = {
1140 {
1141 I2C_BOARD_INFO("ak4643", 0x13),
1142 },
1143};
1144
Kuninori Morimoto91cf5082010-03-11 10:42:52 +00001145static struct i2c_board_info i2c1_devices[] = {
1146 {
Kuninori Morimoto8fc883c2010-03-11 07:34:37 +00001147 I2C_BOARD_INFO("r2025sd", 0x32),
1148 },
Kuninori Morimoto91cf5082010-03-11 10:42:52 +00001149};
1150
Magnus Damm2b7eda62010-02-05 11:14:58 +00001151static struct map_desc ap4evb_io_desc[] __initdata = {
1152 /* create a 1:1 entity map for 0xe6xxxxxx
1153 * used by CPGA, INTC and PFC.
1154 */
1155 {
1156 .virtual = 0xe6000000,
1157 .pfn = __phys_to_pfn(0xe6000000),
1158 .length = 256 << 20,
1159 .type = MT_DEVICE_NONSHARED
1160 },
1161};
1162
1163static void __init ap4evb_map_io(void)
1164{
1165 iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
1166
Magnus Damm495b3ce2010-05-12 14:21:34 +00001167 /* setup early devices and console here as well */
Magnus Damm2b7eda62010-02-05 11:14:58 +00001168 sh7372_add_early_devices();
Magnus Damm4ae04ac2010-02-08 11:02:54 +00001169 shmobile_setup_console();
Magnus Damm2b7eda62010-02-05 11:14:58 +00001170}
1171
Kuninori Morimotocb9215e2010-05-24 06:50:44 +00001172#define GPIO_PORT9CR 0xE6051009
1173#define GPIO_PORT10CR 0xE605100A
Kuninori Morimoto2669efe2010-10-31 10:43:14 -04001174#define USCCR1 0xE6058144
Magnus Damm2b7eda62010-02-05 11:14:58 +00001175static void __init ap4evb_init(void)
1176{
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001177 u32 srcr4;
Kuninori Morimotocb9215e2010-05-24 06:50:44 +00001178 struct clk *clk;
1179
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +00001180 sh7372_pinmux_init();
1181
Kuninori Morimotob228b482010-02-18 16:44:41 +09001182 /* enable SCIFA0 */
1183 gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
1184 gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
1185
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +00001186 /* enable SMSC911X */
1187 gpio_request(GPIO_FN_CS5A, NULL);
1188 gpio_request(GPIO_FN_IRQ6_39, NULL);
1189
Kuninori Morimoto8cb3a2e2010-02-22 09:30:12 +00001190 /* enable Debug switch (S6) */
1191 gpio_request(GPIO_PORT32, NULL);
1192 gpio_request(GPIO_PORT33, NULL);
1193 gpio_request(GPIO_PORT34, NULL);
1194 gpio_request(GPIO_PORT35, NULL);
1195 gpio_direction_input(GPIO_PORT32);
1196 gpio_direction_input(GPIO_PORT33);
1197 gpio_direction_input(GPIO_PORT34);
1198 gpio_direction_input(GPIO_PORT35);
1199 gpio_export(GPIO_PORT32, 0);
1200 gpio_export(GPIO_PORT33, 0);
1201 gpio_export(GPIO_PORT34, 0);
1202 gpio_export(GPIO_PORT35, 0);
1203
Magnus Damm3a14d032010-03-10 09:26:44 +00001204 /* SDHI0 */
1205 gpio_request(GPIO_FN_SDHICD0, NULL);
1206 gpio_request(GPIO_FN_SDHIWP0, NULL);
1207 gpio_request(GPIO_FN_SDHICMD0, NULL);
1208 gpio_request(GPIO_FN_SDHICLK0, NULL);
1209 gpio_request(GPIO_FN_SDHID0_3, NULL);
1210 gpio_request(GPIO_FN_SDHID0_2, NULL);
1211 gpio_request(GPIO_FN_SDHID0_1, NULL);
1212 gpio_request(GPIO_FN_SDHID0_0, NULL);
1213
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001214 /* SDHI1 */
1215 gpio_request(GPIO_FN_SDHICMD1, NULL);
1216 gpio_request(GPIO_FN_SDHICLK1, NULL);
1217 gpio_request(GPIO_FN_SDHID1_3, NULL);
1218 gpio_request(GPIO_FN_SDHID1_2, NULL);
1219 gpio_request(GPIO_FN_SDHID1_1, NULL);
1220 gpio_request(GPIO_FN_SDHID1_0, NULL);
Kuninori Morimoto91cf5082010-03-11 10:42:52 +00001221
Kuninori Morimotoc8ee3d42010-05-13 01:08:21 +00001222 /* MMCIF */
1223 gpio_request(GPIO_FN_MMCD0_0, NULL);
1224 gpio_request(GPIO_FN_MMCD0_1, NULL);
1225 gpio_request(GPIO_FN_MMCD0_2, NULL);
1226 gpio_request(GPIO_FN_MMCD0_3, NULL);
1227 gpio_request(GPIO_FN_MMCD0_4, NULL);
1228 gpio_request(GPIO_FN_MMCD0_5, NULL);
1229 gpio_request(GPIO_FN_MMCD0_6, NULL);
1230 gpio_request(GPIO_FN_MMCD0_7, NULL);
1231 gpio_request(GPIO_FN_MMCCMD0, NULL);
1232 gpio_request(GPIO_FN_MMCCLK0, NULL);
1233
Kuninori Morimotofb54d262010-04-13 06:16:32 +00001234 /* USB enable */
1235 gpio_request(GPIO_FN_VBUS0_1, NULL);
1236 gpio_request(GPIO_FN_IDIN_1_18, NULL);
1237 gpio_request(GPIO_FN_PWEN_1_115, NULL);
1238 gpio_request(GPIO_FN_OVCN_1_114, NULL);
1239 gpio_request(GPIO_FN_EXTLP_1, NULL);
1240 gpio_request(GPIO_FN_OVCN2_1, NULL);
1241
1242 /* setup USB phy */
Kuninori Morimotod0fb0c42010-12-28 05:54:53 +00001243 __raw_writew(0x8a0a, 0xE6058130); /* USBCR4 */
Kuninori Morimotofb54d262010-04-13 06:16:32 +00001244
Kuninori Morimoto2669efe2010-10-31 10:43:14 -04001245 /* enable FSI2 port A (ak4643) */
Kuninori Morimotocb9215e2010-05-24 06:50:44 +00001246 gpio_request(GPIO_FN_FSIAIBT, NULL);
1247 gpio_request(GPIO_FN_FSIAILR, NULL);
1248 gpio_request(GPIO_FN_FSIAISLD, NULL);
1249 gpio_request(GPIO_FN_FSIAOSLD, NULL);
1250 gpio_request(GPIO_PORT161, NULL);
1251 gpio_direction_output(GPIO_PORT161, 0); /* slave */
1252
1253 gpio_request(GPIO_PORT9, NULL);
1254 gpio_request(GPIO_PORT10, NULL);
1255 gpio_no_direction(GPIO_PORT9CR); /* FSIAOBT needs no direction */
1256 gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
1257
Arnd Hannemann68accd72010-09-10 18:54:20 +02001258 /* card detect pin for MMC slot (CN7) */
1259 gpio_request(GPIO_PORT41, NULL);
1260 gpio_direction_input(GPIO_PORT41);
1261
Kuninori Morimoto2669efe2010-10-31 10:43:14 -04001262 /* setup FSI2 port B (HDMI) */
1263 gpio_request(GPIO_FN_FSIBCK, NULL);
1264 __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
1265
Kuninori Morimotocb9215e2010-05-24 06:50:44 +00001266 /* set SPU2 clock to 119.6 MHz */
1267 clk = clk_get(NULL, "spu_clk");
Paul Mundt2ae2b762010-05-31 14:25:57 +09001268 if (!IS_ERR(clk)) {
Kuninori Morimotocb9215e2010-05-24 06:50:44 +00001269 clk_set_rate(clk, clk_round_rate(clk, 119600000));
1270 clk_put(clk);
1271 }
1272
Kuninori Morimotocb9215e2010-05-24 06:50:44 +00001273 /*
1274 * set irq priority, to avoid sound chopping
1275 * when NFS rootfs is used
1276 * FSI(3) > SMSC911X(2)
1277 */
1278 intc_set_priority(IRQ_FSI, 3);
1279
1280 i2c_register_board_info(0, i2c0_devices,
1281 ARRAY_SIZE(i2c0_devices));
1282
1283 i2c_register_board_info(1, i2c1_devices,
1284 ARRAY_SIZE(i2c1_devices));
1285
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001286#ifdef CONFIG_AP4EVB_QHD
Magnus Dammdd8a61a2010-08-31 09:22:36 +00001287
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001288 /*
Magnus Dammdd8a61a2010-08-31 09:22:36 +00001289 * For QHD Panel (MIPI-DSI, CONFIG_AP4EVB_QHD=y) and
1290 * IRQ28 for Touch Panel, set dip switches S3, S43 as OFF, ON.
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001291 */
1292
1293 /* enable KEYSC */
1294 gpio_request(GPIO_FN_KEYOUT0, NULL);
1295 gpio_request(GPIO_FN_KEYOUT1, NULL);
1296 gpio_request(GPIO_FN_KEYOUT2, NULL);
1297 gpio_request(GPIO_FN_KEYOUT3, NULL);
1298 gpio_request(GPIO_FN_KEYOUT4, NULL);
1299 gpio_request(GPIO_FN_KEYIN0_136, NULL);
1300 gpio_request(GPIO_FN_KEYIN1_135, NULL);
1301 gpio_request(GPIO_FN_KEYIN2_134, NULL);
1302 gpio_request(GPIO_FN_KEYIN3_133, NULL);
1303 gpio_request(GPIO_FN_KEYIN4, NULL);
1304
1305 /* enable TouchScreen */
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001306 irq_set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001307
1308 tsc_device.irq = IRQ28;
1309 i2c_register_board_info(1, &tsc_device, 1);
1310
1311 /* LCDC0 */
1312 lcdc_info.clock_source = LCDC_CLK_PERIPHERAL;
1313 lcdc_info.ch[0].interface_type = RGB24;
1314 lcdc_info.ch[0].clock_divider = 1;
1315 lcdc_info.ch[0].flags = LCDC_FLAGS_DWPOL;
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001316 lcdc_info.ch[0].lcd_size_cfg.width = 44;
1317 lcdc_info.ch[0].lcd_size_cfg.height = 79;
1318
1319 platform_add_devices(qhd_devices, ARRAY_SIZE(qhd_devices));
1320
1321#else
1322 /*
Magnus Dammdd8a61a2010-08-31 09:22:36 +00001323 * For WVGA Panel (18-bit RGB, CONFIG_AP4EVB_WVGA=y) and
1324 * IRQ7 for Touch Panel, set dip switches S3, S43 to ON, OFF.
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001325 */
Magnus Dammdd8a61a2010-08-31 09:22:36 +00001326
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001327 gpio_request(GPIO_FN_LCDD17, NULL);
1328 gpio_request(GPIO_FN_LCDD16, NULL);
1329 gpio_request(GPIO_FN_LCDD15, NULL);
1330 gpio_request(GPIO_FN_LCDD14, NULL);
1331 gpio_request(GPIO_FN_LCDD13, NULL);
1332 gpio_request(GPIO_FN_LCDD12, NULL);
1333 gpio_request(GPIO_FN_LCDD11, NULL);
1334 gpio_request(GPIO_FN_LCDD10, NULL);
1335 gpio_request(GPIO_FN_LCDD9, NULL);
1336 gpio_request(GPIO_FN_LCDD8, NULL);
1337 gpio_request(GPIO_FN_LCDD7, NULL);
1338 gpio_request(GPIO_FN_LCDD6, NULL);
1339 gpio_request(GPIO_FN_LCDD5, NULL);
1340 gpio_request(GPIO_FN_LCDD4, NULL);
1341 gpio_request(GPIO_FN_LCDD3, NULL);
1342 gpio_request(GPIO_FN_LCDD2, NULL);
1343 gpio_request(GPIO_FN_LCDD1, NULL);
1344 gpio_request(GPIO_FN_LCDD0, NULL);
1345 gpio_request(GPIO_FN_LCDDISP, NULL);
1346 gpio_request(GPIO_FN_LCDDCK, NULL);
1347
1348 gpio_request(GPIO_PORT189, NULL); /* backlight */
1349 gpio_direction_output(GPIO_PORT189, 1);
1350
1351 gpio_request(GPIO_PORT151, NULL); /* LCDDON */
1352 gpio_direction_output(GPIO_PORT151, 1);
1353
1354 lcdc_info.clock_source = LCDC_CLK_BUS;
1355 lcdc_info.ch[0].interface_type = RGB18;
Kuninori Morimotof60cb472011-03-02 09:05:44 +00001356 lcdc_info.ch[0].clock_divider = 3;
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001357 lcdc_info.ch[0].flags = 0;
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001358 lcdc_info.ch[0].lcd_size_cfg.width = 152;
1359 lcdc_info.ch[0].lcd_size_cfg.height = 91;
1360
1361 /* enable TouchScreen */
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001362 irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
Kuninori Morimoto9fa1b7f2010-06-04 03:15:09 +00001363
1364 tsc_device.irq = IRQ7;
1365 i2c_register_board_info(0, &tsc_device, 1);
1366#endif /* CONFIG_AP4EVB_QHD */
Guennadi Liakhovetski341291a2010-05-23 14:12:46 +00001367
Guennadi Liakhovetski1a0b1ea2010-10-20 15:15:49 +02001368 /* CEU */
1369
1370 /*
1371 * TODO: reserve memory for V4L2 DMA buffers, when a suitable API
1372 * becomes available
1373 */
1374
1375 /* MIPI-CSI stuff */
1376 gpio_request(GPIO_FN_VIO_CKO, NULL);
1377
1378 clk = clk_get(NULL, "vck1_clk");
1379 if (!IS_ERR(clk)) {
1380 clk_set_rate(clk, clk_round_rate(clk, 13000000));
1381 clk_enable(clk);
1382 clk_put(clk);
1383 }
1384
Magnus Damm2b7eda62010-02-05 11:14:58 +00001385 sh7372_add_standard_devices();
1386
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001387 /* HDMI */
1388 gpio_request(GPIO_FN_HDMI_HPD, NULL);
1389 gpio_request(GPIO_FN_HDMI_CEC, NULL);
1390
1391 /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
1392#define SRCR4 0xe61580bc
1393 srcr4 = __raw_readl(SRCR4);
1394 __raw_writel(srcr4 | (1 << 13), SRCR4);
1395 udelay(50);
1396 __raw_writel(srcr4 & ~(1 << 13), SRCR4);
1397
Magnus Damm2b7eda62010-02-05 11:14:58 +00001398 platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
Guennadi Liakhovetski2ce51f82011-04-04 17:08:05 +02001399
1400 hdmi_init_pm_clock();
Kuninori Morimoto6084c812011-04-05 01:22:33 +00001401 fsi_init_pm_clock();
Magnus Damm2b7eda62010-02-05 11:14:58 +00001402}
1403
Magnus Damm495b3ce2010-05-12 14:21:34 +00001404static void __init ap4evb_timer_init(void)
1405{
1406 sh7372_clock_init();
1407 shmobile_timer.init();
Guennadi Liakhovetskidfbcdf62010-07-21 10:13:25 +00001408
1409 /* External clock source */
Kuninori Morimoto685e4082010-10-15 05:14:54 +00001410 clk_set_rate(&sh7372_dv_clki_clk, 27000000);
Magnus Damm495b3ce2010-05-12 14:21:34 +00001411}
1412
1413static struct sys_timer ap4evb_timer = {
1414 .init = ap4evb_timer_init,
1415};
1416
Magnus Damm2b7eda62010-02-05 11:14:58 +00001417MACHINE_START(AP4EVB, "ap4evb")
Magnus Damm2b7eda62010-02-05 11:14:58 +00001418 .map_io = ap4evb_map_io,
1419 .init_irq = sh7372_init_irq,
Magnus Damm863b1712010-12-28 08:27:01 +00001420 .handle_irq = shmobile_handle_irq_intc,
Magnus Damm2b7eda62010-02-05 11:14:58 +00001421 .init_machine = ap4evb_init,
Magnus Damm495b3ce2010-05-12 14:21:34 +00001422 .timer = &ap4evb_timer,
Magnus Damm2b7eda62010-02-05 11:14:58 +00001423MACHINE_END