nfsd4: check for negative dentry before use in nfsv4 readdir
[linux-2.6.git] / arch / arm / mach-pxa / palmtx.c
blob14393d0ad8b837d94d8a7f17ad23ccc906f20e25
1 /*
2 * Hardware definitions for PalmTX
4 * Author: Marek Vasut <marek.vasut@gmail.com>
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
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.
16 * (find more info at www.hackndev.com)
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>
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
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>
44 #include "generic.h"
45 #include "devices.h"
47 /******************************************************************************
48 * Pin configuration
49 ******************************************************************************/
50 static unsigned long palmtx_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 */
62 /* AC97 */
63 GPIO28_AC97_BITCLK,
64 GPIO29_AC97_SDATA_IN_0,
65 GPIO30_AC97_SDATA_OUT,
66 GPIO31_AC97_SYNC,
67 GPIO95_AC97_nRESET,
69 /* IrDA */
70 GPIO40_GPIO, /* ir disable */
71 GPIO46_FICP_RXD,
72 GPIO47_FICP_TXD,
74 /* PWM */
75 GPIO16_PWM0_OUT,
77 /* USB */
78 GPIO13_GPIO, /* usb detect */
79 GPIO93_GPIO, /* usb power */
81 /* PCMCIA */
82 GPIO48_nPOE,
83 GPIO49_nPWE,
84 GPIO50_nPIOR,
85 GPIO51_nPIOW,
86 GPIO85_nPCE_1,
87 GPIO54_nPCE_2,
88 GPIO79_PSKTSEL,
89 GPIO55_nPREG,
90 GPIO56_nPWAIT,
91 GPIO57_nIOIS16,
92 GPIO94_GPIO, /* wifi power 1 */
93 GPIO108_GPIO, /* wifi power 2 */
94 GPIO116_GPIO, /* wifi ready */
96 /* MATRIX KEYPAD */
97 GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
98 GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
99 GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
100 GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
101 GPIO103_KP_MKOUT_0,
102 GPIO104_KP_MKOUT_1,
103 GPIO105_KP_MKOUT_2,
105 /* LCD */
106 GPIO58_LCD_LDD_0,
107 GPIO59_LCD_LDD_1,
108 GPIO60_LCD_LDD_2,
109 GPIO61_LCD_LDD_3,
110 GPIO62_LCD_LDD_4,
111 GPIO63_LCD_LDD_5,
112 GPIO64_LCD_LDD_6,
113 GPIO65_LCD_LDD_7,
114 GPIO66_LCD_LDD_8,
115 GPIO67_LCD_LDD_9,
116 GPIO68_LCD_LDD_10,
117 GPIO69_LCD_LDD_11,
118 GPIO70_LCD_LDD_12,
119 GPIO71_LCD_LDD_13,
120 GPIO72_LCD_LDD_14,
121 GPIO73_LCD_LDD_15,
122 GPIO74_LCD_FCLK,
123 GPIO75_LCD_LCLK,
124 GPIO76_LCD_PCLK,
125 GPIO77_LCD_BIAS,
127 /* MISC. */
128 GPIO10_GPIO, /* hotsync button */
129 GPIO12_GPIO, /* power detect */
130 GPIO107_GPIO, /* earphone detect */
133 /******************************************************************************
134 * SD/MMC card controller
135 ******************************************************************************/
136 static int palmtx_mci_init(struct device *dev, irq_handler_t palmtx_detect_int,
137 void *data)
139 int err = 0;
141 /* Setup an interrupt for detecting card insert/remove events */
142 err = gpio_request(GPIO_NR_PALMTX_SD_DETECT_N, "SD IRQ");
143 if (err)
144 goto err;
145 err = gpio_direction_input(GPIO_NR_PALMTX_SD_DETECT_N);
146 if (err)
147 goto err2;
148 err = request_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N),
149 palmtx_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
150 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
151 "SD/MMC card detect", data);
152 if (err) {
153 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
154 __func__);
155 goto err2;
158 err = gpio_request(GPIO_NR_PALMTX_SD_POWER, "SD_POWER");
159 if (err)
160 goto err3;
161 err = gpio_direction_output(GPIO_NR_PALMTX_SD_POWER, 0);
162 if (err)
163 goto err4;
165 err = gpio_request(GPIO_NR_PALMTX_SD_READONLY, "SD_READONLY");
166 if (err)
167 goto err4;
168 err = gpio_direction_input(GPIO_NR_PALMTX_SD_READONLY);
169 if (err)
170 goto err5;
172 printk(KERN_DEBUG "%s: irq registered\n", __func__);
174 return 0;
176 err5:
177 gpio_free(GPIO_NR_PALMTX_SD_READONLY);
178 err4:
179 gpio_free(GPIO_NR_PALMTX_SD_POWER);
180 err3:
181 free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
182 err2:
183 gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
184 err:
185 return err;
188 static void palmtx_mci_exit(struct device *dev, void *data)
190 gpio_free(GPIO_NR_PALMTX_SD_READONLY);
191 gpio_free(GPIO_NR_PALMTX_SD_POWER);
192 free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
193 gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
196 static void palmtx_mci_power(struct device *dev, unsigned int vdd)
198 struct pxamci_platform_data *p_d = dev->platform_data;
199 gpio_set_value(GPIO_NR_PALMTX_SD_POWER, p_d->ocr_mask & (1 << vdd));
202 static int palmtx_mci_get_ro(struct device *dev)
204 return gpio_get_value(GPIO_NR_PALMTX_SD_READONLY);
207 static struct pxamci_platform_data palmtx_mci_platform_data = {
208 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
209 .setpower = palmtx_mci_power,
210 .get_ro = palmtx_mci_get_ro,
211 .init = palmtx_mci_init,
212 .exit = palmtx_mci_exit,
215 /******************************************************************************
216 * GPIO keyboard
217 ******************************************************************************/
218 static unsigned int palmtx_matrix_keys[] = {
219 KEY(0, 0, KEY_POWER),
220 KEY(0, 1, KEY_F1),
221 KEY(0, 2, KEY_ENTER),
223 KEY(1, 0, KEY_F2),
224 KEY(1, 1, KEY_F3),
225 KEY(1, 2, KEY_F4),
227 KEY(2, 0, KEY_UP),
228 KEY(2, 2, KEY_DOWN),
230 KEY(3, 0, KEY_RIGHT),
231 KEY(3, 2, KEY_LEFT),
234 static struct pxa27x_keypad_platform_data palmtx_keypad_platform_data = {
235 .matrix_key_rows = 4,
236 .matrix_key_cols = 3,
237 .matrix_key_map = palmtx_matrix_keys,
238 .matrix_key_map_size = ARRAY_SIZE(palmtx_matrix_keys),
240 .debounce_interval = 30,
243 /******************************************************************************
244 * GPIO keys
245 ******************************************************************************/
246 static struct gpio_keys_button palmtx_pxa_buttons[] = {
247 {KEY_F8, GPIO_NR_PALMTX_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
250 static struct gpio_keys_platform_data palmtx_pxa_keys_data = {
251 .buttons = palmtx_pxa_buttons,
252 .nbuttons = ARRAY_SIZE(palmtx_pxa_buttons),
255 static struct platform_device palmtx_pxa_keys = {
256 .name = "gpio-keys",
257 .id = -1,
258 .dev = {
259 .platform_data = &palmtx_pxa_keys_data,
263 /******************************************************************************
264 * Backlight
265 ******************************************************************************/
266 static int palmtx_backlight_init(struct device *dev)
268 int ret;
270 ret = gpio_request(GPIO_NR_PALMTX_BL_POWER, "BL POWER");
271 if (ret)
272 goto err;
273 ret = gpio_direction_output(GPIO_NR_PALMTX_BL_POWER, 0);
274 if (ret)
275 goto err2;
276 ret = gpio_request(GPIO_NR_PALMTX_LCD_POWER, "LCD POWER");
277 if (ret)
278 goto err2;
279 ret = gpio_direction_output(GPIO_NR_PALMTX_LCD_POWER, 0);
280 if (ret)
281 goto err3;
283 return 0;
284 err3:
285 gpio_free(GPIO_NR_PALMTX_LCD_POWER);
286 err2:
287 gpio_free(GPIO_NR_PALMTX_BL_POWER);
288 err:
289 return ret;
292 static int palmtx_backlight_notify(int brightness)
294 gpio_set_value(GPIO_NR_PALMTX_BL_POWER, brightness);
295 gpio_set_value(GPIO_NR_PALMTX_LCD_POWER, brightness);
296 return brightness;
299 static void palmtx_backlight_exit(struct device *dev)
301 gpio_free(GPIO_NR_PALMTX_BL_POWER);
302 gpio_free(GPIO_NR_PALMTX_LCD_POWER);
305 static struct platform_pwm_backlight_data palmtx_backlight_data = {
306 .pwm_id = 0,
307 .max_brightness = PALMTX_MAX_INTENSITY,
308 .dft_brightness = PALMTX_MAX_INTENSITY,
309 .pwm_period_ns = PALMTX_PERIOD_NS,
310 .init = palmtx_backlight_init,
311 .notify = palmtx_backlight_notify,
312 .exit = palmtx_backlight_exit,
315 static struct platform_device palmtx_backlight = {
316 .name = "pwm-backlight",
317 .dev = {
318 .parent = &pxa27x_device_pwm0.dev,
319 .platform_data = &palmtx_backlight_data,
323 /******************************************************************************
324 * IrDA
325 ******************************************************************************/
326 static int palmtx_irda_startup(struct device *dev)
328 int err;
329 err = gpio_request(GPIO_NR_PALMTX_IR_DISABLE, "IR DISABLE");
330 if (err)
331 goto err;
332 err = gpio_direction_output(GPIO_NR_PALMTX_IR_DISABLE, 1);
333 if (err)
334 gpio_free(GPIO_NR_PALMTX_IR_DISABLE);
335 err:
336 return err;
339 static void palmtx_irda_shutdown(struct device *dev)
341 gpio_free(GPIO_NR_PALMTX_IR_DISABLE);
344 static void palmtx_irda_transceiver_mode(struct device *dev, int mode)
346 gpio_set_value(GPIO_NR_PALMTX_IR_DISABLE, mode & IR_OFF);
347 pxa2xx_transceiver_mode(dev, mode);
350 static struct pxaficp_platform_data palmtx_ficp_platform_data = {
351 .startup = palmtx_irda_startup,
352 .shutdown = palmtx_irda_shutdown,
353 .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
354 .transceiver_mode = palmtx_irda_transceiver_mode,
357 /******************************************************************************
358 * UDC
359 ******************************************************************************/
360 static struct pxa2xx_udc_mach_info palmtx_udc_info __initdata = {
361 .gpio_vbus = GPIO_NR_PALMTX_USB_DETECT_N,
362 .gpio_vbus_inverted = 1,
363 .gpio_pullup = GPIO_NR_PALMTX_USB_PULLUP,
364 .gpio_pullup_inverted = 0,
367 /******************************************************************************
368 * Power supply
369 ******************************************************************************/
370 static int power_supply_init(struct device *dev)
372 int ret;
374 ret = gpio_request(GPIO_NR_PALMTX_POWER_DETECT, "CABLE_STATE_AC");
375 if (ret)
376 goto err1;
377 ret = gpio_direction_input(GPIO_NR_PALMTX_POWER_DETECT);
378 if (ret)
379 goto err2;
381 return 0;
383 err2:
384 gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
385 err1:
386 return ret;
389 static int palmtx_is_ac_online(void)
391 return gpio_get_value(GPIO_NR_PALMTX_POWER_DETECT);
394 static void power_supply_exit(struct device *dev)
396 gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
399 static char *palmtx_supplicants[] = {
400 "main-battery",
403 static struct pda_power_pdata power_supply_info = {
404 .init = power_supply_init,
405 .is_ac_online = palmtx_is_ac_online,
406 .exit = power_supply_exit,
407 .supplied_to = palmtx_supplicants,
408 .num_supplicants = ARRAY_SIZE(palmtx_supplicants),
411 static struct platform_device power_supply = {
412 .name = "pda-power",
413 .id = -1,
414 .dev = {
415 .platform_data = &power_supply_info,
419 /******************************************************************************
420 * WM97xx battery
421 ******************************************************************************/
422 static struct wm97xx_batt_info wm97xx_batt_pdata = {
423 .batt_aux = WM97XX_AUX_ID3,
424 .temp_aux = WM97XX_AUX_ID2,
425 .charge_gpio = -1,
426 .max_voltage = PALMTX_BAT_MAX_VOLTAGE,
427 .min_voltage = PALMTX_BAT_MIN_VOLTAGE,
428 .batt_mult = 1000,
429 .batt_div = 414,
430 .temp_mult = 1,
431 .temp_div = 1,
432 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
433 .batt_name = "main-batt",
436 /******************************************************************************
437 * Framebuffer
438 ******************************************************************************/
439 static struct pxafb_mode_info palmtx_lcd_modes[] = {
441 .pixclock = 57692,
442 .xres = 320,
443 .yres = 480,
444 .bpp = 16,
446 .left_margin = 32,
447 .right_margin = 1,
448 .upper_margin = 7,
449 .lower_margin = 1,
451 .hsync_len = 4,
452 .vsync_len = 1,
456 static struct pxafb_mach_info palmtx_lcd_screen = {
457 .modes = palmtx_lcd_modes,
458 .num_modes = ARRAY_SIZE(palmtx_lcd_modes),
459 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
462 /******************************************************************************
463 * Power management - standby
464 ******************************************************************************/
465 #ifdef CONFIG_PM
466 static u32 *addr __initdata;
467 static u32 resume[3] __initdata = {
468 0xe3a00101, /* mov r0, #0x40000000 */
469 0xe380060f, /* orr r0, r0, #0x00f00000 */
470 0xe590f008, /* ldr pc, [r0, #0x08] */
473 static int __init palmtx_pm_init(void)
475 int i;
477 /* this is where the bootloader jumps */
478 addr = phys_to_virt(PALMTX_STR_BASE);
480 for (i = 0; i < 3; i++)
481 addr[i] = resume[i];
483 return 0;
486 device_initcall(palmtx_pm_init);
487 #endif
489 /******************************************************************************
490 * Machine init
491 ******************************************************************************/
492 static struct platform_device *devices[] __initdata = {
493 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
494 &palmtx_pxa_keys,
495 #endif
496 &palmtx_backlight,
497 &power_supply,
500 static struct map_desc palmtx_io_desc[] __initdata = {
502 .virtual = PALMTX_PCMCIA_VIRT,
503 .pfn = __phys_to_pfn(PALMTX_PCMCIA_PHYS),
504 .length = PALMTX_PCMCIA_SIZE,
505 .type = MT_DEVICE
509 static void __init palmtx_map_io(void)
511 pxa_map_io();
512 iotable_init(palmtx_io_desc, ARRAY_SIZE(palmtx_io_desc));
515 /* setup udc GPIOs initial state */
516 static void __init palmtx_udc_init(void)
518 if (!gpio_request(GPIO_NR_PALMTX_USB_PULLUP, "UDC Vbus")) {
519 gpio_direction_output(GPIO_NR_PALMTX_USB_PULLUP, 1);
520 gpio_free(GPIO_NR_PALMTX_USB_PULLUP);
525 static void __init palmtx_init(void)
527 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmtx_pin_config));
529 set_pxa_fb_info(&palmtx_lcd_screen);
530 pxa_set_mci_info(&palmtx_mci_platform_data);
531 palmtx_udc_init();
532 pxa_set_udc_info(&palmtx_udc_info);
533 pxa_set_ac97_info(NULL);
534 pxa_set_ficp_info(&palmtx_ficp_platform_data);
535 pxa_set_keypad_info(&palmtx_keypad_platform_data);
536 wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
538 platform_add_devices(devices, ARRAY_SIZE(devices));
541 MACHINE_START(PALMTX, "Palm T|X")
542 .phys_io = PALMTX_PHYS_IO_START,
543 .io_pg_offst = io_p2v(0x40000000),
544 .boot_params = 0xa0000100,
545 .map_io = palmtx_map_io,
546 .init_irq = pxa27x_init_irq,
547 .timer = &pxa_timer,
548 .init_machine = palmtx_init
549 MACHINE_END