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 static int palmz72_mci_init(struct device
*dev
,
133 irq_handler_t palmz72_detect_int
, void *data
)
137 /* Setup an interrupt for detecting card insert/remove events */
138 err
= gpio_request(GPIO_NR_PALMZ72_SD_DETECT_N
, "SD IRQ");
141 err
= gpio_direction_input(GPIO_NR_PALMZ72_SD_DETECT_N
);
144 err
= request_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N
),
145 palmz72_detect_int
, IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
|
146 IRQF_TRIGGER_FALLING
| IRQF_TRIGGER_RISING
,
147 "SD/MMC card detect", data
);
149 printk(KERN_ERR
"%s: cannot request SD/MMC card detect IRQ\n",
154 /* SD_POWER is not actually power, but it is more like chip
155 * select, i.e. it is inverted */
157 err
= gpio_request(GPIO_NR_PALMZ72_SD_POWER_N
, "SD_POWER");
160 err
= gpio_direction_output(GPIO_NR_PALMZ72_SD_POWER_N
, 0);
163 err
= gpio_request(GPIO_NR_PALMZ72_SD_RO
, "SD_RO");
166 err
= gpio_direction_input(GPIO_NR_PALMZ72_SD_RO
);
170 printk(KERN_DEBUG
"%s: irq registered\n", __func__
);
175 gpio_free(GPIO_NR_PALMZ72_SD_RO
);
177 gpio_free(GPIO_NR_PALMZ72_SD_POWER_N
);
179 free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N
), data
);
181 gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N
);
186 static void palmz72_mci_exit(struct device
*dev
, void *data
)
188 gpio_free(GPIO_NR_PALMZ72_SD_POWER_N
);
189 free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N
), data
);
190 gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N
);
191 gpio_free(GPIO_NR_PALMZ72_SD_RO
);
194 static void palmz72_mci_power(struct device
*dev
, unsigned int vdd
)
196 struct pxamci_platform_data
*p_d
= dev
->platform_data
;
197 if (p_d
->ocr_mask
& (1 << vdd
))
198 gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N
, 0);
200 gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N
, 1);
203 static int palmz72_mci_ro(struct device
*dev
)
205 return gpio_get_value(GPIO_NR_PALMZ72_SD_RO
);
208 static struct pxamci_platform_data palmz72_mci_platform_data
= {
209 .ocr_mask
= MMC_VDD_32_33
| MMC_VDD_33_34
,
210 .setpower
= palmz72_mci_power
,
211 .get_ro
= palmz72_mci_ro
,
212 .init
= palmz72_mci_init
,
213 .exit
= palmz72_mci_exit
,
216 /******************************************************************************
218 ******************************************************************************/
219 static unsigned int palmz72_matrix_keys
[] = {
220 KEY(0, 0, KEY_POWER
),
222 KEY(0, 2, KEY_ENTER
),
231 KEY(3, 0, KEY_RIGHT
),
235 static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data
= {
236 .matrix_key_rows
= 4,
237 .matrix_key_cols
= 3,
238 .matrix_key_map
= palmz72_matrix_keys
,
239 .matrix_key_map_size
= ARRAY_SIZE(palmz72_matrix_keys
),
241 .debounce_interval
= 30,
244 /******************************************************************************
246 ******************************************************************************/
247 static int palmz72_backlight_init(struct device
*dev
)
251 ret
= gpio_request(GPIO_NR_PALMZ72_BL_POWER
, "BL POWER");
254 ret
= gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER
, 0);
257 ret
= gpio_request(GPIO_NR_PALMZ72_LCD_POWER
, "LCD POWER");
260 ret
= gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER
, 0);
266 gpio_free(GPIO_NR_PALMZ72_LCD_POWER
);
268 gpio_free(GPIO_NR_PALMZ72_BL_POWER
);
273 static int palmz72_backlight_notify(int brightness
)
275 gpio_set_value(GPIO_NR_PALMZ72_BL_POWER
, brightness
);
276 gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER
, brightness
);
280 static void palmz72_backlight_exit(struct device
*dev
)
282 gpio_free(GPIO_NR_PALMZ72_BL_POWER
);
283 gpio_free(GPIO_NR_PALMZ72_LCD_POWER
);
286 static struct platform_pwm_backlight_data palmz72_backlight_data
= {
288 .max_brightness
= PALMZ72_MAX_INTENSITY
,
289 .dft_brightness
= PALMZ72_MAX_INTENSITY
,
290 .pwm_period_ns
= PALMZ72_PERIOD_NS
,
291 .init
= palmz72_backlight_init
,
292 .notify
= palmz72_backlight_notify
,
293 .exit
= palmz72_backlight_exit
,
296 static struct platform_device palmz72_backlight
= {
297 .name
= "pwm-backlight",
299 .parent
= &pxa27x_device_pwm0
.dev
,
300 .platform_data
= &palmz72_backlight_data
,
304 /******************************************************************************
306 ******************************************************************************/
307 static int palmz72_irda_startup(struct device
*dev
)
310 err
= gpio_request(GPIO_NR_PALMZ72_IR_DISABLE
, "IR DISABLE");
313 err
= gpio_direction_output(GPIO_NR_PALMZ72_IR_DISABLE
, 1);
315 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE
);
320 static void palmz72_irda_shutdown(struct device
*dev
)
322 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE
);
325 static void palmz72_irda_transceiver_mode(struct device
*dev
, int mode
)
327 gpio_set_value(GPIO_NR_PALMZ72_IR_DISABLE
, mode
& IR_OFF
);
328 pxa2xx_transceiver_mode(dev
, mode
);
331 static struct pxaficp_platform_data palmz72_ficp_platform_data
= {
332 .startup
= palmz72_irda_startup
,
333 .shutdown
= palmz72_irda_shutdown
,
334 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
335 .transceiver_mode
= palmz72_irda_transceiver_mode
,
338 /******************************************************************************
340 ******************************************************************************/
341 static struct gpio_led gpio_leds
[] = {
343 .name
= "palmz72:green:led",
344 .default_trigger
= "none",
345 .gpio
= GPIO_NR_PALMZ72_LED_GREEN
,
349 static struct gpio_led_platform_data gpio_led_info
= {
351 .num_leds
= ARRAY_SIZE(gpio_leds
),
354 static struct platform_device palmz72_leds
= {
358 .platform_data
= &gpio_led_info
,
362 /******************************************************************************
364 ******************************************************************************/
365 static struct gpio_vbus_mach_info palmz72_udc_info
= {
366 .gpio_vbus
= GPIO_NR_PALMZ72_USB_DETECT_N
,
367 .gpio_pullup
= GPIO_NR_PALMZ72_USB_PULLUP
,
370 static struct platform_device palmz72_gpio_vbus
= {
374 .platform_data
= &palmz72_udc_info
,
378 /******************************************************************************
380 ******************************************************************************/
381 static int power_supply_init(struct device
*dev
)
385 ret
= gpio_request(GPIO_NR_PALMZ72_POWER_DETECT
, "CABLE_STATE_AC");
388 ret
= gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT
);
392 ret
= gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N
, "CABLE_STATE_USB");
395 ret
= gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N
);
401 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N
);
403 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT
);
408 static int palmz72_is_ac_online(void)
410 return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT
);
413 static int palmz72_is_usb_online(void)
415 return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N
);
418 static void power_supply_exit(struct device
*dev
)
420 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N
);
421 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT
);
424 static char *palmz72_supplicants
[] = {
428 static struct pda_power_pdata power_supply_info
= {
429 .init
= power_supply_init
,
430 .is_ac_online
= palmz72_is_ac_online
,
431 .is_usb_online
= palmz72_is_usb_online
,
432 .exit
= power_supply_exit
,
433 .supplied_to
= palmz72_supplicants
,
434 .num_supplicants
= ARRAY_SIZE(palmz72_supplicants
),
437 static struct platform_device power_supply
= {
441 .platform_data
= &power_supply_info
,
445 /******************************************************************************
447 ******************************************************************************/
448 static struct wm97xx_batt_info wm97xx_batt_pdata
= {
449 .batt_aux
= WM97XX_AUX_ID3
,
450 .temp_aux
= WM97XX_AUX_ID2
,
452 .max_voltage
= PALMZ72_BAT_MAX_VOLTAGE
,
453 .min_voltage
= PALMZ72_BAT_MIN_VOLTAGE
,
458 .batt_tech
= POWER_SUPPLY_TECHNOLOGY_LIPO
,
459 .batt_name
= "main-batt",
462 /******************************************************************************
464 ******************************************************************************/
465 static struct platform_device palmz72_asoc
= {
466 .name
= "palm27x-asoc",
470 /******************************************************************************
472 ******************************************************************************/
473 static struct pxafb_mode_info palmz72_lcd_modes
[] = {
490 static struct pxafb_mach_info palmz72_lcd_screen
= {
491 .modes
= palmz72_lcd_modes
,
492 .num_modes
= ARRAY_SIZE(palmz72_lcd_modes
),
493 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_PCLK_EDGE_FALL
,
498 /* We have some black magic here
499 * PalmOS ROM on recover expects special struct physical address
500 * to be transferred via PSPR. Using this struct PalmOS restores
501 * its state after sleep. As for Linux, we need to setup it the
502 * same way. More than that, PalmOS ROM changes some values in memory.
503 * For now only one location is found, which needs special treatment.
504 * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
505 * for reading backtraces for me :)
508 #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
510 static struct palmz72_resume_info palmz72_resume_info
= {
514 /* reset state, MMU off etc */
522 static unsigned long store_ptr
;
524 /* sys_device for Palm Zire 72 PM */
526 static int palmz72_pm_suspend(struct sys_device
*dev
, pm_message_t msg
)
528 /* setup the resume_info struct for the original bootloader */
529 palmz72_resume_info
.resume_addr
= (u32
) pxa_cpu_resume
;
531 /* Storing memory touched by ROM */
532 store_ptr
= *PALMZ72_SAVE_DWORD
;
534 /* Setting PSPR to a proper value */
535 PSPR
= virt_to_phys(&palmz72_resume_info
);
540 static int palmz72_pm_resume(struct sys_device
*dev
)
542 *PALMZ72_SAVE_DWORD
= store_ptr
;
546 static struct sysdev_class palmz72_pm_sysclass
= {
547 .name
= "palmz72_pm",
548 .suspend
= palmz72_pm_suspend
,
549 .resume
= palmz72_pm_resume
,
552 static struct sys_device palmz72_pm_device
= {
553 .cls
= &palmz72_pm_sysclass
,
556 static int __init
palmz72_pm_init(void)
559 if (machine_is_palmz72()) {
560 ret
= sysdev_class_register(&palmz72_pm_sysclass
);
562 ret
= sysdev_register(&palmz72_pm_device
);
567 device_initcall(palmz72_pm_init
);
570 /******************************************************************************
572 ******************************************************************************/
573 static struct platform_device
*devices
[] __initdata
= {
581 /* setup udc GPIOs initial state */
582 static void __init
palmz72_udc_init(void)
584 if (!gpio_request(GPIO_NR_PALMZ72_USB_PULLUP
, "USB Pullup")) {
585 gpio_direction_output(GPIO_NR_PALMZ72_USB_PULLUP
, 0);
586 gpio_free(GPIO_NR_PALMZ72_USB_PULLUP
);
590 static void __init
palmz72_init(void)
592 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config
));
594 set_pxa_fb_info(&palmz72_lcd_screen
);
595 pxa_set_mci_info(&palmz72_mci_platform_data
);
597 pxa_set_ac97_info(NULL
);
598 pxa_set_ficp_info(&palmz72_ficp_platform_data
);
599 pxa_set_keypad_info(&palmz72_keypad_platform_data
);
600 wm97xx_bat_set_pdata(&wm97xx_batt_pdata
);
602 platform_add_devices(devices
, ARRAY_SIZE(devices
));
605 MACHINE_START(PALMZ72
, "Palm Zire72")
606 .phys_io
= 0x40000000,
607 .io_pg_offst
= io_p2v(0x40000000),
608 .boot_params
= 0xa0000100,
609 .map_io
= pxa_map_io
,
610 .init_irq
= pxa27x_init_irq
,
612 .init_machine
= palmz72_init