Merge branch 'stable-3.2' into pandora-3.2
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap3pandora.c
1 /*
2  * board-omap3pandora.c (Pandora Handheld Console)
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16  * 02110-1301 USA
17  *
18  */
19
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/platform_device.h>
23
24 #include <linux/spi/spi.h>
25 #include <linux/regulator/machine.h>
26 #include <linux/i2c/twl.h>
27 #include <linux/wl12xx.h>
28 #include <linux/mtd/partitions.h>
29 #include <linux/mtd/nand.h>
30 #include <linux/leds.h>
31 #include <linux/leds_pwm.h>
32 #include <linux/input.h>
33 #include <linux/input/matrix_keypad.h>
34 #include <linux/gpio.h>
35 #include <linux/gpio_keys.h>
36 #include <linux/mmc/host.h>
37 #include <linux/mmc/card.h>
38 #include <linux/regulator/fixed.h>
39 #include <linux/i2c/vsense.h>
40
41 #include <asm/mach-types.h>
42 #include <asm/mach/arch.h>
43 #include <asm/mach/map.h>
44
45 #include <plat/board.h>
46 #include <plat/common.h>
47 #include <mach/hardware.h>
48 #include <plat/mcspi.h>
49 #include <plat/usb.h>
50 #include <video/omapdss.h>
51 #include <plat/nand.h>
52
53 #include "mux.h"
54 #include "sdram-micron-mt46h32m32lf-6.h"
55 #include "sdram-micron-mt29c4g96mazapcjg-5.h"
56 #include "hsmmc.h"
57 #include "common-board-devices.h"
58
59 #define PANDORA_WIFI_IRQ_GPIO           21
60 #define PANDORA_WIFI_NRESET_GPIO        23
61 #define OMAP3_PANDORA_TS_GPIO           94
62 #define PANDORA_EN_USB_5V_GPIO          164
63
64 static struct mtd_partition omap3pandora_nand_partitions[] = {
65         {
66                 .name           = "xloader",
67                 .offset         = 0,
68                 .size           = 4 * NAND_BLOCK_SIZE,
69                 .mask_flags     = MTD_WRITEABLE
70         }, {
71                 .name           = "uboot",
72                 .offset         = MTDPART_OFS_APPEND,
73                 .size           = 15 * NAND_BLOCK_SIZE,
74         }, {
75                 .name           = "uboot-env",
76                 .offset         = MTDPART_OFS_APPEND,
77                 .size           = 1 * NAND_BLOCK_SIZE,
78         }, {
79                 .name           = "boot",
80                 .offset         = MTDPART_OFS_APPEND,
81                 .size           = 80 * NAND_BLOCK_SIZE,
82         }, {
83                 .name           = "rootfs",
84                 .offset         = MTDPART_OFS_APPEND,
85                 .size           = MTDPART_SIZ_FULL,
86         },
87 };
88
89 static struct omap_nand_platform_data pandora_nand_data = {
90         .cs             = 0,
91         .devsize        = NAND_BUSWIDTH_16,
92         .xfer_type      = NAND_OMAP_PREFETCH_DMA,
93         .parts          = omap3pandora_nand_partitions,
94         .nr_parts       = ARRAY_SIZE(omap3pandora_nand_partitions),
95         .dev_ready      = true,
96 };
97
98 static struct gpio_led pandora_gpio_leds[] = {
99         {
100                 .name                   = "pandora::sd1",
101                 .default_trigger        = "mmc0",
102                 .gpio                   = 128,
103         }, {
104                 .name                   = "pandora::sd2",
105                 .default_trigger        = "mmc1",
106                 .gpio                   = 129,
107         }, {
108                 .name                   = "pandora::bluetooth",
109                 .gpio                   = 158,
110         }, {
111                 .name                   = "pandora::wifi",
112                 .gpio                   = 159,
113         },
114 };
115
116 static struct gpio_led_platform_data pandora_gpio_led_data = {
117         .leds           = pandora_gpio_leds,
118         .num_leds       = ARRAY_SIZE(pandora_gpio_leds),
119 };
120
121 static struct platform_device pandora_leds_gpio = {
122         .name   = "leds-gpio",
123         .id     = -1,
124         .dev    = {
125                 .platform_data  = &pandora_gpio_led_data,
126         },
127 };
128
129 static struct led_pwm pandora_pwm_leds[] = {
130         {
131                 .name                   = "pandora::keypad_bl",
132                 .pwm_id                 = 0, /* LEDA */
133         }, {
134                 .name                   = "pandora::power",
135                 .default_trigger        = "default-on",
136                 .pwm_id                 = 1, /* LEDB */
137         }, {
138                 .name                   = "pandora::charger",
139                 .default_trigger        = "bq27500-0-charging",
140                 .pwm_id                 = 3, /* PWM1 */
141         }
142 };
143
144 static struct led_pwm_platform_data pandora_pwm_led_data = {
145         .leds           = pandora_pwm_leds,
146         .num_leds       = ARRAY_SIZE(pandora_pwm_leds),
147 };
148
149 static struct platform_device pandora_leds_pwm = {
150         .name   = "leds-twl4030-pwm",
151         .id     = -1,
152         .dev    = {
153                 .platform_data  = &pandora_pwm_led_data,
154         },
155 };
156
157 static struct platform_device pandora_bl = {
158         .name   = "pandora-backlight",
159         .id     = -1,
160 };
161
162 #define GPIO_BUTTON(gpio_num, ev_type, ev_code, act_low, descr) \
163 {                                                               \
164         .gpio           = gpio_num,                             \
165         .type           = ev_type,                              \
166         .code           = ev_code,                              \
167         .active_low     = act_low,                              \
168         .debounce_interval = 4,                                 \
169         .desc           = "btn " descr,                         \
170 }
171
172 #define GPIO_BUTTON_LOW(gpio_num, event_code, description)      \
173         GPIO_BUTTON(gpio_num, EV_KEY, event_code, 1, description)
174
175 static struct gpio_keys_button pandora_gpio_keys[] = {
176         GPIO_BUTTON_LOW(110,    KEY_UP,         "up"),
177         GPIO_BUTTON_LOW(103,    KEY_DOWN,       "down"),
178         GPIO_BUTTON_LOW(96,     KEY_LEFT,       "left"),
179         GPIO_BUTTON_LOW(98,     KEY_RIGHT,      "right"),
180         GPIO_BUTTON_LOW(109,    KEY_PAGEUP,     "game 1"),
181         GPIO_BUTTON_LOW(111,    KEY_END,        "game 2"),
182         GPIO_BUTTON_LOW(106,    KEY_PAGEDOWN,   "game 3"),
183         GPIO_BUTTON_LOW(101,    KEY_HOME,       "game 4"),
184         GPIO_BUTTON_LOW(102,    KEY_RIGHTSHIFT, "l"),
185         GPIO_BUTTON_LOW(97,     KEY_KPPLUS,     "l2"),
186         GPIO_BUTTON_LOW(105,    KEY_RIGHTCTRL,  "r"),
187         GPIO_BUTTON_LOW(107,    KEY_KPMINUS,    "r2"),
188         GPIO_BUTTON_LOW(104,    KEY_LEFTCTRL,   "ctrl"),
189         GPIO_BUTTON_LOW(99,     KEY_MENU,       "menu"),
190         GPIO_BUTTON_LOW(176,    KEY_COFFEE,     "hold"),
191         GPIO_BUTTON(100, EV_KEY, KEY_LEFTALT, 0, "alt"),
192         GPIO_BUTTON(108, EV_SW, SW_LID, 1, "lid"),
193 };
194
195 static struct gpio_keys_platform_data pandora_gpio_key_info = {
196         .buttons        = pandora_gpio_keys,
197         .nbuttons       = ARRAY_SIZE(pandora_gpio_keys),
198 };
199
200 static struct platform_device pandora_keys_gpio = {
201         .name   = "gpio-keys",
202         .id     = -1,
203         .dev    = {
204                 .platform_data  = &pandora_gpio_key_info,
205         },
206 };
207
208 /* HACK: this requires patched twl4030_keypad driver */
209 #define FNKEY(row, col, code) KEY((row + 8), col, code)
210
211 static const uint32_t board_keymap[] = {
212         /* row, col, code */
213         KEY(0, 0, KEY_9),
214         KEY(0, 1, KEY_8),
215         KEY(0, 2, KEY_I),
216         KEY(0, 3, KEY_J),
217         KEY(0, 4, KEY_N),
218         KEY(0, 5, KEY_M),
219         KEY(1, 0, KEY_0),
220         KEY(1, 1, KEY_7),
221         KEY(1, 2, KEY_U),
222         KEY(1, 3, KEY_H),
223         KEY(1, 4, KEY_B),
224         KEY(1, 5, KEY_SPACE),
225         KEY(2, 0, KEY_BACKSPACE),
226         KEY(2, 1, KEY_6),
227         KEY(2, 2, KEY_Y),
228         KEY(2, 3, KEY_G),
229         KEY(2, 4, KEY_V),
230         KEY(2, 5, KEY_FN),
231         KEY(3, 0, KEY_O),
232         KEY(3, 1, KEY_5),
233         KEY(3, 2, KEY_T),
234         KEY(3, 3, KEY_F),
235         KEY(3, 4, KEY_C),
236         KEY(4, 0, KEY_P),
237         KEY(4, 1, KEY_4),
238         KEY(4, 2, KEY_R),
239         KEY(4, 3, KEY_D),
240         KEY(4, 4, KEY_X),
241         KEY(5, 0, KEY_K),
242         KEY(5, 1, KEY_3),
243         KEY(5, 2, KEY_E),
244         KEY(5, 3, KEY_S),
245         KEY(5, 4, KEY_Z),
246         KEY(6, 0, KEY_L),
247         KEY(6, 1, KEY_2),
248         KEY(6, 2, KEY_W),
249         KEY(6, 3, KEY_A),
250         KEY(6, 4, KEY_DOT),
251         KEY(7, 0, KEY_ENTER),
252         KEY(7, 1, KEY_1),
253         KEY(7, 2, KEY_Q),
254         KEY(7, 3, KEY_LEFTSHIFT),
255         KEY(7, 4, KEY_COMMA),
256         /* Fn keys */
257         FNKEY(0, 0, KEY_F9),
258         FNKEY(0, 1, KEY_F8),
259         FNKEY(0, 2, KEY_BRIGHTNESSUP),
260         FNKEY(0, 3, KEY_F13),           /* apostrophe, differs from Fn-A? */
261         FNKEY(0, 4, KEY_F22),
262         FNKEY(0, 5, KEY_F23),
263         FNKEY(1, 0, KEY_F10),
264         FNKEY(1, 1, KEY_F7),
265         FNKEY(1, 2, KEY_BRIGHTNESSDOWN),
266         FNKEY(1, 3, KEY_GRAVE),
267         FNKEY(1, 4, KEY_F14),           /* pipe/bar */
268         FNKEY(1, 5, KEY_TAB),
269         FNKEY(2, 0, KEY_INSERT),
270         FNKEY(2, 1, KEY_F6),
271         FNKEY(2, 2, KEY_F15),           /* dash */
272         FNKEY(2, 3, KEY_EQUAL),
273         FNKEY(2, 4, KEY_F16),           /* # (pound/hash) */
274         FNKEY(2, 5, KEY_FN),
275         FNKEY(3, 0, KEY_F11),
276         FNKEY(3, 1, KEY_F5),
277         FNKEY(3, 2, KEY_F17),           /* ! */
278         FNKEY(3, 3, KEY_KPPLUS),
279         FNKEY(3, 4, KEY_BACKSLASH),
280         FNKEY(4, 0, KEY_F12),
281         FNKEY(4, 1, KEY_F4),
282         FNKEY(4, 2, KEY_RIGHTBRACE),
283         FNKEY(4, 3, KEY_KPMINUS),
284         FNKEY(4, 4, KEY_QUESTION),
285         FNKEY(5, 0, KEY_F18),           /* Â£ (pound) */
286         FNKEY(5, 1, KEY_F3),
287         FNKEY(5, 2, KEY_LEFTBRACE),
288         FNKEY(5, 3, KEY_F19),           /* " */
289         FNKEY(5, 4, KEY_SLASH),
290         FNKEY(6, 0, KEY_YEN),
291         FNKEY(6, 1, KEY_F2),
292         FNKEY(6, 2, KEY_F20),           /* @ */
293         FNKEY(6, 3, KEY_APOSTROPHE),
294         FNKEY(6, 4, KEY_F21),           /* : */
295         FNKEY(7, 0, KEY_ENTER),
296         FNKEY(7, 1, KEY_F1),
297         FNKEY(7, 2, KEY_ESC),
298         FNKEY(7, 3, KEY_CAPSLOCK),
299         FNKEY(7, 4, KEY_SEMICOLON),
300 };
301
302 static struct matrix_keymap_data board_map_data = {
303         .keymap                 = board_keymap,
304         .keymap_size            = ARRAY_SIZE(board_keymap),
305 };
306
307 static struct twl4030_keypad_data pandora_kp_data = {
308         .keymap_data    = &board_map_data,
309         .rows           = 8,
310         .cols           = 6,
311         .rep            = 1,
312 };
313
314 static struct omap_dss_device pandora_lcd_device = {
315         .name                   = "lcd",
316         .driver_name            = "tpo_td043mtea1_panel",
317         .type                   = OMAP_DISPLAY_TYPE_DPI,
318         .phy.dpi.data_lines     = 24,
319         .reset_gpio             = 157,
320 };
321
322 static struct omap_dss_device pandora_tv_device = {
323         .name                   = "tv",
324         .driver_name            = "venc",
325         .type                   = OMAP_DISPLAY_TYPE_VENC,
326         .phy.venc.type          = OMAP_DSS_VENC_TYPE_SVIDEO,
327 };
328
329 static struct omap_dss_device *pandora_dss_devices[] = {
330         &pandora_lcd_device,
331         &pandora_tv_device,
332 };
333
334 static struct omap_dss_board_info pandora_dss_data = {
335         .num_devices    = ARRAY_SIZE(pandora_dss_devices),
336         .devices        = pandora_dss_devices,
337         .default_device = &pandora_lcd_device,
338 };
339
340 static void pandora_wl1251_init_card(struct mmc_card *card)
341 {
342         /*
343          * We have TI wl1251 attached to MMC3. Pass this information to
344          * SDIO core because it can't be probed by normal methods.
345          */
346         card->quirks |= MMC_QUIRK_NONSTD_SDIO;
347         card->cccr.wide_bus = 1;
348         card->cis.vendor = 0x104c;
349         card->cis.device = 0x9066;
350         card->cis.blksize = 512;
351         card->cis.max_dtr = 20000000;
352 }
353
354 static struct omap2_hsmmc_info omap3pandora_mmc[] = {
355         {
356                 .mmc            = 1,
357                 .caps           = MMC_CAP_4_BIT_DATA,
358                 .gpio_cd        = -EINVAL,
359                 //.gpio_wp      = 126,
360                 .gpio_wp        = -EINVAL,
361                 .ext_clock      = 0,
362         },
363         {
364                 .mmc            = 2,
365                 .caps           = MMC_CAP_4_BIT_DATA,
366                 .gpio_cd        = -EINVAL,
367                 //.gpio_wp      = 127,
368                 .gpio_wp        = -EINVAL,
369                 .ext_clock      = 1,
370                 .transceiver    = true,
371         },
372         {
373                 .mmc            = 3,
374                 .caps           = MMC_CAP_4_BIT_DATA | MMC_CAP_POWER_OFF_CARD,
375                 .gpio_cd        = -EINVAL,
376                 .gpio_wp        = -EINVAL,
377                 .init_card      = pandora_wl1251_init_card,
378         },
379         {}      /* Terminator */
380 };
381
382 static int omap3pandora_twl_gpio_setup(struct device *dev,
383                 unsigned gpio, unsigned ngpio)
384 {
385         int ret, gpio_32khz;
386
387         /* gpio + {0,1} is "mmc{0,1}_cd" (input/IRQ) */
388         omap3pandora_mmc[0].gpio_cd = gpio + 0;
389         omap3pandora_mmc[1].gpio_cd = gpio + 1;
390         omap2_hsmmc_init(omap3pandora_mmc);
391
392         /* gpio + 13 drives 32kHz buffer for wifi module */
393         gpio_32khz = gpio + 13;
394         ret = gpio_request_one(gpio_32khz, GPIOF_OUT_INIT_HIGH, "wifi 32kHz");
395         if (ret < 0) {
396                 pr_err("Cannot get GPIO line %d, ret=%d\n", gpio_32khz, ret);
397                 return -ENODEV;
398         }
399
400         return 0;
401 }
402
403 static struct twl4030_gpio_platform_data omap3pandora_gpio_data = {
404         .gpio_base      = OMAP_MAX_GPIO_LINES,
405         .irq_base       = TWL4030_GPIO_IRQ_BASE,
406         .irq_end        = TWL4030_GPIO_IRQ_END,
407         .setup          = omap3pandora_twl_gpio_setup,
408 };
409
410 static struct regulator_consumer_supply pandora_vmmc1_supply[] = {
411         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
412 };
413
414 static struct regulator_consumer_supply pandora_vmmc2_supply[] = {
415         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.1")
416 };
417
418 static struct regulator_consumer_supply pandora_vmmc3_supply[] = {
419         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.2"),
420 };
421
422 static struct regulator_consumer_supply pandora_vdds_supplies[] = {
423         REGULATOR_SUPPLY("vdds_sdi", "omapdss"),
424         REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
425         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
426 };
427
428 static struct regulator_consumer_supply pandora_vcc_lcd_supply[] = {
429         REGULATOR_SUPPLY("vcc", "display0"),
430 };
431
432 static struct regulator_consumer_supply pandora_usb_phy_supply[] = {
433         REGULATOR_SUPPLY("hsusb1", "ehci-omap.0"),
434 };
435
436 /* ads7846 on SPI and 2 nub controllers on I2C */
437 static struct regulator_consumer_supply pandora_vaux4_supplies[] = {
438         REGULATOR_SUPPLY("vcc", "spi1.0"),
439         REGULATOR_SUPPLY("vcc", "3-0066"),
440         REGULATOR_SUPPLY("vcc", "3-0067"),
441 };
442
443 static struct regulator_consumer_supply pandora_adac_supply[] = {
444         REGULATOR_SUPPLY("vcc", "soc-audio"),
445         REGULATOR_SUPPLY("lidsw", NULL),
446 };
447
448 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
449 static struct regulator_init_data pandora_vmmc1 = {
450         .constraints = {
451                 .min_uV                 = 1850000,
452                 .max_uV                 = 3150000,
453                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
454                                         | REGULATOR_MODE_STANDBY,
455                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
456                                         | REGULATOR_CHANGE_MODE
457                                         | REGULATOR_CHANGE_STATUS,
458         },
459         .num_consumer_supplies  = ARRAY_SIZE(pandora_vmmc1_supply),
460         .consumer_supplies      = pandora_vmmc1_supply,
461 };
462
463 /* VMMC2 for MMC2 pins CMD, CLK, DAT0..DAT3 (max 100 mA) */
464 static struct regulator_init_data pandora_vmmc2 = {
465         .constraints = {
466                 .min_uV                 = 1850000,
467                 .max_uV                 = 3150000,
468                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
469                                         | REGULATOR_MODE_STANDBY,
470                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
471                                         | REGULATOR_CHANGE_MODE
472                                         | REGULATOR_CHANGE_STATUS,
473         },
474         .num_consumer_supplies  = ARRAY_SIZE(pandora_vmmc2_supply),
475         .consumer_supplies      = pandora_vmmc2_supply,
476 };
477
478 /* VAUX1 for LCD */
479 static struct regulator_init_data pandora_vaux1 = {
480         .constraints = {
481                 .min_uV                 = 3000000,
482                 .max_uV                 = 3000000,
483                 .apply_uV               = true,
484                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
485                                         | REGULATOR_MODE_STANDBY,
486                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
487                                         | REGULATOR_CHANGE_STATUS,
488         },
489         .num_consumer_supplies  = ARRAY_SIZE(pandora_vcc_lcd_supply),
490         .consumer_supplies      = pandora_vcc_lcd_supply,
491 };
492
493 /* VAUX2 for USB host PHY */
494 static struct regulator_init_data pandora_vaux2 = {
495         .constraints = {
496                 .min_uV                 = 1800000,
497                 .max_uV                 = 1800000,
498                 .apply_uV               = true,
499                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
500                                         | REGULATOR_MODE_STANDBY,
501                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
502                                         | REGULATOR_CHANGE_STATUS,
503         },
504         .num_consumer_supplies  = ARRAY_SIZE(pandora_usb_phy_supply),
505         .consumer_supplies      = pandora_usb_phy_supply,
506 };
507
508 /* VAUX4 for ads7846 and nubs */
509 static struct regulator_init_data pandora_vaux4 = {
510         .constraints = {
511                 .min_uV                 = 2800000,
512                 .max_uV                 = 2800000,
513                 .apply_uV               = true,
514                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
515                                         | REGULATOR_MODE_STANDBY,
516                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
517                                         | REGULATOR_CHANGE_STATUS,
518         },
519         .num_consumer_supplies  = ARRAY_SIZE(pandora_vaux4_supplies),
520         .consumer_supplies      = pandora_vaux4_supplies,
521 };
522
523 /* VSIM for audio DAC */
524 static struct regulator_init_data pandora_vsim = {
525         .constraints = {
526                 .min_uV                 = 2800000,
527                 .max_uV                 = 2800000,
528                 .apply_uV               = true,
529                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
530                                         | REGULATOR_MODE_STANDBY,
531                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
532                                         | REGULATOR_CHANGE_STATUS,
533         },
534         .num_consumer_supplies  = ARRAY_SIZE(pandora_adac_supply),
535         .consumer_supplies      = pandora_adac_supply,
536 };
537
538 /* Fixed regulator internal to Wifi module */
539 static struct regulator_init_data pandora_vmmc3 = {
540         .constraints = {
541                 .valid_ops_mask         = REGULATOR_CHANGE_STATUS,
542         },
543         .num_consumer_supplies  = ARRAY_SIZE(pandora_vmmc3_supply),
544         .consumer_supplies      = pandora_vmmc3_supply,
545 };
546
547 static struct fixed_voltage_config pandora_vwlan = {
548         .supply_name            = "vwlan",
549         .microvolts             = 1800000, /* 1.8V */
550         .gpio                   = PANDORA_WIFI_NRESET_GPIO,
551         .startup_delay          = 50000, /* 50ms */
552         .enable_high            = 1,
553         .enabled_at_boot        = 0,
554         .init_data              = &pandora_vmmc3,
555 };
556
557 static struct platform_device pandora_vwlan_device = {
558         .name           = "reg-fixed-voltage",
559         .id             = 1,
560         .dev = {
561                 .platform_data = &pandora_vwlan,
562         },
563 };
564
565 static char *pandora_power_supplied_to[] = {
566         "bq27500-0",
567 };
568
569 static struct twl4030_bci_platform_data pandora_bci_data = {
570         .supplied_to            = pandora_power_supplied_to,
571         .num_supplicants        = ARRAY_SIZE(pandora_power_supplied_to),
572 };
573
574 static struct twl4030_power_data pandora_power_data = {
575         .use_poweroff   = 1,
576 };
577
578 static struct twl4030_platform_data omap3pandora_twldata = {
579         .gpio           = &omap3pandora_gpio_data,
580         .vmmc1          = &pandora_vmmc1,
581         .vmmc2          = &pandora_vmmc2,
582         .vaux1          = &pandora_vaux1,
583         .vaux2          = &pandora_vaux2,
584         .vaux4          = &pandora_vaux4,
585         .vsim           = &pandora_vsim,
586         .keypad         = &pandora_kp_data,
587         .bci            = &pandora_bci_data,
588         .power          = &pandora_power_data,
589 };
590
591 static struct i2c_board_info __initdata omap3pandora_i2c_boardinfo[] = {
592         {
593                 I2C_BOARD_INFO("tps65950", 0x48),
594                 .flags = I2C_CLIENT_WAKE,
595                 .irq = INT_34XX_SYS_NIRQ,
596                 .platform_data = &omap3pandora_twldata,
597         },
598 };
599
600 static struct vsense_platform_data omap3pandora_nub1_data = {
601         .gpio_irq       = 161,
602         .gpio_reset     = 156,
603 };
604
605 static struct vsense_platform_data omap3pandora_nub2_data = {
606         .gpio_irq       = 162,
607         .gpio_reset     = 156,
608 };
609
610 static struct i2c_board_info __initdata omap3pandora_i2c3_boardinfo[] = {
611         {
612                 I2C_BOARD_INFO("vsense", 0x66),
613                 .flags = I2C_CLIENT_WAKE,
614                 .platform_data = &omap3pandora_nub1_data,
615         }, {
616                 I2C_BOARD_INFO("vsense", 0x67),
617                 .flags = I2C_CLIENT_WAKE,
618                 .platform_data = &omap3pandora_nub2_data,
619         }, {
620                 I2C_BOARD_INFO("bq27500", 0x55),
621                 .flags = I2C_CLIENT_WAKE,
622         },
623 };
624
625 static int __init omap3pandora_i2c_init(void)
626 {
627         omap3_pmic_get_config(&omap3pandora_twldata,
628                         TWL_COMMON_PDATA_USB | TWL_COMMON_PDATA_AUDIO,
629                         TWL_COMMON_REGULATOR_VDAC | TWL_COMMON_REGULATOR_VPLL2);
630
631         omap3pandora_twldata.vdac->constraints.apply_uV = true;
632
633         omap3pandora_twldata.vpll2->constraints.apply_uV = true;
634         omap3pandora_twldata.vpll2->num_consumer_supplies =
635                                         ARRAY_SIZE(pandora_vdds_supplies);
636         omap3pandora_twldata.vpll2->consumer_supplies = pandora_vdds_supplies;
637
638         omap3_pmic_init("tps65950", &omap3pandora_twldata);
639         /* i2c2 pins are not connected */
640         omap_register_i2c_bus(3, 100, omap3pandora_i2c3_boardinfo,
641                         ARRAY_SIZE(omap3pandora_i2c3_boardinfo));
642         return 0;
643 }
644
645 static struct spi_board_info omap3pandora_spi_board_info[] __initdata = {
646         {
647                 .modalias               = "tpo_td043mtea1_panel_spi",
648                 .bus_num                = 1,
649                 .chip_select            = 1,
650                 .max_speed_hz           = 375000,
651                 .platform_data          = &pandora_lcd_device,
652         }
653 };
654
655 static void __init pandora_wl1251_init(void)
656 {
657         struct wl12xx_platform_data pandora_wl1251_pdata;
658         int ret;
659
660         memset(&pandora_wl1251_pdata, 0, sizeof(pandora_wl1251_pdata));
661
662         ret = gpio_request_one(PANDORA_WIFI_IRQ_GPIO, GPIOF_IN, "wl1251 irq");
663         if (ret < 0)
664                 goto fail;
665
666         pandora_wl1251_pdata.irq = gpio_to_irq(PANDORA_WIFI_IRQ_GPIO);
667         if (pandora_wl1251_pdata.irq < 0)
668                 goto fail_irq;
669
670         pandora_wl1251_pdata.use_eeprom = true;
671         ret = wl12xx_set_platform_data(&pandora_wl1251_pdata);
672         if (ret < 0)
673                 goto fail_irq;
674
675         return;
676
677 fail_irq:
678         gpio_free(PANDORA_WIFI_IRQ_GPIO);
679 fail:
680         printk(KERN_ERR "wl1251 board initialisation failed\n");
681 }
682
683 static void __init pandora_usb_host_init(void)
684 {
685         int ret;
686
687         ret = gpio_request_one(PANDORA_EN_USB_5V_GPIO, GPIOF_OUT_INIT_HIGH,
688                 "ehci vbus");
689         if (ret < 0)
690                 pr_err("Cannot set vbus GPIO, ret=%d\n", ret);
691 }
692
693 #include <linux/spi/ads7846.h>
694 #include <asm/system.h>
695
696 static DECLARE_COMPLETION(ts_completion);
697 static struct timespec ts_last_framedone;
698
699 static void vsync_irq_wait_handler(void *data, u32 mask)
700 {
701         getnstimeofday(&ts_last_framedone);
702         complete(&ts_completion);
703 }
704
705 static void ads7846_wait_for_sync(void)
706 {
707         struct timespec now, diff;
708         u32 diff_us;
709
710         getnstimeofday(&now);
711         diff = timespec_sub(now, ts_last_framedone);
712         diff_us = diff.tv_nsec / NSEC_PER_USEC + diff.tv_sec * USEC_PER_SEC;
713         if (diff_us < 1023 || diff_us > 40000)
714                 /* still blanking or display inactive */
715                 return;
716
717         /* wait for blanking period */
718         disable_hlt();
719         wait_for_completion_timeout(&ts_completion, HZ / 30);
720         enable_hlt();
721 }
722
723 static int pandora_pendown_state(void)
724 {
725         static int val_old;
726         int val;
727         int ret;
728         
729         val = !gpio_get_value(OMAP3_PANDORA_TS_GPIO);
730         if (!in_irq() && !in_atomic() && val != val_old) {
731                 init_completion(&ts_completion);
732                 dispc_runtime_get();
733                 if (val)
734                         ret = omap_dispc_register_isr(vsync_irq_wait_handler,
735                                 NULL, DISPC_IRQ_VSYNC);
736                 else
737                         ret = omap_dispc_unregister_isr(vsync_irq_wait_handler,
738                                 NULL, DISPC_IRQ_VSYNC);
739                 dispc_runtime_put();
740                 if (ret != 0)
741                         pr_err("%s: can't (un)register isr: %d %d\n",
742                                 __func__, val, ret);
743                 val_old = val;
744         }
745
746         return val;
747 }
748
749 static struct ads7846_platform_data pandora_ads7846_cfg = {
750         .x_max                  = 0x0fff,
751         .y_max                  = 0x0fff,
752         .x_plate_ohms           = 180,
753         .pressure_max           = 255,
754         .debounce_max           = 10,
755         .debounce_tol           = 3,
756         .debounce_rep           = 1,
757         .gpio_pendown           = OMAP3_PANDORA_TS_GPIO,
758         .keep_vref_on           = 1,
759         .wait_for_sync          = ads7846_wait_for_sync,
760         .get_pendown_state      = pandora_pendown_state,
761 };
762
763 static struct platform_device *omap3pandora_devices[] __initdata = {
764         &pandora_leds_gpio,
765         &pandora_leds_pwm,
766         &pandora_bl,
767         &pandora_keys_gpio,
768         &pandora_vwlan_device,
769 };
770
771 static const struct usbhs_omap_board_data usbhs_bdata __initconst = {
772
773         .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
774         .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
775         .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
776
777         .phy_reset  = true,
778         .reset_gpio_port[0]  = -EINVAL,
779         .reset_gpio_port[1]  = 16,
780         .reset_gpio_port[2]  = -EINVAL
781 };
782
783 #ifdef CONFIG_OMAP_MUX
784 static struct omap_board_mux board_mux[] __initdata = {
785         /* enable wakeup for pandora button (GPIO99) */
786         OMAP3_MUX(CAM_D0, OMAP_INPUT_EN | OMAP_WAKEUP_EN | OMAP_MUX_MODE4),
787         { .reg_offset = OMAP_MUX_TERMINATOR },
788 };
789 #endif
790
791 static struct regulator *lid_switch_power;
792
793 #ifdef CONFIG_PM_SLEEP
794 static int pandora_pm_suspend(struct device *dev)
795 {
796         if (!IS_ERR_OR_NULL(lid_switch_power))
797                 regulator_disable(lid_switch_power);
798
799         return 0;
800 }
801
802 static int pandora_pm_resume(struct device *dev)
803 {
804         if (!IS_ERR_OR_NULL(lid_switch_power))
805                 regulator_enable(lid_switch_power);
806
807         return 0;
808 }
809 #endif
810
811 static SIMPLE_DEV_PM_OPS(pandora_pm, pandora_pm_suspend, pandora_pm_resume);
812
813 static int __devinit pandora_pm_probe(struct platform_device *pdev)
814 {
815         lid_switch_power = regulator_get(NULL, "lidsw");
816         if (!IS_ERR(lid_switch_power))
817                 regulator_enable(lid_switch_power);
818
819         return 0;
820 }
821
822 static struct platform_driver pandora_pm_driver = {
823         .probe          = pandora_pm_probe,
824         .driver         = {
825                 .name   = "pandora-pm",
826                 .pm     = &pandora_pm,
827         },
828 };
829
830 static struct platform_device pandora_pm_dev = {
831         .name   = "pandora-pm",
832         .id     = -1,
833 };
834
835 static int __init pandora_pm_drv_reg(void)
836 {
837         platform_device_register(&pandora_pm_dev);
838         return platform_driver_register(&pandora_pm_driver);
839 }
840 late_initcall(pandora_pm_drv_reg);
841
842 static void __init omap3pandora_init(void)
843 {
844         struct omap_sdrc_params *sdrc_params;
845
846         omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
847         pandora_usb_host_init();
848         omap3pandora_i2c_init();
849         pandora_wl1251_init();
850         platform_add_devices(omap3pandora_devices,
851                         ARRAY_SIZE(omap3pandora_devices));
852         omap_display_init(&pandora_dss_data);
853         omap_serial_init();
854
855         sdrc_params = mt46h32m32lf6_sdrc_params;
856         if (cpu_is_omap3630() || omap_rev() >= OMAP3430_REV_ES3_0)
857                 sdrc_params = mt29c4g96mazapcjg5_sdrc_params;
858         omap_sdrc_init(sdrc_params, sdrc_params);
859
860         spi_register_board_info(omap3pandora_spi_board_info,
861                         ARRAY_SIZE(omap3pandora_spi_board_info));
862         omap_ads7846_init(1, OMAP3_PANDORA_TS_GPIO, 4, &pandora_ads7846_cfg);
863         usbhs_init(&usbhs_bdata);
864         usb_musb_init(NULL);
865         gpmc_nand_init(&pandora_nand_data);
866
867         /* Ensure SDRC pins are mux'd for self-refresh */
868         omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
869         omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
870 }
871
872 /* HACK: create it here, so that others don't need to bother */
873 #ifdef CONFIG_PROC_FS
874 #include <linux/proc_fs.h>
875
876 static int __init proc_pandora_init(void)
877 {
878         struct proc_dir_entry *ret;
879
880         ret = proc_mkdir("pandora", NULL);
881         if (!ret)
882                 return -ENOMEM;
883         return 0;
884 }
885 fs_initcall(proc_pandora_init);
886 #endif
887
888 MACHINE_START(OMAP3_PANDORA, "Pandora Handheld Console")
889         .atag_offset    = 0x100,
890         .reserve        = omap_reserve,
891         .map_io         = omap3_map_io,
892         .init_early     = omap35xx_init_early,
893         .init_irq       = omap3_init_irq,
894         .init_machine   = omap3pandora_init,
895         .timer          = &omap3_timer,
896 MACHINE_END