Commit | Line | Data |
---|---|---|
2b7eda63 MD |
1 | /* |
2 | * AP4EVB board support | |
3 | * | |
4 | * Copyright (C) 2010 Magnus Damm | |
5 | * Copyright (C) 2008 Yoshihiro Shimoda | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; version 2 of the License. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | #include <linux/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> | |
91cf5082 KM |
29 | #include <linux/i2c.h> |
30 | #include <linux/i2c/tsc2007.h> | |
2b7eda63 | 31 | #include <linux/io.h> |
1b7e0677 KM |
32 | #include <linux/smsc911x.h> |
33 | #include <linux/gpio.h> | |
17ccb834 KM |
34 | #include <linux/input.h> |
35 | #include <linux/input/sh_keysc.h> | |
fb54d268 | 36 | #include <linux/usb/r8a66597.h> |
2b7eda63 | 37 | #include <mach/common.h> |
1b7e0677 | 38 | #include <mach/sh7372.h> |
2b7eda63 MD |
39 | #include <asm/mach-types.h> |
40 | #include <asm/mach/arch.h> | |
41 | #include <asm/mach/map.h> | |
495b3cea | 42 | #include <asm/mach/time.h> |
2b7eda63 | 43 | |
02624a17 KM |
44 | /* |
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 | ||
17ccb834 | 86 | /* |
dda128dc | 87 | * LCD / IRQ / KEYSC / IrDA |
17ccb834 | 88 | * |
dda128dc KM |
89 | * 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 | | |
17ccb834 KM |
97 | */ |
98 | ||
fb54d268 KM |
99 | /* |
100 | * USB | |
101 | * | |
102 | * J7 : 1-2 MAX3355E VBUS | |
103 | * 2-3 DC 5.0V | |
104 | * | |
105 | * S39: bit2: off | |
106 | */ | |
107 | ||
1b7e0677 | 108 | /* MTD */ |
2b7eda63 MD |
109 | static 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 | ||
138 | static 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 | ||
144 | static struct resource nor_flash_resources[] = { | |
145 | [0] = { | |
146 | .start = 0x00000000, | |
147 | .end = 0x08000000 - 1, | |
148 | .flags = IORESOURCE_MEM, | |
149 | } | |
150 | }; | |
151 | ||
152 | static 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 | ||
1b7e0677 KM |
161 | /* SMSC 9220 */ |
162 | static struct resource smc911x_resources[] = { | |
163 | { | |
164 | .start = 0x14000000, | |
165 | .end = 0x16000000 - 1, | |
166 | .flags = IORESOURCE_MEM, | |
167 | }, { | |
33c9607a | 168 | .start = evt2irq(0x02c0) /* IRQ6A */, |
1b7e0677 KM |
169 | .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL, |
170 | }, | |
171 | }; | |
172 | ||
173 | static 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 | ||
179 | static 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 | }; | |
2b7eda63 | 188 | |
17ccb834 KM |
189 | /* KEYSC (Needs SW43 set to ON) */ |
190 | static 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 | ||
203 | static struct resource keysc_resources[] = { | |
204 | [0] = { | |
205 | .name = "KEYSC", | |
206 | .start = 0xe61b0000, | |
207 | .end = 0xe61b0063, | |
208 | .flags = IORESOURCE_MEM, | |
209 | }, | |
210 | [1] = { | |
33c9607a | 211 | .start = evt2irq(0x0be0), /* KEYSC_KEY */ |
17ccb834 KM |
212 | .flags = IORESOURCE_IRQ, |
213 | }, | |
214 | }; | |
215 | ||
216 | static 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 | ||
3a14d039 MD |
226 | /* SDHI0 */ |
227 | static struct resource sdhi0_resources[] = { | |
228 | [0] = { | |
229 | .name = "SDHI0", | |
230 | .start = 0xe6850000, | |
231 | .end = 0xe68501ff, | |
232 | .flags = IORESOURCE_MEM, | |
233 | }, | |
234 | [1] = { | |
33c9607a | 235 | .start = evt2irq(0x0e00) /* SDHI0 */, |
3a14d039 MD |
236 | .flags = IORESOURCE_IRQ, |
237 | }, | |
238 | }; | |
239 | ||
240 | static 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 | ||
fb54d268 KM |
247 | /* USB1 */ |
248 | void 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 | ||
257 | static struct r8a66597_platdata usb1_host_data = { | |
258 | .on_chip = 1, | |
259 | .port_power = usb1_host_port_power, | |
260 | }; | |
261 | ||
262 | static struct resource usb1_host_resources[] = { | |
263 | [0] = { | |
264 | .name = "USBHS", | |
265 | .start = 0xE68B0000, | |
266 | .end = 0xE68B00E6 - 1, | |
267 | .flags = IORESOURCE_MEM, | |
268 | }, | |
269 | [1] = { | |
33c9607a | 270 | .start = evt2irq(0x1ce0) /* USB1_USB1I0 */, |
fb54d268 KM |
271 | .flags = IORESOURCE_IRQ, |
272 | }, | |
273 | }; | |
274 | ||
275 | static struct platform_device usb1_host_device = { | |
276 | .name = "r8a66597_hcd", | |
277 | .id = 1, | |
278 | .dev = { | |
279 | .dma_mask = NULL, /* not use dma */ | |
280 | .coherent_dma_mask = 0xffffffff, | |
281 | .platform_data = &usb1_host_data, | |
282 | }, | |
283 | .num_resources = ARRAY_SIZE(usb1_host_resources), | |
284 | .resource = usb1_host_resources, | |
285 | }; | |
286 | ||
2b7eda63 MD |
287 | static struct platform_device *ap4evb_devices[] __initdata = { |
288 | &nor_flash_device, | |
1b7e0677 | 289 | &smc911x_device, |
17ccb834 | 290 | &keysc_device, |
3a14d039 | 291 | &sdhi0_device, |
fb54d268 | 292 | &usb1_host_device, |
2b7eda63 MD |
293 | }; |
294 | ||
dda128dc | 295 | /* TouchScreen (Needs SW3 set to OFF) */ |
33c9607a | 296 | #define IRQ28 evt2irq(0x3380) /* IRQ28A */ |
91cf5082 KM |
297 | struct tsc2007_platform_data tsc2007_info = { |
298 | .model = 2007, | |
299 | .x_plate_ohms = 180, | |
300 | }; | |
301 | ||
302 | /* I2C */ | |
303 | static struct i2c_board_info i2c1_devices[] = { | |
8fc883c2 KM |
304 | { |
305 | I2C_BOARD_INFO("r2025sd", 0x32), | |
306 | }, | |
91cf5082 KM |
307 | { |
308 | I2C_BOARD_INFO("tsc2007", 0x48), | |
309 | .type = "tsc2007", | |
310 | .platform_data = &tsc2007_info, | |
311 | .irq = IRQ28, | |
312 | }, | |
313 | }; | |
314 | ||
2b7eda63 MD |
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. | |
318 | */ | |
319 | { | |
320 | .virtual = 0xe6000000, | |
321 | .pfn = __phys_to_pfn(0xe6000000), | |
322 | .length = 256 << 20, | |
323 | .type = MT_DEVICE_NONSHARED | |
324 | }, | |
325 | }; | |
326 | ||
327 | static void __init ap4evb_map_io(void) | |
328 | { | |
329 | iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc)); | |
330 | ||
495b3cea | 331 | /* setup early devices and console here as well */ |
2b7eda63 | 332 | sh7372_add_early_devices(); |
4ae04acb | 333 | shmobile_setup_console(); |
2b7eda63 MD |
334 | } |
335 | ||
336 | static void __init ap4evb_init(void) | |
337 | { | |
1b7e0677 KM |
338 | sh7372_pinmux_init(); |
339 | ||
b228b48e KM |
340 | /* enable SCIFA0 */ |
341 | gpio_request(GPIO_FN_SCIFA0_TXD, NULL); | |
342 | gpio_request(GPIO_FN_SCIFA0_RXD, NULL); | |
343 | ||
1b7e0677 KM |
344 | /* enable SMSC911X */ |
345 | gpio_request(GPIO_FN_CS5A, NULL); | |
346 | gpio_request(GPIO_FN_IRQ6_39, NULL); | |
347 | ||
5098280e KM |
348 | /* enable LED 1 - 4 */ |
349 | gpio_request(GPIO_PORT185, NULL); | |
350 | gpio_request(GPIO_PORT186, NULL); | |
351 | gpio_request(GPIO_PORT187, NULL); | |
352 | gpio_request(GPIO_PORT188, NULL); | |
353 | gpio_direction_output(GPIO_PORT185, 1); | |
354 | gpio_direction_output(GPIO_PORT186, 1); | |
355 | gpio_direction_output(GPIO_PORT187, 1); | |
356 | gpio_direction_output(GPIO_PORT188, 1); | |
357 | gpio_export(GPIO_PORT185, 0); | |
358 | gpio_export(GPIO_PORT186, 0); | |
359 | gpio_export(GPIO_PORT187, 0); | |
360 | gpio_export(GPIO_PORT188, 0); | |
361 | ||
8cb3a2eb KM |
362 | /* enable Debug switch (S6) */ |
363 | gpio_request(GPIO_PORT32, NULL); | |
364 | gpio_request(GPIO_PORT33, NULL); | |
365 | gpio_request(GPIO_PORT34, NULL); | |
366 | gpio_request(GPIO_PORT35, NULL); | |
367 | gpio_direction_input(GPIO_PORT32); | |
368 | gpio_direction_input(GPIO_PORT33); | |
369 | gpio_direction_input(GPIO_PORT34); | |
370 | gpio_direction_input(GPIO_PORT35); | |
371 | gpio_export(GPIO_PORT32, 0); | |
372 | gpio_export(GPIO_PORT33, 0); | |
373 | gpio_export(GPIO_PORT34, 0); | |
374 | gpio_export(GPIO_PORT35, 0); | |
375 | ||
17ccb834 KM |
376 | /* enable KEYSC */ |
377 | gpio_request(GPIO_FN_KEYOUT0, NULL); | |
378 | gpio_request(GPIO_FN_KEYOUT1, NULL); | |
379 | gpio_request(GPIO_FN_KEYOUT2, NULL); | |
380 | gpio_request(GPIO_FN_KEYOUT3, NULL); | |
381 | gpio_request(GPIO_FN_KEYOUT4, NULL); | |
382 | gpio_request(GPIO_FN_KEYIN0_136, NULL); | |
383 | gpio_request(GPIO_FN_KEYIN1_135, NULL); | |
384 | gpio_request(GPIO_FN_KEYIN2_134, NULL); | |
385 | gpio_request(GPIO_FN_KEYIN3_133, NULL); | |
386 | gpio_request(GPIO_FN_KEYIN4, NULL); | |
387 | ||
3a14d039 MD |
388 | /* SDHI0 */ |
389 | gpio_request(GPIO_FN_SDHICD0, NULL); | |
390 | gpio_request(GPIO_FN_SDHIWP0, NULL); | |
391 | gpio_request(GPIO_FN_SDHICMD0, NULL); | |
392 | gpio_request(GPIO_FN_SDHICLK0, NULL); | |
393 | gpio_request(GPIO_FN_SDHID0_3, NULL); | |
394 | gpio_request(GPIO_FN_SDHID0_2, NULL); | |
395 | gpio_request(GPIO_FN_SDHID0_1, NULL); | |
396 | gpio_request(GPIO_FN_SDHID0_0, NULL); | |
397 | ||
91cf5082 KM |
398 | /* enable TouchScreen */ |
399 | gpio_request(GPIO_FN_IRQ28_123, NULL); | |
400 | set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW); | |
401 | ||
402 | i2c_register_board_info(1, i2c1_devices, | |
403 | ARRAY_SIZE(i2c1_devices)); | |
404 | ||
fb54d268 KM |
405 | /* USB enable */ |
406 | gpio_request(GPIO_FN_VBUS0_1, NULL); | |
407 | gpio_request(GPIO_FN_IDIN_1_18, NULL); | |
408 | gpio_request(GPIO_FN_PWEN_1_115, NULL); | |
409 | gpio_request(GPIO_FN_OVCN_1_114, NULL); | |
410 | gpio_request(GPIO_FN_EXTLP_1, NULL); | |
411 | gpio_request(GPIO_FN_OVCN2_1, NULL); | |
412 | ||
413 | /* setup USB phy */ | |
414 | __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */ | |
415 | ||
2b7eda63 MD |
416 | sh7372_add_standard_devices(); |
417 | ||
418 | platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices)); | |
419 | } | |
420 | ||
495b3cea MD |
421 | static void __init ap4evb_timer_init(void) |
422 | { | |
423 | sh7372_clock_init(); | |
424 | shmobile_timer.init(); | |
425 | } | |
426 | ||
427 | static struct sys_timer ap4evb_timer = { | |
428 | .init = ap4evb_timer_init, | |
429 | }; | |
430 | ||
2b7eda63 MD |
431 | MACHINE_START(AP4EVB, "ap4evb") |
432 | .phys_io = 0xe6000000, | |
433 | .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc, | |
434 | .map_io = ap4evb_map_io, | |
435 | .init_irq = sh7372_init_irq, | |
436 | .init_machine = ap4evb_init, | |
495b3cea | 437 | .timer = &ap4evb_timer, |
2b7eda63 | 438 | MACHINE_END |