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