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/power_supply.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
36 #include <mach/pxa27x.h>
37 #include <mach/audio.h>
38 #include <mach/palmz72.h>
40 #include <mach/pxafb.h>
41 #include <mach/irda.h>
42 #include <mach/pxa27x_keypad.h>
49 /******************************************************************************
51 ******************************************************************************/
52 static unsigned long palmz72_pin_config
[] __initdata
= {
60 GPIO14_GPIO
, /* SD detect */
61 GPIO115_GPIO
, /* SD RO */
62 GPIO98_GPIO
, /* SD power */
66 GPIO29_AC97_SDATA_IN_0
,
67 GPIO30_AC97_SDATA_OUT
,
71 GPIO49_GPIO
, /* ir disable */
79 GPIO15_GPIO
, /* usb detect */
80 GPIO12_GPIO
, /* usb pullup */
81 GPIO95_GPIO
, /* usb power */
84 GPIO100_KP_MKIN_0
| WAKEUP_ON_LEVEL_HIGH
,
85 GPIO101_KP_MKIN_1
| WAKEUP_ON_LEVEL_HIGH
,
86 GPIO102_KP_MKIN_2
| WAKEUP_ON_LEVEL_HIGH
,
87 GPIO97_KP_MKIN_3
| WAKEUP_ON_LEVEL_HIGH
,
113 GPIO20_GPIO
, /* bl power */
114 GPIO21_GPIO
, /* LCD border switch */
115 GPIO22_GPIO
, /* LCD border color */
116 GPIO96_GPIO
, /* lcd power */
119 GPIO0_GPIO
| WAKEUP_ON_LEVEL_HIGH
, /* power detect */
120 GPIO88_GPIO
, /* green led */
121 GPIO27_GPIO
, /* WM9712 IRQ */
124 /******************************************************************************
125 * SD/MMC card controller
126 ******************************************************************************/
127 static int palmz72_mci_init(struct device
*dev
,
128 irq_handler_t palmz72_detect_int
, void *data
)
132 /* Setup an interrupt for detecting card insert/remove events */
133 err
= gpio_request(GPIO_NR_PALMZ72_SD_DETECT_N
, "SD IRQ");
136 err
= gpio_direction_input(GPIO_NR_PALMZ72_SD_DETECT_N
);
139 err
= request_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N
),
140 palmz72_detect_int
, IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
|
141 IRQF_TRIGGER_FALLING
| IRQF_TRIGGER_RISING
,
142 "SD/MMC card detect", data
);
144 printk(KERN_ERR
"%s: cannot request SD/MMC card detect IRQ\n",
149 /* SD_POWER is not actually power, but it is more like chip
150 * select, i.e. it is inverted */
152 err
= gpio_request(GPIO_NR_PALMZ72_SD_POWER_N
, "SD_POWER");
155 err
= gpio_direction_output(GPIO_NR_PALMZ72_SD_POWER_N
, 0);
158 err
= gpio_request(GPIO_NR_PALMZ72_SD_RO
, "SD_RO");
161 err
= gpio_direction_input(GPIO_NR_PALMZ72_SD_RO
);
165 printk(KERN_DEBUG
"%s: irq registered\n", __func__
);
170 gpio_free(GPIO_NR_PALMZ72_SD_RO
);
172 gpio_free(GPIO_NR_PALMZ72_SD_POWER_N
);
174 free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N
), data
);
176 gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N
);
181 static void palmz72_mci_exit(struct device
*dev
, void *data
)
183 gpio_free(GPIO_NR_PALMZ72_SD_POWER_N
);
184 free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N
), data
);
185 gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N
);
186 gpio_free(GPIO_NR_PALMZ72_SD_RO
);
189 static void palmz72_mci_power(struct device
*dev
, unsigned int vdd
)
191 struct pxamci_platform_data
*p_d
= dev
->platform_data
;
192 if (p_d
->ocr_mask
& (1 << vdd
))
193 gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N
, 0);
195 gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N
, 1);
198 static int palmz72_mci_ro(struct device
*dev
)
200 return gpio_get_value(GPIO_NR_PALMZ72_SD_RO
);
203 static struct pxamci_platform_data palmz72_mci_platform_data
= {
204 .ocr_mask
= MMC_VDD_32_33
| MMC_VDD_33_34
,
205 .setpower
= palmz72_mci_power
,
206 .get_ro
= palmz72_mci_ro
,
207 .init
= palmz72_mci_init
,
208 .exit
= palmz72_mci_exit
,
211 /******************************************************************************
213 ******************************************************************************/
214 static unsigned int palmz72_matrix_keys
[] = {
215 KEY(0, 0, KEY_POWER
),
217 KEY(0, 2, KEY_ENTER
),
226 KEY(3, 0, KEY_RIGHT
),
230 static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data
= {
231 .matrix_key_rows
= 4,
232 .matrix_key_cols
= 3,
233 .matrix_key_map
= palmz72_matrix_keys
,
234 .matrix_key_map_size
= ARRAY_SIZE(palmz72_matrix_keys
),
236 .debounce_interval
= 30,
239 /******************************************************************************
241 ******************************************************************************/
242 static int palmz72_backlight_init(struct device
*dev
)
246 ret
= gpio_request(GPIO_NR_PALMZ72_BL_POWER
, "BL POWER");
249 ret
= gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER
, 0);
252 ret
= gpio_request(GPIO_NR_PALMZ72_LCD_POWER
, "LCD POWER");
255 ret
= gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER
, 0);
261 gpio_free(GPIO_NR_PALMZ72_LCD_POWER
);
263 gpio_free(GPIO_NR_PALMZ72_BL_POWER
);
268 static int palmz72_backlight_notify(int brightness
)
270 gpio_set_value(GPIO_NR_PALMZ72_BL_POWER
, brightness
);
271 gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER
, brightness
);
275 static void palmz72_backlight_exit(struct device
*dev
)
277 gpio_free(GPIO_NR_PALMZ72_BL_POWER
);
278 gpio_free(GPIO_NR_PALMZ72_LCD_POWER
);
281 static struct platform_pwm_backlight_data palmz72_backlight_data
= {
283 .max_brightness
= PALMZ72_MAX_INTENSITY
,
284 .dft_brightness
= PALMZ72_MAX_INTENSITY
,
285 .pwm_period_ns
= PALMZ72_PERIOD_NS
,
286 .init
= palmz72_backlight_init
,
287 .notify
= palmz72_backlight_notify
,
288 .exit
= palmz72_backlight_exit
,
291 static struct platform_device palmz72_backlight
= {
292 .name
= "pwm-backlight",
294 .parent
= &pxa27x_device_pwm0
.dev
,
295 .platform_data
= &palmz72_backlight_data
,
299 /******************************************************************************
301 ******************************************************************************/
302 static int palmz72_irda_startup(struct device
*dev
)
305 err
= gpio_request(GPIO_NR_PALMZ72_IR_DISABLE
, "IR DISABLE");
308 err
= gpio_direction_output(GPIO_NR_PALMZ72_IR_DISABLE
, 1);
310 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE
);
315 static void palmz72_irda_shutdown(struct device
*dev
)
317 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE
);
320 static void palmz72_irda_transceiver_mode(struct device
*dev
, int mode
)
322 gpio_set_value(GPIO_NR_PALMZ72_IR_DISABLE
, mode
& IR_OFF
);
323 pxa2xx_transceiver_mode(dev
, mode
);
326 static struct pxaficp_platform_data palmz72_ficp_platform_data
= {
327 .startup
= palmz72_irda_startup
,
328 .shutdown
= palmz72_irda_shutdown
,
329 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
330 .transceiver_mode
= palmz72_irda_transceiver_mode
,
333 /******************************************************************************
335 ******************************************************************************/
336 static struct gpio_led gpio_leds
[] = {
338 .name
= "palmz72:green:led",
339 .default_trigger
= "none",
340 .gpio
= GPIO_NR_PALMZ72_LED_GREEN
,
344 static struct gpio_led_platform_data gpio_led_info
= {
346 .num_leds
= ARRAY_SIZE(gpio_leds
),
349 static struct platform_device palmz72_leds
= {
353 .platform_data
= &gpio_led_info
,
357 /******************************************************************************
359 ******************************************************************************/
360 static int power_supply_init(struct device
*dev
)
364 ret
= gpio_request(GPIO_NR_PALMZ72_POWER_DETECT
, "CABLE_STATE_AC");
367 ret
= gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT
);
371 ret
= gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N
, "CABLE_STATE_USB");
374 ret
= gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N
);
380 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N
);
382 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT
);
387 static int palmz72_is_ac_online(void)
389 return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT
);
392 static int palmz72_is_usb_online(void)
394 return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N
);
397 static void power_supply_exit(struct device
*dev
)
399 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N
);
400 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT
);
403 static char *palmz72_supplicants
[] = {
407 static struct pda_power_pdata power_supply_info
= {
408 .init
= power_supply_init
,
409 .is_ac_online
= palmz72_is_ac_online
,
410 .is_usb_online
= palmz72_is_usb_online
,
411 .exit
= power_supply_exit
,
412 .supplied_to
= palmz72_supplicants
,
413 .num_supplicants
= ARRAY_SIZE(palmz72_supplicants
),
416 static struct platform_device power_supply
= {
420 .platform_data
= &power_supply_info
,
424 /******************************************************************************
426 ******************************************************************************/
427 static struct pxafb_mode_info palmz72_lcd_modes
[] = {
444 static struct pxafb_mach_info palmz72_lcd_screen
= {
445 .modes
= palmz72_lcd_modes
,
446 .num_modes
= ARRAY_SIZE(palmz72_lcd_modes
),
447 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_PCLK_EDGE_FALL
,
452 /* We have some black magic here
453 * PalmOS ROM on recover expects special struct physical address
454 * to be transferred via PSPR. Using this struct PalmOS restores
455 * its state after sleep. As for Linux, we need to setup it the
456 * same way. More than that, PalmOS ROM changes some values in memory.
457 * For now only one location is found, which needs special treatment.
458 * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
459 * for reading backtraces for me :)
462 #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
464 static struct palmz72_resume_info palmz72_resume_info
= {
468 /* reset state, MMU off etc */
476 static unsigned long store_ptr
;
478 /* sys_device for Palm Zire 72 PM */
480 static int palmz72_pm_suspend(struct sys_device
*dev
, pm_message_t msg
)
482 /* setup the resume_info struct for the original bootloader */
483 palmz72_resume_info
.resume_addr
= (u32
) pxa_cpu_resume
;
485 /* Storing memory touched by ROM */
486 store_ptr
= *PALMZ72_SAVE_DWORD
;
488 /* Setting PSPR to a proper value */
489 PSPR
= virt_to_phys(&palmz72_resume_info
);
494 static int palmz72_pm_resume(struct sys_device
*dev
)
496 *PALMZ72_SAVE_DWORD
= store_ptr
;
500 static struct sysdev_class palmz72_pm_sysclass
= {
501 .name
= "palmz72_pm",
502 .suspend
= palmz72_pm_suspend
,
503 .resume
= palmz72_pm_resume
,
506 static struct sys_device palmz72_pm_device
= {
507 .cls
= &palmz72_pm_sysclass
,
510 static int __init
palmz72_pm_init(void)
513 if (machine_is_palmz72()) {
514 ret
= sysdev_class_register(&palmz72_pm_sysclass
);
516 ret
= sysdev_register(&palmz72_pm_device
);
521 device_initcall(palmz72_pm_init
);
524 /******************************************************************************
526 ******************************************************************************/
527 static struct platform_device
*devices
[] __initdata
= {
533 static void __init
palmz72_init(void)
535 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config
));
536 set_pxa_fb_info(&palmz72_lcd_screen
);
537 pxa_set_mci_info(&palmz72_mci_platform_data
);
538 pxa_set_ac97_info(NULL
);
539 pxa_set_ficp_info(&palmz72_ficp_platform_data
);
540 pxa_set_keypad_info(&palmz72_keypad_platform_data
);
541 platform_add_devices(devices
, ARRAY_SIZE(devices
));
544 MACHINE_START(PALMZ72
, "Palm Zire72")
545 .phys_io
= 0x40000000,
546 .io_pg_offst
= io_p2v(0x40000000),
547 .boot_params
= 0xa0000100,
548 .map_io
= pxa_map_io
,
549 .init_irq
= pxa27x_init_irq
,
551 .init_machine
= palmz72_init