Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6
[pandora-kernel.git] / arch / arm / mach-shmobile / board-ap4evb.c
1 /*
2  * AP4EVB 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/io.h>
30 #include <linux/smsc911x.h>
31 #include <linux/gpio.h>
32 #include <linux/input.h>
33 #include <linux/input/sh_keysc.h>
34 #include <mach/common.h>
35 #include <mach/sh7372.h>
36 #include <asm/mach-types.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/map.h>
39
40 /*
41  * Address      Interface               BusWidth        note
42  * ------------------------------------------------------------------
43  * 0x0000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = ON
44  * 0x0800_0000  user area               -
45  * 0x1000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = OFF
46  * 0x1400_0000  Ether (LAN9220)         16bit
47  * 0x1600_0000  user area               -               cannot use with NAND
48  * 0x1800_0000  user area               -
49  * 0x1A00_0000  -
50  * 0x4000_0000  LPDDR2-SDRAM (POP)      32bit
51  */
52
53 /*
54  * NOR Flash ROM
55  *
56  *  SW1  |     SW2    | SW7  | NOR Flash ROM
57  *  bit1 | bit1  bit2 | bit1 | Memory allocation
58  * ------+------------+------+------------------
59  *  OFF  | ON     OFF | ON   |    Area 0
60  *  OFF  | ON     OFF | OFF  |    Area 4
61  */
62
63 /*
64  * NAND Flash ROM
65  *
66  *  SW1  |     SW2    | SW7  | NAND Flash ROM
67  *  bit1 | bit1  bit2 | bit2 | Memory allocation
68  * ------+------------+------+------------------
69  *  OFF  | ON     OFF | ON   |    FCE 0
70  *  OFF  | ON     OFF | OFF  |    FCE 1
71  */
72
73 /*
74  * SMSC 9220
75  *
76  *  SW1         SMSC 9220
77  * -----------------------
78  *  ON          access disable
79  *  OFF         access enable
80  */
81
82 /*
83  * KEYSC
84  *
85  * SW43         KEYSC
86  * -------------------------
87  * ON           enable
88  * OFF          disable
89  */
90
91 /* MTD */
92 static struct mtd_partition nor_flash_partitions[] = {
93         {
94                 .name           = "loader",
95                 .offset         = 0x00000000,
96                 .size           = 512 * 1024,
97         },
98         {
99                 .name           = "bootenv",
100                 .offset         = MTDPART_OFS_APPEND,
101                 .size           = 512 * 1024,
102         },
103         {
104                 .name           = "kernel_ro",
105                 .offset         = MTDPART_OFS_APPEND,
106                 .size           = 8 * 1024 * 1024,
107                 .mask_flags     = MTD_WRITEABLE,
108         },
109         {
110                 .name           = "kernel",
111                 .offset         = MTDPART_OFS_APPEND,
112                 .size           = 8 * 1024 * 1024,
113         },
114         {
115                 .name           = "data",
116                 .offset         = MTDPART_OFS_APPEND,
117                 .size           = MTDPART_SIZ_FULL,
118         },
119 };
120
121 static struct physmap_flash_data nor_flash_data = {
122         .width          = 2,
123         .parts          = nor_flash_partitions,
124         .nr_parts       = ARRAY_SIZE(nor_flash_partitions),
125 };
126
127 static struct resource nor_flash_resources[] = {
128         [0]     = {
129                 .start  = 0x00000000,
130                 .end    = 0x08000000 - 1,
131                 .flags  = IORESOURCE_MEM,
132         }
133 };
134
135 static struct platform_device nor_flash_device = {
136         .name           = "physmap-flash",
137         .dev            = {
138                 .platform_data  = &nor_flash_data,
139         },
140         .num_resources  = ARRAY_SIZE(nor_flash_resources),
141         .resource       = nor_flash_resources,
142 };
143
144 /* SMSC 9220 */
145 static struct resource smc911x_resources[] = {
146         {
147                 .start  = 0x14000000,
148                 .end    = 0x16000000 - 1,
149                 .flags  = IORESOURCE_MEM,
150         }, {
151                 .start  = 6,
152                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
153         },
154 };
155
156 static struct smsc911x_platform_config smsc911x_info = {
157         .flags          = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
158         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
159         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
160 };
161
162 static struct platform_device smc911x_device = {
163         .name           = "smsc911x",
164         .id             = -1,
165         .num_resources  = ARRAY_SIZE(smc911x_resources),
166         .resource       = smc911x_resources,
167         .dev            = {
168                 .platform_data = &smsc911x_info,
169         },
170 };
171
172 /* KEYSC (Needs SW43 set to ON) */
173 static struct sh_keysc_info keysc_info = {
174         .mode           = SH_KEYSC_MODE_1,
175         .scan_timing    = 3,
176         .delay          = 2500,
177         .keycodes = {
178                 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
179                 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
180                 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
181                 KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
182                 KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
183         },
184 };
185
186 static struct resource keysc_resources[] = {
187         [0] = {
188                 .name   = "KEYSC",
189                 .start  = 0xe61b0000,
190                 .end    = 0xe61b0063,
191                 .flags  = IORESOURCE_MEM,
192         },
193         [1] = {
194                 .start  = 79,
195                 .flags  = IORESOURCE_IRQ,
196         },
197 };
198
199 static struct platform_device keysc_device = {
200         .name           = "sh_keysc",
201         .id             = 0, /* "keysc0" clock */
202         .num_resources  = ARRAY_SIZE(keysc_resources),
203         .resource       = keysc_resources,
204         .dev    = {
205                 .platform_data  = &keysc_info,
206         },
207 };
208
209 static struct platform_device *ap4evb_devices[] __initdata = {
210         &nor_flash_device,
211         &smc911x_device,
212         &keysc_device,
213 };
214
215 static struct map_desc ap4evb_io_desc[] __initdata = {
216         /* create a 1:1 entity map for 0xe6xxxxxx
217          * used by CPGA, INTC and PFC.
218          */
219         {
220                 .virtual        = 0xe6000000,
221                 .pfn            = __phys_to_pfn(0xe6000000),
222                 .length         = 256 << 20,
223                 .type           = MT_DEVICE_NONSHARED
224         },
225 };
226
227 static void __init ap4evb_map_io(void)
228 {
229         iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
230
231         /* setup early devices, clocks and console here as well */
232         sh7372_add_early_devices();
233         sh7367_clock_init(); /* use g3 clocks for now */
234         shmobile_setup_console();
235 }
236
237 static void __init ap4evb_init(void)
238 {
239         sh7372_pinmux_init();
240
241         /* enable SCIFA0 */
242         gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
243         gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
244
245         /* enable SMSC911X */
246         gpio_request(GPIO_FN_CS5A,      NULL);
247         gpio_request(GPIO_FN_IRQ6_39,   NULL);
248
249         /* enable LED 1 - 4 */
250         gpio_request(GPIO_PORT185, NULL);
251         gpio_request(GPIO_PORT186, NULL);
252         gpio_request(GPIO_PORT187, NULL);
253         gpio_request(GPIO_PORT188, NULL);
254         gpio_direction_output(GPIO_PORT185, 1);
255         gpio_direction_output(GPIO_PORT186, 1);
256         gpio_direction_output(GPIO_PORT187, 1);
257         gpio_direction_output(GPIO_PORT188, 1);
258         gpio_export(GPIO_PORT185, 0);
259         gpio_export(GPIO_PORT186, 0);
260         gpio_export(GPIO_PORT187, 0);
261         gpio_export(GPIO_PORT188, 0);
262
263         /* enable Debug switch (S6) */
264         gpio_request(GPIO_PORT32, NULL);
265         gpio_request(GPIO_PORT33, NULL);
266         gpio_request(GPIO_PORT34, NULL);
267         gpio_request(GPIO_PORT35, NULL);
268         gpio_direction_input(GPIO_PORT32);
269         gpio_direction_input(GPIO_PORT33);
270         gpio_direction_input(GPIO_PORT34);
271         gpio_direction_input(GPIO_PORT35);
272         gpio_export(GPIO_PORT32, 0);
273         gpio_export(GPIO_PORT33, 0);
274         gpio_export(GPIO_PORT34, 0);
275         gpio_export(GPIO_PORT35, 0);
276
277         /* enable KEYSC */
278         gpio_request(GPIO_FN_KEYOUT0, NULL);
279         gpio_request(GPIO_FN_KEYOUT1, NULL);
280         gpio_request(GPIO_FN_KEYOUT2, NULL);
281         gpio_request(GPIO_FN_KEYOUT3, NULL);
282         gpio_request(GPIO_FN_KEYOUT4, NULL);
283         gpio_request(GPIO_FN_KEYIN0_136, NULL);
284         gpio_request(GPIO_FN_KEYIN1_135, NULL);
285         gpio_request(GPIO_FN_KEYIN2_134, NULL);
286         gpio_request(GPIO_FN_KEYIN3_133, NULL);
287         gpio_request(GPIO_FN_KEYIN4,     NULL);
288
289         sh7372_add_standard_devices();
290
291         platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
292 }
293
294 MACHINE_START(AP4EVB, "ap4evb")
295         .phys_io        = 0xe6000000,
296         .io_pg_offst    = ((0xe6000000) >> 18) & 0xfffc,
297         .map_io         = ap4evb_map_io,
298         .init_irq       = sh7372_init_irq,
299         .init_machine   = ap4evb_init,
300         .timer          = &shmobile_timer,
301 MACHINE_END