]>
Commit | Line | Data |
---|---|---|
e5c271ec PZ |
1 | /* |
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> | |
e07ff8d8 | 19 | #include <linux/delay.h> |
e181191a | 20 | #include <linux/gpio.h> |
e5c271ec PZ |
21 | #include <linux/gpio_keys.h> |
22 | #include <linux/input.h> | |
70e357f8 | 23 | #include <linux/mfd/htc-egpio.h> |
81447b2e | 24 | #include <linux/mfd/htc-pasic3.h> |
e5c271ec | 25 | #include <linux/mtd/physmap.h> |
350d115d | 26 | #include <linux/pda_power.h> |
bd3208ba | 27 | #include <linux/pwm.h> |
85847a36 | 28 | #include <linux/pwm_backlight.h> |
6967cca8 HS |
29 | #include <linux/regulator/driver.h> |
30 | #include <linux/regulator/gpio-regulator.h> | |
eb650b9e | 31 | #include <linux/regulator/machine.h> |
6489c611 | 32 | #include <linux/usb/gpio_vbus.h> |
b459396e | 33 | #include <linux/i2c/pxa-i2c.h> |
e5c271ec | 34 | |
a09e64fb | 35 | #include <mach/hardware.h> |
e5c271ec PZ |
36 | #include <asm/mach-types.h> |
37 | #include <asm/mach/arch.h> | |
9f97da78 | 38 | #include <asm/system_info.h> |
51c62982 EM |
39 | |
40 | #include <mach/pxa27x.h> | |
a09e64fb | 41 | #include <mach/magician.h> |
293b2da1 AB |
42 | #include <linux/platform_data/video-pxafb.h> |
43 | #include <linux/platform_data/mmc-pxamci.h> | |
44 | #include <linux/platform_data/irda-pxaficp.h> | |
45 | #include <linux/platform_data/usb-ohci-pxa27x.h> | |
e5c271ec | 46 | |
85847a36 | 47 | #include "devices.h" |
e5c271ec PZ |
48 | #include "generic.h" |
49 | ||
7a97010e | 50 | static unsigned long magician_pin_config[] __initdata = { |
b168281c PZ |
51 | |
52 | /* SDRAM and Static Memory I/O Signals */ | |
53 | GPIO20_nSDCS_2, | |
54 | GPIO21_nSDCS_3, | |
55 | GPIO15_nCS_1, | |
ccb6f9ae PC |
56 | GPIO78_nCS_2, /* PASIC3 */ |
57 | GPIO79_nCS_3, /* EGPIO CPLD */ | |
b168281c PZ |
58 | GPIO80_nCS_4, |
59 | GPIO33_nCS_5, | |
60 | ||
61 | /* I2C */ | |
62 | GPIO117_I2C_SCL, | |
63 | GPIO118_I2C_SDA, | |
64 | ||
65 | /* PWM 0 */ | |
66 | GPIO16_PWM0_OUT, | |
67 | ||
68 | /* I2S */ | |
69 | GPIO28_I2S_BITCLK_OUT, | |
70 | GPIO29_I2S_SDATA_IN, | |
71 | GPIO31_I2S_SYNC, | |
72 | GPIO113_I2S_SYSCLK, | |
73 | ||
16c3ea43 PZ |
74 | /* SSP 1 */ |
75 | GPIO23_SSP1_SCLK, | |
76 | GPIO24_SSP1_SFRM, | |
77 | GPIO25_SSP1_TXD, | |
78 | ||
b168281c PZ |
79 | /* SSP 2 */ |
80 | GPIO19_SSP2_SCLK, | |
81 | GPIO14_SSP2_SFRM, | |
82 | GPIO89_SSP2_TXD, | |
83 | GPIO88_SSP2_RXD, | |
84 | ||
85 | /* MMC */ | |
86 | GPIO32_MMC_CLK, | |
87 | GPIO92_MMC_DAT_0, | |
88 | GPIO109_MMC_DAT_1, | |
89 | GPIO110_MMC_DAT_2, | |
90 | GPIO111_MMC_DAT_3, | |
91 | GPIO112_MMC_CMD, | |
92 | ||
93 | /* LCD */ | |
bedbda97 | 94 | GPIOxx_LCD_TFT_16BPP, |
b168281c PZ |
95 | |
96 | /* QCI */ | |
97 | GPIO12_CIF_DD_7, | |
98 | GPIO17_CIF_DD_6, | |
99 | GPIO50_CIF_DD_3, | |
100 | GPIO51_CIF_DD_2, | |
101 | GPIO52_CIF_DD_4, | |
102 | GPIO53_CIF_MCLK, | |
103 | GPIO54_CIF_PCLK, | |
104 | GPIO55_CIF_DD_1, | |
105 | GPIO81_CIF_DD_0, | |
106 | GPIO82_CIF_DD_5, | |
107 | GPIO84_CIF_FV, | |
108 | GPIO85_CIF_LV, | |
2f131958 PZ |
109 | |
110 | /* Magician specific input GPIOs */ | |
111 | GPIO9_GPIO, /* unknown */ | |
112 | GPIO10_GPIO, /* GSM_IRQ */ | |
113 | GPIO13_GPIO, /* CPLD_IRQ */ | |
114 | GPIO107_GPIO, /* DS1WM_IRQ */ | |
115 | GPIO108_GPIO, /* GSM_READY */ | |
116 | GPIO115_GPIO, /* nPEN_IRQ */ | |
6f584cfa EM |
117 | |
118 | /* I2C */ | |
119 | GPIO117_I2C_SCL, | |
120 | GPIO118_I2C_SDA, | |
b168281c PZ |
121 | }; |
122 | ||
e5c271ec PZ |
123 | /* |
124 | * IRDA | |
125 | */ | |
126 | ||
e5c271ec | 127 | static struct pxaficp_platform_data magician_ficp_info = { |
c4bd0172 MV |
128 | .gpio_pwdown = GPIO83_MAGICIAN_nIR_EN, |
129 | .transceiver_cap = IR_SIRMODE | IR_OFF, | |
e5c271ec PZ |
130 | }; |
131 | ||
132 | /* | |
133 | * GPIO Keys | |
134 | */ | |
135 | ||
51c10bbc PZ |
136 | #define INIT_KEY(_code, _gpio, _desc) \ |
137 | { \ | |
ccb6f9ae PC |
138 | .code = KEY_##_code, \ |
139 | .gpio = _gpio, \ | |
140 | .desc = _desc, \ | |
141 | .type = EV_KEY, \ | |
142 | .wakeup = 1, \ | |
51c10bbc PZ |
143 | } |
144 | ||
e5c271ec | 145 | static struct gpio_keys_button magician_button_table[] = { |
51c10bbc PZ |
146 | INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"), |
147 | INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"), | |
148 | INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"), | |
149 | INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"), | |
150 | INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"), | |
151 | INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"), | |
152 | INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"), | |
153 | INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"), | |
154 | INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"), | |
155 | INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"), | |
156 | INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"), | |
157 | INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"), | |
158 | INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"), | |
159 | INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"), | |
160 | INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"), | |
e5c271ec PZ |
161 | }; |
162 | ||
163 | static struct gpio_keys_platform_data gpio_keys_data = { | |
ccb6f9ae PC |
164 | .buttons = magician_button_table, |
165 | .nbuttons = ARRAY_SIZE(magician_button_table), | |
e5c271ec PZ |
166 | }; |
167 | ||
168 | static struct platform_device gpio_keys = { | |
ccb6f9ae PC |
169 | .name = "gpio-keys", |
170 | .dev = { | |
e5c271ec PZ |
171 | .platform_data = &gpio_keys_data, |
172 | }, | |
ccb6f9ae | 173 | .id = -1, |
e5c271ec PZ |
174 | }; |
175 | ||
70e357f8 PZ |
176 | /* |
177 | * EGPIO (Xilinx CPLD) | |
178 | * | |
179 | * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input | |
180 | */ | |
181 | ||
182 | static struct resource egpio_resources[] = { | |
183 | [0] = { | |
ccb6f9ae PC |
184 | .start = PXA_CS3_PHYS, |
185 | .end = PXA_CS3_PHYS + 0x20 - 1, | |
186 | .flags = IORESOURCE_MEM, | |
70e357f8 PZ |
187 | }, |
188 | [1] = { | |
ccb6f9ae PC |
189 | .start = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ), |
190 | .end = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ), | |
191 | .flags = IORESOURCE_IRQ, | |
70e357f8 PZ |
192 | }, |
193 | }; | |
194 | ||
195 | static struct htc_egpio_chip egpio_chips[] = { | |
196 | [0] = { | |
ccb6f9ae PC |
197 | .reg_start = 0, |
198 | .gpio_base = MAGICIAN_EGPIO(0, 0), | |
199 | .num_gpios = 24, | |
200 | .direction = HTC_EGPIO_OUTPUT, | |
201 | .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */ | |
70e357f8 PZ |
202 | }, |
203 | [1] = { | |
ccb6f9ae PC |
204 | .reg_start = 4, |
205 | .gpio_base = MAGICIAN_EGPIO(4, 0), | |
206 | .num_gpios = 24, | |
207 | .direction = HTC_EGPIO_INPUT, | |
70e357f8 PZ |
208 | }, |
209 | }; | |
210 | ||
211 | static struct htc_egpio_platform_data egpio_info = { | |
ccb6f9ae PC |
212 | .reg_width = 8, |
213 | .bus_width = 32, | |
214 | .irq_base = IRQ_BOARD_START, | |
215 | .num_irqs = 4, | |
216 | .ack_register = 3, | |
217 | .chip = egpio_chips, | |
218 | .num_chips = ARRAY_SIZE(egpio_chips), | |
70e357f8 PZ |
219 | }; |
220 | ||
221 | static struct platform_device egpio = { | |
ccb6f9ae PC |
222 | .name = "htc-egpio", |
223 | .id = -1, | |
224 | .resource = egpio_resources, | |
225 | .num_resources = ARRAY_SIZE(egpio_resources), | |
70e357f8 PZ |
226 | .dev = { |
227 | .platform_data = &egpio_info, | |
228 | }, | |
229 | }; | |
230 | ||
e5c271ec | 231 | /* |
e07ff8d8 | 232 | * LCD - Toppoly TD028STEB1 or Samsung LTP280QV |
e5c271ec PZ |
233 | */ |
234 | ||
235 | static struct pxafb_mode_info toppoly_modes[] = { | |
236 | { | |
ccb6f9ae PC |
237 | .pixclock = 96153, |
238 | .bpp = 16, | |
239 | .xres = 240, | |
240 | .yres = 320, | |
241 | .hsync_len = 11, | |
242 | .vsync_len = 3, | |
243 | .left_margin = 19, | |
244 | .upper_margin = 2, | |
245 | .right_margin = 10, | |
246 | .lower_margin = 2, | |
247 | .sync = 0, | |
e5c271ec PZ |
248 | }, |
249 | }; | |
250 | ||
e07ff8d8 PZ |
251 | static struct pxafb_mode_info samsung_modes[] = { |
252 | { | |
e7b97a4c | 253 | .pixclock = 226469, |
ccb6f9ae PC |
254 | .bpp = 16, |
255 | .xres = 240, | |
256 | .yres = 320, | |
257 | .hsync_len = 8, | |
258 | .vsync_len = 4, | |
259 | .left_margin = 9, | |
260 | .upper_margin = 4, | |
261 | .right_margin = 9, | |
262 | .lower_margin = 4, | |
263 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, | |
e07ff8d8 PZ |
264 | }, |
265 | }; | |
266 | ||
267 | static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si) | |
268 | { | |
dedad4d2 | 269 | pr_debug("Toppoly LCD power: %s\n", on ? "on" : "off"); |
e07ff8d8 PZ |
270 | |
271 | if (on) { | |
e07ff8d8 | 272 | gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1); |
6001ae70 | 273 | gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1); |
e07ff8d8 PZ |
274 | udelay(2000); |
275 | gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1); | |
276 | udelay(2000); | |
277 | /* FIXME: enable LCDC here */ | |
278 | udelay(2000); | |
6001ae70 | 279 | gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1); |
e07ff8d8 | 280 | udelay(2000); |
6001ae70 | 281 | gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1); |
e07ff8d8 | 282 | } else { |
e07ff8d8 | 283 | msleep(15); |
6001ae70 | 284 | gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0); |
e07ff8d8 | 285 | udelay(500); |
6001ae70 | 286 | gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0); |
e07ff8d8 | 287 | udelay(1000); |
6001ae70 | 288 | gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0); |
e07ff8d8 PZ |
289 | gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0); |
290 | } | |
291 | } | |
292 | ||
293 | static void samsung_lcd_power(int on, struct fb_var_screeninfo *si) | |
294 | { | |
dedad4d2 | 295 | pr_debug("Samsung LCD power: %s\n", on ? "on" : "off"); |
e07ff8d8 PZ |
296 | |
297 | if (on) { | |
e07ff8d8 PZ |
298 | if (system_rev < 3) |
299 | gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1); | |
300 | else | |
301 | gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1); | |
fa5407ad | 302 | mdelay(6); |
6001ae70 | 303 | gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1); |
fa5407ad | 304 | mdelay(6); /* Avdd -> Voff >5ms */ |
6001ae70 | 305 | gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1); |
fa5407ad | 306 | mdelay(16); /* Voff -> Von >(5+10)ms */ |
6001ae70 | 307 | gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1); |
e07ff8d8 | 308 | } else { |
6001ae70 | 309 | gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0); |
fa5407ad | 310 | mdelay(16); |
6001ae70 | 311 | gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0); |
fa5407ad | 312 | mdelay(6); |
6001ae70 | 313 | gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0); |
fa5407ad | 314 | mdelay(6); |
e07ff8d8 PZ |
315 | if (system_rev < 3) |
316 | gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0); | |
317 | else | |
318 | gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0); | |
319 | } | |
320 | } | |
321 | ||
e5c271ec | 322 | static struct pxafb_mach_info toppoly_info = { |
ccb6f9ae PC |
323 | .modes = toppoly_modes, |
324 | .num_modes = 1, | |
325 | .fixed_modes = 1, | |
326 | .lcd_conn = LCD_COLOR_TFT_16BPP, | |
327 | .pxafb_lcd_power = toppoly_lcd_power, | |
e07ff8d8 PZ |
328 | }; |
329 | ||
330 | static struct pxafb_mach_info samsung_info = { | |
ccb6f9ae PC |
331 | .modes = samsung_modes, |
332 | .num_modes = 1, | |
333 | .fixed_modes = 1, | |
334 | .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL | | |
335 | LCD_ALTERNATE_MAPPING, | |
336 | .pxafb_lcd_power = samsung_lcd_power, | |
e5c271ec PZ |
337 | }; |
338 | ||
339 | /* | |
340 | * Backlight | |
341 | */ | |
342 | ||
bd3208ba TR |
343 | static struct pwm_lookup magician_pwm_lookup[] = { |
344 | PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight", NULL, 30923, | |
345 | PWM_POLARITY_NORMAL), | |
346 | }; | |
347 | ||
5db15f86 | 348 | static struct gpio magician_bl_gpios[] = { |
ccb6f9ae PC |
349 | { EGPIO_MAGICIAN_BL_POWER, GPIOF_DIR_OUT, "Backlight power" }, |
350 | { EGPIO_MAGICIAN_BL_POWER2, GPIOF_DIR_OUT, "Backlight power 2" }, | |
5db15f86 PZ |
351 | }; |
352 | ||
85847a36 | 353 | static int magician_backlight_init(struct device *dev) |
e5c271ec | 354 | { |
5db15f86 | 355 | return gpio_request_array(ARRAY_AND_SIZE(magician_bl_gpios)); |
85847a36 PZ |
356 | } |
357 | ||
2d51a521 | 358 | static int magician_backlight_notify(struct device *dev, int brightness) |
85847a36 PZ |
359 | { |
360 | gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness); | |
361 | if (brightness >= 200) { | |
362 | gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1); | |
363 | return brightness - 72; | |
e5c271ec | 364 | } else { |
85847a36 PZ |
365 | gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0); |
366 | return brightness; | |
e5c271ec PZ |
367 | } |
368 | } | |
369 | ||
85847a36 PZ |
370 | static void magician_backlight_exit(struct device *dev) |
371 | { | |
5db15f86 | 372 | gpio_free_array(ARRAY_AND_SIZE(magician_bl_gpios)); |
85847a36 PZ |
373 | } |
374 | ||
375 | static struct platform_pwm_backlight_data backlight_data = { | |
ccb6f9ae PC |
376 | .max_brightness = 272, |
377 | .dft_brightness = 100, | |
378 | .enable_gpio = -1, | |
379 | .init = magician_backlight_init, | |
380 | .notify = magician_backlight_notify, | |
381 | .exit = magician_backlight_exit, | |
e5c271ec PZ |
382 | }; |
383 | ||
384 | static struct platform_device backlight = { | |
ccb6f9ae PC |
385 | .name = "pwm-backlight", |
386 | .id = -1, | |
387 | .dev = { | |
388 | .parent = &pxa27x_device_pwm0.dev, | |
389 | .platform_data = &backlight_data, | |
e5c271ec | 390 | }, |
e5c271ec PZ |
391 | }; |
392 | ||
81447b2e PZ |
393 | /* |
394 | * LEDs | |
395 | */ | |
396 | ||
a55facae | 397 | static struct gpio_led gpio_leds[] = { |
81447b2e PZ |
398 | { |
399 | .name = "magician::vibra", | |
400 | .default_trigger = "none", | |
401 | .gpio = GPIO22_MAGICIAN_VIBRA_EN, | |
402 | }, | |
403 | { | |
404 | .name = "magician::phone_bl", | |
05199ecb | 405 | .default_trigger = "backlight", |
81447b2e PZ |
406 | .gpio = GPIO103_MAGICIAN_LED_KP, |
407 | }, | |
408 | }; | |
409 | ||
410 | static struct gpio_led_platform_data gpio_led_info = { | |
411 | .leds = gpio_leds, | |
412 | .num_leds = ARRAY_SIZE(gpio_leds), | |
413 | }; | |
414 | ||
415 | static struct platform_device leds_gpio = { | |
ccb6f9ae PC |
416 | .name = "leds-gpio", |
417 | .id = -1, | |
418 | .dev = { | |
81447b2e PZ |
419 | .platform_data = &gpio_led_info, |
420 | }, | |
421 | }; | |
422 | ||
423 | static struct pasic3_led pasic3_leds[] = { | |
424 | { | |
425 | .led = { | |
ccb6f9ae | 426 | .name = "magician:red", |
81447b2e PZ |
427 | .default_trigger = "ds2760-battery.0-charging", |
428 | }, | |
ccb6f9ae PC |
429 | .hw_num = 0, |
430 | .bit2 = PASIC3_BIT2_LED0, | |
431 | .mask = PASIC3_MASK_LED0, | |
81447b2e PZ |
432 | }, |
433 | { | |
434 | .led = { | |
ccb6f9ae | 435 | .name = "magician:green", |
81447b2e PZ |
436 | .default_trigger = "ds2760-battery.0-charging-or-full", |
437 | }, | |
ccb6f9ae PC |
438 | .hw_num = 1, |
439 | .bit2 = PASIC3_BIT2_LED1, | |
440 | .mask = PASIC3_MASK_LED1, | |
81447b2e PZ |
441 | }, |
442 | { | |
443 | .led = { | |
ccb6f9ae | 444 | .name = "magician:blue", |
81447b2e PZ |
445 | .default_trigger = "bluetooth", |
446 | }, | |
ccb6f9ae PC |
447 | .hw_num = 2, |
448 | .bit2 = PASIC3_BIT2_LED2, | |
449 | .mask = PASIC3_MASK_LED2, | |
81447b2e PZ |
450 | }, |
451 | }; | |
452 | ||
e03e0590 | 453 | static struct pasic3_leds_machinfo pasic3_leds_info = { |
ccb6f9ae PC |
454 | .num_leds = ARRAY_SIZE(pasic3_leds), |
455 | .power_gpio = EGPIO_MAGICIAN_LED_POWER, | |
456 | .leds = pasic3_leds, | |
81447b2e PZ |
457 | }; |
458 | ||
459 | /* | |
460 | * PASIC3 with DS1WM | |
461 | */ | |
462 | ||
463 | static struct resource pasic3_resources[] = { | |
464 | [0] = { | |
ccb6f9ae | 465 | .start = PXA_CS2_PHYS, |
81447b2e | 466 | .end = PXA_CS2_PHYS + 0x1b, |
ccb6f9ae | 467 | .flags = IORESOURCE_MEM, |
81447b2e PZ |
468 | }, |
469 | /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */ | |
470 | [1] = { | |
ccb6f9ae PC |
471 | .start = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ), |
472 | .end = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ), | |
473 | .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE, | |
81447b2e PZ |
474 | } |
475 | }; | |
476 | ||
477 | static struct pasic3_platform_data pasic3_platform_data = { | |
ccb6f9ae PC |
478 | .led_pdata = &pasic3_leds_info, |
479 | .clock_rate = 4000000, | |
81447b2e PZ |
480 | }; |
481 | ||
482 | static struct platform_device pasic3 = { | |
483 | .name = "pasic3", | |
484 | .id = -1, | |
485 | .num_resources = ARRAY_SIZE(pasic3_resources), | |
486 | .resource = pasic3_resources, | |
487 | .dev = { | |
488 | .platform_data = &pasic3_platform_data, | |
489 | }, | |
490 | }; | |
e5c271ec | 491 | |
6489c611 PZ |
492 | /* |
493 | * USB "Transceiver" | |
494 | */ | |
495 | ||
496 | static struct resource gpio_vbus_resource = { | |
ccb6f9ae PC |
497 | .flags = IORESOURCE_IRQ, |
498 | .start = IRQ_MAGICIAN_VBUS, | |
499 | .end = IRQ_MAGICIAN_VBUS, | |
6489c611 PZ |
500 | }; |
501 | ||
502 | static struct gpio_vbus_mach_info gpio_vbus_info = { | |
ccb6f9ae | 503 | .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN, |
f78b3a12 | 504 | .gpio_vbus = EGPIO_MAGICIAN_CABLE_VBUS, |
6489c611 PZ |
505 | }; |
506 | ||
507 | static struct platform_device gpio_vbus = { | |
ccb6f9ae PC |
508 | .name = "gpio-vbus", |
509 | .id = -1, | |
510 | .num_resources = 1, | |
511 | .resource = &gpio_vbus_resource, | |
6489c611 PZ |
512 | .dev = { |
513 | .platform_data = &gpio_vbus_info, | |
514 | }, | |
515 | }; | |
516 | ||
350d115d PZ |
517 | /* |
518 | * External power | |
519 | */ | |
520 | ||
eac2eacc | 521 | static int magician_supply_init(struct device *dev) |
ff279202 | 522 | { |
eac2eacc PC |
523 | int ret = -1; |
524 | ||
525 | ret = gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "Cable is AC charger"); | |
526 | if (ret) { | |
527 | pr_err("Cannot request AC/USB charger GPIO (%i)\n", ret); | |
528 | goto err_ac; | |
529 | } | |
530 | ||
531 | ret = gpio_request(EGPIO_MAGICIAN_CABLE_INSERTED, "Cable inserted"); | |
532 | if (ret) { | |
533 | pr_err("Cannot request cable detection GPIO (%i)\n", ret); | |
534 | goto err_usb; | |
535 | } | |
536 | ||
537 | return 0; | |
538 | ||
539 | err_usb: | |
540 | gpio_free(EGPIO_MAGICIAN_CABLE_TYPE); | |
541 | err_ac: | |
542 | return ret; | |
543 | } | |
544 | ||
545 | static void magician_set_charge(int flags) | |
546 | { | |
547 | if (flags & PDA_POWER_CHARGE_AC) { | |
548 | pr_debug("Charging from AC\n"); | |
549 | gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1); | |
550 | } else if (flags & PDA_POWER_CHARGE_USB) { | |
551 | pr_debug("Charging from USB\n"); | |
552 | gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1); | |
553 | } else { | |
554 | pr_debug("Charging disabled\n"); | |
555 | gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 0); | |
556 | } | |
ff279202 PZ |
557 | } |
558 | ||
350d115d PZ |
559 | static int magician_is_ac_online(void) |
560 | { | |
eac2eacc PC |
561 | return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) && |
562 | gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE); /* AC=1 */ | |
563 | } | |
564 | ||
565 | static int magician_is_usb_online(void) | |
566 | { | |
567 | return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) && | |
568 | (!gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE)); /* USB=0 */ | |
350d115d PZ |
569 | } |
570 | ||
eac2eacc | 571 | static void magician_supply_exit(struct device *dev) |
ff279202 | 572 | { |
eac2eacc | 573 | gpio_free(EGPIO_MAGICIAN_CABLE_INSERTED); |
f78b3a12 | 574 | gpio_free(EGPIO_MAGICIAN_CABLE_TYPE); |
ff279202 PZ |
575 | } |
576 | ||
81447b2e PZ |
577 | static char *magician_supplicants[] = { |
578 | "ds2760-battery.0", "backup-battery" | |
579 | }; | |
580 | ||
350d115d | 581 | static struct pda_power_pdata power_supply_info = { |
eac2eacc PC |
582 | .init = magician_supply_init, |
583 | .exit = magician_supply_exit, | |
ccb6f9ae | 584 | .is_ac_online = magician_is_ac_online, |
eac2eacc PC |
585 | .is_usb_online = magician_is_usb_online, |
586 | .set_charge = magician_set_charge, | |
ccb6f9ae PC |
587 | .supplied_to = magician_supplicants, |
588 | .num_supplicants = ARRAY_SIZE(magician_supplicants), | |
350d115d PZ |
589 | }; |
590 | ||
591 | static struct resource power_supply_resources[] = { | |
592 | [0] = { | |
ccb6f9ae PC |
593 | .name = "ac", |
594 | .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE | | |
595 | IORESOURCE_IRQ_LOWEDGE, | |
596 | .start = IRQ_MAGICIAN_VBUS, | |
597 | .end = IRQ_MAGICIAN_VBUS, | |
350d115d PZ |
598 | }, |
599 | [1] = { | |
ccb6f9ae PC |
600 | .name = "usb", |
601 | .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE | | |
602 | IORESOURCE_IRQ_LOWEDGE, | |
603 | .start = IRQ_MAGICIAN_VBUS, | |
604 | .end = IRQ_MAGICIAN_VBUS, | |
350d115d PZ |
605 | }, |
606 | }; | |
607 | ||
608 | static struct platform_device power_supply = { | |
ccb6f9ae PC |
609 | .name = "pda-power", |
610 | .id = -1, | |
611 | .dev = { | |
350d115d PZ |
612 | .platform_data = &power_supply_info, |
613 | }, | |
ccb6f9ae PC |
614 | .resource = power_supply_resources, |
615 | .num_resources = ARRAY_SIZE(power_supply_resources), | |
350d115d PZ |
616 | }; |
617 | ||
eb650b9e PZ |
618 | /* |
619 | * Battery charger | |
620 | */ | |
621 | ||
622 | static struct regulator_consumer_supply bq24022_consumers[] = { | |
0bf189ab AL |
623 | REGULATOR_SUPPLY("vbus_draw", NULL), |
624 | REGULATOR_SUPPLY("ac_draw", NULL), | |
eb650b9e PZ |
625 | }; |
626 | ||
627 | static struct regulator_init_data bq24022_init_data = { | |
628 | .constraints = { | |
ccb6f9ae PC |
629 | .max_uA = 500000, |
630 | .valid_ops_mask = REGULATOR_CHANGE_CURRENT | | |
631 | REGULATOR_CHANGE_STATUS, | |
eb650b9e | 632 | }, |
ccb6f9ae PC |
633 | .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers), |
634 | .consumer_supplies = bq24022_consumers, | |
eb650b9e PZ |
635 | }; |
636 | ||
6967cca8 HS |
637 | static struct gpio bq24022_gpios[] = { |
638 | { EGPIO_MAGICIAN_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" }, | |
639 | }; | |
640 | ||
641 | static struct gpio_regulator_state bq24022_states[] = { | |
642 | { .value = 100000, .gpios = (0 << 0) }, | |
643 | { .value = 500000, .gpios = (1 << 0) }, | |
644 | }; | |
645 | ||
646 | static struct gpio_regulator_config bq24022_info = { | |
ccb6f9ae | 647 | .supply_name = "bq24022", |
6967cca8 | 648 | |
ccb6f9ae PC |
649 | .enable_gpio = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN, |
650 | .enable_high = 0, | |
eac2eacc | 651 | .enabled_at_boot = 1, |
6967cca8 | 652 | |
ccb6f9ae PC |
653 | .gpios = bq24022_gpios, |
654 | .nr_gpios = ARRAY_SIZE(bq24022_gpios), | |
6967cca8 | 655 | |
ccb6f9ae PC |
656 | .states = bq24022_states, |
657 | .nr_states = ARRAY_SIZE(bq24022_states), | |
6967cca8 | 658 | |
ccb6f9ae PC |
659 | .type = REGULATOR_CURRENT, |
660 | .init_data = &bq24022_init_data, | |
eb650b9e PZ |
661 | }; |
662 | ||
663 | static struct platform_device bq24022 = { | |
ccb6f9ae PC |
664 | .name = "gpio-regulator", |
665 | .id = -1, | |
666 | .dev = { | |
eb650b9e PZ |
667 | .platform_data = &bq24022_info, |
668 | }, | |
669 | }; | |
350d115d | 670 | |
bdb0c16a PZ |
671 | /* |
672 | * MMC/SD | |
673 | */ | |
674 | ||
675 | static int magician_mci_init(struct device *dev, | |
ccb6f9ae | 676 | irq_handler_t detect_irq, void *data) |
bdb0c16a | 677 | { |
ed7936f9 | 678 | return request_irq(IRQ_MAGICIAN_SD, detect_irq, 0, |
ccb6f9ae | 679 | "mmc card detect", data); |
bdb0c16a PZ |
680 | } |
681 | ||
682 | static void magician_mci_exit(struct device *dev, void *data) | |
683 | { | |
684 | free_irq(IRQ_MAGICIAN_SD, data); | |
685 | } | |
686 | ||
687 | static struct pxamci_platform_data magician_mci_info = { | |
ccb6f9ae PC |
688 | .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, |
689 | .init = magician_mci_init, | |
690 | .exit = magician_mci_exit, | |
7a648256 RJ |
691 | .gpio_card_detect = -1, |
692 | .gpio_card_ro = EGPIO_MAGICIAN_nSD_READONLY, | |
693 | .gpio_card_ro_invert = 1, | |
694 | .gpio_power = EGPIO_MAGICIAN_SD_POWER, | |
bdb0c16a PZ |
695 | }; |
696 | ||
697 | ||
e5c271ec PZ |
698 | /* |
699 | * USB OHCI | |
700 | */ | |
701 | ||
e5c271ec | 702 | static struct pxaohci_platform_data magician_ohci_info = { |
097b5334 EM |
703 | .port_mode = PMM_PERPORT_MODE, |
704 | .flags = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW, | |
705 | .power_budget = 0, | |
e5c271ec PZ |
706 | }; |
707 | ||
e5c271ec PZ |
708 | /* |
709 | * StrataFlash | |
710 | */ | |
711 | ||
667f390b | 712 | static void magician_set_vpp(struct platform_device *pdev, int vpp) |
aa797590 PZ |
713 | { |
714 | gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp); | |
715 | } | |
716 | ||
e5c271ec | 717 | static struct resource strataflash_resource = { |
ccb6f9ae PC |
718 | .start = PXA_CS0_PHYS, |
719 | .end = PXA_CS0_PHYS + SZ_64M - 1, | |
720 | .flags = IORESOURCE_MEM, | |
e5c271ec PZ |
721 | }; |
722 | ||
723 | static struct physmap_flash_data strataflash_data = { | |
ccb6f9ae PC |
724 | .width = 4, |
725 | .set_vpp = magician_set_vpp, | |
e5c271ec PZ |
726 | }; |
727 | ||
728 | static struct platform_device strataflash = { | |
ccb6f9ae PC |
729 | .name = "physmap-flash", |
730 | .id = -1, | |
731 | .resource = &strataflash_resource, | |
732 | .num_resources = 1, | |
e5c271ec PZ |
733 | .dev = { |
734 | .platform_data = &strataflash_data, | |
735 | }, | |
736 | }; | |
737 | ||
f8f9d5ec PZ |
738 | /* |
739 | * I2C | |
740 | */ | |
741 | ||
742 | static struct i2c_pxa_platform_data i2c_info = { | |
743 | .fast_mode = 1, | |
744 | }; | |
745 | ||
e5c271ec PZ |
746 | /* |
747 | * Platform devices | |
748 | */ | |
749 | ||
750 | static struct platform_device *devices[] __initdata = { | |
751 | &gpio_keys, | |
70e357f8 | 752 | &egpio, |
e5c271ec | 753 | &backlight, |
81447b2e | 754 | &pasic3, |
eb650b9e | 755 | &bq24022, |
6489c611 | 756 | &gpio_vbus, |
350d115d | 757 | &power_supply, |
e5c271ec | 758 | &strataflash, |
81447b2e | 759 | &leds_gpio, |
e5c271ec PZ |
760 | }; |
761 | ||
5db15f86 | 762 | static struct gpio magician_global_gpios[] = { |
ccb6f9ae | 763 | { GPIO13_MAGICIAN_CPLD_IRQ, GPIOF_IN, "CPLD_IRQ" }, |
5db15f86 | 764 | { GPIO107_MAGICIAN_DS1WM_IRQ, GPIOF_IN, "DS1WM_IRQ" }, |
6001ae70 PC |
765 | |
766 | /* NOTICE valid LCD init sequence */ | |
767 | { GPIO106_MAGICIAN_LCD_DCDC_NRESET, GPIOF_OUT_INIT_LOW, "LCD DCDC nreset" }, | |
768 | { GPIO104_MAGICIAN_LCD_VOFF_EN, GPIOF_OUT_INIT_LOW, "LCD VOFF enable" }, | |
769 | { GPIO105_MAGICIAN_LCD_VON_EN, GPIOF_OUT_INIT_LOW, "LCD VON enable" }, | |
5db15f86 PZ |
770 | { GPIO83_MAGICIAN_nIR_EN, GPIOF_OUT_INIT_HIGH, "nIR_EN" }, |
771 | }; | |
772 | ||
e5c271ec PZ |
773 | static void __init magician_init(void) |
774 | { | |
e07ff8d8 PZ |
775 | void __iomem *cpld; |
776 | int lcd_select; | |
a1999cd1 PZ |
777 | int err; |
778 | ||
b168281c | 779 | pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config)); |
5db15f86 PZ |
780 | err = gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios)); |
781 | if (err) | |
7f63a752 | 782 | pr_err("magician: Failed to request global GPIOs: %d\n", err); |
b168281c | 783 | |
cc155c6f RK |
784 | pxa_set_ffuart_info(NULL); |
785 | pxa_set_btuart_info(NULL); | |
786 | pxa_set_stuart_info(NULL); | |
787 | ||
bd3208ba | 788 | pwm_add_table(magician_pwm_lookup, ARRAY_SIZE(magician_pwm_lookup)); |
2f1a5bf7 | 789 | platform_add_devices(ARRAY_AND_SIZE(devices)); |
a1999cd1 | 790 | |
5db15f86 | 791 | pxa_set_ficp_info(&magician_ficp_info); |
dee63169 | 792 | pxa27x_set_i2c_power_info(NULL); |
f8f9d5ec | 793 | pxa_set_i2c_info(&i2c_info); |
bdb0c16a | 794 | pxa_set_mci_info(&magician_mci_info); |
e5c271ec | 795 | pxa_set_ohci_info(&magician_ohci_info); |
e07ff8d8 PZ |
796 | |
797 | /* Check LCD type we have */ | |
798 | cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000); | |
799 | if (cpld) { | |
ccb6f9ae PC |
800 | u8 board_id = __raw_readb(cpld + 0x14); |
801 | ||
a1999cd1 | 802 | iounmap(cpld); |
e07ff8d8 PZ |
803 | system_rev = board_id & 0x7; |
804 | lcd_select = board_id & 0x8; | |
e07ff8d8 | 805 | pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly"); |
5db15f86 | 806 | if (lcd_select && (system_rev < 3)) |
6001ae70 | 807 | /* NOTICE valid LCD init sequence */ |
5db15f86 | 808 | gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER, |
6382a594 | 809 | GPIOF_OUT_INIT_LOW, "Samsung LCD Power"); |
ccb6f9ae PC |
810 | pxa_set_fb_info(NULL, |
811 | lcd_select ? &samsung_info : &toppoly_info); | |
e07ff8d8 PZ |
812 | } else |
813 | pr_err("LCD detection: CPLD mapping failed\n"); | |
e5c271ec PZ |
814 | } |
815 | ||
e5c271ec | 816 | MACHINE_START(MAGICIAN, "HTC Magician") |
ccb6f9ae PC |
817 | .atag_offset = 0x100, |
818 | .map_io = pxa27x_map_io, | |
819 | .nr_irqs = MAGICIAN_NR_IRQS, | |
820 | .init_irq = pxa27x_init_irq, | |
821 | .handle_irq = pxa27x_handle_irq, | |
822 | .init_machine = magician_init, | |
6bb27d73 | 823 | .init_time = pxa_timer_init, |
271a74fc | 824 | .restart = pxa_restart, |
e5c271ec | 825 | MACHINE_END |