b3ae8b958ad6b661a46ae018603097b670df2558
[linux-2.6.git] / arch / arm / mach-pxa / palmld.c
1 /*
2  * Hardware definitions for Palm LifeDrive
3  *
4  * Author:     Marek Vasut <marek.vasut@gmail.com>
5  *
6  * Based on work of:
7  *              Alex Osborne <ato@meshy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  *
13  * (find more info at www.hackndev.com)
14  *
15  */
16
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/irq.h>
20 #include <linux/gpio_keys.h>
21 #include <linux/input.h>
22 #include <linux/pda_power.h>
23 #include <linux/pwm_backlight.h>
24 #include <linux/gpio.h>
25 #include <linux/wm97xx_batt.h>
26 #include <linux/power_supply.h>
27 #include <linux/sysdev.h>
28 #include <linux/mtd/mtd.h>
29 #include <linux/mtd/partitions.h>
30 #include <linux/mtd/physmap.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/palmld.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/palmasoc.h>
44
45 #include "generic.h"
46 #include "devices.h"
47
48 /******************************************************************************
49  * Pin configuration
50  ******************************************************************************/
51 static unsigned long palmld_pin_config[] __initdata = {
52         /* MMC */
53         GPIO32_MMC_CLK,
54         GPIO92_MMC_DAT_0,
55         GPIO109_MMC_DAT_1,
56         GPIO110_MMC_DAT_2,
57         GPIO111_MMC_DAT_3,
58         GPIO112_MMC_CMD,
59         GPIO14_GPIO,    /* SD detect */
60         GPIO114_GPIO,   /* SD power */
61         GPIO116_GPIO,   /* SD r/o switch */
62
63         /* AC97 */
64         GPIO28_AC97_BITCLK,
65         GPIO29_AC97_SDATA_IN_0,
66         GPIO30_AC97_SDATA_OUT,
67         GPIO31_AC97_SYNC,
68         GPIO89_AC97_SYSCLK,
69         GPIO95_AC97_nRESET,
70
71         /* IrDA */
72         GPIO108_GPIO,   /* ir disable */
73         GPIO46_FICP_RXD,
74         GPIO47_FICP_TXD,
75
76         /* MATRIX KEYPAD */
77         GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
78         GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
79         GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
80         GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
81         GPIO103_KP_MKOUT_0,
82         GPIO104_KP_MKOUT_1,
83         GPIO105_KP_MKOUT_2,
84
85         /* LCD */
86         GPIO58_LCD_LDD_0,
87         GPIO59_LCD_LDD_1,
88         GPIO60_LCD_LDD_2,
89         GPIO61_LCD_LDD_3,
90         GPIO62_LCD_LDD_4,
91         GPIO63_LCD_LDD_5,
92         GPIO64_LCD_LDD_6,
93         GPIO65_LCD_LDD_7,
94         GPIO66_LCD_LDD_8,
95         GPIO67_LCD_LDD_9,
96         GPIO68_LCD_LDD_10,
97         GPIO69_LCD_LDD_11,
98         GPIO70_LCD_LDD_12,
99         GPIO71_LCD_LDD_13,
100         GPIO72_LCD_LDD_14,
101         GPIO73_LCD_LDD_15,
102         GPIO74_LCD_FCLK,
103         GPIO75_LCD_LCLK,
104         GPIO76_LCD_PCLK,
105         GPIO77_LCD_BIAS,
106
107         /* PWM */
108         GPIO16_PWM0_OUT,
109
110         /* GPIO KEYS */
111         GPIO10_GPIO,    /* hotsync button */
112         GPIO12_GPIO,    /* power switch */
113         GPIO15_GPIO,    /* lock switch */
114
115         /* LEDs */
116         GPIO52_GPIO,    /* green led */
117         GPIO94_GPIO,    /* orange led */
118
119         /* PCMCIA */
120         GPIO48_nPOE,
121         GPIO49_nPWE,
122         GPIO50_nPIOR,
123         GPIO51_nPIOW,
124         GPIO85_nPCE_1,
125         GPIO54_nPCE_2,
126         GPIO79_PSKTSEL,
127         GPIO55_nPREG,
128         GPIO56_nPWAIT,
129         GPIO57_nIOIS16,
130         GPIO36_GPIO,    /* wifi power */
131         GPIO38_GPIO,    /* wifi ready */
132         GPIO81_GPIO,    /* wifi reset */
133
134         /* FFUART */
135         GPIO34_FFUART_RXD,
136         GPIO39_FFUART_TXD,
137
138         /* HDD */
139         GPIO98_GPIO,    /* HDD reset */
140         GPIO115_GPIO,   /* HDD power */
141
142         /* MISC */
143         GPIO13_GPIO,    /* earphone detect */
144 };
145
146 /******************************************************************************
147  * NOR Flash
148  ******************************************************************************/
149 static struct mtd_partition palmld_partitions[] = {
150         {
151                 .name           = "Flash",
152                 .offset         = 0x00000000,
153                 .size           = MTDPART_SIZ_FULL,
154                 .mask_flags     = 0
155         }
156 };
157
158 static struct physmap_flash_data palmld_flash_data[] = {
159         {
160                 .width          = 2,                    /* bankwidth in bytes */
161                 .parts          = palmld_partitions,
162                 .nr_parts       = ARRAY_SIZE(palmld_partitions)
163         }
164 };
165
166 static struct resource palmld_flash_resource = {
167         .start  = PXA_CS0_PHYS,
168         .end    = PXA_CS0_PHYS + SZ_4M - 1,
169         .flags  = IORESOURCE_MEM,
170 };
171
172 static struct platform_device palmld_flash = {
173         .name           = "physmap-flash",
174         .id             = 0,
175         .resource       = &palmld_flash_resource,
176         .num_resources  = 1,
177         .dev            = {
178                 .platform_data = palmld_flash_data,
179         },
180 };
181
182 /******************************************************************************
183  * SD/MMC card controller
184  ******************************************************************************/
185 static struct pxamci_platform_data palmld_mci_platform_data = {
186         .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
187         .gpio_card_detect       = GPIO_NR_PALMLD_SD_DETECT_N,
188         .gpio_card_ro           = GPIO_NR_PALMLD_SD_READONLY,
189         .gpio_power             = GPIO_NR_PALMLD_SD_POWER,
190         .detect_delay           = 20,
191 };
192
193 /******************************************************************************
194  * GPIO keyboard
195  ******************************************************************************/
196 static unsigned int palmld_matrix_keys[] = {
197         KEY(0, 1, KEY_F2),
198         KEY(0, 2, KEY_UP),
199
200         KEY(1, 0, KEY_F3),
201         KEY(1, 1, KEY_F4),
202         KEY(1, 2, KEY_RIGHT),
203
204         KEY(2, 0, KEY_F1),
205         KEY(2, 1, KEY_F5),
206         KEY(2, 2, KEY_DOWN),
207
208         KEY(3, 0, KEY_F6),
209         KEY(3, 1, KEY_ENTER),
210         KEY(3, 2, KEY_LEFT),
211 };
212
213 static struct pxa27x_keypad_platform_data palmld_keypad_platform_data = {
214         .matrix_key_rows        = 4,
215         .matrix_key_cols        = 3,
216         .matrix_key_map         = palmld_matrix_keys,
217         .matrix_key_map_size    = ARRAY_SIZE(palmld_matrix_keys),
218
219         .debounce_interval      = 30,
220 };
221
222 /******************************************************************************
223  * GPIO keys
224  ******************************************************************************/
225 static struct gpio_keys_button palmld_pxa_buttons[] = {
226         {KEY_F8, GPIO_NR_PALMLD_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
227         {KEY_F9, GPIO_NR_PALMLD_LOCK_SWITCH, 0, "Lock Switch" },
228         {KEY_POWER, GPIO_NR_PALMLD_POWER_SWITCH, 0, "Power Switch" },
229 };
230
231 static struct gpio_keys_platform_data palmld_pxa_keys_data = {
232         .buttons        = palmld_pxa_buttons,
233         .nbuttons       = ARRAY_SIZE(palmld_pxa_buttons),
234 };
235
236 static struct platform_device palmld_pxa_keys = {
237         .name   = "gpio-keys",
238         .id     = -1,
239         .dev    = {
240                 .platform_data = &palmld_pxa_keys_data,
241         },
242 };
243
244 /******************************************************************************
245  * Backlight
246  ******************************************************************************/
247 static int palmld_backlight_init(struct device *dev)
248 {
249         int ret;
250
251         ret = gpio_request(GPIO_NR_PALMLD_BL_POWER, "BL POWER");
252         if (ret)
253                 goto err;
254         ret = gpio_direction_output(GPIO_NR_PALMLD_BL_POWER, 0);
255         if (ret)
256                 goto err2;
257         ret = gpio_request(GPIO_NR_PALMLD_LCD_POWER, "LCD POWER");
258         if (ret)
259                 goto err2;
260         ret = gpio_direction_output(GPIO_NR_PALMLD_LCD_POWER, 0);
261         if (ret)
262                 goto err3;
263
264         return 0;
265 err3:
266         gpio_free(GPIO_NR_PALMLD_LCD_POWER);
267 err2:
268         gpio_free(GPIO_NR_PALMLD_BL_POWER);
269 err:
270         return ret;
271 }
272
273 static int palmld_backlight_notify(int brightness)
274 {
275         gpio_set_value(GPIO_NR_PALMLD_BL_POWER, brightness);
276         gpio_set_value(GPIO_NR_PALMLD_LCD_POWER, brightness);
277         return brightness;
278 }
279
280 static void palmld_backlight_exit(struct device *dev)
281 {
282         gpio_free(GPIO_NR_PALMLD_BL_POWER);
283         gpio_free(GPIO_NR_PALMLD_LCD_POWER);
284 }
285
286 static struct platform_pwm_backlight_data palmld_backlight_data = {
287         .pwm_id         = 0,
288         .max_brightness = PALMLD_MAX_INTENSITY,
289         .dft_brightness = PALMLD_MAX_INTENSITY,
290         .pwm_period_ns  = PALMLD_PERIOD_NS,
291         .init           = palmld_backlight_init,
292         .notify         = palmld_backlight_notify,
293         .exit           = palmld_backlight_exit,
294 };
295
296 static struct platform_device palmld_backlight = {
297         .name   = "pwm-backlight",
298         .dev    = {
299                 .parent         = &pxa27x_device_pwm0.dev,
300                 .platform_data  = &palmld_backlight_data,
301         },
302 };
303
304 /******************************************************************************
305  * IrDA
306  ******************************************************************************/
307 static int palmld_irda_startup(struct device *dev)
308 {
309         int err;
310         err = gpio_request(GPIO_NR_PALMLD_IR_DISABLE, "IR DISABLE");
311         if (err)
312                 goto err;
313         err = gpio_direction_output(GPIO_NR_PALMLD_IR_DISABLE, 1);
314         if (err)
315                 gpio_free(GPIO_NR_PALMLD_IR_DISABLE);
316 err:
317         return err;
318 }
319
320 static void palmld_irda_shutdown(struct device *dev)
321 {
322         gpio_free(GPIO_NR_PALMLD_IR_DISABLE);
323 }
324
325 static void palmld_irda_transceiver_mode(struct device *dev, int mode)
326 {
327         gpio_set_value(GPIO_NR_PALMLD_IR_DISABLE, mode & IR_OFF);
328         pxa2xx_transceiver_mode(dev, mode);
329 }
330
331 static struct pxaficp_platform_data palmld_ficp_platform_data = {
332         .startup                = palmld_irda_startup,
333         .shutdown               = palmld_irda_shutdown,
334         .transceiver_cap        = IR_SIRMODE | IR_FIRMODE | IR_OFF,
335         .transceiver_mode       = palmld_irda_transceiver_mode,
336 };
337
338 /******************************************************************************
339  * LEDs
340  ******************************************************************************/
341 struct gpio_led gpio_leds[] = {
342 {
343         .name                   = "palmld:green:led",
344         .default_trigger        = "none",
345         .gpio                   = GPIO_NR_PALMLD_LED_GREEN,
346 }, {
347         .name                   = "palmld:amber:led",
348         .default_trigger        = "none",
349         .gpio                   = GPIO_NR_PALMLD_LED_AMBER,
350 },
351 };
352
353 static struct gpio_led_platform_data gpio_led_info = {
354         .leds           = gpio_leds,
355         .num_leds       = ARRAY_SIZE(gpio_leds),
356 };
357
358 static struct platform_device palmld_leds = {
359         .name   = "leds-gpio",
360         .id     = -1,
361         .dev    = {
362                 .platform_data  = &gpio_led_info,
363         }
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_PALMLD_POWER_DETECT, "CABLE_STATE_AC");
374         if (ret)
375                 goto err1;
376         ret = gpio_direction_input(GPIO_NR_PALMLD_POWER_DETECT);
377         if (ret)
378                 goto err2;
379
380         ret = gpio_request(GPIO_NR_PALMLD_USB_DETECT_N, "CABLE_STATE_USB");
381         if (ret)
382                 goto err2;
383         ret = gpio_direction_input(GPIO_NR_PALMLD_USB_DETECT_N);
384         if (ret)
385                 goto err3;
386
387         return 0;
388
389 err3:
390         gpio_free(GPIO_NR_PALMLD_USB_DETECT_N);
391 err2:
392         gpio_free(GPIO_NR_PALMLD_POWER_DETECT);
393 err1:
394         return ret;
395 }
396
397 static int palmld_is_ac_online(void)
398 {
399         return gpio_get_value(GPIO_NR_PALMLD_POWER_DETECT);
400 }
401
402 static int palmld_is_usb_online(void)
403 {
404         return !gpio_get_value(GPIO_NR_PALMLD_USB_DETECT_N);
405 }
406
407 static void power_supply_exit(struct device *dev)
408 {
409         gpio_free(GPIO_NR_PALMLD_USB_DETECT_N);
410         gpio_free(GPIO_NR_PALMLD_POWER_DETECT);
411 }
412
413 static char *palmld_supplicants[] = {
414         "main-battery",
415 };
416
417 static struct pda_power_pdata power_supply_info = {
418         .init            = power_supply_init,
419         .is_ac_online    = palmld_is_ac_online,
420         .is_usb_online   = palmld_is_usb_online,
421         .exit            = power_supply_exit,
422         .supplied_to     = palmld_supplicants,
423         .num_supplicants = ARRAY_SIZE(palmld_supplicants),
424 };
425
426 static struct platform_device power_supply = {
427         .name = "pda-power",
428         .id   = -1,
429         .dev  = {
430                 .platform_data = &power_supply_info,
431         },
432 };
433
434 /******************************************************************************
435  * WM97xx battery
436  ******************************************************************************/
437 static struct wm97xx_batt_info wm97xx_batt_pdata = {
438         .batt_aux       = WM97XX_AUX_ID3,
439         .temp_aux       = WM97XX_AUX_ID2,
440         .charge_gpio    = -1,
441         .max_voltage    = PALMLD_BAT_MAX_VOLTAGE,
442         .min_voltage    = PALMLD_BAT_MIN_VOLTAGE,
443         .batt_mult      = 1000,
444         .batt_div       = 414,
445         .temp_mult      = 1,
446         .temp_div       = 1,
447         .batt_tech      = POWER_SUPPLY_TECHNOLOGY_LIPO,
448         .batt_name      = "main-batt",
449 };
450
451 /******************************************************************************
452  * aSoC audio
453  ******************************************************************************/
454 static struct palm27x_asoc_info palmld_asoc_pdata = {
455         .jack_gpio      = GPIO_NR_PALMLD_EARPHONE_DETECT,
456 };
457
458 static pxa2xx_audio_ops_t palmld_ac97_pdata = {
459         .reset_gpio     = 95,
460 };
461
462 static struct platform_device palmld_asoc = {
463         .name = "palm27x-asoc",
464         .id   = -1,
465         .dev  = {
466                 .platform_data = &palmld_asoc_pdata,
467         },
468 };
469
470 /******************************************************************************
471  * HDD
472  ******************************************************************************/
473 static struct platform_device palmld_hdd = {
474         .name   = "pata_palmld",
475         .id     = -1,
476 };
477
478 /******************************************************************************
479  * Framebuffer
480  ******************************************************************************/
481 static struct pxafb_mode_info palmld_lcd_modes[] = {
482 {
483         .pixclock       = 57692,
484         .xres           = 320,
485         .yres           = 480,
486         .bpp            = 16,
487
488         .left_margin    = 32,
489         .right_margin   = 1,
490         .upper_margin   = 7,
491         .lower_margin   = 1,
492
493         .hsync_len      = 4,
494         .vsync_len      = 1,
495 },
496 };
497
498 static struct pxafb_mach_info palmld_lcd_screen = {
499         .modes          = palmld_lcd_modes,
500         .num_modes      = ARRAY_SIZE(palmld_lcd_modes),
501         .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
502 };
503
504 /******************************************************************************
505  * Power management - standby
506  ******************************************************************************/
507 static void __init palmld_pm_init(void)
508 {
509         static u32 resume[] = {
510                 0xe3a00101,     /* mov  r0,     #0x40000000 */
511                 0xe380060f,     /* orr  r0, r0, #0x00f00000 */
512                 0xe590f008,     /* ldr  pc, [r0, #0x08] */
513         };
514
515         /* copy the bootloader */
516         memcpy(phys_to_virt(PALMLD_STR_BASE), resume, sizeof(resume));
517 }
518
519 /******************************************************************************
520  * Machine init
521  ******************************************************************************/
522 static struct platform_device *devices[] __initdata = {
523 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
524         &palmld_pxa_keys,
525 #endif
526         &palmld_backlight,
527         &palmld_leds,
528         &power_supply,
529         &palmld_asoc,
530         &palmld_hdd,
531         &palmld_flash,
532 };
533
534 static struct map_desc palmld_io_desc[] __initdata = {
535 {
536         .virtual        = PALMLD_IDE_VIRT,
537         .pfn            = __phys_to_pfn(PALMLD_IDE_PHYS),
538         .length         = PALMLD_IDE_SIZE,
539         .type           = MT_DEVICE
540 },
541 {
542         .virtual        = PALMLD_USB_VIRT,
543         .pfn            = __phys_to_pfn(PALMLD_USB_PHYS),
544         .length         = PALMLD_USB_SIZE,
545         .type           = MT_DEVICE
546 },
547 };
548
549 static void __init palmld_map_io(void)
550 {
551         pxa_map_io();
552         iotable_init(palmld_io_desc, ARRAY_SIZE(palmld_io_desc));
553 }
554
555 static void __init palmld_init(void)
556 {
557         pxa2xx_mfp_config(ARRAY_AND_SIZE(palmld_pin_config));
558
559         palmld_pm_init();
560         set_pxa_fb_info(&palmld_lcd_screen);
561         pxa_set_mci_info(&palmld_mci_platform_data);
562         pxa_set_ac97_info(&palmld_ac97_pdata);
563         pxa_set_ficp_info(&palmld_ficp_platform_data);
564         pxa_set_keypad_info(&palmld_keypad_platform_data);
565         wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
566
567         platform_add_devices(devices, ARRAY_SIZE(devices));
568 }
569
570 MACHINE_START(PALMLD, "Palm LifeDrive")
571         .phys_io        = PALMLD_PHYS_IO_START,
572         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
573         .boot_params    = 0xa0000100,
574         .map_io         = palmld_map_io,
575         .init_irq       = pxa27x_init_irq,
576         .timer          = &pxa_timer,
577         .init_machine   = palmld_init
578 MACHINE_END