Merge branch 'master' of ../nf-2.6
[pandora-kernel.git] / arch / arm / mach-shmobile / board-g4evm.c
1 /*
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>
29 #include <linux/usb/r8a66597.h>
30 #include <linux/io.h>
31 #include <linux/gpio.h>
32 #include <mach/sh7377.h>
33 #include <mach/common.h>
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37
38 static struct mtd_partition nor_flash_partitions[] = {
39         {
40                 .name           = "loader",
41                 .offset         = 0x00000000,
42                 .size           = 512 * 1024,
43         },
44         {
45                 .name           = "bootenv",
46                 .offset         = MTDPART_OFS_APPEND,
47                 .size           = 512 * 1024,
48         },
49         {
50                 .name           = "kernel_ro",
51                 .offset         = MTDPART_OFS_APPEND,
52                 .size           = 8 * 1024 * 1024,
53                 .mask_flags     = MTD_WRITEABLE,
54         },
55         {
56                 .name           = "kernel",
57                 .offset         = MTDPART_OFS_APPEND,
58                 .size           = 8 * 1024 * 1024,
59         },
60         {
61                 .name           = "data",
62                 .offset         = MTDPART_OFS_APPEND,
63                 .size           = MTDPART_SIZ_FULL,
64         },
65 };
66
67 static struct physmap_flash_data nor_flash_data = {
68         .width          = 2,
69         .parts          = nor_flash_partitions,
70         .nr_parts       = ARRAY_SIZE(nor_flash_partitions),
71 };
72
73 static struct resource nor_flash_resources[] = {
74         [0]     = {
75                 .start  = 0x00000000,
76                 .end    = 0x08000000 - 1,
77                 .flags  = IORESOURCE_MEM,
78         }
79 };
80
81 static struct platform_device nor_flash_device = {
82         .name           = "physmap-flash",
83         .dev            = {
84                 .platform_data  = &nor_flash_data,
85         },
86         .num_resources  = ARRAY_SIZE(nor_flash_resources),
87         .resource       = nor_flash_resources,
88 };
89
90 /* USBHS */
91 void usb_host_port_power(int port, int power)
92 {
93         if (!power) /* only power-on supported for now */
94                 return;
95
96         /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
97         __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
98 }
99
100 static struct r8a66597_platdata usb_host_data = {
101         .on_chip = 1,
102         .port_power = usb_host_port_power,
103 };
104
105 static struct resource usb_host_resources[] = {
106         [0] = {
107                 .name   = "USBHS",
108                 .start  = 0xe6890000,
109                 .end    = 0xe68900e5,
110                 .flags  = IORESOURCE_MEM,
111         },
112         [1] = {
113                 .start  = 65,
114                 .end    = 65,
115                 .flags  = IORESOURCE_IRQ,
116         },
117 };
118
119 static struct platform_device usb_host_device = {
120         .name           = "r8a66597_hcd",
121         .id             = 0,
122         .dev = {
123                 .platform_data          = &usb_host_data,
124                 .dma_mask               = NULL,
125                 .coherent_dma_mask      = 0xffffffff,
126         },
127         .num_resources  = ARRAY_SIZE(usb_host_resources),
128         .resource       = usb_host_resources,
129 };
130
131 static struct platform_device *g4evm_devices[] __initdata = {
132         &nor_flash_device,
133         &usb_host_device,
134 };
135
136 static struct map_desc g4evm_io_desc[] __initdata = {
137         /* create a 1:1 entity map for 0xe6xxxxxx
138          * used by CPGA, INTC and PFC.
139          */
140         {
141                 .virtual        = 0xe6000000,
142                 .pfn            = __phys_to_pfn(0xe6000000),
143                 .length         = 256 << 20,
144                 .type           = MT_DEVICE_NONSHARED
145         },
146 };
147
148 static void __init g4evm_map_io(void)
149 {
150         iotable_init(g4evm_io_desc, ARRAY_SIZE(g4evm_io_desc));
151
152         /* setup early devices, clocks and console here as well */
153         sh7377_add_early_devices();
154         sh7367_clock_init(); /* use g3 clocks for now */
155         shmobile_setup_console();
156 }
157
158 static void __init g4evm_init(void)
159 {
160         sh7377_pinmux_init();
161
162         /* Lit DS14 LED */
163         gpio_request(GPIO_PORT109, NULL);
164         gpio_direction_output(GPIO_PORT109, 1);
165         gpio_export(GPIO_PORT109, 1);
166
167         /* Lit DS15 LED */
168         gpio_request(GPIO_PORT110, NULL);
169         gpio_direction_output(GPIO_PORT110, 1);
170         gpio_export(GPIO_PORT110, 1);
171
172         /* Lit DS16 LED */
173         gpio_request(GPIO_PORT112, NULL);
174         gpio_direction_output(GPIO_PORT112, 1);
175         gpio_export(GPIO_PORT112, 1);
176
177         /* Lit DS17 LED */
178         gpio_request(GPIO_PORT113, NULL);
179         gpio_direction_output(GPIO_PORT113, 1);
180         gpio_export(GPIO_PORT113, 1);
181
182         /* USBHS */
183         gpio_request(GPIO_FN_VBUS_0, NULL);
184         gpio_request(GPIO_FN_PWEN, NULL);
185         gpio_request(GPIO_FN_OVCN, NULL);
186         gpio_request(GPIO_FN_OVCN2, NULL);
187         gpio_request(GPIO_FN_EXTLP, NULL);
188         gpio_request(GPIO_FN_IDIN, NULL);
189
190         /* enable clock in SMSTPCR3 */
191         __raw_writel(__raw_readl(0xe615013c) & ~(1 << 22), 0xe615013c);
192
193         /* setup USB phy */
194         __raw_writew(0x0200, 0xe605810a);       /* USBCR1 */
195         __raw_writew(0x00e0, 0xe60581c0);       /* CPFCH */
196         __raw_writew(0x6010, 0xe60581c6);       /* CGPOSR */
197         __raw_writew(0x8a0a, 0xe605810c);       /* USBCR2 */
198
199         sh7377_add_standard_devices();
200
201         platform_add_devices(g4evm_devices, ARRAY_SIZE(g4evm_devices));
202 }
203
204 MACHINE_START(G4EVM, "g4evm")
205         .phys_io        = 0xe6000000,
206         .io_pg_offst    = ((0xe6000000) >> 18) & 0xfffc,
207         .map_io         = g4evm_map_io,
208         .init_irq       = sh7377_init_irq,
209         .init_machine   = g4evm_init,
210         .timer          = &shmobile_timer,
211 MACHINE_END