Commit | Line | Data |
---|---|---|
c49e1e63 SL |
1 | /* |
2 | * Hardware definitions for Palm Zire72 | |
3 | * | |
4 | * Authors: | |
5 | * Vladimir "Farcaller" Pouzanov <farcaller@gmail.com> | |
6 | * Sergey Lapin <slapin@ossfans.org> | |
7 | * Alex Osborne <bobofdoom@gmail.com> | |
8 | * Jan Herman <2hp@seznam.cz> | |
9 | * | |
10 | * Rewrite for mainline: | |
11 | * Marek Vasut <marek.vasut@gmail.com> | |
12 | * | |
13 | * This program is free software; you can redistribute it and/or modify | |
14 | * it under the terms of the GNU General Public License version 2 as | |
15 | * published by the Free Software Foundation. | |
16 | * | |
17 | * (find more info at www.hackndev.com) | |
18 | * | |
19 | */ | |
20 | ||
21 | #include <linux/platform_device.h> | |
22 | #include <linux/sysdev.h> | |
23 | #include <linux/delay.h> | |
24 | #include <linux/irq.h> | |
25 | #include <linux/gpio_keys.h> | |
26 | #include <linux/input.h> | |
27 | #include <linux/pda_power.h> | |
28 | #include <linux/pwm_backlight.h> | |
29 | #include <linux/gpio.h> | |
eb73e622 | 30 | #include <linux/wm97xx_batt.h> |
c49e1e63 | 31 | #include <linux/power_supply.h> |
eb73e622 | 32 | #include <linux/usb/gpio_vbus.h> |
c49e1e63 SL |
33 | |
34 | #include <asm/mach-types.h> | |
35 | #include <asm/mach/arch.h> | |
36 | #include <asm/mach/map.h> | |
37 | ||
51c62982 | 38 | #include <mach/pxa27x.h> |
c49e1e63 SL |
39 | #include <mach/audio.h> |
40 | #include <mach/palmz72.h> | |
41 | #include <mach/mmc.h> | |
42 | #include <mach/pxafb.h> | |
c49e1e63 SL |
43 | #include <mach/irda.h> |
44 | #include <mach/pxa27x_keypad.h> | |
45 | #include <mach/udc.h> | |
eb73e622 MV |
46 | #include <mach/palmasoc.h> |
47 | ||
c49e1e63 SL |
48 | #include <mach/pm.h> |
49 | ||
50 | #include "generic.h" | |
51 | #include "devices.h" | |
52 | ||
53 | /****************************************************************************** | |
54 | * Pin configuration | |
55 | ******************************************************************************/ | |
56 | static unsigned long palmz72_pin_config[] __initdata = { | |
57 | /* MMC */ | |
58 | GPIO32_MMC_CLK, | |
59 | GPIO92_MMC_DAT_0, | |
60 | GPIO109_MMC_DAT_1, | |
61 | GPIO110_MMC_DAT_2, | |
62 | GPIO111_MMC_DAT_3, | |
63 | GPIO112_MMC_CMD, | |
64 | GPIO14_GPIO, /* SD detect */ | |
65 | GPIO115_GPIO, /* SD RO */ | |
66 | GPIO98_GPIO, /* SD power */ | |
67 | ||
68 | /* AC97 */ | |
69 | GPIO28_AC97_BITCLK, | |
70 | GPIO29_AC97_SDATA_IN_0, | |
71 | GPIO30_AC97_SDATA_OUT, | |
72 | GPIO31_AC97_SYNC, | |
eb73e622 MV |
73 | GPIO89_AC97_SYSCLK, |
74 | GPIO113_AC97_nRESET, | |
c49e1e63 SL |
75 | |
76 | /* IrDA */ | |
77 | GPIO49_GPIO, /* ir disable */ | |
78 | GPIO46_FICP_RXD, | |
79 | GPIO47_FICP_TXD, | |
80 | ||
81 | /* PWM */ | |
82 | GPIO16_PWM0_OUT, | |
83 | ||
84 | /* USB */ | |
85 | GPIO15_GPIO, /* usb detect */ | |
eb73e622 | 86 | GPIO95_GPIO, /* usb pullup */ |
c49e1e63 SL |
87 | |
88 | /* Matrix keypad */ | |
89 | GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH, | |
90 | GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH, | |
91 | GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH, | |
92 | GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH, | |
93 | GPIO103_KP_MKOUT_0, | |
94 | GPIO104_KP_MKOUT_1, | |
95 | GPIO105_KP_MKOUT_2, | |
96 | ||
97 | /* LCD */ | |
98 | GPIO58_LCD_LDD_0, | |
99 | GPIO59_LCD_LDD_1, | |
100 | GPIO60_LCD_LDD_2, | |
101 | GPIO61_LCD_LDD_3, | |
102 | GPIO62_LCD_LDD_4, | |
103 | GPIO63_LCD_LDD_5, | |
104 | GPIO64_LCD_LDD_6, | |
105 | GPIO65_LCD_LDD_7, | |
106 | GPIO66_LCD_LDD_8, | |
107 | GPIO67_LCD_LDD_9, | |
108 | GPIO68_LCD_LDD_10, | |
109 | GPIO69_LCD_LDD_11, | |
110 | GPIO70_LCD_LDD_12, | |
111 | GPIO71_LCD_LDD_13, | |
112 | GPIO72_LCD_LDD_14, | |
113 | GPIO73_LCD_LDD_15, | |
114 | GPIO74_LCD_FCLK, | |
115 | GPIO75_LCD_LCLK, | |
116 | GPIO76_LCD_PCLK, | |
117 | GPIO77_LCD_BIAS, | |
118 | GPIO20_GPIO, /* bl power */ | |
119 | GPIO21_GPIO, /* LCD border switch */ | |
120 | GPIO22_GPIO, /* LCD border color */ | |
121 | GPIO96_GPIO, /* lcd power */ | |
122 | ||
123 | /* Misc. */ | |
124 | GPIO0_GPIO | WAKEUP_ON_LEVEL_HIGH, /* power detect */ | |
125 | GPIO88_GPIO, /* green led */ | |
126 | GPIO27_GPIO, /* WM9712 IRQ */ | |
127 | }; | |
128 | ||
129 | /****************************************************************************** | |
130 | * SD/MMC card controller | |
131 | ******************************************************************************/ | |
7a648256 RJ |
132 | /* SD_POWER is not actually power, but it is more like chip |
133 | * select, i.e. it is inverted */ | |
c49e1e63 | 134 | static struct pxamci_platform_data palmz72_mci_platform_data = { |
7a648256 RJ |
135 | .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, |
136 | .gpio_card_detect = GPIO_NR_PALMZ72_SD_DETECT_N, | |
137 | .gpio_card_ro = GPIO_NR_PALMZ72_SD_RO, | |
138 | .gpio_power = GPIO_NR_PALMZ72_SD_POWER_N, | |
139 | .gpio_power_invert = 1, | |
c49e1e63 SL |
140 | }; |
141 | ||
142 | /****************************************************************************** | |
143 | * GPIO keyboard | |
144 | ******************************************************************************/ | |
145 | static unsigned int palmz72_matrix_keys[] = { | |
146 | KEY(0, 0, KEY_POWER), | |
147 | KEY(0, 1, KEY_F1), | |
148 | KEY(0, 2, KEY_ENTER), | |
149 | ||
150 | KEY(1, 0, KEY_F2), | |
151 | KEY(1, 1, KEY_F3), | |
152 | KEY(1, 2, KEY_F4), | |
153 | ||
154 | KEY(2, 0, KEY_UP), | |
155 | KEY(2, 2, KEY_DOWN), | |
156 | ||
157 | KEY(3, 0, KEY_RIGHT), | |
158 | KEY(3, 2, KEY_LEFT), | |
159 | }; | |
160 | ||
161 | static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = { | |
162 | .matrix_key_rows = 4, | |
163 | .matrix_key_cols = 3, | |
164 | .matrix_key_map = palmz72_matrix_keys, | |
165 | .matrix_key_map_size = ARRAY_SIZE(palmz72_matrix_keys), | |
166 | ||
167 | .debounce_interval = 30, | |
168 | }; | |
169 | ||
170 | /****************************************************************************** | |
171 | * Backlight | |
172 | ******************************************************************************/ | |
173 | static int palmz72_backlight_init(struct device *dev) | |
174 | { | |
175 | int ret; | |
176 | ||
177 | ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER"); | |
178 | if (ret) | |
179 | goto err; | |
180 | ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0); | |
181 | if (ret) | |
182 | goto err2; | |
183 | ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER"); | |
184 | if (ret) | |
185 | goto err2; | |
186 | ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0); | |
187 | if (ret) | |
188 | goto err3; | |
189 | ||
190 | return 0; | |
191 | err3: | |
192 | gpio_free(GPIO_NR_PALMZ72_LCD_POWER); | |
193 | err2: | |
194 | gpio_free(GPIO_NR_PALMZ72_BL_POWER); | |
195 | err: | |
196 | return ret; | |
197 | } | |
198 | ||
2d51a521 | 199 | static int palmz72_backlight_notify(struct device *dev, int brightness) |
c49e1e63 SL |
200 | { |
201 | gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness); | |
202 | gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness); | |
203 | return brightness; | |
204 | } | |
205 | ||
206 | static void palmz72_backlight_exit(struct device *dev) | |
207 | { | |
208 | gpio_free(GPIO_NR_PALMZ72_BL_POWER); | |
209 | gpio_free(GPIO_NR_PALMZ72_LCD_POWER); | |
210 | } | |
211 | ||
212 | static struct platform_pwm_backlight_data palmz72_backlight_data = { | |
213 | .pwm_id = 0, | |
214 | .max_brightness = PALMZ72_MAX_INTENSITY, | |
215 | .dft_brightness = PALMZ72_MAX_INTENSITY, | |
216 | .pwm_period_ns = PALMZ72_PERIOD_NS, | |
217 | .init = palmz72_backlight_init, | |
218 | .notify = palmz72_backlight_notify, | |
219 | .exit = palmz72_backlight_exit, | |
220 | }; | |
221 | ||
222 | static struct platform_device palmz72_backlight = { | |
223 | .name = "pwm-backlight", | |
224 | .dev = { | |
225 | .parent = &pxa27x_device_pwm0.dev, | |
226 | .platform_data = &palmz72_backlight_data, | |
227 | }, | |
228 | }; | |
229 | ||
230 | /****************************************************************************** | |
231 | * IrDA | |
232 | ******************************************************************************/ | |
c49e1e63 | 233 | static struct pxaficp_platform_data palmz72_ficp_platform_data = { |
c4bd0172 | 234 | .gpio_pwdown = GPIO_NR_PALMZ72_IR_DISABLE, |
c49e1e63 | 235 | .transceiver_cap = IR_SIRMODE | IR_OFF, |
c49e1e63 SL |
236 | }; |
237 | ||
238 | /****************************************************************************** | |
239 | * LEDs | |
240 | ******************************************************************************/ | |
241 | static struct gpio_led gpio_leds[] = { | |
242 | { | |
243 | .name = "palmz72:green:led", | |
244 | .default_trigger = "none", | |
245 | .gpio = GPIO_NR_PALMZ72_LED_GREEN, | |
246 | }, | |
247 | }; | |
248 | ||
249 | static struct gpio_led_platform_data gpio_led_info = { | |
250 | .leds = gpio_leds, | |
251 | .num_leds = ARRAY_SIZE(gpio_leds), | |
252 | }; | |
253 | ||
254 | static struct platform_device palmz72_leds = { | |
255 | .name = "leds-gpio", | |
256 | .id = -1, | |
257 | .dev = { | |
258 | .platform_data = &gpio_led_info, | |
259 | } | |
260 | }; | |
261 | ||
eb73e622 MV |
262 | /****************************************************************************** |
263 | * UDC | |
264 | ******************************************************************************/ | |
265 | static struct gpio_vbus_mach_info palmz72_udc_info = { | |
266 | .gpio_vbus = GPIO_NR_PALMZ72_USB_DETECT_N, | |
267 | .gpio_pullup = GPIO_NR_PALMZ72_USB_PULLUP, | |
268 | }; | |
269 | ||
270 | static struct platform_device palmz72_gpio_vbus = { | |
271 | .name = "gpio-vbus", | |
272 | .id = -1, | |
273 | .dev = { | |
274 | .platform_data = &palmz72_udc_info, | |
275 | }, | |
276 | }; | |
277 | ||
c49e1e63 SL |
278 | /****************************************************************************** |
279 | * Power supply | |
280 | ******************************************************************************/ | |
281 | static int power_supply_init(struct device *dev) | |
282 | { | |
283 | int ret; | |
284 | ||
285 | ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC"); | |
286 | if (ret) | |
287 | goto err1; | |
288 | ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT); | |
289 | if (ret) | |
290 | goto err2; | |
291 | ||
292 | ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB"); | |
293 | if (ret) | |
294 | goto err2; | |
295 | ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N); | |
296 | if (ret) | |
297 | goto err3; | |
298 | ||
299 | return 0; | |
300 | err3: | |
301 | gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N); | |
302 | err2: | |
303 | gpio_free(GPIO_NR_PALMZ72_POWER_DETECT); | |
304 | err1: | |
305 | return ret; | |
306 | } | |
307 | ||
308 | static int palmz72_is_ac_online(void) | |
309 | { | |
310 | return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT); | |
311 | } | |
312 | ||
313 | static int palmz72_is_usb_online(void) | |
314 | { | |
315 | return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N); | |
316 | } | |
317 | ||
318 | static void power_supply_exit(struct device *dev) | |
319 | { | |
320 | gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N); | |
321 | gpio_free(GPIO_NR_PALMZ72_POWER_DETECT); | |
322 | } | |
323 | ||
324 | static char *palmz72_supplicants[] = { | |
325 | "main-battery", | |
326 | }; | |
327 | ||
328 | static struct pda_power_pdata power_supply_info = { | |
329 | .init = power_supply_init, | |
330 | .is_ac_online = palmz72_is_ac_online, | |
331 | .is_usb_online = palmz72_is_usb_online, | |
332 | .exit = power_supply_exit, | |
333 | .supplied_to = palmz72_supplicants, | |
334 | .num_supplicants = ARRAY_SIZE(palmz72_supplicants), | |
335 | }; | |
336 | ||
337 | static struct platform_device power_supply = { | |
338 | .name = "pda-power", | |
339 | .id = -1, | |
340 | .dev = { | |
341 | .platform_data = &power_supply_info, | |
342 | }, | |
343 | }; | |
344 | ||
eb73e622 MV |
345 | /****************************************************************************** |
346 | * WM97xx battery | |
347 | ******************************************************************************/ | |
348 | static struct wm97xx_batt_info wm97xx_batt_pdata = { | |
349 | .batt_aux = WM97XX_AUX_ID3, | |
350 | .temp_aux = WM97XX_AUX_ID2, | |
351 | .charge_gpio = -1, | |
352 | .max_voltage = PALMZ72_BAT_MAX_VOLTAGE, | |
353 | .min_voltage = PALMZ72_BAT_MIN_VOLTAGE, | |
354 | .batt_mult = 1000, | |
355 | .batt_div = 414, | |
356 | .temp_mult = 1, | |
357 | .temp_div = 1, | |
358 | .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO, | |
359 | .batt_name = "main-batt", | |
360 | }; | |
361 | ||
362 | /****************************************************************************** | |
363 | * aSoC audio | |
364 | ******************************************************************************/ | |
365 | static struct platform_device palmz72_asoc = { | |
366 | .name = "palm27x-asoc", | |
367 | .id = -1, | |
368 | }; | |
369 | ||
c49e1e63 SL |
370 | /****************************************************************************** |
371 | * Framebuffer | |
372 | ******************************************************************************/ | |
373 | static struct pxafb_mode_info palmz72_lcd_modes[] = { | |
374 | { | |
375 | .pixclock = 115384, | |
376 | .xres = 320, | |
377 | .yres = 320, | |
378 | .bpp = 16, | |
379 | ||
380 | .left_margin = 27, | |
381 | .right_margin = 7, | |
382 | .upper_margin = 7, | |
383 | .lower_margin = 8, | |
384 | ||
385 | .hsync_len = 6, | |
386 | .vsync_len = 1, | |
387 | }, | |
388 | }; | |
389 | ||
390 | static struct pxafb_mach_info palmz72_lcd_screen = { | |
391 | .modes = palmz72_lcd_modes, | |
392 | .num_modes = ARRAY_SIZE(palmz72_lcd_modes), | |
393 | .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL, | |
394 | }; | |
395 | ||
fda50a1c SL |
396 | #ifdef CONFIG_PM |
397 | ||
398 | /* We have some black magic here | |
399 | * PalmOS ROM on recover expects special struct physical address | |
400 | * to be transferred via PSPR. Using this struct PalmOS restores | |
401 | * its state after sleep. As for Linux, we need to setup it the | |
402 | * same way. More than that, PalmOS ROM changes some values in memory. | |
403 | * For now only one location is found, which needs special treatment. | |
404 | * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people | |
405 | * for reading backtraces for me :) | |
406 | */ | |
407 | ||
408 | #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050) | |
409 | ||
410 | static struct palmz72_resume_info palmz72_resume_info = { | |
411 | .magic0 = 0xb4e6, | |
412 | .magic1 = 1, | |
413 | ||
414 | /* reset state, MMU off etc */ | |
415 | .arm_control = 0, | |
416 | .aux_control = 0, | |
417 | .ttb = 0, | |
418 | .domain_access = 0, | |
419 | .process_id = 0, | |
420 | }; | |
421 | ||
422 | static unsigned long store_ptr; | |
423 | ||
424 | /* sys_device for Palm Zire 72 PM */ | |
425 | ||
426 | static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg) | |
427 | { | |
428 | /* setup the resume_info struct for the original bootloader */ | |
429 | palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume; | |
430 | ||
431 | /* Storing memory touched by ROM */ | |
432 | store_ptr = *PALMZ72_SAVE_DWORD; | |
433 | ||
434 | /* Setting PSPR to a proper value */ | |
435 | PSPR = virt_to_phys(&palmz72_resume_info); | |
436 | ||
437 | return 0; | |
438 | } | |
439 | ||
440 | static int palmz72_pm_resume(struct sys_device *dev) | |
441 | { | |
442 | *PALMZ72_SAVE_DWORD = store_ptr; | |
443 | return 0; | |
444 | } | |
445 | ||
446 | static struct sysdev_class palmz72_pm_sysclass = { | |
447 | .name = "palmz72_pm", | |
448 | .suspend = palmz72_pm_suspend, | |
449 | .resume = palmz72_pm_resume, | |
450 | }; | |
451 | ||
452 | static struct sys_device palmz72_pm_device = { | |
453 | .cls = &palmz72_pm_sysclass, | |
454 | }; | |
455 | ||
456 | static int __init palmz72_pm_init(void) | |
457 | { | |
458 | int ret = -ENODEV; | |
459 | if (machine_is_palmz72()) { | |
460 | ret = sysdev_class_register(&palmz72_pm_sysclass); | |
461 | if (ret == 0) | |
462 | ret = sysdev_register(&palmz72_pm_device); | |
463 | } | |
464 | return ret; | |
465 | } | |
466 | ||
467 | device_initcall(palmz72_pm_init); | |
468 | #endif | |
469 | ||
c49e1e63 SL |
470 | /****************************************************************************** |
471 | * Machine init | |
472 | ******************************************************************************/ | |
473 | static struct platform_device *devices[] __initdata = { | |
474 | &palmz72_backlight, | |
475 | &palmz72_leds, | |
eb73e622 | 476 | &palmz72_asoc, |
c49e1e63 | 477 | &power_supply, |
eb73e622 | 478 | &palmz72_gpio_vbus, |
c49e1e63 SL |
479 | }; |
480 | ||
eb73e622 MV |
481 | /* setup udc GPIOs initial state */ |
482 | static void __init palmz72_udc_init(void) | |
483 | { | |
484 | if (!gpio_request(GPIO_NR_PALMZ72_USB_PULLUP, "USB Pullup")) { | |
485 | gpio_direction_output(GPIO_NR_PALMZ72_USB_PULLUP, 0); | |
486 | gpio_free(GPIO_NR_PALMZ72_USB_PULLUP); | |
487 | } | |
488 | } | |
489 | ||
c49e1e63 SL |
490 | static void __init palmz72_init(void) |
491 | { | |
492 | pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config)); | |
eb73e622 | 493 | |
cc155c6f RK |
494 | pxa_set_ffuart_info(NULL); |
495 | pxa_set_btuart_info(NULL); | |
496 | pxa_set_stuart_info(NULL); | |
497 | ||
c49e1e63 SL |
498 | set_pxa_fb_info(&palmz72_lcd_screen); |
499 | pxa_set_mci_info(&palmz72_mci_platform_data); | |
eb73e622 | 500 | palmz72_udc_init(); |
c49e1e63 SL |
501 | pxa_set_ac97_info(NULL); |
502 | pxa_set_ficp_info(&palmz72_ficp_platform_data); | |
503 | pxa_set_keypad_info(&palmz72_keypad_platform_data); | |
eb73e622 MV |
504 | wm97xx_bat_set_pdata(&wm97xx_batt_pdata); |
505 | ||
c49e1e63 SL |
506 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
507 | } | |
508 | ||
509 | MACHINE_START(PALMZ72, "Palm Zire72") | |
510 | .phys_io = 0x40000000, | |
511 | .io_pg_offst = io_p2v(0x40000000), | |
512 | .boot_params = 0xa0000100, | |
513 | .map_io = pxa_map_io, | |
514 | .init_irq = pxa27x_init_irq, | |
515 | .timer = &pxa_timer, | |
516 | .init_machine = palmz72_init | |
517 | MACHINE_END |