OMAP3: PM: Ensure MUSB block can idle when driver not loaded
[linux-ginger.git] / arch / arm / mach-pxa / palmz72.c
blobb88eb4dd2c84169a6b912c9322dceac5e6c416de
1 /*
2 * Hardware definitions for Palm Zire72
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>
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>
39 #include <mach/mmc.h>
40 #include <mach/pxafb.h>
41 #include <mach/irda.h>
42 #include <mach/pxa27x_keypad.h>
43 #include <mach/udc.h>
44 #include <mach/pm.h>
46 #include "generic.h"
47 #include "devices.h"
49 /******************************************************************************
50 * Pin configuration
51 ******************************************************************************/
52 static unsigned long palmz72_pin_config[] __initdata = {
53 /* MMC */
54 GPIO32_MMC_CLK,
55 GPIO92_MMC_DAT_0,
56 GPIO109_MMC_DAT_1,
57 GPIO110_MMC_DAT_2,
58 GPIO111_MMC_DAT_3,
59 GPIO112_MMC_CMD,
60 GPIO14_GPIO, /* SD detect */
61 GPIO115_GPIO, /* SD RO */
62 GPIO98_GPIO, /* SD power */
64 /* AC97 */
65 GPIO28_AC97_BITCLK,
66 GPIO29_AC97_SDATA_IN_0,
67 GPIO30_AC97_SDATA_OUT,
68 GPIO31_AC97_SYNC,
70 /* IrDA */
71 GPIO49_GPIO, /* ir disable */
72 GPIO46_FICP_RXD,
73 GPIO47_FICP_TXD,
75 /* PWM */
76 GPIO16_PWM0_OUT,
78 /* USB */
79 GPIO15_GPIO, /* usb detect */
80 GPIO12_GPIO, /* usb pullup */
81 GPIO95_GPIO, /* usb power */
83 /* Matrix keypad */
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,
88 GPIO103_KP_MKOUT_0,
89 GPIO104_KP_MKOUT_1,
90 GPIO105_KP_MKOUT_2,
92 /* LCD */
93 GPIO58_LCD_LDD_0,
94 GPIO59_LCD_LDD_1,
95 GPIO60_LCD_LDD_2,
96 GPIO61_LCD_LDD_3,
97 GPIO62_LCD_LDD_4,
98 GPIO63_LCD_LDD_5,
99 GPIO64_LCD_LDD_6,
100 GPIO65_LCD_LDD_7,
101 GPIO66_LCD_LDD_8,
102 GPIO67_LCD_LDD_9,
103 GPIO68_LCD_LDD_10,
104 GPIO69_LCD_LDD_11,
105 GPIO70_LCD_LDD_12,
106 GPIO71_LCD_LDD_13,
107 GPIO72_LCD_LDD_14,
108 GPIO73_LCD_LDD_15,
109 GPIO74_LCD_FCLK,
110 GPIO75_LCD_LCLK,
111 GPIO76_LCD_PCLK,
112 GPIO77_LCD_BIAS,
113 GPIO20_GPIO, /* bl power */
114 GPIO21_GPIO, /* LCD border switch */
115 GPIO22_GPIO, /* LCD border color */
116 GPIO96_GPIO, /* lcd power */
118 /* Misc. */
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)
130 int err = 0;
132 /* Setup an interrupt for detecting card insert/remove events */
133 err = gpio_request(GPIO_NR_PALMZ72_SD_DETECT_N, "SD IRQ");
134 if (err)
135 goto err;
136 err = gpio_direction_input(GPIO_NR_PALMZ72_SD_DETECT_N);
137 if (err)
138 goto err2;
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);
143 if (err) {
144 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
145 __func__);
146 goto err2;
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");
153 if (err)
154 goto err3;
155 err = gpio_direction_output(GPIO_NR_PALMZ72_SD_POWER_N, 0);
156 if (err)
157 goto err4;
158 err = gpio_request(GPIO_NR_PALMZ72_SD_RO, "SD_RO");
159 if (err)
160 goto err4;
161 err = gpio_direction_input(GPIO_NR_PALMZ72_SD_RO);
162 if (err)
163 goto err5;
165 printk(KERN_DEBUG "%s: irq registered\n", __func__);
167 return 0;
169 err5:
170 gpio_free(GPIO_NR_PALMZ72_SD_RO);
171 err4:
172 gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
173 err3:
174 free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
175 err2:
176 gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
177 err:
178 return err;
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);
194 else
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 /******************************************************************************
212 * GPIO keyboard
213 ******************************************************************************/
214 static unsigned int palmz72_matrix_keys[] = {
215 KEY(0, 0, KEY_POWER),
216 KEY(0, 1, KEY_F1),
217 KEY(0, 2, KEY_ENTER),
219 KEY(1, 0, KEY_F2),
220 KEY(1, 1, KEY_F3),
221 KEY(1, 2, KEY_F4),
223 KEY(2, 0, KEY_UP),
224 KEY(2, 2, KEY_DOWN),
226 KEY(3, 0, KEY_RIGHT),
227 KEY(3, 2, KEY_LEFT),
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 /******************************************************************************
240 * Backlight
241 ******************************************************************************/
242 static int palmz72_backlight_init(struct device *dev)
244 int ret;
246 ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
247 if (ret)
248 goto err;
249 ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
250 if (ret)
251 goto err2;
252 ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
253 if (ret)
254 goto err2;
255 ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
256 if (ret)
257 goto err3;
259 return 0;
260 err3:
261 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
262 err2:
263 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
264 err:
265 return ret;
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);
272 return 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 = {
282 .pwm_id = 0,
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",
293 .dev = {
294 .parent = &pxa27x_device_pwm0.dev,
295 .platform_data = &palmz72_backlight_data,
299 /******************************************************************************
300 * IrDA
301 ******************************************************************************/
302 static int palmz72_irda_startup(struct device *dev)
304 int err;
305 err = gpio_request(GPIO_NR_PALMZ72_IR_DISABLE, "IR DISABLE");
306 if (err)
307 goto err;
308 err = gpio_direction_output(GPIO_NR_PALMZ72_IR_DISABLE, 1);
309 if (err)
310 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
311 err:
312 return err;
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 /******************************************************************************
334 * LEDs
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 = {
345 .leds = gpio_leds,
346 .num_leds = ARRAY_SIZE(gpio_leds),
349 static struct platform_device palmz72_leds = {
350 .name = "leds-gpio",
351 .id = -1,
352 .dev = {
353 .platform_data = &gpio_led_info,
357 /******************************************************************************
358 * Power supply
359 ******************************************************************************/
360 static int power_supply_init(struct device *dev)
362 int ret;
364 ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
365 if (ret)
366 goto err1;
367 ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
368 if (ret)
369 goto err2;
371 ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
372 if (ret)
373 goto err2;
374 ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
375 if (ret)
376 goto err3;
378 return 0;
379 err3:
380 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
381 err2:
382 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
383 err1:
384 return ret;
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[] = {
404 "main-battery",
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 = {
417 .name = "pda-power",
418 .id = -1,
419 .dev = {
420 .platform_data = &power_supply_info,
424 /******************************************************************************
425 * Framebuffer
426 ******************************************************************************/
427 static struct pxafb_mode_info palmz72_lcd_modes[] = {
429 .pixclock = 115384,
430 .xres = 320,
431 .yres = 320,
432 .bpp = 16,
434 .left_margin = 27,
435 .right_margin = 7,
436 .upper_margin = 7,
437 .lower_margin = 8,
439 .hsync_len = 6,
440 .vsync_len = 1,
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,
450 #ifdef CONFIG_PM
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 = {
465 .magic0 = 0xb4e6,
466 .magic1 = 1,
468 /* reset state, MMU off etc */
469 .arm_control = 0,
470 .aux_control = 0,
471 .ttb = 0,
472 .domain_access = 0,
473 .process_id = 0,
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);
491 return 0;
494 static int palmz72_pm_resume(struct sys_device *dev)
496 *PALMZ72_SAVE_DWORD = store_ptr;
497 return 0;
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)
512 int ret = -ENODEV;
513 if (machine_is_palmz72()) {
514 ret = sysdev_class_register(&palmz72_pm_sysclass);
515 if (ret == 0)
516 ret = sysdev_register(&palmz72_pm_device);
518 return ret;
521 device_initcall(palmz72_pm_init);
522 #endif
524 /******************************************************************************
525 * Machine init
526 ******************************************************************************/
527 static struct platform_device *devices[] __initdata = {
528 &palmz72_backlight,
529 &palmz72_leds,
530 &power_supply,
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,
550 .timer = &pxa_timer,
551 .init_machine = palmz72_init
552 MACHINE_END