4 * Copyright (C) 2010 Magnus Damm
5 * Copyright (C) 2008 Yoshihiro Shimoda
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.
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.
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
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>
29 #include <linux/mtd/sh_flctl.h>
30 #include <linux/usb/r8a66597.h>
32 #include <linux/gpio.h>
33 #include <linux/input.h>
34 #include <linux/input/sh_keysc.h>
35 #include <mach/sh7367.h>
36 #include <mach/common.h>
37 #include <asm/mach-types.h>
38 #include <asm/mach/arch.h>
39 #include <asm/mach/map.h>
40 #include <asm/mach/time.h>
45 * S67: 5bit : ON power
46 * : 6bit : ON remote control
50 static struct mtd_partition nor_flash_partitions
[] = {
58 .offset
= MTDPART_OFS_APPEND
,
63 .offset
= MTDPART_OFS_APPEND
,
64 .size
= 8 * 1024 * 1024,
65 .mask_flags
= MTD_WRITEABLE
,
69 .offset
= MTDPART_OFS_APPEND
,
70 .size
= 8 * 1024 * 1024,
74 .offset
= MTDPART_OFS_APPEND
,
75 .size
= MTDPART_SIZ_FULL
,
79 static struct physmap_flash_data nor_flash_data
= {
81 .parts
= nor_flash_partitions
,
82 .nr_parts
= ARRAY_SIZE(nor_flash_partitions
),
85 static struct resource nor_flash_resources
[] = {
88 .end
= 0x08000000 - 1,
89 .flags
= IORESOURCE_MEM
,
93 static struct platform_device nor_flash_device
= {
94 .name
= "physmap-flash",
96 .platform_data
= &nor_flash_data
,
98 .num_resources
= ARRAY_SIZE(nor_flash_resources
),
99 .resource
= nor_flash_resources
,
103 static void usb_host_port_power(int port
, int power
)
105 if (!power
) /* only power-on supported for now */
108 /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
109 __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
112 static struct r8a66597_platdata usb_host_data
= {
114 .port_power
= usb_host_port_power
,
117 static struct resource usb_host_resources
[] = {
122 .flags
= IORESOURCE_MEM
,
125 .start
= evt2irq(0xa20), /* USBHS_USHI0 */
126 .flags
= IORESOURCE_IRQ
,
130 static struct platform_device usb_host_device
= {
131 .name
= "r8a66597_hcd",
134 .platform_data
= &usb_host_data
,
136 .coherent_dma_mask
= 0xffffffff,
138 .num_resources
= ARRAY_SIZE(usb_host_resources
),
139 .resource
= usb_host_resources
,
143 static struct sh_keysc_info keysc_info
= {
144 .mode
= SH_KEYSC_MODE_5
,
148 KEY_A
, KEY_B
, KEY_C
, KEY_D
, KEY_E
, KEY_F
, KEY_G
,
149 KEY_H
, KEY_I
, KEY_J
, KEY_K
, KEY_L
, KEY_M
, KEY_N
,
150 KEY_O
, KEY_P
, KEY_Q
, KEY_R
, KEY_S
, KEY_T
, KEY_U
,
151 KEY_V
, KEY_W
, KEY_X
, KEY_Y
, KEY_Z
, KEY_HOME
, KEY_SLEEP
,
152 KEY_WAKEUP
, KEY_COFFEE
, KEY_0
, KEY_1
, KEY_2
, KEY_3
, KEY_4
,
153 KEY_5
, KEY_6
, KEY_7
, KEY_8
, KEY_9
, KEY_STOP
, KEY_COMPUTER
,
157 static struct resource keysc_resources
[] = {
162 .flags
= IORESOURCE_MEM
,
165 .start
= evt2irq(0xbe0), /* KEYSC_KEY */
166 .flags
= IORESOURCE_IRQ
,
170 static struct platform_device keysc_device
= {
172 .num_resources
= ARRAY_SIZE(keysc_resources
),
173 .resource
= keysc_resources
,
175 .platform_data
= &keysc_info
,
179 static struct mtd_partition nand_partition_info
[] = {
183 .size
= 64 * 1024 * 1024,
187 .offset
= MTDPART_OFS_APPEND
,
188 .size
= 128 * 1024 * 1024,
192 .offset
= MTDPART_OFS_APPEND
,
193 .size
= 64 * 1024 * 1024,
197 static struct resource nand_flash_resources
[] = {
201 .flags
= IORESOURCE_MEM
,
205 static struct sh_flctl_platform_data nand_flash_data
= {
206 .parts
= nand_partition_info
,
207 .nr_parts
= ARRAY_SIZE(nand_partition_info
),
208 .flcmncr_val
= QTSEL_E
| FCKSEL_E
| TYPESEL_SET
| NANWF_E
209 | SHBUSSEL
| SEL_16BIT
,
212 static struct platform_device nand_flash_device
= {
214 .resource
= nand_flash_resources
,
215 .num_resources
= ARRAY_SIZE(nand_flash_resources
),
217 .platform_data
= &nand_flash_data
,
221 static struct resource irda_resources
[] = {
224 .end
= 0xE6D01FD4 - 1,
225 .flags
= IORESOURCE_MEM
,
228 .start
= evt2irq(0x480), /* IRDA */
229 .flags
= IORESOURCE_IRQ
,
233 static struct platform_device irda_device
= {
236 .resource
= irda_resources
,
237 .num_resources
= ARRAY_SIZE(irda_resources
),
240 static struct platform_device
*g3evm_devices
[] __initdata
= {
248 static struct map_desc g3evm_io_desc
[] __initdata
= {
249 /* create a 1:1 entity map for 0xe6xxxxxx
250 * used by CPGA, INTC and PFC.
253 .virtual = 0xe6000000,
254 .pfn
= __phys_to_pfn(0xe6000000),
256 .type
= MT_DEVICE_NONSHARED
260 static void __init
g3evm_map_io(void)
262 iotable_init(g3evm_io_desc
, ARRAY_SIZE(g3evm_io_desc
));
264 /* setup early devices and console here as well */
265 sh7367_add_early_devices();
266 shmobile_setup_console();
269 static void __init
g3evm_init(void)
271 sh7367_pinmux_init();
274 gpio_request(GPIO_PORT22
, NULL
);
275 gpio_direction_output(GPIO_PORT22
, 1);
276 gpio_export(GPIO_PORT22
, 0);
279 gpio_request(GPIO_PORT23
, NULL
);
280 gpio_direction_output(GPIO_PORT23
, 1);
281 gpio_export(GPIO_PORT23
, 0);
284 gpio_request(GPIO_PORT24
, NULL
);
285 gpio_direction_output(GPIO_PORT24
, 1);
286 gpio_export(GPIO_PORT24
, 0);
289 gpio_request(GPIO_FN_SCIFA1_TXD
, NULL
);
290 gpio_request(GPIO_FN_SCIFA1_RXD
, NULL
);
291 gpio_request(GPIO_FN_SCIFA1_CTS
, NULL
);
292 gpio_request(GPIO_FN_SCIFA1_RTS
, NULL
);
295 gpio_request(GPIO_FN_VBUS0
, NULL
);
296 gpio_request(GPIO_FN_PWEN
, NULL
);
297 gpio_request(GPIO_FN_OVCN
, NULL
);
298 gpio_request(GPIO_FN_OVCN2
, NULL
);
299 gpio_request(GPIO_FN_EXTLP
, NULL
);
300 gpio_request(GPIO_FN_IDIN
, NULL
);
303 __raw_writew(0x0300, 0xe605810a); /* USBCR1 */
304 __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
305 __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */
306 __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */
309 gpio_request(GPIO_FN_PORT42_KEYOUT0
, NULL
);
310 gpio_request(GPIO_FN_PORT43_KEYOUT1
, NULL
);
311 gpio_request(GPIO_FN_PORT44_KEYOUT2
, NULL
);
312 gpio_request(GPIO_FN_PORT45_KEYOUT3
, NULL
);
313 gpio_request(GPIO_FN_PORT46_KEYOUT4
, NULL
);
314 gpio_request(GPIO_FN_PORT47_KEYOUT5
, NULL
);
315 gpio_request(GPIO_FN_PORT48_KEYIN0_PU
, NULL
);
316 gpio_request(GPIO_FN_PORT49_KEYIN1_PU
, NULL
);
317 gpio_request(GPIO_FN_PORT50_KEYIN2_PU
, NULL
);
318 gpio_request(GPIO_FN_PORT55_KEYIN3_PU
, NULL
);
319 gpio_request(GPIO_FN_PORT56_KEYIN4_PU
, NULL
);
320 gpio_request(GPIO_FN_PORT57_KEYIN5_PU
, NULL
);
321 gpio_request(GPIO_FN_PORT58_KEYIN6_PU
, NULL
);
324 gpio_request(GPIO_FN_FCE0
, NULL
);
325 gpio_request(GPIO_FN_D0_ED0_NAF0
, NULL
);
326 gpio_request(GPIO_FN_D1_ED1_NAF1
, NULL
);
327 gpio_request(GPIO_FN_D2_ED2_NAF2
, NULL
);
328 gpio_request(GPIO_FN_D3_ED3_NAF3
, NULL
);
329 gpio_request(GPIO_FN_D4_ED4_NAF4
, NULL
);
330 gpio_request(GPIO_FN_D5_ED5_NAF5
, NULL
);
331 gpio_request(GPIO_FN_D6_ED6_NAF6
, NULL
);
332 gpio_request(GPIO_FN_D7_ED7_NAF7
, NULL
);
333 gpio_request(GPIO_FN_D8_ED8_NAF8
, NULL
);
334 gpio_request(GPIO_FN_D9_ED9_NAF9
, NULL
);
335 gpio_request(GPIO_FN_D10_ED10_NAF10
, NULL
);
336 gpio_request(GPIO_FN_D11_ED11_NAF11
, NULL
);
337 gpio_request(GPIO_FN_D12_ED12_NAF12
, NULL
);
338 gpio_request(GPIO_FN_D13_ED13_NAF13
, NULL
);
339 gpio_request(GPIO_FN_D14_ED14_NAF14
, NULL
);
340 gpio_request(GPIO_FN_D15_ED15_NAF15
, NULL
);
341 gpio_request(GPIO_FN_WE0_XWR0_FWE
, NULL
);
342 gpio_request(GPIO_FN_FRB
, NULL
);
343 /* FOE, FCDE, FSC on dedicated pins */
344 __raw_writel(__raw_readl(0xe6158048) & ~(1 << 15), 0xe6158048);
347 gpio_request(GPIO_FN_IRDA_OUT
, NULL
);
348 gpio_request(GPIO_FN_IRDA_IN
, NULL
);
349 gpio_request(GPIO_FN_IRDA_FIRSEL
, NULL
);
350 set_irq_type(evt2irq(0x480), IRQ_TYPE_LEVEL_LOW
);
352 sh7367_add_standard_devices();
354 platform_add_devices(g3evm_devices
, ARRAY_SIZE(g3evm_devices
));
357 static void __init
g3evm_timer_init(void)
360 shmobile_timer
.init();
363 static struct sys_timer g3evm_timer
= {
364 .init
= g3evm_timer_init
,
367 MACHINE_START(G3EVM
, "g3evm")
368 .map_io
= g3evm_map_io
,
369 .init_irq
= sh7367_init_irq
,
370 .handle_irq
= shmobile_handle_irq_intc
,
371 .init_machine
= g3evm_init
,
372 .timer
= &g3evm_timer
,