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,
126 /* Magician specific input GPIOs */
127 GPIO9_GPIO, /* unknown */
128 GPIO10_GPIO, /* GSM_IRQ */
129 GPIO13_GPIO, /* CPLD_IRQ */
130 GPIO107_GPIO, /* DS1WM_IRQ */
131 GPIO108_GPIO, /* GSM_READY */
132 GPIO115_GPIO, /* nPEN_IRQ */
143 static void magician_irda_transceiver_mode(struct device *dev, int mode)
145 gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
146 pxa2xx_transceiver_mode(dev, mode);
149 static struct pxaficp_platform_data magician_ficp_info = {
150 .transceiver_cap = IR_SIRMODE | IR_OFF,
151 .transceiver_mode = magician_irda_transceiver_mode,
158 #define INIT_KEY(_code, _gpio, _desc) \
160 .code = KEY_##_code, \
167 static struct gpio_keys_button magician_button_table[] = {
168 INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"),
169 INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"),
170 INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"),
171 INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"),
172 INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"),
173 INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"),
174 INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"),
175 INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"),
176 INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"),
177 INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"),
178 INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"),
179 INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"),
180 INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"),
181 INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"),
182 INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"),
185 static struct gpio_keys_platform_data gpio_keys_data = {
186 .buttons = magician_button_table,
187 .nbuttons = ARRAY_SIZE(magician_button_table),
190 static struct platform_device gpio_keys = {
193 .platform_data = &gpio_keys_data,
200 * EGPIO (Xilinx CPLD)
202 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
205 static struct resource egpio_resources[] = {
207 .start = PXA_CS3_PHYS,
208 .end = PXA_CS3_PHYS + 0x20 - 1,
209 .flags = IORESOURCE_MEM,
212 .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
213 .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
214 .flags = IORESOURCE_IRQ,
218 static struct htc_egpio_chip egpio_chips[] = {
221 .gpio_base = MAGICIAN_EGPIO(0, 0),
223 .direction = HTC_EGPIO_OUTPUT,
224 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
228 .gpio_base = MAGICIAN_EGPIO(4, 0),
230 .direction = HTC_EGPIO_INPUT,
234 static struct htc_egpio_platform_data egpio_info = {
237 .irq_base = IRQ_BOARD_START,
241 .num_chips = ARRAY_SIZE(egpio_chips),
244 static struct platform_device egpio = {
247 .resource = egpio_resources,
248 .num_resources = ARRAY_SIZE(egpio_resources),
250 .platform_data = &egpio_info,
255 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
258 static struct pxafb_mode_info toppoly_modes[] = {
274 static struct pxafb_mode_info samsung_modes[] = {
286 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
290 static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
292 pr_debug("Toppoly LCD power\n");
296 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
297 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
299 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
301 /* FIXME: enable LCDC here */
303 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
305 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
309 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
311 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
313 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
314 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
318 static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
320 pr_debug("Samsung LCD power\n");
325 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
327 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
329 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
331 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
333 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
338 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
340 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
342 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
345 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
347 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
351 static struct pxafb_mach_info toppoly_info = {
352 .modes = toppoly_modes,
355 .lcd_conn = LCD_COLOR_TFT_16BPP,
356 .pxafb_lcd_power = toppoly_lcd_power,
359 static struct pxafb_mach_info samsung_info = {
360 .modes = samsung_modes,
363 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |\
364 LCD_ALTERNATE_MAPPING,
365 .pxafb_lcd_power = samsung_lcd_power,
372 static int magician_backlight_init(struct device *dev)
376 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
379 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
385 gpio_free(EGPIO_MAGICIAN_BL_POWER);
390 static int magician_backlight_notify(int brightness)
392 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
393 if (brightness >= 200) {
394 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
395 return brightness - 72;
397 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
402 static void magician_backlight_exit(struct device *dev)
404 gpio_free(EGPIO_MAGICIAN_BL_POWER);
405 gpio_free(EGPIO_MAGICIAN_BL_POWER2);
408 static struct platform_pwm_backlight_data backlight_data = {
410 .max_brightness = 272,
411 .dft_brightness = 100,
412 .pwm_period_ns = 30923,
413 .init = magician_backlight_init,
414 .notify = magician_backlight_notify,
415 .exit = magician_backlight_exit,
418 static struct platform_device backlight = {
419 .name = "pwm-backlight",
422 .parent = &pxa27x_device_pwm0.dev,
423 .platform_data = &backlight_data,
431 static struct gpio_led gpio_leds[] = {
433 .name = "magician::vibra",
434 .default_trigger = "none",
435 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
438 .name = "magician::phone_bl",
439 .default_trigger = "backlight",
440 .gpio = GPIO103_MAGICIAN_LED_KP,
444 static struct gpio_led_platform_data gpio_led_info = {
446 .num_leds = ARRAY_SIZE(gpio_leds),
449 static struct platform_device leds_gpio = {
453 .platform_data = &gpio_led_info,
457 static struct pasic3_led pasic3_leds[] = {
460 .name = "magician:red",
461 .default_trigger = "ds2760-battery.0-charging",
464 .bit2 = PASIC3_BIT2_LED0,
465 .mask = PASIC3_MASK_LED0,
469 .name = "magician:green",
470 .default_trigger = "ds2760-battery.0-charging-or-full",
473 .bit2 = PASIC3_BIT2_LED1,
474 .mask = PASIC3_MASK_LED1,
478 .name = "magician:blue",
479 .default_trigger = "bluetooth",
482 .bit2 = PASIC3_BIT2_LED2,
483 .mask = PASIC3_MASK_LED2,
487 static struct pasic3_leds_machinfo pasic3_leds_info = {
488 .num_leds = ARRAY_SIZE(pasic3_leds),
489 .power_gpio = EGPIO_MAGICIAN_LED_POWER,
497 static struct resource pasic3_resources[] = {
499 .start = PXA_CS2_PHYS,
500 .end = PXA_CS2_PHYS + 0x1b,
501 .flags = IORESOURCE_MEM,
503 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
505 .start = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
506 .end = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
507 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
511 static struct pasic3_platform_data pasic3_platform_data = {
513 .led_pdata = &pasic3_leds_info,
514 .clock_rate = 4000000,
517 static struct platform_device pasic3 = {
520 .num_resources = ARRAY_SIZE(pasic3_resources),
521 .resource = pasic3_resources,
523 .platform_data = &pasic3_platform_data,
531 static struct resource gpio_vbus_resource = {
532 .flags = IORESOURCE_IRQ,
533 .start = IRQ_MAGICIAN_VBUS,
534 .end = IRQ_MAGICIAN_VBUS,
537 static struct gpio_vbus_mach_info gpio_vbus_info = {
538 .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
539 .gpio_vbus = EGPIO_MAGICIAN_CABLE_STATE_USB,
542 static struct platform_device gpio_vbus = {
546 .resource = &gpio_vbus_resource,
548 .platform_data = &gpio_vbus_info,
556 static int power_supply_init(struct device *dev)
558 return gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
561 static int magician_is_ac_online(void)
563 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
566 static void power_supply_exit(struct device *dev)
568 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
571 static char *magician_supplicants[] = {
572 "ds2760-battery.0", "backup-battery"
575 static struct pda_power_pdata power_supply_info = {
576 .init = power_supply_init,
577 .is_ac_online = magician_is_ac_online,
578 .exit = power_supply_exit,
579 .supplied_to = magician_supplicants,
580 .num_supplicants = ARRAY_SIZE(magician_supplicants),
583 static struct resource power_supply_resources[] = {
586 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
587 IORESOURCE_IRQ_LOWEDGE,
588 .start = IRQ_MAGICIAN_VBUS,
589 .end = IRQ_MAGICIAN_VBUS,
593 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
594 IORESOURCE_IRQ_LOWEDGE,
595 .start = IRQ_MAGICIAN_VBUS,
596 .end = IRQ_MAGICIAN_VBUS,
600 static struct platform_device power_supply = {
604 .platform_data = &power_supply_info,
606 .resource = power_supply_resources,
607 .num_resources = ARRAY_SIZE(power_supply_resources),
614 static struct regulator_consumer_supply bq24022_consumers[] = {
616 .dev = &gpio_vbus.dev,
617 .supply = "vbus_draw",
620 .dev = &power_supply.dev,
625 static struct regulator_init_data bq24022_init_data = {
628 .valid_ops_mask = REGULATOR_CHANGE_CURRENT,
630 .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers),
631 .consumer_supplies = bq24022_consumers,
634 static struct bq24022_mach_info bq24022_info = {
635 .gpio_nce = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
636 .gpio_iset2 = EGPIO_MAGICIAN_BQ24022_ISET2,
637 .init_data = &bq24022_init_data,
640 static struct platform_device bq24022 = {
644 .platform_data = &bq24022_info,
652 static int magician_mci_init(struct device *dev,
653 irq_handler_t detect_irq, void *data)
657 err = request_irq(IRQ_MAGICIAN_SD, detect_irq,
658 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
659 "MMC card detect", data);
661 goto err_request_irq;
662 err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER");
664 goto err_request_power;
665 err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY");
667 goto err_request_readonly;
671 err_request_readonly:
672 gpio_free(EGPIO_MAGICIAN_SD_POWER);
674 free_irq(IRQ_MAGICIAN_SD, data);
679 static void magician_mci_setpower(struct device *dev, unsigned int vdd)
681 struct pxamci_platform_data *pdata = dev->platform_data;
683 gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
686 static int magician_mci_get_ro(struct device *dev)
688 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
691 static void magician_mci_exit(struct device *dev, void *data)
693 gpio_free(EGPIO_MAGICIAN_nSD_READONLY);
694 gpio_free(EGPIO_MAGICIAN_SD_POWER);
695 free_irq(IRQ_MAGICIAN_SD, data);
698 static struct pxamci_platform_data magician_mci_info = {
699 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
700 .init = magician_mci_init,
701 .get_ro = magician_mci_get_ro,
702 .setpower = magician_mci_setpower,
703 .exit = magician_mci_exit,
711 static struct pxaohci_platform_data magician_ohci_info = {
712 .port_mode = PMM_PERPORT_MODE,
713 .flags = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW,
722 static void magician_set_vpp(struct map_info *map, int vpp)
724 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
727 static struct resource strataflash_resource = {
728 .start = PXA_CS0_PHYS,
729 .end = PXA_CS0_PHYS + SZ_64M - 1,
730 .flags = IORESOURCE_MEM,
733 static struct physmap_flash_data strataflash_data = {
735 .set_vpp = magician_set_vpp,
738 static struct platform_device strataflash = {
739 .name = "physmap-flash",
741 .resource = &strataflash_resource,
744 .platform_data = &strataflash_data,
752 static struct platform_device *devices[] __initdata = {
764 static void __init magician_init(void)
770 gpio_request(GPIO13_MAGICIAN_CPLD_IRQ, "CPLD_IRQ");
771 gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ, "DS1WM_IRQ");
773 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
775 platform_add_devices(devices, ARRAY_SIZE(devices));
777 err = gpio_request(GPIO83_MAGICIAN_nIR_EN, "nIR_EN");
779 gpio_direction_output(GPIO83_MAGICIAN_nIR_EN, 1);
780 pxa_set_ficp_info(&magician_ficp_info);
782 pxa27x_set_i2c_power_info(NULL);
783 pxa_set_i2c_info(NULL);
784 pxa_set_mci_info(&magician_mci_info);
785 pxa_set_ohci_info(&magician_ohci_info);
787 /* Check LCD type we have */
788 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
790 u8 board_id = __raw_readb(cpld+0x14);
792 system_rev = board_id & 0x7;
793 lcd_select = board_id & 0x8;
794 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
795 if (lcd_select && (system_rev < 3)) {
796 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER");
797 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
799 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1");
800 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2");
801 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3");
802 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0);
803 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0);
804 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0);
805 set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
807 pr_err("LCD detection: CPLD mapping failed\n");
811 MACHINE_START(MAGICIAN, "HTC Magician")
812 .phys_io = 0x40000000,
813 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
814 .boot_params = 0xa0000100,
815 .map_io = pxa_map_io,
816 .init_irq = pxa27x_init_irq,
817 .init_machine = magician_init,