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