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