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