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