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