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