4 * Copyright (C) 2010 Magnus Damm
5 * Copyright (C) 2008 Yoshihiro Shimoda
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/irq.h>
24 #include <linux/platform_device.h>
25 #include <linux/delay.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/mtd/physmap.h>
29 #include <linux/i2c.h>
30 #include <linux/i2c/tsc2007.h>
32 #include <linux/smsc911x.h>
33 #include <linux/gpio.h>
34 #include <linux/input.h>
35 #include <linux/input/sh_keysc.h>
36 #include <linux/usb/r8a66597.h>
37 #include <mach/common.h>
38 #include <mach/sh7372.h>
39 #include <asm/mach-types.h>
40 #include <asm/mach/arch.h>
41 #include <asm/mach/map.h>
44 * Address Interface BusWidth note
45 * ------------------------------------------------------------------
46 * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
47 * 0x0800_0000 user area -
48 * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
49 * 0x1400_0000 Ether (LAN9220) 16bit
50 * 0x1600_0000 user area - cannot use with NAND
51 * 0x1800_0000 user area -
53 * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
59 * SW1 | SW2 | SW7 | NOR Flash ROM
60 * bit1 | bit1 bit2 | bit1 | Memory allocation
61 * ------+------------+------+------------------
62 * OFF | ON OFF | ON | Area 0
63 * OFF | ON OFF | OFF | Area 4
69 * SW1 | SW2 | SW7 | NAND Flash ROM
70 * bit1 | bit1 bit2 | bit2 | Memory allocation
71 * ------+------------+------+------------------
72 * OFF | ON OFF | ON | FCE 0
73 * OFF | ON OFF | OFF | FCE 1
80 * -----------------------
86 * LCD / IRQ / KEYSC / IrDA
88 * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (TouchScreen)
93 * -------------+-----------------------+---------------+
94 * ON | KEY / IrDA | LCD |
95 * OFF | KEY / IrDA / IRQ | IRQ |
101 * J7 : 1-2 MAX3355E VBUS
108 static struct mtd_partition nor_flash_partitions[] = {
111 .offset = 0x00000000,
116 .offset = MTDPART_OFS_APPEND,
121 .offset = MTDPART_OFS_APPEND,
122 .size = 8 * 1024 * 1024,
123 .mask_flags = MTD_WRITEABLE,
127 .offset = MTDPART_OFS_APPEND,
128 .size = 8 * 1024 * 1024,
132 .offset = MTDPART_OFS_APPEND,
133 .size = MTDPART_SIZ_FULL,
137 static struct physmap_flash_data nor_flash_data = {
139 .parts = nor_flash_partitions,
140 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
143 static struct resource nor_flash_resources[] = {
146 .end = 0x08000000 - 1,
147 .flags = IORESOURCE_MEM,
151 static struct platform_device nor_flash_device = {
152 .name = "physmap-flash",
154 .platform_data = &nor_flash_data,
156 .num_resources = ARRAY_SIZE(nor_flash_resources),
157 .resource = nor_flash_resources,
161 static struct resource smc911x_resources[] = {
164 .end = 0x16000000 - 1,
165 .flags = IORESOURCE_MEM,
168 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
172 static struct smsc911x_platform_config smsc911x_info = {
173 .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
174 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
175 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
178 static struct platform_device smc911x_device = {
181 .num_resources = ARRAY_SIZE(smc911x_resources),
182 .resource = smc911x_resources,
184 .platform_data = &smsc911x_info,
188 /* KEYSC (Needs SW43 set to ON) */
189 static struct sh_keysc_info keysc_info = {
190 .mode = SH_KEYSC_MODE_1,
194 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
195 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
196 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
197 KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
198 KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
202 static struct resource keysc_resources[] = {
207 .flags = IORESOURCE_MEM,
211 .flags = IORESOURCE_IRQ,
215 static struct platform_device keysc_device = {
217 .id = 0, /* "keysc0" clock */
218 .num_resources = ARRAY_SIZE(keysc_resources),
219 .resource = keysc_resources,
221 .platform_data = &keysc_info,
226 static struct resource sdhi0_resources[] = {
231 .flags = IORESOURCE_MEM,
235 .flags = IORESOURCE_IRQ,
239 static struct platform_device sdhi0_device = {
240 .name = "sh_mobile_sdhi",
241 .num_resources = ARRAY_SIZE(sdhi0_resources),
242 .resource = sdhi0_resources,
247 void usb1_host_port_power(int port, int power)
249 if (!power) /* only power-on supported for now */
252 /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
253 __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
256 static struct r8a66597_platdata usb1_host_data = {
258 .port_power = usb1_host_port_power,
261 static struct resource usb1_host_resources[] = {
265 .end = 0xE68B00E6 - 1,
266 .flags = IORESOURCE_MEM,
271 .flags = IORESOURCE_IRQ,
275 static struct platform_device usb1_host_device = {
276 .name = "r8a66597_hcd",
279 .dma_mask = NULL, /* not use dma */
280 .coherent_dma_mask = 0xffffffff,
281 .platform_data = &usb1_host_data,
283 .num_resources = ARRAY_SIZE(usb1_host_resources),
284 .resource = usb1_host_resources,
287 static struct platform_device *ap4evb_devices[] __initdata = {
295 /* TouchScreen (Needs SW3 set to OFF) */
297 struct tsc2007_platform_data tsc2007_info = {
303 static struct i2c_board_info i2c1_devices[] = {
305 I2C_BOARD_INFO("r2025sd", 0x32),
308 I2C_BOARD_INFO("tsc2007", 0x48),
310 .platform_data = &tsc2007_info,
315 static struct map_desc ap4evb_io_desc[] __initdata = {
316 /* create a 1:1 entity map for 0xe6xxxxxx
317 * used by CPGA, INTC and PFC.
320 .virtual = 0xe6000000,
321 .pfn = __phys_to_pfn(0xe6000000),
323 .type = MT_DEVICE_NONSHARED
327 static void __init ap4evb_map_io(void)
329 iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
331 /* setup early devices, clocks and console here as well */
332 sh7372_add_early_devices();
333 sh7367_clock_init(); /* use g3 clocks for now */
334 shmobile_setup_console();
337 static void __init ap4evb_init(void)
339 sh7372_pinmux_init();
342 gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
343 gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
345 /* enable SMSC911X */
346 gpio_request(GPIO_FN_CS5A, NULL);
347 gpio_request(GPIO_FN_IRQ6_39, NULL);
349 /* enable LED 1 - 4 */
350 gpio_request(GPIO_PORT185, NULL);
351 gpio_request(GPIO_PORT186, NULL);
352 gpio_request(GPIO_PORT187, NULL);
353 gpio_request(GPIO_PORT188, NULL);
354 gpio_direction_output(GPIO_PORT185, 1);
355 gpio_direction_output(GPIO_PORT186, 1);
356 gpio_direction_output(GPIO_PORT187, 1);
357 gpio_direction_output(GPIO_PORT188, 1);
358 gpio_export(GPIO_PORT185, 0);
359 gpio_export(GPIO_PORT186, 0);
360 gpio_export(GPIO_PORT187, 0);
361 gpio_export(GPIO_PORT188, 0);
363 /* enable Debug switch (S6) */
364 gpio_request(GPIO_PORT32, NULL);
365 gpio_request(GPIO_PORT33, NULL);
366 gpio_request(GPIO_PORT34, NULL);
367 gpio_request(GPIO_PORT35, NULL);
368 gpio_direction_input(GPIO_PORT32);
369 gpio_direction_input(GPIO_PORT33);
370 gpio_direction_input(GPIO_PORT34);
371 gpio_direction_input(GPIO_PORT35);
372 gpio_export(GPIO_PORT32, 0);
373 gpio_export(GPIO_PORT33, 0);
374 gpio_export(GPIO_PORT34, 0);
375 gpio_export(GPIO_PORT35, 0);
378 gpio_request(GPIO_FN_KEYOUT0, NULL);
379 gpio_request(GPIO_FN_KEYOUT1, NULL);
380 gpio_request(GPIO_FN_KEYOUT2, NULL);
381 gpio_request(GPIO_FN_KEYOUT3, NULL);
382 gpio_request(GPIO_FN_KEYOUT4, NULL);
383 gpio_request(GPIO_FN_KEYIN0_136, NULL);
384 gpio_request(GPIO_FN_KEYIN1_135, NULL);
385 gpio_request(GPIO_FN_KEYIN2_134, NULL);
386 gpio_request(GPIO_FN_KEYIN3_133, NULL);
387 gpio_request(GPIO_FN_KEYIN4, NULL);
390 gpio_request(GPIO_FN_SDHICD0, NULL);
391 gpio_request(GPIO_FN_SDHIWP0, NULL);
392 gpio_request(GPIO_FN_SDHICMD0, NULL);
393 gpio_request(GPIO_FN_SDHICLK0, NULL);
394 gpio_request(GPIO_FN_SDHID0_3, NULL);
395 gpio_request(GPIO_FN_SDHID0_2, NULL);
396 gpio_request(GPIO_FN_SDHID0_1, NULL);
397 gpio_request(GPIO_FN_SDHID0_0, NULL);
399 /* enable TouchScreen */
400 gpio_request(GPIO_FN_IRQ28_123, NULL);
401 set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
403 i2c_register_board_info(1, i2c1_devices,
404 ARRAY_SIZE(i2c1_devices));
407 gpio_request(GPIO_FN_VBUS0_1, NULL);
408 gpio_request(GPIO_FN_IDIN_1_18, NULL);
409 gpio_request(GPIO_FN_PWEN_1_115, NULL);
410 gpio_request(GPIO_FN_OVCN_1_114, NULL);
411 gpio_request(GPIO_FN_EXTLP_1, NULL);
412 gpio_request(GPIO_FN_OVCN2_1, NULL);
415 __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
417 sh7372_add_standard_devices();
419 platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
422 MACHINE_START(AP4EVB, "ap4evb")
423 .phys_io = 0xe6000000,
424 .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
425 .map_io = ap4evb_map_io,
426 .init_irq = sh7372_init_irq,
427 .init_machine = ap4evb_init,
428 .timer = &shmobile_timer,