blob: 9ca16ec48f64b368787cff46e703ffc646ee8a95 [file] [log] [blame]
Philipp Zabele5c271e2007-11-22 17:59:11 +01001/*
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 Zabele07ff8d82008-04-09 19:27:10 +010019#include <linux/delay.h>
Philipp Zabele1811912008-06-22 13:00:55 +010020#include <linux/gpio.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010021#include <linux/gpio_keys.h>
22#include <linux/input.h>
Philipp Zabel70e357f2008-04-09 19:22:57 +010023#include <linux/mfd/htc-egpio.h>
Philipp Zabel81447b22008-04-12 13:28:02 +010024#include <linux/mfd/htc-pasic3.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010025#include <linux/mtd/physmap.h>
Philipp Zabel350d1152008-04-09 19:25:56 +010026#include <linux/pda_power.h>
Philipp Zabel85847a32008-05-22 14:20:01 +010027#include <linux/pwm_backlight.h>
Philipp Zabel6489c612009-02-01 11:20:30 +010028#include <linux/usb/gpio_vbus.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010029
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/hardware.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010031#include <asm/mach-types.h>
32#include <asm/mach/arch.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010033#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>
38#include <mach/i2c.h>
39#include <mach/mmc.h>
40#include <mach/irda.h>
41#include <mach/ohci.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010042
Philipp Zabel85847a32008-05-22 14:20:01 +010043#include "devices.h"
Philipp Zabele5c271e2007-11-22 17:59:11 +010044#include "generic.h"
45
Philipp Zabel7a970102008-06-26 21:03:54 +010046static unsigned long magician_pin_config[] __initdata = {
Philipp Zabelb1682812008-04-12 13:29:22 +010047
48 /* SDRAM and Static Memory I/O Signals */
49 GPIO20_nSDCS_2,
50 GPIO21_nSDCS_3,
51 GPIO15_nCS_1,
52 GPIO78_nCS_2, /* PASIC3 */
53 GPIO79_nCS_3, /* EGPIO CPLD */
54 GPIO80_nCS_4,
55 GPIO33_nCS_5,
56
57 /* I2C */
58 GPIO117_I2C_SCL,
59 GPIO118_I2C_SDA,
60
61 /* PWM 0 */
62 GPIO16_PWM0_OUT,
63
64 /* I2S */
65 GPIO28_I2S_BITCLK_OUT,
66 GPIO29_I2S_SDATA_IN,
67 GPIO31_I2S_SYNC,
68 GPIO113_I2S_SYSCLK,
69
Philipp Zabel16c3ea42009-01-17 18:45:41 +010070 /* SSP 1 */
71 GPIO23_SSP1_SCLK,
72 GPIO24_SSP1_SFRM,
73 GPIO25_SSP1_TXD,
74
Philipp Zabelb1682812008-04-12 13:29:22 +010075 /* SSP 2 */
76 GPIO19_SSP2_SCLK,
77 GPIO14_SSP2_SFRM,
78 GPIO89_SSP2_TXD,
79 GPIO88_SSP2_RXD,
80
81 /* MMC */
82 GPIO32_MMC_CLK,
83 GPIO92_MMC_DAT_0,
84 GPIO109_MMC_DAT_1,
85 GPIO110_MMC_DAT_2,
86 GPIO111_MMC_DAT_3,
87 GPIO112_MMC_CMD,
88
89 /* LCD */
90 GPIO58_LCD_LDD_0,
91 GPIO59_LCD_LDD_1,
92 GPIO60_LCD_LDD_2,
93 GPIO61_LCD_LDD_3,
94 GPIO62_LCD_LDD_4,
95 GPIO63_LCD_LDD_5,
96 GPIO64_LCD_LDD_6,
97 GPIO65_LCD_LDD_7,
98 GPIO66_LCD_LDD_8,
99 GPIO67_LCD_LDD_9,
100 GPIO68_LCD_LDD_10,
101 GPIO69_LCD_LDD_11,
102 GPIO70_LCD_LDD_12,
103 GPIO71_LCD_LDD_13,
104 GPIO72_LCD_LDD_14,
105 GPIO73_LCD_LDD_15,
106 GPIO74_LCD_FCLK,
107 GPIO75_LCD_LCLK,
108 GPIO76_LCD_PCLK,
109 GPIO77_LCD_BIAS,
110
111 /* QCI */
112 GPIO12_CIF_DD_7,
113 GPIO17_CIF_DD_6,
114 GPIO50_CIF_DD_3,
115 GPIO51_CIF_DD_2,
116 GPIO52_CIF_DD_4,
117 GPIO53_CIF_MCLK,
118 GPIO54_CIF_PCLK,
119 GPIO55_CIF_DD_1,
120 GPIO81_CIF_DD_0,
121 GPIO82_CIF_DD_5,
122 GPIO84_CIF_FV,
123 GPIO85_CIF_LV,
Philipp Zabel2f131952008-04-20 17:40:11 +0100124
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 */
Eric Miao6f584cf2008-11-28 16:00:24 +0800132
133 /* I2C */
134 GPIO117_I2C_SCL,
135 GPIO118_I2C_SDA,
Philipp Zabelb1682812008-04-12 13:29:22 +0100136};
137
Philipp Zabele5c271e2007-11-22 17:59:11 +0100138/*
139 * IRDA
140 */
141
142static void magician_irda_transceiver_mode(struct device *dev, int mode)
143{
144 gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
Dmitry Baryshkov0fc3ff32008-07-02 13:54:46 +0100145 pxa2xx_transceiver_mode(dev, mode);
Philipp Zabele5c271e2007-11-22 17:59:11 +0100146}
147
148static struct pxaficp_platform_data magician_ficp_info = {
149 .transceiver_cap = IR_SIRMODE | IR_OFF,
150 .transceiver_mode = magician_irda_transceiver_mode,
151};
152
153/*
154 * GPIO Keys
155 */
156
Philipp Zabel51c10bb2009-01-17 18:45:44 +0100157#define INIT_KEY(_code, _gpio, _desc) \
158 { \
159 .code = KEY_##_code, \
160 .gpio = _gpio, \
161 .desc = _desc, \
162 .type = EV_KEY, \
163 .wakeup = 1, \
164 }
165
Philipp Zabele5c271e2007-11-22 17:59:11 +0100166static struct gpio_keys_button magician_button_table[] = {
Philipp Zabel51c10bb2009-01-17 18:45:44 +0100167 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"),
Philipp Zabele5c271e2007-11-22 17:59:11 +0100182};
183
184static struct gpio_keys_platform_data gpio_keys_data = {
185 .buttons = magician_button_table,
186 .nbuttons = ARRAY_SIZE(magician_button_table),
187};
188
189static struct platform_device gpio_keys = {
190 .name = "gpio-keys",
191 .dev = {
192 .platform_data = &gpio_keys_data,
193 },
194 .id = -1,
195};
196
Philipp Zabel70e357f2008-04-09 19:22:57 +0100197
198/*
199 * EGPIO (Xilinx CPLD)
200 *
201 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
202 */
203
204static struct resource egpio_resources[] = {
205 [0] = {
206 .start = PXA_CS3_PHYS,
Philipp Zabel23804612009-02-09 17:34:05 +0100207 .end = PXA_CS3_PHYS + 0x20 - 1,
Philipp Zabel70e357f2008-04-09 19:22:57 +0100208 .flags = IORESOURCE_MEM,
209 },
210 [1] = {
211 .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
212 .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
213 .flags = IORESOURCE_IRQ,
214 },
215};
216
217static struct htc_egpio_chip egpio_chips[] = {
218 [0] = {
219 .reg_start = 0,
220 .gpio_base = MAGICIAN_EGPIO(0, 0),
221 .num_gpios = 24,
222 .direction = HTC_EGPIO_OUTPUT,
223 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
224 },
225 [1] = {
226 .reg_start = 4,
227 .gpio_base = MAGICIAN_EGPIO(4, 0),
228 .num_gpios = 24,
229 .direction = HTC_EGPIO_INPUT,
230 },
231};
232
233static struct htc_egpio_platform_data egpio_info = {
234 .reg_width = 8,
235 .bus_width = 32,
236 .irq_base = IRQ_BOARD_START,
237 .num_irqs = 4,
238 .ack_register = 3,
239 .chip = egpio_chips,
240 .num_chips = ARRAY_SIZE(egpio_chips),
241};
242
243static struct platform_device egpio = {
244 .name = "htc-egpio",
245 .id = -1,
246 .resource = egpio_resources,
247 .num_resources = ARRAY_SIZE(egpio_resources),
248 .dev = {
249 .platform_data = &egpio_info,
250 },
251};
252
Philipp Zabele5c271e2007-11-22 17:59:11 +0100253/*
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100254 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
Philipp Zabele5c271e2007-11-22 17:59:11 +0100255 */
256
257static struct pxafb_mode_info toppoly_modes[] = {
258 {
259 .pixclock = 96153,
260 .bpp = 16,
261 .xres = 240,
262 .yres = 320,
263 .hsync_len = 11,
264 .vsync_len = 3,
265 .left_margin = 19,
266 .upper_margin = 2,
267 .right_margin = 10,
268 .lower_margin = 2,
269 .sync = 0,
270 },
271};
272
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100273static struct pxafb_mode_info samsung_modes[] = {
274 {
275 .pixclock = 96153,
276 .bpp = 16,
277 .xres = 240,
278 .yres = 320,
279 .hsync_len = 8,
280 .vsync_len = 4,
281 .left_margin = 9,
282 .upper_margin = 4,
283 .right_margin = 9,
284 .lower_margin = 4,
285 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
286 },
287};
288
289static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
290{
291 pr_debug("Toppoly LCD power\n");
292
293 if (on) {
294 pr_debug("on\n");
295 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
296 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
297 udelay(2000);
298 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
299 udelay(2000);
300 /* FIXME: enable LCDC here */
301 udelay(2000);
302 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
303 udelay(2000);
304 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
305 } else {
306 pr_debug("off\n");
307 msleep(15);
308 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
309 udelay(500);
310 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
311 udelay(1000);
312 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
313 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
314 }
315}
316
317static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
318{
319 pr_debug("Samsung LCD power\n");
320
321 if (on) {
322 pr_debug("on\n");
323 if (system_rev < 3)
324 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
325 else
326 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
327 mdelay(10);
328 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
329 mdelay(10);
330 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
331 mdelay(30);
332 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
333 mdelay(10);
334 } else {
335 pr_debug("off\n");
336 mdelay(10);
337 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
338 mdelay(30);
339 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
340 mdelay(10);
341 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
342 mdelay(10);
343 if (system_rev < 3)
344 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
345 else
346 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
347 }
348}
349
Philipp Zabele5c271e2007-11-22 17:59:11 +0100350static struct pxafb_mach_info toppoly_info = {
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100351 .modes = toppoly_modes,
352 .num_modes = 1,
353 .fixed_modes = 1,
Eric Miao95873192008-12-07 17:49:01 +0800354 .lcd_conn = LCD_COLOR_TFT_16BPP,
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100355 .pxafb_lcd_power = toppoly_lcd_power,
356};
357
358static struct pxafb_mach_info samsung_info = {
359 .modes = samsung_modes,
360 .num_modes = 1,
361 .fixed_modes = 1,
Eric Miao95873192008-12-07 17:49:01 +0800362 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |\
363 LCD_ALTERNATE_MAPPING,
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100364 .pxafb_lcd_power = samsung_lcd_power,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100365};
366
367/*
368 * Backlight
369 */
370
Philipp Zabel85847a32008-05-22 14:20:01 +0100371static int magician_backlight_init(struct device *dev)
Philipp Zabele5c271e2007-11-22 17:59:11 +0100372{
Philipp Zabel85847a32008-05-22 14:20:01 +0100373 int ret;
374
375 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
376 if (ret)
377 goto err;
378 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
379 if (ret)
380 goto err2;
381 return 0;
382
383err2:
384 gpio_free(EGPIO_MAGICIAN_BL_POWER);
385err:
386 return ret;
387}
388
389static int magician_backlight_notify(int brightness)
390{
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;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100395 } else {
Philipp Zabel85847a32008-05-22 14:20:01 +0100396 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
397 return brightness;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100398 }
399}
400
Philipp Zabel85847a32008-05-22 14:20:01 +0100401static void magician_backlight_exit(struct device *dev)
402{
403 gpio_free(EGPIO_MAGICIAN_BL_POWER);
404 gpio_free(EGPIO_MAGICIAN_BL_POWER2);
405}
406
407static struct platform_pwm_backlight_data backlight_data = {
408 .pwm_id = 0,
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,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100415};
416
417static struct platform_device backlight = {
Philipp Zabel85847a32008-05-22 14:20:01 +0100418 .name = "pwm-backlight",
Philipp Zabel14d10122008-06-30 18:11:55 +0100419 .id = -1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100420 .dev = {
Philipp Zabel85847a32008-05-22 14:20:01 +0100421 .parent = &pxa27x_device_pwm0.dev,
422 .platform_data = &backlight_data,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100423 },
Philipp Zabele5c271e2007-11-22 17:59:11 +0100424};
425
Philipp Zabel81447b22008-04-12 13:28:02 +0100426/*
427 * LEDs
428 */
429
Russell Kinga55faca2008-09-25 14:35:48 +0100430static struct gpio_led gpio_leds[] = {
Philipp Zabel81447b22008-04-12 13:28:02 +0100431 {
432 .name = "magician::vibra",
433 .default_trigger = "none",
434 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
435 },
436 {
437 .name = "magician::phone_bl",
438 .default_trigger = "none",
439 .gpio = GPIO103_MAGICIAN_LED_KP,
440 },
441};
442
443static struct gpio_led_platform_data gpio_led_info = {
444 .leds = gpio_leds,
445 .num_leds = ARRAY_SIZE(gpio_leds),
446};
447
448static struct platform_device leds_gpio = {
449 .name = "leds-gpio",
450 .id = -1,
451 .dev = {
452 .platform_data = &gpio_led_info,
453 },
454};
455
456static struct pasic3_led pasic3_leds[] = {
457 {
458 .led = {
459 .name = "magician:red",
460 .default_trigger = "ds2760-battery.0-charging",
461 },
462 .hw_num = 0,
463 .bit2 = PASIC3_BIT2_LED0,
464 .mask = PASIC3_MASK_LED0,
465 },
466 {
467 .led = {
468 .name = "magician:green",
469 .default_trigger = "ds2760-battery.0-charging-or-full",
470 },
471 .hw_num = 1,
472 .bit2 = PASIC3_BIT2_LED1,
473 .mask = PASIC3_MASK_LED1,
474 },
475 {
476 .led = {
477 .name = "magician:blue",
478 .default_trigger = "bluetooth",
479 },
480 .hw_num = 2,
481 .bit2 = PASIC3_BIT2_LED2,
482 .mask = PASIC3_MASK_LED2,
483 },
484};
485
486static struct platform_device pasic3;
487
Philipp Zabele03e0592008-04-24 18:10:46 +0100488static struct pasic3_leds_machinfo pasic3_leds_info = {
Philipp Zabel81447b22008-04-12 13:28:02 +0100489 .num_leds = ARRAY_SIZE(pasic3_leds),
490 .power_gpio = EGPIO_MAGICIAN_LED_POWER,
491 .leds = pasic3_leds,
492};
493
494/*
495 * PASIC3 with DS1WM
496 */
497
498static struct resource pasic3_resources[] = {
499 [0] = {
500 .start = PXA_CS2_PHYS,
501 .end = PXA_CS2_PHYS + 0x1b,
502 .flags = IORESOURCE_MEM,
503 },
504 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
505 [1] = {
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,
509 }
510};
511
512static struct pasic3_platform_data pasic3_platform_data = {
513 .bus_shift = 2,
514 .led_pdata = &pasic3_leds_info,
515 .clock_rate = 4000000,
516};
517
518static struct platform_device pasic3 = {
519 .name = "pasic3",
520 .id = -1,
521 .num_resources = ARRAY_SIZE(pasic3_resources),
522 .resource = pasic3_resources,
523 .dev = {
524 .platform_data = &pasic3_platform_data,
525 },
526};
Philipp Zabele5c271e2007-11-22 17:59:11 +0100527
528/*
Philipp Zabel6489c612009-02-01 11:20:30 +0100529 * USB "Transceiver"
530 */
531
532static struct resource gpio_vbus_resource = {
533 .flags = IORESOURCE_IRQ,
534 .start = IRQ_MAGICIAN_VBUS,
535 .end = IRQ_MAGICIAN_VBUS,
536};
537
538static struct gpio_vbus_mach_info gpio_vbus_info = {
539 .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
540 .gpio_vbus = EGPIO_MAGICIAN_CABLE_STATE_USB,
541};
542
543static struct platform_device gpio_vbus = {
544 .name = "gpio-vbus",
545 .id = -1,
546 .num_resources = 1,
547 .resource = &gpio_vbus_resource,
548 .dev = {
549 .platform_data = &gpio_vbus_info,
550 },
551};
552
553/*
Philipp Zabel350d1152008-04-09 19:25:56 +0100554 * External power
555 */
556
Philipp Zabelff279202008-05-22 10:14:21 +0100557static int power_supply_init(struct device *dev)
558{
559 int ret;
560
561 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
562 if (ret)
563 goto err_cs_ac;
564 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB, "CABLE_STATE_USB");
565 if (ret)
566 goto err_cs_usb;
567 ret = gpio_request(EGPIO_MAGICIAN_CHARGE_EN, "CHARGE_EN");
568 if (ret)
569 goto err_chg_en;
570 ret = gpio_request(GPIO30_MAGICIAN_nCHARGE_EN, "nCHARGE_EN");
571 if (!ret)
572 ret = gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN, 0);
573 if (ret)
574 goto err_nchg_en;
575
576 return 0;
577
578err_nchg_en:
579 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
580err_chg_en:
581 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
582err_cs_usb:
583 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
584err_cs_ac:
585 return ret;
586}
587
Philipp Zabel350d1152008-04-09 19:25:56 +0100588static int magician_is_ac_online(void)
589{
590 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
591}
592
593static int magician_is_usb_online(void)
594{
595 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
596}
597
598static void magician_set_charge(int flags)
599{
600 gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
601 gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
602}
603
Philipp Zabelff279202008-05-22 10:14:21 +0100604static void power_supply_exit(struct device *dev)
605{
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);
610}
611
Philipp Zabel81447b22008-04-12 13:28:02 +0100612static char *magician_supplicants[] = {
613 "ds2760-battery.0", "backup-battery"
614};
615
Philipp Zabel350d1152008-04-09 19:25:56 +0100616static struct pda_power_pdata power_supply_info = {
Philipp Zabelff279202008-05-22 10:14:21 +0100617 .init = power_supply_init,
Philipp Zabel81447b22008-04-12 13:28:02 +0100618 .is_ac_online = magician_is_ac_online,
619 .is_usb_online = magician_is_usb_online,
620 .set_charge = magician_set_charge,
Philipp Zabelff279202008-05-22 10:14:21 +0100621 .exit = power_supply_exit,
Philipp Zabel81447b22008-04-12 13:28:02 +0100622 .supplied_to = magician_supplicants,
623 .num_supplicants = ARRAY_SIZE(magician_supplicants),
Philipp Zabel350d1152008-04-09 19:25:56 +0100624};
625
626static struct resource power_supply_resources[] = {
627 [0] = {
628 .name = "ac",
Philipp Zabeld942d772009-02-09 17:34:07 +0100629 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
630 IORESOURCE_IRQ_LOWEDGE,
Philipp Zabel6489c612009-02-01 11:20:30 +0100631 .start = IRQ_MAGICIAN_VBUS,
632 .end = IRQ_MAGICIAN_VBUS,
Philipp Zabel350d1152008-04-09 19:25:56 +0100633 },
634 [1] = {
635 .name = "usb",
Philipp Zabeld942d772009-02-09 17:34:07 +0100636 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
637 IORESOURCE_IRQ_LOWEDGE,
Philipp Zabel6489c612009-02-01 11:20:30 +0100638 .start = IRQ_MAGICIAN_VBUS,
639 .end = IRQ_MAGICIAN_VBUS,
Philipp Zabel350d1152008-04-09 19:25:56 +0100640 },
641};
642
643static struct platform_device power_supply = {
644 .name = "pda-power",
645 .id = -1,
646 .dev = {
647 .platform_data = &power_supply_info,
648 },
649 .resource = power_supply_resources,
650 .num_resources = ARRAY_SIZE(power_supply_resources),
651};
652
653
654/*
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100655 * MMC/SD
656 */
657
658static int magician_mci_init(struct device *dev,
659 irq_handler_t detect_irq, void *data)
660{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100661 int err;
662
663 err = request_irq(IRQ_MAGICIAN_SD, detect_irq,
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100664 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
665 "MMC card detect", data);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100666 if (err)
667 goto err_request_irq;
668 err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER");
669 if (err)
670 goto err_request_power;
671 err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY");
672 if (err)
673 goto err_request_readonly;
674
675 return 0;
676
677err_request_readonly:
678 gpio_free(EGPIO_MAGICIAN_SD_POWER);
679err_request_power:
680 free_irq(IRQ_MAGICIAN_SD, data);
681err_request_irq:
682 return err;
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100683}
684
685static void magician_mci_setpower(struct device *dev, unsigned int vdd)
686{
687 struct pxamci_platform_data *pdata = dev->platform_data;
688
689 gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
690}
691
692static int magician_mci_get_ro(struct device *dev)
693{
694 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
695}
696
697static void magician_mci_exit(struct device *dev, void *data)
698{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100699 gpio_free(EGPIO_MAGICIAN_nSD_READONLY);
700 gpio_free(EGPIO_MAGICIAN_SD_POWER);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100701 free_irq(IRQ_MAGICIAN_SD, data);
702}
703
704static struct pxamci_platform_data magician_mci_info = {
705 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
706 .init = magician_mci_init,
707 .get_ro = magician_mci_get_ro,
708 .setpower = magician_mci_setpower,
709 .exit = magician_mci_exit,
710};
711
712
713/*
Philipp Zabele5c271e2007-11-22 17:59:11 +0100714 * USB OHCI
715 */
716
Philipp Zabele5c271e2007-11-22 17:59:11 +0100717static struct pxaohci_platform_data magician_ohci_info = {
Eric Miao097b5332008-09-27 15:49:57 +0800718 .port_mode = PMM_PERPORT_MODE,
719 .flags = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW,
720 .power_budget = 0,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100721};
722
723
724/*
725 * StrataFlash
726 */
727
Philipp Zabelaa797592008-04-09 19:24:05 +0100728static void magician_set_vpp(struct map_info *map, int vpp)
729{
730 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
731}
732
Philipp Zabele5c271e2007-11-22 17:59:11 +0100733static struct resource strataflash_resource = {
734 .start = PXA_CS0_PHYS,
Philipp Zabelfcb78d12009-01-17 18:45:43 +0100735 .end = PXA_CS0_PHYS + SZ_64M - 1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100736 .flags = IORESOURCE_MEM,
737};
738
739static struct physmap_flash_data strataflash_data = {
740 .width = 4,
Philipp Zabelaa797592008-04-09 19:24:05 +0100741 .set_vpp = magician_set_vpp,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100742};
743
744static struct platform_device strataflash = {
745 .name = "physmap-flash",
746 .id = -1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100747 .resource = &strataflash_resource,
Philipp Zabel70e357f2008-04-09 19:22:57 +0100748 .num_resources = 1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100749 .dev = {
750 .platform_data = &strataflash_data,
751 },
752};
753
754/*
755 * Platform devices
756 */
757
758static struct platform_device *devices[] __initdata = {
759 &gpio_keys,
Philipp Zabel70e357f2008-04-09 19:22:57 +0100760 &egpio,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100761 &backlight,
Philipp Zabel81447b22008-04-12 13:28:02 +0100762 &pasic3,
Philipp Zabel6489c612009-02-01 11:20:30 +0100763 &gpio_vbus,
Philipp Zabel350d1152008-04-09 19:25:56 +0100764 &power_supply,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100765 &strataflash,
Philipp Zabel81447b22008-04-12 13:28:02 +0100766 &leds_gpio,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100767};
768
769static void __init magician_init(void)
770{
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100771 void __iomem *cpld;
772 int lcd_select;
Philipp Zabela1999cd2008-04-20 17:39:12 +0100773 int err;
774
775 gpio_request(GPIO13_MAGICIAN_CPLD_IRQ, "CPLD_IRQ");
776 gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ, "DS1WM_IRQ");
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100777
Philipp Zabelb1682812008-04-12 13:29:22 +0100778 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
779
Philipp Zabele5c271e2007-11-22 17:59:11 +0100780 platform_add_devices(devices, ARRAY_SIZE(devices));
Philipp Zabela1999cd2008-04-20 17:39:12 +0100781
782 err = gpio_request(GPIO83_MAGICIAN_nIR_EN, "nIR_EN");
783 if (!err) {
784 gpio_direction_output(GPIO83_MAGICIAN_nIR_EN, 1);
785 pxa_set_ficp_info(&magician_ficp_info);
786 }
Philipp Zabeldee63162009-01-17 18:45:42 +0100787 pxa27x_set_i2c_power_info(NULL);
Philipp Zabele6816f32008-04-09 19:14:15 +0100788 pxa_set_i2c_info(NULL);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100789 pxa_set_mci_info(&magician_mci_info);
Philipp Zabele5c271e2007-11-22 17:59:11 +0100790 pxa_set_ohci_info(&magician_ohci_info);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100791
792 /* Check LCD type we have */
793 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
794 if (cpld) {
795 u8 board_id = __raw_readb(cpld+0x14);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100796 iounmap(cpld);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100797 system_rev = board_id & 0x7;
798 lcd_select = board_id & 0x8;
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100799 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
Philipp Zabela1999cd2008-04-20 17:39:12 +0100800 if (lcd_select && (system_rev < 3)) {
801 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER");
802 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
803 }
804 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1");
805 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2");
806 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3");
807 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0);
808 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0);
809 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100810 set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
811 } else
812 pr_err("LCD detection: CPLD mapping failed\n");
Philipp Zabele5c271e2007-11-22 17:59:11 +0100813}
814
815
816MACHINE_START(MAGICIAN, "HTC Magician")
817 .phys_io = 0x40000000,
818 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
819 .boot_params = 0xa0000100,
820 .map_io = pxa_map_io,
821 .init_irq = pxa27x_init_irq,
822 .init_machine = magician_init,
823 .timer = &pxa_timer,
824MACHINE_END