7d056cb2334e593037ca4fcb8dda56019ecb5745
[pandora-kernel.git] / arch / arm / mach-pxa / em-x270.c
1 /*
2  * Support for CompuLab EM-X270 platform
3  *
4  * Copyright (C) 2007, 2008 CompuLab, Ltd.
5  * Author: Mike Rapoport <mike@compulab.co.il>
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 version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/irq.h>
13 #include <linux/platform_device.h>
14
15 #include <linux/dm9000.h>
16 #include <linux/rtc-v3020.h>
17 #include <linux/mtd/nand.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/mtd/physmap.h>
20 #include <linux/input.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/gpio.h>
23 #include <linux/mfd/da903x.h>
24 #include <linux/regulator/machine.h>
25 #include <linux/spi/spi.h>
26 #include <linux/spi/tdo24m.h>
27
28 #include <media/soc_camera.h>
29
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32
33 #include <mach/mfp-pxa27x.h>
34 #include <mach/pxa-regs.h>
35 #include <mach/pxa27x-udc.h>
36 #include <mach/audio.h>
37 #include <mach/pxafb.h>
38 #include <mach/ohci.h>
39 #include <mach/mmc.h>
40 #include <mach/pxa27x_keypad.h>
41 #include <mach/i2c.h>
42 #include <mach/camera.h>
43 #include <mach/pxa2xx_spi.h>
44
45 #include "generic.h"
46 #include "devices.h"
47
48 /* GPIO IRQ usage */
49 #define GPIO41_ETHIRQ           (41)
50 #define GPIO13_MMC_CD           (13)
51 #define EM_X270_ETHIRQ          IRQ_GPIO(GPIO41_ETHIRQ)
52
53 /* NAND control GPIOs */
54 #define GPIO11_NAND_CS  (11)
55 #define GPIO56_NAND_RB  (56)
56
57 /* Miscelaneous GPIOs */
58 #define GPIO93_CAM_RESET        (93)
59 #define GPIO95_MMC_WP           (95)
60
61 static unsigned long em_x270_pin_config[] = {
62         /* AC'97 */
63         GPIO28_AC97_BITCLK,
64         GPIO29_AC97_SDATA_IN_0,
65         GPIO30_AC97_SDATA_OUT,
66         GPIO31_AC97_SYNC,
67         GPIO98_AC97_SYSCLK,
68         GPIO113_AC97_nRESET,
69
70         /* BTUART */
71         GPIO42_BTUART_RXD,
72         GPIO43_BTUART_TXD,
73         GPIO44_BTUART_CTS,
74         GPIO45_BTUART_RTS,
75
76         /* STUART */
77         GPIO46_STUART_RXD,
78         GPIO47_STUART_TXD,
79
80         /* MCI controller */
81         GPIO32_MMC_CLK,
82         GPIO112_MMC_CMD,
83         GPIO92_MMC_DAT_0,
84         GPIO109_MMC_DAT_1,
85         GPIO110_MMC_DAT_2,
86         GPIO111_MMC_DAT_3,
87
88         /* LCD */
89         GPIO58_LCD_LDD_0,
90         GPIO59_LCD_LDD_1,
91         GPIO60_LCD_LDD_2,
92         GPIO61_LCD_LDD_3,
93         GPIO62_LCD_LDD_4,
94         GPIO63_LCD_LDD_5,
95         GPIO64_LCD_LDD_6,
96         GPIO65_LCD_LDD_7,
97         GPIO66_LCD_LDD_8,
98         GPIO67_LCD_LDD_9,
99         GPIO68_LCD_LDD_10,
100         GPIO69_LCD_LDD_11,
101         GPIO70_LCD_LDD_12,
102         GPIO71_LCD_LDD_13,
103         GPIO72_LCD_LDD_14,
104         GPIO73_LCD_LDD_15,
105         GPIO74_LCD_FCLK,
106         GPIO75_LCD_LCLK,
107         GPIO76_LCD_PCLK,
108         GPIO77_LCD_BIAS,
109
110         /* QCI */
111         GPIO84_CIF_FV,
112         GPIO25_CIF_LV,
113         GPIO53_CIF_MCLK,
114         GPIO54_CIF_PCLK,
115         GPIO81_CIF_DD_0,
116         GPIO55_CIF_DD_1,
117         GPIO51_CIF_DD_2,
118         GPIO50_CIF_DD_3,
119         GPIO52_CIF_DD_4,
120         GPIO48_CIF_DD_5,
121         GPIO17_CIF_DD_6,
122         GPIO12_CIF_DD_7,
123
124         /* I2C */
125         GPIO117_I2C_SCL,
126         GPIO118_I2C_SDA,
127
128         /* Keypad */
129         GPIO100_KP_MKIN_0       | WAKEUP_ON_LEVEL_HIGH,
130         GPIO101_KP_MKIN_1       | WAKEUP_ON_LEVEL_HIGH,
131         GPIO102_KP_MKIN_2       | WAKEUP_ON_LEVEL_HIGH,
132         GPIO34_KP_MKIN_3        | WAKEUP_ON_LEVEL_HIGH,
133         GPIO39_KP_MKIN_4        | WAKEUP_ON_LEVEL_HIGH,
134         GPIO99_KP_MKIN_5        | WAKEUP_ON_LEVEL_HIGH,
135         GPIO91_KP_MKIN_6        | WAKEUP_ON_LEVEL_HIGH,
136         GPIO36_KP_MKIN_7        | WAKEUP_ON_LEVEL_HIGH,
137         GPIO103_KP_MKOUT_0,
138         GPIO104_KP_MKOUT_1,
139         GPIO105_KP_MKOUT_2,
140         GPIO106_KP_MKOUT_3,
141         GPIO107_KP_MKOUT_4,
142         GPIO108_KP_MKOUT_5,
143         GPIO96_KP_MKOUT_6,
144         GPIO22_KP_MKOUT_7,
145
146         /* SSP1 */
147         GPIO26_SSP1_RXD,
148         GPIO23_SSP1_SCLK,
149         GPIO24_SSP1_SFRM,
150         GPIO57_SSP1_TXD,
151
152         /* SSP2 */
153         GPIO19_SSP2_SCLK,
154         GPIO14_SSP2_SFRM,
155         GPIO89_SSP2_TXD,
156         GPIO88_SSP2_RXD,
157
158         /* SDRAM and local bus */
159         GPIO15_nCS_1,
160         GPIO78_nCS_2,
161         GPIO79_nCS_3,
162         GPIO80_nCS_4,
163         GPIO49_nPWE,
164         GPIO18_RDY,
165
166         /* GPIO */
167         GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,       /* sleep/resume button */
168         GPIO95_GPIO,                            /* MMC Write protect */
169
170         /* power controls */
171         GPIO20_GPIO     | MFP_LPM_DRIVE_LOW,    /* GPRS_PWEN */
172         GPIO93_GPIO     | MFP_LPM_DRIVE_LOW,    /* Camera reset */
173         GPIO115_GPIO    | MFP_LPM_DRIVE_LOW,    /* WLAN_PWEN */
174
175         /* NAND controls */
176         GPIO11_GPIO     | MFP_LPM_DRIVE_HIGH,   /* NAND CE# */
177         GPIO56_GPIO,                            /* NAND Ready/Busy */
178
179         /* interrupts */
180         GPIO13_GPIO,    /* MMC card detect */
181         GPIO41_GPIO,    /* DM9000 interrupt */
182 };
183
184 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
185 static struct resource em_x270_dm9000_resource[] = {
186         [0] = {
187                 .start = PXA_CS2_PHYS,
188                 .end   = PXA_CS2_PHYS + 3,
189                 .flags = IORESOURCE_MEM,
190         },
191         [1] = {
192                 .start = PXA_CS2_PHYS + 8,
193                 .end   = PXA_CS2_PHYS + 8 + 0x3f,
194                 .flags = IORESOURCE_MEM,
195         },
196         [2] = {
197                 .start = EM_X270_ETHIRQ,
198                 .end   = EM_X270_ETHIRQ,
199                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
200         }
201 };
202
203 static struct dm9000_plat_data em_x270_dm9000_platdata = {
204         .flags          = DM9000_PLATF_32BITONLY,
205 };
206
207 static struct platform_device em_x270_dm9000 = {
208         .name           = "dm9000",
209         .id             = 0,
210         .num_resources  = ARRAY_SIZE(em_x270_dm9000_resource),
211         .resource       = em_x270_dm9000_resource,
212         .dev            = {
213                 .platform_data = &em_x270_dm9000_platdata,
214         }
215 };
216
217 static void __init em_x270_init_dm9000(void)
218 {
219         platform_device_register(&em_x270_dm9000);
220 }
221 #else
222 static inline void em_x270_init_dm9000(void) {}
223 #endif
224
225 /* V3020 RTC */
226 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
227 static struct resource em_x270_v3020_resource[] = {
228         [0] = {
229                 .start = PXA_CS4_PHYS,
230                 .end   = PXA_CS4_PHYS + 3,
231                 .flags = IORESOURCE_MEM,
232         },
233 };
234
235 static struct v3020_platform_data em_x270_v3020_platdata = {
236         .leftshift = 0,
237 };
238
239 static struct platform_device em_x270_rtc = {
240         .name           = "v3020",
241         .num_resources  = ARRAY_SIZE(em_x270_v3020_resource),
242         .resource       = em_x270_v3020_resource,
243         .id             = -1,
244         .dev            = {
245                 .platform_data = &em_x270_v3020_platdata,
246         }
247 };
248
249 static void __init em_x270_init_rtc(void)
250 {
251         platform_device_register(&em_x270_rtc);
252 }
253 #else
254 static inline void em_x270_init_rtc(void) {}
255 #endif
256
257 /* NAND flash */
258 #if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
259 static inline void nand_cs_on(void)
260 {
261         gpio_set_value(GPIO11_NAND_CS, 0);
262 }
263
264 static void nand_cs_off(void)
265 {
266         dsb();
267
268         gpio_set_value(GPIO11_NAND_CS, 1);
269 }
270
271 /* hardware specific access to control-lines */
272 static void em_x270_nand_cmd_ctl(struct mtd_info *mtd, int dat,
273                                  unsigned int ctrl)
274 {
275         struct nand_chip *this = mtd->priv;
276         unsigned long nandaddr = (unsigned long)this->IO_ADDR_W;
277
278         dsb();
279
280         if (ctrl & NAND_CTRL_CHANGE) {
281                 if (ctrl & NAND_ALE)
282                         nandaddr |=  (1 << 3);
283                 else
284                         nandaddr &= ~(1 << 3);
285                 if (ctrl & NAND_CLE)
286                         nandaddr |=  (1 << 2);
287                 else
288                         nandaddr &= ~(1 << 2);
289                 if (ctrl & NAND_NCE)
290                         nand_cs_on();
291                 else
292                         nand_cs_off();
293         }
294
295         dsb();
296         this->IO_ADDR_W = (void __iomem *)nandaddr;
297         if (dat != NAND_CMD_NONE)
298                 writel(dat, this->IO_ADDR_W);
299
300         dsb();
301 }
302
303 /* read device ready pin */
304 static int em_x270_nand_device_ready(struct mtd_info *mtd)
305 {
306         dsb();
307
308         return gpio_get_value(GPIO56_NAND_RB);
309 }
310
311 static struct mtd_partition em_x270_partition_info[] = {
312         [0] = {
313                 .name   = "em_x270-0",
314                 .offset = 0,
315                 .size   = SZ_4M,
316         },
317         [1] = {
318                 .name   = "em_x270-1",
319                 .offset = MTDPART_OFS_APPEND,
320                 .size   = MTDPART_SIZ_FULL
321         },
322 };
323
324 static const char *em_x270_part_probes[] = { "cmdlinepart", NULL };
325
326 struct platform_nand_data em_x270_nand_platdata = {
327         .chip = {
328                 .nr_chips = 1,
329                 .chip_offset = 0,
330                 .nr_partitions = ARRAY_SIZE(em_x270_partition_info),
331                 .partitions = em_x270_partition_info,
332                 .chip_delay = 20,
333                 .part_probe_types = em_x270_part_probes,
334         },
335         .ctrl = {
336                 .hwcontrol = 0,
337                 .dev_ready = em_x270_nand_device_ready,
338                 .select_chip = 0,
339                 .cmd_ctrl = em_x270_nand_cmd_ctl,
340         },
341 };
342
343 static struct resource em_x270_nand_resource[] = {
344         [0] = {
345                 .start = PXA_CS1_PHYS,
346                 .end   = PXA_CS1_PHYS + 12,
347                 .flags = IORESOURCE_MEM,
348         },
349 };
350
351 static struct platform_device em_x270_nand = {
352         .name           = "gen_nand",
353         .num_resources  = ARRAY_SIZE(em_x270_nand_resource),
354         .resource       = em_x270_nand_resource,
355         .id             = -1,
356         .dev            = {
357                 .platform_data = &em_x270_nand_platdata,
358         }
359 };
360
361 static void __init em_x270_init_nand(void)
362 {
363         int err;
364
365         err = gpio_request(GPIO11_NAND_CS, "NAND CS");
366         if (err) {
367                 pr_warning("EM-X270: failed to request NAND CS gpio\n");
368                 return;
369         }
370
371         gpio_direction_output(GPIO11_NAND_CS, 1);
372
373         err = gpio_request(GPIO56_NAND_RB, "NAND R/B");
374         if (err) {
375                 pr_warning("EM-X270: failed to request NAND R/B gpio\n");
376                 gpio_free(GPIO11_NAND_CS);
377                 return;
378         }
379
380         gpio_direction_input(GPIO56_NAND_RB);
381
382         platform_device_register(&em_x270_nand);
383 }
384 #else
385 static inline void em_x270_init_nand(void) {}
386 #endif
387
388 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
389 static struct mtd_partition em_x270_nor_parts[] = {
390         {
391                 .name =         "Bootloader",
392                 .offset =       0x00000000,
393                 .size =         0x00050000,
394                 .mask_flags =   MTD_WRITEABLE  /* force read-only */
395         }, {
396                 .name =         "Environment",
397                 .offset =       0x00050000,
398                 .size =         0x00010000,
399         }, {
400                 .name =         "Reserved",
401                 .offset =       0x00060000,
402                 .size =         0x00050000,
403                 .mask_flags =   MTD_WRITEABLE  /* force read-only */
404         }, {
405                 .name =         "Splashscreen",
406                 .offset =       0x000b0000,
407                 .size =         0x00050000,
408         }
409 };
410
411 static struct physmap_flash_data em_x270_nor_data[] = {
412         [0] = {
413                 .width = 2,
414                 .parts = em_x270_nor_parts,
415                 .nr_parts = ARRAY_SIZE(em_x270_nor_parts),
416         },
417 };
418
419 static struct resource em_x270_nor_flash_resource = {
420         .start  = PXA_CS0_PHYS,
421         .end    = PXA_CS0_PHYS + SZ_1M - 1,
422         .flags  = IORESOURCE_MEM,
423 };
424
425 static struct platform_device em_x270_physmap_flash = {
426         .name           = "physmap-flash",
427         .id             = 0,
428         .num_resources  = 1,
429         .resource       = &em_x270_nor_flash_resource,
430         .dev            = {
431                 .platform_data  = &em_x270_nor_data,
432         },
433 };
434
435 static void __init em_x270_init_nor(void)
436 {
437         platform_device_register(&em_x270_physmap_flash);
438 }
439 #else
440 static inline void em_x270_init_nor(void) {}
441 #endif
442
443 /* PXA27x OHCI controller setup */
444 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
445 static int em_x270_ohci_init(struct device *dev)
446 {
447         /* enable port 2 transiever */
448         UP2OCR = UP2OCR_HXS | UP2OCR_HXOE;
449
450         return 0;
451 }
452
453 static struct pxaohci_platform_data em_x270_ohci_platform_data = {
454         .port_mode      = PMM_PERPORT_MODE,
455         .flags          = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
456         .init           = em_x270_ohci_init,
457 };
458
459 static void __init em_x270_init_ohci(void)
460 {
461         pxa_set_ohci_info(&em_x270_ohci_platform_data);
462 }
463 #else
464 static inline void em_x270_init_ohci(void) {}
465 #endif
466
467 /* MCI controller setup */
468 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
469 static struct regulator *em_x270_sdio_ldo;
470
471 static int em_x270_mci_init(struct device *dev,
472                             irq_handler_t em_x270_detect_int,
473                             void *data)
474 {
475         int err;
476
477         em_x270_sdio_ldo = regulator_get(dev, "vcc sdio");
478         if (IS_ERR(em_x270_sdio_ldo)) {
479                 dev_err(dev, "can't request SDIO power supply: %ld\n",
480                         PTR_ERR(em_x270_sdio_ldo));
481                 return PTR_ERR(em_x270_sdio_ldo);
482         }
483
484         err = request_irq(gpio_to_irq(GPIO13_MMC_CD), em_x270_detect_int,
485                               IRQF_DISABLED | IRQF_TRIGGER_RISING |
486                               IRQF_TRIGGER_FALLING,
487                               "MMC card detect", data);
488         if (err) {
489                 dev_err(dev, "can't request MMC card detect IRQ: %d\n", err);
490                 goto err_irq;
491         }
492
493         err = gpio_request(GPIO95_MMC_WP, "MMC WP");
494         if (err) {
495                 dev_err(dev, "can't request MMC write protect: %d\n", err);
496                 goto err_gpio_wp;
497         }
498
499         gpio_direction_input(GPIO95_MMC_WP);
500
501         return 0;
502
503 err_gpio_wp:
504         free_irq(gpio_to_irq(GPIO13_MMC_CD), data);
505 err_irq:
506         regulator_put(em_x270_sdio_ldo);
507
508         return err;
509 }
510
511 static void em_x270_mci_setpower(struct device *dev, unsigned int vdd)
512 {
513         struct pxamci_platform_data* p_d = dev->platform_data;
514
515         if ((1 << vdd) & p_d->ocr_mask) {
516                 int vdd_uV = (2000 + (vdd - __ffs(MMC_VDD_20_21)) * 100) * 1000;
517
518                 regulator_set_voltage(em_x270_sdio_ldo, vdd_uV, vdd_uV);
519                 regulator_enable(em_x270_sdio_ldo);
520         } else {
521                 regulator_disable(em_x270_sdio_ldo);
522         }
523 }
524
525 static void em_x270_mci_exit(struct device *dev, void *data)
526 {
527         free_irq(gpio_to_irq(GPIO13_MMC_CD), data);
528 }
529
530 static int em_x270_mci_get_ro(struct device *dev)
531 {
532         return gpio_get_value(GPIO95_MMC_WP);
533 }
534
535 static struct pxamci_platform_data em_x270_mci_platform_data = {
536         .ocr_mask       = MMC_VDD_20_21|MMC_VDD_21_22|MMC_VDD_22_23|
537                           MMC_VDD_24_25|MMC_VDD_25_26|MMC_VDD_26_27|
538                           MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
539                           MMC_VDD_30_31|MMC_VDD_31_32,
540         .init           = em_x270_mci_init,
541         .setpower       = em_x270_mci_setpower,
542         .get_ro         = em_x270_mci_get_ro,
543         .exit           = em_x270_mci_exit,
544 };
545
546 static void __init em_x270_init_mmc(void)
547 {
548         em_x270_mci_platform_data.detect_delay  = msecs_to_jiffies(250);
549         pxa_set_mci_info(&em_x270_mci_platform_data);
550 }
551 #else
552 static inline void em_x270_init_mmc(void) {}
553 #endif
554
555 /* LCD */
556 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
557 static struct pxafb_mode_info em_x270_lcd_modes[] = {
558         [0] = {
559                 .pixclock       = 38250,
560                 .bpp            = 16,
561                 .xres           = 480,
562                 .yres           = 640,
563                 .hsync_len      = 8,
564                 .vsync_len      = 2,
565                 .left_margin    = 8,
566                 .upper_margin   = 2,
567                 .right_margin   = 24,
568                 .lower_margin   = 4,
569                 .sync           = 0,
570         },
571         [1] = {
572                 .pixclock       = 153800,
573                 .bpp            = 16,
574                 .xres           = 240,
575                 .yres           = 320,
576                 .hsync_len      = 8,
577                 .vsync_len      = 2,
578                 .left_margin    = 8,
579                 .upper_margin   = 2,
580                 .right_margin   = 88,
581                 .lower_margin   = 2,
582                 .sync           = 0,
583         },
584 };
585
586 static struct pxafb_mach_info em_x270_lcd = {
587         .modes          = em_x270_lcd_modes,
588         .num_modes      = 2,
589         .lcd_conn       = LCD_COLOR_TFT_16BPP,
590 };
591
592 static void __init em_x270_init_lcd(void)
593 {
594         set_pxa_fb_info(&em_x270_lcd);
595 }
596 #else
597 static inline void em_x270_init_lcd(void) {}
598 #endif
599
600 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
601 static struct pxa2xx_spi_master em_x270_spi_info = {
602         .num_chipselect = 1,
603 };
604
605 static struct pxa2xx_spi_chip em_x270_tdo24m_chip = {
606         .rx_threshold = 1,
607         .tx_threshold = 1,
608 };
609
610 static struct tdo24m_platform_data em_x270_tdo24m_pdata = {
611         .model = TDO35S,
612 };
613
614 static struct spi_board_info em_x270_spi_devices[] __initdata = {
615         {
616                 .modalias = "tdo24m",
617                 .max_speed_hz = 1000000,
618                 .bus_num = 1,
619                 .chip_select = 0,
620                 .controller_data = &em_x270_tdo24m_chip,
621                 .platform_data = &em_x270_tdo24m_pdata,
622         },
623 };
624
625 static void __init em_x270_init_spi(void)
626 {
627         pxa2xx_set_spi_info(1, &em_x270_spi_info);
628         spi_register_board_info(ARRAY_AND_SIZE(em_x270_spi_devices));
629 }
630 #else
631 static inline void em_x270_init_spi(void) {}
632 #endif
633
634 #if defined(CONFIG_SND_PXA2XX_AC97) || defined(CONFIG_SND_PXA2XX_AC97_MODULE)
635 static void __init em_x270_init_ac97(void)
636 {
637         pxa_set_ac97_info(NULL);
638 }
639 #else
640 static inline void em_x270_init_ac97(void) {}
641 #endif
642
643 #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
644 static unsigned int em_x270_matrix_keys[] = {
645         KEY(0, 0, KEY_A), KEY(1, 0, KEY_UP), KEY(2, 1, KEY_B),
646         KEY(0, 2, KEY_LEFT), KEY(1, 1, KEY_ENTER), KEY(2, 0, KEY_RIGHT),
647         KEY(0, 1, KEY_C), KEY(1, 2, KEY_DOWN), KEY(2, 2, KEY_D),
648 };
649
650 struct pxa27x_keypad_platform_data em_x270_keypad_info = {
651         /* code map for the matrix keys */
652         .matrix_key_rows        = 3,
653         .matrix_key_cols        = 3,
654         .matrix_key_map         = em_x270_matrix_keys,
655         .matrix_key_map_size    = ARRAY_SIZE(em_x270_matrix_keys),
656 };
657
658 static void __init em_x270_init_keypad(void)
659 {
660         pxa_set_keypad_info(&em_x270_keypad_info);
661 }
662 #else
663 static inline void em_x270_init_keypad(void) {}
664 #endif
665
666 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
667 static struct gpio_keys_button gpio_keys_button[] = {
668         [0] = {
669                 .desc   = "sleep/wakeup",
670                 .code   = KEY_SUSPEND,
671                 .type   = EV_PWR,
672                 .gpio   = 1,
673                 .wakeup = 1,
674         },
675 };
676
677 static struct gpio_keys_platform_data em_x270_gpio_keys_data = {
678         .buttons        = gpio_keys_button,
679         .nbuttons       = 1,
680 };
681
682 static struct platform_device em_x270_gpio_keys = {
683         .name           = "gpio-keys",
684         .id             = -1,
685         .dev            = {
686                 .platform_data  = &em_x270_gpio_keys_data,
687         },
688 };
689
690 static void __init em_x270_init_gpio_keys(void)
691 {
692         platform_device_register(&em_x270_gpio_keys);
693 }
694 #else
695 static inline void em_x270_init_gpio_keys(void) {}
696 #endif
697
698 /* Quick Capture Interface and sensor setup */
699 #if defined(CONFIG_VIDEO_PXA27x) || defined(CONFIG_VIDEO_PXA27x_MODULE)
700 static struct regulator *em_x270_camera_ldo;
701
702 static int em_x270_sensor_init(struct device *dev)
703 {
704         int ret;
705
706         ret = gpio_request(GPIO93_CAM_RESET, "camera reset");
707         if (ret)
708                 return ret;
709
710         gpio_direction_output(GPIO93_CAM_RESET, 0);
711
712         em_x270_camera_ldo = regulator_get(NULL, "vcc cam");
713         if (em_x270_camera_ldo == NULL) {
714                 gpio_free(GPIO93_CAM_RESET);
715                 return -ENODEV;
716         }
717
718         ret = regulator_enable(em_x270_camera_ldo);
719         if (ret) {
720                 regulator_put(em_x270_camera_ldo);
721                 gpio_free(GPIO93_CAM_RESET);
722                 return ret;
723         }
724
725         gpio_set_value(GPIO93_CAM_RESET, 1);
726
727         return 0;
728 }
729
730 struct pxacamera_platform_data em_x270_camera_platform_data = {
731         .init   = em_x270_sensor_init,
732         .flags  = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 |
733                 PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
734         .mclk_10khz = 2600,
735 };
736
737 static int em_x270_sensor_power(struct device *dev, int on)
738 {
739         int ret;
740         int is_on = regulator_is_enabled(em_x270_camera_ldo);
741
742         if (on == is_on)
743                 return 0;
744
745         gpio_set_value(GPIO93_CAM_RESET, !on);
746
747         if (on)
748                 ret = regulator_enable(em_x270_camera_ldo);
749         else
750                 ret = regulator_disable(em_x270_camera_ldo);
751
752         if (ret)
753                 return ret;
754
755         gpio_set_value(GPIO93_CAM_RESET, on);
756
757         return 0;
758 }
759
760 static struct soc_camera_link iclink = {
761         .bus_id = 0,
762         .power = em_x270_sensor_power,
763 };
764
765 static struct i2c_board_info em_x270_i2c_cam_info[] = {
766         {
767                 I2C_BOARD_INFO("mt9m111", 0x48),
768                 .platform_data = &iclink,
769         },
770 };
771
772 static struct i2c_pxa_platform_data em_x270_i2c_info = {
773         .fast_mode = 1,
774 };
775
776 static void  __init em_x270_init_camera(void)
777 {
778         pxa_set_i2c_info(&em_x270_i2c_info);
779         i2c_register_board_info(0, ARRAY_AND_SIZE(em_x270_i2c_cam_info));
780         pxa_set_camera_info(&em_x270_camera_platform_data);
781 }
782 #else
783 static inline void em_x270_init_camera(void) {}
784 #endif
785
786 /* DA9030 related initializations */
787 #define REGULATOR_CONSUMER(_name, _dev, _supply)                               \
788         static struct regulator_consumer_supply _name##_consumers[] = { \
789                 {                                                       \
790                         .dev = _dev,                                    \
791                         .supply = _supply,                              \
792                 },                                                      \
793         }
794
795 REGULATOR_CONSUMER(ldo3, NULL, "vcc gps");
796 REGULATOR_CONSUMER(ldo5, NULL, "vcc cam");
797 REGULATOR_CONSUMER(ldo10, &pxa_device_mci.dev, "vcc sdio");
798 REGULATOR_CONSUMER(ldo12, NULL, "vcc usb");
799 REGULATOR_CONSUMER(ldo19, NULL, "vcc gprs");
800
801 #define REGULATOR_INIT(_ldo, _min_uV, _max_uV, _ops_mask)               \
802         static struct regulator_init_data _ldo##_data = {               \
803                 .constraints = {                                        \
804                         .min_uV = _min_uV,                              \
805                         .max_uV = _max_uV,                              \
806                         .state_mem = {                                  \
807                                 .enabled = 0,                           \
808                         },                                              \
809                         .valid_ops_mask = _ops_mask,                    \
810                 },                                                      \
811                 .num_consumer_supplies = ARRAY_SIZE(_ldo##_consumers),  \
812                 .consumer_supplies = _ldo##_consumers,                  \
813         };
814
815 REGULATOR_INIT(ldo3, 3200000, 3200000, REGULATOR_CHANGE_STATUS);
816 REGULATOR_INIT(ldo5, 3000000, 3000000, REGULATOR_CHANGE_STATUS);
817 REGULATOR_INIT(ldo10, 2000000, 3200000,
818                REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE);
819 REGULATOR_INIT(ldo12, 3000000, 3000000, REGULATOR_CHANGE_STATUS);
820 REGULATOR_INIT(ldo19, 3200000, 3200000, REGULATOR_CHANGE_STATUS);
821
822 struct led_info em_x270_led_info = {
823         .name = "em-x270:orange",
824         .default_trigger = "battery-charging-or-full",
825 };
826
827 #define DA9030_SUBDEV(_name, _id, _pdata)       \
828         {                                       \
829                 .name = "da903x-" #_name,       \
830                 .id = DA9030_ID_##_id,          \
831                 .platform_data = _pdata,        \
832         }
833
834 #define DA9030_LDO(num) DA9030_SUBDEV(regulator, LDO##num, &ldo##num##_data)
835
836 struct da903x_subdev_info em_x270_da9030_subdevs[] = {
837         DA9030_LDO(3),
838         DA9030_LDO(5),
839         DA9030_LDO(10),
840         DA9030_LDO(12),
841         DA9030_LDO(19),
842
843         DA9030_SUBDEV(led, LED_PC, &em_x270_led_info),
844         DA9030_SUBDEV(backlight, WLED, &em_x270_led_info),
845 };
846
847 static struct da903x_platform_data em_x270_da9030_info = {
848         .num_subdevs = ARRAY_SIZE(em_x270_da9030_subdevs),
849         .subdevs = em_x270_da9030_subdevs,
850 };
851
852 static struct i2c_board_info em_x270_i2c_pmic_info = {
853         I2C_BOARD_INFO("da9030", 0x49),
854         .irq = IRQ_GPIO(0),
855         .platform_data = &em_x270_da9030_info,
856 };
857
858 static struct i2c_pxa_platform_data em_x270_pwr_i2c_info = {
859         .use_pio = 1,
860 };
861
862 static void __init em_x270_init_da9030(void)
863 {
864         pxa27x_set_i2c_power_info(&em_x270_pwr_i2c_info);
865         i2c_register_board_info(1, &em_x270_i2c_pmic_info, 1);
866 }
867
868 static void __init em_x270_init(void)
869 {
870         pxa2xx_mfp_config(ARRAY_AND_SIZE(em_x270_pin_config));
871
872         em_x270_init_da9030();
873         em_x270_init_dm9000();
874         em_x270_init_rtc();
875         em_x270_init_nand();
876         em_x270_init_nor();
877         em_x270_init_lcd();
878         em_x270_init_mmc();
879         em_x270_init_ohci();
880         em_x270_init_keypad();
881         em_x270_init_gpio_keys();
882         em_x270_init_ac97();
883         em_x270_init_camera();
884         em_x270_init_spi();
885 }
886
887 MACHINE_START(EM_X270, "Compulab EM-X270")
888         .boot_params    = 0xa0000100,
889         .phys_io        = 0x40000000,
890         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
891         .map_io         = pxa_map_io,
892         .init_irq       = pxa27x_init_irq,
893         .timer          = &pxa_timer,
894         .init_machine   = em_x270_init,
895 MACHINE_END