blob: b627e89037f5e567d15101b1e3fe3051bbfa94c0 [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>
Magnus Damm7fdda672010-02-10 20:10:55 +090036#include <mach/sh7367.h>
Magnus Dammc793c1b2010-02-05 11:14:49 +000037#include <mach/common.h>
38#include <asm/mach-types.h>
39#include <asm/mach/arch.h>
Magnus Dammc793c1b2010-02-05 11:14:49 +000040
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +000041/*
42 * IrDA
43 *
44 * S67: 5bit : ON power
45 * : 6bit : ON remote control
46 * OFF IrDA
47 */
48
Magnus Dammc793c1b2010-02-05 11:14:49 +000049static struct mtd_partition nor_flash_partitions[] = {
50 {
51 .name = "loader",
52 .offset = 0x00000000,
53 .size = 512 * 1024,
54 },
55 {
56 .name = "bootenv",
57 .offset = MTDPART_OFS_APPEND,
58 .size = 512 * 1024,
59 },
60 {
61 .name = "kernel_ro",
62 .offset = MTDPART_OFS_APPEND,
63 .size = 8 * 1024 * 1024,
64 .mask_flags = MTD_WRITEABLE,
65 },
66 {
67 .name = "kernel",
68 .offset = MTDPART_OFS_APPEND,
69 .size = 8 * 1024 * 1024,
70 },
71 {
72 .name = "data",
73 .offset = MTDPART_OFS_APPEND,
74 .size = MTDPART_SIZ_FULL,
75 },
76};
77
78static struct physmap_flash_data nor_flash_data = {
79 .width = 2,
80 .parts = nor_flash_partitions,
81 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
82};
83
84static struct resource nor_flash_resources[] = {
85 [0] = {
86 .start = 0x00000000,
87 .end = 0x08000000 - 1,
88 .flags = IORESOURCE_MEM,
89 }
90};
91
92static struct platform_device nor_flash_device = {
93 .name = "physmap-flash",
94 .dev = {
95 .platform_data = &nor_flash_data,
96 },
97 .num_resources = ARRAY_SIZE(nor_flash_resources),
98 .resource = nor_flash_resources,
99};
100
Magnus Damm3a7b8022010-02-10 20:13:31 +0900101/* USBHS */
Kuninori Morimoto1c14e6c2010-06-02 00:25:19 +0000102static void usb_host_port_power(int port, int power)
Magnus Damm3a7b8022010-02-10 20:13:31 +0900103{
104 if (!power) /* only power-on supported for now */
105 return;
106
107 /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
108 __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
109}
110
111static struct r8a66597_platdata usb_host_data = {
112 .on_chip = 1,
113 .port_power = usb_host_port_power,
114};
115
116static struct resource usb_host_resources[] = {
117 [0] = {
118 .name = "USBHS",
119 .start = 0xe6890000,
120 .end = 0xe68900e5,
121 .flags = IORESOURCE_MEM,
122 },
123 [1] = {
Magnus Damm74905092010-05-20 14:35:30 +0000124 .start = evt2irq(0xa20), /* USBHS_USHI0 */
Magnus Damm3a7b8022010-02-10 20:13:31 +0900125 .flags = IORESOURCE_IRQ,
126 },
127};
128
129static struct platform_device usb_host_device = {
130 .name = "r8a66597_hcd",
131 .id = 0,
132 .dev = {
133 .platform_data = &usb_host_data,
134 .dma_mask = NULL,
135 .coherent_dma_mask = 0xffffffff,
136 },
137 .num_resources = ARRAY_SIZE(usb_host_resources),
138 .resource = usb_host_resources,
139};
Magnus Dammc793c1b2010-02-05 11:14:49 +0000140
Magnus Damm03fb2562010-02-16 10:48:15 +0000141/* KEYSC */
142static struct sh_keysc_info keysc_info = {
143 .mode = SH_KEYSC_MODE_5,
144 .scan_timing = 3,
145 .delay = 100,
146 .keycodes = {
147 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
148 KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N,
149 KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U,
150 KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP,
151 KEY_WAKEUP, KEY_COFFEE, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
152 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_STOP, KEY_COMPUTER,
153 },
154};
155
156static struct resource keysc_resources[] = {
157 [0] = {
158 .name = "KEYSC",
159 .start = 0xe61b0000,
160 .end = 0xe61b000f,
161 .flags = IORESOURCE_MEM,
162 },
163 [1] = {
Magnus Damm74905092010-05-20 14:35:30 +0000164 .start = evt2irq(0xbe0), /* KEYSC_KEY */
Magnus Damm03fb2562010-02-16 10:48:15 +0000165 .flags = IORESOURCE_IRQ,
166 },
167};
168
169static struct platform_device keysc_device = {
170 .name = "sh_keysc",
171 .num_resources = ARRAY_SIZE(keysc_resources),
172 .resource = keysc_resources,
173 .dev = {
174 .platform_data = &keysc_info,
175 },
176};
177
Magnus Damm143f3b82010-02-19 09:54:06 +0000178static struct mtd_partition nand_partition_info[] = {
179 {
180 .name = "system",
181 .offset = 0,
182 .size = 64 * 1024 * 1024,
183 },
184 {
185 .name = "userdata",
186 .offset = MTDPART_OFS_APPEND,
187 .size = 128 * 1024 * 1024,
188 },
189 {
190 .name = "cache",
191 .offset = MTDPART_OFS_APPEND,
192 .size = 64 * 1024 * 1024,
193 },
194};
195
196static struct resource nand_flash_resources[] = {
197 [0] = {
198 .start = 0xe6a30000,
199 .end = 0xe6a3009b,
200 .flags = IORESOURCE_MEM,
201 }
202};
203
204static struct sh_flctl_platform_data nand_flash_data = {
205 .parts = nand_partition_info,
206 .nr_parts = ARRAY_SIZE(nand_partition_info),
207 .flcmncr_val = QTSEL_E | FCKSEL_E | TYPESEL_SET | NANWF_E
208 | SHBUSSEL | SEL_16BIT,
209};
210
211static struct platform_device nand_flash_device = {
212 .name = "sh_flctl",
213 .resource = nand_flash_resources,
214 .num_resources = ARRAY_SIZE(nand_flash_resources),
215 .dev = {
216 .platform_data = &nand_flash_data,
217 },
218};
219
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000220static struct resource irda_resources[] = {
221 [0] = {
222 .start = 0xE6D00000,
223 .end = 0xE6D01FD4 - 1,
224 .flags = IORESOURCE_MEM,
225 },
226 [1] = {
Magnus Damm74905092010-05-20 14:35:30 +0000227 .start = evt2irq(0x480), /* IRDA */
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000228 .flags = IORESOURCE_IRQ,
229 },
230};
231
232static struct platform_device irda_device = {
233 .name = "sh_irda",
Kuninori Morimoto8a2b6be2010-06-08 06:25:17 +0000234 .id = -1,
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000235 .resource = irda_resources,
236 .num_resources = ARRAY_SIZE(irda_resources),
237};
238
Magnus Dammc793c1b2010-02-05 11:14:49 +0000239static struct platform_device *g3evm_devices[] __initdata = {
240 &nor_flash_device,
Magnus Damm3a7b8022010-02-10 20:13:31 +0900241 &usb_host_device,
Magnus Damm03fb2562010-02-16 10:48:15 +0000242 &keysc_device,
Magnus Damm143f3b82010-02-19 09:54:06 +0000243 &nand_flash_device,
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000244 &irda_device,
Magnus Dammc793c1b2010-02-05 11:14:49 +0000245};
246
Magnus Dammc793c1b2010-02-05 11:14:49 +0000247static void __init g3evm_init(void)
248{
Magnus Damm7fdda672010-02-10 20:10:55 +0900249 sh7367_pinmux_init();
250
251 /* Lit DS4 LED */
252 gpio_request(GPIO_PORT22, NULL);
253 gpio_direction_output(GPIO_PORT22, 1);
254 gpio_export(GPIO_PORT22, 0);
255
256 /* Lit DS8 LED */
257 gpio_request(GPIO_PORT23, NULL);
258 gpio_direction_output(GPIO_PORT23, 1);
259 gpio_export(GPIO_PORT23, 0);
260
261 /* Lit DS3 LED */
262 gpio_request(GPIO_PORT24, NULL);
263 gpio_direction_output(GPIO_PORT24, 1);
264 gpio_export(GPIO_PORT24, 0);
265
266 /* SCIFA1 */
267 gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
268 gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
269 gpio_request(GPIO_FN_SCIFA1_CTS, NULL);
270 gpio_request(GPIO_FN_SCIFA1_RTS, NULL);
271
Magnus Damm3a7b8022010-02-10 20:13:31 +0900272 /* USBHS */
273 gpio_request(GPIO_FN_VBUS0, NULL);
274 gpio_request(GPIO_FN_PWEN, NULL);
275 gpio_request(GPIO_FN_OVCN, NULL);
276 gpio_request(GPIO_FN_OVCN2, NULL);
277 gpio_request(GPIO_FN_EXTLP, NULL);
278 gpio_request(GPIO_FN_IDIN, NULL);
279
Magnus Damm3a7b8022010-02-10 20:13:31 +0900280 /* setup USB phy */
281 __raw_writew(0x0300, 0xe605810a); /* USBCR1 */
282 __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
283 __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */
284 __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */
285
Magnus Damm03fb2562010-02-16 10:48:15 +0000286 /* KEYSC @ CN7 */
287 gpio_request(GPIO_FN_PORT42_KEYOUT0, NULL);
288 gpio_request(GPIO_FN_PORT43_KEYOUT1, NULL);
289 gpio_request(GPIO_FN_PORT44_KEYOUT2, NULL);
290 gpio_request(GPIO_FN_PORT45_KEYOUT3, NULL);
291 gpio_request(GPIO_FN_PORT46_KEYOUT4, NULL);
292 gpio_request(GPIO_FN_PORT47_KEYOUT5, NULL);
293 gpio_request(GPIO_FN_PORT48_KEYIN0_PU, NULL);
294 gpio_request(GPIO_FN_PORT49_KEYIN1_PU, NULL);
295 gpio_request(GPIO_FN_PORT50_KEYIN2_PU, NULL);
296 gpio_request(GPIO_FN_PORT55_KEYIN3_PU, NULL);
297 gpio_request(GPIO_FN_PORT56_KEYIN4_PU, NULL);
298 gpio_request(GPIO_FN_PORT57_KEYIN5_PU, NULL);
299 gpio_request(GPIO_FN_PORT58_KEYIN6_PU, NULL);
300
Magnus Damm143f3b82010-02-19 09:54:06 +0000301 /* FLCTL */
302 gpio_request(GPIO_FN_FCE0, NULL);
303 gpio_request(GPIO_FN_D0_ED0_NAF0, NULL);
304 gpio_request(GPIO_FN_D1_ED1_NAF1, NULL);
305 gpio_request(GPIO_FN_D2_ED2_NAF2, NULL);
306 gpio_request(GPIO_FN_D3_ED3_NAF3, NULL);
307 gpio_request(GPIO_FN_D4_ED4_NAF4, NULL);
308 gpio_request(GPIO_FN_D5_ED5_NAF5, NULL);
309 gpio_request(GPIO_FN_D6_ED6_NAF6, NULL);
310 gpio_request(GPIO_FN_D7_ED7_NAF7, NULL);
311 gpio_request(GPIO_FN_D8_ED8_NAF8, NULL);
312 gpio_request(GPIO_FN_D9_ED9_NAF9, NULL);
313 gpio_request(GPIO_FN_D10_ED10_NAF10, NULL);
314 gpio_request(GPIO_FN_D11_ED11_NAF11, NULL);
315 gpio_request(GPIO_FN_D12_ED12_NAF12, NULL);
316 gpio_request(GPIO_FN_D13_ED13_NAF13, NULL);
317 gpio_request(GPIO_FN_D14_ED14_NAF14, NULL);
318 gpio_request(GPIO_FN_D15_ED15_NAF15, NULL);
319 gpio_request(GPIO_FN_WE0_XWR0_FWE, NULL);
320 gpio_request(GPIO_FN_FRB, NULL);
321 /* FOE, FCDE, FSC on dedicated pins */
322 __raw_writel(__raw_readl(0xe6158048) & ~(1 << 15), 0xe6158048);
323
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000324 /* IrDA */
325 gpio_request(GPIO_FN_IRDA_OUT, NULL);
326 gpio_request(GPIO_FN_IRDA_IN, NULL);
327 gpio_request(GPIO_FN_IRDA_FIRSEL, NULL);
Kuninori Morimoto85f91dd2010-05-13 01:07:54 +0000328
Magnus Dammc793c1b2010-02-05 11:14:49 +0000329 sh7367_add_standard_devices();
330
331 platform_add_devices(g3evm_devices, ARRAY_SIZE(g3evm_devices));
332}
333
334MACHINE_START(G3EVM, "g3evm")
Magnus Damm237caf92012-02-29 21:37:04 +0900335 .map_io = sh7367_map_io,
336 .init_early = sh7367_add_early_devices,
Magnus Dammc793c1b2010-02-05 11:14:49 +0000337 .init_irq = sh7367_init_irq,
Magnus Damm863b1712010-12-28 08:27:01 +0000338 .handle_irq = shmobile_handle_irq_intc,
Magnus Dammc793c1b2010-02-05 11:14:49 +0000339 .init_machine = g3evm_init,
Magnus Damm9e8de442012-03-06 17:36:22 +0900340 .timer = &shmobile_timer,
Magnus Dammc793c1b2010-02-05 11:14:49 +0000341MACHINE_END