Merge branch 'fix/soundcore' into for-linus
[pandora-kernel.git] / arch / arm / mach-pxa / palmz72.c
1 /*
2  * Hardware definitions for Palm Zire72
3  *
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>
9  *
10  * Rewrite for mainline:
11  *      Marek Vasut <marek.vasut@gmail.com>
12  *
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.
16  *
17  * (find more info at www.hackndev.com)
18  *
19  */
20
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>
33
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37
38 #include <mach/pxa27x.h>
39 #include <mach/audio.h>
40 #include <mach/palmz72.h>
41 #include <mach/mmc.h>
42 #include <mach/pxafb.h>
43 #include <mach/irda.h>
44 #include <mach/pxa27x_keypad.h>
45 #include <mach/udc.h>
46 #include <mach/palmasoc.h>
47
48 #include <mach/pm.h>
49
50 #include "generic.h"
51 #include "devices.h"
52
53 /******************************************************************************
54  * Pin configuration
55  ******************************************************************************/
56 static unsigned long palmz72_pin_config[] __initdata = {
57         /* MMC */
58         GPIO32_MMC_CLK,
59         GPIO92_MMC_DAT_0,
60         GPIO109_MMC_DAT_1,
61         GPIO110_MMC_DAT_2,
62         GPIO111_MMC_DAT_3,
63         GPIO112_MMC_CMD,
64         GPIO14_GPIO,    /* SD detect */
65         GPIO115_GPIO,   /* SD RO */
66         GPIO98_GPIO,    /* SD power */
67
68         /* AC97 */
69         GPIO28_AC97_BITCLK,
70         GPIO29_AC97_SDATA_IN_0,
71         GPIO30_AC97_SDATA_OUT,
72         GPIO31_AC97_SYNC,
73         GPIO89_AC97_SYSCLK,
74         GPIO113_AC97_nRESET,
75
76         /* IrDA */
77         GPIO49_GPIO,    /* ir disable */
78         GPIO46_FICP_RXD,
79         GPIO47_FICP_TXD,
80
81         /* PWM */
82         GPIO16_PWM0_OUT,
83
84         /* USB */
85         GPIO15_GPIO,    /* usb detect */
86         GPIO95_GPIO,    /* usb pullup */
87
88         /* Matrix keypad */
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,
93         GPIO103_KP_MKOUT_0,
94         GPIO104_KP_MKOUT_1,
95         GPIO105_KP_MKOUT_2,
96
97         /* LCD */
98         GPIO58_LCD_LDD_0,
99         GPIO59_LCD_LDD_1,
100         GPIO60_LCD_LDD_2,
101         GPIO61_LCD_LDD_3,
102         GPIO62_LCD_LDD_4,
103         GPIO63_LCD_LDD_5,
104         GPIO64_LCD_LDD_6,
105         GPIO65_LCD_LDD_7,
106         GPIO66_LCD_LDD_8,
107         GPIO67_LCD_LDD_9,
108         GPIO68_LCD_LDD_10,
109         GPIO69_LCD_LDD_11,
110         GPIO70_LCD_LDD_12,
111         GPIO71_LCD_LDD_13,
112         GPIO72_LCD_LDD_14,
113         GPIO73_LCD_LDD_15,
114         GPIO74_LCD_FCLK,
115         GPIO75_LCD_LCLK,
116         GPIO76_LCD_PCLK,
117         GPIO77_LCD_BIAS,
118         GPIO20_GPIO,    /* bl power */
119         GPIO21_GPIO,    /* LCD border switch */
120         GPIO22_GPIO,    /* LCD border color */
121         GPIO96_GPIO,    /* lcd power */
122
123         /* Misc. */
124         GPIO0_GPIO      | WAKEUP_ON_LEVEL_HIGH, /* power detect */
125         GPIO88_GPIO,                            /* green led */
126         GPIO27_GPIO,                            /* WM9712 IRQ */
127 };
128
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)
134 {
135         int err = 0;
136
137         /* Setup an interrupt for detecting card insert/remove events */
138         err = gpio_request(GPIO_NR_PALMZ72_SD_DETECT_N, "SD IRQ");
139         if (err)
140                 goto err;
141         err = gpio_direction_input(GPIO_NR_PALMZ72_SD_DETECT_N);
142         if (err)
143                 goto err2;
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);
148         if (err) {
149                 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
150                                 __func__);
151                 goto err2;
152         }
153
154         /* SD_POWER is not actually power, but it is more like chip
155          * select, i.e. it is inverted */
156
157         err = gpio_request(GPIO_NR_PALMZ72_SD_POWER_N, "SD_POWER");
158         if (err)
159                 goto err3;
160         err = gpio_direction_output(GPIO_NR_PALMZ72_SD_POWER_N, 0);
161         if (err)
162                 goto err4;
163         err = gpio_request(GPIO_NR_PALMZ72_SD_RO, "SD_RO");
164         if (err)
165                 goto err4;
166         err = gpio_direction_input(GPIO_NR_PALMZ72_SD_RO);
167         if (err)
168                 goto err5;
169
170         printk(KERN_DEBUG "%s: irq registered\n", __func__);
171
172         return 0;
173
174 err5:
175         gpio_free(GPIO_NR_PALMZ72_SD_RO);
176 err4:
177         gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
178 err3:
179         free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
180 err2:
181         gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
182 err:
183         return err;
184 }
185
186 static void palmz72_mci_exit(struct device *dev, void *data)
187 {
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);
192 }
193
194 static void palmz72_mci_power(struct device *dev, unsigned int vdd)
195 {
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);
199         else
200                 gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N, 1);
201 }
202
203 static int palmz72_mci_ro(struct device *dev)
204 {
205         return gpio_get_value(GPIO_NR_PALMZ72_SD_RO);
206 }
207
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,
214 };
215
216 /******************************************************************************
217  * GPIO keyboard
218  ******************************************************************************/
219 static unsigned int palmz72_matrix_keys[] = {
220         KEY(0, 0, KEY_POWER),
221         KEY(0, 1, KEY_F1),
222         KEY(0, 2, KEY_ENTER),
223
224         KEY(1, 0, KEY_F2),
225         KEY(1, 1, KEY_F3),
226         KEY(1, 2, KEY_F4),
227
228         KEY(2, 0, KEY_UP),
229         KEY(2, 2, KEY_DOWN),
230
231         KEY(3, 0, KEY_RIGHT),
232         KEY(3, 2, KEY_LEFT),
233 };
234
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),
240
241         .debounce_interval      = 30,
242 };
243
244 /******************************************************************************
245  * Backlight
246  ******************************************************************************/
247 static int palmz72_backlight_init(struct device *dev)
248 {
249         int ret;
250
251         ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
252         if (ret)
253                 goto err;
254         ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
255         if (ret)
256                 goto err2;
257         ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
258         if (ret)
259                 goto err2;
260         ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
261         if (ret)
262                 goto err3;
263
264         return 0;
265 err3:
266         gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
267 err2:
268         gpio_free(GPIO_NR_PALMZ72_BL_POWER);
269 err:
270         return ret;
271 }
272
273 static int palmz72_backlight_notify(int brightness)
274 {
275         gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
276         gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
277         return brightness;
278 }
279
280 static void palmz72_backlight_exit(struct device *dev)
281 {
282         gpio_free(GPIO_NR_PALMZ72_BL_POWER);
283         gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
284 }
285
286 static struct platform_pwm_backlight_data palmz72_backlight_data = {
287         .pwm_id         = 0,
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,
294 };
295
296 static struct platform_device palmz72_backlight = {
297         .name   = "pwm-backlight",
298         .dev    = {
299                 .parent         = &pxa27x_device_pwm0.dev,
300                 .platform_data  = &palmz72_backlight_data,
301         },
302 };
303
304 /******************************************************************************
305  * IrDA
306  ******************************************************************************/
307 static int palmz72_irda_startup(struct device *dev)
308 {
309         int err;
310         err = gpio_request(GPIO_NR_PALMZ72_IR_DISABLE, "IR DISABLE");
311         if (err)
312                 goto err;
313         err = gpio_direction_output(GPIO_NR_PALMZ72_IR_DISABLE, 1);
314         if (err)
315                 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
316 err:
317         return err;
318 }
319
320 static void palmz72_irda_shutdown(struct device *dev)
321 {
322         gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
323 }
324
325 static void palmz72_irda_transceiver_mode(struct device *dev, int mode)
326 {
327         gpio_set_value(GPIO_NR_PALMZ72_IR_DISABLE, mode & IR_OFF);
328         pxa2xx_transceiver_mode(dev, mode);
329 }
330
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,
336 };
337
338 /******************************************************************************
339  * LEDs
340  ******************************************************************************/
341 static struct gpio_led gpio_leds[] = {
342         {
343                 .name                   = "palmz72:green:led",
344                 .default_trigger        = "none",
345                 .gpio                   = GPIO_NR_PALMZ72_LED_GREEN,
346         },
347 };
348
349 static struct gpio_led_platform_data gpio_led_info = {
350         .leds           = gpio_leds,
351         .num_leds       = ARRAY_SIZE(gpio_leds),
352 };
353
354 static struct platform_device palmz72_leds = {
355         .name   = "leds-gpio",
356         .id     = -1,
357         .dev    = {
358                 .platform_data  = &gpio_led_info,
359         }
360 };
361
362 /******************************************************************************
363  * UDC
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,
368 };
369
370 static struct platform_device palmz72_gpio_vbus = {
371         .name   = "gpio-vbus",
372         .id     = -1,
373         .dev    = {
374                 .platform_data  = &palmz72_udc_info,
375         },
376 };
377
378 /******************************************************************************
379  * Power supply
380  ******************************************************************************/
381 static int power_supply_init(struct device *dev)
382 {
383         int ret;
384
385         ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
386         if (ret)
387                 goto err1;
388         ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
389         if (ret)
390                 goto err2;
391
392         ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
393         if (ret)
394                 goto err2;
395         ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
396         if (ret)
397                 goto err3;
398
399         return 0;
400 err3:
401         gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
402 err2:
403         gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
404 err1:
405         return ret;
406 }
407
408 static int palmz72_is_ac_online(void)
409 {
410         return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
411 }
412
413 static int palmz72_is_usb_online(void)
414 {
415         return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N);
416 }
417
418 static void power_supply_exit(struct device *dev)
419 {
420         gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
421         gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
422 }
423
424 static char *palmz72_supplicants[] = {
425         "main-battery",
426 };
427
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),
435 };
436
437 static struct platform_device power_supply = {
438         .name = "pda-power",
439         .id   = -1,
440         .dev  = {
441                 .platform_data = &power_supply_info,
442         },
443 };
444
445 /******************************************************************************
446  * WM97xx battery
447  ******************************************************************************/
448 static struct wm97xx_batt_info wm97xx_batt_pdata = {
449         .batt_aux       = WM97XX_AUX_ID3,
450         .temp_aux       = WM97XX_AUX_ID2,
451         .charge_gpio    = -1,
452         .max_voltage    = PALMZ72_BAT_MAX_VOLTAGE,
453         .min_voltage    = PALMZ72_BAT_MIN_VOLTAGE,
454         .batt_mult      = 1000,
455         .batt_div       = 414,
456         .temp_mult      = 1,
457         .temp_div       = 1,
458         .batt_tech      = POWER_SUPPLY_TECHNOLOGY_LIPO,
459         .batt_name      = "main-batt",
460 };
461
462 /******************************************************************************
463  * aSoC audio
464  ******************************************************************************/
465 static struct platform_device palmz72_asoc = {
466         .name = "palm27x-asoc",
467         .id   = -1,
468 };
469
470 /******************************************************************************
471  * Framebuffer
472  ******************************************************************************/
473 static struct pxafb_mode_info palmz72_lcd_modes[] = {
474 {
475         .pixclock       = 115384,
476         .xres           = 320,
477         .yres           = 320,
478         .bpp            = 16,
479
480         .left_margin    = 27,
481         .right_margin   = 7,
482         .upper_margin   = 7,
483         .lower_margin   = 8,
484
485         .hsync_len      = 6,
486         .vsync_len      = 1,
487 },
488 };
489
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,
494 };
495
496 #ifdef CONFIG_PM
497
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 :)
506  */
507
508 #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
509
510 static struct palmz72_resume_info palmz72_resume_info = {
511         .magic0 = 0xb4e6,
512         .magic1 = 1,
513
514         /* reset state, MMU off etc */
515         .arm_control = 0,
516         .aux_control = 0,
517         .ttb = 0,
518         .domain_access = 0,
519         .process_id = 0,
520 };
521
522 static unsigned long store_ptr;
523
524 /* sys_device for Palm Zire 72 PM */
525
526 static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
527 {
528         /* setup the resume_info struct for the original bootloader */
529         palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume;
530
531         /* Storing memory touched by ROM */
532         store_ptr = *PALMZ72_SAVE_DWORD;
533
534         /* Setting PSPR to a proper value */
535         PSPR = virt_to_phys(&palmz72_resume_info);
536
537         return 0;
538 }
539
540 static int palmz72_pm_resume(struct sys_device *dev)
541 {
542         *PALMZ72_SAVE_DWORD = store_ptr;
543         return 0;
544 }
545
546 static struct sysdev_class palmz72_pm_sysclass = {
547         .name = "palmz72_pm",
548         .suspend = palmz72_pm_suspend,
549         .resume = palmz72_pm_resume,
550 };
551
552 static struct sys_device palmz72_pm_device = {
553         .cls = &palmz72_pm_sysclass,
554 };
555
556 static int __init palmz72_pm_init(void)
557 {
558         int ret = -ENODEV;
559         if (machine_is_palmz72()) {
560                 ret = sysdev_class_register(&palmz72_pm_sysclass);
561                 if (ret == 0)
562                         ret = sysdev_register(&palmz72_pm_device);
563         }
564         return ret;
565 }
566
567 device_initcall(palmz72_pm_init);
568 #endif
569
570 /******************************************************************************
571  * Machine init
572  ******************************************************************************/
573 static struct platform_device *devices[] __initdata = {
574         &palmz72_backlight,
575         &palmz72_leds,
576         &palmz72_asoc,
577         &power_supply,
578         &palmz72_gpio_vbus,
579 };
580
581 /* setup udc GPIOs initial state */
582 static void __init palmz72_udc_init(void)
583 {
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);
587         }
588 }
589
590 static void __init palmz72_init(void)
591 {
592         pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
593
594         set_pxa_fb_info(&palmz72_lcd_screen);
595         pxa_set_mci_info(&palmz72_mci_platform_data);
596         palmz72_udc_init();
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);
601
602         platform_add_devices(devices, ARRAY_SIZE(devices));
603 }
604
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,
611         .timer          = &pxa_timer,
612         .init_machine   = palmz72_init
613 MACHINE_END