blob: 300caeb21371a4b8833404c3a1247ad28cb697d8 [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 Zabele07ff8d2008-04-09 19:27:10 +010019#include <linux/delay.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010020#include <linux/gpio_keys.h>
21#include <linux/input.h>
Philipp Zabel70e357f2008-04-09 19:22:57 +010022#include <linux/mfd/htc-egpio.h>
Philipp Zabel81447b22008-04-12 13:28:02 +010023#include <linux/mfd/htc-pasic3.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010024#include <linux/mtd/mtd.h>
25#include <linux/mtd/map.h>
26#include <linux/mtd/physmap.h>
Philipp Zabel350d1152008-04-09 19:25:56 +010027#include <linux/pda_power.h>
Philipp Zabel85847a32008-05-22 14:20:01 +010028#include <linux/pwm_backlight.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010029
30#include <asm/gpio.h>
31#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>
37#include <asm/arch/pxafb.h>
Philipp Zabele6816f32008-04-09 19:14:15 +010038#include <asm/arch/i2c.h>
Philipp Zabelbdb0c162008-04-09 19:24:55 +010039#include <asm/arch/mmc.h>
Philipp Zabele5c271e2007-11-22 17:59:11 +010040#include <asm/arch/irda.h>
41#include <asm/arch/ohci.h>
42
Philipp Zabel85847a32008-05-22 14:20:01 +010043#include "devices.h"
Philipp Zabele5c271e2007-11-22 17:59:11 +010044#include "generic.h"
45
Philipp Zabelb1682812008-04-12 13:29:22 +010046static unsigned long magician_pin_config[] = {
47
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
70 /* SSP 2 */
71 GPIO19_SSP2_SCLK,
72 GPIO14_SSP2_SFRM,
73 GPIO89_SSP2_TXD,
74 GPIO88_SSP2_RXD,
75
76 /* MMC */
77 GPIO32_MMC_CLK,
78 GPIO92_MMC_DAT_0,
79 GPIO109_MMC_DAT_1,
80 GPIO110_MMC_DAT_2,
81 GPIO111_MMC_DAT_3,
82 GPIO112_MMC_CMD,
83
84 /* LCD */
85 GPIO58_LCD_LDD_0,
86 GPIO59_LCD_LDD_1,
87 GPIO60_LCD_LDD_2,
88 GPIO61_LCD_LDD_3,
89 GPIO62_LCD_LDD_4,
90 GPIO63_LCD_LDD_5,
91 GPIO64_LCD_LDD_6,
92 GPIO65_LCD_LDD_7,
93 GPIO66_LCD_LDD_8,
94 GPIO67_LCD_LDD_9,
95 GPIO68_LCD_LDD_10,
96 GPIO69_LCD_LDD_11,
97 GPIO70_LCD_LDD_12,
98 GPIO71_LCD_LDD_13,
99 GPIO72_LCD_LDD_14,
100 GPIO73_LCD_LDD_15,
101 GPIO74_LCD_FCLK,
102 GPIO75_LCD_LCLK,
103 GPIO76_LCD_PCLK,
104 GPIO77_LCD_BIAS,
105
106 /* QCI */
107 GPIO12_CIF_DD_7,
108 GPIO17_CIF_DD_6,
109 GPIO50_CIF_DD_3,
110 GPIO51_CIF_DD_2,
111 GPIO52_CIF_DD_4,
112 GPIO53_CIF_MCLK,
113 GPIO54_CIF_PCLK,
114 GPIO55_CIF_DD_1,
115 GPIO81_CIF_DD_0,
116 GPIO82_CIF_DD_5,
117 GPIO84_CIF_FV,
118 GPIO85_CIF_LV,
Philipp Zabel2f131952008-04-20 17:40:11 +0100119
120 /* Magician specific input GPIOs */
121 GPIO9_GPIO, /* unknown */
122 GPIO10_GPIO, /* GSM_IRQ */
123 GPIO13_GPIO, /* CPLD_IRQ */
124 GPIO107_GPIO, /* DS1WM_IRQ */
125 GPIO108_GPIO, /* GSM_READY */
126 GPIO115_GPIO, /* nPEN_IRQ */
Philipp Zabelb1682812008-04-12 13:29:22 +0100127};
128
Philipp Zabele5c271e2007-11-22 17:59:11 +0100129/*
130 * IRDA
131 */
132
133static void magician_irda_transceiver_mode(struct device *dev, int mode)
134{
135 gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
136}
137
138static struct pxaficp_platform_data magician_ficp_info = {
139 .transceiver_cap = IR_SIRMODE | IR_OFF,
140 .transceiver_mode = magician_irda_transceiver_mode,
141};
142
143/*
144 * GPIO Keys
145 */
146
147static struct gpio_keys_button magician_button_table[] = {
148 {KEY_POWER, GPIO0_MAGICIAN_KEY_POWER, 0, "Power button"},
149 {KEY_ESC, GPIO37_MAGICIAN_KEY_HANGUP, 0, "Hangup button"},
150 {KEY_F10, GPIO38_MAGICIAN_KEY_CONTACTS, 0, "Contacts button"},
151 {KEY_CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, 0, "Calendar button"},
152 {KEY_CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, 0, "Camera button"},
153 {KEY_UP, GPIO93_MAGICIAN_KEY_UP, 0, "Up button"},
154 {KEY_DOWN, GPIO94_MAGICIAN_KEY_DOWN, 0, "Down button"},
155 {KEY_LEFT, GPIO95_MAGICIAN_KEY_LEFT, 0, "Left button"},
156 {KEY_RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, 0, "Right button"},
157 {KEY_KPENTER, GPIO97_MAGICIAN_KEY_ENTER, 0, "Action button"},
158 {KEY_RECORD, GPIO98_MAGICIAN_KEY_RECORD, 0, "Record button"},
159 {KEY_VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, 0, "Volume up"},
160 {KEY_VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, 0, "Volume down"},
161 {KEY_PHONE, GPIO102_MAGICIAN_KEY_PHONE, 0, "Phone button"},
162 {KEY_PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, 0, "Headset button"},
163};
164
165static struct gpio_keys_platform_data gpio_keys_data = {
166 .buttons = magician_button_table,
167 .nbuttons = ARRAY_SIZE(magician_button_table),
168};
169
170static struct platform_device gpio_keys = {
171 .name = "gpio-keys",
172 .dev = {
173 .platform_data = &gpio_keys_data,
174 },
175 .id = -1,
176};
177
Philipp Zabel70e357f2008-04-09 19:22:57 +0100178
179/*
180 * EGPIO (Xilinx CPLD)
181 *
182 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
183 */
184
185static struct resource egpio_resources[] = {
186 [0] = {
187 .start = PXA_CS3_PHYS,
188 .end = PXA_CS3_PHYS + 0x20,
189 .flags = IORESOURCE_MEM,
190 },
191 [1] = {
192 .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
193 .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
194 .flags = IORESOURCE_IRQ,
195 },
196};
197
198static struct htc_egpio_chip egpio_chips[] = {
199 [0] = {
200 .reg_start = 0,
201 .gpio_base = MAGICIAN_EGPIO(0, 0),
202 .num_gpios = 24,
203 .direction = HTC_EGPIO_OUTPUT,
204 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
205 },
206 [1] = {
207 .reg_start = 4,
208 .gpio_base = MAGICIAN_EGPIO(4, 0),
209 .num_gpios = 24,
210 .direction = HTC_EGPIO_INPUT,
211 },
212};
213
214static struct htc_egpio_platform_data egpio_info = {
215 .reg_width = 8,
216 .bus_width = 32,
217 .irq_base = IRQ_BOARD_START,
218 .num_irqs = 4,
219 .ack_register = 3,
220 .chip = egpio_chips,
221 .num_chips = ARRAY_SIZE(egpio_chips),
222};
223
224static struct platform_device egpio = {
225 .name = "htc-egpio",
226 .id = -1,
227 .resource = egpio_resources,
228 .num_resources = ARRAY_SIZE(egpio_resources),
229 .dev = {
230 .platform_data = &egpio_info,
231 },
232};
233
Philipp Zabele5c271e2007-11-22 17:59:11 +0100234/*
Philipp Zabele07ff8d2008-04-09 19:27:10 +0100235 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
Philipp Zabele5c271e2007-11-22 17:59:11 +0100236 */
237
238static struct pxafb_mode_info toppoly_modes[] = {
239 {
240 .pixclock = 96153,
241 .bpp = 16,
242 .xres = 240,
243 .yres = 320,
244 .hsync_len = 11,
245 .vsync_len = 3,
246 .left_margin = 19,
247 .upper_margin = 2,
248 .right_margin = 10,
249 .lower_margin = 2,
250 .sync = 0,
251 },
252};
253
Philipp Zabele07ff8d2008-04-09 19:27:10 +0100254static struct pxafb_mode_info samsung_modes[] = {
255 {
256 .pixclock = 96153,
257 .bpp = 16,
258 .xres = 240,
259 .yres = 320,
260 .hsync_len = 8,
261 .vsync_len = 4,
262 .left_margin = 9,
263 .upper_margin = 4,
264 .right_margin = 9,
265 .lower_margin = 4,
266 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
267 },
268};
269
270static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
271{
272 pr_debug("Toppoly LCD power\n");
273
274 if (on) {
275 pr_debug("on\n");
276 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
277 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
278 udelay(2000);
279 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
280 udelay(2000);
281 /* FIXME: enable LCDC here */
282 udelay(2000);
283 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
284 udelay(2000);
285 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
286 } else {
287 pr_debug("off\n");
288 msleep(15);
289 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
290 udelay(500);
291 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
292 udelay(1000);
293 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
294 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
295 }
296}
297
298static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
299{
300 pr_debug("Samsung LCD power\n");
301
302 if (on) {
303 pr_debug("on\n");
304 if (system_rev < 3)
305 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
306 else
307 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
308 mdelay(10);
309 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
310 mdelay(10);
311 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
312 mdelay(30);
313 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
314 mdelay(10);
315 } else {
316 pr_debug("off\n");
317 mdelay(10);
318 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
319 mdelay(30);
320 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
321 mdelay(10);
322 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
323 mdelay(10);
324 if (system_rev < 3)
325 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
326 else
327 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
328 }
329}
330
Philipp Zabele5c271e2007-11-22 17:59:11 +0100331static struct pxafb_mach_info toppoly_info = {
Philipp Zabele07ff8d2008-04-09 19:27:10 +0100332 .modes = toppoly_modes,
333 .num_modes = 1,
334 .fixed_modes = 1,
335 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
336 .lccr3 = LCCR3_PixRsEdg,
337 .pxafb_lcd_power = toppoly_lcd_power,
338};
339
340static struct pxafb_mach_info samsung_info = {
341 .modes = samsung_modes,
342 .num_modes = 1,
343 .fixed_modes = 1,
344 .lccr0 = LCCR0_LDDALT | LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
345 .lccr3 = LCCR3_PixFlEdg,
346 .pxafb_lcd_power = samsung_lcd_power,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100347};
348
349/*
350 * Backlight
351 */
352
Philipp Zabel85847a32008-05-22 14:20:01 +0100353static int magician_backlight_init(struct device *dev)
Philipp Zabele5c271e2007-11-22 17:59:11 +0100354{
Philipp Zabel85847a32008-05-22 14:20:01 +0100355 int ret;
356
357 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
358 if (ret)
359 goto err;
360 ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
361 if (ret)
362 goto err2;
363 return 0;
364
365err2:
366 gpio_free(EGPIO_MAGICIAN_BL_POWER);
367err:
368 return ret;
369}
370
371static int magician_backlight_notify(int brightness)
372{
373 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
374 if (brightness >= 200) {
375 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
376 return brightness - 72;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100377 } else {
Philipp Zabel85847a32008-05-22 14:20:01 +0100378 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
379 return brightness;
Philipp Zabele5c271e2007-11-22 17:59:11 +0100380 }
381}
382
Philipp Zabel85847a32008-05-22 14:20:01 +0100383static void magician_backlight_exit(struct device *dev)
384{
385 gpio_free(EGPIO_MAGICIAN_BL_POWER);
386 gpio_free(EGPIO_MAGICIAN_BL_POWER2);
387}
388
389static struct platform_pwm_backlight_data backlight_data = {
390 .pwm_id = 0,
391 .max_brightness = 272,
392 .dft_brightness = 100,
393 .pwm_period_ns = 30923,
394 .init = magician_backlight_init,
395 .notify = magician_backlight_notify,
396 .exit = magician_backlight_exit,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100397};
398
399static struct platform_device backlight = {
Philipp Zabel85847a32008-05-22 14:20:01 +0100400 .name = "pwm-backlight",
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
513static int magician_is_ac_online(void)
514{
515 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
516}
517
518static int magician_is_usb_online(void)
519{
520 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
521}
522
523static void magician_set_charge(int flags)
524{
525 gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
526 gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
527}
528
Philipp Zabel81447b22008-04-12 13:28:02 +0100529static char *magician_supplicants[] = {
530 "ds2760-battery.0", "backup-battery"
531};
532
Philipp Zabel350d1152008-04-09 19:25:56 +0100533static struct pda_power_pdata power_supply_info = {
Philipp Zabel81447b22008-04-12 13:28:02 +0100534 .is_ac_online = magician_is_ac_online,
535 .is_usb_online = magician_is_usb_online,
536 .set_charge = magician_set_charge,
537 .supplied_to = magician_supplicants,
538 .num_supplicants = ARRAY_SIZE(magician_supplicants),
Philipp Zabel350d1152008-04-09 19:25:56 +0100539};
540
541static struct resource power_supply_resources[] = {
542 [0] = {
543 .name = "ac",
544 .flags = IORESOURCE_IRQ,
545 .start = IRQ_MAGICIAN_AC,
546 .end = IRQ_MAGICIAN_AC,
547 },
548 [1] = {
549 .name = "usb",
550 .flags = IORESOURCE_IRQ,
551 .start = IRQ_MAGICIAN_AC,
552 .end = IRQ_MAGICIAN_AC,
553 },
554};
555
556static struct platform_device power_supply = {
557 .name = "pda-power",
558 .id = -1,
559 .dev = {
560 .platform_data = &power_supply_info,
561 },
562 .resource = power_supply_resources,
563 .num_resources = ARRAY_SIZE(power_supply_resources),
564};
565
566
567/*
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100568 * MMC/SD
569 */
570
571static int magician_mci_init(struct device *dev,
572 irq_handler_t detect_irq, void *data)
573{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100574 int err;
575
576 err = request_irq(IRQ_MAGICIAN_SD, detect_irq,
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100577 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
578 "MMC card detect", data);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100579 if (err)
580 goto err_request_irq;
581 err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER");
582 if (err)
583 goto err_request_power;
584 err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY");
585 if (err)
586 goto err_request_readonly;
587
588 return 0;
589
590err_request_readonly:
591 gpio_free(EGPIO_MAGICIAN_SD_POWER);
592err_request_power:
593 free_irq(IRQ_MAGICIAN_SD, data);
594err_request_irq:
595 return err;
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100596}
597
598static void magician_mci_setpower(struct device *dev, unsigned int vdd)
599{
600 struct pxamci_platform_data *pdata = dev->platform_data;
601
602 gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
603}
604
605static int magician_mci_get_ro(struct device *dev)
606{
607 return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
608}
609
610static void magician_mci_exit(struct device *dev, void *data)
611{
Philipp Zabela1999cd2008-04-20 17:39:12 +0100612 gpio_free(EGPIO_MAGICIAN_nSD_READONLY);
613 gpio_free(EGPIO_MAGICIAN_SD_POWER);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100614 free_irq(IRQ_MAGICIAN_SD, data);
615}
616
617static struct pxamci_platform_data magician_mci_info = {
618 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
619 .init = magician_mci_init,
620 .get_ro = magician_mci_get_ro,
621 .setpower = magician_mci_setpower,
622 .exit = magician_mci_exit,
623};
624
625
626/*
Philipp Zabele5c271e2007-11-22 17:59:11 +0100627 * USB OHCI
628 */
629
630static int magician_ohci_init(struct device *dev)
631{
632 UHCHR = (UHCHR | UHCHR_SSEP2 | UHCHR_PCPL | UHCHR_CGR) &
633 ~(UHCHR_SSEP1 | UHCHR_SSEP3 | UHCHR_SSE);
634
635 return 0;
636}
637
638static struct pxaohci_platform_data magician_ohci_info = {
639 .port_mode = PMM_PERPORT_MODE,
640 .init = magician_ohci_init,
641 .power_budget = 0,
642};
643
644
645/*
646 * StrataFlash
647 */
648
Philipp Zabelaa797592008-04-09 19:24:05 +0100649static void magician_set_vpp(struct map_info *map, int vpp)
650{
651 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
652}
653
Philipp Zabele5c271e2007-11-22 17:59:11 +0100654#define PXA_CS_SIZE 0x04000000
655
656static struct resource strataflash_resource = {
657 .start = PXA_CS0_PHYS,
658 .end = PXA_CS0_PHYS + PXA_CS_SIZE - 1,
659 .flags = IORESOURCE_MEM,
660};
661
662static struct physmap_flash_data strataflash_data = {
663 .width = 4,
Philipp Zabelaa797592008-04-09 19:24:05 +0100664 .set_vpp = magician_set_vpp,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100665};
666
667static struct platform_device strataflash = {
668 .name = "physmap-flash",
669 .id = -1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100670 .resource = &strataflash_resource,
Philipp Zabel70e357f2008-04-09 19:22:57 +0100671 .num_resources = 1,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100672 .dev = {
673 .platform_data = &strataflash_data,
674 },
675};
676
677/*
678 * Platform devices
679 */
680
681static struct platform_device *devices[] __initdata = {
682 &gpio_keys,
Philipp Zabel70e357f2008-04-09 19:22:57 +0100683 &egpio,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100684 &backlight,
Philipp Zabel81447b22008-04-12 13:28:02 +0100685 &pasic3,
Philipp Zabel350d1152008-04-09 19:25:56 +0100686 &power_supply,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100687 &strataflash,
Philipp Zabel81447b22008-04-12 13:28:02 +0100688 &leds_gpio,
Philipp Zabele5c271e2007-11-22 17:59:11 +0100689};
690
691static void __init magician_init(void)
692{
Philipp Zabele07ff8d2008-04-09 19:27:10 +0100693 void __iomem *cpld;
694 int lcd_select;
Philipp Zabela1999cd2008-04-20 17:39:12 +0100695 int err;
696
697 gpio_request(GPIO13_MAGICIAN_CPLD_IRQ, "CPLD_IRQ");
698 gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ, "DS1WM_IRQ");
Philipp Zabele07ff8d2008-04-09 19:27:10 +0100699
Philipp Zabelb1682812008-04-12 13:29:22 +0100700 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
701
Philipp Zabele5c271e2007-11-22 17:59:11 +0100702 platform_add_devices(devices, ARRAY_SIZE(devices));
Philipp Zabela1999cd2008-04-20 17:39:12 +0100703
704 err = gpio_request(GPIO83_MAGICIAN_nIR_EN, "nIR_EN");
705 if (!err) {
706 gpio_direction_output(GPIO83_MAGICIAN_nIR_EN, 1);
707 pxa_set_ficp_info(&magician_ficp_info);
708 }
Philipp Zabele6816f32008-04-09 19:14:15 +0100709 pxa_set_i2c_info(NULL);
Philipp Zabelbdb0c162008-04-09 19:24:55 +0100710 pxa_set_mci_info(&magician_mci_info);
Philipp Zabele5c271e2007-11-22 17:59:11 +0100711 pxa_set_ohci_info(&magician_ohci_info);
Philipp Zabele07ff8d2008-04-09 19:27:10 +0100712
713 /* Check LCD type we have */
714 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
715 if (cpld) {
716 u8 board_id = __raw_readb(cpld+0x14);
Philipp Zabela1999cd2008-04-20 17:39:12 +0100717 iounmap(cpld);
Philipp Zabele07ff8d2008-04-09 19:27:10 +0100718 system_rev = board_id & 0x7;
719 lcd_select = board_id & 0x8;
Philipp Zabele07ff8d2008-04-09 19:27:10 +0100720 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
Philipp Zabela1999cd2008-04-20 17:39:12 +0100721 if (lcd_select && (system_rev < 3)) {
722 gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER");
723 gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
724 }
725 gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1");
726 gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2");
727 gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3");
728 gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0);
729 gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0);
730 gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0);
Philipp Zabele07ff8d2008-04-09 19:27:10 +0100731 set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
732 } else
733 pr_err("LCD detection: CPLD mapping failed\n");
Philipp Zabele5c271e2007-11-22 17:59:11 +0100734}
735
736
737MACHINE_START(MAGICIAN, "HTC Magician")
738 .phys_io = 0x40000000,
739 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
740 .boot_params = 0xa0000100,
741 .map_io = pxa_map_io,
742 .init_irq = pxa27x_init_irq,
743 .init_machine = magician_init,
744 .timer = &pxa_timer,
745MACHINE_END