Merge tag 'soc2' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[platform/adaptation/renesas_rcar/renesas_kernel.git] / arch / arm / mach-pxa / magician.c
1 /*
2  * Support for HTC Magician PDA phones:
3  * i-mate JAM, O2 Xda mini, Orange SPV M500, Qtek s100, Qtek s110
4  * and T-Mobile MDA Compact.
5  *
6  * Copyright (c) 2006-2007 Philipp Zabel
7  *
8  * Based on hx4700.c, spitz.c and others.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/delay.h>
20 #include <linux/gpio.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/input.h>
23 #include <linux/mfd/htc-egpio.h>
24 #include <linux/mfd/htc-pasic3.h>
25 #include <linux/mtd/physmap.h>
26 #include <linux/pda_power.h>
27 #include <linux/pwm_backlight.h>
28 #include <linux/regulator/driver.h>
29 #include <linux/regulator/gpio-regulator.h>
30 #include <linux/regulator/machine.h>
31 #include <linux/usb/gpio_vbus.h>
32 #include <linux/i2c/pxa-i2c.h>
33
34 #include <mach/hardware.h>
35 #include <asm/mach-types.h>
36 #include <asm/mach/arch.h>
37
38 #include <mach/pxa27x.h>
39 #include <mach/magician.h>
40 #include <mach/pxafb.h>
41 #include <mach/mmc.h>
42 #include <mach/irda.h>
43 #include <mach/ohci.h>
44
45 #include "devices.h"
46 #include "generic.h"
47
48 static unsigned long magician_pin_config[] __initdata = {
49
50         /* SDRAM and Static Memory I/O Signals */
51         GPIO20_nSDCS_2,
52         GPIO21_nSDCS_3,
53         GPIO15_nCS_1,
54         GPIO78_nCS_2,   /* PASIC3 */
55         GPIO79_nCS_3,   /* EGPIO CPLD */
56         GPIO80_nCS_4,
57         GPIO33_nCS_5,
58
59         /* I2C */
60         GPIO117_I2C_SCL,
61         GPIO118_I2C_SDA,
62
63         /* PWM 0 */
64         GPIO16_PWM0_OUT,
65
66         /* I2S */
67         GPIO28_I2S_BITCLK_OUT,
68         GPIO29_I2S_SDATA_IN,
69         GPIO31_I2S_SYNC,
70         GPIO113_I2S_SYSCLK,
71
72         /* SSP 1 */
73         GPIO23_SSP1_SCLK,
74         GPIO24_SSP1_SFRM,
75         GPIO25_SSP1_TXD,
76
77         /* SSP 2 */
78         GPIO19_SSP2_SCLK,
79         GPIO14_SSP2_SFRM,
80         GPIO89_SSP2_TXD,
81         GPIO88_SSP2_RXD,
82
83         /* MMC */
84         GPIO32_MMC_CLK,
85         GPIO92_MMC_DAT_0,
86         GPIO109_MMC_DAT_1,
87         GPIO110_MMC_DAT_2,
88         GPIO111_MMC_DAT_3,
89         GPIO112_MMC_CMD,
90
91         /* LCD */
92         GPIOxx_LCD_TFT_16BPP,
93
94         /* QCI */
95         GPIO12_CIF_DD_7,
96         GPIO17_CIF_DD_6,
97         GPIO50_CIF_DD_3,
98         GPIO51_CIF_DD_2,
99         GPIO52_CIF_DD_4,
100         GPIO53_CIF_MCLK,
101         GPIO54_CIF_PCLK,
102         GPIO55_CIF_DD_1,
103         GPIO81_CIF_DD_0,
104         GPIO82_CIF_DD_5,
105         GPIO84_CIF_FV,
106         GPIO85_CIF_LV,
107
108         /* Magician specific input GPIOs */
109         GPIO9_GPIO,     /* unknown */
110         GPIO10_GPIO,    /* GSM_IRQ */
111         GPIO13_GPIO,    /* CPLD_IRQ */
112         GPIO107_GPIO,   /* DS1WM_IRQ */
113         GPIO108_GPIO,   /* GSM_READY */
114         GPIO115_GPIO,   /* nPEN_IRQ */
115
116         /* I2C */
117         GPIO117_I2C_SCL,
118         GPIO118_I2C_SDA,
119 };
120
121 /*
122  * IRDA
123  */
124
125 static struct pxaficp_platform_data magician_ficp_info = {
126         .gpio_pwdown            = GPIO83_MAGICIAN_nIR_EN,
127         .transceiver_cap        = IR_SIRMODE | IR_OFF,
128 };
129
130 /*
131  * GPIO Keys
132  */
133
134 #define INIT_KEY(_code, _gpio, _desc)   \
135         {                               \
136                 .code   = KEY_##_code,  \
137                 .gpio   = _gpio,        \
138                 .desc   = _desc,        \
139                 .type   = EV_KEY,       \
140                 .wakeup = 1,            \
141         }
142
143 static struct gpio_keys_button magician_button_table[] = {
144         INIT_KEY(POWER,      GPIO0_MAGICIAN_KEY_POWER,      "Power button"),
145         INIT_KEY(ESC,        GPIO37_MAGICIAN_KEY_HANGUP,    "Hangup button"),
146         INIT_KEY(F10,        GPIO38_MAGICIAN_KEY_CONTACTS,  "Contacts button"),
147         INIT_KEY(CALENDAR,   GPIO90_MAGICIAN_KEY_CALENDAR,  "Calendar button"),
148         INIT_KEY(CAMERA,     GPIO91_MAGICIAN_KEY_CAMERA,    "Camera button"),
149         INIT_KEY(UP,         GPIO93_MAGICIAN_KEY_UP,        "Up button"),
150         INIT_KEY(DOWN,       GPIO94_MAGICIAN_KEY_DOWN,      "Down button"),
151         INIT_KEY(LEFT,       GPIO95_MAGICIAN_KEY_LEFT,      "Left button"),
152         INIT_KEY(RIGHT,      GPIO96_MAGICIAN_KEY_RIGHT,     "Right button"),
153         INIT_KEY(KPENTER,    GPIO97_MAGICIAN_KEY_ENTER,     "Action button"),
154         INIT_KEY(RECORD,     GPIO98_MAGICIAN_KEY_RECORD,    "Record button"),
155         INIT_KEY(VOLUMEUP,   GPIO100_MAGICIAN_KEY_VOL_UP,   "Volume up"),
156         INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"),
157         INIT_KEY(PHONE,      GPIO102_MAGICIAN_KEY_PHONE,    "Phone button"),
158         INIT_KEY(PLAY,       GPIO99_MAGICIAN_HEADPHONE_IN,  "Headset button"),
159 };
160
161 static struct gpio_keys_platform_data gpio_keys_data = {
162         .buttons  = magician_button_table,
163         .nbuttons = ARRAY_SIZE(magician_button_table),
164 };
165
166 static struct platform_device gpio_keys = {
167         .name = "gpio-keys",
168         .dev  = {
169                 .platform_data = &gpio_keys_data,
170         },
171         .id   = -1,
172 };
173
174
175 /*
176  * EGPIO (Xilinx CPLD)
177  *
178  * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
179  */
180
181 static struct resource egpio_resources[] = {
182         [0] = {
183                 .start = PXA_CS3_PHYS,
184                 .end   = PXA_CS3_PHYS + 0x20 - 1,
185                 .flags = IORESOURCE_MEM,
186         },
187         [1] = {
188                 .start = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
189                 .end   = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
190                 .flags = IORESOURCE_IRQ,
191         },
192 };
193
194 static struct htc_egpio_chip egpio_chips[] = {
195         [0] = {
196                 .reg_start = 0,
197                 .gpio_base = MAGICIAN_EGPIO(0, 0),
198                 .num_gpios = 24,
199                 .direction = HTC_EGPIO_OUTPUT,
200                 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
201         },
202         [1] = {
203                 .reg_start = 4,
204                 .gpio_base = MAGICIAN_EGPIO(4, 0),
205                 .num_gpios = 24,
206                 .direction = HTC_EGPIO_INPUT,
207         },
208 };
209
210 static struct htc_egpio_platform_data egpio_info = {
211         .reg_width    = 8,
212         .bus_width    = 32,
213         .irq_base     = IRQ_BOARD_START,
214         .num_irqs     = 4,
215         .ack_register = 3,
216         .chip         = egpio_chips,
217         .num_chips    = ARRAY_SIZE(egpio_chips),
218 };
219
220 static struct platform_device egpio = {
221         .name          = "htc-egpio",
222         .id            = -1,
223         .resource      = egpio_resources,
224         .num_resources = ARRAY_SIZE(egpio_resources),
225         .dev = {
226                 .platform_data = &egpio_info,
227         },
228 };
229
230 /*
231  * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
232  */
233
234 static struct pxafb_mode_info toppoly_modes[] = {
235         {
236                 .pixclock     = 96153,
237                 .bpp          = 16,
238                 .xres         = 240,
239                 .yres         = 320,
240                 .hsync_len    = 11,
241                 .vsync_len    = 3,
242                 .left_margin  = 19,
243                 .upper_margin = 2,
244                 .right_margin = 10,
245                 .lower_margin = 2,
246                 .sync         = 0,
247         },
248 };
249
250 static struct pxafb_mode_info samsung_modes[] = {
251         {
252                 .pixclock     = 96153,
253                 .bpp          = 16,
254                 .xres         = 240,
255                 .yres         = 320,
256                 .hsync_len    = 8,
257                 .vsync_len    = 4,
258                 .left_margin  = 9,
259                 .upper_margin = 4,
260                 .right_margin = 9,
261                 .lower_margin = 4,
262                 .sync         = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
263         },
264 };
265
266 static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
267 {
268         pr_debug("Toppoly LCD power\n");
269
270         if (on) {
271                 pr_debug("on\n");
272                 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
273                 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
274                 udelay(2000);
275                 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
276                 udelay(2000);
277                 /* FIXME: enable LCDC here */
278                 udelay(2000);
279                 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
280                 udelay(2000);
281                 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
282         } else {
283                 pr_debug("off\n");
284                 msleep(15);
285                 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
286                 udelay(500);
287                 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
288                 udelay(1000);
289                 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
290                 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
291         }
292 }
293
294 static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
295 {
296         pr_debug("Samsung LCD power\n");
297
298         if (on) {
299                 pr_debug("on\n");
300                 if (system_rev < 3)
301                         gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
302                 else
303                         gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
304                 mdelay(10);
305                 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
306                 mdelay(10);
307                 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
308                 mdelay(30);
309                 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
310                 mdelay(10);
311         } else {
312                 pr_debug("off\n");
313                 mdelay(10);
314                 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
315                 mdelay(30);
316                 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
317                 mdelay(10);
318                 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
319                 mdelay(10);
320                 if (system_rev < 3)
321                         gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
322                 else
323                         gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
324         }
325 }
326
327 static struct pxafb_mach_info toppoly_info = {
328         .modes           = toppoly_modes,
329         .num_modes       = 1,
330         .fixed_modes     = 1,
331         .lcd_conn       = LCD_COLOR_TFT_16BPP,
332         .pxafb_lcd_power = toppoly_lcd_power,
333 };
334
335 static struct pxafb_mach_info samsung_info = {
336         .modes           = samsung_modes,
337         .num_modes       = 1,
338         .fixed_modes     = 1,
339         .lcd_conn        = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |\
340                            LCD_ALTERNATE_MAPPING,
341         .pxafb_lcd_power = samsung_lcd_power,
342 };
343
344 /*
345  * Backlight
346  */
347
348 static struct gpio magician_bl_gpios[] = {
349         { EGPIO_MAGICIAN_BL_POWER,  GPIOF_DIR_OUT, "Backlight power" },
350         { EGPIO_MAGICIAN_BL_POWER2, GPIOF_DIR_OUT, "Backlight power 2" },
351 };
352
353 static int magician_backlight_init(struct device *dev)
354 {
355         return gpio_request_array(ARRAY_AND_SIZE(magician_bl_gpios));
356 }
357
358 static int magician_backlight_notify(struct device *dev, int brightness)
359 {
360         gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
361         if (brightness >= 200) {
362                 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
363                 return brightness - 72;
364         } else {
365                 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
366                 return brightness;
367         }
368 }
369
370 static void magician_backlight_exit(struct device *dev)
371 {
372         gpio_free_array(ARRAY_AND_SIZE(magician_bl_gpios));
373 }
374
375 static struct platform_pwm_backlight_data backlight_data = {
376         .pwm_id         = 0,
377         .max_brightness = 272,
378         .dft_brightness = 100,
379         .pwm_period_ns  = 30923,
380         .init           = magician_backlight_init,
381         .notify         = magician_backlight_notify,
382         .exit           = magician_backlight_exit,
383 };
384
385 static struct platform_device backlight = {
386         .name = "pwm-backlight",
387         .id   = -1,
388         .dev  = {
389                 .parent        = &pxa27x_device_pwm0.dev,
390                 .platform_data = &backlight_data,
391         },
392 };
393
394 /*
395  * LEDs
396  */
397
398 static struct gpio_led gpio_leds[] = {
399         {
400                 .name = "magician::vibra",
401                 .default_trigger = "none",
402                 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
403         },
404         {
405                 .name = "magician::phone_bl",
406                 .default_trigger = "backlight",
407                 .gpio = GPIO103_MAGICIAN_LED_KP,
408         },
409 };
410
411 static struct gpio_led_platform_data gpio_led_info = {
412         .leds = gpio_leds,
413         .num_leds = ARRAY_SIZE(gpio_leds),
414 };
415
416 static struct platform_device leds_gpio = {
417         .name = "leds-gpio",
418         .id   = -1,
419         .dev  = {
420                 .platform_data = &gpio_led_info,
421         },
422 };
423
424 static struct pasic3_led pasic3_leds[] = {
425         {
426                 .led = {
427                         .name            = "magician:red",
428                         .default_trigger = "ds2760-battery.0-charging",
429                 },
430                 .hw_num = 0,
431                 .bit2   = PASIC3_BIT2_LED0,
432                 .mask   = PASIC3_MASK_LED0,
433         },
434         {
435                 .led = {
436                         .name            = "magician:green",
437                         .default_trigger = "ds2760-battery.0-charging-or-full",
438                 },
439                 .hw_num = 1,
440                 .bit2   = PASIC3_BIT2_LED1,
441                 .mask   = PASIC3_MASK_LED1,
442         },
443         {
444                 .led = {
445                         .name            = "magician:blue",
446                         .default_trigger = "bluetooth",
447                 },
448                 .hw_num = 2,
449                 .bit2   = PASIC3_BIT2_LED2,
450                 .mask   = PASIC3_MASK_LED2,
451         },
452 };
453
454 static struct pasic3_leds_machinfo pasic3_leds_info = {
455         .num_leds   = ARRAY_SIZE(pasic3_leds),
456         .power_gpio = EGPIO_MAGICIAN_LED_POWER,
457         .leds       = pasic3_leds,
458 };
459
460 /*
461  * PASIC3 with DS1WM
462  */
463
464 static struct resource pasic3_resources[] = {
465         [0] = {
466                 .start  = PXA_CS2_PHYS,
467                 .end    = PXA_CS2_PHYS + 0x1b,
468                 .flags  = IORESOURCE_MEM,
469         },
470         /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
471         [1] = {
472                 .start  = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
473                 .end    = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
474                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
475         }
476 };
477
478 static struct pasic3_platform_data pasic3_platform_data = {
479         .led_pdata  = &pasic3_leds_info,
480         .clock_rate = 4000000,
481 };
482
483 static struct platform_device pasic3 = {
484         .name           = "pasic3",
485         .id             = -1,
486         .num_resources  = ARRAY_SIZE(pasic3_resources),
487         .resource       = pasic3_resources,
488         .dev = {
489                 .platform_data = &pasic3_platform_data,
490         },
491 };
492
493 /*
494  * USB "Transceiver"
495  */
496
497 static struct resource gpio_vbus_resource = {
498         .flags = IORESOURCE_IRQ,
499         .start = IRQ_MAGICIAN_VBUS,
500         .end   = IRQ_MAGICIAN_VBUS,
501 };
502
503 static struct gpio_vbus_mach_info gpio_vbus_info = {
504         .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
505         .gpio_vbus   = EGPIO_MAGICIAN_CABLE_STATE_USB,
506 };
507
508 static struct platform_device gpio_vbus = {
509         .name          = "gpio-vbus",
510         .id            = -1,
511         .num_resources = 1,
512         .resource      = &gpio_vbus_resource,
513         .dev = {
514                 .platform_data = &gpio_vbus_info,
515         },
516 };
517
518 /*
519  * External power
520  */
521
522 static int power_supply_init(struct device *dev)
523 {
524         return gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
525 }
526
527 static int magician_is_ac_online(void)
528 {
529         return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
530 }
531
532 static void power_supply_exit(struct device *dev)
533 {
534         gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
535 }
536
537 static char *magician_supplicants[] = {
538         "ds2760-battery.0", "backup-battery"
539 };
540
541 static struct pda_power_pdata power_supply_info = {
542         .init            = power_supply_init,
543         .is_ac_online    = magician_is_ac_online,
544         .exit            = power_supply_exit,
545         .supplied_to     = magician_supplicants,
546         .num_supplicants = ARRAY_SIZE(magician_supplicants),
547 };
548
549 static struct resource power_supply_resources[] = {
550         [0] = {
551                 .name  = "ac",
552                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
553                          IORESOURCE_IRQ_LOWEDGE,
554                 .start = IRQ_MAGICIAN_VBUS,
555                 .end   = IRQ_MAGICIAN_VBUS,
556         },
557         [1] = {
558                 .name  = "usb",
559                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
560                          IORESOURCE_IRQ_LOWEDGE,
561                 .start = IRQ_MAGICIAN_VBUS,
562                 .end   = IRQ_MAGICIAN_VBUS,
563         },
564 };
565
566 static struct platform_device power_supply = {
567         .name = "pda-power",
568         .id   = -1,
569         .dev  = {
570                 .platform_data = &power_supply_info,
571         },
572         .resource      = power_supply_resources,
573         .num_resources = ARRAY_SIZE(power_supply_resources),
574 };
575
576 /*
577  * Battery charger
578  */
579
580 static struct regulator_consumer_supply bq24022_consumers[] = {
581         {
582                 .dev = &gpio_vbus.dev,
583                 .supply = "vbus_draw",
584         },
585         {
586                 .dev = &power_supply.dev,
587                 .supply = "ac_draw",
588         },
589 };
590
591 static struct regulator_init_data bq24022_init_data = {
592         .constraints = {
593                 .max_uA         = 500000,
594                 .valid_ops_mask = REGULATOR_CHANGE_CURRENT | REGULATOR_CHANGE_STATUS,
595         },
596         .num_consumer_supplies  = ARRAY_SIZE(bq24022_consumers),
597         .consumer_supplies      = bq24022_consumers,
598 };
599
600 static struct gpio bq24022_gpios[] = {
601         { EGPIO_MAGICIAN_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" },
602 };
603
604 static struct gpio_regulator_state bq24022_states[] = {
605         { .value = 100000, .gpios = (0 << 0) },
606         { .value = 500000, .gpios = (1 << 0) },
607 };
608
609 static struct gpio_regulator_config bq24022_info = {
610         .supply_name = "bq24022",
611
612         .enable_gpio = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
613         .enable_high = 0,
614         .enabled_at_boot = 0,
615
616         .gpios = bq24022_gpios,
617         .nr_gpios = ARRAY_SIZE(bq24022_gpios),
618
619         .states = bq24022_states,
620         .nr_states = ARRAY_SIZE(bq24022_states),
621
622         .type = REGULATOR_CURRENT,
623         .init_data = &bq24022_init_data,
624 };
625
626 static struct platform_device bq24022 = {
627         .name = "gpio-regulator",
628         .id   = -1,
629         .dev  = {
630                 .platform_data = &bq24022_info,
631         },
632 };
633
634 /*
635  * MMC/SD
636  */
637
638 static int magician_mci_init(struct device *dev,
639                                 irq_handler_t detect_irq, void *data)
640 {
641         return request_irq(IRQ_MAGICIAN_SD, detect_irq,
642                                 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
643                                 "mmc card detect", data);
644 }
645
646 static void magician_mci_exit(struct device *dev, void *data)
647 {
648         free_irq(IRQ_MAGICIAN_SD, data);
649 }
650
651 static struct pxamci_platform_data magician_mci_info = {
652         .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
653         .init                   = magician_mci_init,
654         .exit                   = magician_mci_exit,
655         .gpio_card_detect       = -1,
656         .gpio_card_ro           = EGPIO_MAGICIAN_nSD_READONLY,
657         .gpio_card_ro_invert    = 1,
658         .gpio_power             = EGPIO_MAGICIAN_SD_POWER,
659 };
660
661
662 /*
663  * USB OHCI
664  */
665
666 static struct pxaohci_platform_data magician_ohci_info = {
667         .port_mode      = PMM_PERPORT_MODE,
668         .flags          = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW,
669         .power_budget   = 0,
670 };
671
672
673 /*
674  * StrataFlash
675  */
676
677 static void magician_set_vpp(struct platform_device *pdev, int vpp)
678 {
679         gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
680 }
681
682 static struct resource strataflash_resource = {
683         .start = PXA_CS0_PHYS,
684         .end   = PXA_CS0_PHYS + SZ_64M - 1,
685         .flags = IORESOURCE_MEM,
686 };
687
688 static struct physmap_flash_data strataflash_data = {
689         .width = 4,
690         .set_vpp = magician_set_vpp,
691 };
692
693 static struct platform_device strataflash = {
694         .name          = "physmap-flash",
695         .id            = -1,
696         .resource      = &strataflash_resource,
697         .num_resources = 1,
698         .dev = {
699                 .platform_data = &strataflash_data,
700         },
701 };
702
703 /*
704  * I2C
705  */
706
707 static struct i2c_pxa_platform_data i2c_info = {
708         .fast_mode = 1,
709 };
710
711 /*
712  * Platform devices
713  */
714
715 static struct platform_device *devices[] __initdata = {
716         &gpio_keys,
717         &egpio,
718         &backlight,
719         &pasic3,
720         &bq24022,
721         &gpio_vbus,
722         &power_supply,
723         &strataflash,
724         &leds_gpio,
725 };
726
727 static struct gpio magician_global_gpios[] = {
728         { GPIO13_MAGICIAN_CPLD_IRQ,   GPIOF_IN, "CPLD_IRQ" },
729         { GPIO107_MAGICIAN_DS1WM_IRQ, GPIOF_IN, "DS1WM_IRQ" },
730         { GPIO104_MAGICIAN_LCD_POWER_1, GPIOF_OUT_INIT_LOW, "LCD power 1" },
731         { GPIO105_MAGICIAN_LCD_POWER_2, GPIOF_OUT_INIT_LOW, "LCD power 2" },
732         { GPIO106_MAGICIAN_LCD_POWER_3, GPIOF_OUT_INIT_LOW, "LCD power 3" },
733         { GPIO83_MAGICIAN_nIR_EN, GPIOF_OUT_INIT_HIGH, "nIR_EN" },
734 };
735
736 static void __init magician_init(void)
737 {
738         void __iomem *cpld;
739         int lcd_select;
740         int err;
741
742         pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
743         err = gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios));
744         if (err)
745                 pr_err("magician: Failed to request GPIOs: %d\n", err);
746
747         pxa_set_ffuart_info(NULL);
748         pxa_set_btuart_info(NULL);
749         pxa_set_stuart_info(NULL);
750
751         platform_add_devices(ARRAY_AND_SIZE(devices));
752
753         pxa_set_ficp_info(&magician_ficp_info);
754         pxa27x_set_i2c_power_info(NULL);
755         pxa_set_i2c_info(&i2c_info);
756         pxa_set_mci_info(&magician_mci_info);
757         pxa_set_ohci_info(&magician_ohci_info);
758
759         /* Check LCD type we have */
760         cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
761         if (cpld) {
762                 u8 board_id = __raw_readb(cpld+0x14);
763                 iounmap(cpld);
764                 system_rev = board_id & 0x7;
765                 lcd_select = board_id & 0x8;
766                 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
767                 if (lcd_select && (system_rev < 3))
768                         gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER,
769                                          GPIOF_OUT_INIT_LOW, "SAMSUNG_POWER");
770                 pxa_set_fb_info(NULL, lcd_select ? &samsung_info : &toppoly_info);
771         } else
772                 pr_err("LCD detection: CPLD mapping failed\n");
773 }
774
775
776 MACHINE_START(MAGICIAN, "HTC Magician")
777         .atag_offset = 0x100,
778         .map_io = pxa27x_map_io,
779         .nr_irqs = MAGICIAN_NR_IRQS,
780         .init_irq = pxa27x_init_irq,
781         .handle_irq = pxa27x_handle_irq,
782         .init_machine = magician_init,
783         .timer = &pxa_timer,
784         .restart        = pxa_restart,
785 MACHINE_END