blob: 46d757d2759d0120c37db14f79ce1d55b5015b11 [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>
NISHIMOTO Hiroki276b4f62010-02-12 08:10:06 +000037#include <mach/sh7377.h>
Magnus Dammf2aaf662010-02-05 11:15:07 +000038#include <mach/common.h>
39#include <asm/mach-types.h>
40#include <asm/mach/arch.h>
Magnus Dammf2aaf662010-02-05 11:15:07 +000041
Kuninori Morimoto819ee862010-03-29 06:31:36 +000042/*
43 * SDHI
44 *
45 * SDHI0 : card detection is possible
46 * SDHI1 : card detection is impossible
47 *
48 * [G4-MAIN-BOARD]
49 * JP74 : short # DBG_2V8A for SDHI0
50 * JP75 : NC # DBG_3V3A for SDHI0
51 * JP76 : NC # DBG_3V3A_SD for SDHI0
52 * JP77 : NC # 3V3A_SDIO for SDHI1
53 * JP78 : short # DBG_2V8A for SDHI1
54 * JP79 : NC # DBG_3V3A for SDHI1
55 * JP80 : NC # DBG_3V3A_SD for SDHI1
56 *
57 * [G4-CORE-BOARD]
58 * S32 : all off # to dissever from G3-CORE_DBG board
59 * S33 : all off # to dissever from G3-CORE_DBG board
60 *
61 * [G3-CORE_DBG-BOARD]
62 * S1 : all off # to dissever from G3-CORE_DBG board
63 * S3 : all off # to dissever from G3-CORE_DBG board
64 * S4 : all off # to dissever from G3-CORE_DBG board
65 */
66
Magnus Dammf2aaf662010-02-05 11:15:07 +000067static struct mtd_partition nor_flash_partitions[] = {
68 {
69 .name = "loader",
70 .offset = 0x00000000,
71 .size = 512 * 1024,
72 },
73 {
74 .name = "bootenv",
75 .offset = MTDPART_OFS_APPEND,
76 .size = 512 * 1024,
77 },
78 {
79 .name = "kernel_ro",
80 .offset = MTDPART_OFS_APPEND,
81 .size = 8 * 1024 * 1024,
82 .mask_flags = MTD_WRITEABLE,
83 },
84 {
85 .name = "kernel",
86 .offset = MTDPART_OFS_APPEND,
87 .size = 8 * 1024 * 1024,
88 },
89 {
90 .name = "data",
91 .offset = MTDPART_OFS_APPEND,
92 .size = MTDPART_SIZ_FULL,
93 },
94};
95
96static struct physmap_flash_data nor_flash_data = {
97 .width = 2,
98 .parts = nor_flash_partitions,
99 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
100};
101
102static struct resource nor_flash_resources[] = {
103 [0] = {
104 .start = 0x00000000,
105 .end = 0x08000000 - 1,
106 .flags = IORESOURCE_MEM,
107 }
108};
109
110static struct platform_device nor_flash_device = {
111 .name = "physmap-flash",
112 .dev = {
113 .platform_data = &nor_flash_data,
114 },
115 .num_resources = ARRAY_SIZE(nor_flash_resources),
116 .resource = nor_flash_resources,
117};
118
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000119/* USBHS */
Kuninori Morimotod64a1b02010-06-02 00:25:14 +0000120static void usb_host_port_power(int port, int power)
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000121{
122 if (!power) /* only power-on supported for now */
123 return;
124
125 /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
126 __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
127}
128
129static struct r8a66597_platdata usb_host_data = {
130 .on_chip = 1,
131 .port_power = usb_host_port_power,
132};
133
134static struct resource usb_host_resources[] = {
135 [0] = {
136 .name = "USBHS",
137 .start = 0xe6890000,
138 .end = 0xe68900e5,
139 .flags = IORESOURCE_MEM,
140 },
141 [1] = {
Magnus Damm043296d2010-05-20 14:39:21 +0000142 .start = evt2irq(0x0a20), /* USBHS_USHI0 */
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000143 .flags = IORESOURCE_IRQ,
144 },
145};
146
147static struct platform_device usb_host_device = {
148 .name = "r8a66597_hcd",
149 .id = 0,
150 .dev = {
151 .platform_data = &usb_host_data,
152 .dma_mask = NULL,
153 .coherent_dma_mask = 0xffffffff,
154 },
155 .num_resources = ARRAY_SIZE(usb_host_resources),
156 .resource = usb_host_resources,
157};
Magnus Dammf2aaf662010-02-05 11:15:07 +0000158
NISHIMOTO Hiroki6676a1702010-02-23 10:55:10 +0000159/* KEYSC */
160static struct sh_keysc_info keysc_info = {
161 .mode = SH_KEYSC_MODE_5,
162 .scan_timing = 3,
163 .delay = 100,
164 .keycodes = {
165 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F,
166 KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L,
167 KEY_M, KEY_N, KEY_U, KEY_P, KEY_Q, KEY_R,
168 KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X,
169 KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP, KEY_WAKEUP, KEY_COFFEE,
170 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5,
171 KEY_6, KEY_7, KEY_8, KEY_9, KEY_STOP, KEY_COMPUTER,
172 },
173};
174
175static struct resource keysc_resources[] = {
176 [0] = {
177 .name = "KEYSC",
178 .start = 0xe61b0000,
179 .end = 0xe61b000f,
180 .flags = IORESOURCE_MEM,
181 },
182 [1] = {
Magnus Damm043296d2010-05-20 14:39:21 +0000183 .start = evt2irq(0x0be0), /* KEYSC_KEY */
NISHIMOTO Hiroki6676a1702010-02-23 10:55:10 +0000184 .flags = IORESOURCE_IRQ,
185 },
186};
187
188static struct platform_device keysc_device = {
189 .name = "sh_keysc",
190 .id = 0, /* keysc0 clock */
191 .num_resources = ARRAY_SIZE(keysc_resources),
192 .resource = keysc_resources,
193 .dev = {
194 .platform_data = &keysc_info,
195 },
196};
197
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000198/* SDHI */
Magnus Damm9213c002011-01-06 10:41:09 +0000199static struct sh_mobile_sdhi_info sdhi0_info = {
200 .tmio_caps = MMC_CAP_SDIO_IRQ,
201};
202
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000203static struct resource sdhi0_resources[] = {
204 [0] = {
205 .name = "SDHI0",
206 .start = 0xe6d50000,
Paul Mundt1acd3de2011-05-25 14:54:30 +0900207 .end = 0xe6d500ff,
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000208 .flags = IORESOURCE_MEM,
209 },
210 [1] = {
Magnus Damm043296d2010-05-20 14:39:21 +0000211 .start = evt2irq(0x0e00), /* SDHI0 */
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000212 .flags = IORESOURCE_IRQ,
213 },
214};
215
216static struct platform_device sdhi0_device = {
217 .name = "sh_mobile_sdhi",
218 .num_resources = ARRAY_SIZE(sdhi0_resources),
219 .resource = sdhi0_resources,
220 .id = 0,
Magnus Damm9213c002011-01-06 10:41:09 +0000221 .dev = {
222 .platform_data = &sdhi0_info,
223 },
224};
225
226static struct sh_mobile_sdhi_info sdhi1_info = {
227 .tmio_caps = MMC_CAP_NONREMOVABLE | MMC_CAP_SDIO_IRQ,
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000228};
229
230static struct resource sdhi1_resources[] = {
231 [0] = {
232 .name = "SDHI1",
233 .start = 0xe6d60000,
Guennadi Liakhovetski31d31fe72011-03-09 13:09:27 +0100234 .end = 0xe6d600ff,
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000235 .flags = IORESOURCE_MEM,
236 },
237 [1] = {
Magnus Damm043296d2010-05-20 14:39:21 +0000238 .start = evt2irq(0x0e80), /* SDHI1 */
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000239 .flags = IORESOURCE_IRQ,
240 },
241};
242
243static struct platform_device sdhi1_device = {
244 .name = "sh_mobile_sdhi",
245 .num_resources = ARRAY_SIZE(sdhi1_resources),
246 .resource = sdhi1_resources,
247 .id = 1,
Magnus Damm9213c002011-01-06 10:41:09 +0000248 .dev = {
249 .platform_data = &sdhi1_info,
250 },
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000251};
252
Magnus Dammf2aaf662010-02-05 11:15:07 +0000253static struct platform_device *g4evm_devices[] __initdata = {
254 &nor_flash_device,
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000255 &usb_host_device,
NISHIMOTO Hiroki6676a1702010-02-23 10:55:10 +0000256 &keysc_device,
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000257 &sdhi0_device,
258 &sdhi1_device,
Magnus Dammf2aaf662010-02-05 11:15:07 +0000259};
260
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000261#define GPIO_SDHID0_D0 0xe60520fc
262#define GPIO_SDHID0_D1 0xe60520fd
263#define GPIO_SDHID0_D2 0xe60520fe
264#define GPIO_SDHID0_D3 0xe60520ff
265#define GPIO_SDHICMD0 0xe6052100
266
267#define GPIO_SDHID1_D0 0xe6052103
268#define GPIO_SDHID1_D1 0xe6052104
269#define GPIO_SDHID1_D2 0xe6052105
270#define GPIO_SDHID1_D3 0xe6052106
271#define GPIO_SDHICMD1 0xe6052107
272
273/*
274 * FIXME !!
275 *
276 * gpio_pull_up is quick_hack.
277 *
278 * current gpio frame work doesn't have
279 * the method to control only pull up/down/free.
280 * this function should be replaced by correct gpio function
281 */
282static void __init gpio_pull_up(u32 addr)
283{
284 u8 data = __raw_readb(addr);
285
286 data &= 0x0F;
287 data |= 0xC0;
288 __raw_writeb(data, addr);
289}
290
Magnus Dammf2aaf662010-02-05 11:15:07 +0000291static void __init g4evm_init(void)
292{
NISHIMOTO Hiroki276b4f62010-02-12 08:10:06 +0000293 sh7377_pinmux_init();
294
295 /* Lit DS14 LED */
296 gpio_request(GPIO_PORT109, NULL);
297 gpio_direction_output(GPIO_PORT109, 1);
298 gpio_export(GPIO_PORT109, 1);
299
300 /* Lit DS15 LED */
301 gpio_request(GPIO_PORT110, NULL);
302 gpio_direction_output(GPIO_PORT110, 1);
303 gpio_export(GPIO_PORT110, 1);
304
305 /* Lit DS16 LED */
306 gpio_request(GPIO_PORT112, NULL);
307 gpio_direction_output(GPIO_PORT112, 1);
308 gpio_export(GPIO_PORT112, 1);
309
310 /* Lit DS17 LED */
311 gpio_request(GPIO_PORT113, NULL);
312 gpio_direction_output(GPIO_PORT113, 1);
313 gpio_export(GPIO_PORT113, 1);
314
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000315 /* USBHS */
316 gpio_request(GPIO_FN_VBUS_0, NULL);
317 gpio_request(GPIO_FN_PWEN, NULL);
318 gpio_request(GPIO_FN_OVCN, NULL);
319 gpio_request(GPIO_FN_OVCN2, NULL);
320 gpio_request(GPIO_FN_EXTLP, NULL);
321 gpio_request(GPIO_FN_IDIN, NULL);
322
NISHIMOTO Hirokiaa18ef62010-02-12 08:11:18 +0000323 /* setup USB phy */
324 __raw_writew(0x0200, 0xe605810a); /* USBCR1 */
325 __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
326 __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */
327 __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */
328
NISHIMOTO Hiroki6676a1702010-02-23 10:55:10 +0000329 /* KEYSC @ CN31 */
330 gpio_request(GPIO_FN_PORT60_KEYOUT5, NULL);
331 gpio_request(GPIO_FN_PORT61_KEYOUT4, NULL);
332 gpio_request(GPIO_FN_PORT62_KEYOUT3, NULL);
333 gpio_request(GPIO_FN_PORT63_KEYOUT2, NULL);
334 gpio_request(GPIO_FN_PORT64_KEYOUT1, NULL);
335 gpio_request(GPIO_FN_PORT65_KEYOUT0, NULL);
336 gpio_request(GPIO_FN_PORT66_KEYIN0_PU, NULL);
337 gpio_request(GPIO_FN_PORT67_KEYIN1_PU, NULL);
338 gpio_request(GPIO_FN_PORT68_KEYIN2_PU, NULL);
339 gpio_request(GPIO_FN_PORT69_KEYIN3_PU, NULL);
340 gpio_request(GPIO_FN_PORT70_KEYIN4_PU, NULL);
341 gpio_request(GPIO_FN_PORT71_KEYIN5_PU, NULL);
342 gpio_request(GPIO_FN_PORT72_KEYIN6_PU, NULL);
343
Kuninori Morimoto819ee862010-03-29 06:31:36 +0000344 /* SDHI0 */
345 gpio_request(GPIO_FN_SDHICLK0, NULL);
346 gpio_request(GPIO_FN_SDHICD0, NULL);
347 gpio_request(GPIO_FN_SDHID0_0, NULL);
348 gpio_request(GPIO_FN_SDHID0_1, NULL);
349 gpio_request(GPIO_FN_SDHID0_2, NULL);
350 gpio_request(GPIO_FN_SDHID0_3, NULL);
351 gpio_request(GPIO_FN_SDHICMD0, NULL);
352 gpio_request(GPIO_FN_SDHIWP0, NULL);
353 gpio_pull_up(GPIO_SDHID0_D0);
354 gpio_pull_up(GPIO_SDHID0_D1);
355 gpio_pull_up(GPIO_SDHID0_D2);
356 gpio_pull_up(GPIO_SDHID0_D3);
357 gpio_pull_up(GPIO_SDHICMD0);
358
359 /* SDHI1 */
360 gpio_request(GPIO_FN_SDHICLK1, NULL);
361 gpio_request(GPIO_FN_SDHID1_0, NULL);
362 gpio_request(GPIO_FN_SDHID1_1, NULL);
363 gpio_request(GPIO_FN_SDHID1_2, NULL);
364 gpio_request(GPIO_FN_SDHID1_3, NULL);
365 gpio_request(GPIO_FN_SDHICMD1, NULL);
366 gpio_pull_up(GPIO_SDHID1_D0);
367 gpio_pull_up(GPIO_SDHID1_D1);
368 gpio_pull_up(GPIO_SDHID1_D2);
369 gpio_pull_up(GPIO_SDHID1_D3);
370 gpio_pull_up(GPIO_SDHICMD1);
371
Magnus Dammf2aaf662010-02-05 11:15:07 +0000372 sh7377_add_standard_devices();
373
374 platform_add_devices(g4evm_devices, ARRAY_SIZE(g4evm_devices));
375}
376
377MACHINE_START(G4EVM, "g4evm")
Magnus Dammbfc46f32012-02-29 21:37:12 +0900378 .map_io = sh7377_map_io,
379 .init_early = sh7377_add_early_devices,
Magnus Dammf2aaf662010-02-05 11:15:07 +0000380 .init_irq = sh7377_init_irq,
Magnus Damm863b1712010-12-28 08:27:01 +0000381 .handle_irq = shmobile_handle_irq_intc,
Magnus Dammf2aaf662010-02-05 11:15:07 +0000382 .init_machine = g4evm_init,
Magnus Damm03f7bee2012-03-06 17:36:29 +0900383 .timer = &shmobile_timer,
Magnus Dammf2aaf662010-02-05 11:15:07 +0000384MACHINE_END