blob: 2dc14c361c14c53a6f7601b515aeb9676b2aa997 [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/mtd.h>
26#include <linux/mtd/map.h>
27#include <linux/mtd/physmap.h>
Philipp Zabel350d1152008-04-09 19:25:56 +010028#include <linux/pda_power.h>
Philipp Zabel85847a32008-05-22 14:20:01 +010029#include <linux/pwm_backlight.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010030
Philipp Zabele5c271e2007-11-22 17:59:11 +010031#include <asm/hardware.h>
32#include <asm/mach-types.h>
33#include <asm/mach/arch.h>
34#include <asm/arch/magician.h>
Philipp Zabelb1682812008-04-12 13:29:22 +010035#include <asm/arch/mfp-pxa27x.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010036#include <asm/arch/pxa-regs.h>
Russell King0b0a9df2008-05-18 14:59:36 +010037#include <asm/arch/pxa2xx-regs.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010038#include <asm/arch/pxafb.h>
Philipp Zabele6816f32008-04-09 19:14:15 +010039#include <asm/arch/i2c.h>
Philipp Zabelbdb0c162008-04-09 19:24:55 +010040#include <asm/arch/mmc.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010041#include <asm/arch/irda.h>
42#include <asm/arch/ohci.h>
43
Philipp Zabel85847a32008-05-22 14:20:01 +010044#include "devices.h"
Philipp Zabele5c271e2007-11-22 17:59:11 +010045#include "generic.h"
46
Philipp Zabel7a970102008-06-26 21:03:54 +010047static unsigned long magician_pin_config[] __initdata = {
Philipp Zabelb1682812008-04-12 13:29:22 +010048
49 /* SDRAM and Static Memory I/O Signals */
50 GPIO20_nSDCS_2,
51 GPIO21_nSDCS_3,
52 GPIO15_nCS_1,
53 GPIO78_nCS_2, /* PASIC3 */
54 GPIO79_nCS_3, /* EGPIO CPLD */
55 GPIO80_nCS_4,
56 GPIO33_nCS_5,
57
58 /* I2C */
59 GPIO117_I2C_SCL,
60 GPIO118_I2C_SDA,
61
62 /* PWM 0 */
63 GPIO16_PWM0_OUT,
64
65 /* I2S */
66 GPIO28_I2S_BITCLK_OUT,
67 GPIO29_I2S_SDATA_IN,
68 GPIO31_I2S_SYNC,
69 GPIO113_I2S_SYSCLK,
70
71 /* SSP 2 */
72 GPIO19_SSP2_SCLK,
73 GPIO14_SSP2_SFRM,
74 GPIO89_SSP2_TXD,
75 GPIO88_SSP2_RXD,
76
77 /* MMC */
78 GPIO32_MMC_CLK,
79 GPIO92_MMC_DAT_0,
80 GPIO109_MMC_DAT_1,
81 GPIO110_MMC_DAT_2,
82 GPIO111_MMC_DAT_3,
83 GPIO112_MMC_CMD,
84
85 /* LCD */
86 GPIO58_LCD_LDD_0,
87 GPIO59_LCD_LDD_1,
88 GPIO60_LCD_LDD_2,
89 GPIO61_LCD_LDD_3,
90 GPIO62_LCD_LDD_4,
91 GPIO63_LCD_LDD_5,
92 GPIO64_LCD_LDD_6,
93 GPIO65_LCD_LDD_7,
94 GPIO66_LCD_LDD_8,
95 GPIO67_LCD_LDD_9,
96 GPIO68_LCD_LDD_10,
97 GPIO69_LCD_LDD_11,
98 GPIO70_LCD_LDD_12,
99 GPIO71_LCD_LDD_13,
100 GPIO72_LCD_LDD_14,
101 GPIO73_LCD_LDD_15,
102 GPIO74_LCD_FCLK,
103 GPIO75_LCD_LCLK,
104 GPIO76_LCD_PCLK,
105 GPIO77_LCD_BIAS,
106
107 /* QCI */
108 GPIO12_CIF_DD_7,
109 GPIO17_CIF_DD_6,
110 GPIO50_CIF_DD_3,
111 GPIO51_CIF_DD_2,
112 GPIO52_CIF_DD_4,
113 GPIO53_CIF_MCLK,
114 GPIO54_CIF_PCLK,
115 GPIO55_CIF_DD_1,
116 GPIO81_CIF_DD_0,
117 GPIO82_CIF_DD_5,
118 GPIO84_CIF_FV,
119 GPIO85_CIF_LV,
Philipp Zabel2f131952008-04-20 17:40:11 +0100120
121 /* Magician specific input GPIOs */
122 GPIO9_GPIO, /* unknown */
123 GPIO10_GPIO, /* GSM_IRQ */
124 GPIO13_GPIO, /* CPLD_IRQ */
125 GPIO107_GPIO, /* DS1WM_IRQ */
126 GPIO108_GPIO, /* GSM_READY */
127 GPIO115_GPIO, /* nPEN_IRQ */
Philipp Zabelb1682812008-04-12 13:29:22 +0100128};
129
Philipp Zabele5c271e2007-11-22 17:59:11 +0100130/*
131 * IRDA
132 */
133
134static void magician_irda_transceiver_mode(struct device *dev, int mode)
135{
136 gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
137}
138
139static struct pxaficp_platform_data magician_ficp_info = {
140 .transceiver_cap = IR_SIRMODE | IR_OFF,
141 .transceiver_mode = magician_irda_transceiver_mode,
142};
143
144/*
145 * GPIO Keys
146 */
147
148static struct gpio_keys_button magician_button_table[] = {
149 {KEY_POWER, GPIO0_MAGICIAN_KEY_POWER, 0, "Power button"},
150 {KEY_ESC, GPIO37_MAGICIAN_KEY_HANGUP, 0, "Hangup button"},
151 {KEY_F10, GPIO38_MAGICIAN_KEY_CONTACTS, 0, "Contacts button"},
152 {KEY_CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, 0, "Calendar button"},
153 {KEY_CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, 0, "Camera button"},
154 {KEY_UP, GPIO93_MAGICIAN_KEY_UP, 0, "Up button"},
155 {KEY_DOWN, GPIO94_MAGICIAN_KEY_DOWN, 0, "Down button"},
156 {KEY_LEFT, GPIO95_MAGICIAN_KEY_LEFT, 0, "Left button"},
157 {KEY_RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, 0, "Right button"},
158 {KEY_KPENTER, GPIO97_MAGICIAN_KEY_ENTER, 0, "Action button"},
159 {KEY_RECORD, GPIO98_MAGICIAN_KEY_RECORD, 0, "Record button"},
160 {KEY_VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, 0, "Volume up"},
161 {KEY_VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, 0, "Volume down"},
162 {KEY_PHONE, GPIO102_MAGICIAN_KEY_PHONE, 0, "Phone button"},
163 {KEY_PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, 0, "Headset button"},
164};
165
166static struct gpio_keys_platform_data gpio_keys_data = {
167 .buttons = magician_button_table,
168 .nbuttons = ARRAY_SIZE(magician_button_table),
169};
170
171static struct platform_device gpio_keys = {
172 .name = "gpio-keys",
173 .dev = {
174 .platform_data = &gpio_keys_data,
175 },
176 .id = -1,
177};
178
Philipp Zabel70e357f2008-04-09 19:22:57 +0100179
180/*
181 * EGPIO (Xilinx CPLD)
182 *
183 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
184 */
185
186static struct resource egpio_resources[] = {
187 [0] = {
188 .start = PXA_CS3_PHYS,
189 .end = PXA_CS3_PHYS + 0x20,
190 .flags = IORESOURCE_MEM,
191 },
192 [1] = {
193 .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
194 .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
195 .flags = IORESOURCE_IRQ,
196 },
197};
198
199static struct htc_egpio_chip egpio_chips[] = {
200 [0] = {
201 .reg_start = 0,
202 .gpio_base = MAGICIAN_EGPIO(0, 0),
203 .num_gpios = 24,
204 .direction = HTC_EGPIO_OUTPUT,
205 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
206 },
207 [1] = {
208 .reg_start = 4,
209 .gpio_base = MAGICIAN_EGPIO(4, 0),
210 .num_gpios = 24,
211 .direction = HTC_EGPIO_INPUT,
212 },
213};
214
215static struct htc_egpio_platform_data egpio_info = {
216 .reg_width = 8,
217 .bus_width = 32,
218 .irq_base = IRQ_BOARD_START,
219 .num_irqs = 4,
220 .ack_register = 3,
221 .chip = egpio_chips,
222 .num_chips = ARRAY_SIZE(egpio_chips),
223};
224
225static struct platform_device egpio = {
226 .name = "htc-egpio",
227 .id = -1,
228 .resource = egpio_resources,
229 .num_resources = ARRAY_SIZE(egpio_resources),
230 .dev = {
231 .platform_data = &egpio_info,
232 },
233};
234
Philipp Zabele5c271e2007-11-22 17:59:11 +0100235/*
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100236 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
Philipp Zabele5c271e2007-11-22 17:59:11 +0100237 */
238
239static struct pxafb_mode_info toppoly_modes[] = {
240 {
241 .pixclock = 96153,
242 .bpp = 16,
243 .xres = 240,
244 .yres = 320,
245 .hsync_len = 11,
246 .vsync_len = 3,
247 .left_margin = 19,
248 .upper_margin = 2,
249 .right_margin = 10,
250 .lower_margin = 2,
251 .sync = 0,
252 },
253};
254
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100255static struct pxafb_mode_info samsung_modes[] = {
256 {
257 .pixclock = 96153,
258 .bpp = 16,
259 .xres = 240,
260 .yres = 320,
261 .hsync_len = 8,
262 .vsync_len = 4,
263 .left_margin = 9,
264 .upper_margin = 4,
265 .right_margin = 9,
266 .lower_margin = 4,
267 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
268 },
269};
270
271static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
272{
273 pr_debug("Toppoly LCD power\n");
274
275 if (on) {
276 pr_debug("on\n");
277 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
278 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
279 udelay(2000);
280 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
281 udelay(2000);
282 /* FIXME: enable LCDC here */
283 udelay(2000);
284 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
285 udelay(2000);
286 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
287 } else {
288 pr_debug("off\n");
289 msleep(15);
290 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
291 udelay(500);
292 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
293 udelay(1000);
294 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
295 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
296 }
297}
298
299static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
300{
301 pr_debug("Samsung LCD power\n");
302
303 if (on) {
304 pr_debug("on\n");
305 if (system_rev < 3)
306 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
307 else
308 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
309 mdelay(10);
310 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
311 mdelay(10);
312 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
313 mdelay(30);
314 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
315 mdelay(10);
316 } else {
317 pr_debug("off\n");
318 mdelay(10);
319 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
320 mdelay(30);
321 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
322 mdelay(10);
323 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
324 mdelay(10);
325 if (system_rev < 3)
326 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
327 else
328 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
329 }
330}
331
Philipp Zabele5c271e2007-11-22 17:59:11 +0100332static struct pxafb_mach_info toppoly_info = {
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100333 .modes = toppoly_modes,
334 .num_modes = 1,
335 .fixed_modes = 1,
336 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
337 .lccr3 = LCCR3_PixRsEdg,
338 .pxafb_lcd_power = toppoly_lcd_power,
339};
340
341static struct pxafb_mach_info samsung_info = {
342 .modes = samsung_modes,
343 .num_modes = 1,
344 .fixed_modes = 1,
345 .lccr0 = LCCR0_LDDALT | LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
346 .lccr3 = LCCR3_PixFlEdg,
347 .pxafb_lcd_power = samsung_lcd_power,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100348};
349
350/*
351 * Backlight
352 */
353
Philipp Zabel85847a32008-05-22 14:20:01 +0100354static int magician_backlight_init(struct device *dev)
Philipp Zabele5c271e2007-11-22 17:59:11 +0100355{
Philipp Zabel85847a32008-05-22 14:20:01 +0100356 int ret;
357
358 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
359 if (ret)
360 goto err;
361 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
362 if (ret)
363 goto err2;
364 return 0;
365
366err2:
367 gpio_free(EGPIO_MAGICIAN_BL_POWER);
368err:
369 return ret;
370}
371
372static int magician_backlight_notify(int brightness)
373{
374 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
375 if (brightness >= 200) {
376 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
377 return brightness - 72;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100378 } else {
Philipp Zabel85847a32008-05-22 14:20:01 +0100379 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
380 return brightness;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100381 }
382}
383
Philipp Zabel85847a32008-05-22 14:20:01 +0100384static void magician_backlight_exit(struct device *dev)
385{
386 gpio_free(EGPIO_MAGICIAN_BL_POWER);
387 gpio_free(EGPIO_MAGICIAN_BL_POWER2);
388}
389
390static struct platform_pwm_backlight_data backlight_data = {
391 .pwm_id = 0,
392 .max_brightness = 272,
393 .dft_brightness = 100,
394 .pwm_period_ns = 30923,
395 .init = magician_backlight_init,
396 .notify = magician_backlight_notify,
397 .exit = magician_backlight_exit,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100398};
399
400static struct platform_device backlight = {
Philipp Zabel85847a32008-05-22 14:20:01 +0100401 .name = "pwm-backlight",
Philipp Zabele5c271e2007-11-22 17:59:11 +0100402 .dev = {
Philipp Zabel85847a32008-05-22 14:20:01 +0100403 .parent = &pxa27x_device_pwm0.dev,
404 .platform_data = &backlight_data,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100405 },
Philipp Zabele5c271e2007-11-22 17:59:11 +0100406};
407
Philipp Zabel81447b22008-04-12 13:28:02 +0100408/*
409 * LEDs
410 */
411
412struct gpio_led gpio_leds[] = {
413 {
414 .name = "magician::vibra",
415 .default_trigger = "none",
416 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
417 },
418 {
419 .name = "magician::phone_bl",
420 .default_trigger = "none",
421 .gpio = GPIO103_MAGICIAN_LED_KP,
422 },
423};
424
425static struct gpio_led_platform_data gpio_led_info = {
426 .leds = gpio_leds,
427 .num_leds = ARRAY_SIZE(gpio_leds),
428};
429
430static struct platform_device leds_gpio = {
431 .name = "leds-gpio",
432 .id = -1,
433 .dev = {
434 .platform_data = &gpio_led_info,
435 },
436};
437
438static struct pasic3_led pasic3_leds[] = {
439 {
440 .led = {
441 .name = "magician:red",
442 .default_trigger = "ds2760-battery.0-charging",
443 },
444 .hw_num = 0,
445 .bit2 = PASIC3_BIT2_LED0,
446 .mask = PASIC3_MASK_LED0,
447 },
448 {
449 .led = {
450 .name = "magician:green",
451 .default_trigger = "ds2760-battery.0-charging-or-full",
452 },
453 .hw_num = 1,
454 .bit2 = PASIC3_BIT2_LED1,
455 .mask = PASIC3_MASK_LED1,
456 },
457 {
458 .led = {
459 .name = "magician:blue",
460 .default_trigger = "bluetooth",
461 },
462 .hw_num = 2,
463 .bit2 = PASIC3_BIT2_LED2,
464 .mask = PASIC3_MASK_LED2,
465 },
466};
467
468static struct platform_device pasic3;
469
Philipp Zabele03e0592008-04-24 18:10:46 +0100470static struct pasic3_leds_machinfo pasic3_leds_info = {
Philipp Zabel81447b22008-04-12 13:28:02 +0100471 .num_leds = ARRAY_SIZE(pasic3_leds),
472 .power_gpio = EGPIO_MAGICIAN_LED_POWER,
473 .leds = pasic3_leds,
474};
475
476/*
477 * PASIC3 with DS1WM
478 */
479
480static struct resource pasic3_resources[] = {
481 [0] = {
482 .start = PXA_CS2_PHYS,
483 .end = PXA_CS2_PHYS + 0x1b,
484 .flags = IORESOURCE_MEM,
485 },
486 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
487 [1] = {
488 .start = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
489 .end = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
490 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
491 }
492};
493
494static struct pasic3_platform_data pasic3_platform_data = {
495 .bus_shift = 2,
496 .led_pdata = &pasic3_leds_info,
497 .clock_rate = 4000000,
498};
499
500static struct platform_device pasic3 = {
501 .name = "pasic3",
502 .id = -1,
503 .num_resources = ARRAY_SIZE(pasic3_resources),
504 .resource = pasic3_resources,
505 .dev = {
506 .platform_data = &pasic3_platform_data,
507 },
508};
Philipp Zabele5c271e2007-11-22 17:59:11 +0100509
510/*
Philipp Zabel350d1152008-04-09 19:25:56 +0100511 * External power
512 */
513
Philipp Zabelff279202008-05-22 10:14:21 +0100514static int power_supply_init(struct device *dev)
515{
516 int ret;
517
518 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
519 if (ret)
520 goto err_cs_ac;
521 ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB, "CABLE_STATE_USB");
522 if (ret)
523 goto err_cs_usb;
524 ret = gpio_request(EGPIO_MAGICIAN_CHARGE_EN, "CHARGE_EN");
525 if (ret)
526 goto err_chg_en;
527 ret = gpio_request(GPIO30_MAGICIAN_nCHARGE_EN, "nCHARGE_EN");
528 if (!ret)
529 ret = gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN, 0);
530 if (ret)
531 goto err_nchg_en;
532
533 return 0;
534
535err_nchg_en:
536 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
537err_chg_en:
538 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
539err_cs_usb:
540 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
541err_cs_ac:
542 return ret;
543}
544
Philipp Zabel350d1152008-04-09 19:25:56 +0100545static int magician_is_ac_online(void)
546{
547 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
548}
549
550static int magician_is_usb_online(void)
551{
552 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
553}
554
555static void magician_set_charge(int flags)
556{
557 gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
558 gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
559}
560
Philipp Zabelff279202008-05-22 10:14:21 +0100561static void power_supply_exit(struct device *dev)
562{
563 gpio_free(GPIO30_MAGICIAN_nCHARGE_EN);
564 gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
565 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
566 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
567}
568
Philipp Zabel81447b22008-04-12 13:28:02 +0100569static char *magician_supplicants[] = {
570 "ds2760-battery.0", "backup-battery"
571};
572
Philipp Zabel350d1152008-04-09 19:25:56 +0100573static struct pda_power_pdata power_supply_info = {
Philipp Zabelff279202008-05-22 10:14:21 +0100574 .init = power_supply_init,
Philipp Zabel81447b22008-04-12 13:28:02 +0100575 .is_ac_online = magician_is_ac_online,
576 .is_usb_online = magician_is_usb_online,
577 .set_charge = magician_set_charge,
Philipp Zabelff279202008-05-22 10:14:21 +0100578 .exit = power_supply_exit,
Philipp Zabel81447b22008-04-12 13:28:02 +0100579 .supplied_to = magician_supplicants,
580 .num_supplicants = ARRAY_SIZE(magician_supplicants),
Philipp Zabel350d1152008-04-09 19:25:56 +0100581};
582
583static struct resource power_supply_resources[] = {
584 [0] = {
585 .name = "ac",
586 .flags = IORESOURCE_IRQ,
587 .start = IRQ_MAGICIAN_AC,
588 .end = IRQ_MAGICIAN_AC,
589 },
590 [1] = {
591 .name = "usb",
592 .flags = IORESOURCE_IRQ,
593 .start = IRQ_MAGICIAN_AC,
594 .end = IRQ_MAGICIAN_AC,
595 },
596};
597
598static struct platform_device power_supply = {
599 .name = "pda-power",
600 .id = -1,
601 .dev = {
602 .platform_data = &power_supply_info,
603 },
604 .resource = power_supply_resources,
605 .num_resources = ARRAY_SIZE(power_supply_resources),
606};
607
608
609/*
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100610 * MMC/SD
611 */
612
613static int magician_mci_init(struct device *dev,
614 irq_handler_t detect_irq, void *data)
615{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100616 int err;
617
618 err = request_irq(IRQ_MAGICIAN_SD, detect_irq,
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100619 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
620 "MMC card detect", data);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100621 if (err)
622 goto err_request_irq;
623 err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER");
624 if (err)
625 goto err_request_power;
626 err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY");
627 if (err)
628 goto err_request_readonly;
629
630 return 0;
631
632err_request_readonly:
633 gpio_free(EGPIO_MAGICIAN_SD_POWER);
634err_request_power:
635 free_irq(IRQ_MAGICIAN_SD, data);
636err_request_irq:
637 return err;
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100638}
639
640static void magician_mci_setpower(struct device *dev, unsigned int vdd)
641{
642 struct pxamci_platform_data *pdata = dev->platform_data;
643
644 gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
645}
646
647static int magician_mci_get_ro(struct device *dev)
648{
649 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
650}
651
652static void magician_mci_exit(struct device *dev, void *data)
653{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100654 gpio_free(EGPIO_MAGICIAN_nSD_READONLY);
655 gpio_free(EGPIO_MAGICIAN_SD_POWER);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100656 free_irq(IRQ_MAGICIAN_SD, data);
657}
658
659static struct pxamci_platform_data magician_mci_info = {
660 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
661 .init = magician_mci_init,
662 .get_ro = magician_mci_get_ro,
663 .setpower = magician_mci_setpower,
664 .exit = magician_mci_exit,
665};
666
667
668/*
Philipp Zabele5c271e2007-11-22 17:59:11 +0100669 * USB OHCI
670 */
671
672static int magician_ohci_init(struct device *dev)
673{
674 UHCHR = (UHCHR | UHCHR_SSEP2 | UHCHR_PCPL | UHCHR_CGR) &
675 ~(UHCHR_SSEP1 | UHCHR_SSEP3 | UHCHR_SSE);
676
677 return 0;
678}
679
680static struct pxaohci_platform_data magician_ohci_info = {
681 .port_mode = PMM_PERPORT_MODE,
682 .init = magician_ohci_init,
683 .power_budget = 0,
684};
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 Zabele6816f32008-04-09 19:14:15 +0100751 pxa_set_i2c_info(NULL);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100752 pxa_set_mci_info(&magician_mci_info);
Philipp Zabele5c271e2007-11-22 17:59:11 +0100753 pxa_set_ohci_info(&magician_ohci_info);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100754
755 /* Check LCD type we have */
756 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
757 if (cpld) {
758 u8 board_id = __raw_readb(cpld+0x14);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100759 iounmap(cpld);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100760 system_rev = board_id & 0x7;
761 lcd_select = board_id & 0x8;
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100762 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
Philipp Zabela1999cd2008-04-20 17:39:12 +0100763 if (lcd_select && (system_rev < 3)) {
764 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER");
765 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
766 }
767 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1");
768 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2");
769 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3");
770 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0);
771 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0);
772 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0);
Philipp Zabele07ff8d82008-04-09 19:27:10 +0100773 set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
774 } else
775 pr_err("LCD detection: CPLD mapping failed\n");
Philipp Zabele5c271e2007-11-22 17:59:11 +0100776}
777
778
779MACHINE_START(MAGICIAN, "HTC Magician")
780 .phys_io = 0x40000000,
781 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
782 .boot_params = 0xa0000100,
783 .map_io = pxa_map_io,
784 .init_irq = pxa27x_init_irq,
785 .init_machine = magician_init,
786 .timer = &pxa_timer,
787MACHINE_END