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/usb/gpio_vbus.h>
30 #include <mach/hardware.h>
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <mach/magician.h>
34 #include <mach/mfp-pxa27x.h>
35 #include <mach/pxa-regs.h>
36 #include <mach/pxa2xx-regs.h>
37 #include <mach/pxafb.h>
40 #include <mach/irda.h>
41 #include <mach/ohci.h>
46 static unsigned long magician_pin_config[] __initdata = {
48 /* SDRAM and Static Memory I/O Signals */
52 GPIO78_nCS_2, /* PASIC3 */
53 GPIO79_nCS_3, /* EGPIO CPLD */
65 GPIO28_I2S_BITCLK_OUT,
125 /* Magician specific input GPIOs */
126 GPIO9_GPIO, /* unknown */
127 GPIO10_GPIO, /* GSM_IRQ */
128 GPIO13_GPIO, /* CPLD_IRQ */
129 GPIO107_GPIO, /* DS1WM_IRQ */
130 GPIO108_GPIO, /* GSM_READY */
131 GPIO115_GPIO, /* nPEN_IRQ */
142 static void magician_irda_transceiver_mode(struct device *dev, int mode)
144 gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
145 pxa2xx_transceiver_mode(dev, mode);
148 static struct pxaficp_platform_data magician_ficp_info = {
149 .transceiver_cap = IR_SIRMODE | IR_OFF,
150 .transceiver_mode = magician_irda_transceiver_mode,
157 #define INIT_KEY(_code, _gpio, _desc) \
159 .code = KEY_##_code, \
166 static struct gpio_keys_button magician_button_table[] = {
167 INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"),
168 INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"),
169 INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"),
170 INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"),
171 INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"),
172 INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"),
173 INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"),
174 INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"),
175 INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"),
176 INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"),
177 INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"),
178 INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"),
179 INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"),
180 INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"),
181 INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"),
184 static struct gpio_keys_platform_data gpio_keys_data = {
185 .buttons = magician_button_table,
186 .nbuttons = ARRAY_SIZE(magician_button_table),
189 static struct platform_device gpio_keys = {
192 .platform_data = &gpio_keys_data,
199 * EGPIO (Xilinx CPLD)
201 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
204 static struct resource egpio_resources[] = {
206 .start = PXA_CS3_PHYS,
207 .end = PXA_CS3_PHYS + 0x20,
208 .flags = IORESOURCE_MEM,
211 .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
212 .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
213 .flags = IORESOURCE_IRQ,
217 static struct htc_egpio_chip egpio_chips[] = {
220 .gpio_base = MAGICIAN_EGPIO(0, 0),
222 .direction = HTC_EGPIO_OUTPUT,
223 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
227 .gpio_base = MAGICIAN_EGPIO(4, 0),
229 .direction = HTC_EGPIO_INPUT,
233 static struct htc_egpio_platform_data egpio_info = {
236 .irq_base = IRQ_BOARD_START,
240 .num_chips = ARRAY_SIZE(egpio_chips),
243 static struct platform_device egpio = {
246 .resource = egpio_resources,
247 .num_resources = ARRAY_SIZE(egpio_resources),
249 .platform_data = &egpio_info,
254 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
257 static struct pxafb_mode_info toppoly_modes[] = {
273 static struct pxafb_mode_info samsung_modes[] = {
285 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
289 static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
291 pr_debug("Toppoly LCD power\n");
295 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
296 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
298 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
300 /* FIXME: enable LCDC here */
302 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
304 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
308 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
310 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
312 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
313 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
317 static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
319 pr_debug("Samsung LCD power\n");
324 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
326 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
328 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
330 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
332 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
337 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
339 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
341 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
344 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
346 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
350 static struct pxafb_mach_info toppoly_info = {
351 .modes = toppoly_modes,
354 .lcd_conn = LCD_COLOR_TFT_16BPP,
355 .pxafb_lcd_power = toppoly_lcd_power,
358 static struct pxafb_mach_info samsung_info = {
359 .modes = samsung_modes,
362 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |\
363 LCD_ALTERNATE_MAPPING,
364 .pxafb_lcd_power = samsung_lcd_power,
371 static int magician_backlight_init(struct device *dev)
375 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
378 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
384 gpio_free(EGPIO_MAGICIAN_BL_POWER);
389 static int magician_backlight_notify(int brightness)
391 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
392 if (brightness >= 200) {
393 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
394 return brightness - 72;
396 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
401 static void magician_backlight_exit(struct device *dev)
403 gpio_free(EGPIO_MAGICIAN_BL_POWER);
404 gpio_free(EGPIO_MAGICIAN_BL_POWER2);
407 static struct platform_pwm_backlight_data backlight_data = {
409 .max_brightness = 272,
410 .dft_brightness = 100,
411 .pwm_period_ns = 30923,
412 .init = magician_backlight_init,
413 .notify = magician_backlight_notify,
414 .exit = magician_backlight_exit,
417 static struct platform_device backlight = {
418 .name = "pwm-backlight",
421 .parent = &pxa27x_device_pwm0.dev,
422 .platform_data = &backlight_data,
430 static struct gpio_led gpio_leds[] = {
432 .name = "magician::vibra",
433 .default_trigger = "none",
434 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
437 .name = "magician::phone_bl",
438 .default_trigger = "none",
439 .gpio = GPIO103_MAGICIAN_LED_KP,
443 static struct gpio_led_platform_data gpio_led_info = {
445 .num_leds = ARRAY_SIZE(gpio_leds),
448 static struct platform_device leds_gpio = {
452 .platform_data = &gpio_led_info,
456 static struct pasic3_led pasic3_leds[] = {
459 .name = "magician:red",
460 .default_trigger = "ds2760-battery.0-charging",
463 .bit2 = PASIC3_BIT2_LED0,
464 .mask = PASIC3_MASK_LED0,
468 .name = "magician:green",
469 .default_trigger = "ds2760-battery.0-charging-or-full",
472 .bit2 = PASIC3_BIT2_LED1,
473 .mask = PASIC3_MASK_LED1,
477 .name = "magician:blue",
478 .default_trigger = "bluetooth",
481 .bit2 = PASIC3_BIT2_LED2,
482 .mask = PASIC3_MASK_LED2,
486 static struct platform_device pasic3;
488 static struct pasic3_leds_machinfo pasic3_leds_info = {
489 .num_leds = ARRAY_SIZE(pasic3_leds),
490 .power_gpio = EGPIO_MAGICIAN_LED_POWER,
498 static struct resource pasic3_resources[] = {
500 .start = PXA_CS2_PHYS,
501 .end = PXA_CS2_PHYS + 0x1b,
502 .flags = IORESOURCE_MEM,
504 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
506 .start = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
507 .end = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
508 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
512 static struct pasic3_platform_data pasic3_platform_data = {
514 .led_pdata = &pasic3_leds_info,
515 .clock_rate = 4000000,
518 static struct platform_device pasic3 = {
521 .num_resources = ARRAY_SIZE(pasic3_resources),
522 .resource = pasic3_resources,
524 .platform_data = &pasic3_platform_data,
532 static struct resource gpio_vbus_resource = {
533 .flags = IORESOURCE_IRQ,
534 .start = IRQ_MAGICIAN_VBUS,
535 .end = IRQ_MAGICIAN_VBUS,
538 static struct gpio_vbus_mach_info gpio_vbus_info = {
539 .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
540 .gpio_vbus = EGPIO_MAGICIAN_CABLE_STATE_USB,
543 static struct platform_device gpio_vbus = {
547 .resource = &gpio_vbus_resource,
549 .platform_data = &gpio_vbus_info,
557 static int power_supply_init(struct device *dev)
561 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
564 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB, "CABLE_STATE_USB");
567 ret = gpio_request(EGPIO_MAGICIAN_CHARGE_EN, "CHARGE_EN");
570 ret = gpio_request(GPIO30_MAGICIAN_nCHARGE_EN, "nCHARGE_EN");
572 ret = gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN, 0);
579 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
581 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
583 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
588 static int magician_is_ac_online(void)
590 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
593 static int magician_is_usb_online(void)
595 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
598 static void magician_set_charge(int flags)
600 gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
601 gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
604 static void power_supply_exit(struct device *dev)
606 gpio_free(GPIO30_MAGICIAN_nCHARGE_EN);
607 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
608 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
609 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
612 static char *magician_supplicants[] = {
613 "ds2760-battery.0", "backup-battery"
616 static struct pda_power_pdata power_supply_info = {
617 .init = power_supply_init,
618 .is_ac_online = magician_is_ac_online,
619 .is_usb_online = magician_is_usb_online,
620 .set_charge = magician_set_charge,
621 .exit = power_supply_exit,
622 .supplied_to = magician_supplicants,
623 .num_supplicants = ARRAY_SIZE(magician_supplicants),
626 static struct resource power_supply_resources[] = {
629 .flags = IORESOURCE_IRQ,
630 .start = IRQ_MAGICIAN_VBUS,
631 .end = IRQ_MAGICIAN_VBUS,
635 .flags = IORESOURCE_IRQ,
636 .start = IRQ_MAGICIAN_VBUS,
637 .end = IRQ_MAGICIAN_VBUS,
641 static struct platform_device power_supply = {
645 .platform_data = &power_supply_info,
647 .resource = power_supply_resources,
648 .num_resources = ARRAY_SIZE(power_supply_resources),
656 static int magician_mci_init(struct device *dev,
657 irq_handler_t detect_irq, void *data)
661 err = request_irq(IRQ_MAGICIAN_SD, detect_irq,
662 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
663 "MMC card detect", data);
665 goto err_request_irq;
666 err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER");
668 goto err_request_power;
669 err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY");
671 goto err_request_readonly;
675 err_request_readonly:
676 gpio_free(EGPIO_MAGICIAN_SD_POWER);
678 free_irq(IRQ_MAGICIAN_SD, data);
683 static void magician_mci_setpower(struct device *dev, unsigned int vdd)
685 struct pxamci_platform_data *pdata = dev->platform_data;
687 gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
690 static int magician_mci_get_ro(struct device *dev)
692 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
695 static void magician_mci_exit(struct device *dev, void *data)
697 gpio_free(EGPIO_MAGICIAN_nSD_READONLY);
698 gpio_free(EGPIO_MAGICIAN_SD_POWER);
699 free_irq(IRQ_MAGICIAN_SD, data);
702 static struct pxamci_platform_data magician_mci_info = {
703 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
704 .init = magician_mci_init,
705 .get_ro = magician_mci_get_ro,
706 .setpower = magician_mci_setpower,
707 .exit = magician_mci_exit,
715 static struct pxaohci_platform_data magician_ohci_info = {
716 .port_mode = PMM_PERPORT_MODE,
717 .flags = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW,
726 static void magician_set_vpp(struct map_info *map, int vpp)
728 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
731 static struct resource strataflash_resource = {
732 .start = PXA_CS0_PHYS,
733 .end = PXA_CS0_PHYS + SZ_64M - 1,
734 .flags = IORESOURCE_MEM,
737 static struct physmap_flash_data strataflash_data = {
739 .set_vpp = magician_set_vpp,
742 static struct platform_device strataflash = {
743 .name = "physmap-flash",
745 .resource = &strataflash_resource,
748 .platform_data = &strataflash_data,
756 static struct platform_device *devices[] __initdata = {
767 static void __init magician_init(void)
773 gpio_request(GPIO13_MAGICIAN_CPLD_IRQ, "CPLD_IRQ");
774 gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ, "DS1WM_IRQ");
776 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
778 platform_add_devices(devices, ARRAY_SIZE(devices));
780 err = gpio_request(GPIO83_MAGICIAN_nIR_EN, "nIR_EN");
782 gpio_direction_output(GPIO83_MAGICIAN_nIR_EN, 1);
783 pxa_set_ficp_info(&magician_ficp_info);
785 pxa27x_set_i2c_power_info(NULL);
786 pxa_set_i2c_info(NULL);
787 pxa_set_mci_info(&magician_mci_info);
788 pxa_set_ohci_info(&magician_ohci_info);
790 /* Check LCD type we have */
791 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
793 u8 board_id = __raw_readb(cpld+0x14);
795 system_rev = board_id & 0x7;
796 lcd_select = board_id & 0x8;
797 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
798 if (lcd_select && (system_rev < 3)) {
799 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER");
800 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
802 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1");
803 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2");
804 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3");
805 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0);
806 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0);
807 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0);
808 set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
810 pr_err("LCD detection: CPLD mapping failed\n");
814 MACHINE_START(MAGICIAN, "HTC Magician")
815 .phys_io = 0x40000000,
816 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
817 .boot_params = 0xa0000100,
818 .map_io = pxa_map_io,
819 .init_irq = pxa27x_init_irq,
820 .init_machine = magician_init,