Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 1 | /* |
| 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. |
| 5 | * |
| 6 | * Copyright (c) 2006-2007 Philipp Zabel |
| 7 | * |
| 8 | * Based on hx4700.c, spitz.c and others. |
| 9 | * |
| 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. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/platform_device.h> |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 19 | #include <linux/delay.h> |
Philipp Zabel | e181191 | 2008-06-22 13:00:55 +0100 | [diff] [blame] | 20 | #include <linux/gpio.h> |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 21 | #include <linux/gpio_keys.h> |
| 22 | #include <linux/input.h> |
Philipp Zabel | 70e357f | 2008-04-09 19:22:57 +0100 | [diff] [blame] | 23 | #include <linux/mfd/htc-egpio.h> |
Philipp Zabel | 81447b2 | 2008-04-12 13:28:02 +0100 | [diff] [blame] | 24 | #include <linux/mfd/htc-pasic3.h> |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 25 | #include <linux/mtd/physmap.h> |
Philipp Zabel | 350d115 | 2008-04-09 19:25:56 +0100 | [diff] [blame] | 26 | #include <linux/pda_power.h> |
Philipp Zabel | 85847a3 | 2008-05-22 14:20:01 +0100 | [diff] [blame] | 27 | #include <linux/pwm_backlight.h> |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 28 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 29 | #include <mach/hardware.h> |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 30 | #include <asm/mach-types.h> |
| 31 | #include <asm/mach/arch.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 32 | #include <mach/magician.h> |
| 33 | #include <mach/mfp-pxa27x.h> |
| 34 | #include <mach/pxa-regs.h> |
| 35 | #include <mach/pxa2xx-regs.h> |
| 36 | #include <mach/pxafb.h> |
| 37 | #include <mach/i2c.h> |
| 38 | #include <mach/mmc.h> |
| 39 | #include <mach/irda.h> |
| 40 | #include <mach/ohci.h> |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 41 | |
Philipp Zabel | 85847a3 | 2008-05-22 14:20:01 +0100 | [diff] [blame] | 42 | #include "devices.h" |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 43 | #include "generic.h" |
| 44 | |
Philipp Zabel | 7a97010 | 2008-06-26 21:03:54 +0100 | [diff] [blame] | 45 | static unsigned long magician_pin_config[] __initdata = { |
Philipp Zabel | b168281 | 2008-04-12 13:29:22 +0100 | [diff] [blame] | 46 | |
| 47 | /* SDRAM and Static Memory I/O Signals */ |
| 48 | GPIO20_nSDCS_2, |
| 49 | GPIO21_nSDCS_3, |
| 50 | GPIO15_nCS_1, |
| 51 | GPIO78_nCS_2, /* PASIC3 */ |
| 52 | GPIO79_nCS_3, /* EGPIO CPLD */ |
| 53 | GPIO80_nCS_4, |
| 54 | GPIO33_nCS_5, |
| 55 | |
| 56 | /* I2C */ |
| 57 | GPIO117_I2C_SCL, |
| 58 | GPIO118_I2C_SDA, |
| 59 | |
| 60 | /* PWM 0 */ |
| 61 | GPIO16_PWM0_OUT, |
| 62 | |
| 63 | /* I2S */ |
| 64 | GPIO28_I2S_BITCLK_OUT, |
| 65 | GPIO29_I2S_SDATA_IN, |
| 66 | GPIO31_I2S_SYNC, |
| 67 | GPIO113_I2S_SYSCLK, |
| 68 | |
Philipp Zabel | 16c3ea4 | 2009-01-17 18:45:41 +0100 | [diff] [blame] | 69 | /* SSP 1 */ |
| 70 | GPIO23_SSP1_SCLK, |
| 71 | GPIO24_SSP1_SFRM, |
| 72 | GPIO25_SSP1_TXD, |
| 73 | |
Philipp Zabel | b168281 | 2008-04-12 13:29:22 +0100 | [diff] [blame] | 74 | /* SSP 2 */ |
| 75 | GPIO19_SSP2_SCLK, |
| 76 | GPIO14_SSP2_SFRM, |
| 77 | GPIO89_SSP2_TXD, |
| 78 | GPIO88_SSP2_RXD, |
| 79 | |
| 80 | /* MMC */ |
| 81 | GPIO32_MMC_CLK, |
| 82 | GPIO92_MMC_DAT_0, |
| 83 | GPIO109_MMC_DAT_1, |
| 84 | GPIO110_MMC_DAT_2, |
| 85 | GPIO111_MMC_DAT_3, |
| 86 | GPIO112_MMC_CMD, |
| 87 | |
| 88 | /* LCD */ |
| 89 | GPIO58_LCD_LDD_0, |
| 90 | GPIO59_LCD_LDD_1, |
| 91 | GPIO60_LCD_LDD_2, |
| 92 | GPIO61_LCD_LDD_3, |
| 93 | GPIO62_LCD_LDD_4, |
| 94 | GPIO63_LCD_LDD_5, |
| 95 | GPIO64_LCD_LDD_6, |
| 96 | GPIO65_LCD_LDD_7, |
| 97 | GPIO66_LCD_LDD_8, |
| 98 | GPIO67_LCD_LDD_9, |
| 99 | GPIO68_LCD_LDD_10, |
| 100 | GPIO69_LCD_LDD_11, |
| 101 | GPIO70_LCD_LDD_12, |
| 102 | GPIO71_LCD_LDD_13, |
| 103 | GPIO72_LCD_LDD_14, |
| 104 | GPIO73_LCD_LDD_15, |
| 105 | GPIO74_LCD_FCLK, |
| 106 | GPIO75_LCD_LCLK, |
| 107 | GPIO76_LCD_PCLK, |
| 108 | GPIO77_LCD_BIAS, |
| 109 | |
| 110 | /* QCI */ |
| 111 | GPIO12_CIF_DD_7, |
| 112 | GPIO17_CIF_DD_6, |
| 113 | GPIO50_CIF_DD_3, |
| 114 | GPIO51_CIF_DD_2, |
| 115 | GPIO52_CIF_DD_4, |
| 116 | GPIO53_CIF_MCLK, |
| 117 | GPIO54_CIF_PCLK, |
| 118 | GPIO55_CIF_DD_1, |
| 119 | GPIO81_CIF_DD_0, |
| 120 | GPIO82_CIF_DD_5, |
| 121 | GPIO84_CIF_FV, |
| 122 | GPIO85_CIF_LV, |
Philipp Zabel | 2f13195 | 2008-04-20 17:40:11 +0100 | [diff] [blame] | 123 | |
| 124 | /* Magician specific input GPIOs */ |
| 125 | GPIO9_GPIO, /* unknown */ |
| 126 | GPIO10_GPIO, /* GSM_IRQ */ |
| 127 | GPIO13_GPIO, /* CPLD_IRQ */ |
| 128 | GPIO107_GPIO, /* DS1WM_IRQ */ |
| 129 | GPIO108_GPIO, /* GSM_READY */ |
| 130 | GPIO115_GPIO, /* nPEN_IRQ */ |
Eric Miao | 6f584cf | 2008-11-28 16:00:24 +0800 | [diff] [blame] | 131 | |
| 132 | /* I2C */ |
| 133 | GPIO117_I2C_SCL, |
| 134 | GPIO118_I2C_SDA, |
Philipp Zabel | b168281 | 2008-04-12 13:29:22 +0100 | [diff] [blame] | 135 | }; |
| 136 | |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 137 | /* |
| 138 | * IRDA |
| 139 | */ |
| 140 | |
| 141 | static void magician_irda_transceiver_mode(struct device *dev, int mode) |
| 142 | { |
| 143 | gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF); |
Dmitry Baryshkov | 0fc3ff3 | 2008-07-02 13:54:46 +0100 | [diff] [blame] | 144 | pxa2xx_transceiver_mode(dev, mode); |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static struct pxaficp_platform_data magician_ficp_info = { |
| 148 | .transceiver_cap = IR_SIRMODE | IR_OFF, |
| 149 | .transceiver_mode = magician_irda_transceiver_mode, |
| 150 | }; |
| 151 | |
| 152 | /* |
| 153 | * GPIO Keys |
| 154 | */ |
| 155 | |
Philipp Zabel | 51c10bb | 2009-01-17 18:45:44 +0100 | [diff] [blame^] | 156 | #define INIT_KEY(_code, _gpio, _desc) \ |
| 157 | { \ |
| 158 | .code = KEY_##_code, \ |
| 159 | .gpio = _gpio, \ |
| 160 | .desc = _desc, \ |
| 161 | .type = EV_KEY, \ |
| 162 | .wakeup = 1, \ |
| 163 | } |
| 164 | |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 165 | static struct gpio_keys_button magician_button_table[] = { |
Philipp Zabel | 51c10bb | 2009-01-17 18:45:44 +0100 | [diff] [blame^] | 166 | INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"), |
| 167 | INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"), |
| 168 | INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"), |
| 169 | INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"), |
| 170 | INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"), |
| 171 | INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"), |
| 172 | INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"), |
| 173 | INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"), |
| 174 | INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"), |
| 175 | INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"), |
| 176 | INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"), |
| 177 | INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"), |
| 178 | INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"), |
| 179 | INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"), |
| 180 | INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"), |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | static struct gpio_keys_platform_data gpio_keys_data = { |
| 184 | .buttons = magician_button_table, |
| 185 | .nbuttons = ARRAY_SIZE(magician_button_table), |
| 186 | }; |
| 187 | |
| 188 | static struct platform_device gpio_keys = { |
| 189 | .name = "gpio-keys", |
| 190 | .dev = { |
| 191 | .platform_data = &gpio_keys_data, |
| 192 | }, |
| 193 | .id = -1, |
| 194 | }; |
| 195 | |
Philipp Zabel | 70e357f | 2008-04-09 19:22:57 +0100 | [diff] [blame] | 196 | |
| 197 | /* |
| 198 | * EGPIO (Xilinx CPLD) |
| 199 | * |
| 200 | * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input |
| 201 | */ |
| 202 | |
| 203 | static struct resource egpio_resources[] = { |
| 204 | [0] = { |
| 205 | .start = PXA_CS3_PHYS, |
| 206 | .end = PXA_CS3_PHYS + 0x20, |
| 207 | .flags = IORESOURCE_MEM, |
| 208 | }, |
| 209 | [1] = { |
| 210 | .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ), |
| 211 | .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ), |
| 212 | .flags = IORESOURCE_IRQ, |
| 213 | }, |
| 214 | }; |
| 215 | |
| 216 | static struct htc_egpio_chip egpio_chips[] = { |
| 217 | [0] = { |
| 218 | .reg_start = 0, |
| 219 | .gpio_base = MAGICIAN_EGPIO(0, 0), |
| 220 | .num_gpios = 24, |
| 221 | .direction = HTC_EGPIO_OUTPUT, |
| 222 | .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */ |
| 223 | }, |
| 224 | [1] = { |
| 225 | .reg_start = 4, |
| 226 | .gpio_base = MAGICIAN_EGPIO(4, 0), |
| 227 | .num_gpios = 24, |
| 228 | .direction = HTC_EGPIO_INPUT, |
| 229 | }, |
| 230 | }; |
| 231 | |
| 232 | static struct htc_egpio_platform_data egpio_info = { |
| 233 | .reg_width = 8, |
| 234 | .bus_width = 32, |
| 235 | .irq_base = IRQ_BOARD_START, |
| 236 | .num_irqs = 4, |
| 237 | .ack_register = 3, |
| 238 | .chip = egpio_chips, |
| 239 | .num_chips = ARRAY_SIZE(egpio_chips), |
| 240 | }; |
| 241 | |
| 242 | static struct platform_device egpio = { |
| 243 | .name = "htc-egpio", |
| 244 | .id = -1, |
| 245 | .resource = egpio_resources, |
| 246 | .num_resources = ARRAY_SIZE(egpio_resources), |
| 247 | .dev = { |
| 248 | .platform_data = &egpio_info, |
| 249 | }, |
| 250 | }; |
| 251 | |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 252 | /* |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 253 | * LCD - Toppoly TD028STEB1 or Samsung LTP280QV |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 254 | */ |
| 255 | |
| 256 | static struct pxafb_mode_info toppoly_modes[] = { |
| 257 | { |
| 258 | .pixclock = 96153, |
| 259 | .bpp = 16, |
| 260 | .xres = 240, |
| 261 | .yres = 320, |
| 262 | .hsync_len = 11, |
| 263 | .vsync_len = 3, |
| 264 | .left_margin = 19, |
| 265 | .upper_margin = 2, |
| 266 | .right_margin = 10, |
| 267 | .lower_margin = 2, |
| 268 | .sync = 0, |
| 269 | }, |
| 270 | }; |
| 271 | |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 272 | static struct pxafb_mode_info samsung_modes[] = { |
| 273 | { |
| 274 | .pixclock = 96153, |
| 275 | .bpp = 16, |
| 276 | .xres = 240, |
| 277 | .yres = 320, |
| 278 | .hsync_len = 8, |
| 279 | .vsync_len = 4, |
| 280 | .left_margin = 9, |
| 281 | .upper_margin = 4, |
| 282 | .right_margin = 9, |
| 283 | .lower_margin = 4, |
| 284 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 285 | }, |
| 286 | }; |
| 287 | |
| 288 | static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si) |
| 289 | { |
| 290 | pr_debug("Toppoly LCD power\n"); |
| 291 | |
| 292 | if (on) { |
| 293 | pr_debug("on\n"); |
| 294 | gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1); |
| 295 | gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1); |
| 296 | udelay(2000); |
| 297 | gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1); |
| 298 | udelay(2000); |
| 299 | /* FIXME: enable LCDC here */ |
| 300 | udelay(2000); |
| 301 | gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1); |
| 302 | udelay(2000); |
| 303 | gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1); |
| 304 | } else { |
| 305 | pr_debug("off\n"); |
| 306 | msleep(15); |
| 307 | gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0); |
| 308 | udelay(500); |
| 309 | gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0); |
| 310 | udelay(1000); |
| 311 | gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0); |
| 312 | gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | static void samsung_lcd_power(int on, struct fb_var_screeninfo *si) |
| 317 | { |
| 318 | pr_debug("Samsung LCD power\n"); |
| 319 | |
| 320 | if (on) { |
| 321 | pr_debug("on\n"); |
| 322 | if (system_rev < 3) |
| 323 | gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1); |
| 324 | else |
| 325 | gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1); |
| 326 | mdelay(10); |
| 327 | gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1); |
| 328 | mdelay(10); |
| 329 | gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1); |
| 330 | mdelay(30); |
| 331 | gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1); |
| 332 | mdelay(10); |
| 333 | } else { |
| 334 | pr_debug("off\n"); |
| 335 | mdelay(10); |
| 336 | gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0); |
| 337 | mdelay(30); |
| 338 | gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0); |
| 339 | mdelay(10); |
| 340 | gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0); |
| 341 | mdelay(10); |
| 342 | if (system_rev < 3) |
| 343 | gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0); |
| 344 | else |
| 345 | gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0); |
| 346 | } |
| 347 | } |
| 348 | |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 349 | static struct pxafb_mach_info toppoly_info = { |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 350 | .modes = toppoly_modes, |
| 351 | .num_modes = 1, |
| 352 | .fixed_modes = 1, |
Eric Miao | 9587319 | 2008-12-07 17:49:01 +0800 | [diff] [blame] | 353 | .lcd_conn = LCD_COLOR_TFT_16BPP, |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 354 | .pxafb_lcd_power = toppoly_lcd_power, |
| 355 | }; |
| 356 | |
| 357 | static struct pxafb_mach_info samsung_info = { |
| 358 | .modes = samsung_modes, |
| 359 | .num_modes = 1, |
| 360 | .fixed_modes = 1, |
Eric Miao | 9587319 | 2008-12-07 17:49:01 +0800 | [diff] [blame] | 361 | .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |\ |
| 362 | LCD_ALTERNATE_MAPPING, |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 363 | .pxafb_lcd_power = samsung_lcd_power, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 364 | }; |
| 365 | |
| 366 | /* |
| 367 | * Backlight |
| 368 | */ |
| 369 | |
Philipp Zabel | 85847a3 | 2008-05-22 14:20:01 +0100 | [diff] [blame] | 370 | static int magician_backlight_init(struct device *dev) |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 371 | { |
Philipp Zabel | 85847a3 | 2008-05-22 14:20:01 +0100 | [diff] [blame] | 372 | int ret; |
| 373 | |
| 374 | ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER"); |
| 375 | if (ret) |
| 376 | goto err; |
| 377 | ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2"); |
| 378 | if (ret) |
| 379 | goto err2; |
| 380 | return 0; |
| 381 | |
| 382 | err2: |
| 383 | gpio_free(EGPIO_MAGICIAN_BL_POWER); |
| 384 | err: |
| 385 | return ret; |
| 386 | } |
| 387 | |
| 388 | static int magician_backlight_notify(int brightness) |
| 389 | { |
| 390 | gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness); |
| 391 | if (brightness >= 200) { |
| 392 | gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1); |
| 393 | return brightness - 72; |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 394 | } else { |
Philipp Zabel | 85847a3 | 2008-05-22 14:20:01 +0100 | [diff] [blame] | 395 | gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0); |
| 396 | return brightness; |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
Philipp Zabel | 85847a3 | 2008-05-22 14:20:01 +0100 | [diff] [blame] | 400 | static void magician_backlight_exit(struct device *dev) |
| 401 | { |
| 402 | gpio_free(EGPIO_MAGICIAN_BL_POWER); |
| 403 | gpio_free(EGPIO_MAGICIAN_BL_POWER2); |
| 404 | } |
| 405 | |
| 406 | static struct platform_pwm_backlight_data backlight_data = { |
| 407 | .pwm_id = 0, |
| 408 | .max_brightness = 272, |
| 409 | .dft_brightness = 100, |
| 410 | .pwm_period_ns = 30923, |
| 411 | .init = magician_backlight_init, |
| 412 | .notify = magician_backlight_notify, |
| 413 | .exit = magician_backlight_exit, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 414 | }; |
| 415 | |
| 416 | static struct platform_device backlight = { |
Philipp Zabel | 85847a3 | 2008-05-22 14:20:01 +0100 | [diff] [blame] | 417 | .name = "pwm-backlight", |
Philipp Zabel | 14d1012 | 2008-06-30 18:11:55 +0100 | [diff] [blame] | 418 | .id = -1, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 419 | .dev = { |
Philipp Zabel | 85847a3 | 2008-05-22 14:20:01 +0100 | [diff] [blame] | 420 | .parent = &pxa27x_device_pwm0.dev, |
| 421 | .platform_data = &backlight_data, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 422 | }, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 423 | }; |
| 424 | |
Philipp Zabel | 81447b2 | 2008-04-12 13:28:02 +0100 | [diff] [blame] | 425 | /* |
| 426 | * LEDs |
| 427 | */ |
| 428 | |
Russell King | a55faca | 2008-09-25 14:35:48 +0100 | [diff] [blame] | 429 | static struct gpio_led gpio_leds[] = { |
Philipp Zabel | 81447b2 | 2008-04-12 13:28:02 +0100 | [diff] [blame] | 430 | { |
| 431 | .name = "magician::vibra", |
| 432 | .default_trigger = "none", |
| 433 | .gpio = GPIO22_MAGICIAN_VIBRA_EN, |
| 434 | }, |
| 435 | { |
| 436 | .name = "magician::phone_bl", |
| 437 | .default_trigger = "none", |
| 438 | .gpio = GPIO103_MAGICIAN_LED_KP, |
| 439 | }, |
| 440 | }; |
| 441 | |
| 442 | static struct gpio_led_platform_data gpio_led_info = { |
| 443 | .leds = gpio_leds, |
| 444 | .num_leds = ARRAY_SIZE(gpio_leds), |
| 445 | }; |
| 446 | |
| 447 | static struct platform_device leds_gpio = { |
| 448 | .name = "leds-gpio", |
| 449 | .id = -1, |
| 450 | .dev = { |
| 451 | .platform_data = &gpio_led_info, |
| 452 | }, |
| 453 | }; |
| 454 | |
| 455 | static struct pasic3_led pasic3_leds[] = { |
| 456 | { |
| 457 | .led = { |
| 458 | .name = "magician:red", |
| 459 | .default_trigger = "ds2760-battery.0-charging", |
| 460 | }, |
| 461 | .hw_num = 0, |
| 462 | .bit2 = PASIC3_BIT2_LED0, |
| 463 | .mask = PASIC3_MASK_LED0, |
| 464 | }, |
| 465 | { |
| 466 | .led = { |
| 467 | .name = "magician:green", |
| 468 | .default_trigger = "ds2760-battery.0-charging-or-full", |
| 469 | }, |
| 470 | .hw_num = 1, |
| 471 | .bit2 = PASIC3_BIT2_LED1, |
| 472 | .mask = PASIC3_MASK_LED1, |
| 473 | }, |
| 474 | { |
| 475 | .led = { |
| 476 | .name = "magician:blue", |
| 477 | .default_trigger = "bluetooth", |
| 478 | }, |
| 479 | .hw_num = 2, |
| 480 | .bit2 = PASIC3_BIT2_LED2, |
| 481 | .mask = PASIC3_MASK_LED2, |
| 482 | }, |
| 483 | }; |
| 484 | |
| 485 | static struct platform_device pasic3; |
| 486 | |
Philipp Zabel | e03e059 | 2008-04-24 18:10:46 +0100 | [diff] [blame] | 487 | static struct pasic3_leds_machinfo pasic3_leds_info = { |
Philipp Zabel | 81447b2 | 2008-04-12 13:28:02 +0100 | [diff] [blame] | 488 | .num_leds = ARRAY_SIZE(pasic3_leds), |
| 489 | .power_gpio = EGPIO_MAGICIAN_LED_POWER, |
| 490 | .leds = pasic3_leds, |
| 491 | }; |
| 492 | |
| 493 | /* |
| 494 | * PASIC3 with DS1WM |
| 495 | */ |
| 496 | |
| 497 | static struct resource pasic3_resources[] = { |
| 498 | [0] = { |
| 499 | .start = PXA_CS2_PHYS, |
| 500 | .end = PXA_CS2_PHYS + 0x1b, |
| 501 | .flags = IORESOURCE_MEM, |
| 502 | }, |
| 503 | /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */ |
| 504 | [1] = { |
| 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, |
| 508 | } |
| 509 | }; |
| 510 | |
| 511 | static struct pasic3_platform_data pasic3_platform_data = { |
| 512 | .bus_shift = 2, |
| 513 | .led_pdata = &pasic3_leds_info, |
| 514 | .clock_rate = 4000000, |
| 515 | }; |
| 516 | |
| 517 | static struct platform_device pasic3 = { |
| 518 | .name = "pasic3", |
| 519 | .id = -1, |
| 520 | .num_resources = ARRAY_SIZE(pasic3_resources), |
| 521 | .resource = pasic3_resources, |
| 522 | .dev = { |
| 523 | .platform_data = &pasic3_platform_data, |
| 524 | }, |
| 525 | }; |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 526 | |
| 527 | /* |
Philipp Zabel | 350d115 | 2008-04-09 19:25:56 +0100 | [diff] [blame] | 528 | * External power |
| 529 | */ |
| 530 | |
Philipp Zabel | ff27920 | 2008-05-22 10:14:21 +0100 | [diff] [blame] | 531 | static int power_supply_init(struct device *dev) |
| 532 | { |
| 533 | int ret; |
| 534 | |
| 535 | ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC"); |
| 536 | if (ret) |
| 537 | goto err_cs_ac; |
| 538 | ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB, "CABLE_STATE_USB"); |
| 539 | if (ret) |
| 540 | goto err_cs_usb; |
| 541 | ret = gpio_request(EGPIO_MAGICIAN_CHARGE_EN, "CHARGE_EN"); |
| 542 | if (ret) |
| 543 | goto err_chg_en; |
| 544 | ret = gpio_request(GPIO30_MAGICIAN_nCHARGE_EN, "nCHARGE_EN"); |
| 545 | if (!ret) |
| 546 | ret = gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN, 0); |
| 547 | if (ret) |
| 548 | goto err_nchg_en; |
| 549 | |
| 550 | return 0; |
| 551 | |
| 552 | err_nchg_en: |
| 553 | gpio_free(EGPIO_MAGICIAN_CHARGE_EN); |
| 554 | err_chg_en: |
| 555 | gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB); |
| 556 | err_cs_usb: |
| 557 | gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC); |
| 558 | err_cs_ac: |
| 559 | return ret; |
| 560 | } |
| 561 | |
Philipp Zabel | 350d115 | 2008-04-09 19:25:56 +0100 | [diff] [blame] | 562 | static int magician_is_ac_online(void) |
| 563 | { |
| 564 | return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC); |
| 565 | } |
| 566 | |
| 567 | static int magician_is_usb_online(void) |
| 568 | { |
| 569 | return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB); |
| 570 | } |
| 571 | |
| 572 | static void magician_set_charge(int flags) |
| 573 | { |
| 574 | gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags); |
| 575 | gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags); |
| 576 | } |
| 577 | |
Philipp Zabel | ff27920 | 2008-05-22 10:14:21 +0100 | [diff] [blame] | 578 | static void power_supply_exit(struct device *dev) |
| 579 | { |
| 580 | gpio_free(GPIO30_MAGICIAN_nCHARGE_EN); |
| 581 | gpio_free(EGPIO_MAGICIAN_CHARGE_EN); |
| 582 | gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB); |
| 583 | gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC); |
| 584 | } |
| 585 | |
Philipp Zabel | 81447b2 | 2008-04-12 13:28:02 +0100 | [diff] [blame] | 586 | static char *magician_supplicants[] = { |
| 587 | "ds2760-battery.0", "backup-battery" |
| 588 | }; |
| 589 | |
Philipp Zabel | 350d115 | 2008-04-09 19:25:56 +0100 | [diff] [blame] | 590 | static struct pda_power_pdata power_supply_info = { |
Philipp Zabel | ff27920 | 2008-05-22 10:14:21 +0100 | [diff] [blame] | 591 | .init = power_supply_init, |
Philipp Zabel | 81447b2 | 2008-04-12 13:28:02 +0100 | [diff] [blame] | 592 | .is_ac_online = magician_is_ac_online, |
| 593 | .is_usb_online = magician_is_usb_online, |
| 594 | .set_charge = magician_set_charge, |
Philipp Zabel | ff27920 | 2008-05-22 10:14:21 +0100 | [diff] [blame] | 595 | .exit = power_supply_exit, |
Philipp Zabel | 81447b2 | 2008-04-12 13:28:02 +0100 | [diff] [blame] | 596 | .supplied_to = magician_supplicants, |
| 597 | .num_supplicants = ARRAY_SIZE(magician_supplicants), |
Philipp Zabel | 350d115 | 2008-04-09 19:25:56 +0100 | [diff] [blame] | 598 | }; |
| 599 | |
| 600 | static struct resource power_supply_resources[] = { |
| 601 | [0] = { |
| 602 | .name = "ac", |
| 603 | .flags = IORESOURCE_IRQ, |
| 604 | .start = IRQ_MAGICIAN_AC, |
| 605 | .end = IRQ_MAGICIAN_AC, |
| 606 | }, |
| 607 | [1] = { |
| 608 | .name = "usb", |
| 609 | .flags = IORESOURCE_IRQ, |
| 610 | .start = IRQ_MAGICIAN_AC, |
| 611 | .end = IRQ_MAGICIAN_AC, |
| 612 | }, |
| 613 | }; |
| 614 | |
| 615 | static struct platform_device power_supply = { |
| 616 | .name = "pda-power", |
| 617 | .id = -1, |
| 618 | .dev = { |
| 619 | .platform_data = &power_supply_info, |
| 620 | }, |
| 621 | .resource = power_supply_resources, |
| 622 | .num_resources = ARRAY_SIZE(power_supply_resources), |
| 623 | }; |
| 624 | |
| 625 | |
| 626 | /* |
Philipp Zabel | bdb0c16 | 2008-04-09 19:24:55 +0100 | [diff] [blame] | 627 | * MMC/SD |
| 628 | */ |
| 629 | |
| 630 | static int magician_mci_init(struct device *dev, |
| 631 | irq_handler_t detect_irq, void *data) |
| 632 | { |
Philipp Zabel | a1999cd | 2008-04-20 17:39:12 +0100 | [diff] [blame] | 633 | int err; |
| 634 | |
| 635 | err = request_irq(IRQ_MAGICIAN_SD, detect_irq, |
Philipp Zabel | bdb0c16 | 2008-04-09 19:24:55 +0100 | [diff] [blame] | 636 | IRQF_DISABLED | IRQF_SAMPLE_RANDOM, |
| 637 | "MMC card detect", data); |
Philipp Zabel | a1999cd | 2008-04-20 17:39:12 +0100 | [diff] [blame] | 638 | if (err) |
| 639 | goto err_request_irq; |
| 640 | err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER"); |
| 641 | if (err) |
| 642 | goto err_request_power; |
| 643 | err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY"); |
| 644 | if (err) |
| 645 | goto err_request_readonly; |
| 646 | |
| 647 | return 0; |
| 648 | |
| 649 | err_request_readonly: |
| 650 | gpio_free(EGPIO_MAGICIAN_SD_POWER); |
| 651 | err_request_power: |
| 652 | free_irq(IRQ_MAGICIAN_SD, data); |
| 653 | err_request_irq: |
| 654 | return err; |
Philipp Zabel | bdb0c16 | 2008-04-09 19:24:55 +0100 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | static void magician_mci_setpower(struct device *dev, unsigned int vdd) |
| 658 | { |
| 659 | struct pxamci_platform_data *pdata = dev->platform_data; |
| 660 | |
| 661 | gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask); |
| 662 | } |
| 663 | |
| 664 | static int magician_mci_get_ro(struct device *dev) |
| 665 | { |
| 666 | return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY)); |
| 667 | } |
| 668 | |
| 669 | static void magician_mci_exit(struct device *dev, void *data) |
| 670 | { |
Philipp Zabel | a1999cd | 2008-04-20 17:39:12 +0100 | [diff] [blame] | 671 | gpio_free(EGPIO_MAGICIAN_nSD_READONLY); |
| 672 | gpio_free(EGPIO_MAGICIAN_SD_POWER); |
Philipp Zabel | bdb0c16 | 2008-04-09 19:24:55 +0100 | [diff] [blame] | 673 | free_irq(IRQ_MAGICIAN_SD, data); |
| 674 | } |
| 675 | |
| 676 | static struct pxamci_platform_data magician_mci_info = { |
| 677 | .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, |
| 678 | .init = magician_mci_init, |
| 679 | .get_ro = magician_mci_get_ro, |
| 680 | .setpower = magician_mci_setpower, |
| 681 | .exit = magician_mci_exit, |
| 682 | }; |
| 683 | |
| 684 | |
| 685 | /* |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 686 | * USB OHCI |
| 687 | */ |
| 688 | |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 689 | static struct pxaohci_platform_data magician_ohci_info = { |
Eric Miao | 097b533 | 2008-09-27 15:49:57 +0800 | [diff] [blame] | 690 | .port_mode = PMM_PERPORT_MODE, |
| 691 | .flags = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW, |
| 692 | .power_budget = 0, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 693 | }; |
| 694 | |
| 695 | |
| 696 | /* |
| 697 | * StrataFlash |
| 698 | */ |
| 699 | |
Philipp Zabel | aa79759 | 2008-04-09 19:24:05 +0100 | [diff] [blame] | 700 | static void magician_set_vpp(struct map_info *map, int vpp) |
| 701 | { |
| 702 | gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp); |
| 703 | } |
| 704 | |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 705 | static struct resource strataflash_resource = { |
| 706 | .start = PXA_CS0_PHYS, |
Philipp Zabel | fcb78d1 | 2009-01-17 18:45:43 +0100 | [diff] [blame] | 707 | .end = PXA_CS0_PHYS + SZ_64M - 1, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 708 | .flags = IORESOURCE_MEM, |
| 709 | }; |
| 710 | |
| 711 | static struct physmap_flash_data strataflash_data = { |
| 712 | .width = 4, |
Philipp Zabel | aa79759 | 2008-04-09 19:24:05 +0100 | [diff] [blame] | 713 | .set_vpp = magician_set_vpp, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 714 | }; |
| 715 | |
| 716 | static struct platform_device strataflash = { |
| 717 | .name = "physmap-flash", |
| 718 | .id = -1, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 719 | .resource = &strataflash_resource, |
Philipp Zabel | 70e357f | 2008-04-09 19:22:57 +0100 | [diff] [blame] | 720 | .num_resources = 1, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 721 | .dev = { |
| 722 | .platform_data = &strataflash_data, |
| 723 | }, |
| 724 | }; |
| 725 | |
| 726 | /* |
| 727 | * Platform devices |
| 728 | */ |
| 729 | |
| 730 | static struct platform_device *devices[] __initdata = { |
| 731 | &gpio_keys, |
Philipp Zabel | 70e357f | 2008-04-09 19:22:57 +0100 | [diff] [blame] | 732 | &egpio, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 733 | &backlight, |
Philipp Zabel | 81447b2 | 2008-04-12 13:28:02 +0100 | [diff] [blame] | 734 | &pasic3, |
Philipp Zabel | 350d115 | 2008-04-09 19:25:56 +0100 | [diff] [blame] | 735 | &power_supply, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 736 | &strataflash, |
Philipp Zabel | 81447b2 | 2008-04-12 13:28:02 +0100 | [diff] [blame] | 737 | &leds_gpio, |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 738 | }; |
| 739 | |
| 740 | static void __init magician_init(void) |
| 741 | { |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 742 | void __iomem *cpld; |
| 743 | int lcd_select; |
Philipp Zabel | a1999cd | 2008-04-20 17:39:12 +0100 | [diff] [blame] | 744 | int err; |
| 745 | |
| 746 | gpio_request(GPIO13_MAGICIAN_CPLD_IRQ, "CPLD_IRQ"); |
| 747 | gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ, "DS1WM_IRQ"); |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 748 | |
Philipp Zabel | b168281 | 2008-04-12 13:29:22 +0100 | [diff] [blame] | 749 | pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config)); |
| 750 | |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 751 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
Philipp Zabel | a1999cd | 2008-04-20 17:39:12 +0100 | [diff] [blame] | 752 | |
| 753 | err = gpio_request(GPIO83_MAGICIAN_nIR_EN, "nIR_EN"); |
| 754 | if (!err) { |
| 755 | gpio_direction_output(GPIO83_MAGICIAN_nIR_EN, 1); |
| 756 | pxa_set_ficp_info(&magician_ficp_info); |
| 757 | } |
Philipp Zabel | dee6316 | 2009-01-17 18:45:42 +0100 | [diff] [blame] | 758 | pxa27x_set_i2c_power_info(NULL); |
Philipp Zabel | e6816f3 | 2008-04-09 19:14:15 +0100 | [diff] [blame] | 759 | pxa_set_i2c_info(NULL); |
Philipp Zabel | bdb0c16 | 2008-04-09 19:24:55 +0100 | [diff] [blame] | 760 | pxa_set_mci_info(&magician_mci_info); |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 761 | pxa_set_ohci_info(&magician_ohci_info); |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 762 | |
| 763 | /* Check LCD type we have */ |
| 764 | cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000); |
| 765 | if (cpld) { |
| 766 | u8 board_id = __raw_readb(cpld+0x14); |
Philipp Zabel | a1999cd | 2008-04-20 17:39:12 +0100 | [diff] [blame] | 767 | iounmap(cpld); |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 768 | system_rev = board_id & 0x7; |
| 769 | lcd_select = board_id & 0x8; |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 770 | pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly"); |
Philipp Zabel | a1999cd | 2008-04-20 17:39:12 +0100 | [diff] [blame] | 771 | if (lcd_select && (system_rev < 3)) { |
| 772 | gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER"); |
| 773 | gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0); |
| 774 | } |
| 775 | gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1"); |
| 776 | gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2"); |
| 777 | gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3"); |
| 778 | gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0); |
| 779 | gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0); |
| 780 | gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0); |
Philipp Zabel | e07ff8d | 2008-04-09 19:27:10 +0100 | [diff] [blame] | 781 | set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info); |
| 782 | } else |
| 783 | pr_err("LCD detection: CPLD mapping failed\n"); |
Philipp Zabel | e5c271e | 2007-11-22 17:59:11 +0100 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | |
| 787 | MACHINE_START(MAGICIAN, "HTC Magician") |
| 788 | .phys_io = 0x40000000, |
| 789 | .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc, |
| 790 | .boot_params = 0xa0000100, |
| 791 | .map_io = pxa_map_io, |
| 792 | .init_irq = pxa27x_init_irq, |
| 793 | .init_machine = magician_init, |
| 794 | .timer = &pxa_timer, |
| 795 | MACHINE_END |