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_keys.h>
21 #include <linux/input.h>
22 #include <linux/mfd/htc-egpio.h>
23 #include <linux/mfd/htc-pasic3.h>
24 #include <linux/mtd/mtd.h>
25 #include <linux/mtd/map.h>
26 #include <linux/mtd/physmap.h>
27 #include <linux/pda_power.h>
30 #include <asm/hardware.h>
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/arch/magician.h>
34 #include <asm/arch/mfp-pxa27x.h>
35 #include <asm/arch/pxa-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>
44 static unsigned long magician_pin_config[] = {
46 /* SDRAM and Static Memory I/O Signals */
50 GPIO78_nCS_2, /* PASIC3 */
51 GPIO79_nCS_3, /* EGPIO CPLD */
63 GPIO28_I2S_BITCLK_OUT,
123 static void magician_irda_transceiver_mode(struct device *dev, int mode)
125 gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
128 static struct pxaficp_platform_data magician_ficp_info = {
129 .transceiver_cap = IR_SIRMODE | IR_OFF,
130 .transceiver_mode = magician_irda_transceiver_mode,
137 static struct gpio_keys_button magician_button_table[] = {
138 {KEY_POWER, GPIO0_MAGICIAN_KEY_POWER, 0, "Power button"},
139 {KEY_ESC, GPIO37_MAGICIAN_KEY_HANGUP, 0, "Hangup button"},
140 {KEY_F10, GPIO38_MAGICIAN_KEY_CONTACTS, 0, "Contacts button"},
141 {KEY_CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, 0, "Calendar button"},
142 {KEY_CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, 0, "Camera button"},
143 {KEY_UP, GPIO93_MAGICIAN_KEY_UP, 0, "Up button"},
144 {KEY_DOWN, GPIO94_MAGICIAN_KEY_DOWN, 0, "Down button"},
145 {KEY_LEFT, GPIO95_MAGICIAN_KEY_LEFT, 0, "Left button"},
146 {KEY_RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, 0, "Right button"},
147 {KEY_KPENTER, GPIO97_MAGICIAN_KEY_ENTER, 0, "Action button"},
148 {KEY_RECORD, GPIO98_MAGICIAN_KEY_RECORD, 0, "Record button"},
149 {KEY_VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, 0, "Volume up"},
150 {KEY_VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, 0, "Volume down"},
151 {KEY_PHONE, GPIO102_MAGICIAN_KEY_PHONE, 0, "Phone button"},
152 {KEY_PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, 0, "Headset button"},
155 static struct gpio_keys_platform_data gpio_keys_data = {
156 .buttons = magician_button_table,
157 .nbuttons = ARRAY_SIZE(magician_button_table),
160 static struct platform_device gpio_keys = {
163 .platform_data = &gpio_keys_data,
170 * EGPIO (Xilinx CPLD)
172 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
175 static struct resource egpio_resources[] = {
177 .start = PXA_CS3_PHYS,
178 .end = PXA_CS3_PHYS + 0x20,
179 .flags = IORESOURCE_MEM,
182 .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
183 .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
184 .flags = IORESOURCE_IRQ,
188 static struct htc_egpio_chip egpio_chips[] = {
191 .gpio_base = MAGICIAN_EGPIO(0, 0),
193 .direction = HTC_EGPIO_OUTPUT,
194 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
198 .gpio_base = MAGICIAN_EGPIO(4, 0),
200 .direction = HTC_EGPIO_INPUT,
204 static struct htc_egpio_platform_data egpio_info = {
207 .irq_base = IRQ_BOARD_START,
211 .num_chips = ARRAY_SIZE(egpio_chips),
214 static struct platform_device egpio = {
217 .resource = egpio_resources,
218 .num_resources = ARRAY_SIZE(egpio_resources),
220 .platform_data = &egpio_info,
225 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
228 static struct pxafb_mode_info toppoly_modes[] = {
244 static struct pxafb_mode_info samsung_modes[] = {
256 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
260 static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
262 pr_debug("Toppoly LCD power\n");
266 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
267 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
269 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
271 /* FIXME: enable LCDC here */
273 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
275 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
279 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
281 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
283 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
284 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
288 static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
290 pr_debug("Samsung LCD power\n");
295 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
297 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
299 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
301 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
303 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);
315 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
317 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
321 static struct pxafb_mach_info toppoly_info = {
322 .modes = toppoly_modes,
325 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
326 .lccr3 = LCCR3_PixRsEdg,
327 .pxafb_lcd_power = toppoly_lcd_power,
330 static struct pxafb_mach_info samsung_info = {
331 .modes = samsung_modes,
334 .lccr0 = LCCR0_LDDALT | LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
335 .lccr3 = LCCR3_PixFlEdg,
336 .pxafb_lcd_power = samsung_lcd_power,
343 static void magician_set_bl_intensity(int intensity)
348 if (intensity > 0xc7) {
349 PWM_PWDUTY0 = intensity - 0x48;
350 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
352 PWM_PWDUTY0 = intensity;
353 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
355 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, 1);
356 pxa_set_cken(CKEN_PWM0, 1);
358 /* PWM_PWDUTY0 = intensity; */
359 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, 0);
360 pxa_set_cken(CKEN_PWM0, 0);
364 static struct generic_bl_info backlight_info = {
365 .default_intensity = 0x64,
367 .max_intensity = 0xc7+0x48,
368 .set_bl_intensity = magician_set_bl_intensity,
371 static struct platform_device backlight = {
372 .name = "generic-bl",
374 .platform_data = &backlight_info,
383 struct gpio_led gpio_leds[] = {
385 .name = "magician::vibra",
386 .default_trigger = "none",
387 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
390 .name = "magician::phone_bl",
391 .default_trigger = "none",
392 .gpio = GPIO103_MAGICIAN_LED_KP,
396 static struct gpio_led_platform_data gpio_led_info = {
398 .num_leds = ARRAY_SIZE(gpio_leds),
401 static struct platform_device leds_gpio = {
405 .platform_data = &gpio_led_info,
409 static struct pasic3_led pasic3_leds[] = {
412 .name = "magician:red",
413 .default_trigger = "ds2760-battery.0-charging",
416 .bit2 = PASIC3_BIT2_LED0,
417 .mask = PASIC3_MASK_LED0,
421 .name = "magician:green",
422 .default_trigger = "ds2760-battery.0-charging-or-full",
425 .bit2 = PASIC3_BIT2_LED1,
426 .mask = PASIC3_MASK_LED1,
430 .name = "magician:blue",
431 .default_trigger = "bluetooth",
434 .bit2 = PASIC3_BIT2_LED2,
435 .mask = PASIC3_MASK_LED2,
439 static struct platform_device pasic3;
441 static struct pasic3_leds_machinfo __devinit pasic3_leds_info = {
442 .num_leds = ARRAY_SIZE(pasic3_leds),
443 .power_gpio = EGPIO_MAGICIAN_LED_POWER,
451 static struct resource pasic3_resources[] = {
453 .start = PXA_CS2_PHYS,
454 .end = PXA_CS2_PHYS + 0x1b,
455 .flags = IORESOURCE_MEM,
457 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
459 .start = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
460 .end = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
461 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
465 static struct pasic3_platform_data pasic3_platform_data = {
467 .led_pdata = &pasic3_leds_info,
468 .clock_rate = 4000000,
471 static struct platform_device pasic3 = {
474 .num_resources = ARRAY_SIZE(pasic3_resources),
475 .resource = pasic3_resources,
477 .platform_data = &pasic3_platform_data,
485 static int magician_is_ac_online(void)
487 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
490 static int magician_is_usb_online(void)
492 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
495 static void magician_set_charge(int flags)
497 gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
498 gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
501 static char *magician_supplicants[] = {
502 "ds2760-battery.0", "backup-battery"
505 static struct pda_power_pdata power_supply_info = {
506 .is_ac_online = magician_is_ac_online,
507 .is_usb_online = magician_is_usb_online,
508 .set_charge = magician_set_charge,
509 .supplied_to = magician_supplicants,
510 .num_supplicants = ARRAY_SIZE(magician_supplicants),
513 static struct resource power_supply_resources[] = {
516 .flags = IORESOURCE_IRQ,
517 .start = IRQ_MAGICIAN_AC,
518 .end = IRQ_MAGICIAN_AC,
522 .flags = IORESOURCE_IRQ,
523 .start = IRQ_MAGICIAN_AC,
524 .end = IRQ_MAGICIAN_AC,
528 static struct platform_device power_supply = {
532 .platform_data = &power_supply_info,
534 .resource = power_supply_resources,
535 .num_resources = ARRAY_SIZE(power_supply_resources),
543 static int magician_mci_init(struct device *dev,
544 irq_handler_t detect_irq, void *data)
546 return request_irq(IRQ_MAGICIAN_SD, detect_irq,
547 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
548 "MMC card detect", data);
551 static void magician_mci_setpower(struct device *dev, unsigned int vdd)
553 struct pxamci_platform_data *pdata = dev->platform_data;
555 gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
558 static int magician_mci_get_ro(struct device *dev)
560 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
563 static void magician_mci_exit(struct device *dev, void *data)
565 free_irq(IRQ_MAGICIAN_SD, data);
568 static struct pxamci_platform_data magician_mci_info = {
569 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
570 .init = magician_mci_init,
571 .get_ro = magician_mci_get_ro,
572 .setpower = magician_mci_setpower,
573 .exit = magician_mci_exit,
581 static int magician_ohci_init(struct device *dev)
583 UHCHR = (UHCHR | UHCHR_SSEP2 | UHCHR_PCPL | UHCHR_CGR) &
584 ~(UHCHR_SSEP1 | UHCHR_SSEP3 | UHCHR_SSE);
589 static struct pxaohci_platform_data magician_ohci_info = {
590 .port_mode = PMM_PERPORT_MODE,
591 .init = magician_ohci_init,
600 static void magician_set_vpp(struct map_info *map, int vpp)
602 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
605 #define PXA_CS_SIZE 0x04000000
607 static struct resource strataflash_resource = {
608 .start = PXA_CS0_PHYS,
609 .end = PXA_CS0_PHYS + PXA_CS_SIZE - 1,
610 .flags = IORESOURCE_MEM,
613 static struct physmap_flash_data strataflash_data = {
615 .set_vpp = magician_set_vpp,
618 static struct platform_device strataflash = {
619 .name = "physmap-flash",
621 .resource = &strataflash_resource,
624 .platform_data = &strataflash_data,
632 static struct platform_device *devices[] __initdata = {
642 static void __init magician_init(void)
647 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
649 platform_add_devices(devices, ARRAY_SIZE(devices));
650 pxa_set_i2c_info(NULL);
651 pxa_set_mci_info(&magician_mci_info);
652 pxa_set_ohci_info(&magician_ohci_info);
653 pxa_set_ficp_info(&magician_ficp_info);
655 /* Check LCD type we have */
656 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
658 u8 board_id = __raw_readb(cpld+0x14);
659 system_rev = board_id & 0x7;
660 lcd_select = board_id & 0x8;
662 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
663 if (lcd_select && (system_rev < 3))
664 pxa_gpio_mode(GPIO75_MAGICIAN_SAMSUNG_POWER_MD);
665 pxa_gpio_mode(GPIO104_MAGICIAN_LCD_POWER_1_MD);
666 pxa_gpio_mode(GPIO105_MAGICIAN_LCD_POWER_2_MD);
667 pxa_gpio_mode(GPIO106_MAGICIAN_LCD_POWER_3_MD);
668 set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
670 pr_err("LCD detection: CPLD mapping failed\n");
674 MACHINE_START(MAGICIAN, "HTC Magician")
675 .phys_io = 0x40000000,
676 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
677 .boot_params = 0xa0000100,
678 .map_io = pxa_map_io,
679 .init_irq = pxa27x_init_irq,
680 .init_machine = magician_init,