[ARM] pxa: introduce pxa{25x,27x,300,320,930}.h for board usage
[deliverable/linux.git] / arch / arm / mach-pxa / palmz72.c
1 /*
2 * Hardware definitions for Palm Zire72
3 *
4 * Authors:
5 * Vladimir "Farcaller" Pouzanov <farcaller@gmail.com>
6 * Sergey Lapin <slapin@ossfans.org>
7 * Alex Osborne <bobofdoom@gmail.com>
8 * Jan Herman <2hp@seznam.cz>
9 *
10 * Rewrite for mainline:
11 * Marek Vasut <marek.vasut@gmail.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 *
17 * (find more info at www.hackndev.com)
18 *
19 */
20
21 #include <linux/platform_device.h>
22 #include <linux/sysdev.h>
23 #include <linux/delay.h>
24 #include <linux/irq.h>
25 #include <linux/gpio_keys.h>
26 #include <linux/input.h>
27 #include <linux/pda_power.h>
28 #include <linux/pwm_backlight.h>
29 #include <linux/gpio.h>
30 #include <linux/power_supply.h>
31
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35
36 #include <mach/pxa27x.h>
37 #include <mach/audio.h>
38 #include <mach/palmz72.h>
39 #include <mach/mmc.h>
40 #include <mach/pxafb.h>
41 #include <mach/irda.h>
42 #include <mach/pxa27x_keypad.h>
43 #include <mach/udc.h>
44 #include <mach/pm.h>
45
46 #include "generic.h"
47 #include "devices.h"
48
49 /******************************************************************************
50 * Pin configuration
51 ******************************************************************************/
52 static unsigned long palmz72_pin_config[] __initdata = {
53 /* MMC */
54 GPIO32_MMC_CLK,
55 GPIO92_MMC_DAT_0,
56 GPIO109_MMC_DAT_1,
57 GPIO110_MMC_DAT_2,
58 GPIO111_MMC_DAT_3,
59 GPIO112_MMC_CMD,
60 GPIO14_GPIO, /* SD detect */
61 GPIO115_GPIO, /* SD RO */
62 GPIO98_GPIO, /* SD power */
63
64 /* AC97 */
65 GPIO28_AC97_BITCLK,
66 GPIO29_AC97_SDATA_IN_0,
67 GPIO30_AC97_SDATA_OUT,
68 GPIO31_AC97_SYNC,
69
70 /* IrDA */
71 GPIO49_GPIO, /* ir disable */
72 GPIO46_FICP_RXD,
73 GPIO47_FICP_TXD,
74
75 /* PWM */
76 GPIO16_PWM0_OUT,
77
78 /* USB */
79 GPIO15_GPIO, /* usb detect */
80 GPIO12_GPIO, /* usb pullup */
81 GPIO95_GPIO, /* usb power */
82
83 /* Matrix keypad */
84 GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
85 GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
86 GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
87 GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
88 GPIO103_KP_MKOUT_0,
89 GPIO104_KP_MKOUT_1,
90 GPIO105_KP_MKOUT_2,
91
92 /* LCD */
93 GPIO58_LCD_LDD_0,
94 GPIO59_LCD_LDD_1,
95 GPIO60_LCD_LDD_2,
96 GPIO61_LCD_LDD_3,
97 GPIO62_LCD_LDD_4,
98 GPIO63_LCD_LDD_5,
99 GPIO64_LCD_LDD_6,
100 GPIO65_LCD_LDD_7,
101 GPIO66_LCD_LDD_8,
102 GPIO67_LCD_LDD_9,
103 GPIO68_LCD_LDD_10,
104 GPIO69_LCD_LDD_11,
105 GPIO70_LCD_LDD_12,
106 GPIO71_LCD_LDD_13,
107 GPIO72_LCD_LDD_14,
108 GPIO73_LCD_LDD_15,
109 GPIO74_LCD_FCLK,
110 GPIO75_LCD_LCLK,
111 GPIO76_LCD_PCLK,
112 GPIO77_LCD_BIAS,
113 GPIO20_GPIO, /* bl power */
114 GPIO21_GPIO, /* LCD border switch */
115 GPIO22_GPIO, /* LCD border color */
116 GPIO96_GPIO, /* lcd power */
117
118 /* Misc. */
119 GPIO0_GPIO | WAKEUP_ON_LEVEL_HIGH, /* power detect */
120 GPIO88_GPIO, /* green led */
121 GPIO27_GPIO, /* WM9712 IRQ */
122 };
123
124 /******************************************************************************
125 * SD/MMC card controller
126 ******************************************************************************/
127 static int palmz72_mci_init(struct device *dev,
128 irq_handler_t palmz72_detect_int, void *data)
129 {
130 int err = 0;
131
132 /* Setup an interrupt for detecting card insert/remove events */
133 err = gpio_request(GPIO_NR_PALMZ72_SD_DETECT_N, "SD IRQ");
134 if (err)
135 goto err;
136 err = gpio_direction_input(GPIO_NR_PALMZ72_SD_DETECT_N);
137 if (err)
138 goto err2;
139 err = request_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N),
140 palmz72_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
141 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
142 "SD/MMC card detect", data);
143 if (err) {
144 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
145 __func__);
146 goto err2;
147 }
148
149 /* SD_POWER is not actually power, but it is more like chip
150 * select, i.e. it is inverted */
151
152 err = gpio_request(GPIO_NR_PALMZ72_SD_POWER_N, "SD_POWER");
153 if (err)
154 goto err3;
155 err = gpio_direction_output(GPIO_NR_PALMZ72_SD_POWER_N, 0);
156 if (err)
157 goto err4;
158 err = gpio_request(GPIO_NR_PALMZ72_SD_RO, "SD_RO");
159 if (err)
160 goto err4;
161 err = gpio_direction_input(GPIO_NR_PALMZ72_SD_RO);
162 if (err)
163 goto err5;
164
165 printk(KERN_DEBUG "%s: irq registered\n", __func__);
166
167 return 0;
168
169 err5:
170 gpio_free(GPIO_NR_PALMZ72_SD_RO);
171 err4:
172 gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
173 err3:
174 free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
175 err2:
176 gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
177 err:
178 return err;
179 }
180
181 static void palmz72_mci_exit(struct device *dev, void *data)
182 {
183 gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
184 free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
185 gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
186 gpio_free(GPIO_NR_PALMZ72_SD_RO);
187 }
188
189 static void palmz72_mci_power(struct device *dev, unsigned int vdd)
190 {
191 struct pxamci_platform_data *p_d = dev->platform_data;
192 if (p_d->ocr_mask & (1 << vdd))
193 gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N, 0);
194 else
195 gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N, 1);
196 }
197
198 static int palmz72_mci_ro(struct device *dev)
199 {
200 return gpio_get_value(GPIO_NR_PALMZ72_SD_RO);
201 }
202
203 static struct pxamci_platform_data palmz72_mci_platform_data = {
204 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
205 .setpower = palmz72_mci_power,
206 .get_ro = palmz72_mci_ro,
207 .init = palmz72_mci_init,
208 .exit = palmz72_mci_exit,
209 };
210
211 /******************************************************************************
212 * GPIO keyboard
213 ******************************************************************************/
214 static unsigned int palmz72_matrix_keys[] = {
215 KEY(0, 0, KEY_POWER),
216 KEY(0, 1, KEY_F1),
217 KEY(0, 2, KEY_ENTER),
218
219 KEY(1, 0, KEY_F2),
220 KEY(1, 1, KEY_F3),
221 KEY(1, 2, KEY_F4),
222
223 KEY(2, 0, KEY_UP),
224 KEY(2, 2, KEY_DOWN),
225
226 KEY(3, 0, KEY_RIGHT),
227 KEY(3, 2, KEY_LEFT),
228 };
229
230 static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
231 .matrix_key_rows = 4,
232 .matrix_key_cols = 3,
233 .matrix_key_map = palmz72_matrix_keys,
234 .matrix_key_map_size = ARRAY_SIZE(palmz72_matrix_keys),
235
236 .debounce_interval = 30,
237 };
238
239 /******************************************************************************
240 * Backlight
241 ******************************************************************************/
242 static int palmz72_backlight_init(struct device *dev)
243 {
244 int ret;
245
246 ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
247 if (ret)
248 goto err;
249 ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
250 if (ret)
251 goto err2;
252 ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
253 if (ret)
254 goto err2;
255 ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
256 if (ret)
257 goto err3;
258
259 return 0;
260 err3:
261 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
262 err2:
263 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
264 err:
265 return ret;
266 }
267
268 static int palmz72_backlight_notify(int brightness)
269 {
270 gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
271 gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
272 return brightness;
273 }
274
275 static void palmz72_backlight_exit(struct device *dev)
276 {
277 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
278 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
279 }
280
281 static struct platform_pwm_backlight_data palmz72_backlight_data = {
282 .pwm_id = 0,
283 .max_brightness = PALMZ72_MAX_INTENSITY,
284 .dft_brightness = PALMZ72_MAX_INTENSITY,
285 .pwm_period_ns = PALMZ72_PERIOD_NS,
286 .init = palmz72_backlight_init,
287 .notify = palmz72_backlight_notify,
288 .exit = palmz72_backlight_exit,
289 };
290
291 static struct platform_device palmz72_backlight = {
292 .name = "pwm-backlight",
293 .dev = {
294 .parent = &pxa27x_device_pwm0.dev,
295 .platform_data = &palmz72_backlight_data,
296 },
297 };
298
299 /******************************************************************************
300 * IrDA
301 ******************************************************************************/
302 static int palmz72_irda_startup(struct device *dev)
303 {
304 int err;
305 err = gpio_request(GPIO_NR_PALMZ72_IR_DISABLE, "IR DISABLE");
306 if (err)
307 goto err;
308 err = gpio_direction_output(GPIO_NR_PALMZ72_IR_DISABLE, 1);
309 if (err)
310 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
311 err:
312 return err;
313 }
314
315 static void palmz72_irda_shutdown(struct device *dev)
316 {
317 gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
318 }
319
320 static void palmz72_irda_transceiver_mode(struct device *dev, int mode)
321 {
322 gpio_set_value(GPIO_NR_PALMZ72_IR_DISABLE, mode & IR_OFF);
323 pxa2xx_transceiver_mode(dev, mode);
324 }
325
326 static struct pxaficp_platform_data palmz72_ficp_platform_data = {
327 .startup = palmz72_irda_startup,
328 .shutdown = palmz72_irda_shutdown,
329 .transceiver_cap = IR_SIRMODE | IR_OFF,
330 .transceiver_mode = palmz72_irda_transceiver_mode,
331 };
332
333 /******************************************************************************
334 * LEDs
335 ******************************************************************************/
336 static struct gpio_led gpio_leds[] = {
337 {
338 .name = "palmz72:green:led",
339 .default_trigger = "none",
340 .gpio = GPIO_NR_PALMZ72_LED_GREEN,
341 },
342 };
343
344 static struct gpio_led_platform_data gpio_led_info = {
345 .leds = gpio_leds,
346 .num_leds = ARRAY_SIZE(gpio_leds),
347 };
348
349 static struct platform_device palmz72_leds = {
350 .name = "leds-gpio",
351 .id = -1,
352 .dev = {
353 .platform_data = &gpio_led_info,
354 }
355 };
356
357 /******************************************************************************
358 * Power supply
359 ******************************************************************************/
360 static int power_supply_init(struct device *dev)
361 {
362 int ret;
363
364 ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
365 if (ret)
366 goto err1;
367 ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
368 if (ret)
369 goto err2;
370
371 ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
372 if (ret)
373 goto err2;
374 ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
375 if (ret)
376 goto err3;
377
378 return 0;
379 err3:
380 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
381 err2:
382 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
383 err1:
384 return ret;
385 }
386
387 static int palmz72_is_ac_online(void)
388 {
389 return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
390 }
391
392 static int palmz72_is_usb_online(void)
393 {
394 return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N);
395 }
396
397 static void power_supply_exit(struct device *dev)
398 {
399 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
400 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
401 }
402
403 static char *palmz72_supplicants[] = {
404 "main-battery",
405 };
406
407 static struct pda_power_pdata power_supply_info = {
408 .init = power_supply_init,
409 .is_ac_online = palmz72_is_ac_online,
410 .is_usb_online = palmz72_is_usb_online,
411 .exit = power_supply_exit,
412 .supplied_to = palmz72_supplicants,
413 .num_supplicants = ARRAY_SIZE(palmz72_supplicants),
414 };
415
416 static struct platform_device power_supply = {
417 .name = "pda-power",
418 .id = -1,
419 .dev = {
420 .platform_data = &power_supply_info,
421 },
422 };
423
424 /******************************************************************************
425 * Framebuffer
426 ******************************************************************************/
427 static struct pxafb_mode_info palmz72_lcd_modes[] = {
428 {
429 .pixclock = 115384,
430 .xres = 320,
431 .yres = 320,
432 .bpp = 16,
433
434 .left_margin = 27,
435 .right_margin = 7,
436 .upper_margin = 7,
437 .lower_margin = 8,
438
439 .hsync_len = 6,
440 .vsync_len = 1,
441 },
442 };
443
444 static struct pxafb_mach_info palmz72_lcd_screen = {
445 .modes = palmz72_lcd_modes,
446 .num_modes = ARRAY_SIZE(palmz72_lcd_modes),
447 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
448 };
449
450 #ifdef CONFIG_PM
451
452 /* We have some black magic here
453 * PalmOS ROM on recover expects special struct physical address
454 * to be transferred via PSPR. Using this struct PalmOS restores
455 * its state after sleep. As for Linux, we need to setup it the
456 * same way. More than that, PalmOS ROM changes some values in memory.
457 * For now only one location is found, which needs special treatment.
458 * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
459 * for reading backtraces for me :)
460 */
461
462 #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
463
464 static struct palmz72_resume_info palmz72_resume_info = {
465 .magic0 = 0xb4e6,
466 .magic1 = 1,
467
468 /* reset state, MMU off etc */
469 .arm_control = 0,
470 .aux_control = 0,
471 .ttb = 0,
472 .domain_access = 0,
473 .process_id = 0,
474 };
475
476 static unsigned long store_ptr;
477
478 /* sys_device for Palm Zire 72 PM */
479
480 static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
481 {
482 /* setup the resume_info struct for the original bootloader */
483 palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume;
484
485 /* Storing memory touched by ROM */
486 store_ptr = *PALMZ72_SAVE_DWORD;
487
488 /* Setting PSPR to a proper value */
489 PSPR = virt_to_phys(&palmz72_resume_info);
490
491 return 0;
492 }
493
494 static int palmz72_pm_resume(struct sys_device *dev)
495 {
496 *PALMZ72_SAVE_DWORD = store_ptr;
497 return 0;
498 }
499
500 static struct sysdev_class palmz72_pm_sysclass = {
501 .name = "palmz72_pm",
502 .suspend = palmz72_pm_suspend,
503 .resume = palmz72_pm_resume,
504 };
505
506 static struct sys_device palmz72_pm_device = {
507 .cls = &palmz72_pm_sysclass,
508 };
509
510 static int __init palmz72_pm_init(void)
511 {
512 int ret = -ENODEV;
513 if (machine_is_palmz72()) {
514 ret = sysdev_class_register(&palmz72_pm_sysclass);
515 if (ret == 0)
516 ret = sysdev_register(&palmz72_pm_device);
517 }
518 return ret;
519 }
520
521 device_initcall(palmz72_pm_init);
522 #endif
523
524 /******************************************************************************
525 * Machine init
526 ******************************************************************************/
527 static struct platform_device *devices[] __initdata = {
528 &palmz72_backlight,
529 &palmz72_leds,
530 &power_supply,
531 };
532
533 static void __init palmz72_init(void)
534 {
535 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
536 set_pxa_fb_info(&palmz72_lcd_screen);
537 pxa_set_mci_info(&palmz72_mci_platform_data);
538 pxa_set_ac97_info(NULL);
539 pxa_set_ficp_info(&palmz72_ficp_platform_data);
540 pxa_set_keypad_info(&palmz72_keypad_platform_data);
541 platform_add_devices(devices, ARRAY_SIZE(devices));
542 }
543
544 MACHINE_START(PALMZ72, "Palm Zire72")
545 .phys_io = 0x40000000,
546 .io_pg_offst = io_p2v(0x40000000),
547 .boot_params = 0xa0000100,
548 .map_io = pxa_map_io,
549 .init_irq = pxa27x_init_irq,
550 .timer = &pxa_timer,
551 .init_machine = palmz72_init
552 MACHINE_END
This page took 0.058504 seconds and 5 git commands to generate.