blob: bad5821be41a3eae77d2512a6703ac4e345bfe53 [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
Philipp Zabele5c271e2007-11-22 17:59:11 +010029#include <asm/hardware.h>
30#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
32#include <asm/arch/magician.h>
Philipp Zabelb1682812008-04-12 13:29:22 +010033#include <asm/arch/mfp-pxa27x.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010034#include <asm/arch/pxa-regs.h>
Russell King0b0a9df2008-05-18 14:59:36 +010035#include <asm/arch/pxa2xx-regs.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010036#include <asm/arch/pxafb.h>
Philipp Zabele6816f32008-04-09 19:14:15 +010037#include <asm/arch/i2c.h>
Philipp Zabelbdb0c162008-04-09 19:24:55 +010038#include <asm/arch/mmc.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010039#include <asm/arch/irda.h>
40#include <asm/arch/ohci.h>
41
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
69 /* SSP 2 */
70 GPIO19_SSP2_SCLK,
71 GPIO14_SSP2_SFRM,
72 GPIO89_SSP2_TXD,
73 GPIO88_SSP2_RXD,
74
75 /* MMC */
76 GPIO32_MMC_CLK,
77 GPIO92_MMC_DAT_0,
78 GPIO109_MMC_DAT_1,
79 GPIO110_MMC_DAT_2,
80 GPIO111_MMC_DAT_3,
81 GPIO112_MMC_CMD,
82
83 /* LCD */
84 GPIO58_LCD_LDD_0,
85 GPIO59_LCD_LDD_1,
86 GPIO60_LCD_LDD_2,
87 GPIO61_LCD_LDD_3,
88 GPIO62_LCD_LDD_4,
89 GPIO63_LCD_LDD_5,
90 GPIO64_LCD_LDD_6,
91 GPIO65_LCD_LDD_7,
92 GPIO66_LCD_LDD_8,
93 GPIO67_LCD_LDD_9,
94 GPIO68_LCD_LDD_10,
95 GPIO69_LCD_LDD_11,
96 GPIO70_LCD_LDD_12,
97 GPIO71_LCD_LDD_13,
98 GPIO72_LCD_LDD_14,
99 GPIO73_LCD_LDD_15,
100 GPIO74_LCD_FCLK,
101 GPIO75_LCD_LCLK,
102 GPIO76_LCD_PCLK,
103 GPIO77_LCD_BIAS,
104
105 /* QCI */
106 GPIO12_CIF_DD_7,
107 GPIO17_CIF_DD_6,
108 GPIO50_CIF_DD_3,
109 GPIO51_CIF_DD_2,
110 GPIO52_CIF_DD_4,
111 GPIO53_CIF_MCLK,
112 GPIO54_CIF_PCLK,
113 GPIO55_CIF_DD_1,
114 GPIO81_CIF_DD_0,
115 GPIO82_CIF_DD_5,
116 GPIO84_CIF_FV,
117 GPIO85_CIF_LV,
Philipp Zabel2f131952008-04-20 17:40:11 +0100118
119 /* Magician specific input GPIOs */
120 GPIO9_GPIO, /* unknown */
121 GPIO10_GPIO, /* GSM_IRQ */
122 GPIO13_GPIO, /* CPLD_IRQ */
123 GPIO107_GPIO, /* DS1WM_IRQ */
124 GPIO108_GPIO, /* GSM_READY */
125 GPIO115_GPIO, /* nPEN_IRQ */
Philipp Zabelb1682812008-04-12 13:29:22 +0100126};
127
Philipp Zabele5c271e2007-11-22 17:59:11 +0100128/*
129 * IRDA
130 */
131
132static void magician_irda_transceiver_mode(struct device *dev, int mode)
133{
134 gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
135}
136
137static struct pxaficp_platform_data magician_ficp_info = {
138 .transceiver_cap = IR_SIRMODE | IR_OFF,
139 .transceiver_mode = magician_irda_transceiver_mode,
140};
141
142/*
143 * GPIO Keys
144 */
145
146static struct gpio_keys_button magician_button_table[] = {
147 {KEY_POWER, GPIO0_MAGICIAN_KEY_POWER, 0, "Power button"},
148 {KEY_ESC, GPIO37_MAGICIAN_KEY_HANGUP, 0, "Hangup button"},
149 {KEY_F10, GPIO38_MAGICIAN_KEY_CONTACTS, 0, "Contacts button"},
150 {KEY_CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, 0, "Calendar button"},
151 {KEY_CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, 0, "Camera button"},
152 {KEY_UP, GPIO93_MAGICIAN_KEY_UP, 0, "Up button"},
153 {KEY_DOWN, GPIO94_MAGICIAN_KEY_DOWN, 0, "Down button"},
154 {KEY_LEFT, GPIO95_MAGICIAN_KEY_LEFT, 0, "Left button"},
155 {KEY_RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, 0, "Right button"},
156 {KEY_KPENTER, GPIO97_MAGICIAN_KEY_ENTER, 0, "Action button"},
157 {KEY_RECORD, GPIO98_MAGICIAN_KEY_RECORD, 0, "Record button"},
158 {KEY_VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, 0, "Volume up"},
159 {KEY_VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, 0, "Volume down"},
160 {KEY_PHONE, GPIO102_MAGICIAN_KEY_PHONE, 0, "Phone button"},
161 {KEY_PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, 0, "Headset button"},
162};
163
164static struct gpio_keys_platform_data gpio_keys_data = {
165 .buttons = magician_button_table,
166 .nbuttons = ARRAY_SIZE(magician_button_table),
167};
168
169static struct platform_device gpio_keys = {
170 .name = "gpio-keys",
171 .dev = {
172 .platform_data = &gpio_keys_data,
173 },
174 .id = -1,
175};
176
Philipp Zabel70e357f2008-04-09 19:22:57 +0100177
178/*
179 * EGPIO (Xilinx CPLD)
180 *
181 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
182 */
183
184static struct resource egpio_resources[] = {
185 [0] = {
186 .start = PXA_CS3_PHYS,
187 .end = PXA_CS3_PHYS + 0x20,
188 .flags = IORESOURCE_MEM,
189 },
190 [1] = {
191 .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
192 .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
193 .flags = IORESOURCE_IRQ,
194 },
195};
196
197static struct htc_egpio_chip egpio_chips[] = {
198 [0] = {
199 .reg_start = 0,
200 .gpio_base = MAGICIAN_EGPIO(0, 0),
201 .num_gpios = 24,
202 .direction = HTC_EGPIO_OUTPUT,
203 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
204 },
205 [1] = {
206 .reg_start = 4,
207 .gpio_base = MAGICIAN_EGPIO(4, 0),
208 .num_gpios = 24,
209 .direction = HTC_EGPIO_INPUT,
210 },
211};
212
213static struct htc_egpio_platform_data egpio_info = {
214 .reg_width = 8,
215 .bus_width = 32,
216 .irq_base = IRQ_BOARD_START,
217 .num_irqs = 4,
218 .ack_register = 3,
219 .chip = egpio_chips,
220 .num_chips = ARRAY_SIZE(egpio_chips),
221};
222
223static struct platform_device egpio = {
224 .name = "htc-egpio",
225 .id = -1,
226 .resource = egpio_resources,
227 .num_resources = ARRAY_SIZE(egpio_resources),
228 .dev = {
229 .platform_data = &egpio_info,
230 },
231};
232
Philipp Zabele5c271e2007-11-22 17:59:11 +0100233/*
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100234 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
Philipp Zabele5c271e2007-11-22 17:59:11 +0100235 */
236
237static struct pxafb_mode_info toppoly_modes[] = {
238 {
239 .pixclock = 96153,
240 .bpp = 16,
241 .xres = 240,
242 .yres = 320,
243 .hsync_len = 11,
244 .vsync_len = 3,
245 .left_margin = 19,
246 .upper_margin = 2,
247 .right_margin = 10,
248 .lower_margin = 2,
249 .sync = 0,
250 },
251};
252
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100253static struct pxafb_mode_info samsung_modes[] = {
254 {
255 .pixclock = 96153,
256 .bpp = 16,
257 .xres = 240,
258 .yres = 320,
259 .hsync_len = 8,
260 .vsync_len = 4,
261 .left_margin = 9,
262 .upper_margin = 4,
263 .right_margin = 9,
264 .lower_margin = 4,
265 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
266 },
267};
268
269static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
270{
271 pr_debug("Toppoly LCD power\n");
272
273 if (on) {
274 pr_debug("on\n");
275 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
276 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
277 udelay(2000);
278 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
279 udelay(2000);
280 /* FIXME: enable LCDC here */
281 udelay(2000);
282 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
283 udelay(2000);
284 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
285 } else {
286 pr_debug("off\n");
287 msleep(15);
288 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
289 udelay(500);
290 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
291 udelay(1000);
292 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
293 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
294 }
295}
296
297static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
298{
299 pr_debug("Samsung LCD power\n");
300
301 if (on) {
302 pr_debug("on\n");
303 if (system_rev < 3)
304 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
305 else
306 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
307 mdelay(10);
308 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
309 mdelay(10);
310 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
311 mdelay(30);
312 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
313 mdelay(10);
314 } else {
315 pr_debug("off\n");
316 mdelay(10);
317 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
318 mdelay(30);
319 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
320 mdelay(10);
321 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
322 mdelay(10);
323 if (system_rev < 3)
324 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
325 else
326 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
327 }
328}
329
Philipp Zabele5c271e2007-11-22 17:59:11 +0100330static struct pxafb_mach_info toppoly_info = {
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100331 .modes = toppoly_modes,
332 .num_modes = 1,
333 .fixed_modes = 1,
334 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
335 .lccr3 = LCCR3_PixRsEdg,
336 .pxafb_lcd_power = toppoly_lcd_power,
337};
338
339static struct pxafb_mach_info samsung_info = {
340 .modes = samsung_modes,
341 .num_modes = 1,
342 .fixed_modes = 1,
343 .lccr0 = LCCR0_LDDALT | LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
344 .lccr3 = LCCR3_PixFlEdg,
345 .pxafb_lcd_power = samsung_lcd_power,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100346};
347
348/*
349 * Backlight
350 */
351
Philipp Zabel85847a32008-05-22 14:20:01 +0100352static int magician_backlight_init(struct device *dev)
Philipp Zabele5c271e2007-11-22 17:59:11 +0100353{
Philipp Zabel85847a32008-05-22 14:20:01 +0100354 int ret;
355
356 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
357 if (ret)
358 goto err;
359 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
360 if (ret)
361 goto err2;
362 return 0;
363
364err2:
365 gpio_free(EGPIO_MAGICIAN_BL_POWER);
366err:
367 return ret;
368}
369
370static int magician_backlight_notify(int brightness)
371{
372 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
373 if (brightness >= 200) {
374 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
375 return brightness - 72;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100376 } else {
Philipp Zabel85847a32008-05-22 14:20:01 +0100377 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
378 return brightness;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100379 }
380}
381
Philipp Zabel85847a32008-05-22 14:20:01 +0100382static void magician_backlight_exit(struct device *dev)
383{
384 gpio_free(EGPIO_MAGICIAN_BL_POWER);
385 gpio_free(EGPIO_MAGICIAN_BL_POWER2);
386}
387
388static struct platform_pwm_backlight_data backlight_data = {
389 .pwm_id = 0,
390 .max_brightness = 272,
391 .dft_brightness = 100,
392 .pwm_period_ns = 30923,
393 .init = magician_backlight_init,
394 .notify = magician_backlight_notify,
395 .exit = magician_backlight_exit,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100396};
397
398static struct platform_device backlight = {
Philipp Zabel85847a32008-05-22 14:20:01 +0100399 .name = "pwm-backlight",
Philipp Zabel14d10122008-06-30 18:11:55 +0100400 .id = -1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100401 .dev = {
Philipp Zabel85847a32008-05-22 14:20:01 +0100402 .parent = &pxa27x_device_pwm0.dev,
403 .platform_data = &backlight_data,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100404 },
Philipp Zabele5c271e2007-11-22 17:59:11 +0100405};
406
Philipp Zabel81447b22008-04-12 13:28:02 +0100407/*
408 * LEDs
409 */
410
411struct gpio_led gpio_leds[] = {
412 {
413 .name = "magician::vibra",
414 .default_trigger = "none",
415 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
416 },
417 {
418 .name = "magician::phone_bl",
419 .default_trigger = "none",
420 .gpio = GPIO103_MAGICIAN_LED_KP,
421 },
422};
423
424static struct gpio_led_platform_data gpio_led_info = {
425 .leds = gpio_leds,
426 .num_leds = ARRAY_SIZE(gpio_leds),
427};
428
429static struct platform_device leds_gpio = {
430 .name = "leds-gpio",
431 .id = -1,
432 .dev = {
433 .platform_data = &gpio_led_info,
434 },
435};
436
437static struct pasic3_led pasic3_leds[] = {
438 {
439 .led = {
440 .name = "magician:red",
441 .default_trigger = "ds2760-battery.0-charging",
442 },
443 .hw_num = 0,
444 .bit2 = PASIC3_BIT2_LED0,
445 .mask = PASIC3_MASK_LED0,
446 },
447 {
448 .led = {
449 .name = "magician:green",
450 .default_trigger = "ds2760-battery.0-charging-or-full",
451 },
452 .hw_num = 1,
453 .bit2 = PASIC3_BIT2_LED1,
454 .mask = PASIC3_MASK_LED1,
455 },
456 {
457 .led = {
458 .name = "magician:blue",
459 .default_trigger = "bluetooth",
460 },
461 .hw_num = 2,
462 .bit2 = PASIC3_BIT2_LED2,
463 .mask = PASIC3_MASK_LED2,
464 },
465};
466
467static struct platform_device pasic3;
468
Philipp Zabele03e0592008-04-24 18:10:46 +0100469static struct pasic3_leds_machinfo pasic3_leds_info = {
Philipp Zabel81447b22008-04-12 13:28:02 +0100470 .num_leds = ARRAY_SIZE(pasic3_leds),
471 .power_gpio = EGPIO_MAGICIAN_LED_POWER,
472 .leds = pasic3_leds,
473};
474
475/*
476 * PASIC3 with DS1WM
477 */
478
479static struct resource pasic3_resources[] = {
480 [0] = {
481 .start = PXA_CS2_PHYS,
482 .end = PXA_CS2_PHYS + 0x1b,
483 .flags = IORESOURCE_MEM,
484 },
485 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
486 [1] = {
487 .start = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
488 .end = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
489 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
490 }
491};
492
493static struct pasic3_platform_data pasic3_platform_data = {
494 .bus_shift = 2,
495 .led_pdata = &pasic3_leds_info,
496 .clock_rate = 4000000,
497};
498
499static struct platform_device pasic3 = {
500 .name = "pasic3",
501 .id = -1,
502 .num_resources = ARRAY_SIZE(pasic3_resources),
503 .resource = pasic3_resources,
504 .dev = {
505 .platform_data = &pasic3_platform_data,
506 },
507};
Philipp Zabele5c271e2007-11-22 17:59:11 +0100508
509/*
Philipp Zabel350d1152008-04-09 19:25:56 +0100510 * External power
511 */
512
Philipp Zabelff279202008-05-22 10:14:21 +0100513static int power_supply_init(struct device *dev)
514{
515 int ret;
516
517 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
518 if (ret)
519 goto err_cs_ac;
520 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB, "CABLE_STATE_USB");
521 if (ret)
522 goto err_cs_usb;
523 ret = gpio_request(EGPIO_MAGICIAN_CHARGE_EN, "CHARGE_EN");
524 if (ret)
525 goto err_chg_en;
526 ret = gpio_request(GPIO30_MAGICIAN_nCHARGE_EN, "nCHARGE_EN");
527 if (!ret)
528 ret = gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN, 0);
529 if (ret)
530 goto err_nchg_en;
531
532 return 0;
533
534err_nchg_en:
535 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
536err_chg_en:
537 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
538err_cs_usb:
539 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
540err_cs_ac:
541 return ret;
542}
543
Philipp Zabel350d1152008-04-09 19:25:56 +0100544static int magician_is_ac_online(void)
545{
546 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
547}
548
549static int magician_is_usb_online(void)
550{
551 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
552}
553
554static void magician_set_charge(int flags)
555{
556 gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
557 gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
558}
559
Philipp Zabelff279202008-05-22 10:14:21 +0100560static void power_supply_exit(struct device *dev)
561{
562 gpio_free(GPIO30_MAGICIAN_nCHARGE_EN);
563 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
564 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
565 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
566}
567
Philipp Zabel81447b22008-04-12 13:28:02 +0100568static char *magician_supplicants[] = {
569 "ds2760-battery.0", "backup-battery"
570};
571
Philipp Zabel350d1152008-04-09 19:25:56 +0100572static struct pda_power_pdata power_supply_info = {
Philipp Zabelff279202008-05-22 10:14:21 +0100573 .init = power_supply_init,
Philipp Zabel81447b22008-04-12 13:28:02 +0100574 .is_ac_online = magician_is_ac_online,
575 .is_usb_online = magician_is_usb_online,
576 .set_charge = magician_set_charge,
Philipp Zabelff279202008-05-22 10:14:21 +0100577 .exit = power_supply_exit,
Philipp Zabel81447b22008-04-12 13:28:02 +0100578 .supplied_to = magician_supplicants,
579 .num_supplicants = ARRAY_SIZE(magician_supplicants),
Philipp Zabel350d1152008-04-09 19:25:56 +0100580};
581
582static struct resource power_supply_resources[] = {
583 [0] = {
584 .name = "ac",
585 .flags = IORESOURCE_IRQ,
586 .start = IRQ_MAGICIAN_AC,
587 .end = IRQ_MAGICIAN_AC,
588 },
589 [1] = {
590 .name = "usb",
591 .flags = IORESOURCE_IRQ,
592 .start = IRQ_MAGICIAN_AC,
593 .end = IRQ_MAGICIAN_AC,
594 },
595};
596
597static struct platform_device power_supply = {
598 .name = "pda-power",
599 .id = -1,
600 .dev = {
601 .platform_data = &power_supply_info,
602 },
603 .resource = power_supply_resources,
604 .num_resources = ARRAY_SIZE(power_supply_resources),
605};
606
607
608/*
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100609 * MMC/SD
610 */
611
612static int magician_mci_init(struct device *dev,
613 irq_handler_t detect_irq, void *data)
614{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100615 int err;
616
617 err = request_irq(IRQ_MAGICIAN_SD, detect_irq,
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100618 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
619 "MMC card detect", data);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100620 if (err)
621 goto err_request_irq;
622 err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER");
623 if (err)
624 goto err_request_power;
625 err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY");
626 if (err)
627 goto err_request_readonly;
628
629 return 0;
630
631err_request_readonly:
632 gpio_free(EGPIO_MAGICIAN_SD_POWER);
633err_request_power:
634 free_irq(IRQ_MAGICIAN_SD, data);
635err_request_irq:
636 return err;
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100637}
638
639static void magician_mci_setpower(struct device *dev, unsigned int vdd)
640{
641 struct pxamci_platform_data *pdata = dev->platform_data;
642
643 gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
644}
645
646static int magician_mci_get_ro(struct device *dev)
647{
648 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
649}
650
651static void magician_mci_exit(struct device *dev, void *data)
652{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100653 gpio_free(EGPIO_MAGICIAN_nSD_READONLY);
654 gpio_free(EGPIO_MAGICIAN_SD_POWER);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100655 free_irq(IRQ_MAGICIAN_SD, data);
656}
657
658static struct pxamci_platform_data magician_mci_info = {
659 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
660 .init = magician_mci_init,
661 .get_ro = magician_mci_get_ro,
662 .setpower = magician_mci_setpower,
663 .exit = magician_mci_exit,
664};
665
666
667/*
Philipp Zabele5c271e2007-11-22 17:59:11 +0100668 * USB OHCI
669 */
670
671static int magician_ohci_init(struct device *dev)
672{
673 UHCHR = (UHCHR | UHCHR_SSEP2 | UHCHR_PCPL | UHCHR_CGR) &
674 ~(UHCHR_SSEP1 | UHCHR_SSEP3 | UHCHR_SSE);
675
676 return 0;
677}
678
679static struct pxaohci_platform_data magician_ohci_info = {
680 .port_mode = PMM_PERPORT_MODE,
681 .init = magician_ohci_init,
682 .power_budget = 0,
683};
684
685
686/*
687 * StrataFlash
688 */
689
Philipp Zabelaa797592008-04-09 19:24:05 +0100690static void magician_set_vpp(struct map_info *map, int vpp)
691{
692 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
693}
694
Philipp Zabele5c271e2007-11-22 17:59:11 +0100695#define PXA_CS_SIZE 0x04000000
696
697static struct resource strataflash_resource = {
698 .start = PXA_CS0_PHYS,
699 .end = PXA_CS0_PHYS + PXA_CS_SIZE - 1,
700 .flags = IORESOURCE_MEM,
701};
702
703static struct physmap_flash_data strataflash_data = {
704 .width = 4,
Philipp Zabelaa797592008-04-09 19:24:05 +0100705 .set_vpp = magician_set_vpp,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100706};
707
708static struct platform_device strataflash = {
709 .name = "physmap-flash",
710 .id = -1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100711 .resource = &strataflash_resource,
Philipp Zabel70e357f2008-04-09 19:22:57 +0100712 .num_resources = 1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100713 .dev = {
714 .platform_data = &strataflash_data,
715 },
716};
717
718/*
719 * Platform devices
720 */
721
722static struct platform_device *devices[] __initdata = {
723 &gpio_keys,
Philipp Zabel70e357f2008-04-09 19:22:57 +0100724 &egpio,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100725 &backlight,
Philipp Zabel81447b22008-04-12 13:28:02 +0100726 &pasic3,
Philipp Zabel350d1152008-04-09 19:25:56 +0100727 &power_supply,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100728 &strataflash,
Philipp Zabel81447b22008-04-12 13:28:02 +0100729 &leds_gpio,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100730};
731
732static void __init magician_init(void)
733{
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100734 void __iomem *cpld;
735 int lcd_select;
Philipp Zabela1999cd2008-04-20 17:39:12 +0100736 int err;
737
738 gpio_request(GPIO13_MAGICIAN_CPLD_IRQ, "CPLD_IRQ");
739 gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ, "DS1WM_IRQ");
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100740
Philipp Zabelb1682812008-04-12 13:29:22 +0100741 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
742
Philipp Zabele5c271e2007-11-22 17:59:11 +0100743 platform_add_devices(devices, ARRAY_SIZE(devices));
Philipp Zabela1999cd2008-04-20 17:39:12 +0100744
745 err = gpio_request(GPIO83_MAGICIAN_nIR_EN, "nIR_EN");
746 if (!err) {
747 gpio_direction_output(GPIO83_MAGICIAN_nIR_EN, 1);
748 pxa_set_ficp_info(&magician_ficp_info);
749 }
Philipp Zabele6816f32008-04-09 19:14:15 +0100750 pxa_set_i2c_info(NULL);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100751 pxa_set_mci_info(&magician_mci_info);
Philipp Zabele5c271e2007-11-22 17:59:11 +0100752 pxa_set_ohci_info(&magician_ohci_info);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100753
754 /* Check LCD type we have */
755 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
756 if (cpld) {
757 u8 board_id = __raw_readb(cpld+0x14);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100758 iounmap(cpld);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100759 system_rev = board_id & 0x7;
760 lcd_select = board_id & 0x8;
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100761 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
Philipp Zabela1999cd2008-04-20 17:39:12 +0100762 if (lcd_select && (system_rev < 3)) {
763 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER");
764 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
765 }
766 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1");
767 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2");
768 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3");
769 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0);
770 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0);
771 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100772 set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
773 } else
774 pr_err("LCD detection: CPLD mapping failed\n");
Philipp Zabele5c271e2007-11-22 17:59:11 +0100775}
776
777
778MACHINE_START(MAGICIAN, "HTC Magician")
779 .phys_io = 0x40000000,
780 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
781 .boot_params = 0xa0000100,
782 .map_io = pxa_map_io,
783 .init_irq = pxa27x_init_irq,
784 .init_machine = magician_init,
785 .timer = &pxa_timer,
786MACHINE_END