blob: f734d6635470ac62ff6b4a860959aea30870fe7f [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 Zabele5c271e2007-11-22 17:59:11 +010028
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/hardware.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010030#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010032#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 Zabele5c271e2007-11-22 17:59:11 +010041
Philipp Zabel85847a32008-05-22 14:20:01 +010042#include "devices.h"
Philipp Zabele5c271e2007-11-22 17:59:11 +010043#include "generic.h"
44
Philipp Zabel7a970102008-06-26 21:03:54 +010045static unsigned long magician_pin_config[] __initdata = {
Philipp Zabelb1682812008-04-12 13:29:22 +010046
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 Zabel16c3ea42009-01-17 18:45:41 +010069 /* SSP 1 */
70 GPIO23_SSP1_SCLK,
71 GPIO24_SSP1_SFRM,
72 GPIO25_SSP1_TXD,
73
Philipp Zabelb1682812008-04-12 13:29:22 +010074 /* 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 Zabel2f131952008-04-20 17:40:11 +0100123
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 Miao6f584cf2008-11-28 16:00:24 +0800131
132 /* I2C */
133 GPIO117_I2C_SCL,
134 GPIO118_I2C_SDA,
Philipp Zabelb1682812008-04-12 13:29:22 +0100135};
136
Philipp Zabele5c271e2007-11-22 17:59:11 +0100137/*
138 * IRDA
139 */
140
141static void magician_irda_transceiver_mode(struct device *dev, int mode)
142{
143 gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
Dmitry Baryshkov0fc3ff32008-07-02 13:54:46 +0100144 pxa2xx_transceiver_mode(dev, mode);
Philipp Zabele5c271e2007-11-22 17:59:11 +0100145}
146
147static 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
156static struct gpio_keys_button magician_button_table[] = {
157 {KEY_POWER, GPIO0_MAGICIAN_KEY_POWER, 0, "Power button"},
158 {KEY_ESC, GPIO37_MAGICIAN_KEY_HANGUP, 0, "Hangup button"},
159 {KEY_F10, GPIO38_MAGICIAN_KEY_CONTACTS, 0, "Contacts button"},
160 {KEY_CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, 0, "Calendar button"},
161 {KEY_CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, 0, "Camera button"},
162 {KEY_UP, GPIO93_MAGICIAN_KEY_UP, 0, "Up button"},
163 {KEY_DOWN, GPIO94_MAGICIAN_KEY_DOWN, 0, "Down button"},
164 {KEY_LEFT, GPIO95_MAGICIAN_KEY_LEFT, 0, "Left button"},
165 {KEY_RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, 0, "Right button"},
166 {KEY_KPENTER, GPIO97_MAGICIAN_KEY_ENTER, 0, "Action button"},
167 {KEY_RECORD, GPIO98_MAGICIAN_KEY_RECORD, 0, "Record button"},
168 {KEY_VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, 0, "Volume up"},
169 {KEY_VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, 0, "Volume down"},
170 {KEY_PHONE, GPIO102_MAGICIAN_KEY_PHONE, 0, "Phone button"},
171 {KEY_PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, 0, "Headset button"},
172};
173
174static struct gpio_keys_platform_data gpio_keys_data = {
175 .buttons = magician_button_table,
176 .nbuttons = ARRAY_SIZE(magician_button_table),
177};
178
179static struct platform_device gpio_keys = {
180 .name = "gpio-keys",
181 .dev = {
182 .platform_data = &gpio_keys_data,
183 },
184 .id = -1,
185};
186
Philipp Zabel70e357f2008-04-09 19:22:57 +0100187
188/*
189 * EGPIO (Xilinx CPLD)
190 *
191 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
192 */
193
194static struct resource egpio_resources[] = {
195 [0] = {
196 .start = PXA_CS3_PHYS,
197 .end = PXA_CS3_PHYS + 0x20,
198 .flags = IORESOURCE_MEM,
199 },
200 [1] = {
201 .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
202 .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
203 .flags = IORESOURCE_IRQ,
204 },
205};
206
207static struct htc_egpio_chip egpio_chips[] = {
208 [0] = {
209 .reg_start = 0,
210 .gpio_base = MAGICIAN_EGPIO(0, 0),
211 .num_gpios = 24,
212 .direction = HTC_EGPIO_OUTPUT,
213 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
214 },
215 [1] = {
216 .reg_start = 4,
217 .gpio_base = MAGICIAN_EGPIO(4, 0),
218 .num_gpios = 24,
219 .direction = HTC_EGPIO_INPUT,
220 },
221};
222
223static struct htc_egpio_platform_data egpio_info = {
224 .reg_width = 8,
225 .bus_width = 32,
226 .irq_base = IRQ_BOARD_START,
227 .num_irqs = 4,
228 .ack_register = 3,
229 .chip = egpio_chips,
230 .num_chips = ARRAY_SIZE(egpio_chips),
231};
232
233static struct platform_device egpio = {
234 .name = "htc-egpio",
235 .id = -1,
236 .resource = egpio_resources,
237 .num_resources = ARRAY_SIZE(egpio_resources),
238 .dev = {
239 .platform_data = &egpio_info,
240 },
241};
242
Philipp Zabele5c271e2007-11-22 17:59:11 +0100243/*
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100244 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
Philipp Zabele5c271e2007-11-22 17:59:11 +0100245 */
246
247static struct pxafb_mode_info toppoly_modes[] = {
248 {
249 .pixclock = 96153,
250 .bpp = 16,
251 .xres = 240,
252 .yres = 320,
253 .hsync_len = 11,
254 .vsync_len = 3,
255 .left_margin = 19,
256 .upper_margin = 2,
257 .right_margin = 10,
258 .lower_margin = 2,
259 .sync = 0,
260 },
261};
262
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100263static struct pxafb_mode_info samsung_modes[] = {
264 {
265 .pixclock = 96153,
266 .bpp = 16,
267 .xres = 240,
268 .yres = 320,
269 .hsync_len = 8,
270 .vsync_len = 4,
271 .left_margin = 9,
272 .upper_margin = 4,
273 .right_margin = 9,
274 .lower_margin = 4,
275 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
276 },
277};
278
279static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
280{
281 pr_debug("Toppoly LCD power\n");
282
283 if (on) {
284 pr_debug("on\n");
285 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
286 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
287 udelay(2000);
288 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
289 udelay(2000);
290 /* FIXME: enable LCDC here */
291 udelay(2000);
292 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
293 udelay(2000);
294 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
295 } else {
296 pr_debug("off\n");
297 msleep(15);
298 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
299 udelay(500);
300 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
301 udelay(1000);
302 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
303 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
304 }
305}
306
307static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
308{
309 pr_debug("Samsung LCD power\n");
310
311 if (on) {
312 pr_debug("on\n");
313 if (system_rev < 3)
314 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
315 else
316 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
317 mdelay(10);
318 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
319 mdelay(10);
320 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
321 mdelay(30);
322 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
323 mdelay(10);
324 } else {
325 pr_debug("off\n");
326 mdelay(10);
327 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
328 mdelay(30);
329 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
330 mdelay(10);
331 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
332 mdelay(10);
333 if (system_rev < 3)
334 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
335 else
336 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
337 }
338}
339
Philipp Zabele5c271e2007-11-22 17:59:11 +0100340static struct pxafb_mach_info toppoly_info = {
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100341 .modes = toppoly_modes,
342 .num_modes = 1,
343 .fixed_modes = 1,
Eric Miao95873192008-12-07 17:49:01 +0800344 .lcd_conn = LCD_COLOR_TFT_16BPP,
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100345 .pxafb_lcd_power = toppoly_lcd_power,
346};
347
348static struct pxafb_mach_info samsung_info = {
349 .modes = samsung_modes,
350 .num_modes = 1,
351 .fixed_modes = 1,
Eric Miao95873192008-12-07 17:49:01 +0800352 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |\
353 LCD_ALTERNATE_MAPPING,
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100354 .pxafb_lcd_power = samsung_lcd_power,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100355};
356
357/*
358 * Backlight
359 */
360
Philipp Zabel85847a32008-05-22 14:20:01 +0100361static int magician_backlight_init(struct device *dev)
Philipp Zabele5c271e2007-11-22 17:59:11 +0100362{
Philipp Zabel85847a32008-05-22 14:20:01 +0100363 int ret;
364
365 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
366 if (ret)
367 goto err;
368 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
369 if (ret)
370 goto err2;
371 return 0;
372
373err2:
374 gpio_free(EGPIO_MAGICIAN_BL_POWER);
375err:
376 return ret;
377}
378
379static int magician_backlight_notify(int brightness)
380{
381 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
382 if (brightness >= 200) {
383 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
384 return brightness - 72;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100385 } else {
Philipp Zabel85847a32008-05-22 14:20:01 +0100386 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
387 return brightness;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100388 }
389}
390
Philipp Zabel85847a32008-05-22 14:20:01 +0100391static void magician_backlight_exit(struct device *dev)
392{
393 gpio_free(EGPIO_MAGICIAN_BL_POWER);
394 gpio_free(EGPIO_MAGICIAN_BL_POWER2);
395}
396
397static struct platform_pwm_backlight_data backlight_data = {
398 .pwm_id = 0,
399 .max_brightness = 272,
400 .dft_brightness = 100,
401 .pwm_period_ns = 30923,
402 .init = magician_backlight_init,
403 .notify = magician_backlight_notify,
404 .exit = magician_backlight_exit,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100405};
406
407static struct platform_device backlight = {
Philipp Zabel85847a32008-05-22 14:20:01 +0100408 .name = "pwm-backlight",
Philipp Zabel14d10122008-06-30 18:11:55 +0100409 .id = -1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100410 .dev = {
Philipp Zabel85847a32008-05-22 14:20:01 +0100411 .parent = &pxa27x_device_pwm0.dev,
412 .platform_data = &backlight_data,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100413 },
Philipp Zabele5c271e2007-11-22 17:59:11 +0100414};
415
Philipp Zabel81447b22008-04-12 13:28:02 +0100416/*
417 * LEDs
418 */
419
Russell Kinga55faca2008-09-25 14:35:48 +0100420static struct gpio_led gpio_leds[] = {
Philipp Zabel81447b22008-04-12 13:28:02 +0100421 {
422 .name = "magician::vibra",
423 .default_trigger = "none",
424 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
425 },
426 {
427 .name = "magician::phone_bl",
428 .default_trigger = "none",
429 .gpio = GPIO103_MAGICIAN_LED_KP,
430 },
431};
432
433static struct gpio_led_platform_data gpio_led_info = {
434 .leds = gpio_leds,
435 .num_leds = ARRAY_SIZE(gpio_leds),
436};
437
438static struct platform_device leds_gpio = {
439 .name = "leds-gpio",
440 .id = -1,
441 .dev = {
442 .platform_data = &gpio_led_info,
443 },
444};
445
446static struct pasic3_led pasic3_leds[] = {
447 {
448 .led = {
449 .name = "magician:red",
450 .default_trigger = "ds2760-battery.0-charging",
451 },
452 .hw_num = 0,
453 .bit2 = PASIC3_BIT2_LED0,
454 .mask = PASIC3_MASK_LED0,
455 },
456 {
457 .led = {
458 .name = "magician:green",
459 .default_trigger = "ds2760-battery.0-charging-or-full",
460 },
461 .hw_num = 1,
462 .bit2 = PASIC3_BIT2_LED1,
463 .mask = PASIC3_MASK_LED1,
464 },
465 {
466 .led = {
467 .name = "magician:blue",
468 .default_trigger = "bluetooth",
469 },
470 .hw_num = 2,
471 .bit2 = PASIC3_BIT2_LED2,
472 .mask = PASIC3_MASK_LED2,
473 },
474};
475
476static struct platform_device pasic3;
477
Philipp Zabele03e0592008-04-24 18:10:46 +0100478static struct pasic3_leds_machinfo pasic3_leds_info = {
Philipp Zabel81447b22008-04-12 13:28:02 +0100479 .num_leds = ARRAY_SIZE(pasic3_leds),
480 .power_gpio = EGPIO_MAGICIAN_LED_POWER,
481 .leds = pasic3_leds,
482};
483
484/*
485 * PASIC3 with DS1WM
486 */
487
488static struct resource pasic3_resources[] = {
489 [0] = {
490 .start = PXA_CS2_PHYS,
491 .end = PXA_CS2_PHYS + 0x1b,
492 .flags = IORESOURCE_MEM,
493 },
494 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
495 [1] = {
496 .start = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
497 .end = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
498 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
499 }
500};
501
502static struct pasic3_platform_data pasic3_platform_data = {
503 .bus_shift = 2,
504 .led_pdata = &pasic3_leds_info,
505 .clock_rate = 4000000,
506};
507
508static struct platform_device pasic3 = {
509 .name = "pasic3",
510 .id = -1,
511 .num_resources = ARRAY_SIZE(pasic3_resources),
512 .resource = pasic3_resources,
513 .dev = {
514 .platform_data = &pasic3_platform_data,
515 },
516};
Philipp Zabele5c271e2007-11-22 17:59:11 +0100517
518/*
Philipp Zabel350d1152008-04-09 19:25:56 +0100519 * External power
520 */
521
Philipp Zabelff279202008-05-22 10:14:21 +0100522static int power_supply_init(struct device *dev)
523{
524 int ret;
525
526 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
527 if (ret)
528 goto err_cs_ac;
529 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB, "CABLE_STATE_USB");
530 if (ret)
531 goto err_cs_usb;
532 ret = gpio_request(EGPIO_MAGICIAN_CHARGE_EN, "CHARGE_EN");
533 if (ret)
534 goto err_chg_en;
535 ret = gpio_request(GPIO30_MAGICIAN_nCHARGE_EN, "nCHARGE_EN");
536 if (!ret)
537 ret = gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN, 0);
538 if (ret)
539 goto err_nchg_en;
540
541 return 0;
542
543err_nchg_en:
544 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
545err_chg_en:
546 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
547err_cs_usb:
548 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
549err_cs_ac:
550 return ret;
551}
552
Philipp Zabel350d1152008-04-09 19:25:56 +0100553static int magician_is_ac_online(void)
554{
555 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
556}
557
558static int magician_is_usb_online(void)
559{
560 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
561}
562
563static void magician_set_charge(int flags)
564{
565 gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
566 gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
567}
568
Philipp Zabelff279202008-05-22 10:14:21 +0100569static void power_supply_exit(struct device *dev)
570{
571 gpio_free(GPIO30_MAGICIAN_nCHARGE_EN);
572 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
573 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
574 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
575}
576
Philipp Zabel81447b22008-04-12 13:28:02 +0100577static char *magician_supplicants[] = {
578 "ds2760-battery.0", "backup-battery"
579};
580
Philipp Zabel350d1152008-04-09 19:25:56 +0100581static struct pda_power_pdata power_supply_info = {
Philipp Zabelff279202008-05-22 10:14:21 +0100582 .init = power_supply_init,
Philipp Zabel81447b22008-04-12 13:28:02 +0100583 .is_ac_online = magician_is_ac_online,
584 .is_usb_online = magician_is_usb_online,
585 .set_charge = magician_set_charge,
Philipp Zabelff279202008-05-22 10:14:21 +0100586 .exit = power_supply_exit,
Philipp Zabel81447b22008-04-12 13:28:02 +0100587 .supplied_to = magician_supplicants,
588 .num_supplicants = ARRAY_SIZE(magician_supplicants),
Philipp Zabel350d1152008-04-09 19:25:56 +0100589};
590
591static struct resource power_supply_resources[] = {
592 [0] = {
593 .name = "ac",
594 .flags = IORESOURCE_IRQ,
595 .start = IRQ_MAGICIAN_AC,
596 .end = IRQ_MAGICIAN_AC,
597 },
598 [1] = {
599 .name = "usb",
600 .flags = IORESOURCE_IRQ,
601 .start = IRQ_MAGICIAN_AC,
602 .end = IRQ_MAGICIAN_AC,
603 },
604};
605
606static struct platform_device power_supply = {
607 .name = "pda-power",
608 .id = -1,
609 .dev = {
610 .platform_data = &power_supply_info,
611 },
612 .resource = power_supply_resources,
613 .num_resources = ARRAY_SIZE(power_supply_resources),
614};
615
616
617/*
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100618 * MMC/SD
619 */
620
621static int magician_mci_init(struct device *dev,
622 irq_handler_t detect_irq, void *data)
623{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100624 int err;
625
626 err = request_irq(IRQ_MAGICIAN_SD, detect_irq,
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100627 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
628 "MMC card detect", data);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100629 if (err)
630 goto err_request_irq;
631 err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER");
632 if (err)
633 goto err_request_power;
634 err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY");
635 if (err)
636 goto err_request_readonly;
637
638 return 0;
639
640err_request_readonly:
641 gpio_free(EGPIO_MAGICIAN_SD_POWER);
642err_request_power:
643 free_irq(IRQ_MAGICIAN_SD, data);
644err_request_irq:
645 return err;
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100646}
647
648static void magician_mci_setpower(struct device *dev, unsigned int vdd)
649{
650 struct pxamci_platform_data *pdata = dev->platform_data;
651
652 gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
653}
654
655static int magician_mci_get_ro(struct device *dev)
656{
657 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
658}
659
660static void magician_mci_exit(struct device *dev, void *data)
661{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100662 gpio_free(EGPIO_MAGICIAN_nSD_READONLY);
663 gpio_free(EGPIO_MAGICIAN_SD_POWER);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100664 free_irq(IRQ_MAGICIAN_SD, data);
665}
666
667static struct pxamci_platform_data magician_mci_info = {
668 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
669 .init = magician_mci_init,
670 .get_ro = magician_mci_get_ro,
671 .setpower = magician_mci_setpower,
672 .exit = magician_mci_exit,
673};
674
675
676/*
Philipp Zabele5c271e2007-11-22 17:59:11 +0100677 * USB OHCI
678 */
679
Philipp Zabele5c271e2007-11-22 17:59:11 +0100680static struct pxaohci_platform_data magician_ohci_info = {
Eric Miao097b5332008-09-27 15:49:57 +0800681 .port_mode = PMM_PERPORT_MODE,
682 .flags = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW,
683 .power_budget = 0,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100684};
685
686
687/*
688 * StrataFlash
689 */
690
Philipp Zabelaa797592008-04-09 19:24:05 +0100691static void magician_set_vpp(struct map_info *map, int vpp)
692{
693 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
694}
695
Philipp Zabele5c271e2007-11-22 17:59:11 +0100696#define PXA_CS_SIZE 0x04000000
697
698static struct resource strataflash_resource = {
699 .start = PXA_CS0_PHYS,
700 .end = PXA_CS0_PHYS + PXA_CS_SIZE - 1,
701 .flags = IORESOURCE_MEM,
702};
703
704static struct physmap_flash_data strataflash_data = {
705 .width = 4,
Philipp Zabelaa797592008-04-09 19:24:05 +0100706 .set_vpp = magician_set_vpp,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100707};
708
709static struct platform_device strataflash = {
710 .name = "physmap-flash",
711 .id = -1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100712 .resource = &strataflash_resource,
Philipp Zabel70e357f2008-04-09 19:22:57 +0100713 .num_resources = 1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100714 .dev = {
715 .platform_data = &strataflash_data,
716 },
717};
718
719/*
720 * Platform devices
721 */
722
723static struct platform_device *devices[] __initdata = {
724 &gpio_keys,
Philipp Zabel70e357f2008-04-09 19:22:57 +0100725 &egpio,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100726 &backlight,
Philipp Zabel81447b22008-04-12 13:28:02 +0100727 &pasic3,
Philipp Zabel350d1152008-04-09 19:25:56 +0100728 &power_supply,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100729 &strataflash,
Philipp Zabel81447b22008-04-12 13:28:02 +0100730 &leds_gpio,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100731};
732
733static void __init magician_init(void)
734{
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100735 void __iomem *cpld;
736 int lcd_select;
Philipp Zabela1999cd2008-04-20 17:39:12 +0100737 int err;
738
739 gpio_request(GPIO13_MAGICIAN_CPLD_IRQ, "CPLD_IRQ");
740 gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ, "DS1WM_IRQ");
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100741
Philipp Zabelb1682812008-04-12 13:29:22 +0100742 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
743
Philipp Zabele5c271e2007-11-22 17:59:11 +0100744 platform_add_devices(devices, ARRAY_SIZE(devices));
Philipp Zabela1999cd2008-04-20 17:39:12 +0100745
746 err = gpio_request(GPIO83_MAGICIAN_nIR_EN, "nIR_EN");
747 if (!err) {
748 gpio_direction_output(GPIO83_MAGICIAN_nIR_EN, 1);
749 pxa_set_ficp_info(&magician_ficp_info);
750 }
Philipp Zabeldee63162009-01-17 18:45:42 +0100751 pxa27x_set_i2c_power_info(NULL);
Philipp Zabele6816f32008-04-09 19:14:15 +0100752 pxa_set_i2c_info(NULL);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100753 pxa_set_mci_info(&magician_mci_info);
Philipp Zabele5c271e2007-11-22 17:59:11 +0100754 pxa_set_ohci_info(&magician_ohci_info);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100755
756 /* Check LCD type we have */
757 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
758 if (cpld) {
759 u8 board_id = __raw_readb(cpld+0x14);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100760 iounmap(cpld);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100761 system_rev = board_id & 0x7;
762 lcd_select = board_id & 0x8;
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100763 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
Philipp Zabela1999cd2008-04-20 17:39:12 +0100764 if (lcd_select && (system_rev < 3)) {
765 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER");
766 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
767 }
768 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1");
769 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2");
770 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3");
771 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0);
772 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0);
773 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100774 set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
775 } else
776 pr_err("LCD detection: CPLD mapping failed\n");
Philipp Zabele5c271e2007-11-22 17:59:11 +0100777}
778
779
780MACHINE_START(MAGICIAN, "HTC Magician")
781 .phys_io = 0x40000000,
782 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
783 .boot_params = 0xa0000100,
784 .map_io = pxa_map_io,
785 .init_irq = pxa27x_init_irq,
786 .init_machine = magician_init,
787 .timer = &pxa_timer,
788MACHINE_END