Pull misc-2.6.39 into release branch
[pandora-kernel.git] / arch / arm / mach-shmobile / board-ag5evm.c
1 /*
2  * arch/arm/mach-shmobile/board-ag5evm.c
3  *
4  * Copyright (C) 2010  Takashi Yoshii <yoshii.takashi.zj@renesas.com>
5  * Copyright (C) 2009  Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
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  */
21
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/irq.h>
26 #include <linux/platform_device.h>
27 #include <linux/delay.h>
28 #include <linux/io.h>
29 #include <linux/dma-mapping.h>
30 #include <linux/serial_sci.h>
31 #include <linux/smsc911x.h>
32 #include <linux/gpio.h>
33 #include <linux/input.h>
34 #include <linux/input/sh_keysc.h>
35 #include <linux/mmc/host.h>
36 #include <linux/mmc/sh_mmcif.h>
37 #include <linux/sh_clk.h>
38 #include <video/sh_mobile_lcdc.h>
39 #include <video/sh_mipi_dsi.h>
40 #include <sound/sh_fsi.h>
41 #include <mach/hardware.h>
42 #include <mach/sh73a0.h>
43 #include <mach/common.h>
44 #include <asm/mach-types.h>
45 #include <asm/mach/arch.h>
46 #include <asm/mach/map.h>
47 #include <asm/mach/time.h>
48 #include <asm/hardware/gic.h>
49 #include <asm/hardware/cache-l2x0.h>
50 #include <asm/traps.h>
51
52 static struct resource smsc9220_resources[] = {
53         [0] = {
54                 .start          = 0x14000000,
55                 .end            = 0x14000000 + SZ_64K - 1,
56                 .flags          = IORESOURCE_MEM,
57         },
58         [1] = {
59                 .start          = gic_spi(33), /* PINT1 */
60                 .flags          = IORESOURCE_IRQ,
61         },
62 };
63
64 static struct smsc911x_platform_config smsc9220_platdata = {
65         .flags          = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
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 static struct sh_keysc_info keysc_platdata = {
82         .mode           = SH_KEYSC_MODE_6,
83         .scan_timing    = 3,
84         .delay          = 100,
85         .keycodes       = {
86                 KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
87                 KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N,
88                 KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U,
89                 KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP,
90                 KEY_SPACE, KEY_9, KEY_6, KEY_3, KEY_WAKEUP, KEY_RIGHT, \
91                 KEY_COFFEE,
92                 KEY_0, KEY_8, KEY_5, KEY_2, KEY_DOWN, KEY_ENTER, KEY_UP,
93                 KEY_KPASTERISK, KEY_7, KEY_4, KEY_1, KEY_STOP, KEY_LEFT, \
94                 KEY_COMPUTER,
95         },
96 };
97
98 static struct resource keysc_resources[] = {
99         [0] = {
100                 .name   = "KEYSC",
101                 .start  = 0xe61b0000,
102                 .end    = 0xe61b0098 - 1,
103                 .flags  = IORESOURCE_MEM,
104         },
105         [1] = {
106                 .start  = gic_spi(71),
107                 .flags  = IORESOURCE_IRQ,
108         },
109 };
110
111 static struct platform_device keysc_device = {
112         .name           = "sh_keysc",
113         .id             = 0,
114         .num_resources  = ARRAY_SIZE(keysc_resources),
115         .resource       = keysc_resources,
116         .dev            = {
117                 .platform_data  = &keysc_platdata,
118         },
119 };
120
121 /* FSI A */
122 static struct sh_fsi_platform_info fsi_info = {
123         .porta_flags = SH_FSI_OUT_SLAVE_MODE    |
124                        SH_FSI_IN_SLAVE_MODE     |
125                        SH_FSI_OFMT(I2S)         |
126                        SH_FSI_IFMT(I2S),
127 };
128
129 static struct resource fsi_resources[] = {
130         [0] = {
131                 .name   = "FSI",
132                 .start  = 0xEC230000,
133                 .end    = 0xEC230400 - 1,
134                 .flags  = IORESOURCE_MEM,
135         },
136         [1] = {
137                 .start  = gic_spi(146),
138                 .flags  = IORESOURCE_IRQ,
139         },
140 };
141
142 static struct platform_device fsi_device = {
143         .name           = "sh_fsi2",
144         .id             = -1,
145         .num_resources  = ARRAY_SIZE(fsi_resources),
146         .resource       = fsi_resources,
147         .dev    = {
148                 .platform_data  = &fsi_info,
149         },
150 };
151
152 static struct resource sh_mmcif_resources[] = {
153         [0] = {
154                 .name   = "MMCIF",
155                 .start  = 0xe6bd0000,
156                 .end    = 0xe6bd00ff,
157                 .flags  = IORESOURCE_MEM,
158         },
159         [1] = {
160                 .start  = gic_spi(141),
161                 .flags  = IORESOURCE_IRQ,
162         },
163         [2] = {
164                 .start  = gic_spi(140),
165                 .flags  = IORESOURCE_IRQ,
166         },
167 };
168
169 static struct sh_mmcif_plat_data sh_mmcif_platdata = {
170         .sup_pclk       = 0,
171         .ocr            = MMC_VDD_165_195,
172         .caps           = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
173 };
174
175 static struct platform_device mmc_device = {
176         .name           = "sh_mmcif",
177         .id             = 0,
178         .dev            = {
179                 .dma_mask               = NULL,
180                 .coherent_dma_mask      = 0xffffffff,
181                 .platform_data          = &sh_mmcif_platdata,
182         },
183         .num_resources  = ARRAY_SIZE(sh_mmcif_resources),
184         .resource       = sh_mmcif_resources,
185 };
186
187 /* IrDA */
188 static struct resource irda_resources[] = {
189         [0] = {
190                 .start  = 0xE6D00000,
191                 .end    = 0xE6D01FD4 - 1,
192                 .flags  = IORESOURCE_MEM,
193         },
194         [1] = {
195                 .start  = gic_spi(95),
196                 .flags  = IORESOURCE_IRQ,
197         },
198 };
199
200 static struct platform_device irda_device = {
201         .name           = "sh_irda",
202         .id             = 0,
203         .resource       = irda_resources,
204         .num_resources  = ARRAY_SIZE(irda_resources),
205 };
206
207 static unsigned char lcd_backlight_seq[3][2] = {
208         { 0x04, 0x07 },
209         { 0x23, 0x80 },
210         { 0x03, 0x01 },
211 };
212
213 static void lcd_backlight_on(void)
214 {
215         struct i2c_adapter *a;
216         struct i2c_msg msg;
217         int k;
218
219         a = i2c_get_adapter(1);
220         for (k = 0; a && k < 3; k++) {
221                 msg.addr = 0x6d;
222                 msg.buf = &lcd_backlight_seq[k][0];
223                 msg.len = 2;
224                 msg.flags = 0;
225                 if (i2c_transfer(a, &msg, 1) != 1)
226                         break;
227         }
228 }
229
230 static void lcd_backlight_reset(void)
231 {
232         gpio_set_value(GPIO_PORT235, 0);
233         mdelay(24);
234         gpio_set_value(GPIO_PORT235, 1);
235 }
236
237 static void lcd_on(void *board_data, struct fb_info *info)
238 {
239         lcd_backlight_on();
240 }
241
242 static void lcd_off(void *board_data)
243 {
244         lcd_backlight_reset();
245 }
246
247 /* LCDC0 */
248 static const struct fb_videomode lcdc0_modes[] = {
249         {
250                 .name           = "R63302(QHD)",
251                 .xres           = 544,
252                 .yres           = 961,
253                 .left_margin    = 72,
254                 .right_margin   = 600,
255                 .hsync_len      = 16,
256                 .upper_margin   = 8,
257                 .lower_margin   = 8,
258                 .vsync_len      = 2,
259                 .sync           = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
260         },
261 };
262
263 static struct sh_mobile_lcdc_info lcdc0_info = {
264         .clock_source = LCDC_CLK_PERIPHERAL,
265         .ch[0] = {
266                 .chan = LCDC_CHAN_MAINLCD,
267                 .interface_type = RGB24,
268                 .clock_divider = 1,
269                 .flags = LCDC_FLAGS_DWPOL,
270                 .lcd_size_cfg.width = 44,
271                 .lcd_size_cfg.height = 79,
272                 .bpp = 16,
273                 .lcd_cfg = lcdc0_modes,
274                 .num_cfg = ARRAY_SIZE(lcdc0_modes),
275                 .board_cfg = {
276                         .display_on = lcd_on,
277                         .display_off = lcd_off,
278                 },
279         }
280 };
281
282 static struct resource lcdc0_resources[] = {
283         [0] = {
284                 .name   = "LCDC0",
285                 .start  = 0xfe940000, /* P4-only space */
286                 .end    = 0xfe943fff,
287                 .flags  = IORESOURCE_MEM,
288         },
289         [1] = {
290                 .start  = intcs_evt2irq(0x580),
291                 .flags  = IORESOURCE_IRQ,
292         },
293 };
294
295 static struct platform_device lcdc0_device = {
296         .name           = "sh_mobile_lcdc_fb",
297         .num_resources  = ARRAY_SIZE(lcdc0_resources),
298         .resource       = lcdc0_resources,
299         .id             = 0,
300         .dev    = {
301                 .platform_data  = &lcdc0_info,
302                 .coherent_dma_mask = ~0,
303         },
304 };
305
306 /* MIPI-DSI */
307 static struct resource mipidsi0_resources[] = {
308         [0] = {
309                 .start  = 0xfeab0000,
310                 .end    = 0xfeab3fff,
311                 .flags  = IORESOURCE_MEM,
312         },
313         [1] = {
314                 .start  = 0xfeab4000,
315                 .end    = 0xfeab7fff,
316                 .flags  = IORESOURCE_MEM,
317         },
318 };
319
320 static struct sh_mipi_dsi_info mipidsi0_info = {
321         .data_format    = MIPI_RGB888,
322         .lcd_chan       = &lcdc0_info.ch[0],
323         .vsynw_offset   = 20,
324         .clksrc         = 1,
325         .flags          = SH_MIPI_DSI_HSABM,
326 };
327
328 static struct platform_device mipidsi0_device = {
329         .name           = "sh-mipi-dsi",
330         .num_resources  = ARRAY_SIZE(mipidsi0_resources),
331         .resource       = mipidsi0_resources,
332         .id             = 0,
333         .dev    = {
334                 .platform_data  = &mipidsi0_info,
335         },
336 };
337
338 static struct platform_device *ag5evm_devices[] __initdata = {
339         &eth_device,
340         &keysc_device,
341         &fsi_device,
342         &mmc_device,
343         &irda_device,
344         &lcdc0_device,
345         &mipidsi0_device,
346 };
347
348 static struct map_desc ag5evm_io_desc[] __initdata = {
349         /* create a 1:1 entity map for 0xe6xxxxxx
350          * used by CPGA, INTC and PFC.
351          */
352         {
353                 .virtual        = 0xe6000000,
354                 .pfn            = __phys_to_pfn(0xe6000000),
355                 .length         = 256 << 20,
356                 .type           = MT_DEVICE_NONSHARED
357         },
358 };
359
360 static void __init ag5evm_map_io(void)
361 {
362         iotable_init(ag5evm_io_desc, ARRAY_SIZE(ag5evm_io_desc));
363
364         /* setup early devices and console here as well */
365         sh73a0_add_early_devices();
366         shmobile_setup_console();
367 }
368
369 #define PINTC_ADDR      0xe6900000
370 #define PINTER0A        (PINTC_ADDR + 0xa0)
371 #define PINTCR0A        (PINTC_ADDR + 0xb0)
372
373 void __init ag5evm_init_irq(void)
374 {
375         sh73a0_init_irq();
376
377         /* setup PINT: enable PINTA2 as active low */
378         __raw_writel(__raw_readl(PINTER0A) | (1<<29), PINTER0A);
379         __raw_writew(__raw_readw(PINTCR0A) | (2<<10), PINTCR0A);
380 }
381
382 #define DSI0PHYCR       0xe615006c
383
384 static void __init ag5evm_init(void)
385 {
386         sh73a0_pinmux_init();
387
388         /* enable SCIFA2 */
389         gpio_request(GPIO_FN_SCIFA2_TXD1, NULL);
390         gpio_request(GPIO_FN_SCIFA2_RXD1, NULL);
391         gpio_request(GPIO_FN_SCIFA2_RTS1_, NULL);
392         gpio_request(GPIO_FN_SCIFA2_CTS1_, NULL);
393
394         /* enable KEYSC */
395         gpio_request(GPIO_FN_KEYIN0_PU, NULL);
396         gpio_request(GPIO_FN_KEYIN1_PU, NULL);
397         gpio_request(GPIO_FN_KEYIN2_PU, NULL);
398         gpio_request(GPIO_FN_KEYIN3_PU, NULL);
399         gpio_request(GPIO_FN_KEYIN4_PU, NULL);
400         gpio_request(GPIO_FN_KEYIN5_PU, NULL);
401         gpio_request(GPIO_FN_KEYIN6_PU, NULL);
402         gpio_request(GPIO_FN_KEYIN7_PU, NULL);
403         gpio_request(GPIO_FN_KEYOUT0, NULL);
404         gpio_request(GPIO_FN_KEYOUT1, NULL);
405         gpio_request(GPIO_FN_KEYOUT2, NULL);
406         gpio_request(GPIO_FN_KEYOUT3, NULL);
407         gpio_request(GPIO_FN_KEYOUT4, NULL);
408         gpio_request(GPIO_FN_KEYOUT5, NULL);
409         gpio_request(GPIO_FN_PORT59_KEYOUT6, NULL);
410         gpio_request(GPIO_FN_PORT58_KEYOUT7, NULL);
411         gpio_request(GPIO_FN_KEYOUT8, NULL);
412         gpio_request(GPIO_FN_PORT149_KEYOUT9, NULL);
413
414         /* enable I2C channel 2 and 3 */
415         gpio_request(GPIO_FN_PORT236_I2C_SDA2, NULL);
416         gpio_request(GPIO_FN_PORT237_I2C_SCL2, NULL);
417         gpio_request(GPIO_FN_PORT248_I2C_SCL3, NULL);
418         gpio_request(GPIO_FN_PORT249_I2C_SDA3, NULL);
419
420         /* enable MMCIF */
421         gpio_request(GPIO_FN_MMCCLK0, NULL);
422         gpio_request(GPIO_FN_MMCCMD0_PU, NULL);
423         gpio_request(GPIO_FN_MMCD0_0, NULL);
424         gpio_request(GPIO_FN_MMCD0_1, NULL);
425         gpio_request(GPIO_FN_MMCD0_2, NULL);
426         gpio_request(GPIO_FN_MMCD0_3, NULL);
427         gpio_request(GPIO_FN_MMCD0_4, NULL);
428         gpio_request(GPIO_FN_MMCD0_5, NULL);
429         gpio_request(GPIO_FN_MMCD0_6, NULL);
430         gpio_request(GPIO_FN_MMCD0_7, NULL);
431         gpio_request(GPIO_PORT208, NULL); /* Reset */
432         gpio_direction_output(GPIO_PORT208, 1);
433
434         /* enable SMSC911X */
435         gpio_request(GPIO_PORT144, NULL); /* PINTA2 */
436         gpio_direction_input(GPIO_PORT144);
437         gpio_request(GPIO_PORT145, NULL); /* RESET */
438         gpio_direction_output(GPIO_PORT145, 1);
439
440         /* FSI A */
441         gpio_request(GPIO_FN_FSIACK, NULL);
442         gpio_request(GPIO_FN_FSIAILR, NULL);
443         gpio_request(GPIO_FN_FSIAIBT, NULL);
444         gpio_request(GPIO_FN_FSIAISLD, NULL);
445         gpio_request(GPIO_FN_FSIAOSLD, NULL);
446
447         /* IrDA */
448         gpio_request(GPIO_FN_PORT241_IRDA_OUT, NULL);
449         gpio_request(GPIO_FN_PORT242_IRDA_IN,  NULL);
450         gpio_request(GPIO_FN_PORT243_IRDA_FIRSEL, NULL);
451
452         /* LCD panel */
453         gpio_request(GPIO_PORT217, NULL); /* RESET */
454         gpio_direction_output(GPIO_PORT217, 0);
455         mdelay(1);
456         gpio_set_value(GPIO_PORT217, 1);
457         mdelay(100);
458
459         /* LCD backlight controller */
460         gpio_request(GPIO_PORT235, NULL); /* RESET */
461         gpio_direction_output(GPIO_PORT235, 0);
462         lcd_backlight_reset();
463
464         /* MIPI-DSI clock setup */
465         __raw_writel(0x2a809010, DSI0PHYCR);
466
467 #ifdef CONFIG_CACHE_L2X0
468         /* Shared attribute override enable, 64K*8way */
469         l2x0_init(__io(0xf0100000), 0x00460000, 0xc2000fff);
470 #endif
471         sh73a0_add_standard_devices();
472         platform_add_devices(ag5evm_devices, ARRAY_SIZE(ag5evm_devices));
473 }
474
475 static void __init ag5evm_timer_init(void)
476 {
477         sh73a0_clock_init();
478         shmobile_timer.init();
479         return;
480 }
481
482 struct sys_timer ag5evm_timer = {
483         .init   = ag5evm_timer_init,
484 };
485
486 MACHINE_START(AG5EVM, "ag5evm")
487         .map_io         = ag5evm_map_io,
488         .init_irq       = ag5evm_init_irq,
489         .handle_irq     = shmobile_handle_irq_gic,
490         .init_machine   = ag5evm_init,
491         .timer          = &ag5evm_timer,
492 MACHINE_END