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 <asm/hardware.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/arch/magician.h>
33 #include <asm/arch/mfp-pxa27x.h>
34 #include <asm/arch/pxa-regs.h>
35 #include <asm/arch/pxa2xx-regs.h>
36 #include <asm/arch/pxafb.h>
37 #include <asm/arch/i2c.h>
38 #include <asm/arch/mmc.h>
39 #include <asm/arch/irda.h>
40 #include <asm/arch/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 */
132 static void magician_irda_transceiver_mode(struct device *dev, int mode)
134 gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
135 pxa2xx_transceiver_mode(dev, mode);
138 static struct pxaficp_platform_data magician_ficp_info = {
139 .transceiver_cap = IR_SIRMODE | IR_OFF,
140 .transceiver_mode = magician_irda_transceiver_mode,
147 static struct gpio_keys_button magician_button_table[] = {
148 {KEY_POWER, GPIO0_MAGICIAN_KEY_POWER, 0, "Power button"},
149 {KEY_ESC, GPIO37_MAGICIAN_KEY_HANGUP, 0, "Hangup button"},
150 {KEY_F10, GPIO38_MAGICIAN_KEY_CONTACTS, 0, "Contacts button"},
151 {KEY_CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, 0, "Calendar button"},
152 {KEY_CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, 0, "Camera button"},
153 {KEY_UP, GPIO93_MAGICIAN_KEY_UP, 0, "Up button"},
154 {KEY_DOWN, GPIO94_MAGICIAN_KEY_DOWN, 0, "Down button"},
155 {KEY_LEFT, GPIO95_MAGICIAN_KEY_LEFT, 0, "Left button"},
156 {KEY_RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, 0, "Right button"},
157 {KEY_KPENTER, GPIO97_MAGICIAN_KEY_ENTER, 0, "Action button"},
158 {KEY_RECORD, GPIO98_MAGICIAN_KEY_RECORD, 0, "Record button"},
159 {KEY_VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, 0, "Volume up"},
160 {KEY_VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, 0, "Volume down"},
161 {KEY_PHONE, GPIO102_MAGICIAN_KEY_PHONE, 0, "Phone button"},
162 {KEY_PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, 0, "Headset button"},
165 static struct gpio_keys_platform_data gpio_keys_data = {
166 .buttons = magician_button_table,
167 .nbuttons = ARRAY_SIZE(magician_button_table),
170 static struct platform_device gpio_keys = {
173 .platform_data = &gpio_keys_data,
180 * EGPIO (Xilinx CPLD)
182 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
185 static struct resource egpio_resources[] = {
187 .start = PXA_CS3_PHYS,
188 .end = PXA_CS3_PHYS + 0x20,
189 .flags = IORESOURCE_MEM,
192 .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
193 .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
194 .flags = IORESOURCE_IRQ,
198 static struct htc_egpio_chip egpio_chips[] = {
201 .gpio_base = MAGICIAN_EGPIO(0, 0),
203 .direction = HTC_EGPIO_OUTPUT,
204 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
208 .gpio_base = MAGICIAN_EGPIO(4, 0),
210 .direction = HTC_EGPIO_INPUT,
214 static struct htc_egpio_platform_data egpio_info = {
217 .irq_base = IRQ_BOARD_START,
221 .num_chips = ARRAY_SIZE(egpio_chips),
224 static struct platform_device egpio = {
227 .resource = egpio_resources,
228 .num_resources = ARRAY_SIZE(egpio_resources),
230 .platform_data = &egpio_info,
235 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
238 static struct pxafb_mode_info toppoly_modes[] = {
254 static struct pxafb_mode_info samsung_modes[] = {
266 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
270 static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
272 pr_debug("Toppoly LCD power\n");
276 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
277 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
279 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
281 /* FIXME: enable LCDC here */
283 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
285 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
289 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
291 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
293 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
294 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
298 static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
300 pr_debug("Samsung LCD power\n");
305 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
307 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
309 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
311 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
313 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
318 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
320 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
322 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
325 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
327 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
331 static struct pxafb_mach_info toppoly_info = {
332 .modes = toppoly_modes,
335 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
336 .lccr3 = LCCR3_PixRsEdg,
337 .pxafb_lcd_power = toppoly_lcd_power,
340 static struct pxafb_mach_info samsung_info = {
341 .modes = samsung_modes,
344 .lccr0 = LCCR0_LDDALT | LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
345 .lccr3 = LCCR3_PixFlEdg,
346 .pxafb_lcd_power = samsung_lcd_power,
353 static int magician_backlight_init(struct device *dev)
357 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
360 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
366 gpio_free(EGPIO_MAGICIAN_BL_POWER);
371 static int magician_backlight_notify(int brightness)
373 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
374 if (brightness >= 200) {
375 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
376 return brightness - 72;
378 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
383 static void magician_backlight_exit(struct device *dev)
385 gpio_free(EGPIO_MAGICIAN_BL_POWER);
386 gpio_free(EGPIO_MAGICIAN_BL_POWER2);
389 static struct platform_pwm_backlight_data backlight_data = {
391 .max_brightness = 272,
392 .dft_brightness = 100,
393 .pwm_period_ns = 30923,
394 .init = magician_backlight_init,
395 .notify = magician_backlight_notify,
396 .exit = magician_backlight_exit,
399 static struct platform_device backlight = {
400 .name = "pwm-backlight",
403 .parent = &pxa27x_device_pwm0.dev,
404 .platform_data = &backlight_data,
412 struct gpio_led gpio_leds[] = {
414 .name = "magician::vibra",
415 .default_trigger = "none",
416 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
419 .name = "magician::phone_bl",
420 .default_trigger = "none",
421 .gpio = GPIO103_MAGICIAN_LED_KP,
425 static struct gpio_led_platform_data gpio_led_info = {
427 .num_leds = ARRAY_SIZE(gpio_leds),
430 static struct platform_device leds_gpio = {
434 .platform_data = &gpio_led_info,
438 static struct pasic3_led pasic3_leds[] = {
441 .name = "magician:red",
442 .default_trigger = "ds2760-battery.0-charging",
445 .bit2 = PASIC3_BIT2_LED0,
446 .mask = PASIC3_MASK_LED0,
450 .name = "magician:green",
451 .default_trigger = "ds2760-battery.0-charging-or-full",
454 .bit2 = PASIC3_BIT2_LED1,
455 .mask = PASIC3_MASK_LED1,
459 .name = "magician:blue",
460 .default_trigger = "bluetooth",
463 .bit2 = PASIC3_BIT2_LED2,
464 .mask = PASIC3_MASK_LED2,
468 static struct platform_device pasic3;
470 static struct pasic3_leds_machinfo pasic3_leds_info = {
471 .num_leds = ARRAY_SIZE(pasic3_leds),
472 .power_gpio = EGPIO_MAGICIAN_LED_POWER,
480 static struct resource pasic3_resources[] = {
482 .start = PXA_CS2_PHYS,
483 .end = PXA_CS2_PHYS + 0x1b,
484 .flags = IORESOURCE_MEM,
486 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
488 .start = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
489 .end = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
490 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
494 static struct pasic3_platform_data pasic3_platform_data = {
496 .led_pdata = &pasic3_leds_info,
497 .clock_rate = 4000000,
500 static struct platform_device pasic3 = {
503 .num_resources = ARRAY_SIZE(pasic3_resources),
504 .resource = pasic3_resources,
506 .platform_data = &pasic3_platform_data,
514 static int power_supply_init(struct device *dev)
518 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
521 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB, "CABLE_STATE_USB");
524 ret = gpio_request(EGPIO_MAGICIAN_CHARGE_EN, "CHARGE_EN");
527 ret = gpio_request(GPIO30_MAGICIAN_nCHARGE_EN, "nCHARGE_EN");
529 ret = gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN, 0);
536 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
538 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
540 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
545 static int magician_is_ac_online(void)
547 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
550 static int magician_is_usb_online(void)
552 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
555 static void magician_set_charge(int flags)
557 gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
558 gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
561 static void power_supply_exit(struct device *dev)
563 gpio_free(GPIO30_MAGICIAN_nCHARGE_EN);
564 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
565 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
566 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
569 static char *magician_supplicants[] = {
570 "ds2760-battery.0", "backup-battery"
573 static struct pda_power_pdata power_supply_info = {
574 .init = power_supply_init,
575 .is_ac_online = magician_is_ac_online,
576 .is_usb_online = magician_is_usb_online,
577 .set_charge = magician_set_charge,
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,
587 .start = IRQ_MAGICIAN_AC,
588 .end = IRQ_MAGICIAN_AC,
592 .flags = IORESOURCE_IRQ,
593 .start = IRQ_MAGICIAN_AC,
594 .end = IRQ_MAGICIAN_AC,
598 static struct platform_device power_supply = {
602 .platform_data = &power_supply_info,
604 .resource = power_supply_resources,
605 .num_resources = ARRAY_SIZE(power_supply_resources),
613 static int magician_mci_init(struct device *dev,
614 irq_handler_t detect_irq, void *data)
618 err = request_irq(IRQ_MAGICIAN_SD, detect_irq,
619 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
620 "MMC card detect", data);
622 goto err_request_irq;
623 err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER");
625 goto err_request_power;
626 err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY");
628 goto err_request_readonly;
632 err_request_readonly:
633 gpio_free(EGPIO_MAGICIAN_SD_POWER);
635 free_irq(IRQ_MAGICIAN_SD, data);
640 static void magician_mci_setpower(struct device *dev, unsigned int vdd)
642 struct pxamci_platform_data *pdata = dev->platform_data;
644 gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
647 static int magician_mci_get_ro(struct device *dev)
649 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
652 static void magician_mci_exit(struct device *dev, void *data)
654 gpio_free(EGPIO_MAGICIAN_nSD_READONLY);
655 gpio_free(EGPIO_MAGICIAN_SD_POWER);
656 free_irq(IRQ_MAGICIAN_SD, data);
659 static struct pxamci_platform_data magician_mci_info = {
660 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
661 .init = magician_mci_init,
662 .get_ro = magician_mci_get_ro,
663 .setpower = magician_mci_setpower,
664 .exit = magician_mci_exit,
672 static int magician_ohci_init(struct device *dev)
674 UHCHR = (UHCHR | UHCHR_SSEP2 | UHCHR_PCPL | UHCHR_CGR) &
675 ~(UHCHR_SSEP1 | UHCHR_SSEP3 | UHCHR_SSE);
680 static struct pxaohci_platform_data magician_ohci_info = {
681 .port_mode = PMM_PERPORT_MODE,
682 .init = magician_ohci_init,
691 static void magician_set_vpp(struct map_info *map, int vpp)
693 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
696 #define PXA_CS_SIZE 0x04000000
698 static struct resource strataflash_resource = {
699 .start = PXA_CS0_PHYS,
700 .end = PXA_CS0_PHYS + PXA_CS_SIZE - 1,
701 .flags = IORESOURCE_MEM,
704 static struct physmap_flash_data strataflash_data = {
706 .set_vpp = magician_set_vpp,
709 static struct platform_device strataflash = {
710 .name = "physmap-flash",
712 .resource = &strataflash_resource,
715 .platform_data = &strataflash_data,
723 static struct platform_device *devices[] __initdata = {
733 static void __init magician_init(void)
739 gpio_request(GPIO13_MAGICIAN_CPLD_IRQ, "CPLD_IRQ");
740 gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ, "DS1WM_IRQ");
742 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
744 platform_add_devices(devices, ARRAY_SIZE(devices));
746 err = gpio_request(GPIO83_MAGICIAN_nIR_EN, "nIR_EN");
748 gpio_direction_output(GPIO83_MAGICIAN_nIR_EN, 1);
749 pxa_set_ficp_info(&magician_ficp_info);
751 pxa_set_i2c_info(NULL);
752 pxa_set_mci_info(&magician_mci_info);
753 pxa_set_ohci_info(&magician_ohci_info);
755 /* Check LCD type we have */
756 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
758 u8 board_id = __raw_readb(cpld+0x14);
760 system_rev = board_id & 0x7;
761 lcd_select = board_id & 0x8;
762 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
763 if (lcd_select && (system_rev < 3)) {
764 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER");
765 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
767 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1");
768 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2");
769 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3");
770 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0);
771 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0);
772 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0);
773 set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
775 pr_err("LCD detection: CPLD mapping failed\n");
779 MACHINE_START(MAGICIAN, "HTC Magician")
780 .phys_io = 0x40000000,
781 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
782 .boot_params = 0xa0000100,
783 .map_io = pxa_map_io,
784 .init_irq = pxa27x_init_irq,
785 .init_machine = magician_init,