blob: 4d197e36270a83d8e22f894a21c269383dc60f74 [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 */
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>
Kuninori Morimoto91cf5082010-03-11 10:42:52 +000029#include <linux/i2c.h>
30#include <linux/i2c/tsc2007.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000031#include <linux/io.h>
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +000032#include <linux/smsc911x.h>
33#include <linux/gpio.h>
Kuninori Morimoto17ccb832010-02-23 07:07:01 +000034#include <linux/input.h>
35#include <linux/input/sh_keysc.h>
Kuninori Morimotofb54d262010-04-13 06:16:32 +000036#include <linux/usb/r8a66597.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000037#include <mach/common.h>
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +000038#include <mach/sh7372.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000039#include <asm/mach-types.h>
40#include <asm/mach/arch.h>
41#include <asm/mach/map.h>
Magnus Damm495b3ce2010-05-12 14:21:34 +000042#include <asm/mach/time.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000043
Kuninori Morimoto02624a12010-02-18 17:58:19 +090044/*
45 * Address Interface BusWidth note
46 * ------------------------------------------------------------------
47 * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
48 * 0x0800_0000 user area -
49 * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
50 * 0x1400_0000 Ether (LAN9220) 16bit
51 * 0x1600_0000 user area - cannot use with NAND
52 * 0x1800_0000 user area -
53 * 0x1A00_0000 -
54 * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
55 */
56
57/*
58 * NOR Flash ROM
59 *
60 * SW1 | SW2 | SW7 | NOR Flash ROM
61 * bit1 | bit1 bit2 | bit1 | Memory allocation
62 * ------+------------+------+------------------
63 * OFF | ON OFF | ON | Area 0
64 * OFF | ON OFF | OFF | Area 4
65 */
66
67/*
68 * NAND Flash ROM
69 *
70 * SW1 | SW2 | SW7 | NAND Flash ROM
71 * bit1 | bit1 bit2 | bit2 | Memory allocation
72 * ------+------------+------+------------------
73 * OFF | ON OFF | ON | FCE 0
74 * OFF | ON OFF | OFF | FCE 1
75 */
76
77/*
78 * SMSC 9220
79 *
80 * SW1 SMSC 9220
81 * -----------------------
82 * ON access disable
83 * OFF access enable
84 */
85
Kuninori Morimoto17ccb832010-02-23 07:07:01 +000086/*
Kuninori Morimotodda128d2010-03-12 10:07:55 +000087 * LCD / IRQ / KEYSC / IrDA
Kuninori Morimoto17ccb832010-02-23 07:07:01 +000088 *
Kuninori Morimotodda128d2010-03-12 10:07:55 +000089 * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (TouchScreen)
90 * LCD = 2nd LCDC
91 *
92 * | SW43 |
93 * SW3 | ON | OFF |
94 * -------------+-----------------------+---------------+
95 * ON | KEY / IrDA | LCD |
96 * OFF | KEY / IrDA / IRQ | IRQ |
Kuninori Morimoto17ccb832010-02-23 07:07:01 +000097 */
98
Kuninori Morimotofb54d262010-04-13 06:16:32 +000099/*
100 * USB
101 *
102 * J7 : 1-2 MAX3355E VBUS
103 * 2-3 DC 5.0V
104 *
105 * S39: bit2: off
106 */
107
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000108/* MTD */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000109static struct mtd_partition nor_flash_partitions[] = {
110 {
111 .name = "loader",
112 .offset = 0x00000000,
113 .size = 512 * 1024,
114 },
115 {
116 .name = "bootenv",
117 .offset = MTDPART_OFS_APPEND,
118 .size = 512 * 1024,
119 },
120 {
121 .name = "kernel_ro",
122 .offset = MTDPART_OFS_APPEND,
123 .size = 8 * 1024 * 1024,
124 .mask_flags = MTD_WRITEABLE,
125 },
126 {
127 .name = "kernel",
128 .offset = MTDPART_OFS_APPEND,
129 .size = 8 * 1024 * 1024,
130 },
131 {
132 .name = "data",
133 .offset = MTDPART_OFS_APPEND,
134 .size = MTDPART_SIZ_FULL,
135 },
136};
137
138static struct physmap_flash_data nor_flash_data = {
139 .width = 2,
140 .parts = nor_flash_partitions,
141 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
142};
143
144static struct resource nor_flash_resources[] = {
145 [0] = {
146 .start = 0x00000000,
147 .end = 0x08000000 - 1,
148 .flags = IORESOURCE_MEM,
149 }
150};
151
152static struct platform_device nor_flash_device = {
153 .name = "physmap-flash",
154 .dev = {
155 .platform_data = &nor_flash_data,
156 },
157 .num_resources = ARRAY_SIZE(nor_flash_resources),
158 .resource = nor_flash_resources,
159};
160
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000161/* SMSC 9220 */
162static struct resource smc911x_resources[] = {
163 {
164 .start = 0x14000000,
165 .end = 0x16000000 - 1,
166 .flags = IORESOURCE_MEM,
167 }, {
168 .start = 6,
169 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
170 },
171};
172
173static struct smsc911x_platform_config smsc911x_info = {
174 .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
175 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
176 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
177};
178
179static struct platform_device smc911x_device = {
180 .name = "smsc911x",
181 .id = -1,
182 .num_resources = ARRAY_SIZE(smc911x_resources),
183 .resource = smc911x_resources,
184 .dev = {
185 .platform_data = &smsc911x_info,
186 },
187};
Magnus Damm2b7eda62010-02-05 11:14:58 +0000188
Kuninori Morimoto17ccb832010-02-23 07:07:01 +0000189/* KEYSC (Needs SW43 set to ON) */
190static struct sh_keysc_info keysc_info = {
191 .mode = SH_KEYSC_MODE_1,
192 .scan_timing = 3,
193 .delay = 2500,
194 .keycodes = {
195 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
196 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
197 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
198 KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
199 KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
200 },
201};
202
203static struct resource keysc_resources[] = {
204 [0] = {
205 .name = "KEYSC",
206 .start = 0xe61b0000,
207 .end = 0xe61b0063,
208 .flags = IORESOURCE_MEM,
209 },
210 [1] = {
211 .start = 79,
212 .flags = IORESOURCE_IRQ,
213 },
214};
215
216static struct platform_device keysc_device = {
217 .name = "sh_keysc",
218 .id = 0, /* "keysc0" clock */
219 .num_resources = ARRAY_SIZE(keysc_resources),
220 .resource = keysc_resources,
221 .dev = {
222 .platform_data = &keysc_info,
223 },
224};
225
Magnus Damm3a14d032010-03-10 09:26:44 +0000226/* SDHI0 */
227static struct resource sdhi0_resources[] = {
228 [0] = {
229 .name = "SDHI0",
230 .start = 0xe6850000,
231 .end = 0xe68501ff,
232 .flags = IORESOURCE_MEM,
233 },
234 [1] = {
235 .start = 96,
236 .flags = IORESOURCE_IRQ,
237 },
238};
239
240static struct platform_device sdhi0_device = {
241 .name = "sh_mobile_sdhi",
242 .num_resources = ARRAY_SIZE(sdhi0_resources),
243 .resource = sdhi0_resources,
244 .id = 0,
245};
246
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000247/* USB1 */
248void usb1_host_port_power(int port, int power)
249{
250 if (!power) /* only power-on supported for now */
251 return;
252
253 /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
254 __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
255}
256
257static struct r8a66597_platdata usb1_host_data = {
258 .on_chip = 1,
259 .port_power = usb1_host_port_power,
260};
261
262static struct resource usb1_host_resources[] = {
263 [0] = {
264 .name = "USBHS",
265 .start = 0xE68B0000,
266 .end = 0xE68B00E6 - 1,
267 .flags = IORESOURCE_MEM,
268 },
269 [1] = {
270 .start = 215,
271 .end = 215,
272 .flags = IORESOURCE_IRQ,
273 },
274};
275
276static struct platform_device usb1_host_device = {
277 .name = "r8a66597_hcd",
278 .id = 1,
279 .dev = {
280 .dma_mask = NULL, /* not use dma */
281 .coherent_dma_mask = 0xffffffff,
282 .platform_data = &usb1_host_data,
283 },
284 .num_resources = ARRAY_SIZE(usb1_host_resources),
285 .resource = usb1_host_resources,
286};
287
Magnus Damm2b7eda62010-02-05 11:14:58 +0000288static struct platform_device *ap4evb_devices[] __initdata = {
289 &nor_flash_device,
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000290 &smc911x_device,
Kuninori Morimoto17ccb832010-02-23 07:07:01 +0000291 &keysc_device,
Magnus Damm3a14d032010-03-10 09:26:44 +0000292 &sdhi0_device,
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000293 &usb1_host_device,
Magnus Damm2b7eda62010-02-05 11:14:58 +0000294};
295
Kuninori Morimotodda128d2010-03-12 10:07:55 +0000296/* TouchScreen (Needs SW3 set to OFF) */
Kuninori Morimoto91cf5082010-03-11 10:42:52 +0000297#define IRQ28 396
298struct tsc2007_platform_data tsc2007_info = {
299 .model = 2007,
300 .x_plate_ohms = 180,
301};
302
303/* I2C */
304static struct i2c_board_info i2c1_devices[] = {
305 {
Kuninori Morimoto8fc883c2010-03-11 07:34:37 +0000306 I2C_BOARD_INFO("r2025sd", 0x32),
307 },
308 {
Kuninori Morimoto91cf5082010-03-11 10:42:52 +0000309 I2C_BOARD_INFO("tsc2007", 0x48),
310 .type = "tsc2007",
311 .platform_data = &tsc2007_info,
312 .irq = IRQ28,
313 },
314};
315
Magnus Damm2b7eda62010-02-05 11:14:58 +0000316static struct map_desc ap4evb_io_desc[] __initdata = {
317 /* create a 1:1 entity map for 0xe6xxxxxx
318 * used by CPGA, INTC and PFC.
319 */
320 {
321 .virtual = 0xe6000000,
322 .pfn = __phys_to_pfn(0xe6000000),
323 .length = 256 << 20,
324 .type = MT_DEVICE_NONSHARED
325 },
326};
327
328static void __init ap4evb_map_io(void)
329{
330 iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
331
Magnus Damm495b3ce2010-05-12 14:21:34 +0000332 /* setup early devices and console here as well */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000333 sh7372_add_early_devices();
Magnus Damm4ae04ac2010-02-08 11:02:54 +0000334 shmobile_setup_console();
Magnus Damm2b7eda62010-02-05 11:14:58 +0000335}
336
337static void __init ap4evb_init(void)
338{
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000339 sh7372_pinmux_init();
340
Kuninori Morimotob228b482010-02-18 16:44:41 +0900341 /* enable SCIFA0 */
342 gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
343 gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
344
Kuninori Morimoto1b7e0672010-02-17 09:30:14 +0000345 /* enable SMSC911X */
346 gpio_request(GPIO_FN_CS5A, NULL);
347 gpio_request(GPIO_FN_IRQ6_39, NULL);
348
Kuninori Morimoto50982802010-02-22 09:20:39 +0000349 /* 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);
362
Kuninori Morimoto8cb3a2e2010-02-22 09:30:12 +0000363 /* 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);
376
Kuninori Morimoto17ccb832010-02-23 07:07:01 +0000377 /* enable KEYSC */
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);
388
Magnus Damm3a14d032010-03-10 09:26:44 +0000389 /* SDHI0 */
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);
398
Kuninori Morimoto91cf5082010-03-11 10:42:52 +0000399 /* enable TouchScreen */
400 gpio_request(GPIO_FN_IRQ28_123, NULL);
401 set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
402
403 i2c_register_board_info(1, i2c1_devices,
404 ARRAY_SIZE(i2c1_devices));
405
Kuninori Morimotofb54d262010-04-13 06:16:32 +0000406 /* USB enable */
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);
413
414 /* setup USB phy */
415 __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
416
Magnus Damm2b7eda62010-02-05 11:14:58 +0000417 sh7372_add_standard_devices();
418
419 platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
420}
421
Magnus Damm495b3ce2010-05-12 14:21:34 +0000422static void __init ap4evb_timer_init(void)
423{
424 sh7372_clock_init();
425 shmobile_timer.init();
426}
427
428static struct sys_timer ap4evb_timer = {
429 .init = ap4evb_timer_init,
430};
431
Magnus Damm2b7eda62010-02-05 11:14:58 +0000432MACHINE_START(AP4EVB, "ap4evb")
433 .phys_io = 0xe6000000,
434 .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
435 .map_io = ap4evb_map_io,
436 .init_irq = sh7372_init_irq,
437 .init_machine = ap4evb_init,
Magnus Damm495b3ce2010-05-12 14:21:34 +0000438 .timer = &ap4evb_timer,
Magnus Damm2b7eda62010-02-05 11:14:58 +0000439MACHINE_END