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.
6 * Copyright (c) 2006-2007 Philipp Zabel
8 * Based on hx4700.c, spitz.c and others.
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.
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>
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>
39 #include <mach/irda.h>
40 #include <mach/ohci.h>
45 static unsigned long magician_pin_config
[] __initdata
= {
47 /* SDRAM and Static Memory I/O Signals */
51 GPIO78_nCS_2
, /* PASIC3 */
52 GPIO79_nCS_3
, /* EGPIO CPLD */
64 GPIO28_I2S_BITCLK_OUT
,
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 */
136 static void magician_irda_transceiver_mode(struct device
*dev
, int mode
)
138 gpio_set_value(GPIO83_MAGICIAN_nIR_EN
, mode
& IR_OFF
);
139 pxa2xx_transceiver_mode(dev
, mode
);
142 static struct pxaficp_platform_data magician_ficp_info
= {
143 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
144 .transceiver_mode
= magician_irda_transceiver_mode
,
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"},
169 static struct gpio_keys_platform_data gpio_keys_data
= {
170 .buttons
= magician_button_table
,
171 .nbuttons
= ARRAY_SIZE(magician_button_table
),
174 static struct platform_device gpio_keys
= {
177 .platform_data
= &gpio_keys_data
,
184 * EGPIO (Xilinx CPLD)
186 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
189 static struct resource egpio_resources
[] = {
191 .start
= PXA_CS3_PHYS
,
192 .end
= PXA_CS3_PHYS
+ 0x20,
193 .flags
= IORESOURCE_MEM
,
196 .start
= gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ
),
197 .end
= gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ
),
198 .flags
= IORESOURCE_IRQ
,
202 static struct htc_egpio_chip egpio_chips
[] = {
205 .gpio_base
= MAGICIAN_EGPIO(0, 0),
207 .direction
= HTC_EGPIO_OUTPUT
,
208 .initial_values
= 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
212 .gpio_base
= MAGICIAN_EGPIO(4, 0),
214 .direction
= HTC_EGPIO_INPUT
,
218 static struct htc_egpio_platform_data egpio_info
= {
221 .irq_base
= IRQ_BOARD_START
,
225 .num_chips
= ARRAY_SIZE(egpio_chips
),
228 static struct platform_device egpio
= {
231 .resource
= egpio_resources
,
232 .num_resources
= ARRAY_SIZE(egpio_resources
),
234 .platform_data
= &egpio_info
,
239 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
242 static struct pxafb_mode_info toppoly_modes
[] = {
258 static struct pxafb_mode_info samsung_modes
[] = {
270 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
274 static void toppoly_lcd_power(int on
, struct fb_var_screeninfo
*si
)
276 pr_debug("Toppoly LCD power\n");
280 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER
, 1);
281 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 1);
283 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 1);
285 /* FIXME: enable LCDC here */
287 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 1);
289 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 1);
293 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 0);
295 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 0);
297 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 0);
298 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 0);
302 static void samsung_lcd_power(int on
, struct fb_var_screeninfo
*si
)
304 pr_debug("Samsung LCD power\n");
309 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER
, 1);
311 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 1);
313 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 1);
315 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 1);
317 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 1);
322 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 0);
324 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 0);
326 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 0);
329 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER
, 0);
331 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 0);
335 static struct pxafb_mach_info toppoly_info
= {
336 .modes
= toppoly_modes
,
339 .lccr0
= LCCR0_Color
| LCCR0_Sngl
| LCCR0_Act
,
340 .lccr3
= LCCR3_PixRsEdg
,
341 .pxafb_lcd_power
= toppoly_lcd_power
,
344 static struct pxafb_mach_info samsung_info
= {
345 .modes
= samsung_modes
,
348 .lccr0
= LCCR0_LDDALT
| LCCR0_Color
| LCCR0_Sngl
| LCCR0_Act
,
349 .lccr3
= LCCR3_PixFlEdg
,
350 .pxafb_lcd_power
= samsung_lcd_power
,
357 static int magician_backlight_init(struct device
*dev
)
361 ret
= gpio_request(EGPIO_MAGICIAN_BL_POWER
, "BL_POWER");
364 ret
= gpio_request(EGPIO_MAGICIAN_BL_POWER2
, "BL_POWER2");
370 gpio_free(EGPIO_MAGICIAN_BL_POWER
);
375 static int magician_backlight_notify(int brightness
)
377 gpio_set_value(EGPIO_MAGICIAN_BL_POWER
, brightness
);
378 if (brightness
>= 200) {
379 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2
, 1);
380 return brightness
- 72;
382 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2
, 0);
387 static void magician_backlight_exit(struct device
*dev
)
389 gpio_free(EGPIO_MAGICIAN_BL_POWER
);
390 gpio_free(EGPIO_MAGICIAN_BL_POWER2
);
393 static struct platform_pwm_backlight_data backlight_data
= {
395 .max_brightness
= 272,
396 .dft_brightness
= 100,
397 .pwm_period_ns
= 30923,
398 .init
= magician_backlight_init
,
399 .notify
= magician_backlight_notify
,
400 .exit
= magician_backlight_exit
,
403 static struct platform_device backlight
= {
404 .name
= "pwm-backlight",
407 .parent
= &pxa27x_device_pwm0
.dev
,
408 .platform_data
= &backlight_data
,
416 static struct gpio_led gpio_leds
[] = {
418 .name
= "magician::vibra",
419 .default_trigger
= "none",
420 .gpio
= GPIO22_MAGICIAN_VIBRA_EN
,
423 .name
= "magician::phone_bl",
424 .default_trigger
= "none",
425 .gpio
= GPIO103_MAGICIAN_LED_KP
,
429 static struct gpio_led_platform_data gpio_led_info
= {
431 .num_leds
= ARRAY_SIZE(gpio_leds
),
434 static struct platform_device leds_gpio
= {
438 .platform_data
= &gpio_led_info
,
442 static struct pasic3_led pasic3_leds
[] = {
445 .name
= "magician:red",
446 .default_trigger
= "ds2760-battery.0-charging",
449 .bit2
= PASIC3_BIT2_LED0
,
450 .mask
= PASIC3_MASK_LED0
,
454 .name
= "magician:green",
455 .default_trigger
= "ds2760-battery.0-charging-or-full",
458 .bit2
= PASIC3_BIT2_LED1
,
459 .mask
= PASIC3_MASK_LED1
,
463 .name
= "magician:blue",
464 .default_trigger
= "bluetooth",
467 .bit2
= PASIC3_BIT2_LED2
,
468 .mask
= PASIC3_MASK_LED2
,
472 static struct platform_device pasic3
;
474 static struct pasic3_leds_machinfo pasic3_leds_info
= {
475 .num_leds
= ARRAY_SIZE(pasic3_leds
),
476 .power_gpio
= EGPIO_MAGICIAN_LED_POWER
,
484 static struct resource pasic3_resources
[] = {
486 .start
= PXA_CS2_PHYS
,
487 .end
= PXA_CS2_PHYS
+ 0x1b,
488 .flags
= IORESOURCE_MEM
,
490 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
492 .start
= gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ
),
493 .end
= gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ
),
494 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
,
498 static struct pasic3_platform_data pasic3_platform_data
= {
500 .led_pdata
= &pasic3_leds_info
,
501 .clock_rate
= 4000000,
504 static struct platform_device pasic3
= {
507 .num_resources
= ARRAY_SIZE(pasic3_resources
),
508 .resource
= pasic3_resources
,
510 .platform_data
= &pasic3_platform_data
,
518 static int power_supply_init(struct device
*dev
)
522 ret
= gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC
, "CABLE_STATE_AC");
525 ret
= gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB
, "CABLE_STATE_USB");
528 ret
= gpio_request(EGPIO_MAGICIAN_CHARGE_EN
, "CHARGE_EN");
531 ret
= gpio_request(GPIO30_MAGICIAN_nCHARGE_EN
, "nCHARGE_EN");
533 ret
= gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN
, 0);
540 gpio_free(EGPIO_MAGICIAN_CHARGE_EN
);
542 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB
);
544 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC
);
549 static int magician_is_ac_online(void)
551 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC
);
554 static int magician_is_usb_online(void)
556 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB
);
559 static void magician_set_charge(int flags
)
561 gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN
, !flags
);
562 gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN
, flags
);
565 static void power_supply_exit(struct device
*dev
)
567 gpio_free(GPIO30_MAGICIAN_nCHARGE_EN
);
568 gpio_free(EGPIO_MAGICIAN_CHARGE_EN
);
569 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB
);
570 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC
);
573 static char *magician_supplicants
[] = {
574 "ds2760-battery.0", "backup-battery"
577 static struct pda_power_pdata power_supply_info
= {
578 .init
= power_supply_init
,
579 .is_ac_online
= magician_is_ac_online
,
580 .is_usb_online
= magician_is_usb_online
,
581 .set_charge
= magician_set_charge
,
582 .exit
= power_supply_exit
,
583 .supplied_to
= magician_supplicants
,
584 .num_supplicants
= ARRAY_SIZE(magician_supplicants
),
587 static struct resource power_supply_resources
[] = {
590 .flags
= IORESOURCE_IRQ
,
591 .start
= IRQ_MAGICIAN_AC
,
592 .end
= IRQ_MAGICIAN_AC
,
596 .flags
= IORESOURCE_IRQ
,
597 .start
= IRQ_MAGICIAN_AC
,
598 .end
= IRQ_MAGICIAN_AC
,
602 static struct platform_device power_supply
= {
606 .platform_data
= &power_supply_info
,
608 .resource
= power_supply_resources
,
609 .num_resources
= ARRAY_SIZE(power_supply_resources
),
617 static int magician_mci_init(struct device
*dev
,
618 irq_handler_t detect_irq
, void *data
)
622 err
= request_irq(IRQ_MAGICIAN_SD
, detect_irq
,
623 IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
,
624 "MMC card detect", data
);
626 goto err_request_irq
;
627 err
= gpio_request(EGPIO_MAGICIAN_SD_POWER
, "SD_POWER");
629 goto err_request_power
;
630 err
= gpio_request(EGPIO_MAGICIAN_nSD_READONLY
, "nSD_READONLY");
632 goto err_request_readonly
;
636 err_request_readonly
:
637 gpio_free(EGPIO_MAGICIAN_SD_POWER
);
639 free_irq(IRQ_MAGICIAN_SD
, data
);
644 static void magician_mci_setpower(struct device
*dev
, unsigned int vdd
)
646 struct pxamci_platform_data
*pdata
= dev
->platform_data
;
648 gpio_set_value(EGPIO_MAGICIAN_SD_POWER
, (1 << vdd
) & pdata
->ocr_mask
);
651 static int magician_mci_get_ro(struct device
*dev
)
653 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY
));
656 static void magician_mci_exit(struct device
*dev
, void *data
)
658 gpio_free(EGPIO_MAGICIAN_nSD_READONLY
);
659 gpio_free(EGPIO_MAGICIAN_SD_POWER
);
660 free_irq(IRQ_MAGICIAN_SD
, data
);
663 static struct pxamci_platform_data magician_mci_info
= {
664 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
665 .init
= magician_mci_init
,
666 .get_ro
= magician_mci_get_ro
,
667 .setpower
= magician_mci_setpower
,
668 .exit
= magician_mci_exit
,
676 static struct pxaohci_platform_data magician_ohci_info
= {
677 .port_mode
= PMM_PERPORT_MODE
,
678 .flags
= ENABLE_PORT1
| ENABLE_PORT3
| POWER_CONTROL_LOW
,
687 static void magician_set_vpp(struct map_info
*map
, int vpp
)
689 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP
, vpp
);
692 #define PXA_CS_SIZE 0x04000000
694 static struct resource strataflash_resource
= {
695 .start
= PXA_CS0_PHYS
,
696 .end
= PXA_CS0_PHYS
+ PXA_CS_SIZE
- 1,
697 .flags
= IORESOURCE_MEM
,
700 static struct physmap_flash_data strataflash_data
= {
702 .set_vpp
= magician_set_vpp
,
705 static struct platform_device strataflash
= {
706 .name
= "physmap-flash",
708 .resource
= &strataflash_resource
,
711 .platform_data
= &strataflash_data
,
719 static struct platform_device
*devices
[] __initdata
= {
729 static void __init
magician_init(void)
735 gpio_request(GPIO13_MAGICIAN_CPLD_IRQ
, "CPLD_IRQ");
736 gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ
, "DS1WM_IRQ");
738 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config
));
740 platform_add_devices(devices
, ARRAY_SIZE(devices
));
742 err
= gpio_request(GPIO83_MAGICIAN_nIR_EN
, "nIR_EN");
744 gpio_direction_output(GPIO83_MAGICIAN_nIR_EN
, 1);
745 pxa_set_ficp_info(&magician_ficp_info
);
747 pxa_set_i2c_info(NULL
);
748 pxa_set_mci_info(&magician_mci_info
);
749 pxa_set_ohci_info(&magician_ohci_info
);
751 /* Check LCD type we have */
752 cpld
= ioremap_nocache(PXA_CS3_PHYS
, 0x1000);
754 u8 board_id
= __raw_readb(cpld
+0x14);
756 system_rev
= board_id
& 0x7;
757 lcd_select
= board_id
& 0x8;
758 pr_info("LCD type: %s\n", lcd_select
? "Samsung" : "Toppoly");
759 if (lcd_select
&& (system_rev
< 3)) {
760 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER
, "SAMSUNG_POWER");
761 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER
, 0);
763 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1
, "LCD_POWER_1");
764 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2
, "LCD_POWER_2");
765 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3
, "LCD_POWER_3");
766 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1
, 0);
767 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2
, 0);
768 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3
, 0);
769 set_pxa_fb_info(lcd_select
? &samsung_info
: &toppoly_info
);
771 pr_err("LCD detection: CPLD mapping failed\n");
775 MACHINE_START(MAGICIAN
, "HTC Magician")
776 .phys_io
= 0x40000000,
777 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
778 .boot_params
= 0xa0000100,
779 .map_io
= pxa_map_io
,
780 .init_irq
= pxa27x_init_irq
,
781 .init_machine
= magician_init
,