Linux 2.6.31.8
[linux/fpc-iii.git] / arch / arm / mach-pxa / palmte2.c
blobd823b09801df5865c1b279233fc2d04a0ee49b43
1 /*
2 * Hardware definitions for Palm Tungsten|E2
4 * Author:
5 * Carlos Eduardo Medaglia Dyonisio <cadu@nerdfeliz.com>
7 * Rewrite for mainline:
8 * Marek Vasut <marek.vasut@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * (find more info at www.hackndev.com)
18 #include <linux/platform_device.h>
19 #include <linux/delay.h>
20 #include <linux/irq.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/input.h>
23 #include <linux/pda_power.h>
24 #include <linux/pwm_backlight.h>
25 #include <linux/gpio.h>
26 #include <linux/wm97xx_batt.h>
27 #include <linux/power_supply.h>
28 #include <linux/usb/gpio_vbus.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
34 #include <mach/audio.h>
35 #include <mach/palmte2.h>
36 #include <mach/mmc.h>
37 #include <mach/pxafb.h>
38 #include <mach/mfp-pxa25x.h>
39 #include <mach/irda.h>
40 #include <mach/udc.h>
41 #include <mach/palmasoc.h>
43 #include "generic.h"
44 #include "devices.h"
46 /******************************************************************************
47 * Pin configuration
48 ******************************************************************************/
49 static unsigned long palmte2_pin_config[] __initdata = {
50 /* MMC */
51 GPIO6_MMC_CLK,
52 GPIO8_MMC_CS0,
53 GPIO10_GPIO, /* SD detect */
54 GPIO55_GPIO, /* SD power */
55 GPIO51_GPIO, /* SD r/o switch */
57 /* AC97 */
58 GPIO28_AC97_BITCLK,
59 GPIO29_AC97_SDATA_IN_0,
60 GPIO30_AC97_SDATA_OUT,
61 GPIO31_AC97_SYNC,
63 /* PWM */
64 GPIO16_PWM0_OUT,
66 /* USB */
67 GPIO15_GPIO, /* usb detect */
68 GPIO53_GPIO, /* usb power */
70 /* IrDA */
71 GPIO48_GPIO, /* ir disable */
72 GPIO46_FICP_RXD,
73 GPIO47_FICP_TXD,
75 /* LCD */
76 GPIO58_LCD_LDD_0,
77 GPIO59_LCD_LDD_1,
78 GPIO60_LCD_LDD_2,
79 GPIO61_LCD_LDD_3,
80 GPIO62_LCD_LDD_4,
81 GPIO63_LCD_LDD_5,
82 GPIO64_LCD_LDD_6,
83 GPIO65_LCD_LDD_7,
84 GPIO66_LCD_LDD_8,
85 GPIO67_LCD_LDD_9,
86 GPIO68_LCD_LDD_10,
87 GPIO69_LCD_LDD_11,
88 GPIO70_LCD_LDD_12,
89 GPIO71_LCD_LDD_13,
90 GPIO72_LCD_LDD_14,
91 GPIO73_LCD_LDD_15,
92 GPIO74_LCD_FCLK,
93 GPIO75_LCD_LCLK,
94 GPIO76_LCD_PCLK,
95 GPIO77_LCD_BIAS,
97 /* GPIO KEYS */
98 GPIO5_GPIO, /* notes */
99 GPIO7_GPIO, /* tasks */
100 GPIO11_GPIO, /* calendar */
101 GPIO13_GPIO, /* contacts */
102 GPIO14_GPIO, /* center */
103 GPIO19_GPIO, /* left */
104 GPIO20_GPIO, /* right */
105 GPIO21_GPIO, /* down */
106 GPIO22_GPIO, /* up */
108 /* MISC */
109 GPIO1_RST, /* reset */
110 GPIO4_GPIO, /* Hotsync button */
111 GPIO9_GPIO, /* power detect */
112 GPIO15_GPIO, /* earphone detect */
113 GPIO37_GPIO, /* LCD power */
114 GPIO56_GPIO, /* Backlight power */
117 /******************************************************************************
118 * SD/MMC card controller
119 ******************************************************************************/
120 static int palmte2_mci_init(struct device *dev,
121 irq_handler_t palmte2_detect_int, void *data)
123 int err = 0;
125 /* Setup an interrupt for detecting card insert/remove events */
126 err = gpio_request(GPIO_NR_PALMTE2_SD_DETECT_N, "SD IRQ");
127 if (err)
128 goto err;
129 err = gpio_direction_input(GPIO_NR_PALMTE2_SD_DETECT_N);
130 if (err)
131 goto err2;
132 err = request_irq(gpio_to_irq(GPIO_NR_PALMTE2_SD_DETECT_N),
133 palmte2_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
134 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
135 "SD/MMC card detect", data);
136 if (err) {
137 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
138 __func__);
139 goto err2;
142 err = gpio_request(GPIO_NR_PALMTE2_SD_POWER, "SD_POWER");
143 if (err)
144 goto err3;
145 err = gpio_direction_output(GPIO_NR_PALMTE2_SD_POWER, 0);
146 if (err)
147 goto err4;
149 err = gpio_request(GPIO_NR_PALMTE2_SD_READONLY, "SD_READONLY");
150 if (err)
151 goto err4;
152 err = gpio_direction_input(GPIO_NR_PALMTE2_SD_READONLY);
153 if (err)
154 goto err5;
156 printk(KERN_DEBUG "%s: irq registered\n", __func__);
158 return 0;
160 err5:
161 gpio_free(GPIO_NR_PALMTE2_SD_READONLY);
162 err4:
163 gpio_free(GPIO_NR_PALMTE2_SD_POWER);
164 err3:
165 free_irq(gpio_to_irq(GPIO_NR_PALMTE2_SD_DETECT_N), data);
166 err2:
167 gpio_free(GPIO_NR_PALMTE2_SD_DETECT_N);
168 err:
169 return err;
172 static void palmte2_mci_exit(struct device *dev, void *data)
174 gpio_free(GPIO_NR_PALMTE2_SD_READONLY);
175 gpio_free(GPIO_NR_PALMTE2_SD_POWER);
176 free_irq(gpio_to_irq(GPIO_NR_PALMTE2_SD_DETECT_N), data);
177 gpio_free(GPIO_NR_PALMTE2_SD_DETECT_N);
180 static void palmte2_mci_power(struct device *dev, unsigned int vdd)
182 struct pxamci_platform_data *p_d = dev->platform_data;
183 gpio_set_value(GPIO_NR_PALMTE2_SD_POWER, p_d->ocr_mask & (1 << vdd));
186 static int palmte2_mci_get_ro(struct device *dev)
188 return gpio_get_value(GPIO_NR_PALMTE2_SD_READONLY);
191 static struct pxamci_platform_data palmte2_mci_platform_data = {
192 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
193 .setpower = palmte2_mci_power,
194 .get_ro = palmte2_mci_get_ro,
195 .init = palmte2_mci_init,
196 .exit = palmte2_mci_exit,
199 /******************************************************************************
200 * GPIO keys
201 ******************************************************************************/
202 static struct gpio_keys_button palmte2_pxa_buttons[] = {
203 {KEY_F1, GPIO_NR_PALMTE2_KEY_CONTACTS, 1, "Contacts" },
204 {KEY_F2, GPIO_NR_PALMTE2_KEY_CALENDAR, 1, "Calendar" },
205 {KEY_F3, GPIO_NR_PALMTE2_KEY_TASKS, 1, "Tasks" },
206 {KEY_F4, GPIO_NR_PALMTE2_KEY_NOTES, 1, "Notes" },
207 {KEY_ENTER, GPIO_NR_PALMTE2_KEY_CENTER, 1, "Center" },
208 {KEY_LEFT, GPIO_NR_PALMTE2_KEY_LEFT, 1, "Left" },
209 {KEY_RIGHT, GPIO_NR_PALMTE2_KEY_RIGHT, 1, "Right" },
210 {KEY_DOWN, GPIO_NR_PALMTE2_KEY_DOWN, 1, "Down" },
211 {KEY_UP, GPIO_NR_PALMTE2_KEY_UP, 1, "Up" },
214 static struct gpio_keys_platform_data palmte2_pxa_keys_data = {
215 .buttons = palmte2_pxa_buttons,
216 .nbuttons = ARRAY_SIZE(palmte2_pxa_buttons),
219 static struct platform_device palmte2_pxa_keys = {
220 .name = "gpio-keys",
221 .id = -1,
222 .dev = {
223 .platform_data = &palmte2_pxa_keys_data,
227 /******************************************************************************
228 * Backlight
229 ******************************************************************************/
230 static int palmte2_backlight_init(struct device *dev)
232 int ret;
234 ret = gpio_request(GPIO_NR_PALMTE2_BL_POWER, "BL POWER");
235 if (ret)
236 goto err;
237 ret = gpio_direction_output(GPIO_NR_PALMTE2_BL_POWER, 0);
238 if (ret)
239 goto err2;
240 ret = gpio_request(GPIO_NR_PALMTE2_LCD_POWER, "LCD POWER");
241 if (ret)
242 goto err2;
243 ret = gpio_direction_output(GPIO_NR_PALMTE2_LCD_POWER, 0);
244 if (ret)
245 goto err3;
247 return 0;
248 err3:
249 gpio_free(GPIO_NR_PALMTE2_LCD_POWER);
250 err2:
251 gpio_free(GPIO_NR_PALMTE2_BL_POWER);
252 err:
253 return ret;
256 static int palmte2_backlight_notify(int brightness)
258 gpio_set_value(GPIO_NR_PALMTE2_BL_POWER, brightness);
259 gpio_set_value(GPIO_NR_PALMTE2_LCD_POWER, brightness);
260 return brightness;
263 static void palmte2_backlight_exit(struct device *dev)
265 gpio_free(GPIO_NR_PALMTE2_BL_POWER);
266 gpio_free(GPIO_NR_PALMTE2_LCD_POWER);
269 static struct platform_pwm_backlight_data palmte2_backlight_data = {
270 .pwm_id = 0,
271 .max_brightness = PALMTE2_MAX_INTENSITY,
272 .dft_brightness = PALMTE2_MAX_INTENSITY,
273 .pwm_period_ns = PALMTE2_PERIOD_NS,
274 .init = palmte2_backlight_init,
275 .notify = palmte2_backlight_notify,
276 .exit = palmte2_backlight_exit,
279 static struct platform_device palmte2_backlight = {
280 .name = "pwm-backlight",
281 .dev = {
282 .parent = &pxa25x_device_pwm0.dev,
283 .platform_data = &palmte2_backlight_data,
287 /******************************************************************************
288 * IrDA
289 ******************************************************************************/
290 static int palmte2_irda_startup(struct device *dev)
292 int err;
293 err = gpio_request(GPIO_NR_PALMTE2_IR_DISABLE, "IR DISABLE");
294 if (err)
295 goto err;
296 err = gpio_direction_output(GPIO_NR_PALMTE2_IR_DISABLE, 1);
297 if (err)
298 gpio_free(GPIO_NR_PALMTE2_IR_DISABLE);
299 err:
300 return err;
303 static void palmte2_irda_shutdown(struct device *dev)
305 gpio_free(GPIO_NR_PALMTE2_IR_DISABLE);
308 static void palmte2_irda_transceiver_mode(struct device *dev, int mode)
310 gpio_set_value(GPIO_NR_PALMTE2_IR_DISABLE, mode & IR_OFF);
311 pxa2xx_transceiver_mode(dev, mode);
314 static struct pxaficp_platform_data palmte2_ficp_platform_data = {
315 .startup = palmte2_irda_startup,
316 .shutdown = palmte2_irda_shutdown,
317 .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
318 .transceiver_mode = palmte2_irda_transceiver_mode,
321 /******************************************************************************
322 * UDC
323 ******************************************************************************/
324 static struct gpio_vbus_mach_info palmte2_udc_info = {
325 .gpio_vbus = GPIO_NR_PALMTE2_USB_DETECT_N,
326 .gpio_vbus_inverted = 1,
327 .gpio_pullup = GPIO_NR_PALMTE2_USB_PULLUP,
330 static struct platform_device palmte2_gpio_vbus = {
331 .name = "gpio-vbus",
332 .id = -1,
333 .dev = {
334 .platform_data = &palmte2_udc_info,
338 /******************************************************************************
339 * Power supply
340 ******************************************************************************/
341 static int power_supply_init(struct device *dev)
343 int ret;
345 ret = gpio_request(GPIO_NR_PALMTE2_POWER_DETECT, "CABLE_STATE_AC");
346 if (ret)
347 goto err1;
348 ret = gpio_direction_input(GPIO_NR_PALMTE2_POWER_DETECT);
349 if (ret)
350 goto err2;
352 return 0;
354 err2:
355 gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
356 err1:
357 return ret;
360 static int palmte2_is_ac_online(void)
362 return gpio_get_value(GPIO_NR_PALMTE2_POWER_DETECT);
365 static void power_supply_exit(struct device *dev)
367 gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
370 static char *palmte2_supplicants[] = {
371 "main-battery",
374 static struct pda_power_pdata power_supply_info = {
375 .init = power_supply_init,
376 .is_ac_online = palmte2_is_ac_online,
377 .exit = power_supply_exit,
378 .supplied_to = palmte2_supplicants,
379 .num_supplicants = ARRAY_SIZE(palmte2_supplicants),
382 static struct platform_device power_supply = {
383 .name = "pda-power",
384 .id = -1,
385 .dev = {
386 .platform_data = &power_supply_info,
390 /******************************************************************************
391 * WM97xx battery
392 ******************************************************************************/
393 static struct wm97xx_batt_info wm97xx_batt_pdata = {
394 .batt_aux = WM97XX_AUX_ID3,
395 .temp_aux = WM97XX_AUX_ID2,
396 .charge_gpio = -1,
397 .max_voltage = PALMTE2_BAT_MAX_VOLTAGE,
398 .min_voltage = PALMTE2_BAT_MIN_VOLTAGE,
399 .batt_mult = 1000,
400 .batt_div = 414,
401 .temp_mult = 1,
402 .temp_div = 1,
403 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
404 .batt_name = "main-batt",
407 /******************************************************************************
408 * aSoC audio
409 ******************************************************************************/
410 static struct palm27x_asoc_info palmte2_asoc_pdata = {
411 .jack_gpio = GPIO_NR_PALMTE2_EARPHONE_DETECT,
414 static struct platform_device palmte2_asoc = {
415 .name = "palm27x-asoc",
416 .id = -1,
417 .dev = {
418 .platform_data = &palmte2_asoc_pdata,
422 /******************************************************************************
423 * Framebuffer
424 ******************************************************************************/
425 static struct pxafb_mode_info palmte2_lcd_modes[] = {
427 .pixclock = 77757,
428 .xres = 320,
429 .yres = 320,
430 .bpp = 16,
432 .left_margin = 28,
433 .right_margin = 7,
434 .upper_margin = 7,
435 .lower_margin = 5,
437 .hsync_len = 4,
438 .vsync_len = 1,
442 static struct pxafb_mach_info palmte2_lcd_screen = {
443 .modes = palmte2_lcd_modes,
444 .num_modes = ARRAY_SIZE(palmte2_lcd_modes),
445 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
448 /******************************************************************************
449 * Machine init
450 ******************************************************************************/
451 static struct platform_device *devices[] __initdata = {
452 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
453 &palmte2_pxa_keys,
454 #endif
455 &palmte2_backlight,
456 &power_supply,
457 &palmte2_asoc,
458 &palmte2_gpio_vbus,
461 /* setup udc GPIOs initial state */
462 static void __init palmte2_udc_init(void)
464 if (!gpio_request(GPIO_NR_PALMTE2_USB_PULLUP, "UDC Vbus")) {
465 gpio_direction_output(GPIO_NR_PALMTE2_USB_PULLUP, 1);
466 gpio_free(GPIO_NR_PALMTE2_USB_PULLUP);
470 static void __init palmte2_init(void)
472 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmte2_pin_config));
474 set_pxa_fb_info(&palmte2_lcd_screen);
475 pxa_set_mci_info(&palmte2_mci_platform_data);
476 palmte2_udc_init();
477 pxa_set_ac97_info(NULL);
478 pxa_set_ficp_info(&palmte2_ficp_platform_data);
479 wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
481 platform_add_devices(devices, ARRAY_SIZE(devices));
484 MACHINE_START(PALMTE2, "Palm Tungsten|E2")
485 .phys_io = 0x40000000,
486 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
487 .boot_params = 0xa0000100,
488 .map_io = pxa_map_io,
489 .init_irq = pxa25x_init_irq,
490 .timer = &pxa_timer,
491 .init_machine = palmte2_init
492 MACHINE_END