blob: 6dbdc428c244b546c962e1bbae866ff579baa546 [file] [log] [blame]
Magnus Dammc793c1b2010-02-05 11:14:49 +00001/*
2 * G3EVM 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>
Magnus Damm143f3b82010-02-19 09:54:06 +000029#include <linux/mtd/sh_flctl.h>
Magnus Damm3a7b8022010-02-10 20:13:31 +090030#include <linux/usb/r8a66597.h>
Magnus Dammc793c1b2010-02-05 11:14:49 +000031#include <linux/io.h>
Magnus Damm7fdda672010-02-10 20:10:55 +090032#include <linux/gpio.h>
Magnus Damm03fb2562010-02-16 10:48:15 +000033#include <linux/input.h>
34#include <linux/input/sh_keysc.h>
Jon Medhurst9b742022011-08-04 17:05:21 +010035#include <linux/dma-mapping.h>
Rob Herring250a2722012-01-03 16:57:33 -060036#include <mach/irqs.h>
Magnus Damm7fdda672010-02-10 20:10:55 +090037#include <mach/sh7367.h>
Magnus Dammc793c1b2010-02-05 11:14:49 +000038#include <mach/common.h>
39#include <asm/mach-types.h>
40#include <asm/mach/arch.h>
41#include <asm/mach/map.h>
Magnus Damm4f0836b2010-05-20 14:49:28 +000042#include <asm/mach/time.h>
Magnus Dammc793c1b2010-02-05 11:14:49 +000043
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +000044/*
45 * IrDA
46 *
47 * S67: 5bit : ON power
48 * : 6bit : ON remote control
49 * OFF IrDA
50 */
51
Magnus Dammc793c1b2010-02-05 11:14:49 +000052static struct mtd_partition nor_flash_partitions[] = {
53 {
54 .name = "loader",
55 .offset = 0x00000000,
56 .size = 512 * 1024,
57 },
58 {
59 .name = "bootenv",
60 .offset = MTDPART_OFS_APPEND,
61 .size = 512 * 1024,
62 },
63 {
64 .name = "kernel_ro",
65 .offset = MTDPART_OFS_APPEND,
66 .size = 8 * 1024 * 1024,
67 .mask_flags = MTD_WRITEABLE,
68 },
69 {
70 .name = "kernel",
71 .offset = MTDPART_OFS_APPEND,
72 .size = 8 * 1024 * 1024,
73 },
74 {
75 .name = "data",
76 .offset = MTDPART_OFS_APPEND,
77 .size = MTDPART_SIZ_FULL,
78 },
79};
80
81static struct physmap_flash_data nor_flash_data = {
82 .width = 2,
83 .parts = nor_flash_partitions,
84 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
85};
86
87static struct resource nor_flash_resources[] = {
88 [0] = {
89 .start = 0x00000000,
90 .end = 0x08000000 - 1,
91 .flags = IORESOURCE_MEM,
92 }
93};
94
95static struct platform_device nor_flash_device = {
96 .name = "physmap-flash",
97 .dev = {
98 .platform_data = &nor_flash_data,
99 },
100 .num_resources = ARRAY_SIZE(nor_flash_resources),
101 .resource = nor_flash_resources,
102};
103
Magnus Damm3a7b8022010-02-10 20:13:31 +0900104/* USBHS */
Kuninori Morimoto1c14e6c2010-06-02 00:25:19 +0000105static void usb_host_port_power(int port, int power)
Magnus Damm3a7b8022010-02-10 20:13:31 +0900106{
107 if (!power) /* only power-on supported for now */
108 return;
109
110 /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
111 __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
112}
113
114static struct r8a66597_platdata usb_host_data = {
115 .on_chip = 1,
116 .port_power = usb_host_port_power,
117};
118
119static struct resource usb_host_resources[] = {
120 [0] = {
121 .name = "USBHS",
122 .start = 0xe6890000,
123 .end = 0xe68900e5,
124 .flags = IORESOURCE_MEM,
125 },
126 [1] = {
Magnus Damm74905092010-05-20 14:35:30 +0000127 .start = evt2irq(0xa20), /* USBHS_USHI0 */
Magnus Damm3a7b8022010-02-10 20:13:31 +0900128 .flags = IORESOURCE_IRQ,
129 },
130};
131
132static struct platform_device usb_host_device = {
133 .name = "r8a66597_hcd",
134 .id = 0,
135 .dev = {
136 .platform_data = &usb_host_data,
137 .dma_mask = NULL,
138 .coherent_dma_mask = 0xffffffff,
139 },
140 .num_resources = ARRAY_SIZE(usb_host_resources),
141 .resource = usb_host_resources,
142};
Magnus Dammc793c1b2010-02-05 11:14:49 +0000143
Magnus Damm03fb2562010-02-16 10:48:15 +0000144/* KEYSC */
145static struct sh_keysc_info keysc_info = {
146 .mode = SH_KEYSC_MODE_5,
147 .scan_timing = 3,
148 .delay = 100,
149 .keycodes = {
150 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
151 KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N,
152 KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U,
153 KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP,
154 KEY_WAKEUP, KEY_COFFEE, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
155 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_STOP, KEY_COMPUTER,
156 },
157};
158
159static struct resource keysc_resources[] = {
160 [0] = {
161 .name = "KEYSC",
162 .start = 0xe61b0000,
163 .end = 0xe61b000f,
164 .flags = IORESOURCE_MEM,
165 },
166 [1] = {
Magnus Damm74905092010-05-20 14:35:30 +0000167 .start = evt2irq(0xbe0), /* KEYSC_KEY */
Magnus Damm03fb2562010-02-16 10:48:15 +0000168 .flags = IORESOURCE_IRQ,
169 },
170};
171
172static struct platform_device keysc_device = {
173 .name = "sh_keysc",
174 .num_resources = ARRAY_SIZE(keysc_resources),
175 .resource = keysc_resources,
176 .dev = {
177 .platform_data = &keysc_info,
178 },
179};
180
Magnus Damm143f3b82010-02-19 09:54:06 +0000181static struct mtd_partition nand_partition_info[] = {
182 {
183 .name = "system",
184 .offset = 0,
185 .size = 64 * 1024 * 1024,
186 },
187 {
188 .name = "userdata",
189 .offset = MTDPART_OFS_APPEND,
190 .size = 128 * 1024 * 1024,
191 },
192 {
193 .name = "cache",
194 .offset = MTDPART_OFS_APPEND,
195 .size = 64 * 1024 * 1024,
196 },
197};
198
199static struct resource nand_flash_resources[] = {
200 [0] = {
201 .start = 0xe6a30000,
202 .end = 0xe6a3009b,
203 .flags = IORESOURCE_MEM,
204 }
205};
206
207static struct sh_flctl_platform_data nand_flash_data = {
208 .parts = nand_partition_info,
209 .nr_parts = ARRAY_SIZE(nand_partition_info),
210 .flcmncr_val = QTSEL_E | FCKSEL_E | TYPESEL_SET | NANWF_E
211 | SHBUSSEL | SEL_16BIT,
212};
213
214static struct platform_device nand_flash_device = {
215 .name = "sh_flctl",
216 .resource = nand_flash_resources,
217 .num_resources = ARRAY_SIZE(nand_flash_resources),
218 .dev = {
219 .platform_data = &nand_flash_data,
220 },
221};
222
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000223static struct resource irda_resources[] = {
224 [0] = {
225 .start = 0xE6D00000,
226 .end = 0xE6D01FD4 - 1,
227 .flags = IORESOURCE_MEM,
228 },
229 [1] = {
Magnus Damm74905092010-05-20 14:35:30 +0000230 .start = evt2irq(0x480), /* IRDA */
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000231 .flags = IORESOURCE_IRQ,
232 },
233};
234
235static struct platform_device irda_device = {
236 .name = "sh_irda",
Kuninori Morimoto8a2b6be2010-06-08 06:25:17 +0000237 .id = -1,
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000238 .resource = irda_resources,
239 .num_resources = ARRAY_SIZE(irda_resources),
240};
241
Magnus Dammc793c1b2010-02-05 11:14:49 +0000242static struct platform_device *g3evm_devices[] __initdata = {
243 &nor_flash_device,
Magnus Damm3a7b8022010-02-10 20:13:31 +0900244 &usb_host_device,
Magnus Damm03fb2562010-02-16 10:48:15 +0000245 &keysc_device,
Magnus Damm143f3b82010-02-19 09:54:06 +0000246 &nand_flash_device,
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000247 &irda_device,
Magnus Dammc793c1b2010-02-05 11:14:49 +0000248};
249
250static struct map_desc g3evm_io_desc[] __initdata = {
251 /* create a 1:1 entity map for 0xe6xxxxxx
252 * used by CPGA, INTC and PFC.
253 */
254 {
255 .virtual = 0xe6000000,
256 .pfn = __phys_to_pfn(0xe6000000),
257 .length = 256 << 20,
258 .type = MT_DEVICE_NONSHARED
259 },
260};
261
262static void __init g3evm_map_io(void)
263{
264 iotable_init(g3evm_io_desc, ARRAY_SIZE(g3evm_io_desc));
265
Magnus Damm4f0836b2010-05-20 14:49:28 +0000266 /* setup early devices and console here as well */
Magnus Dammc793c1b2010-02-05 11:14:49 +0000267 sh7367_add_early_devices();
Magnus Damm4ae04ac2010-02-08 11:02:54 +0000268 shmobile_setup_console();
Magnus Dammc793c1b2010-02-05 11:14:49 +0000269}
270
271static void __init g3evm_init(void)
272{
Magnus Damm7fdda672010-02-10 20:10:55 +0900273 sh7367_pinmux_init();
274
275 /* Lit DS4 LED */
276 gpio_request(GPIO_PORT22, NULL);
277 gpio_direction_output(GPIO_PORT22, 1);
278 gpio_export(GPIO_PORT22, 0);
279
280 /* Lit DS8 LED */
281 gpio_request(GPIO_PORT23, NULL);
282 gpio_direction_output(GPIO_PORT23, 1);
283 gpio_export(GPIO_PORT23, 0);
284
285 /* Lit DS3 LED */
286 gpio_request(GPIO_PORT24, NULL);
287 gpio_direction_output(GPIO_PORT24, 1);
288 gpio_export(GPIO_PORT24, 0);
289
290 /* SCIFA1 */
291 gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
292 gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
293 gpio_request(GPIO_FN_SCIFA1_CTS, NULL);
294 gpio_request(GPIO_FN_SCIFA1_RTS, NULL);
295
Magnus Damm3a7b8022010-02-10 20:13:31 +0900296 /* USBHS */
297 gpio_request(GPIO_FN_VBUS0, NULL);
298 gpio_request(GPIO_FN_PWEN, NULL);
299 gpio_request(GPIO_FN_OVCN, NULL);
300 gpio_request(GPIO_FN_OVCN2, NULL);
301 gpio_request(GPIO_FN_EXTLP, NULL);
302 gpio_request(GPIO_FN_IDIN, NULL);
303
Magnus Damm3a7b8022010-02-10 20:13:31 +0900304 /* setup USB phy */
305 __raw_writew(0x0300, 0xe605810a); /* USBCR1 */
306 __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
307 __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */
308 __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */
309
Magnus Damm03fb2562010-02-16 10:48:15 +0000310 /* KEYSC @ CN7 */
311 gpio_request(GPIO_FN_PORT42_KEYOUT0, NULL);
312 gpio_request(GPIO_FN_PORT43_KEYOUT1, NULL);
313 gpio_request(GPIO_FN_PORT44_KEYOUT2, NULL);
314 gpio_request(GPIO_FN_PORT45_KEYOUT3, NULL);
315 gpio_request(GPIO_FN_PORT46_KEYOUT4, NULL);
316 gpio_request(GPIO_FN_PORT47_KEYOUT5, NULL);
317 gpio_request(GPIO_FN_PORT48_KEYIN0_PU, NULL);
318 gpio_request(GPIO_FN_PORT49_KEYIN1_PU, NULL);
319 gpio_request(GPIO_FN_PORT50_KEYIN2_PU, NULL);
320 gpio_request(GPIO_FN_PORT55_KEYIN3_PU, NULL);
321 gpio_request(GPIO_FN_PORT56_KEYIN4_PU, NULL);
322 gpio_request(GPIO_FN_PORT57_KEYIN5_PU, NULL);
323 gpio_request(GPIO_FN_PORT58_KEYIN6_PU, NULL);
324
Magnus Damm143f3b82010-02-19 09:54:06 +0000325 /* FLCTL */
326 gpio_request(GPIO_FN_FCE0, NULL);
327 gpio_request(GPIO_FN_D0_ED0_NAF0, NULL);
328 gpio_request(GPIO_FN_D1_ED1_NAF1, NULL);
329 gpio_request(GPIO_FN_D2_ED2_NAF2, NULL);
330 gpio_request(GPIO_FN_D3_ED3_NAF3, NULL);
331 gpio_request(GPIO_FN_D4_ED4_NAF4, NULL);
332 gpio_request(GPIO_FN_D5_ED5_NAF5, NULL);
333 gpio_request(GPIO_FN_D6_ED6_NAF6, NULL);
334 gpio_request(GPIO_FN_D7_ED7_NAF7, NULL);
335 gpio_request(GPIO_FN_D8_ED8_NAF8, NULL);
336 gpio_request(GPIO_FN_D9_ED9_NAF9, NULL);
337 gpio_request(GPIO_FN_D10_ED10_NAF10, NULL);
338 gpio_request(GPIO_FN_D11_ED11_NAF11, NULL);
339 gpio_request(GPIO_FN_D12_ED12_NAF12, NULL);
340 gpio_request(GPIO_FN_D13_ED13_NAF13, NULL);
341 gpio_request(GPIO_FN_D14_ED14_NAF14, NULL);
342 gpio_request(GPIO_FN_D15_ED15_NAF15, NULL);
343 gpio_request(GPIO_FN_WE0_XWR0_FWE, NULL);
344 gpio_request(GPIO_FN_FRB, NULL);
345 /* FOE, FCDE, FSC on dedicated pins */
346 __raw_writel(__raw_readl(0xe6158048) & ~(1 << 15), 0xe6158048);
347
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000348 /* IrDA */
349 gpio_request(GPIO_FN_IRDA_OUT, NULL);
350 gpio_request(GPIO_FN_IRDA_IN, NULL);
351 gpio_request(GPIO_FN_IRDA_FIRSEL, NULL);
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000352
Magnus Dammc793c1b2010-02-05 11:14:49 +0000353 sh7367_add_standard_devices();
354
355 platform_add_devices(g3evm_devices, ARRAY_SIZE(g3evm_devices));
356}
357
Magnus Damm4f0836b2010-05-20 14:49:28 +0000358static void __init g3evm_timer_init(void)
359{
360 sh7367_clock_init();
361 shmobile_timer.init();
362}
363
364static struct sys_timer g3evm_timer = {
365 .init = g3evm_timer_init,
366};
367
Magnus Dammc793c1b2010-02-05 11:14:49 +0000368MACHINE_START(G3EVM, "g3evm")
Magnus Dammc793c1b2010-02-05 11:14:49 +0000369 .map_io = g3evm_map_io,
370 .init_irq = sh7367_init_irq,
Magnus Damm863b1712010-12-28 08:27:01 +0000371 .handle_irq = shmobile_handle_irq_intc,
Magnus Dammc793c1b2010-02-05 11:14:49 +0000372 .init_machine = g3evm_init,
Magnus Damm4f0836b2010-05-20 14:49:28 +0000373 .timer = &g3evm_timer,
Magnus Dammc793c1b2010-02-05 11:14:49 +0000374MACHINE_END