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>
28 #include <linux/regulator/bq24022.h>
29 #include <linux/regulator/machine.h>
30 #include <linux/usb/gpio_vbus.h>
32 #include <mach/hardware.h>
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
36 #include <mach/pxa27x.h>
37 #include <mach/magician.h>
38 #include <mach/pxafb.h>
41 #include <mach/irda.h>
42 #include <mach/ohci.h>
47 static unsigned long magician_pin_config
[] __initdata
= {
49 /* SDRAM and Static Memory I/O Signals */
53 GPIO78_nCS_2
, /* PASIC3 */
54 GPIO79_nCS_3
, /* EGPIO CPLD */
66 GPIO28_I2S_BITCLK_OUT
,
107 /* Magician specific input GPIOs */
108 GPIO9_GPIO
, /* unknown */
109 GPIO10_GPIO
, /* GSM_IRQ */
110 GPIO13_GPIO
, /* CPLD_IRQ */
111 GPIO107_GPIO
, /* DS1WM_IRQ */
112 GPIO108_GPIO
, /* GSM_READY */
113 GPIO115_GPIO
, /* nPEN_IRQ */
124 static struct pxaficp_platform_data magician_ficp_info
= {
125 .gpio_pwdown
= GPIO83_MAGICIAN_nIR_EN
,
126 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
133 #define INIT_KEY(_code, _gpio, _desc) \
135 .code = KEY_##_code, \
142 static struct gpio_keys_button magician_button_table
[] = {
143 INIT_KEY(POWER
, GPIO0_MAGICIAN_KEY_POWER
, "Power button"),
144 INIT_KEY(ESC
, GPIO37_MAGICIAN_KEY_HANGUP
, "Hangup button"),
145 INIT_KEY(F10
, GPIO38_MAGICIAN_KEY_CONTACTS
, "Contacts button"),
146 INIT_KEY(CALENDAR
, GPIO90_MAGICIAN_KEY_CALENDAR
, "Calendar button"),
147 INIT_KEY(CAMERA
, GPIO91_MAGICIAN_KEY_CAMERA
, "Camera button"),
148 INIT_KEY(UP
, GPIO93_MAGICIAN_KEY_UP
, "Up button"),
149 INIT_KEY(DOWN
, GPIO94_MAGICIAN_KEY_DOWN
, "Down button"),
150 INIT_KEY(LEFT
, GPIO95_MAGICIAN_KEY_LEFT
, "Left button"),
151 INIT_KEY(RIGHT
, GPIO96_MAGICIAN_KEY_RIGHT
, "Right button"),
152 INIT_KEY(KPENTER
, GPIO97_MAGICIAN_KEY_ENTER
, "Action button"),
153 INIT_KEY(RECORD
, GPIO98_MAGICIAN_KEY_RECORD
, "Record button"),
154 INIT_KEY(VOLUMEUP
, GPIO100_MAGICIAN_KEY_VOL_UP
, "Volume up"),
155 INIT_KEY(VOLUMEDOWN
, GPIO101_MAGICIAN_KEY_VOL_DOWN
, "Volume down"),
156 INIT_KEY(PHONE
, GPIO102_MAGICIAN_KEY_PHONE
, "Phone button"),
157 INIT_KEY(PLAY
, GPIO99_MAGICIAN_HEADPHONE_IN
, "Headset button"),
160 static struct gpio_keys_platform_data gpio_keys_data
= {
161 .buttons
= magician_button_table
,
162 .nbuttons
= ARRAY_SIZE(magician_button_table
),
165 static struct platform_device gpio_keys
= {
168 .platform_data
= &gpio_keys_data
,
175 * EGPIO (Xilinx CPLD)
177 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
180 static struct resource egpio_resources
[] = {
182 .start
= PXA_CS3_PHYS
,
183 .end
= PXA_CS3_PHYS
+ 0x20 - 1,
184 .flags
= IORESOURCE_MEM
,
187 .start
= gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ
),
188 .end
= gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ
),
189 .flags
= IORESOURCE_IRQ
,
193 static struct htc_egpio_chip egpio_chips
[] = {
196 .gpio_base
= MAGICIAN_EGPIO(0, 0),
198 .direction
= HTC_EGPIO_OUTPUT
,
199 .initial_values
= 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
203 .gpio_base
= MAGICIAN_EGPIO(4, 0),
205 .direction
= HTC_EGPIO_INPUT
,
209 static struct htc_egpio_platform_data egpio_info
= {
212 .irq_base
= IRQ_BOARD_START
,
216 .num_chips
= ARRAY_SIZE(egpio_chips
),
219 static struct platform_device egpio
= {
222 .resource
= egpio_resources
,
223 .num_resources
= ARRAY_SIZE(egpio_resources
),
225 .platform_data
= &egpio_info
,
230 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
233 static struct pxafb_mode_info toppoly_modes
[] = {
249 static struct pxafb_mode_info samsung_modes
[] = {
261 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
265 static void toppoly_lcd_power(int on
, struct fb_var_screeninfo
*si
)
267 pr_debug("Toppoly LCD power\n");
271 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER
, 1);
272 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 1);
274 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 1);
276 /* FIXME: enable LCDC here */
278 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 1);
280 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 1);
284 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 0);
286 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 0);
288 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 0);
289 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 0);
293 static void samsung_lcd_power(int on
, struct fb_var_screeninfo
*si
)
295 pr_debug("Samsung LCD power\n");
300 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER
, 1);
302 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 1);
304 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 1);
306 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 1);
308 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 1);
313 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 0);
315 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 0);
317 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 0);
320 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER
, 0);
322 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 0);
326 static struct pxafb_mach_info toppoly_info
= {
327 .modes
= toppoly_modes
,
330 .lcd_conn
= LCD_COLOR_TFT_16BPP
,
331 .pxafb_lcd_power
= toppoly_lcd_power
,
334 static struct pxafb_mach_info samsung_info
= {
335 .modes
= samsung_modes
,
338 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_PCLK_EDGE_FALL
|\
339 LCD_ALTERNATE_MAPPING
,
340 .pxafb_lcd_power
= samsung_lcd_power
,
347 static int magician_backlight_init(struct device
*dev
)
351 ret
= gpio_request(EGPIO_MAGICIAN_BL_POWER
, "BL_POWER");
354 ret
= gpio_request(EGPIO_MAGICIAN_BL_POWER2
, "BL_POWER2");
360 gpio_free(EGPIO_MAGICIAN_BL_POWER
);
365 static int magician_backlight_notify(struct device
*dev
, int brightness
)
367 gpio_set_value(EGPIO_MAGICIAN_BL_POWER
, brightness
);
368 if (brightness
>= 200) {
369 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2
, 1);
370 return brightness
- 72;
372 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2
, 0);
377 static void magician_backlight_exit(struct device
*dev
)
379 gpio_free(EGPIO_MAGICIAN_BL_POWER
);
380 gpio_free(EGPIO_MAGICIAN_BL_POWER2
);
383 static struct platform_pwm_backlight_data backlight_data
= {
385 .max_brightness
= 272,
386 .dft_brightness
= 100,
387 .pwm_period_ns
= 30923,
388 .init
= magician_backlight_init
,
389 .notify
= magician_backlight_notify
,
390 .exit
= magician_backlight_exit
,
393 static struct platform_device backlight
= {
394 .name
= "pwm-backlight",
397 .parent
= &pxa27x_device_pwm0
.dev
,
398 .platform_data
= &backlight_data
,
406 static struct gpio_led gpio_leds
[] = {
408 .name
= "magician::vibra",
409 .default_trigger
= "none",
410 .gpio
= GPIO22_MAGICIAN_VIBRA_EN
,
413 .name
= "magician::phone_bl",
414 .default_trigger
= "backlight",
415 .gpio
= GPIO103_MAGICIAN_LED_KP
,
419 static struct gpio_led_platform_data gpio_led_info
= {
421 .num_leds
= ARRAY_SIZE(gpio_leds
),
424 static struct platform_device leds_gpio
= {
428 .platform_data
= &gpio_led_info
,
432 static struct pasic3_led pasic3_leds
[] = {
435 .name
= "magician:red",
436 .default_trigger
= "ds2760-battery.0-charging",
439 .bit2
= PASIC3_BIT2_LED0
,
440 .mask
= PASIC3_MASK_LED0
,
444 .name
= "magician:green",
445 .default_trigger
= "ds2760-battery.0-charging-or-full",
448 .bit2
= PASIC3_BIT2_LED1
,
449 .mask
= PASIC3_MASK_LED1
,
453 .name
= "magician:blue",
454 .default_trigger
= "bluetooth",
457 .bit2
= PASIC3_BIT2_LED2
,
458 .mask
= PASIC3_MASK_LED2
,
462 static struct pasic3_leds_machinfo pasic3_leds_info
= {
463 .num_leds
= ARRAY_SIZE(pasic3_leds
),
464 .power_gpio
= EGPIO_MAGICIAN_LED_POWER
,
472 static struct resource pasic3_resources
[] = {
474 .start
= PXA_CS2_PHYS
,
475 .end
= PXA_CS2_PHYS
+ 0x1b,
476 .flags
= IORESOURCE_MEM
,
478 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
480 .start
= gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ
),
481 .end
= gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ
),
482 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
,
486 static struct pasic3_platform_data pasic3_platform_data
= {
487 .led_pdata
= &pasic3_leds_info
,
488 .clock_rate
= 4000000,
491 static struct platform_device pasic3
= {
494 .num_resources
= ARRAY_SIZE(pasic3_resources
),
495 .resource
= pasic3_resources
,
497 .platform_data
= &pasic3_platform_data
,
505 static struct resource gpio_vbus_resource
= {
506 .flags
= IORESOURCE_IRQ
,
507 .start
= IRQ_MAGICIAN_VBUS
,
508 .end
= IRQ_MAGICIAN_VBUS
,
511 static struct gpio_vbus_mach_info gpio_vbus_info
= {
512 .gpio_pullup
= GPIO27_MAGICIAN_USBC_PUEN
,
513 .gpio_vbus
= EGPIO_MAGICIAN_CABLE_STATE_USB
,
516 static struct platform_device gpio_vbus
= {
520 .resource
= &gpio_vbus_resource
,
522 .platform_data
= &gpio_vbus_info
,
530 static int power_supply_init(struct device
*dev
)
532 return gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC
, "CABLE_STATE_AC");
535 static int magician_is_ac_online(void)
537 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC
);
540 static void power_supply_exit(struct device
*dev
)
542 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC
);
545 static char *magician_supplicants
[] = {
546 "ds2760-battery.0", "backup-battery"
549 static struct pda_power_pdata power_supply_info
= {
550 .init
= power_supply_init
,
551 .is_ac_online
= magician_is_ac_online
,
552 .exit
= power_supply_exit
,
553 .supplied_to
= magician_supplicants
,
554 .num_supplicants
= ARRAY_SIZE(magician_supplicants
),
557 static struct resource power_supply_resources
[] = {
560 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
|
561 IORESOURCE_IRQ_LOWEDGE
,
562 .start
= IRQ_MAGICIAN_VBUS
,
563 .end
= IRQ_MAGICIAN_VBUS
,
567 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
|
568 IORESOURCE_IRQ_LOWEDGE
,
569 .start
= IRQ_MAGICIAN_VBUS
,
570 .end
= IRQ_MAGICIAN_VBUS
,
574 static struct platform_device power_supply
= {
578 .platform_data
= &power_supply_info
,
580 .resource
= power_supply_resources
,
581 .num_resources
= ARRAY_SIZE(power_supply_resources
),
588 static struct regulator_consumer_supply bq24022_consumers
[] = {
590 .dev
= &gpio_vbus
.dev
,
591 .supply
= "vbus_draw",
594 .dev
= &power_supply
.dev
,
599 static struct regulator_init_data bq24022_init_data
= {
602 .valid_ops_mask
= REGULATOR_CHANGE_CURRENT
,
604 .num_consumer_supplies
= ARRAY_SIZE(bq24022_consumers
),
605 .consumer_supplies
= bq24022_consumers
,
608 static struct bq24022_mach_info bq24022_info
= {
609 .gpio_nce
= GPIO30_MAGICIAN_BQ24022_nCHARGE_EN
,
610 .gpio_iset2
= EGPIO_MAGICIAN_BQ24022_ISET2
,
611 .init_data
= &bq24022_init_data
,
614 static struct platform_device bq24022
= {
618 .platform_data
= &bq24022_info
,
626 static int magician_mci_init(struct device
*dev
,
627 irq_handler_t detect_irq
, void *data
)
629 return request_irq(IRQ_MAGICIAN_SD
, detect_irq
,
630 IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
,
631 "mmc card detect", data
);
634 static void magician_mci_exit(struct device
*dev
, void *data
)
636 free_irq(IRQ_MAGICIAN_SD
, data
);
639 static struct pxamci_platform_data magician_mci_info
= {
640 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
641 .init
= magician_mci_init
,
642 .exit
= magician_mci_exit
,
643 .gpio_card_detect
= -1,
644 .gpio_card_ro
= EGPIO_MAGICIAN_nSD_READONLY
,
645 .gpio_card_ro_invert
= 1,
646 .gpio_power
= EGPIO_MAGICIAN_SD_POWER
,
654 static struct pxaohci_platform_data magician_ohci_info
= {
655 .port_mode
= PMM_PERPORT_MODE
,
656 .flags
= ENABLE_PORT1
| ENABLE_PORT3
| POWER_CONTROL_LOW
,
665 static void magician_set_vpp(struct map_info
*map
, int vpp
)
667 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP
, vpp
);
670 static struct resource strataflash_resource
= {
671 .start
= PXA_CS0_PHYS
,
672 .end
= PXA_CS0_PHYS
+ SZ_64M
- 1,
673 .flags
= IORESOURCE_MEM
,
676 static struct physmap_flash_data strataflash_data
= {
678 .set_vpp
= magician_set_vpp
,
681 static struct platform_device strataflash
= {
682 .name
= "physmap-flash",
684 .resource
= &strataflash_resource
,
687 .platform_data
= &strataflash_data
,
695 static struct i2c_pxa_platform_data i2c_info
= {
703 static struct platform_device
*devices
[] __initdata
= {
715 static void __init
magician_init(void)
721 gpio_request(GPIO13_MAGICIAN_CPLD_IRQ
, "CPLD_IRQ");
722 gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ
, "DS1WM_IRQ");
724 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config
));
726 pxa_set_ffuart_info(NULL
);
727 pxa_set_btuart_info(NULL
);
728 pxa_set_stuart_info(NULL
);
730 platform_add_devices(ARRAY_AND_SIZE(devices
));
732 err
= gpio_request(GPIO83_MAGICIAN_nIR_EN
, "nIR_EN");
734 gpio_direction_output(GPIO83_MAGICIAN_nIR_EN
, 1);
735 pxa_set_ficp_info(&magician_ficp_info
);
737 pxa27x_set_i2c_power_info(NULL
);
738 pxa_set_i2c_info(&i2c_info
);
739 pxa_set_mci_info(&magician_mci_info
);
740 pxa_set_ohci_info(&magician_ohci_info
);
742 /* Check LCD type we have */
743 cpld
= ioremap_nocache(PXA_CS3_PHYS
, 0x1000);
745 u8 board_id
= __raw_readb(cpld
+0x14);
747 system_rev
= board_id
& 0x7;
748 lcd_select
= board_id
& 0x8;
749 pr_info("LCD type: %s\n", lcd_select
? "Samsung" : "Toppoly");
750 if (lcd_select
&& (system_rev
< 3)) {
751 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER
, "SAMSUNG_POWER");
752 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER
, 0);
754 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1
, "LCD_POWER_1");
755 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2
, "LCD_POWER_2");
756 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3
, "LCD_POWER_3");
757 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1
, 0);
758 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2
, 0);
759 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3
, 0);
760 set_pxa_fb_info(lcd_select
? &samsung_info
: &toppoly_info
);
762 pr_err("LCD detection: CPLD mapping failed\n");
766 MACHINE_START(MAGICIAN
, "HTC Magician")
767 .boot_params
= 0xa0000100,
768 .map_io
= pxa27x_map_io
,
769 .nr_irqs
= MAGICIAN_NR_IRQS
,
770 .init_irq
= pxa27x_init_irq
,
771 .init_machine
= magician_init
,