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/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>
34 #include <mach/hardware.h>
35 #include <asm/mach-types.h>
36 #include <asm/mach/arch.h>
37 #include <asm/system_info.h>
39 #include <mach/pxa27x.h>
40 #include <mach/magician.h>
41 #include <linux/platform_data/video-pxafb.h>
42 #include <linux/platform_data/mmc-pxamci.h>
43 #include <linux/platform_data/irda-pxaficp.h>
44 #include <linux/platform_data/usb-ohci-pxa27x.h>
49 static unsigned long magician_pin_config
[] __initdata
= {
51 /* SDRAM and Static Memory I/O Signals */
55 GPIO78_nCS_2
, /* PASIC3 */
56 GPIO79_nCS_3
, /* EGPIO CPLD */
68 GPIO28_I2S_BITCLK_OUT
,
109 /* Magician specific input GPIOs */
110 GPIO9_GPIO
, /* unknown */
111 GPIO10_GPIO
, /* GSM_IRQ */
112 GPIO13_GPIO
, /* CPLD_IRQ */
113 GPIO107_GPIO
, /* DS1WM_IRQ */
114 GPIO108_GPIO
, /* GSM_READY */
115 GPIO115_GPIO
, /* nPEN_IRQ */
126 static struct pxaficp_platform_data magician_ficp_info
= {
127 .gpio_pwdown
= GPIO83_MAGICIAN_nIR_EN
,
128 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
135 #define INIT_KEY(_code, _gpio, _desc) \
137 .code = KEY_##_code, \
144 static struct gpio_keys_button magician_button_table
[] = {
145 INIT_KEY(POWER
, GPIO0_MAGICIAN_KEY_POWER
, "Power button"),
146 INIT_KEY(ESC
, GPIO37_MAGICIAN_KEY_HANGUP
, "Hangup button"),
147 INIT_KEY(F10
, GPIO38_MAGICIAN_KEY_CONTACTS
, "Contacts button"),
148 INIT_KEY(CALENDAR
, GPIO90_MAGICIAN_KEY_CALENDAR
, "Calendar button"),
149 INIT_KEY(CAMERA
, GPIO91_MAGICIAN_KEY_CAMERA
, "Camera button"),
150 INIT_KEY(UP
, GPIO93_MAGICIAN_KEY_UP
, "Up button"),
151 INIT_KEY(DOWN
, GPIO94_MAGICIAN_KEY_DOWN
, "Down button"),
152 INIT_KEY(LEFT
, GPIO95_MAGICIAN_KEY_LEFT
, "Left button"),
153 INIT_KEY(RIGHT
, GPIO96_MAGICIAN_KEY_RIGHT
, "Right button"),
154 INIT_KEY(KPENTER
, GPIO97_MAGICIAN_KEY_ENTER
, "Action button"),
155 INIT_KEY(RECORD
, GPIO98_MAGICIAN_KEY_RECORD
, "Record button"),
156 INIT_KEY(VOLUMEUP
, GPIO100_MAGICIAN_KEY_VOL_UP
, "Volume up"),
157 INIT_KEY(VOLUMEDOWN
, GPIO101_MAGICIAN_KEY_VOL_DOWN
, "Volume down"),
158 INIT_KEY(PHONE
, GPIO102_MAGICIAN_KEY_PHONE
, "Phone button"),
159 INIT_KEY(PLAY
, GPIO99_MAGICIAN_HEADPHONE_IN
, "Headset button"),
162 static struct gpio_keys_platform_data gpio_keys_data
= {
163 .buttons
= magician_button_table
,
164 .nbuttons
= ARRAY_SIZE(magician_button_table
),
167 static struct platform_device gpio_keys
= {
170 .platform_data
= &gpio_keys_data
,
177 * EGPIO (Xilinx CPLD)
179 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
182 static struct resource egpio_resources
[] = {
184 .start
= PXA_CS3_PHYS
,
185 .end
= PXA_CS3_PHYS
+ 0x20 - 1,
186 .flags
= IORESOURCE_MEM
,
189 .start
= PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ
),
190 .end
= PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ
),
191 .flags
= IORESOURCE_IRQ
,
195 static struct htc_egpio_chip egpio_chips
[] = {
198 .gpio_base
= MAGICIAN_EGPIO(0, 0),
200 .direction
= HTC_EGPIO_OUTPUT
,
201 .initial_values
= 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
205 .gpio_base
= MAGICIAN_EGPIO(4, 0),
207 .direction
= HTC_EGPIO_INPUT
,
211 static struct htc_egpio_platform_data egpio_info
= {
214 .irq_base
= IRQ_BOARD_START
,
218 .num_chips
= ARRAY_SIZE(egpio_chips
),
221 static struct platform_device egpio
= {
224 .resource
= egpio_resources
,
225 .num_resources
= ARRAY_SIZE(egpio_resources
),
227 .platform_data
= &egpio_info
,
232 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
235 static struct pxafb_mode_info toppoly_modes
[] = {
251 static struct pxafb_mode_info samsung_modes
[] = {
263 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
267 static void toppoly_lcd_power(int on
, struct fb_var_screeninfo
*si
)
269 pr_debug("Toppoly LCD power\n");
273 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER
, 1);
274 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 1);
276 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 1);
278 /* FIXME: enable LCDC here */
280 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 1);
282 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 1);
286 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 0);
288 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 0);
290 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 0);
291 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 0);
295 static void samsung_lcd_power(int on
, struct fb_var_screeninfo
*si
)
297 pr_debug("Samsung LCD power\n");
302 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER
, 1);
304 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 1);
306 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 1);
308 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 1);
310 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 1);
315 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2
, 0);
317 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1
, 0);
319 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3
, 0);
322 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER
, 0);
324 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER
, 0);
328 static struct pxafb_mach_info toppoly_info
= {
329 .modes
= toppoly_modes
,
332 .lcd_conn
= LCD_COLOR_TFT_16BPP
,
333 .pxafb_lcd_power
= toppoly_lcd_power
,
336 static struct pxafb_mach_info samsung_info
= {
337 .modes
= samsung_modes
,
340 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_PCLK_EDGE_FALL
|\
341 LCD_ALTERNATE_MAPPING
,
342 .pxafb_lcd_power
= samsung_lcd_power
,
349 static struct gpio magician_bl_gpios
[] = {
350 { EGPIO_MAGICIAN_BL_POWER
, GPIOF_DIR_OUT
, "Backlight power" },
351 { EGPIO_MAGICIAN_BL_POWER2
, GPIOF_DIR_OUT
, "Backlight power 2" },
354 static int magician_backlight_init(struct device
*dev
)
356 return gpio_request_array(ARRAY_AND_SIZE(magician_bl_gpios
));
359 static int magician_backlight_notify(struct device
*dev
, int brightness
)
361 gpio_set_value(EGPIO_MAGICIAN_BL_POWER
, brightness
);
362 if (brightness
>= 200) {
363 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2
, 1);
364 return brightness
- 72;
366 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2
, 0);
371 static void magician_backlight_exit(struct device
*dev
)
373 gpio_free_array(ARRAY_AND_SIZE(magician_bl_gpios
));
376 static struct platform_pwm_backlight_data backlight_data
= {
378 .max_brightness
= 272,
379 .dft_brightness
= 100,
380 .pwm_period_ns
= 30923,
382 .init
= magician_backlight_init
,
383 .notify
= magician_backlight_notify
,
384 .exit
= magician_backlight_exit
,
387 static struct platform_device backlight
= {
388 .name
= "pwm-backlight",
391 .parent
= &pxa27x_device_pwm0
.dev
,
392 .platform_data
= &backlight_data
,
400 static struct gpio_led gpio_leds
[] = {
402 .name
= "magician::vibra",
403 .default_trigger
= "none",
404 .gpio
= GPIO22_MAGICIAN_VIBRA_EN
,
407 .name
= "magician::phone_bl",
408 .default_trigger
= "backlight",
409 .gpio
= GPIO103_MAGICIAN_LED_KP
,
413 static struct gpio_led_platform_data gpio_led_info
= {
415 .num_leds
= ARRAY_SIZE(gpio_leds
),
418 static struct platform_device leds_gpio
= {
422 .platform_data
= &gpio_led_info
,
426 static struct pasic3_led pasic3_leds
[] = {
429 .name
= "magician:red",
430 .default_trigger
= "ds2760-battery.0-charging",
433 .bit2
= PASIC3_BIT2_LED0
,
434 .mask
= PASIC3_MASK_LED0
,
438 .name
= "magician:green",
439 .default_trigger
= "ds2760-battery.0-charging-or-full",
442 .bit2
= PASIC3_BIT2_LED1
,
443 .mask
= PASIC3_MASK_LED1
,
447 .name
= "magician:blue",
448 .default_trigger
= "bluetooth",
451 .bit2
= PASIC3_BIT2_LED2
,
452 .mask
= PASIC3_MASK_LED2
,
456 static struct pasic3_leds_machinfo pasic3_leds_info
= {
457 .num_leds
= ARRAY_SIZE(pasic3_leds
),
458 .power_gpio
= EGPIO_MAGICIAN_LED_POWER
,
466 static struct resource pasic3_resources
[] = {
468 .start
= PXA_CS2_PHYS
,
469 .end
= PXA_CS2_PHYS
+ 0x1b,
470 .flags
= IORESOURCE_MEM
,
472 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
474 .start
= PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ
),
475 .end
= PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ
),
476 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
,
480 static struct pasic3_platform_data pasic3_platform_data
= {
481 .led_pdata
= &pasic3_leds_info
,
482 .clock_rate
= 4000000,
485 static struct platform_device pasic3
= {
488 .num_resources
= ARRAY_SIZE(pasic3_resources
),
489 .resource
= pasic3_resources
,
491 .platform_data
= &pasic3_platform_data
,
499 static struct resource gpio_vbus_resource
= {
500 .flags
= IORESOURCE_IRQ
,
501 .start
= IRQ_MAGICIAN_VBUS
,
502 .end
= IRQ_MAGICIAN_VBUS
,
505 static struct gpio_vbus_mach_info gpio_vbus_info
= {
506 .gpio_pullup
= GPIO27_MAGICIAN_USBC_PUEN
,
507 .gpio_vbus
= EGPIO_MAGICIAN_CABLE_STATE_USB
,
510 static struct platform_device gpio_vbus
= {
514 .resource
= &gpio_vbus_resource
,
516 .platform_data
= &gpio_vbus_info
,
524 static int power_supply_init(struct device
*dev
)
526 return gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC
, "CABLE_STATE_AC");
529 static int magician_is_ac_online(void)
531 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC
);
534 static void power_supply_exit(struct device
*dev
)
536 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC
);
539 static char *magician_supplicants
[] = {
540 "ds2760-battery.0", "backup-battery"
543 static struct pda_power_pdata power_supply_info
= {
544 .init
= power_supply_init
,
545 .is_ac_online
= magician_is_ac_online
,
546 .exit
= power_supply_exit
,
547 .supplied_to
= magician_supplicants
,
548 .num_supplicants
= ARRAY_SIZE(magician_supplicants
),
551 static struct resource power_supply_resources
[] = {
554 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
|
555 IORESOURCE_IRQ_LOWEDGE
,
556 .start
= IRQ_MAGICIAN_VBUS
,
557 .end
= IRQ_MAGICIAN_VBUS
,
561 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
|
562 IORESOURCE_IRQ_LOWEDGE
,
563 .start
= IRQ_MAGICIAN_VBUS
,
564 .end
= IRQ_MAGICIAN_VBUS
,
568 static struct platform_device power_supply
= {
572 .platform_data
= &power_supply_info
,
574 .resource
= power_supply_resources
,
575 .num_resources
= ARRAY_SIZE(power_supply_resources
),
582 static struct regulator_consumer_supply bq24022_consumers
[] = {
583 REGULATOR_SUPPLY("vbus_draw", NULL
),
584 REGULATOR_SUPPLY("ac_draw", NULL
),
587 static struct regulator_init_data bq24022_init_data
= {
590 .valid_ops_mask
= REGULATOR_CHANGE_CURRENT
| REGULATOR_CHANGE_STATUS
,
592 .num_consumer_supplies
= ARRAY_SIZE(bq24022_consumers
),
593 .consumer_supplies
= bq24022_consumers
,
596 static struct gpio bq24022_gpios
[] = {
597 { EGPIO_MAGICIAN_BQ24022_ISET2
, GPIOF_OUT_INIT_LOW
, "bq24022_iset2" },
600 static struct gpio_regulator_state bq24022_states
[] = {
601 { .value
= 100000, .gpios
= (0 << 0) },
602 { .value
= 500000, .gpios
= (1 << 0) },
605 static struct gpio_regulator_config bq24022_info
= {
606 .supply_name
= "bq24022",
608 .enable_gpio
= GPIO30_MAGICIAN_BQ24022_nCHARGE_EN
,
610 .enabled_at_boot
= 0,
612 .gpios
= bq24022_gpios
,
613 .nr_gpios
= ARRAY_SIZE(bq24022_gpios
),
615 .states
= bq24022_states
,
616 .nr_states
= ARRAY_SIZE(bq24022_states
),
618 .type
= REGULATOR_CURRENT
,
619 .init_data
= &bq24022_init_data
,
622 static struct platform_device bq24022
= {
623 .name
= "gpio-regulator",
626 .platform_data
= &bq24022_info
,
634 static int magician_mci_init(struct device
*dev
,
635 irq_handler_t detect_irq
, void *data
)
637 return request_irq(IRQ_MAGICIAN_SD
, detect_irq
, 0,
638 "mmc card detect", data
);
641 static void magician_mci_exit(struct device
*dev
, void *data
)
643 free_irq(IRQ_MAGICIAN_SD
, data
);
646 static struct pxamci_platform_data magician_mci_info
= {
647 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
648 .init
= magician_mci_init
,
649 .exit
= magician_mci_exit
,
650 .gpio_card_detect
= -1,
651 .gpio_card_ro
= EGPIO_MAGICIAN_nSD_READONLY
,
652 .gpio_card_ro_invert
= 1,
653 .gpio_power
= EGPIO_MAGICIAN_SD_POWER
,
661 static struct pxaohci_platform_data magician_ohci_info
= {
662 .port_mode
= PMM_PERPORT_MODE
,
663 .flags
= ENABLE_PORT1
| ENABLE_PORT3
| POWER_CONTROL_LOW
,
672 static void magician_set_vpp(struct platform_device
*pdev
, int vpp
)
674 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP
, vpp
);
677 static struct resource strataflash_resource
= {
678 .start
= PXA_CS0_PHYS
,
679 .end
= PXA_CS0_PHYS
+ SZ_64M
- 1,
680 .flags
= IORESOURCE_MEM
,
683 static struct physmap_flash_data strataflash_data
= {
685 .set_vpp
= magician_set_vpp
,
688 static struct platform_device strataflash
= {
689 .name
= "physmap-flash",
691 .resource
= &strataflash_resource
,
694 .platform_data
= &strataflash_data
,
702 static struct i2c_pxa_platform_data i2c_info
= {
710 static struct platform_device
*devices
[] __initdata
= {
722 static struct gpio magician_global_gpios
[] = {
723 { GPIO13_MAGICIAN_CPLD_IRQ
, GPIOF_IN
, "CPLD_IRQ" },
724 { GPIO107_MAGICIAN_DS1WM_IRQ
, GPIOF_IN
, "DS1WM_IRQ" },
725 { GPIO104_MAGICIAN_LCD_POWER_1
, GPIOF_OUT_INIT_LOW
, "LCD power 1" },
726 { GPIO105_MAGICIAN_LCD_POWER_2
, GPIOF_OUT_INIT_LOW
, "LCD power 2" },
727 { GPIO106_MAGICIAN_LCD_POWER_3
, GPIOF_OUT_INIT_LOW
, "LCD power 3" },
728 { GPIO83_MAGICIAN_nIR_EN
, GPIOF_OUT_INIT_HIGH
, "nIR_EN" },
731 static void __init
magician_init(void)
737 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config
));
738 err
= gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios
));
740 pr_err("magician: Failed to request GPIOs: %d\n", err
);
742 pxa_set_ffuart_info(NULL
);
743 pxa_set_btuart_info(NULL
);
744 pxa_set_stuart_info(NULL
);
746 platform_add_devices(ARRAY_AND_SIZE(devices
));
748 pxa_set_ficp_info(&magician_ficp_info
);
749 pxa27x_set_i2c_power_info(NULL
);
750 pxa_set_i2c_info(&i2c_info
);
751 pxa_set_mci_info(&magician_mci_info
);
752 pxa_set_ohci_info(&magician_ohci_info
);
754 /* Check LCD type we have */
755 cpld
= ioremap_nocache(PXA_CS3_PHYS
, 0x1000);
757 u8 board_id
= __raw_readb(cpld
+0x14);
759 system_rev
= board_id
& 0x7;
760 lcd_select
= board_id
& 0x8;
761 pr_info("LCD type: %s\n", lcd_select
? "Samsung" : "Toppoly");
762 if (lcd_select
&& (system_rev
< 3))
763 gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER
,
764 GPIOF_OUT_INIT_LOW
, "SAMSUNG_POWER");
765 pxa_set_fb_info(NULL
, lcd_select
? &samsung_info
: &toppoly_info
);
767 pr_err("LCD detection: CPLD mapping failed\n");
771 MACHINE_START(MAGICIAN
, "HTC Magician")
772 .atag_offset
= 0x100,
773 .map_io
= pxa27x_map_io
,
774 .nr_irqs
= MAGICIAN_NR_IRQS
,
775 .init_irq
= pxa27x_init_irq
,
776 .handle_irq
= pxa27x_handle_irq
,
777 .init_machine
= magician_init
,
778 .init_time
= pxa_timer_init
,
779 .restart
= pxa_restart
,