]> Pileus Git - ~andy/linux/blob - arch/arm/mach-shmobile/board-mackerel.c
Merge branch 'rmobile/urgent' into rmobile-latest
[~andy/linux] / arch / arm / mach-shmobile / board-mackerel.c
1 /*
2  * mackerel board support
3  *
4  * Copyright (C) 2010 Renesas Solutions Corp.
5  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6  *
7  * based on ap4evb
8  * Copyright (C) 2010  Magnus Damm
9  * Copyright (C) 2008  Yoshihiro Shimoda
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; version 2 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  */
24 #include <linux/kernel.h>
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
27 #include <linux/irq.h>
28 #include <linux/platform_device.h>
29 #include <linux/gpio.h>
30 #include <linux/input.h>
31 #include <linux/io.h>
32 #include <linux/i2c.h>
33 #include <linux/leds.h>
34 #include <linux/mtd/mtd.h>
35 #include <linux/mtd/partitions.h>
36 #include <linux/mtd/physmap.h>
37 #include <linux/smsc911x.h>
38 #include <linux/sh_intc.h>
39 #include <linux/tca6416_keypad.h>
40 #include <linux/usb/r8a66597.h>
41
42 #include <video/sh_mobile_lcdc.h>
43
44 #include <sound/sh_fsi.h>
45
46 #include <mach/common.h>
47 #include <mach/sh7372.h>
48
49 #include <asm/mach/arch.h>
50 #include <asm/mach/time.h>
51 #include <asm/mach/map.h>
52 #include <asm/mach-types.h>
53
54 /*
55  * Address      Interface               BusWidth        note
56  * ------------------------------------------------------------------
57  * 0x0000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = ON
58  * 0x0800_0000  user area               -
59  * 0x1000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = OFF
60  * 0x1400_0000  Ether (LAN9220)         16bit
61  * 0x1600_0000  user area               -               cannot use with NAND
62  * 0x1800_0000  user area               -
63  * 0x1A00_0000  -
64  * 0x4000_0000  LPDDR2-SDRAM (POP)      32bit
65  */
66
67 /*
68  * CPU mode
69  *
70  * SW4                                     | Boot Area| Master   | Remarks
71  *  1  | 2   | 3   | 4   | 5   | 6   | 8   |          | Processor|
72  * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
73  * ON  | ON  | OFF | ON  | ON  | OFF | OFF | External | System   | External ROM
74  * ON  | ON  | ON  | ON  | ON  | OFF | OFF | External | System   | ROM Debug
75  * ON  | ON  | X   | ON  | OFF | OFF | OFF | Built-in | System   | ROM Debug
76  * X   | OFF | X   | X   | X   | X   | OFF | Built-in | System   | MaskROM
77  * OFF | X   | X   | X   | X   | X   | OFF | Built-in | System   | MaskROM
78  * X   | X   | X   | OFF | X   | X   | OFF | Built-in | System   | MaskROM
79  * OFF | ON  | OFF | X   | X   | OFF | ON  | External | System   | Standalone
80  * ON  | OFF | OFF | X   | X   | OFF | ON  | External | Realtime | Standalone
81 */
82
83 /*
84  * NOR Flash ROM
85  *
86  *  SW1  |     SW2    | SW7  | NOR Flash ROM
87  *  bit1 | bit1  bit2 | bit1 | Memory allocation
88  * ------+------------+------+------------------
89  *  OFF  | ON     OFF | ON   |    Area 0
90  *  OFF  | ON     OFF | OFF  |    Area 4
91  */
92
93 /*
94  * SMSC 9220
95  *
96  *  SW1         SMSC 9220
97  * -----------------------
98  *  ON          access disable
99  *  OFF         access enable
100  */
101
102 /*
103  * NAND Flash ROM
104  *
105  *  SW1  |     SW2    | SW7  | NAND Flash ROM
106  *  bit1 | bit1  bit2 | bit2 | Memory allocation
107  * ------+------------+------+------------------
108  *  OFF  | ON     OFF | ON   |    FCE 0
109  *  OFF  | ON     OFF | OFF  |    FCE 1
110  */
111
112 /*
113  * External interrupt pin settings
114  *
115  * IRQX  | pin setting        | device             | level
116  * ------+--------------------+--------------------+-------
117  * IRQ0  | ICR1A.IRQ0SA=0010  | SDHI2 card detect  | Low
118  * IRQ6  | ICR1A.IRQ6SA=0011  | Ether(LAN9220)     | High
119  * IRQ7  | ICR1A.IRQ7SA=0010  | LCD Tuch Panel     | Low
120  * IRQ8  | ICR2A.IRQ8SA=0010  | MMC/SD card detect | Low
121  * IRQ9  | ICR2A.IRQ9SA=0010  | KEY(TCA6408)       | Low
122  * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345)    | High
123  * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975)     | High
124  */
125
126 /*
127  * USB
128  *
129  * USB0 : CN22 : Function
130  * USB1 : CN31 : Function/Host *1
131  *
132  * J30 (for CN31) *1
133  * ----------+---------------+-------------
134  * 1-2 short | VBUS 5V       | Host
135  * open      | external VBUS | Function
136  *
137  * *1
138  * CN31 is used as Host in Linux.
139  */
140
141 /*
142  * FIXME !!
143  *
144  * gpio_no_direction
145  * are quick_hack.
146  *
147  * current gpio frame work doesn't have
148  * the method to control only pull up/down/free.
149  * this function should be replaced by correct gpio function
150  */
151 static void __init gpio_no_direction(u32 addr)
152 {
153         __raw_writeb(0x00, addr);
154 }
155
156 /* MTD */
157 static struct mtd_partition nor_flash_partitions[] = {
158         {
159                 .name           = "loader",
160                 .offset         = 0x00000000,
161                 .size           = 512 * 1024,
162                 .mask_flags     = MTD_WRITEABLE,
163         },
164         {
165                 .name           = "bootenv",
166                 .offset         = MTDPART_OFS_APPEND,
167                 .size           = 512 * 1024,
168                 .mask_flags     = MTD_WRITEABLE,
169         },
170         {
171                 .name           = "kernel_ro",
172                 .offset         = MTDPART_OFS_APPEND,
173                 .size           = 8 * 1024 * 1024,
174                 .mask_flags     = MTD_WRITEABLE,
175         },
176         {
177                 .name           = "kernel",
178                 .offset         = MTDPART_OFS_APPEND,
179                 .size           = 8 * 1024 * 1024,
180         },
181         {
182                 .name           = "data",
183                 .offset         = MTDPART_OFS_APPEND,
184                 .size           = MTDPART_SIZ_FULL,
185         },
186 };
187
188 static struct physmap_flash_data nor_flash_data = {
189         .width          = 2,
190         .parts          = nor_flash_partitions,
191         .nr_parts       = ARRAY_SIZE(nor_flash_partitions),
192 };
193
194 static struct resource nor_flash_resources[] = {
195         [0]     = {
196                 .start  = 0x00000000,
197                 .end    = 0x08000000 - 1,
198                 .flags  = IORESOURCE_MEM,
199         }
200 };
201
202 static struct platform_device nor_flash_device = {
203         .name           = "physmap-flash",
204         .dev            = {
205                 .platform_data  = &nor_flash_data,
206         },
207         .num_resources  = ARRAY_SIZE(nor_flash_resources),
208         .resource       = nor_flash_resources,
209 };
210
211 /* SMSC */
212 static struct resource smc911x_resources[] = {
213         {
214                 .start  = 0x14000000,
215                 .end    = 0x16000000 - 1,
216                 .flags  = IORESOURCE_MEM,
217         }, {
218                 .start  = evt2irq(0x02c0) /* IRQ6A */,
219                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
220         },
221 };
222
223 static struct smsc911x_platform_config smsc911x_info = {
224         .flags          = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
225         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
226         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
227 };
228
229 static struct platform_device smc911x_device = {
230         .name           = "smsc911x",
231         .id             = -1,
232         .num_resources  = ARRAY_SIZE(smc911x_resources),
233         .resource       = smc911x_resources,
234         .dev            = {
235                 .platform_data = &smsc911x_info,
236         },
237 };
238
239 /* LCDC */
240 static struct fb_videomode mackerel_lcdc_modes[] = {
241         {
242                 .name           = "WVGA Panel",
243                 .xres           = 800,
244                 .yres           = 480,
245                 .left_margin    = 220,
246                 .right_margin   = 110,
247                 .hsync_len      = 70,
248                 .upper_margin   = 20,
249                 .lower_margin   = 5,
250                 .vsync_len      = 5,
251                 .sync           = 0,
252         },
253 };
254
255 static struct sh_mobile_lcdc_info lcdc_info = {
256         .clock_source = LCDC_CLK_BUS,
257         .ch[0] = {
258                 .chan = LCDC_CHAN_MAINLCD,
259                 .bpp = 16,
260                 .lcd_cfg = mackerel_lcdc_modes,
261                 .num_cfg = ARRAY_SIZE(mackerel_lcdc_modes),
262                 .interface_type         = RGB24,
263                 .clock_divider          = 2,
264                 .flags                  = 0,
265                 .lcd_size_cfg.width     = 152,
266                 .lcd_size_cfg.height    = 91,
267         }
268 };
269
270 static struct resource lcdc_resources[] = {
271         [0] = {
272                 .name   = "LCDC",
273                 .start  = 0xfe940000,
274                 .end    = 0xfe943fff,
275                 .flags  = IORESOURCE_MEM,
276         },
277         [1] = {
278                 .start  = intcs_evt2irq(0x580),
279                 .flags  = IORESOURCE_IRQ,
280         },
281 };
282
283 static struct platform_device lcdc_device = {
284         .name           = "sh_mobile_lcdc_fb",
285         .num_resources  = ARRAY_SIZE(lcdc_resources),
286         .resource       = lcdc_resources,
287         .dev    = {
288                 .platform_data  = &lcdc_info,
289                 .coherent_dma_mask = ~0,
290         },
291 };
292
293 /* USB1 (Host) */
294 static void usb1_host_port_power(int port, int power)
295 {
296         if (!power) /* only power-on is supported for now */
297                 return;
298
299         /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
300         __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
301 }
302
303 static struct r8a66597_platdata usb1_host_data = {
304         .on_chip        = 1,
305         .port_power     = usb1_host_port_power,
306 };
307
308 static struct resource usb1_host_resources[] = {
309         [0] = {
310                 .name   = "USBHS",
311                 .start  = 0xE68B0000,
312                 .end    = 0xE68B00E6 - 1,
313                 .flags  = IORESOURCE_MEM,
314         },
315         [1] = {
316                 .start  = evt2irq(0x1ce0) /* USB1_USB1I0 */,
317                 .flags  = IORESOURCE_IRQ,
318         },
319 };
320
321 static struct platform_device usb1_host_device = {
322         .name   = "r8a66597_hcd",
323         .id     = 1,
324         .dev = {
325                 .dma_mask               = NULL,         /*  not use dma */
326                 .coherent_dma_mask      = 0xffffffff,
327                 .platform_data          = &usb1_host_data,
328         },
329         .num_resources  = ARRAY_SIZE(usb1_host_resources),
330         .resource       = usb1_host_resources,
331 };
332
333 /* LED */
334 static struct gpio_led mackerel_leds[] = {
335         {
336                 .name           = "led0",
337                 .gpio           = GPIO_PORT0,
338                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
339         },
340         {
341                 .name           = "led1",
342                 .gpio           = GPIO_PORT1,
343                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
344         },
345         {
346                 .name           = "led2",
347                 .gpio           = GPIO_PORT2,
348                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
349         },
350         {
351                 .name           = "led3",
352                 .gpio           = GPIO_PORT159,
353                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
354         }
355 };
356
357 static struct gpio_led_platform_data mackerel_leds_pdata = {
358         .leds = mackerel_leds,
359         .num_leds = ARRAY_SIZE(mackerel_leds),
360 };
361
362 static struct platform_device leds_device = {
363         .name = "leds-gpio",
364         .id = 0,
365         .dev = {
366                 .platform_data  = &mackerel_leds_pdata,
367         },
368 };
369
370 /* FSI */
371 #define IRQ_FSI evt2irq(0x1840)
372 static struct sh_fsi_platform_info fsi_info = {
373         .porta_flags =  SH_FSI_BRS_INV          |
374                         SH_FSI_OUT_SLAVE_MODE   |
375                         SH_FSI_IN_SLAVE_MODE    |
376                         SH_FSI_OFMT(PCM)        |
377                         SH_FSI_IFMT(PCM),
378 };
379
380 static struct resource fsi_resources[] = {
381         [0] = {
382                 .name   = "FSI",
383                 .start  = 0xFE3C0000,
384                 .end    = 0xFE3C0400 - 1,
385                 .flags  = IORESOURCE_MEM,
386         },
387         [1] = {
388                 .start  = IRQ_FSI,
389                 .flags  = IORESOURCE_IRQ,
390         },
391 };
392
393 static struct platform_device fsi_device = {
394         .name           = "sh_fsi2",
395         .id             = -1,
396         .num_resources  = ARRAY_SIZE(fsi_resources),
397         .resource       = fsi_resources,
398         .dev    = {
399                 .platform_data  = &fsi_info,
400         },
401 };
402
403 static struct platform_device fsi_ak4643_device = {
404         .name           = "sh_fsi2_a_ak4643",
405 };
406
407 static struct platform_device *mackerel_devices[] __initdata = {
408         &nor_flash_device,
409         &smc911x_device,
410         &lcdc_device,
411         &usb1_host_device,
412         &leds_device,
413         &fsi_device,
414         &fsi_ak4643_device,
415 };
416
417 /* Keypad Initialization */
418 #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
419 {                                                               \
420         .type           = ev_type,                              \
421         .code           = ev_code,                              \
422         .active_low     = act_low,                              \
423 }
424
425 #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
426
427 static struct tca6416_button mackerel_gpio_keys[] = {
428         KEYPAD_BUTTON_LOW(KEY_HOME),
429         KEYPAD_BUTTON_LOW(KEY_MENU),
430         KEYPAD_BUTTON_LOW(KEY_BACK),
431         KEYPAD_BUTTON_LOW(KEY_POWER),
432 };
433
434 static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
435         .buttons        = mackerel_gpio_keys,
436         .nbuttons       = ARRAY_SIZE(mackerel_gpio_keys),
437         .rep            = 1,
438         .use_polling    = 0,
439         .pinmask        = 0x000F,
440 };
441
442 /* I2C */
443 #define IRQ9 evt2irq(0x0320)
444
445 static struct i2c_board_info i2c0_devices[] = {
446         {
447                 I2C_BOARD_INFO("ak4643", 0x13),
448         },
449         /* Keypad */
450         {
451                 I2C_BOARD_INFO("tca6408-keys", 0x20),
452                 .platform_data = &mackerel_tca6416_keys_info,
453                 .irq = IRQ9,
454         },
455 };
456
457 #define IRQ21 evt2irq(0x32a0)
458
459 static struct i2c_board_info i2c1_devices[] = {
460         /* Accelerometer */
461         {
462                 I2C_BOARD_INFO("adxl34x", 0x53),
463                 .irq = IRQ21,
464         },
465 };
466
467 static struct map_desc mackerel_io_desc[] __initdata = {
468         /* create a 1:1 entity map for 0xe6xxxxxx
469          * used by CPGA, INTC and PFC.
470          */
471         {
472                 .virtual        = 0xe6000000,
473                 .pfn            = __phys_to_pfn(0xe6000000),
474                 .length         = 256 << 20,
475                 .type           = MT_DEVICE_NONSHARED
476         },
477 };
478
479 static void __init mackerel_map_io(void)
480 {
481         iotable_init(mackerel_io_desc, ARRAY_SIZE(mackerel_io_desc));
482
483         /* setup early devices and console here as well */
484         sh7372_add_early_devices();
485         shmobile_setup_console();
486 }
487
488 #define GPIO_PORT9CR    0xE6051009
489 #define GPIO_PORT10CR   0xE605100A
490 static void __init mackerel_init(void)
491 {
492         sh7372_pinmux_init();
493
494         /* enable SCIFA0 */
495         gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
496         gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
497
498         /* enable SMSC911X */
499         gpio_request(GPIO_FN_CS5A,      NULL);
500         gpio_request(GPIO_FN_IRQ6_39,   NULL);
501
502         /* LCDC */
503         gpio_request(GPIO_FN_LCDD23,   NULL);
504         gpio_request(GPIO_FN_LCDD22,   NULL);
505         gpio_request(GPIO_FN_LCDD21,   NULL);
506         gpio_request(GPIO_FN_LCDD20,   NULL);
507         gpio_request(GPIO_FN_LCDD19,   NULL);
508         gpio_request(GPIO_FN_LCDD18,   NULL);
509         gpio_request(GPIO_FN_LCDD17,   NULL);
510         gpio_request(GPIO_FN_LCDD16,   NULL);
511         gpio_request(GPIO_FN_LCDD15,   NULL);
512         gpio_request(GPIO_FN_LCDD14,   NULL);
513         gpio_request(GPIO_FN_LCDD13,   NULL);
514         gpio_request(GPIO_FN_LCDD12,   NULL);
515         gpio_request(GPIO_FN_LCDD11,   NULL);
516         gpio_request(GPIO_FN_LCDD10,   NULL);
517         gpio_request(GPIO_FN_LCDD9,    NULL);
518         gpio_request(GPIO_FN_LCDD8,    NULL);
519         gpio_request(GPIO_FN_LCDD7,    NULL);
520         gpio_request(GPIO_FN_LCDD6,    NULL);
521         gpio_request(GPIO_FN_LCDD5,    NULL);
522         gpio_request(GPIO_FN_LCDD4,    NULL);
523         gpio_request(GPIO_FN_LCDD3,    NULL);
524         gpio_request(GPIO_FN_LCDD2,    NULL);
525         gpio_request(GPIO_FN_LCDD1,    NULL);
526         gpio_request(GPIO_FN_LCDD0,    NULL);
527         gpio_request(GPIO_FN_LCDDISP,  NULL);
528         gpio_request(GPIO_FN_LCDDCK,   NULL);
529
530         gpio_request(GPIO_PORT31, NULL); /* backlight */
531         gpio_direction_output(GPIO_PORT31, 1);
532
533         gpio_request(GPIO_PORT151, NULL); /* LCDDON */
534         gpio_direction_output(GPIO_PORT151, 1);
535
536         /* USB enable */
537         gpio_request(GPIO_FN_VBUS0_1,    NULL);
538         gpio_request(GPIO_FN_IDIN_1_18,  NULL);
539         gpio_request(GPIO_FN_PWEN_1_115, NULL);
540         gpio_request(GPIO_FN_OVCN_1_114, NULL);
541         gpio_request(GPIO_FN_EXTLP_1,    NULL);
542         gpio_request(GPIO_FN_OVCN2_1,    NULL);
543
544         /* setup USB phy */
545         __raw_writew(0x8a0a, 0xE6058130);       /* USBCR2 */
546
547         /* enable FSI2 port A (ak4643) */
548         gpio_request(GPIO_FN_FSIAIBT,   NULL);
549         gpio_request(GPIO_FN_FSIAILR,   NULL);
550         gpio_request(GPIO_FN_FSIAISLD,  NULL);
551         gpio_request(GPIO_FN_FSIAOSLD,  NULL);
552         gpio_request(GPIO_PORT161,      NULL);
553         gpio_direction_output(GPIO_PORT161, 0); /* slave */
554
555         gpio_request(GPIO_PORT9,  NULL);
556         gpio_request(GPIO_PORT10, NULL);
557         gpio_no_direction(GPIO_PORT9CR);  /* FSIAOBT needs no direction */
558         gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
559
560         intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
561
562         /* enable Keypad */
563         gpio_request(GPIO_FN_IRQ9_42,   NULL);
564         set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
565
566         /* enable Accelerometer */
567         gpio_request(GPIO_FN_IRQ21,     NULL);
568         set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
569
570         i2c_register_board_info(0, i2c0_devices,
571                                 ARRAY_SIZE(i2c0_devices));
572         i2c_register_board_info(1, i2c1_devices,
573                                 ARRAY_SIZE(i2c1_devices));
574
575         sh7372_add_standard_devices();
576
577         platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
578 }
579
580 static void __init mackerel_timer_init(void)
581 {
582         sh7372_clock_init();
583         shmobile_timer.init();
584 }
585
586 static struct sys_timer mackerel_timer = {
587         .init           = mackerel_timer_init,
588 };
589
590 MACHINE_START(MACKEREL, "mackerel")
591         .map_io         = mackerel_map_io,
592         .init_irq       = sh7372_init_irq,
593         .init_machine   = mackerel_init,
594         .timer          = &mackerel_timer,
595 MACHINE_END