d3b8ca5d4041d07db3271079c22ecb0e13add0e2
[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/i2c.h>
30 #include <linux/i2c/tsc2007.h>
31 #include <linux/io.h>
32 #include <linux/smsc911x.h>
33 #include <linux/gpio.h>
34 #include <linux/input.h>
35 #include <linux/input/sh_keysc.h>
36 #include <linux/usb/r8a66597.h>
37 #include <mach/common.h>
38 #include <mach/sh7372.h>
39 #include <asm/mach-types.h>
40 #include <asm/mach/arch.h>
41 #include <asm/mach/map.h>
42
43 /*
44  * Address      Interface               BusWidth        note
45  * ------------------------------------------------------------------
46  * 0x0000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = ON
47  * 0x0800_0000  user area               -
48  * 0x1000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = OFF
49  * 0x1400_0000  Ether (LAN9220)         16bit
50  * 0x1600_0000  user area               -               cannot use with NAND
51  * 0x1800_0000  user area               -
52  * 0x1A00_0000  -
53  * 0x4000_0000  LPDDR2-SDRAM (POP)      32bit
54  */
55
56 /*
57  * NOR Flash ROM
58  *
59  *  SW1  |     SW2    | SW7  | NOR Flash ROM
60  *  bit1 | bit1  bit2 | bit1 | Memory allocation
61  * ------+------------+------+------------------
62  *  OFF  | ON     OFF | ON   |    Area 0
63  *  OFF  | ON     OFF | OFF  |    Area 4
64  */
65
66 /*
67  * NAND Flash ROM
68  *
69  *  SW1  |     SW2    | SW7  | NAND Flash ROM
70  *  bit1 | bit1  bit2 | bit2 | Memory allocation
71  * ------+------------+------+------------------
72  *  OFF  | ON     OFF | ON   |    FCE 0
73  *  OFF  | ON     OFF | OFF  |    FCE 1
74  */
75
76 /*
77  * SMSC 9220
78  *
79  *  SW1         SMSC 9220
80  * -----------------------
81  *  ON          access disable
82  *  OFF         access enable
83  */
84
85 /*
86  * LCD / IRQ / KEYSC / IrDA
87  *
88  * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (TouchScreen)
89  * LCD = 2nd LCDC
90  *
91  *              |               SW43                    |
92  * SW3          |       ON              |       OFF     |
93  * -------------+-----------------------+---------------+
94  * ON           | KEY / IrDA            | LCD           |
95  * OFF          | KEY / IrDA / IRQ      | IRQ           |
96  */
97
98 /*
99  * USB
100  *
101  * J7 : 1-2  MAX3355E VBUS
102  *      2-3  DC 5.0V
103  *
104  * S39: bit2: off
105  */
106
107 /* MTD */
108 static struct mtd_partition nor_flash_partitions[] = {
109         {
110                 .name           = "loader",
111                 .offset         = 0x00000000,
112                 .size           = 512 * 1024,
113         },
114         {
115                 .name           = "bootenv",
116                 .offset         = MTDPART_OFS_APPEND,
117                 .size           = 512 * 1024,
118         },
119         {
120                 .name           = "kernel_ro",
121                 .offset         = MTDPART_OFS_APPEND,
122                 .size           = 8 * 1024 * 1024,
123                 .mask_flags     = MTD_WRITEABLE,
124         },
125         {
126                 .name           = "kernel",
127                 .offset         = MTDPART_OFS_APPEND,
128                 .size           = 8 * 1024 * 1024,
129         },
130         {
131                 .name           = "data",
132                 .offset         = MTDPART_OFS_APPEND,
133                 .size           = MTDPART_SIZ_FULL,
134         },
135 };
136
137 static struct physmap_flash_data nor_flash_data = {
138         .width          = 2,
139         .parts          = nor_flash_partitions,
140         .nr_parts       = ARRAY_SIZE(nor_flash_partitions),
141 };
142
143 static struct resource nor_flash_resources[] = {
144         [0]     = {
145                 .start  = 0x00000000,
146                 .end    = 0x08000000 - 1,
147                 .flags  = IORESOURCE_MEM,
148         }
149 };
150
151 static struct platform_device nor_flash_device = {
152         .name           = "physmap-flash",
153         .dev            = {
154                 .platform_data  = &nor_flash_data,
155         },
156         .num_resources  = ARRAY_SIZE(nor_flash_resources),
157         .resource       = nor_flash_resources,
158 };
159
160 /* SMSC 9220 */
161 static struct resource smc911x_resources[] = {
162         {
163                 .start  = 0x14000000,
164                 .end    = 0x16000000 - 1,
165                 .flags  = IORESOURCE_MEM,
166         }, {
167                 .start  = 6,
168                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
169         },
170 };
171
172 static struct smsc911x_platform_config smsc911x_info = {
173         .flags          = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
174         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
175         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
176 };
177
178 static struct platform_device smc911x_device = {
179         .name           = "smsc911x",
180         .id             = -1,
181         .num_resources  = ARRAY_SIZE(smc911x_resources),
182         .resource       = smc911x_resources,
183         .dev            = {
184                 .platform_data = &smsc911x_info,
185         },
186 };
187
188 /* KEYSC (Needs SW43 set to ON) */
189 static struct sh_keysc_info keysc_info = {
190         .mode           = SH_KEYSC_MODE_1,
191         .scan_timing    = 3,
192         .delay          = 2500,
193         .keycodes = {
194                 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
195                 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
196                 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
197                 KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
198                 KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
199         },
200 };
201
202 static struct resource keysc_resources[] = {
203         [0] = {
204                 .name   = "KEYSC",
205                 .start  = 0xe61b0000,
206                 .end    = 0xe61b0063,
207                 .flags  = IORESOURCE_MEM,
208         },
209         [1] = {
210                 .start  = 79,
211                 .flags  = IORESOURCE_IRQ,
212         },
213 };
214
215 static struct platform_device keysc_device = {
216         .name           = "sh_keysc",
217         .id             = 0, /* "keysc0" clock */
218         .num_resources  = ARRAY_SIZE(keysc_resources),
219         .resource       = keysc_resources,
220         .dev    = {
221                 .platform_data  = &keysc_info,
222         },
223 };
224
225 /* SDHI0 */
226 static struct resource sdhi0_resources[] = {
227         [0] = {
228                 .name   = "SDHI0",
229                 .start  = 0xe6850000,
230                 .end    = 0xe68501ff,
231                 .flags  = IORESOURCE_MEM,
232         },
233         [1] = {
234                 .start  = 96,
235                 .flags  = IORESOURCE_IRQ,
236         },
237 };
238
239 static struct platform_device sdhi0_device = {
240         .name           = "sh_mobile_sdhi",
241         .num_resources  = ARRAY_SIZE(sdhi0_resources),
242         .resource       = sdhi0_resources,
243         .id             = 0,
244 };
245
246 /* USB1 */
247 void usb1_host_port_power(int port, int power)
248 {
249         if (!power) /* only power-on supported for now */
250                 return;
251
252         /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
253         __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
254 }
255
256 static struct r8a66597_platdata usb1_host_data = {
257         .on_chip        = 1,
258         .port_power     = usb1_host_port_power,
259 };
260
261 static struct resource usb1_host_resources[] = {
262         [0] = {
263                 .name   = "USBHS",
264                 .start  = 0xE68B0000,
265                 .end    = 0xE68B00E6 - 1,
266                 .flags  = IORESOURCE_MEM,
267         },
268         [1] = {
269                 .start  = 215,
270                 .end    = 215,
271                 .flags  = IORESOURCE_IRQ,
272         },
273 };
274
275 static struct platform_device usb1_host_device = {
276         .name   = "r8a66597_hcd",
277         .id     = 1,
278         .dev = {
279                 .dma_mask               = NULL,         /*  not use dma */
280                 .coherent_dma_mask      = 0xffffffff,
281                 .platform_data          = &usb1_host_data,
282         },
283         .num_resources  = ARRAY_SIZE(usb1_host_resources),
284         .resource       = usb1_host_resources,
285 };
286
287 static struct platform_device *ap4evb_devices[] __initdata = {
288         &nor_flash_device,
289         &smc911x_device,
290         &keysc_device,
291         &sdhi0_device,
292         &usb1_host_device,
293 };
294
295 /* TouchScreen (Needs SW3 set to OFF) */
296 #define IRQ28   396
297 struct tsc2007_platform_data tsc2007_info = {
298         .model                  = 2007,
299         .x_plate_ohms           = 180,
300 };
301
302 /* I2C */
303 static struct i2c_board_info i2c1_devices[] = {
304         {
305                 I2C_BOARD_INFO("r2025sd", 0x32),
306         },
307         {
308                 I2C_BOARD_INFO("tsc2007", 0x48),
309                 .type           = "tsc2007",
310                 .platform_data  = &tsc2007_info,
311                 .irq            = IRQ28,
312         },
313 };
314
315 static struct map_desc ap4evb_io_desc[] __initdata = {
316         /* create a 1:1 entity map for 0xe6xxxxxx
317          * used by CPGA, INTC and PFC.
318          */
319         {
320                 .virtual        = 0xe6000000,
321                 .pfn            = __phys_to_pfn(0xe6000000),
322                 .length         = 256 << 20,
323                 .type           = MT_DEVICE_NONSHARED
324         },
325 };
326
327 static void __init ap4evb_map_io(void)
328 {
329         iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
330
331         /* setup early devices, clocks and console here as well */
332         sh7372_add_early_devices();
333         sh7367_clock_init(); /* use g3 clocks for now */
334         shmobile_setup_console();
335 }
336
337 static void __init ap4evb_init(void)
338 {
339         sh7372_pinmux_init();
340
341         /* enable SCIFA0 */
342         gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
343         gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
344
345         /* enable SMSC911X */
346         gpio_request(GPIO_FN_CS5A,      NULL);
347         gpio_request(GPIO_FN_IRQ6_39,   NULL);
348
349         /* enable LED 1 - 4 */
350         gpio_request(GPIO_PORT185, NULL);
351         gpio_request(GPIO_PORT186, NULL);
352         gpio_request(GPIO_PORT187, NULL);
353         gpio_request(GPIO_PORT188, NULL);
354         gpio_direction_output(GPIO_PORT185, 1);
355         gpio_direction_output(GPIO_PORT186, 1);
356         gpio_direction_output(GPIO_PORT187, 1);
357         gpio_direction_output(GPIO_PORT188, 1);
358         gpio_export(GPIO_PORT185, 0);
359         gpio_export(GPIO_PORT186, 0);
360         gpio_export(GPIO_PORT187, 0);
361         gpio_export(GPIO_PORT188, 0);
362
363         /* enable Debug switch (S6) */
364         gpio_request(GPIO_PORT32, NULL);
365         gpio_request(GPIO_PORT33, NULL);
366         gpio_request(GPIO_PORT34, NULL);
367         gpio_request(GPIO_PORT35, NULL);
368         gpio_direction_input(GPIO_PORT32);
369         gpio_direction_input(GPIO_PORT33);
370         gpio_direction_input(GPIO_PORT34);
371         gpio_direction_input(GPIO_PORT35);
372         gpio_export(GPIO_PORT32, 0);
373         gpio_export(GPIO_PORT33, 0);
374         gpio_export(GPIO_PORT34, 0);
375         gpio_export(GPIO_PORT35, 0);
376
377         /* enable KEYSC */
378         gpio_request(GPIO_FN_KEYOUT0, NULL);
379         gpio_request(GPIO_FN_KEYOUT1, NULL);
380         gpio_request(GPIO_FN_KEYOUT2, NULL);
381         gpio_request(GPIO_FN_KEYOUT3, NULL);
382         gpio_request(GPIO_FN_KEYOUT4, NULL);
383         gpio_request(GPIO_FN_KEYIN0_136, NULL);
384         gpio_request(GPIO_FN_KEYIN1_135, NULL);
385         gpio_request(GPIO_FN_KEYIN2_134, NULL);
386         gpio_request(GPIO_FN_KEYIN3_133, NULL);
387         gpio_request(GPIO_FN_KEYIN4,     NULL);
388
389         /* SDHI0 */
390         gpio_request(GPIO_FN_SDHICD0, NULL);
391         gpio_request(GPIO_FN_SDHIWP0, NULL);
392         gpio_request(GPIO_FN_SDHICMD0, NULL);
393         gpio_request(GPIO_FN_SDHICLK0, NULL);
394         gpio_request(GPIO_FN_SDHID0_3, NULL);
395         gpio_request(GPIO_FN_SDHID0_2, NULL);
396         gpio_request(GPIO_FN_SDHID0_1, NULL);
397         gpio_request(GPIO_FN_SDHID0_0, NULL);
398
399         /* enable TouchScreen */
400         gpio_request(GPIO_FN_IRQ28_123, NULL);
401         set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
402
403         i2c_register_board_info(1, i2c1_devices,
404                                 ARRAY_SIZE(i2c1_devices));
405
406         /* USB enable */
407         gpio_request(GPIO_FN_VBUS0_1,    NULL);
408         gpio_request(GPIO_FN_IDIN_1_18,  NULL);
409         gpio_request(GPIO_FN_PWEN_1_115, NULL);
410         gpio_request(GPIO_FN_OVCN_1_114, NULL);
411         gpio_request(GPIO_FN_EXTLP_1,    NULL);
412         gpio_request(GPIO_FN_OVCN2_1,    NULL);
413
414         /* setup USB phy */
415         __raw_writew(0x8a0a, 0xE6058130);       /* USBCR2 */
416
417         sh7372_add_standard_devices();
418
419         platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
420 }
421
422 MACHINE_START(AP4EVB, "ap4evb")
423         .phys_io        = 0xe6000000,
424         .io_pg_offst    = ((0xe6000000) >> 18) & 0xfffc,
425         .map_io         = ap4evb_map_io,
426         .init_irq       = sh7372_init_irq,
427         .init_machine   = ap4evb_init,
428         .timer          = &shmobile_timer,
429 MACHINE_END