b490c0924619bf7e69fce0ca50fbde060532f090
[deliverable/linux.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
44 #include "generic.h"
45 #include "devices.h"
46
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 */
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 */
69 GPIO40_GPIO, /* ir disable */
70 GPIO46_FICP_RXD,
71 GPIO47_FICP_TXD,
72
73 /* PWM */
74 GPIO16_PWM0_OUT,
75
76 /* USB */
77 GPIO13_GPIO, /* usb detect */
78 GPIO95_GPIO, /* usb power */
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,
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 */
130 };
131
132 /******************************************************************************
133 * SD/MMC card controller
134 ******************************************************************************/
135 static 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 */
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 |
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__);
154 goto err2;
155 }
156
157 err = gpio_request(GPIO_NR_PALMTX_SD_POWER, "SD_POWER");
158 if (err)
159 goto err3;
160 err = gpio_direction_output(GPIO_NR_PALMTX_SD_POWER, 0);
161 if (err)
162 goto err4;
163
164 err = gpio_request(GPIO_NR_PALMTX_SD_READONLY, "SD_READONLY");
165 if (err)
166 goto err4;
167 err = gpio_direction_input(GPIO_NR_PALMTX_SD_READONLY);
168 if (err)
169 goto err5;
170
171 printk(KERN_DEBUG "%s: irq registered\n", __func__);
172
173 return 0;
174
175 err5:
176 gpio_free(GPIO_NR_PALMTX_SD_READONLY);
177 err4:
178 gpio_free(GPIO_NR_PALMTX_SD_POWER);
179 err3:
180 free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
181 err2:
182 gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
183 err:
184 return err;
185 }
186
187 static 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);
191 free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
192 gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
193 }
194
195 static 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
201 static int palmtx_mci_get_ro(struct device *dev)
202 {
203 return gpio_get_value(GPIO_NR_PALMTX_SD_READONLY);
204 }
205
206 static 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 ******************************************************************************/
217 static 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),
231 };
232
233 static 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 ******************************************************************************/
245 static struct gpio_keys_button palmtx_pxa_buttons[] = {
246 {KEY_F8, GPIO_NR_PALMTX_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
247 };
248
249 static struct gpio_keys_platform_data palmtx_pxa_keys_data = {
250 .buttons = palmtx_pxa_buttons,
251 .nbuttons = ARRAY_SIZE(palmtx_pxa_buttons),
252 };
253
254 static 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 ******************************************************************************/
265 static 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;
272 ret = gpio_direction_output(GPIO_NR_PALMTX_BL_POWER, 0);
273 if (ret)
274 goto err2;
275 ret = gpio_request(GPIO_NR_PALMTX_LCD_POWER, "LCD POWER");
276 if (ret)
277 goto err2;
278 ret = gpio_direction_output(GPIO_NR_PALMTX_LCD_POWER, 0);
279 if (ret)
280 goto err3;
281
282 return 0;
283 err3:
284 gpio_free(GPIO_NR_PALMTX_LCD_POWER);
285 err2:
286 gpio_free(GPIO_NR_PALMTX_BL_POWER);
287 err:
288 return ret;
289 }
290
291 static 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
298 static 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
304 static 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
314 static 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 ******************************************************************************/
325 static 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);
334 err:
335 return err;
336 }
337
338 static void palmtx_irda_shutdown(struct device *dev)
339 {
340 gpio_free(GPIO_NR_PALMTX_IR_DISABLE);
341 }
342
343 static 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
349 static struct pxaficp_platform_data palmtx_ficp_platform_data = {
350 .startup = palmtx_irda_startup,
351 .shutdown = palmtx_irda_shutdown,
352 .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
353 .transceiver_mode = palmtx_irda_transceiver_mode,
354 };
355
356 /******************************************************************************
357 * UDC
358 ******************************************************************************/
359 static struct pxa2xx_udc_mach_info palmtx_udc_info __initdata = {
360 .gpio_vbus = GPIO_NR_PALMTX_USB_DETECT_N,
361 .gpio_vbus_inverted = 1,
362 .gpio_pullup = GPIO_NR_PALMTX_USB_POWER,
363 .gpio_pullup_inverted = 0,
364 };
365
366 /******************************************************************************
367 * Power supply
368 ******************************************************************************/
369 static 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)
375 goto err1;
376 ret = gpio_direction_input(GPIO_NR_PALMTX_POWER_DETECT);
377 if (ret)
378 goto err2;
379
380 return 0;
381
382 err2:
383 gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
384 err1:
385 return ret;
386 }
387
388 static int palmtx_is_ac_online(void)
389 {
390 return gpio_get_value(GPIO_NR_PALMTX_POWER_DETECT);
391 }
392
393 static void power_supply_exit(struct device *dev)
394 {
395 gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
396 }
397
398 static char *palmtx_supplicants[] = {
399 "main-battery",
400 };
401
402 static struct pda_power_pdata power_supply_info = {
403 .init = power_supply_init,
404 .is_ac_online = palmtx_is_ac_online,
405 .exit = power_supply_exit,
406 .supplied_to = palmtx_supplicants,
407 .num_supplicants = ARRAY_SIZE(palmtx_supplicants),
408 };
409
410 static struct platform_device power_supply = {
411 .name = "pda-power",
412 .id = -1,
413 .dev = {
414 .platform_data = &power_supply_info,
415 },
416 };
417
418 /******************************************************************************
419 * WM97xx battery
420 ******************************************************************************/
421 static 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
435 /******************************************************************************
436 * Framebuffer
437 ******************************************************************************/
438 static 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
455 static 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 ******************************************************************************/
464 static 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,
469 &power_supply,
470 };
471
472 static 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
481 static void __init palmtx_map_io(void)
482 {
483 pxa_map_io();
484 iotable_init(palmtx_io_desc, ARRAY_SIZE(palmtx_io_desc));
485 }
486
487 /* setup udc GPIOs initial state */
488 static 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
497 static 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);
503 palmtx_udc_init();
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);
508 wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
509
510 platform_add_devices(devices, ARRAY_SIZE(devices));
511 }
512
513 MACHINE_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
521 MACHINE_END
This page took 0.042544 seconds and 5 git commands to generate.