Merge branch 'bugfixes' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
[pandora-kernel.git] / arch / arm / mach-shmobile / board-kota2.c
1 /*
2  * kota2 board support
3  *
4  * Copyright (C) 2011  Renesas Solutions Corp.
5  * Copyright (C) 2011  Magnus Damm
6  * Copyright (C) 2010  Takashi Yoshii <yoshii.takashi.zj@renesas.com>
7  * Copyright (C) 2009  Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; version 2 of the License.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/interrupt.h>
26 #include <linux/irq.h>
27 #include <linux/platform_device.h>
28 #include <linux/delay.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 <linux/gpio_keys.h>
35 #include <linux/leds.h>
36 #include <linux/mmc/host.h>
37 #include <linux/mmc/sh_mmcif.h>
38 #include <linux/mfd/tmio.h>
39 #include <linux/mmc/sh_mobile_sdhi.h>
40 #include <mach/hardware.h>
41 #include <mach/sh73a0.h>
42 #include <mach/common.h>
43 #include <asm/mach-types.h>
44 #include <asm/mach/arch.h>
45 #include <asm/mach/map.h>
46 #include <asm/mach/time.h>
47 #include <asm/hardware/gic.h>
48 #include <asm/hardware/cache-l2x0.h>
49 #include <asm/traps.h>
50
51 /* SMSC 9220 */
52 static struct resource smsc9220_resources[] = {
53         [0] = {
54                 .start          = 0x14000000, /* CS5A */
55                 .end            = 0x140000ff, /* A1->A7 */
56                 .flags          = IORESOURCE_MEM,
57         },
58         [1] = {
59                 .start          = gic_spi(33), /* PINTA2 @ PORT144 */
60                 .flags          = IORESOURCE_IRQ,
61         },
62 };
63
64 static struct smsc911x_platform_config smsc9220_platdata = {
65         .flags          = SMSC911X_USE_32BIT, /* 32-bit SW on 16-bit HW bus */
66         .phy_interface  = PHY_INTERFACE_MODE_MII,
67         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
68         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
69 };
70
71 static struct platform_device eth_device = {
72         .name           = "smsc911x",
73         .id             = 0,
74         .dev  = {
75                 .platform_data = &smsc9220_platdata,
76         },
77         .resource       = smsc9220_resources,
78         .num_resources  = ARRAY_SIZE(smsc9220_resources),
79 };
80
81 /* KEYSC */
82 static struct sh_keysc_info keysc_platdata = {
83         .mode           = SH_KEYSC_MODE_6,
84         .scan_timing    = 3,
85         .delay          = 100,
86         .keycodes       = {
87                 KEY_NUMERIC_STAR, KEY_NUMERIC_0, KEY_NUMERIC_POUND,
88                 0, 0, 0, 0, 0,
89                 KEY_NUMERIC_7, KEY_NUMERIC_8, KEY_NUMERIC_9,
90                 0, KEY_DOWN, 0, 0, 0,
91                 KEY_NUMERIC_4, KEY_NUMERIC_5, KEY_NUMERIC_6,
92                 KEY_LEFT, KEY_ENTER, KEY_RIGHT, 0, 0,
93                 KEY_NUMERIC_1, KEY_NUMERIC_2, KEY_NUMERIC_3,
94                 0, KEY_UP, 0, 0, 0,
95                 0, 0, 0, 0, 0, 0, 0, 0,
96                 0, 0, 0, 0, 0, 0, 0, 0,
97                 0, 0, 0, 0, 0, 0, 0, 0,
98                 0, 0, 0, 0, 0, 0, 0, 0,
99         },
100 };
101
102 static struct resource keysc_resources[] = {
103         [0] = {
104                 .name   = "KEYSC",
105                 .start  = 0xe61b0000,
106                 .end    = 0xe61b0098 - 1,
107                 .flags  = IORESOURCE_MEM,
108         },
109         [1] = {
110                 .start  = gic_spi(71),
111                 .flags  = IORESOURCE_IRQ,
112         },
113 };
114
115 static struct platform_device keysc_device = {
116         .name           = "sh_keysc",
117         .id             = 0,
118         .num_resources  = ARRAY_SIZE(keysc_resources),
119         .resource       = keysc_resources,
120         .dev            = {
121                 .platform_data  = &keysc_platdata,
122         },
123 };
124
125 /* GPIO KEY */
126 #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
127
128 static struct gpio_keys_button gpio_buttons[] = {
129         GPIO_KEY(KEY_VOLUMEUP, GPIO_PORT56, "+"), /* S2: VOL+ [IRQ9] */
130         GPIO_KEY(KEY_VOLUMEDOWN, GPIO_PORT54, "-"), /* S3: VOL- [IRQ10] */
131         GPIO_KEY(KEY_MENU, GPIO_PORT27, "Menu"), /* S4: MENU [IRQ30] */
132         GPIO_KEY(KEY_HOMEPAGE, GPIO_PORT26, "Home"), /* S5: HOME [IRQ31] */
133         GPIO_KEY(KEY_BACK, GPIO_PORT11, "Back"), /* S6: BACK [IRQ0] */
134         GPIO_KEY(KEY_PHONE, GPIO_PORT238, "Tel"), /* S7: TEL [IRQ11] */
135         GPIO_KEY(KEY_POWER, GPIO_PORT239, "C1"), /* S8: CAM [IRQ13] */
136         GPIO_KEY(KEY_MAIL, GPIO_PORT224, "Mail"), /* S9: MAIL [IRQ3] */
137         /* Omitted button "C3?": GPIO_PORT223 - S10: CUST [IRQ8] */
138         GPIO_KEY(KEY_CAMERA, GPIO_PORT164, "C2"), /* S11: CAM_HALF [IRQ25] */
139         /* Omitted button "?": GPIO_PORT152 - S12: CAM_FULL [No IRQ] */
140 };
141
142 static struct gpio_keys_platform_data gpio_key_info = {
143         .buttons        = gpio_buttons,
144         .nbuttons       = ARRAY_SIZE(gpio_buttons),
145         .poll_interval  = 250, /* polled for now */
146 };
147
148 static struct platform_device gpio_keys_device = {
149         .name   = "gpio-keys-polled", /* polled for now */
150         .id     = -1,
151         .dev    = {
152                 .platform_data  = &gpio_key_info,
153         },
154 };
155
156 /* GPIO LED */
157 #define GPIO_LED(n, g) { .name = n, .gpio = g }
158
159 static struct gpio_led gpio_leds[] = {
160         GPIO_LED("V2513", GPIO_PORT153), /* PORT153 [TPU1T02] -> V2513 */
161         GPIO_LED("V2514", GPIO_PORT199), /* PORT199 [TPU4TO1] -> V2514 */
162         GPIO_LED("V2515", GPIO_PORT197), /* PORT197 [TPU2TO1] -> V2515 */
163         GPIO_LED("KEYLED", GPIO_PORT163), /* PORT163 [TPU3TO0] -> KEYLED */
164         GPIO_LED("G", GPIO_PORT20), /* PORT20 [GPO0] -> LED7 -> "G" */
165         GPIO_LED("H", GPIO_PORT21), /* PORT21 [GPO1] -> LED8 -> "H" */
166         GPIO_LED("J", GPIO_PORT22), /* PORT22 [GPO2] -> LED9 -> "J" */
167 };
168
169 static struct gpio_led_platform_data gpio_leds_info = {
170         .leds           = gpio_leds,
171         .num_leds       = ARRAY_SIZE(gpio_leds),
172 };
173
174 static struct platform_device gpio_leds_device = {
175         .name   = "leds-gpio",
176         .id     = -1,
177         .dev    = {
178                 .platform_data  = &gpio_leds_info,
179         },
180 };
181
182 /* MMCIF */
183 static struct resource mmcif_resources[] = {
184         [0] = {
185                 .name   = "MMCIF",
186                 .start  = 0xe6bd0000,
187                 .end    = 0xe6bd00ff,
188                 .flags  = IORESOURCE_MEM,
189         },
190         [1] = {
191                 .start  = gic_spi(140),
192                 .flags  = IORESOURCE_IRQ,
193         },
194         [2] = {
195                 .start  = gic_spi(141),
196                 .flags  = IORESOURCE_IRQ,
197         },
198 };
199
200 static struct sh_mmcif_plat_data mmcif_info = {
201         .ocr            = MMC_VDD_165_195,
202         .caps           = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
203 };
204
205 static struct platform_device mmcif_device = {
206         .name           = "sh_mmcif",
207         .id             = 0,
208         .dev            = {
209                 .platform_data          = &mmcif_info,
210         },
211         .num_resources  = ARRAY_SIZE(mmcif_resources),
212         .resource       = mmcif_resources,
213 };
214
215 /* SDHI0 */
216 static struct sh_mobile_sdhi_info sdhi0_info = {
217         .tmio_caps      = MMC_CAP_SD_HIGHSPEED,
218         .tmio_flags     = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_HAS_IDLE_WAIT,
219 };
220
221 static struct resource sdhi0_resources[] = {
222         [0] = {
223                 .name   = "SDHI0",
224                 .start  = 0xee100000,
225                 .end    = 0xee1000ff,
226                 .flags  = IORESOURCE_MEM,
227         },
228         [1] = {
229                 .start  = gic_spi(83),
230                 .flags  = IORESOURCE_IRQ,
231         },
232         [2] = {
233                 .start  = gic_spi(84),
234                 .flags  = IORESOURCE_IRQ,
235         },
236         [3] = {
237                 .start  = gic_spi(85),
238                 .flags  = IORESOURCE_IRQ,
239         },
240 };
241
242 static struct platform_device sdhi0_device = {
243         .name           = "sh_mobile_sdhi",
244         .id             = 0,
245         .num_resources  = ARRAY_SIZE(sdhi0_resources),
246         .resource       = sdhi0_resources,
247         .dev    = {
248                 .platform_data  = &sdhi0_info,
249         },
250 };
251
252 /* SDHI1 */
253 static struct sh_mobile_sdhi_info sdhi1_info = {
254         .tmio_caps      = MMC_CAP_NONREMOVABLE | MMC_CAP_SDIO_IRQ,
255         .tmio_flags     = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_HAS_IDLE_WAIT,
256 };
257
258 static struct resource sdhi1_resources[] = {
259         [0] = {
260                 .name   = "SDHI1",
261                 .start  = 0xee120000,
262                 .end    = 0xee1200ff,
263                 .flags  = IORESOURCE_MEM,
264         },
265         [1] = {
266                 .start  = gic_spi(87),
267                 .flags  = IORESOURCE_IRQ,
268         },
269         [2] = {
270                 .start  = gic_spi(88),
271                 .flags  = IORESOURCE_IRQ,
272         },
273         [3] = {
274                 .start  = gic_spi(89),
275                 .flags  = IORESOURCE_IRQ,
276         },
277 };
278
279 static struct platform_device sdhi1_device = {
280         .name           = "sh_mobile_sdhi",
281         .id             = 1,
282         .num_resources  = ARRAY_SIZE(sdhi1_resources),
283         .resource       = sdhi1_resources,
284         .dev    = {
285                 .platform_data  = &sdhi1_info,
286         },
287 };
288
289 static struct platform_device *kota2_devices[] __initdata = {
290         &eth_device,
291         &keysc_device,
292         &gpio_keys_device,
293         &gpio_leds_device,
294         &mmcif_device,
295         &sdhi0_device,
296         &sdhi1_device,
297 };
298
299 static struct map_desc kota2_io_desc[] __initdata = {
300         /* create a 1:1 entity map for 0xe6xxxxxx
301          * used by CPGA, INTC and PFC.
302          */
303         {
304                 .virtual        = 0xe6000000,
305                 .pfn            = __phys_to_pfn(0xe6000000),
306                 .length         = 256 << 20,
307                 .type           = MT_DEVICE_NONSHARED
308         },
309 };
310
311 static void __init kota2_map_io(void)
312 {
313         iotable_init(kota2_io_desc, ARRAY_SIZE(kota2_io_desc));
314
315         /* setup early devices and console here as well */
316         sh73a0_add_early_devices();
317         shmobile_setup_console();
318 }
319
320 #define PINTER0A        0xe69000a0
321 #define PINTCR0A        0xe69000b0
322
323 void __init kota2_init_irq(void)
324 {
325         sh73a0_init_irq();
326
327         /* setup PINT: enable PINTA2 as active low */
328         __raw_writel(1 << 29, PINTER0A);
329         __raw_writew(2 << 10, PINTCR0A);
330 }
331
332 static void __init kota2_init(void)
333 {
334         sh73a0_pinmux_init();
335
336         /* SCIFA2 (UART2) */
337         gpio_request(GPIO_FN_SCIFA2_TXD1, NULL);
338         gpio_request(GPIO_FN_SCIFA2_RXD1, NULL);
339         gpio_request(GPIO_FN_SCIFA2_RTS1_, NULL);
340         gpio_request(GPIO_FN_SCIFA2_CTS1_, NULL);
341
342         /* SCIFA4 (UART1) */
343         gpio_request(GPIO_FN_SCIFA4_TXD, NULL);
344         gpio_request(GPIO_FN_SCIFA4_RXD, NULL);
345         gpio_request(GPIO_FN_SCIFA4_RTS_, NULL);
346         gpio_request(GPIO_FN_SCIFA4_CTS_, NULL);
347
348         /* SMSC911X */
349         gpio_request(GPIO_FN_D0_NAF0, NULL);
350         gpio_request(GPIO_FN_D1_NAF1, NULL);
351         gpio_request(GPIO_FN_D2_NAF2, NULL);
352         gpio_request(GPIO_FN_D3_NAF3, NULL);
353         gpio_request(GPIO_FN_D4_NAF4, NULL);
354         gpio_request(GPIO_FN_D5_NAF5, NULL);
355         gpio_request(GPIO_FN_D6_NAF6, NULL);
356         gpio_request(GPIO_FN_D7_NAF7, NULL);
357         gpio_request(GPIO_FN_D8_NAF8, NULL);
358         gpio_request(GPIO_FN_D9_NAF9, NULL);
359         gpio_request(GPIO_FN_D10_NAF10, NULL);
360         gpio_request(GPIO_FN_D11_NAF11, NULL);
361         gpio_request(GPIO_FN_D12_NAF12, NULL);
362         gpio_request(GPIO_FN_D13_NAF13, NULL);
363         gpio_request(GPIO_FN_D14_NAF14, NULL);
364         gpio_request(GPIO_FN_D15_NAF15, NULL);
365         gpio_request(GPIO_FN_CS5A_, NULL);
366         gpio_request(GPIO_FN_WE0__FWE, NULL);
367         gpio_request(GPIO_PORT144, NULL); /* PINTA2 */
368         gpio_direction_input(GPIO_PORT144);
369         gpio_request(GPIO_PORT145, NULL); /* RESET */
370         gpio_direction_output(GPIO_PORT145, 1);
371
372         /* KEYSC */
373         gpio_request(GPIO_FN_KEYIN0_PU, NULL);
374         gpio_request(GPIO_FN_KEYIN1_PU, NULL);
375         gpio_request(GPIO_FN_KEYIN2_PU, NULL);
376         gpio_request(GPIO_FN_KEYIN3_PU, NULL);
377         gpio_request(GPIO_FN_KEYIN4_PU, NULL);
378         gpio_request(GPIO_FN_KEYIN5_PU, NULL);
379         gpio_request(GPIO_FN_KEYIN6_PU, NULL);
380         gpio_request(GPIO_FN_KEYIN7_PU, NULL);
381         gpio_request(GPIO_FN_KEYOUT0, NULL);
382         gpio_request(GPIO_FN_KEYOUT1, NULL);
383         gpio_request(GPIO_FN_KEYOUT2, NULL);
384         gpio_request(GPIO_FN_KEYOUT3, NULL);
385         gpio_request(GPIO_FN_KEYOUT4, NULL);
386         gpio_request(GPIO_FN_KEYOUT5, NULL);
387         gpio_request(GPIO_FN_PORT59_KEYOUT6, NULL);
388         gpio_request(GPIO_FN_PORT58_KEYOUT7, NULL);
389         gpio_request(GPIO_FN_KEYOUT8, NULL);
390
391         /* MMCIF */
392         gpio_request(GPIO_FN_MMCCLK0, NULL);
393         gpio_request(GPIO_FN_MMCD0_0, NULL);
394         gpio_request(GPIO_FN_MMCD0_1, NULL);
395         gpio_request(GPIO_FN_MMCD0_2, NULL);
396         gpio_request(GPIO_FN_MMCD0_3, NULL);
397         gpio_request(GPIO_FN_MMCD0_4, NULL);
398         gpio_request(GPIO_FN_MMCD0_5, NULL);
399         gpio_request(GPIO_FN_MMCD0_6, NULL);
400         gpio_request(GPIO_FN_MMCD0_7, NULL);
401         gpio_request(GPIO_FN_MMCCMD0, NULL);
402         gpio_request(GPIO_PORT208, NULL); /* Reset */
403         gpio_direction_output(GPIO_PORT208, 1);
404
405         /* SDHI0 (microSD) */
406         gpio_request(GPIO_FN_SDHICD0_PU, NULL);
407         gpio_request(GPIO_FN_SDHICMD0_PU, NULL);
408         gpio_request(GPIO_FN_SDHICLK0, NULL);
409         gpio_request(GPIO_FN_SDHID0_3_PU, NULL);
410         gpio_request(GPIO_FN_SDHID0_2_PU, NULL);
411         gpio_request(GPIO_FN_SDHID0_1_PU, NULL);
412         gpio_request(GPIO_FN_SDHID0_0_PU, NULL);
413
414         /* SCIFB (BT) */
415         gpio_request(GPIO_FN_PORT159_SCIFB_SCK, NULL);
416         gpio_request(GPIO_FN_PORT160_SCIFB_TXD, NULL);
417         gpio_request(GPIO_FN_PORT161_SCIFB_CTS_, NULL);
418         gpio_request(GPIO_FN_PORT162_SCIFB_RXD, NULL);
419         gpio_request(GPIO_FN_PORT163_SCIFB_RTS_, NULL);
420
421         /* SDHI1 (BCM4330) */
422         gpio_request(GPIO_FN_SDHICLK1, NULL);
423         gpio_request(GPIO_FN_SDHICMD1_PU, NULL);
424         gpio_request(GPIO_FN_SDHID1_3_PU, NULL);
425         gpio_request(GPIO_FN_SDHID1_2_PU, NULL);
426         gpio_request(GPIO_FN_SDHID1_1_PU, NULL);
427         gpio_request(GPIO_FN_SDHID1_0_PU, NULL);
428
429 #ifdef CONFIG_CACHE_L2X0
430         /* Early BRESP enable, Shared attribute override enable, 64K*8way */
431         l2x0_init(__io(0xf0100000), 0x40460000, 0x82000fff);
432 #endif
433         sh73a0_add_standard_devices();
434         platform_add_devices(kota2_devices, ARRAY_SIZE(kota2_devices));
435 }
436
437 static void __init kota2_timer_init(void)
438 {
439         sh73a0_clock_init();
440         shmobile_timer.init();
441         return;
442 }
443
444 struct sys_timer kota2_timer = {
445         .init   = kota2_timer_init,
446 };
447
448 MACHINE_START(KOTA2, "kota2")
449         .map_io         = kota2_map_io,
450         .init_irq       = kota2_init_irq,
451         .handle_irq     = shmobile_handle_irq_gic,
452         .init_machine   = kota2_init,
453         .timer          = &kota2_timer,
454 MACHINE_END