Merge branch 'topic/hda' into for-linus
[pandora-kernel.git] / arch / arm / mach-pxa / palmt5.c
1 /*
2  * Hardware definitions for Palm Tungsten|T5
3  *
4  * Author:      Marek Vasut <marek.vasut@gmail.com>
5  *
6  * Based on work of:
7  *              Ales Snuparek <snuparek@atlas.cz>
8  *              Justin Kendrick <twilightsentry@gmail.com>
9  *              RichardT5 <richard_t5@users.sourceforge.net>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  *
15  * (find more info at www.hackndev.com)
16  *
17  */
18
19 #include <linux/platform_device.h>
20 #include <linux/delay.h>
21 #include <linux/irq.h>
22 #include <linux/gpio_keys.h>
23 #include <linux/input.h>
24 #include <linux/pda_power.h>
25 #include <linux/pwm_backlight.h>
26 #include <linux/gpio.h>
27 #include <linux/wm97xx_batt.h>
28 #include <linux/power_supply.h>
29
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33
34 #include <mach/pxa27x.h>
35 #include <mach/audio.h>
36 #include <mach/palmt5.h>
37 #include <mach/mmc.h>
38 #include <mach/pxafb.h>
39 #include <mach/irda.h>
40 #include <mach/pxa27x_keypad.h>
41 #include <mach/udc.h>
42 #include <mach/palmasoc.h>
43
44 #include "generic.h"
45 #include "devices.h"
46
47 /******************************************************************************
48  * Pin configuration
49  ******************************************************************************/
50 static unsigned long palmt5_pin_config[] __initdata = {
51         /* MMC */
52         GPIO32_MMC_CLK,
53         GPIO92_MMC_DAT_0,
54         GPIO109_MMC_DAT_1,
55         GPIO110_MMC_DAT_2,
56         GPIO111_MMC_DAT_3,
57         GPIO112_MMC_CMD,
58         GPIO14_GPIO,    /* SD detect */
59         GPIO114_GPIO,   /* SD power */
60         GPIO115_GPIO,   /* SD r/o switch */
61
62         /* AC97 */
63         GPIO28_AC97_BITCLK,
64         GPIO29_AC97_SDATA_IN_0,
65         GPIO30_AC97_SDATA_OUT,
66         GPIO31_AC97_SYNC,
67         GPIO89_AC97_SYSCLK,
68         GPIO95_AC97_nRESET,
69
70         /* IrDA */
71         GPIO40_GPIO,    /* ir disable */
72         GPIO46_FICP_RXD,
73         GPIO47_FICP_TXD,
74
75         /* USB */
76         GPIO15_GPIO,    /* usb detect */
77         GPIO93_GPIO,    /* usb power */
78
79         /* MATRIX KEYPAD */
80         GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
81         GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
82         GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
83         GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
84         GPIO103_KP_MKOUT_0,
85         GPIO104_KP_MKOUT_1,
86         GPIO105_KP_MKOUT_2,
87
88         /* LCD */
89         GPIO58_LCD_LDD_0,
90         GPIO59_LCD_LDD_1,
91         GPIO60_LCD_LDD_2,
92         GPIO61_LCD_LDD_3,
93         GPIO62_LCD_LDD_4,
94         GPIO63_LCD_LDD_5,
95         GPIO64_LCD_LDD_6,
96         GPIO65_LCD_LDD_7,
97         GPIO66_LCD_LDD_8,
98         GPIO67_LCD_LDD_9,
99         GPIO68_LCD_LDD_10,
100         GPIO69_LCD_LDD_11,
101         GPIO70_LCD_LDD_12,
102         GPIO71_LCD_LDD_13,
103         GPIO72_LCD_LDD_14,
104         GPIO73_LCD_LDD_15,
105         GPIO74_LCD_FCLK,
106         GPIO75_LCD_LCLK,
107         GPIO76_LCD_PCLK,
108         GPIO77_LCD_BIAS,
109
110         /* PWM */
111         GPIO16_PWM0_OUT,
112
113         /* MISC */
114         GPIO10_GPIO,    /* hotsync button */
115         GPIO90_GPIO,    /* power detect */
116         GPIO107_GPIO,   /* earphone detect */
117 };
118
119 /******************************************************************************
120  * SD/MMC card controller
121  ******************************************************************************/
122 static int palmt5_mci_init(struct device *dev, irq_handler_t palmt5_detect_int,
123                                 void *data)
124 {
125         int err = 0;
126
127         /* Setup an interrupt for detecting card insert/remove events */
128         err = gpio_request(GPIO_NR_PALMT5_SD_DETECT_N, "SD IRQ");
129         if (err)
130                 goto err;
131         err = gpio_direction_input(GPIO_NR_PALMT5_SD_DETECT_N);
132         if (err)
133                 goto err2;
134         err = request_irq(gpio_to_irq(GPIO_NR_PALMT5_SD_DETECT_N),
135                         palmt5_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
136                         IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
137                         "SD/MMC card detect", data);
138         if (err) {
139                 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
140                                 __func__);
141                 goto err2;
142         }
143
144         err = gpio_request(GPIO_NR_PALMT5_SD_POWER, "SD_POWER");
145         if (err)
146                 goto err3;
147         err = gpio_direction_output(GPIO_NR_PALMT5_SD_POWER, 0);
148         if (err)
149                 goto err4;
150
151         err = gpio_request(GPIO_NR_PALMT5_SD_READONLY, "SD_READONLY");
152         if (err)
153                 goto err4;
154         err = gpio_direction_input(GPIO_NR_PALMT5_SD_READONLY);
155         if (err)
156                 goto err5;
157
158         printk(KERN_DEBUG "%s: irq registered\n", __func__);
159
160         return 0;
161
162 err5:
163         gpio_free(GPIO_NR_PALMT5_SD_READONLY);
164 err4:
165         gpio_free(GPIO_NR_PALMT5_SD_POWER);
166 err3:
167         free_irq(gpio_to_irq(GPIO_NR_PALMT5_SD_DETECT_N), data);
168 err2:
169         gpio_free(GPIO_NR_PALMT5_SD_DETECT_N);
170 err:
171         return err;
172 }
173
174 static void palmt5_mci_exit(struct device *dev, void *data)
175 {
176         gpio_free(GPIO_NR_PALMT5_SD_READONLY);
177         gpio_free(GPIO_NR_PALMT5_SD_POWER);
178         free_irq(IRQ_GPIO_PALMT5_SD_DETECT_N, data);
179         gpio_free(GPIO_NR_PALMT5_SD_DETECT_N);
180 }
181
182 static void palmt5_mci_power(struct device *dev, unsigned int vdd)
183 {
184         struct pxamci_platform_data *p_d = dev->platform_data;
185         gpio_set_value(GPIO_NR_PALMT5_SD_POWER, p_d->ocr_mask & (1 << vdd));
186 }
187
188 static int palmt5_mci_get_ro(struct device *dev)
189 {
190         return gpio_get_value(GPIO_NR_PALMT5_SD_READONLY);
191 }
192
193 static struct pxamci_platform_data palmt5_mci_platform_data = {
194         .ocr_mask       = MMC_VDD_32_33 | MMC_VDD_33_34,
195         .setpower       = palmt5_mci_power,
196         .get_ro         = palmt5_mci_get_ro,
197         .init           = palmt5_mci_init,
198         .exit           = palmt5_mci_exit,
199 };
200
201 /******************************************************************************
202  * GPIO keyboard
203  ******************************************************************************/
204 static unsigned int palmt5_matrix_keys[] = {
205         KEY(0, 0, KEY_POWER),
206         KEY(0, 1, KEY_F1),
207         KEY(0, 2, KEY_ENTER),
208
209         KEY(1, 0, KEY_F2),
210         KEY(1, 1, KEY_F3),
211         KEY(1, 2, KEY_F4),
212
213         KEY(2, 0, KEY_UP),
214         KEY(2, 2, KEY_DOWN),
215
216         KEY(3, 0, KEY_RIGHT),
217         KEY(3, 2, KEY_LEFT),
218 };
219
220 static struct pxa27x_keypad_platform_data palmt5_keypad_platform_data = {
221         .matrix_key_rows        = 4,
222         .matrix_key_cols        = 3,
223         .matrix_key_map         = palmt5_matrix_keys,
224         .matrix_key_map_size    = ARRAY_SIZE(palmt5_matrix_keys),
225
226         .debounce_interval      = 30,
227 };
228
229 /******************************************************************************
230  * GPIO keys
231  ******************************************************************************/
232 static struct gpio_keys_button palmt5_pxa_buttons[] = {
233         {KEY_F8, GPIO_NR_PALMT5_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
234 };
235
236 static struct gpio_keys_platform_data palmt5_pxa_keys_data = {
237         .buttons        = palmt5_pxa_buttons,
238         .nbuttons       = ARRAY_SIZE(palmt5_pxa_buttons),
239 };
240
241 static struct platform_device palmt5_pxa_keys = {
242         .name   = "gpio-keys",
243         .id     = -1,
244         .dev    = {
245                 .platform_data = &palmt5_pxa_keys_data,
246         },
247 };
248
249 /******************************************************************************
250  * Backlight
251  ******************************************************************************/
252 static int palmt5_backlight_init(struct device *dev)
253 {
254         int ret;
255
256         ret = gpio_request(GPIO_NR_PALMT5_BL_POWER, "BL POWER");
257         if (ret)
258                 goto err;
259         ret = gpio_direction_output(GPIO_NR_PALMT5_BL_POWER, 0);
260         if (ret)
261                 goto err2;
262         ret = gpio_request(GPIO_NR_PALMT5_LCD_POWER, "LCD POWER");
263         if (ret)
264                 goto err2;
265         ret = gpio_direction_output(GPIO_NR_PALMT5_LCD_POWER, 0);
266         if (ret)
267                 goto err3;
268
269         return 0;
270 err3:
271         gpio_free(GPIO_NR_PALMT5_LCD_POWER);
272 err2:
273         gpio_free(GPIO_NR_PALMT5_BL_POWER);
274 err:
275         return ret;
276 }
277
278 static int palmt5_backlight_notify(int brightness)
279 {
280         gpio_set_value(GPIO_NR_PALMT5_BL_POWER, brightness);
281         gpio_set_value(GPIO_NR_PALMT5_LCD_POWER, brightness);
282         return brightness;
283 }
284
285 static void palmt5_backlight_exit(struct device *dev)
286 {
287         gpio_free(GPIO_NR_PALMT5_BL_POWER);
288         gpio_free(GPIO_NR_PALMT5_LCD_POWER);
289 }
290
291 static struct platform_pwm_backlight_data palmt5_backlight_data = {
292         .pwm_id         = 0,
293         .max_brightness = PALMT5_MAX_INTENSITY,
294         .dft_brightness = PALMT5_MAX_INTENSITY,
295         .pwm_period_ns  = PALMT5_PERIOD_NS,
296         .init           = palmt5_backlight_init,
297         .notify         = palmt5_backlight_notify,
298         .exit           = palmt5_backlight_exit,
299 };
300
301 static struct platform_device palmt5_backlight = {
302         .name   = "pwm-backlight",
303         .dev    = {
304                 .parent         = &pxa27x_device_pwm0.dev,
305                 .platform_data  = &palmt5_backlight_data,
306         },
307 };
308
309 /******************************************************************************
310  * IrDA
311  ******************************************************************************/
312 static int palmt5_irda_startup(struct device *dev)
313 {
314         int err;
315         err = gpio_request(GPIO_NR_PALMT5_IR_DISABLE, "IR DISABLE");
316         if (err)
317                 goto err;
318         err = gpio_direction_output(GPIO_NR_PALMT5_IR_DISABLE, 1);
319         if (err)
320                 gpio_free(GPIO_NR_PALMT5_IR_DISABLE);
321 err:
322         return err;
323 }
324
325 static void palmt5_irda_shutdown(struct device *dev)
326 {
327         gpio_free(GPIO_NR_PALMT5_IR_DISABLE);
328 }
329
330 static void palmt5_irda_transceiver_mode(struct device *dev, int mode)
331 {
332         gpio_set_value(GPIO_NR_PALMT5_IR_DISABLE, mode & IR_OFF);
333         pxa2xx_transceiver_mode(dev, mode);
334 }
335
336 static struct pxaficp_platform_data palmt5_ficp_platform_data = {
337         .startup                = palmt5_irda_startup,
338         .shutdown               = palmt5_irda_shutdown,
339         .transceiver_cap        = IR_SIRMODE | IR_FIRMODE | IR_OFF,
340         .transceiver_mode       = palmt5_irda_transceiver_mode,
341 };
342
343 /******************************************************************************
344  * UDC
345  ******************************************************************************/
346 static struct pxa2xx_udc_mach_info palmt5_udc_info __initdata = {
347         .gpio_vbus              = GPIO_NR_PALMT5_USB_DETECT_N,
348         .gpio_vbus_inverted     = 1,
349         .gpio_pullup            = GPIO_NR_PALMT5_USB_PULLUP,
350         .gpio_pullup_inverted   = 0,
351 };
352
353 /******************************************************************************
354  * Power supply
355  ******************************************************************************/
356 static int power_supply_init(struct device *dev)
357 {
358         int ret;
359
360         ret = gpio_request(GPIO_NR_PALMT5_POWER_DETECT, "CABLE_STATE_AC");
361         if (ret)
362                 goto err1;
363         ret = gpio_direction_input(GPIO_NR_PALMT5_POWER_DETECT);
364         if (ret)
365                 goto err2;
366
367         return 0;
368 err2:
369         gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
370 err1:
371         return ret;
372 }
373
374 static int palmt5_is_ac_online(void)
375 {
376         return gpio_get_value(GPIO_NR_PALMT5_POWER_DETECT);
377 }
378
379 static void power_supply_exit(struct device *dev)
380 {
381         gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
382 }
383
384 static char *palmt5_supplicants[] = {
385         "main-battery",
386 };
387
388 static struct pda_power_pdata power_supply_info = {
389         .init            = power_supply_init,
390         .is_ac_online    = palmt5_is_ac_online,
391         .exit            = power_supply_exit,
392         .supplied_to     = palmt5_supplicants,
393         .num_supplicants = ARRAY_SIZE(palmt5_supplicants),
394 };
395
396 static struct platform_device power_supply = {
397         .name = "pda-power",
398         .id   = -1,
399         .dev  = {
400                 .platform_data = &power_supply_info,
401         },
402 };
403
404 /******************************************************************************
405  * WM97xx battery
406  ******************************************************************************/
407 static struct wm97xx_batt_info wm97xx_batt_pdata = {
408         .batt_aux       = WM97XX_AUX_ID3,
409         .temp_aux       = WM97XX_AUX_ID2,
410         .charge_gpio    = -1,
411         .max_voltage    = PALMT5_BAT_MAX_VOLTAGE,
412         .min_voltage    = PALMT5_BAT_MIN_VOLTAGE,
413         .batt_mult      = 1000,
414         .batt_div       = 414,
415         .temp_mult      = 1,
416         .temp_div       = 1,
417         .batt_tech      = POWER_SUPPLY_TECHNOLOGY_LIPO,
418         .batt_name      = "main-batt",
419 };
420
421 /******************************************************************************
422  * aSoC audio
423  ******************************************************************************/
424 static struct palm27x_asoc_info palmt5_asoc_pdata = {
425         .jack_gpio      = GPIO_NR_PALMT5_EARPHONE_DETECT,
426 };
427
428 static pxa2xx_audio_ops_t palmt5_ac97_pdata = {
429         .reset_gpio     = 95,
430 };
431
432 static struct platform_device palmt5_asoc = {
433         .name = "palm27x-asoc",
434         .id   = -1,
435         .dev  = {
436                 .platform_data = &palmt5_asoc_pdata,
437         },
438 };
439
440 /******************************************************************************
441  * Framebuffer
442  ******************************************************************************/
443 static struct pxafb_mode_info palmt5_lcd_modes[] = {
444 {
445         .pixclock       = 57692,
446         .xres           = 320,
447         .yres           = 480,
448         .bpp            = 16,
449
450         .left_margin    = 32,
451         .right_margin   = 1,
452         .upper_margin   = 7,
453         .lower_margin   = 1,
454
455         .hsync_len      = 4,
456         .vsync_len      = 1,
457 },
458 };
459
460 static struct pxafb_mach_info palmt5_lcd_screen = {
461         .modes          = palmt5_lcd_modes,
462         .num_modes      = ARRAY_SIZE(palmt5_lcd_modes),
463         .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
464 };
465
466 /******************************************************************************
467  * Power management - standby
468  ******************************************************************************/
469 #ifdef CONFIG_PM
470 static u32 *addr __initdata;
471 static u32 resume[3] __initdata = {
472         0xe3a00101,     /* mov  r0,     #0x40000000 */
473         0xe380060f,     /* orr  r0, r0, #0x00f00000 */
474         0xe590f008,     /* ldr  pc, [r0, #0x08] */
475 };
476
477 static int __init palmt5_pm_init(void)
478 {
479         int i;
480
481         /* this is where the bootloader jumps */
482         addr = phys_to_virt(PALMT5_STR_BASE);
483
484         for (i = 0; i < 3; i++)
485                 addr[i] = resume[i];
486
487         return 0;
488 }
489
490 device_initcall(palmt5_pm_init);
491 #endif
492
493 /******************************************************************************
494  * Machine init
495  ******************************************************************************/
496 static struct platform_device *devices[] __initdata = {
497 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
498         &palmt5_pxa_keys,
499 #endif
500         &palmt5_backlight,
501         &power_supply,
502         &palmt5_asoc,
503 };
504
505 /* setup udc GPIOs initial state */
506 static void __init palmt5_udc_init(void)
507 {
508         if (!gpio_request(GPIO_NR_PALMT5_USB_PULLUP, "UDC Vbus")) {
509                 gpio_direction_output(GPIO_NR_PALMT5_USB_PULLUP, 1);
510                 gpio_free(GPIO_NR_PALMT5_USB_PULLUP);
511         }
512 }
513
514 static void __init palmt5_init(void)
515 {
516         pxa2xx_mfp_config(ARRAY_AND_SIZE(palmt5_pin_config));
517
518         set_pxa_fb_info(&palmt5_lcd_screen);
519         pxa_set_mci_info(&palmt5_mci_platform_data);
520         palmt5_udc_init();
521         pxa_set_ac97_info(&palmt5_ac97_pdata);
522         pxa_set_udc_info(&palmt5_udc_info);
523         pxa_set_ficp_info(&palmt5_ficp_platform_data);
524         pxa_set_keypad_info(&palmt5_keypad_platform_data);
525         wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
526         platform_add_devices(devices, ARRAY_SIZE(devices));
527 }
528
529 MACHINE_START(PALMT5, "Palm Tungsten|T5")
530         .phys_io        = PALMT5_PHYS_IO_START,
531         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
532         .boot_params    = 0xa0000100,
533         .map_io         = pxa_map_io,
534         .init_irq       = pxa27x_init_irq,
535         .timer          = &pxa_timer,
536         .init_machine   = palmt5_init
537 MACHINE_END