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/audio.h>
37 #include <mach/palmz72.h>
39 #include <mach/pxafb.h>
40 #include <mach/pxa-regs.h>
41 #include <mach/pxa2xx-regs.h>
42 #include <mach/mfp-pxa27x.h>
43 #include <mach/irda.h>
44 #include <mach/pxa27x_keypad.h>
51 /******************************************************************************
53 ******************************************************************************/
54 static unsigned long palmz72_pin_config[] __initdata = {
62 GPIO14_GPIO, /* SD detect */
63 GPIO115_GPIO, /* SD RO */
64 GPIO98_GPIO, /* SD power */
68 GPIO29_AC97_SDATA_IN_0,
69 GPIO30_AC97_SDATA_OUT,
73 GPIO49_GPIO, /* ir disable */
81 GPIO15_GPIO, /* usb detect */
82 GPIO12_GPIO, /* usb pullup */
83 GPIO95_GPIO, /* usb power */
86 GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
87 GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
88 GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
89 GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
115 GPIO20_GPIO, /* bl power */
116 GPIO21_GPIO, /* LCD border switch */
117 GPIO22_GPIO, /* LCD border color */
118 GPIO96_GPIO, /* lcd power */
121 GPIO0_GPIO | WAKEUP_ON_LEVEL_HIGH, /* power detect */
122 GPIO88_GPIO, /* green led */
123 GPIO27_GPIO, /* WM9712 IRQ */
126 /******************************************************************************
127 * SD/MMC card controller
128 ******************************************************************************/
129 static int palmz72_mci_init(struct device *dev,
130 irq_handler_t palmz72_detect_int, void *data)
134 /* Setup an interrupt for detecting card insert/remove events */
135 err = gpio_request(GPIO_NR_PALMZ72_SD_DETECT_N, "SD IRQ");
138 err = gpio_direction_input(GPIO_NR_PALMZ72_SD_DETECT_N);
141 err = request_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N),
142 palmz72_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
143 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
144 "SD/MMC card detect", data);
146 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
151 /* SD_POWER is not actually power, but it is more like chip
152 * select, i.e. it is inverted */
154 err = gpio_request(GPIO_NR_PALMZ72_SD_POWER_N, "SD_POWER");
157 err = gpio_direction_output(GPIO_NR_PALMZ72_SD_POWER_N, 0);
160 err = gpio_request(GPIO_NR_PALMZ72_SD_RO, "SD_RO");
163 err = gpio_direction_input(GPIO_NR_PALMZ72_SD_RO);
167 printk(KERN_DEBUG "%s: irq registered\n", __func__);
172 gpio_free(GPIO_NR_PALMZ72_SD_RO);
174 gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
176 free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
178 gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
183 static void palmz72_mci_exit(struct device *dev, void *data)
185 gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
186 free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
187 gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
188 gpio_free(GPIO_NR_PALMZ72_SD_RO);
191 static void palmz72_mci_power(struct device *dev, unsigned int vdd)
193 struct pxamci_platform_data *p_d = dev->platform_data;
194 if (p_d->ocr_mask & (1 << vdd))
195 gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N, 0);
197 gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N, 1);
200 static int palmz72_mci_ro(struct device *dev)
202 return gpio_get_value(GPIO_NR_PALMZ72_SD_RO);
205 static struct pxamci_platform_data palmz72_mci_platform_data = {
206 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
207 .setpower = palmz72_mci_power,
208 .get_ro = palmz72_mci_ro,
209 .init = palmz72_mci_init,
210 .exit = palmz72_mci_exit,
213 /******************************************************************************
215 ******************************************************************************/
216 static unsigned int palmz72_matrix_keys[] = {
217 KEY(0, 0, KEY_POWER),
219 KEY(0, 2, KEY_ENTER),
228 KEY(3, 0, KEY_RIGHT),
232 static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
233 .matrix_key_rows = 4,
234 .matrix_key_cols = 3,
235 .matrix_key_map = palmz72_matrix_keys,
236 .matrix_key_map_size = ARRAY_SIZE(palmz72_matrix_keys),
238 .debounce_interval = 30,
241 /******************************************************************************
243 ******************************************************************************/
244 static int palmz72_backlight_init(struct device *dev)
248 ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
251 ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
254 ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
257 ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
263 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
265 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
270 static int palmz72_backlight_notify(int brightness)
272 gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
273 gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
277 static void palmz72_backlight_exit(struct device *dev)
279 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
280 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
283 static struct platform_pwm_backlight_data palmz72_backlight_data = {
285 .max_brightness = PALMZ72_MAX_INTENSITY,
286 .dft_brightness = PALMZ72_MAX_INTENSITY,
287 .pwm_period_ns = PALMZ72_PERIOD_NS,
288 .init = palmz72_backlight_init,
289 .notify = palmz72_backlight_notify,
290 .exit = palmz72_backlight_exit,
293 static struct platform_device palmz72_backlight = {
294 .name = "pwm-backlight",
296 .parent = &pxa27x_device_pwm0.dev,
297 .platform_data = &palmz72_backlight_data,
301 /******************************************************************************
303 ******************************************************************************/
304 static int palmz72_irda_startup(struct device *dev)
307 err = gpio_request(GPIO_NR_PALMZ72_IR_DISABLE, "IR DISABLE");
310 err = gpio_direction_output(GPIO_NR_PALMZ72_IR_DISABLE, 1);
312 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
317 static void palmz72_irda_shutdown(struct device *dev)
319 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
322 static void palmz72_irda_transceiver_mode(struct device *dev, int mode)
324 gpio_set_value(GPIO_NR_PALMZ72_IR_DISABLE, mode & IR_OFF);
325 pxa2xx_transceiver_mode(dev, mode);
328 static struct pxaficp_platform_data palmz72_ficp_platform_data = {
329 .startup = palmz72_irda_startup,
330 .shutdown = palmz72_irda_shutdown,
331 .transceiver_cap = IR_SIRMODE | IR_OFF,
332 .transceiver_mode = palmz72_irda_transceiver_mode,
335 /******************************************************************************
337 ******************************************************************************/
338 static struct gpio_led gpio_leds[] = {
340 .name = "palmz72:green:led",
341 .default_trigger = "none",
342 .gpio = GPIO_NR_PALMZ72_LED_GREEN,
346 static struct gpio_led_platform_data gpio_led_info = {
348 .num_leds = ARRAY_SIZE(gpio_leds),
351 static struct platform_device palmz72_leds = {
355 .platform_data = &gpio_led_info,
359 /******************************************************************************
361 ******************************************************************************/
362 static int power_supply_init(struct device *dev)
366 ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
369 ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
373 ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
376 ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
382 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
384 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
389 static int palmz72_is_ac_online(void)
391 return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
394 static int palmz72_is_usb_online(void)
396 return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N);
399 static void power_supply_exit(struct device *dev)
401 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
402 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
405 static char *palmz72_supplicants[] = {
409 static struct pda_power_pdata power_supply_info = {
410 .init = power_supply_init,
411 .is_ac_online = palmz72_is_ac_online,
412 .is_usb_online = palmz72_is_usb_online,
413 .exit = power_supply_exit,
414 .supplied_to = palmz72_supplicants,
415 .num_supplicants = ARRAY_SIZE(palmz72_supplicants),
418 static struct platform_device power_supply = {
422 .platform_data = &power_supply_info,
426 /******************************************************************************
428 ******************************************************************************/
429 static struct pxafb_mode_info palmz72_lcd_modes[] = {
446 static struct pxafb_mach_info palmz72_lcd_screen = {
447 .modes = palmz72_lcd_modes,
448 .num_modes = ARRAY_SIZE(palmz72_lcd_modes),
449 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
454 /* We have some black magic here
455 * PalmOS ROM on recover expects special struct physical address
456 * to be transferred via PSPR. Using this struct PalmOS restores
457 * its state after sleep. As for Linux, we need to setup it the
458 * same way. More than that, PalmOS ROM changes some values in memory.
459 * For now only one location is found, which needs special treatment.
460 * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
461 * for reading backtraces for me :)
464 #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
466 static struct palmz72_resume_info palmz72_resume_info = {
470 /* reset state, MMU off etc */
478 static unsigned long store_ptr;
480 /* sys_device for Palm Zire 72 PM */
482 static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
484 /* setup the resume_info struct for the original bootloader */
485 palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume;
487 /* Storing memory touched by ROM */
488 store_ptr = *PALMZ72_SAVE_DWORD;
490 /* Setting PSPR to a proper value */
491 PSPR = virt_to_phys(&palmz72_resume_info);
496 static int palmz72_pm_resume(struct sys_device *dev)
498 *PALMZ72_SAVE_DWORD = store_ptr;
502 static struct sysdev_class palmz72_pm_sysclass = {
503 .name = "palmz72_pm",
504 .suspend = palmz72_pm_suspend,
505 .resume = palmz72_pm_resume,
508 static struct sys_device palmz72_pm_device = {
509 .cls = &palmz72_pm_sysclass,
512 static int __init palmz72_pm_init(void)
515 if (machine_is_palmz72()) {
516 ret = sysdev_class_register(&palmz72_pm_sysclass);
518 ret = sysdev_register(&palmz72_pm_device);
523 device_initcall(palmz72_pm_init);
526 /******************************************************************************
528 ******************************************************************************/
529 static struct platform_device *devices[] __initdata = {
535 static void __init palmz72_init(void)
537 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
538 set_pxa_fb_info(&palmz72_lcd_screen);
539 pxa_set_mci_info(&palmz72_mci_platform_data);
540 pxa_set_ac97_info(NULL);
541 pxa_set_ficp_info(&palmz72_ficp_platform_data);
542 pxa_set_keypad_info(&palmz72_keypad_platform_data);
543 platform_add_devices(devices, ARRAY_SIZE(devices));
546 MACHINE_START(PALMZ72, "Palm Zire72")
547 .phys_io = 0x40000000,
548 .io_pg_offst = io_p2v(0x40000000),
549 .boot_params = 0xa0000100,
550 .map_io = pxa_map_io,
551 .init_irq = pxa27x_init_irq,
553 .init_machine = palmz72_init