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