blob: 2936ccc959504760f2d505de6dbdd8244bab8162 [file] [log] [blame]
Magnus Dammf2aaf662010-02-05 11:15:07 +00001/*
2 * G4EVM 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>
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +000029#include <linux/usb/r8a66597.h>
Magnus Dammf2aaf662010-02-05 11:15:07 +000030#include <linux/io.h>
NISHIMOTO Hiroki6676a1702010-02-23 10:55:10 +000031#include <linux/input.h>
32#include <linux/input/sh_keysc.h>
Magnus Damm9213c002011-01-06 10:41:09 +000033#include <linux/mmc/host.h>
Guennadi Liakhovetski17e75d82011-03-09 11:27:56 +010034#include <linux/mmc/sh_mobile_sdhi.h>
NISHIMOTO Hiroki276b4f62010-02-12 08:10:06 +000035#include <linux/gpio.h>
Jon Medhurst9b742022011-08-04 17:05:21 +010036#include <linux/dma-mapping.h>
Rob Herring250a2722012-01-03 16:57:33 -060037#include <mach/irqs.h>
NISHIMOTO Hiroki276b4f62010-02-12 08:10:06 +000038#include <mach/sh7377.h>
Magnus Dammf2aaf662010-02-05 11:15:07 +000039#include <mach/common.h>
40#include <asm/mach-types.h>
41#include <asm/mach/arch.h>
42#include <asm/mach/map.h>
Magnus Damm0163acf2010-05-21 05:19:34 +000043#include <asm/mach/time.h>
Magnus Dammf2aaf662010-02-05 11:15:07 +000044
Kuninori Morimoto819ee862010-03-29 06:31:36 +000045/*
46 * SDHI
47 *
48 * SDHI0 : card detection is possible
49 * SDHI1 : card detection is impossible
50 *
51 * [G4-MAIN-BOARD]
52 * JP74 : short # DBG_2V8A for SDHI0
53 * JP75 : NC # DBG_3V3A for SDHI0
54 * JP76 : NC # DBG_3V3A_SD for SDHI0
55 * JP77 : NC # 3V3A_SDIO for SDHI1
56 * JP78 : short # DBG_2V8A for SDHI1
57 * JP79 : NC # DBG_3V3A for SDHI1
58 * JP80 : NC # DBG_3V3A_SD for SDHI1
59 *
60 * [G4-CORE-BOARD]
61 * S32 : all off # to dissever from G3-CORE_DBG board
62 * S33 : all off # to dissever from G3-CORE_DBG board
63 *
64 * [G3-CORE_DBG-BOARD]
65 * S1 : all off # to dissever from G3-CORE_DBG board
66 * S3 : all off # to dissever from G3-CORE_DBG board
67 * S4 : all off # to dissever from G3-CORE_DBG board
68 */
69
Magnus Dammf2aaf662010-02-05 11:15:07 +000070static struct mtd_partition nor_flash_partitions[] = {
71 {
72 .name = "loader",
73 .offset = 0x00000000,
74 .size = 512 * 1024,
75 },
76 {
77 .name = "bootenv",
78 .offset = MTDPART_OFS_APPEND,
79 .size = 512 * 1024,
80 },
81 {
82 .name = "kernel_ro",
83 .offset = MTDPART_OFS_APPEND,
84 .size = 8 * 1024 * 1024,
85 .mask_flags = MTD_WRITEABLE,
86 },
87 {
88 .name = "kernel",
89 .offset = MTDPART_OFS_APPEND,
90 .size = 8 * 1024 * 1024,
91 },
92 {
93 .name = "data",
94 .offset = MTDPART_OFS_APPEND,
95 .size = MTDPART_SIZ_FULL,
96 },
97};
98
99static struct physmap_flash_data nor_flash_data = {
100 .width = 2,
101 .parts = nor_flash_partitions,
102 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
103};
104
105static struct resource nor_flash_resources[] = {
106 [0] = {
107 .start = 0x00000000,
108 .end = 0x08000000 - 1,
109 .flags = IORESOURCE_MEM,
110 }
111};
112
113static struct platform_device nor_flash_device = {
114 .name = "physmap-flash",
115 .dev = {
116 .platform_data = &nor_flash_data,
117 },
118 .num_resources = ARRAY_SIZE(nor_flash_resources),
119 .resource = nor_flash_resources,
120};
121
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000122/* USBHS */
Kuninori Morimotod64a1b02010-06-02 00:25:14 +0000123static void usb_host_port_power(int port, int power)
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000124{
125 if (!power) /* only power-on supported for now */
126 return;
127
128 /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
129 __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
130}
131
132static struct r8a66597_platdata usb_host_data = {
133 .on_chip = 1,
134 .port_power = usb_host_port_power,
135};
136
137static struct resource usb_host_resources[] = {
138 [0] = {
139 .name = "USBHS",
140 .start = 0xe6890000,
141 .end = 0xe68900e5,
142 .flags = IORESOURCE_MEM,
143 },
144 [1] = {
Magnus Damm043296d2010-05-20 14:39:21 +0000145 .start = evt2irq(0x0a20), /* USBHS_USHI0 */
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000146 .flags = IORESOURCE_IRQ,
147 },
148};
149
150static struct platform_device usb_host_device = {
151 .name = "r8a66597_hcd",
152 .id = 0,
153 .dev = {
154 .platform_data = &usb_host_data,
155 .dma_mask = NULL,
156 .coherent_dma_mask = 0xffffffff,
157 },
158 .num_resources = ARRAY_SIZE(usb_host_resources),
159 .resource = usb_host_resources,
160};
Magnus Dammf2aaf662010-02-05 11:15:07 +0000161
NISHIMOTO Hiroki6676a1702010-02-23 10:55:10 +0000162/* KEYSC */
163static struct sh_keysc_info keysc_info = {
164 .mode = SH_KEYSC_MODE_5,
165 .scan_timing = 3,
166 .delay = 100,
167 .keycodes = {
168 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F,
169 KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L,
170 KEY_M, KEY_N, KEY_U, KEY_P, KEY_Q, KEY_R,
171 KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X,
172 KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP, KEY_WAKEUP, KEY_COFFEE,
173 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5,
174 KEY_6, KEY_7, KEY_8, KEY_9, KEY_STOP, KEY_COMPUTER,
175 },
176};
177
178static struct resource keysc_resources[] = {
179 [0] = {
180 .name = "KEYSC",
181 .start = 0xe61b0000,
182 .end = 0xe61b000f,
183 .flags = IORESOURCE_MEM,
184 },
185 [1] = {
Magnus Damm043296d2010-05-20 14:39:21 +0000186 .start = evt2irq(0x0be0), /* KEYSC_KEY */
NISHIMOTO Hiroki6676a1702010-02-23 10:55:10 +0000187 .flags = IORESOURCE_IRQ,
188 },
189};
190
191static struct platform_device keysc_device = {
192 .name = "sh_keysc",
193 .id = 0, /* keysc0 clock */
194 .num_resources = ARRAY_SIZE(keysc_resources),
195 .resource = keysc_resources,
196 .dev = {
197 .platform_data = &keysc_info,
198 },
199};
200
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000201/* SDHI */
Magnus Damm9213c002011-01-06 10:41:09 +0000202static struct sh_mobile_sdhi_info sdhi0_info = {
203 .tmio_caps = MMC_CAP_SDIO_IRQ,
204};
205
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000206static struct resource sdhi0_resources[] = {
207 [0] = {
208 .name = "SDHI0",
209 .start = 0xe6d50000,
Paul Mundt1acd3de2011-05-25 14:54:30 +0900210 .end = 0xe6d500ff,
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000211 .flags = IORESOURCE_MEM,
212 },
213 [1] = {
Magnus Damm043296d2010-05-20 14:39:21 +0000214 .start = evt2irq(0x0e00), /* SDHI0 */
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000215 .flags = IORESOURCE_IRQ,
216 },
217};
218
219static struct platform_device sdhi0_device = {
220 .name = "sh_mobile_sdhi",
221 .num_resources = ARRAY_SIZE(sdhi0_resources),
222 .resource = sdhi0_resources,
223 .id = 0,
Magnus Damm9213c002011-01-06 10:41:09 +0000224 .dev = {
225 .platform_data = &sdhi0_info,
226 },
227};
228
229static struct sh_mobile_sdhi_info sdhi1_info = {
230 .tmio_caps = MMC_CAP_NONREMOVABLE | MMC_CAP_SDIO_IRQ,
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000231};
232
233static struct resource sdhi1_resources[] = {
234 [0] = {
235 .name = "SDHI1",
236 .start = 0xe6d60000,
Guennadi Liakhovetski31d31fe2011-03-09 13:09:27 +0100237 .end = 0xe6d600ff,
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000238 .flags = IORESOURCE_MEM,
239 },
240 [1] = {
Magnus Damm043296d2010-05-20 14:39:21 +0000241 .start = evt2irq(0x0e80), /* SDHI1 */
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000242 .flags = IORESOURCE_IRQ,
243 },
244};
245
246static struct platform_device sdhi1_device = {
247 .name = "sh_mobile_sdhi",
248 .num_resources = ARRAY_SIZE(sdhi1_resources),
249 .resource = sdhi1_resources,
250 .id = 1,
Magnus Damm9213c002011-01-06 10:41:09 +0000251 .dev = {
252 .platform_data = &sdhi1_info,
253 },
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000254};
255
Magnus Dammf2aaf662010-02-05 11:15:07 +0000256static struct platform_device *g4evm_devices[] __initdata = {
257 &nor_flash_device,
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000258 &usb_host_device,
NISHIMOTO Hiroki6676a1702010-02-23 10:55:10 +0000259 &keysc_device,
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000260 &sdhi0_device,
261 &sdhi1_device,
Magnus Dammf2aaf662010-02-05 11:15:07 +0000262};
263
264static struct map_desc g4evm_io_desc[] __initdata = {
265 /* create a 1:1 entity map for 0xe6xxxxxx
266 * used by CPGA, INTC and PFC.
267 */
268 {
269 .virtual = 0xe6000000,
270 .pfn = __phys_to_pfn(0xe6000000),
271 .length = 256 << 20,
272 .type = MT_DEVICE_NONSHARED
273 },
274};
275
276static void __init g4evm_map_io(void)
277{
278 iotable_init(g4evm_io_desc, ARRAY_SIZE(g4evm_io_desc));
279
Magnus Damm0163acf2010-05-21 05:19:34 +0000280 /* setup early devices and console here as well */
Magnus Dammf2aaf662010-02-05 11:15:07 +0000281 sh7377_add_early_devices();
Magnus Damm4ae04ac2010-02-08 11:02:54 +0000282 shmobile_setup_console();
Magnus Dammf2aaf662010-02-05 11:15:07 +0000283}
284
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000285#define GPIO_SDHID0_D0 0xe60520fc
286#define GPIO_SDHID0_D1 0xe60520fd
287#define GPIO_SDHID0_D2 0xe60520fe
288#define GPIO_SDHID0_D3 0xe60520ff
289#define GPIO_SDHICMD0 0xe6052100
290
291#define GPIO_SDHID1_D0 0xe6052103
292#define GPIO_SDHID1_D1 0xe6052104
293#define GPIO_SDHID1_D2 0xe6052105
294#define GPIO_SDHID1_D3 0xe6052106
295#define GPIO_SDHICMD1 0xe6052107
296
297/*
298 * FIXME !!
299 *
300 * gpio_pull_up is quick_hack.
301 *
302 * current gpio frame work doesn't have
303 * the method to control only pull up/down/free.
304 * this function should be replaced by correct gpio function
305 */
306static void __init gpio_pull_up(u32 addr)
307{
308 u8 data = __raw_readb(addr);
309
310 data &= 0x0F;
311 data |= 0xC0;
312 __raw_writeb(data, addr);
313}
314
Magnus Dammf2aaf662010-02-05 11:15:07 +0000315static void __init g4evm_init(void)
316{
NISHIMOTO Hiroki276b4f62010-02-12 08:10:06 +0000317 sh7377_pinmux_init();
318
319 /* Lit DS14 LED */
320 gpio_request(GPIO_PORT109, NULL);
321 gpio_direction_output(GPIO_PORT109, 1);
322 gpio_export(GPIO_PORT109, 1);
323
324 /* Lit DS15 LED */
325 gpio_request(GPIO_PORT110, NULL);
326 gpio_direction_output(GPIO_PORT110, 1);
327 gpio_export(GPIO_PORT110, 1);
328
329 /* Lit DS16 LED */
330 gpio_request(GPIO_PORT112, NULL);
331 gpio_direction_output(GPIO_PORT112, 1);
332 gpio_export(GPIO_PORT112, 1);
333
334 /* Lit DS17 LED */
335 gpio_request(GPIO_PORT113, NULL);
336 gpio_direction_output(GPIO_PORT113, 1);
337 gpio_export(GPIO_PORT113, 1);
338
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000339 /* USBHS */
340 gpio_request(GPIO_FN_VBUS_0, NULL);
341 gpio_request(GPIO_FN_PWEN, NULL);
342 gpio_request(GPIO_FN_OVCN, NULL);
343 gpio_request(GPIO_FN_OVCN2, NULL);
344 gpio_request(GPIO_FN_EXTLP, NULL);
345 gpio_request(GPIO_FN_IDIN, NULL);
346
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000347 /* setup USB phy */
348 __raw_writew(0x0200, 0xe605810a); /* USBCR1 */
349 __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
350 __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */
351 __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */
352
NISHIMOTO Hiroki6676a1702010-02-23 10:55:10 +0000353 /* KEYSC @ CN31 */
354 gpio_request(GPIO_FN_PORT60_KEYOUT5, NULL);
355 gpio_request(GPIO_FN_PORT61_KEYOUT4, NULL);
356 gpio_request(GPIO_FN_PORT62_KEYOUT3, NULL);
357 gpio_request(GPIO_FN_PORT63_KEYOUT2, NULL);
358 gpio_request(GPIO_FN_PORT64_KEYOUT1, NULL);
359 gpio_request(GPIO_FN_PORT65_KEYOUT0, NULL);
360 gpio_request(GPIO_FN_PORT66_KEYIN0_PU, NULL);
361 gpio_request(GPIO_FN_PORT67_KEYIN1_PU, NULL);
362 gpio_request(GPIO_FN_PORT68_KEYIN2_PU, NULL);
363 gpio_request(GPIO_FN_PORT69_KEYIN3_PU, NULL);
364 gpio_request(GPIO_FN_PORT70_KEYIN4_PU, NULL);
365 gpio_request(GPIO_FN_PORT71_KEYIN5_PU, NULL);
366 gpio_request(GPIO_FN_PORT72_KEYIN6_PU, NULL);
367
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000368 /* SDHI0 */
369 gpio_request(GPIO_FN_SDHICLK0, NULL);
370 gpio_request(GPIO_FN_SDHICD0, NULL);
371 gpio_request(GPIO_FN_SDHID0_0, NULL);
372 gpio_request(GPIO_FN_SDHID0_1, NULL);
373 gpio_request(GPIO_FN_SDHID0_2, NULL);
374 gpio_request(GPIO_FN_SDHID0_3, NULL);
375 gpio_request(GPIO_FN_SDHICMD0, NULL);
376 gpio_request(GPIO_FN_SDHIWP0, NULL);
377 gpio_pull_up(GPIO_SDHID0_D0);
378 gpio_pull_up(GPIO_SDHID0_D1);
379 gpio_pull_up(GPIO_SDHID0_D2);
380 gpio_pull_up(GPIO_SDHID0_D3);
381 gpio_pull_up(GPIO_SDHICMD0);
382
383 /* SDHI1 */
384 gpio_request(GPIO_FN_SDHICLK1, NULL);
385 gpio_request(GPIO_FN_SDHID1_0, NULL);
386 gpio_request(GPIO_FN_SDHID1_1, NULL);
387 gpio_request(GPIO_FN_SDHID1_2, NULL);
388 gpio_request(GPIO_FN_SDHID1_3, NULL);
389 gpio_request(GPIO_FN_SDHICMD1, NULL);
390 gpio_pull_up(GPIO_SDHID1_D0);
391 gpio_pull_up(GPIO_SDHID1_D1);
392 gpio_pull_up(GPIO_SDHID1_D2);
393 gpio_pull_up(GPIO_SDHID1_D3);
394 gpio_pull_up(GPIO_SDHICMD1);
395
Magnus Dammf2aaf662010-02-05 11:15:07 +0000396 sh7377_add_standard_devices();
397
398 platform_add_devices(g4evm_devices, ARRAY_SIZE(g4evm_devices));
399}
400
Magnus Damm0163acf2010-05-21 05:19:34 +0000401static void __init g4evm_timer_init(void)
402{
403 sh7377_clock_init();
404 shmobile_timer.init();
405}
406
407static struct sys_timer g4evm_timer = {
408 .init = g4evm_timer_init,
409};
410
Magnus Dammf2aaf662010-02-05 11:15:07 +0000411MACHINE_START(G4EVM, "g4evm")
Magnus Dammf2aaf662010-02-05 11:15:07 +0000412 .map_io = g4evm_map_io,
413 .init_irq = sh7377_init_irq,
Magnus Damm863b1712010-12-28 08:27:01 +0000414 .handle_irq = shmobile_handle_irq_intc,
Magnus Dammf2aaf662010-02-05 11:15:07 +0000415 .init_machine = g4evm_init,
Magnus Damm0163acf2010-05-21 05:19:34 +0000416 .timer = &g4evm_timer,
Magnus Dammf2aaf662010-02-05 11:15:07 +0000417MACHINE_END