2 * Hardware definitions for Palm Zire72
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>
10 * Rewrite for mainline:
11 * Marek Vasut <marek.vasut@gmail.com>
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.
17 * (find more info at www.hackndev.com)
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>
30 #include <linux/wm97xx_batt.h>
31 #include <linux/power_supply.h>
32 #include <linux/usb/gpio_vbus.h>
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
38 #include <mach/pxa27x.h>
39 #include <mach/audio.h>
40 #include <mach/palmz72.h>
42 #include <mach/pxafb.h>
43 #include <mach/irda.h>
44 #include <mach/pxa27x_keypad.h>
46 #include <mach/palmasoc.h>
53 /******************************************************************************
55 ******************************************************************************/
56 static unsigned long palmz72_pin_config[] __initdata = {
64 GPIO14_GPIO, /* SD detect */
65 GPIO115_GPIO, /* SD RO */
66 GPIO98_GPIO, /* SD power */
70 GPIO29_AC97_SDATA_IN_0,
71 GPIO30_AC97_SDATA_OUT,
77 GPIO49_GPIO, /* ir disable */
85 GPIO15_GPIO, /* usb detect */
86 GPIO95_GPIO, /* usb pullup */
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,
118 GPIO20_GPIO, /* bl power */
119 GPIO21_GPIO, /* LCD border switch */
120 GPIO22_GPIO, /* LCD border color */
121 GPIO96_GPIO, /* lcd power */
124 GPIO0_GPIO | WAKEUP_ON_LEVEL_HIGH, /* power detect */
125 GPIO88_GPIO, /* green led */
126 GPIO27_GPIO, /* WM9712 IRQ */
129 /******************************************************************************
130 * SD/MMC card controller
131 ******************************************************************************/
132 /* SD_POWER is not actually power, but it is more like chip
133 * select, i.e. it is inverted */
134 static struct pxamci_platform_data palmz72_mci_platform_data = {
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,
142 /******************************************************************************
144 ******************************************************************************/
145 static unsigned int palmz72_matrix_keys[] = {
146 KEY(0, 0, KEY_POWER),
148 KEY(0, 2, KEY_ENTER),
157 KEY(3, 0, KEY_RIGHT),
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),
167 .debounce_interval = 30,
170 /******************************************************************************
172 ******************************************************************************/
173 static int palmz72_backlight_init(struct device *dev)
177 ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
180 ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
183 ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
186 ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
192 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
194 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
199 static int palmz72_backlight_notify(int brightness)
201 gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
202 gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
206 static void palmz72_backlight_exit(struct device *dev)
208 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
209 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
212 static struct platform_pwm_backlight_data palmz72_backlight_data = {
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,
222 static struct platform_device palmz72_backlight = {
223 .name = "pwm-backlight",
225 .parent = &pxa27x_device_pwm0.dev,
226 .platform_data = &palmz72_backlight_data,
230 /******************************************************************************
232 ******************************************************************************/
233 static int palmz72_irda_startup(struct device *dev)
236 err = gpio_request(GPIO_NR_PALMZ72_IR_DISABLE, "IR DISABLE");
239 err = gpio_direction_output(GPIO_NR_PALMZ72_IR_DISABLE, 1);
241 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
246 static void palmz72_irda_shutdown(struct device *dev)
248 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
251 static void palmz72_irda_transceiver_mode(struct device *dev, int mode)
253 gpio_set_value(GPIO_NR_PALMZ72_IR_DISABLE, mode & IR_OFF);
254 pxa2xx_transceiver_mode(dev, mode);
257 static struct pxaficp_platform_data palmz72_ficp_platform_data = {
258 .startup = palmz72_irda_startup,
259 .shutdown = palmz72_irda_shutdown,
260 .transceiver_cap = IR_SIRMODE | IR_OFF,
261 .transceiver_mode = palmz72_irda_transceiver_mode,
264 /******************************************************************************
266 ******************************************************************************/
267 static struct gpio_led gpio_leds[] = {
269 .name = "palmz72:green:led",
270 .default_trigger = "none",
271 .gpio = GPIO_NR_PALMZ72_LED_GREEN,
275 static struct gpio_led_platform_data gpio_led_info = {
277 .num_leds = ARRAY_SIZE(gpio_leds),
280 static struct platform_device palmz72_leds = {
284 .platform_data = &gpio_led_info,
288 /******************************************************************************
290 ******************************************************************************/
291 static struct gpio_vbus_mach_info palmz72_udc_info = {
292 .gpio_vbus = GPIO_NR_PALMZ72_USB_DETECT_N,
293 .gpio_pullup = GPIO_NR_PALMZ72_USB_PULLUP,
296 static struct platform_device palmz72_gpio_vbus = {
300 .platform_data = &palmz72_udc_info,
304 /******************************************************************************
306 ******************************************************************************/
307 static int power_supply_init(struct device *dev)
311 ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
314 ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
318 ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
321 ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
327 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
329 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
334 static int palmz72_is_ac_online(void)
336 return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
339 static int palmz72_is_usb_online(void)
341 return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N);
344 static void power_supply_exit(struct device *dev)
346 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
347 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
350 static char *palmz72_supplicants[] = {
354 static struct pda_power_pdata power_supply_info = {
355 .init = power_supply_init,
356 .is_ac_online = palmz72_is_ac_online,
357 .is_usb_online = palmz72_is_usb_online,
358 .exit = power_supply_exit,
359 .supplied_to = palmz72_supplicants,
360 .num_supplicants = ARRAY_SIZE(palmz72_supplicants),
363 static struct platform_device power_supply = {
367 .platform_data = &power_supply_info,
371 /******************************************************************************
373 ******************************************************************************/
374 static struct wm97xx_batt_info wm97xx_batt_pdata = {
375 .batt_aux = WM97XX_AUX_ID3,
376 .temp_aux = WM97XX_AUX_ID2,
378 .max_voltage = PALMZ72_BAT_MAX_VOLTAGE,
379 .min_voltage = PALMZ72_BAT_MIN_VOLTAGE,
384 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
385 .batt_name = "main-batt",
388 /******************************************************************************
390 ******************************************************************************/
391 static struct platform_device palmz72_asoc = {
392 .name = "palm27x-asoc",
396 /******************************************************************************
398 ******************************************************************************/
399 static struct pxafb_mode_info palmz72_lcd_modes[] = {
416 static struct pxafb_mach_info palmz72_lcd_screen = {
417 .modes = palmz72_lcd_modes,
418 .num_modes = ARRAY_SIZE(palmz72_lcd_modes),
419 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
424 /* We have some black magic here
425 * PalmOS ROM on recover expects special struct physical address
426 * to be transferred via PSPR. Using this struct PalmOS restores
427 * its state after sleep. As for Linux, we need to setup it the
428 * same way. More than that, PalmOS ROM changes some values in memory.
429 * For now only one location is found, which needs special treatment.
430 * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
431 * for reading backtraces for me :)
434 #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
436 static struct palmz72_resume_info palmz72_resume_info = {
440 /* reset state, MMU off etc */
448 static unsigned long store_ptr;
450 /* sys_device for Palm Zire 72 PM */
452 static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
454 /* setup the resume_info struct for the original bootloader */
455 palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume;
457 /* Storing memory touched by ROM */
458 store_ptr = *PALMZ72_SAVE_DWORD;
460 /* Setting PSPR to a proper value */
461 PSPR = virt_to_phys(&palmz72_resume_info);
466 static int palmz72_pm_resume(struct sys_device *dev)
468 *PALMZ72_SAVE_DWORD = store_ptr;
472 static struct sysdev_class palmz72_pm_sysclass = {
473 .name = "palmz72_pm",
474 .suspend = palmz72_pm_suspend,
475 .resume = palmz72_pm_resume,
478 static struct sys_device palmz72_pm_device = {
479 .cls = &palmz72_pm_sysclass,
482 static int __init palmz72_pm_init(void)
485 if (machine_is_palmz72()) {
486 ret = sysdev_class_register(&palmz72_pm_sysclass);
488 ret = sysdev_register(&palmz72_pm_device);
493 device_initcall(palmz72_pm_init);
496 /******************************************************************************
498 ******************************************************************************/
499 static struct platform_device *devices[] __initdata = {
507 /* setup udc GPIOs initial state */
508 static void __init palmz72_udc_init(void)
510 if (!gpio_request(GPIO_NR_PALMZ72_USB_PULLUP, "USB Pullup")) {
511 gpio_direction_output(GPIO_NR_PALMZ72_USB_PULLUP, 0);
512 gpio_free(GPIO_NR_PALMZ72_USB_PULLUP);
516 static void __init palmz72_init(void)
518 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
520 set_pxa_fb_info(&palmz72_lcd_screen);
521 pxa_set_mci_info(&palmz72_mci_platform_data);
523 pxa_set_ac97_info(NULL);
524 pxa_set_ficp_info(&palmz72_ficp_platform_data);
525 pxa_set_keypad_info(&palmz72_keypad_platform_data);
526 wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
528 platform_add_devices(devices, ARRAY_SIZE(devices));
531 MACHINE_START(PALMZ72, "Palm Zire72")
532 .phys_io = 0x40000000,
533 .io_pg_offst = io_p2v(0x40000000),
534 .boot_params = 0xa0000100,
535 .map_io = pxa_map_io,
536 .init_irq = pxa27x_init_irq,
538 .init_machine = palmz72_init