Merge branch 'copy_user' of git://git.marvell.com/orion into devel
[platform/adaptation/renesas_rcar/renesas_kernel.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
29 #include <asm/mach-types.h>
30 #include <asm/mach/arch.h>
31 #include <asm/mach/map.h>
32
33 #include <mach/pxa27x.h>
34 #include <mach/audio.h>
35 #include <mach/palmld.h>
36 #include <mach/mmc.h>
37 #include <mach/pxafb.h>
38 #include <mach/irda.h>
39 #include <mach/pxa27x_keypad.h>
40 #include <mach/palmasoc.h>
41
42 #include "generic.h"
43 #include "devices.h"
44
45 /******************************************************************************
46  * Pin configuration
47  ******************************************************************************/
48 static unsigned long palmld_pin_config[] __initdata = {
49         /* MMC */
50         GPIO32_MMC_CLK,
51         GPIO92_MMC_DAT_0,
52         GPIO109_MMC_DAT_1,
53         GPIO110_MMC_DAT_2,
54         GPIO111_MMC_DAT_3,
55         GPIO112_MMC_CMD,
56         GPIO14_GPIO,    /* SD detect */
57         GPIO114_GPIO,   /* SD power */
58         GPIO116_GPIO,   /* SD r/o switch */
59
60         /* AC97 */
61         GPIO28_AC97_BITCLK,
62         GPIO29_AC97_SDATA_IN_0,
63         GPIO30_AC97_SDATA_OUT,
64         GPIO31_AC97_SYNC,
65         GPIO89_AC97_SYSCLK,
66         GPIO95_AC97_nRESET,
67
68         /* IrDA */
69         GPIO108_GPIO,   /* ir disable */
70         GPIO46_FICP_RXD,
71         GPIO47_FICP_TXD,
72
73         /* MATRIX KEYPAD */
74         GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
75         GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
76         GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
77         GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
78         GPIO103_KP_MKOUT_0,
79         GPIO104_KP_MKOUT_1,
80         GPIO105_KP_MKOUT_2,
81
82         /* LCD */
83         GPIO58_LCD_LDD_0,
84         GPIO59_LCD_LDD_1,
85         GPIO60_LCD_LDD_2,
86         GPIO61_LCD_LDD_3,
87         GPIO62_LCD_LDD_4,
88         GPIO63_LCD_LDD_5,
89         GPIO64_LCD_LDD_6,
90         GPIO65_LCD_LDD_7,
91         GPIO66_LCD_LDD_8,
92         GPIO67_LCD_LDD_9,
93         GPIO68_LCD_LDD_10,
94         GPIO69_LCD_LDD_11,
95         GPIO70_LCD_LDD_12,
96         GPIO71_LCD_LDD_13,
97         GPIO72_LCD_LDD_14,
98         GPIO73_LCD_LDD_15,
99         GPIO74_LCD_FCLK,
100         GPIO75_LCD_LCLK,
101         GPIO76_LCD_PCLK,
102         GPIO77_LCD_BIAS,
103
104         /* PWM */
105         GPIO16_PWM0_OUT,
106
107         /* GPIO KEYS */
108         GPIO10_GPIO,    /* hotsync button */
109         GPIO12_GPIO,    /* power switch */
110         GPIO15_GPIO,    /* lock switch */
111
112         /* LEDs */
113         GPIO52_GPIO,    /* green led */
114         GPIO94_GPIO,    /* orange led */
115
116         /* PCMCIA */
117         GPIO48_nPOE,
118         GPIO49_nPWE,
119         GPIO50_nPIOR,
120         GPIO51_nPIOW,
121         GPIO85_nPCE_1,
122         GPIO54_nPCE_2,
123         GPIO79_PSKTSEL,
124         GPIO55_nPREG,
125         GPIO56_nPWAIT,
126         GPIO57_nIOIS16,
127         GPIO36_GPIO,    /* wifi power */
128         GPIO38_GPIO,    /* wifi ready */
129         GPIO81_GPIO,    /* wifi reset */
130
131         /* HDD */
132         GPIO98_GPIO,    /* HDD reset */
133         GPIO115_GPIO,   /* HDD power */
134
135         /* MISC */
136         GPIO13_GPIO,    /* earphone detect */
137 };
138
139 /******************************************************************************
140  * SD/MMC card controller
141  ******************************************************************************/
142 static int palmld_mci_init(struct device *dev, irq_handler_t palmld_detect_int,
143                                 void *data)
144 {
145         int err = 0;
146
147         /* Setup an interrupt for detecting card insert/remove events */
148         err = gpio_request(GPIO_NR_PALMLD_SD_DETECT_N, "SD IRQ");
149         if (err)
150                 goto err;
151         err = gpio_direction_input(GPIO_NR_PALMLD_SD_DETECT_N);
152         if (err)
153                 goto err2;
154         err = request_irq(gpio_to_irq(GPIO_NR_PALMLD_SD_DETECT_N),
155                         palmld_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
156                         IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
157                         "SD/MMC card detect", data);
158         if (err) {
159                 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
160                                 __func__);
161                 goto err2;
162         }
163
164         err = gpio_request(GPIO_NR_PALMLD_SD_POWER, "SD_POWER");
165         if (err)
166                 goto err3;
167         err = gpio_direction_output(GPIO_NR_PALMLD_SD_POWER, 0);
168         if (err)
169                 goto err4;
170
171         err = gpio_request(GPIO_NR_PALMLD_SD_READONLY, "SD_READONLY");
172         if (err)
173                 goto err4;
174         err = gpio_direction_input(GPIO_NR_PALMLD_SD_READONLY);
175         if (err)
176                 goto err5;
177
178         printk(KERN_DEBUG "%s: irq registered\n", __func__);
179
180         return 0;
181
182 err5:
183         gpio_free(GPIO_NR_PALMLD_SD_READONLY);
184 err4:
185         gpio_free(GPIO_NR_PALMLD_SD_POWER);
186 err3:
187         free_irq(gpio_to_irq(GPIO_NR_PALMLD_SD_DETECT_N), data);
188 err2:
189         gpio_free(GPIO_NR_PALMLD_SD_DETECT_N);
190 err:
191         return err;
192 }
193
194 static void palmld_mci_exit(struct device *dev, void *data)
195 {
196         gpio_free(GPIO_NR_PALMLD_SD_READONLY);
197         gpio_free(GPIO_NR_PALMLD_SD_POWER);
198         free_irq(gpio_to_irq(GPIO_NR_PALMLD_SD_DETECT_N), data);
199         gpio_free(GPIO_NR_PALMLD_SD_DETECT_N);
200 }
201
202 static void palmld_mci_power(struct device *dev, unsigned int vdd)
203 {
204         struct pxamci_platform_data *p_d = dev->platform_data;
205         gpio_set_value(GPIO_NR_PALMLD_SD_POWER, p_d->ocr_mask & (1 << vdd));
206 }
207
208 static int palmld_mci_get_ro(struct device *dev)
209 {
210         return gpio_get_value(GPIO_NR_PALMLD_SD_READONLY);
211 }
212
213 static struct pxamci_platform_data palmld_mci_platform_data = {
214         .ocr_mask       = MMC_VDD_32_33 | MMC_VDD_33_34,
215         .setpower       = palmld_mci_power,
216         .get_ro         = palmld_mci_get_ro,
217         .init           = palmld_mci_init,
218         .exit           = palmld_mci_exit,
219 };
220
221 /******************************************************************************
222  * GPIO keyboard
223  ******************************************************************************/
224 static unsigned int palmld_matrix_keys[] = {
225         KEY(0, 1, KEY_F2),
226         KEY(0, 2, KEY_UP),
227
228         KEY(1, 0, KEY_F3),
229         KEY(1, 1, KEY_F4),
230         KEY(1, 2, KEY_RIGHT),
231
232         KEY(2, 0, KEY_F1),
233         KEY(2, 1, KEY_F5),
234         KEY(2, 2, KEY_DOWN),
235
236         KEY(3, 0, KEY_F6),
237         KEY(3, 1, KEY_ENTER),
238         KEY(3, 2, KEY_LEFT),
239 };
240
241 static struct pxa27x_keypad_platform_data palmld_keypad_platform_data = {
242         .matrix_key_rows        = 4,
243         .matrix_key_cols        = 3,
244         .matrix_key_map         = palmld_matrix_keys,
245         .matrix_key_map_size    = ARRAY_SIZE(palmld_matrix_keys),
246
247         .debounce_interval      = 30,
248 };
249
250 /******************************************************************************
251  * GPIO keys
252  ******************************************************************************/
253 static struct gpio_keys_button palmld_pxa_buttons[] = {
254         {KEY_F8, GPIO_NR_PALMLD_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
255         {KEY_F9, GPIO_NR_PALMLD_LOCK_SWITCH, 0, "Lock Switch" },
256         {KEY_POWER, GPIO_NR_PALMLD_POWER_SWITCH, 0, "Power Switch" },
257 };
258
259 static struct gpio_keys_platform_data palmld_pxa_keys_data = {
260         .buttons        = palmld_pxa_buttons,
261         .nbuttons       = ARRAY_SIZE(palmld_pxa_buttons),
262 };
263
264 static struct platform_device palmld_pxa_keys = {
265         .name   = "gpio-keys",
266         .id     = -1,
267         .dev    = {
268                 .platform_data = &palmld_pxa_keys_data,
269         },
270 };
271
272 /******************************************************************************
273  * Backlight
274  ******************************************************************************/
275 static int palmld_backlight_init(struct device *dev)
276 {
277         int ret;
278
279         ret = gpio_request(GPIO_NR_PALMLD_BL_POWER, "BL POWER");
280         if (ret)
281                 goto err;
282         ret = gpio_direction_output(GPIO_NR_PALMLD_BL_POWER, 0);
283         if (ret)
284                 goto err2;
285         ret = gpio_request(GPIO_NR_PALMLD_LCD_POWER, "LCD POWER");
286         if (ret)
287                 goto err2;
288         ret = gpio_direction_output(GPIO_NR_PALMLD_LCD_POWER, 0);
289         if (ret)
290                 goto err3;
291
292         return 0;
293 err3:
294         gpio_free(GPIO_NR_PALMLD_LCD_POWER);
295 err2:
296         gpio_free(GPIO_NR_PALMLD_BL_POWER);
297 err:
298         return ret;
299 }
300
301 static int palmld_backlight_notify(int brightness)
302 {
303         gpio_set_value(GPIO_NR_PALMLD_BL_POWER, brightness);
304         gpio_set_value(GPIO_NR_PALMLD_LCD_POWER, brightness);
305         return brightness;
306 }
307
308 static void palmld_backlight_exit(struct device *dev)
309 {
310         gpio_free(GPIO_NR_PALMLD_BL_POWER);
311         gpio_free(GPIO_NR_PALMLD_LCD_POWER);
312 }
313
314 static struct platform_pwm_backlight_data palmld_backlight_data = {
315         .pwm_id         = 0,
316         .max_brightness = PALMLD_MAX_INTENSITY,
317         .dft_brightness = PALMLD_MAX_INTENSITY,
318         .pwm_period_ns  = PALMLD_PERIOD_NS,
319         .init           = palmld_backlight_init,
320         .notify         = palmld_backlight_notify,
321         .exit           = palmld_backlight_exit,
322 };
323
324 static struct platform_device palmld_backlight = {
325         .name   = "pwm-backlight",
326         .dev    = {
327                 .parent         = &pxa27x_device_pwm0.dev,
328                 .platform_data  = &palmld_backlight_data,
329         },
330 };
331
332 /******************************************************************************
333  * IrDA
334  ******************************************************************************/
335 static int palmld_irda_startup(struct device *dev)
336 {
337         int err;
338         err = gpio_request(GPIO_NR_PALMLD_IR_DISABLE, "IR DISABLE");
339         if (err)
340                 goto err;
341         err = gpio_direction_output(GPIO_NR_PALMLD_IR_DISABLE, 1);
342         if (err)
343                 gpio_free(GPIO_NR_PALMLD_IR_DISABLE);
344 err:
345         return err;
346 }
347
348 static void palmld_irda_shutdown(struct device *dev)
349 {
350         gpio_free(GPIO_NR_PALMLD_IR_DISABLE);
351 }
352
353 static void palmld_irda_transceiver_mode(struct device *dev, int mode)
354 {
355         gpio_set_value(GPIO_NR_PALMLD_IR_DISABLE, mode & IR_OFF);
356         pxa2xx_transceiver_mode(dev, mode);
357 }
358
359 static struct pxaficp_platform_data palmld_ficp_platform_data = {
360         .startup                = palmld_irda_startup,
361         .shutdown               = palmld_irda_shutdown,
362         .transceiver_cap        = IR_SIRMODE | IR_FIRMODE | IR_OFF,
363         .transceiver_mode       = palmld_irda_transceiver_mode,
364 };
365
366 /******************************************************************************
367  * LEDs
368  ******************************************************************************/
369 struct gpio_led gpio_leds[] = {
370 {
371         .name                   = "palmld:green:led",
372         .default_trigger        = "none",
373         .gpio                   = GPIO_NR_PALMLD_LED_GREEN,
374 }, {
375         .name                   = "palmld:amber:led",
376         .default_trigger        = "none",
377         .gpio                   = GPIO_NR_PALMLD_LED_AMBER,
378 },
379 };
380
381 static struct gpio_led_platform_data gpio_led_info = {
382         .leds           = gpio_leds,
383         .num_leds       = ARRAY_SIZE(gpio_leds),
384 };
385
386 static struct platform_device palmld_leds = {
387         .name   = "leds-gpio",
388         .id     = -1,
389         .dev    = {
390                 .platform_data  = &gpio_led_info,
391         }
392 };
393
394 /******************************************************************************
395  * Power supply
396  ******************************************************************************/
397 static int power_supply_init(struct device *dev)
398 {
399         int ret;
400
401         ret = gpio_request(GPIO_NR_PALMLD_POWER_DETECT, "CABLE_STATE_AC");
402         if (ret)
403                 goto err1;
404         ret = gpio_direction_input(GPIO_NR_PALMLD_POWER_DETECT);
405         if (ret)
406                 goto err2;
407
408         ret = gpio_request(GPIO_NR_PALMLD_USB_DETECT_N, "CABLE_STATE_USB");
409         if (ret)
410                 goto err2;
411         ret = gpio_direction_input(GPIO_NR_PALMLD_USB_DETECT_N);
412         if (ret)
413                 goto err3;
414
415         return 0;
416
417 err3:
418         gpio_free(GPIO_NR_PALMLD_USB_DETECT_N);
419 err2:
420         gpio_free(GPIO_NR_PALMLD_POWER_DETECT);
421 err1:
422         return ret;
423 }
424
425 static int palmld_is_ac_online(void)
426 {
427         return gpio_get_value(GPIO_NR_PALMLD_POWER_DETECT);
428 }
429
430 static int palmld_is_usb_online(void)
431 {
432         return !gpio_get_value(GPIO_NR_PALMLD_USB_DETECT_N);
433 }
434
435 static void power_supply_exit(struct device *dev)
436 {
437         gpio_free(GPIO_NR_PALMLD_USB_DETECT_N);
438         gpio_free(GPIO_NR_PALMLD_POWER_DETECT);
439 }
440
441 static char *palmld_supplicants[] = {
442         "main-battery",
443 };
444
445 static struct pda_power_pdata power_supply_info = {
446         .init            = power_supply_init,
447         .is_ac_online    = palmld_is_ac_online,
448         .is_usb_online   = palmld_is_usb_online,
449         .exit            = power_supply_exit,
450         .supplied_to     = palmld_supplicants,
451         .num_supplicants = ARRAY_SIZE(palmld_supplicants),
452 };
453
454 static struct platform_device power_supply = {
455         .name = "pda-power",
456         .id   = -1,
457         .dev  = {
458                 .platform_data = &power_supply_info,
459         },
460 };
461
462 /******************************************************************************
463  * WM97xx battery
464  ******************************************************************************/
465 static struct wm97xx_batt_info wm97xx_batt_pdata = {
466         .batt_aux       = WM97XX_AUX_ID3,
467         .temp_aux       = WM97XX_AUX_ID2,
468         .charge_gpio    = -1,
469         .max_voltage    = PALMLD_BAT_MAX_VOLTAGE,
470         .min_voltage    = PALMLD_BAT_MIN_VOLTAGE,
471         .batt_mult      = 1000,
472         .batt_div       = 414,
473         .temp_mult      = 1,
474         .temp_div       = 1,
475         .batt_tech      = POWER_SUPPLY_TECHNOLOGY_LIPO,
476         .batt_name      = "main-batt",
477 };
478
479 /******************************************************************************
480  * aSoC audio
481  ******************************************************************************/
482 static struct palm27x_asoc_info palmld_asoc_pdata = {
483         .jack_gpio      = GPIO_NR_PALMLD_EARPHONE_DETECT,
484 };
485
486 static pxa2xx_audio_ops_t palmld_ac97_pdata = {
487         .reset_gpio     = 95,
488 };
489
490 static struct platform_device palmld_asoc = {
491         .name = "palm27x-asoc",
492         .id   = -1,
493         .dev  = {
494                 .platform_data = &palmld_asoc_pdata,
495         },
496 };
497
498 /******************************************************************************
499  * HDD
500  ******************************************************************************/
501 static struct platform_device palmld_hdd = {
502         .name   = "pata_palmld",
503         .id     = -1,
504 };
505
506 /******************************************************************************
507  * Framebuffer
508  ******************************************************************************/
509 static struct pxafb_mode_info palmld_lcd_modes[] = {
510 {
511         .pixclock       = 57692,
512         .xres           = 320,
513         .yres           = 480,
514         .bpp            = 16,
515
516         .left_margin    = 32,
517         .right_margin   = 1,
518         .upper_margin   = 7,
519         .lower_margin   = 1,
520
521         .hsync_len      = 4,
522         .vsync_len      = 1,
523 },
524 };
525
526 static struct pxafb_mach_info palmld_lcd_screen = {
527         .modes          = palmld_lcd_modes,
528         .num_modes      = ARRAY_SIZE(palmld_lcd_modes),
529         .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
530 };
531
532 /******************************************************************************
533  * Power management - standby
534  ******************************************************************************/
535 #ifdef CONFIG_PM
536 static u32 *addr __initdata;
537 static u32 resume[3] __initdata = {
538         0xe3a00101,     /* mov  r0,     #0x40000000 */
539         0xe380060f,     /* orr  r0, r0, #0x00f00000 */
540         0xe590f008,     /* ldr  pc, [r0, #0x08] */
541 };
542
543 static int __init palmld_pm_init(void)
544 {
545         int i;
546
547         /* this is where the bootloader jumps */
548         addr = phys_to_virt(PALMLD_STR_BASE);
549
550         for (i = 0; i < 3; i++)
551                 addr[i] = resume[i];
552
553         return 0;
554 }
555
556 device_initcall(palmld_pm_init);
557 #endif
558
559 /******************************************************************************
560  * Machine init
561  ******************************************************************************/
562 static struct platform_device *devices[] __initdata = {
563 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
564         &palmld_pxa_keys,
565 #endif
566         &palmld_backlight,
567         &palmld_leds,
568         &power_supply,
569         &palmld_asoc,
570         &palmld_hdd,
571 };
572
573 static struct map_desc palmld_io_desc[] __initdata = {
574 {
575         .virtual        = PALMLD_IDE_VIRT,
576         .pfn            = __phys_to_pfn(PALMLD_IDE_PHYS),
577         .length         = PALMLD_IDE_SIZE,
578         .type           = MT_DEVICE
579 },
580 {
581         .virtual        = PALMLD_USB_VIRT,
582         .pfn            = __phys_to_pfn(PALMLD_USB_PHYS),
583         .length         = PALMLD_USB_SIZE,
584         .type           = MT_DEVICE
585 },
586 };
587
588 static void __init palmld_map_io(void)
589 {
590         pxa_map_io();
591         iotable_init(palmld_io_desc, ARRAY_SIZE(palmld_io_desc));
592 }
593
594 static void __init palmld_init(void)
595 {
596         pxa2xx_mfp_config(ARRAY_AND_SIZE(palmld_pin_config));
597
598         set_pxa_fb_info(&palmld_lcd_screen);
599         pxa_set_mci_info(&palmld_mci_platform_data);
600         pxa_set_ac97_info(&palmld_ac97_pdata);
601         pxa_set_ficp_info(&palmld_ficp_platform_data);
602         pxa_set_keypad_info(&palmld_keypad_platform_data);
603         wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
604
605         platform_add_devices(devices, ARRAY_SIZE(devices));
606 }
607
608 MACHINE_START(PALMLD, "Palm LifeDrive")
609         .phys_io        = PALMLD_PHYS_IO_START,
610         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
611         .boot_params    = 0xa0000100,
612         .map_io         = palmld_map_io,
613         .init_irq       = pxa27x_init_irq,
614         .timer          = &pxa_timer,
615         .init_machine   = palmld_init
616 MACHINE_END