ARM: n35: Enable wake-up by Power button on Acer n35
[sfrench/cifs-2.6.git] / arch / arm / mach-s3c2410 / mach-n30.c
1 /* Machine specific code for the Acer n30, Acer N35, Navman PiN 570,
2  * Yakumo AlphaX and Airis NC05 PDAs.
3  *
4  * Copyright (c) 2003-2005 Simtec Electronics
5  *      Ben Dooks <ben@simtec.co.uk>
6  *
7  * Copyright (c) 2005-2008 Christer Weinigel <christer@weinigel.se>
8  *
9  * There is a wiki with more information about the n30 port at
10  * http://handhelds.org/moin/moin.cgi/AcerN30Documentation .
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
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19
20 #include <linux/gpio_keys.h>
21 #include <linux/init.h>
22 #include <linux/gpio.h>
23 #include <linux/input.h>
24 #include <linux/interrupt.h>
25 #include <linux/platform_device.h>
26 #include <linux/serial_core.h>
27 #include <linux/timer.h>
28 #include <linux/io.h>
29
30 #include <mach/hardware.h>
31 #include <asm/irq.h>
32 #include <asm/mach-types.h>
33
34 #include <mach/fb.h>
35 #include <mach/leds-gpio.h>
36 #include <mach/regs-gpio.h>
37 #include <mach/regs-lcd.h>
38
39 #include <asm/mach/arch.h>
40 #include <asm/mach/irq.h>
41 #include <asm/mach/map.h>
42
43 #include <plat/iic.h>
44 #include <plat/regs-serial.h>
45
46 #include <plat/clock.h>
47 #include <plat/cpu.h>
48 #include <plat/devs.h>
49 #include <plat/s3c2410.h>
50 #include <plat/udc.h>
51
52 static struct map_desc n30_iodesc[] __initdata = {
53         /* nothing here yet */
54 };
55
56 static struct s3c2410_uartcfg n30_uartcfgs[] = {
57         /* Normal serial port */
58         [0] = {
59                 .hwport      = 0,
60                 .flags       = 0,
61                 .ucon        = 0x2c5,
62                 .ulcon       = 0x03,
63                 .ufcon       = 0x51,
64         },
65         /* IR port */
66         [1] = {
67                 .hwport      = 1,
68                 .flags       = 0,
69                 .uart_flags  = UPF_CONS_FLOW,
70                 .ucon        = 0x2c5,
71                 .ulcon       = 0x43,
72                 .ufcon       = 0x51,
73         },
74         /* On the N30 the bluetooth controller is connected here.
75          * On the N35 and variants the GPS receiver is connected here. */
76         [2] = {
77                 .hwport      = 2,
78                 .flags       = 0,
79                 .ucon        = 0x2c5,
80                 .ulcon       = 0x03,
81                 .ufcon       = 0x51,
82         },
83 };
84
85 static void n30_udc_pullup(enum s3c2410_udc_cmd_e cmd)
86 {
87         switch (cmd) {
88         case S3C2410_UDC_P_ENABLE :
89                 s3c2410_gpio_setpin(S3C2410_GPB(3), 1);
90                 break;
91         case S3C2410_UDC_P_DISABLE :
92                 s3c2410_gpio_setpin(S3C2410_GPB(3), 0);
93                 break;
94         case S3C2410_UDC_P_RESET :
95                 break;
96         default:
97                 break;
98         }
99 }
100
101 static struct s3c2410_udc_mach_info n30_udc_cfg __initdata = {
102         .udc_command            = n30_udc_pullup,
103         .vbus_pin               = S3C2410_GPG(1),
104         .vbus_pin_inverted      = 0,
105 };
106
107 static struct gpio_keys_button n30_buttons[] = {
108         {
109                 .gpio           = S3C2410_GPF(0),
110                 .code           = KEY_POWER,
111                 .desc           = "Power",
112                 .active_low     = 0,
113         },
114         {
115                 .gpio           = S3C2410_GPG(9),
116                 .code           = KEY_UP,
117                 .desc           = "Thumbwheel Up",
118                 .active_low     = 0,
119         },
120         {
121                 .gpio           = S3C2410_GPG(8),
122                 .code           = KEY_DOWN,
123                 .desc           = "Thumbwheel Down",
124                 .active_low     = 0,
125         },
126         {
127                 .gpio           = S3C2410_GPG(7),
128                 .code           = KEY_ENTER,
129                 .desc           = "Thumbwheel Press",
130                 .active_low     = 0,
131         },
132         {
133                 .gpio           = S3C2410_GPF(7),
134                 .code           = KEY_HOMEPAGE,
135                 .desc           = "Home",
136                 .active_low     = 0,
137         },
138         {
139                 .gpio           = S3C2410_GPF(6),
140                 .code           = KEY_CALENDAR,
141                 .desc           = "Calendar",
142                 .active_low     = 0,
143         },
144         {
145                 .gpio           = S3C2410_GPF(5),
146                 .code           = KEY_ADDRESSBOOK,
147                 .desc           = "Contacts",
148                 .active_low     = 0,
149         },
150         {
151                 .gpio           = S3C2410_GPF(4),
152                 .code           = KEY_MAIL,
153                 .desc           = "Mail",
154                 .active_low     = 0,
155         },
156 };
157
158 static struct gpio_keys_platform_data n30_button_data = {
159         .buttons        = n30_buttons,
160         .nbuttons       = ARRAY_SIZE(n30_buttons),
161 };
162
163 static struct platform_device n30_button_device = {
164         .name           = "gpio-keys",
165         .id             = -1,
166         .dev            = {
167                 .platform_data  = &n30_button_data,
168         }
169 };
170
171 static struct gpio_keys_button n35_buttons[] = {
172         {
173                 .gpio           = S3C2410_GPF(0),
174                 .code           = KEY_POWER,
175                 .type           = EV_PWR,
176                 .desc           = "Power",
177                 .active_low     = 0,
178                 .wakeup         = 1,
179         },
180         {
181                 .gpio           = S3C2410_GPG(9),
182                 .code           = KEY_UP,
183                 .desc           = "Joystick Up",
184                 .active_low     = 0,
185         },
186         {
187                 .gpio           = S3C2410_GPG(8),
188                 .code           = KEY_DOWN,
189                 .desc           = "Joystick Down",
190                 .active_low     = 0,
191         },
192         {
193                 .gpio           = S3C2410_GPG(6),
194                 .code           = KEY_DOWN,
195                 .desc           = "Joystick Left",
196                 .active_low     = 0,
197         },
198         {
199                 .gpio           = S3C2410_GPG(5),
200                 .code           = KEY_DOWN,
201                 .desc           = "Joystick Right",
202                 .active_low     = 0,
203         },
204         {
205                 .gpio           = S3C2410_GPG(7),
206                 .code           = KEY_ENTER,
207                 .desc           = "Joystick Press",
208                 .active_low     = 0,
209         },
210         {
211                 .gpio           = S3C2410_GPF(7),
212                 .code           = KEY_HOMEPAGE,
213                 .desc           = "Home",
214                 .active_low     = 0,
215         },
216         {
217                 .gpio           = S3C2410_GPF(6),
218                 .code           = KEY_CALENDAR,
219                 .desc           = "Calendar",
220                 .active_low     = 0,
221         },
222         {
223                 .gpio           = S3C2410_GPF(5),
224                 .code           = KEY_ADDRESSBOOK,
225                 .desc           = "Contacts",
226                 .active_low     = 0,
227         },
228         {
229                 .gpio           = S3C2410_GPF(4),
230                 .code           = KEY_MAIL,
231                 .desc           = "Mail",
232                 .active_low     = 0,
233         },
234         {
235                 .gpio           = S3C2410_GPF(3),
236                 .code           = SW_RADIO,
237                 .desc           = "GPS Antenna",
238                 .active_low     = 0,
239         },
240         {
241                 .gpio           = S3C2410_GPG(2),
242                 .code           = SW_HEADPHONE_INSERT,
243                 .desc           = "Headphone",
244                 .active_low     = 0,
245         },
246 };
247
248 static struct gpio_keys_platform_data n35_button_data = {
249         .buttons        = n35_buttons,
250         .nbuttons       = ARRAY_SIZE(n35_buttons),
251 };
252
253 static struct platform_device n35_button_device = {
254         .name           = "gpio-keys",
255         .id             = -1,
256         .num_resources  = 0,
257         .dev            = {
258                 .platform_data  = &n35_button_data,
259         }
260 };
261
262 /* This is the bluetooth LED on the device. */
263 static struct s3c24xx_led_platdata n30_blue_led_pdata = {
264         .name           = "blue_led",
265         .gpio           = S3C2410_GPG(6),
266         .def_trigger    = "",
267 };
268
269 /* This is the blue LED on the device. Originaly used to indicate GPS activity
270  * by flashing. */
271 static struct s3c24xx_led_platdata n35_blue_led_pdata = {
272         .name           = "blue_led",
273         .gpio           = S3C2410_GPD(8),
274         .def_trigger    = "",
275 };
276
277 /* This LED is driven by the battery microcontroller, and is blinking
278  * red, blinking green or solid green when the battery is low,
279  * charging or full respectively.  By driving GPD9 low, it's possible
280  * to force the LED to blink red, so call that warning LED.  */
281 static struct s3c24xx_led_platdata n30_warning_led_pdata = {
282         .name           = "warning_led",
283         .flags          = S3C24XX_LEDF_ACTLOW,
284         .gpio           = S3C2410_GPD(9),
285         .def_trigger    = "",
286 };
287
288 static struct s3c24xx_led_platdata n35_warning_led_pdata = {
289         .name           = "warning_led",
290         .flags          = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
291         .gpio           = S3C2410_GPD(9),
292         .def_trigger    = "",
293 };
294
295 static struct platform_device n30_blue_led = {
296         .name           = "s3c24xx_led",
297         .id             = 1,
298         .dev            = {
299                 .platform_data  = &n30_blue_led_pdata,
300         },
301 };
302
303 static struct platform_device n35_blue_led = {
304         .name           = "s3c24xx_led",
305         .id             = 1,
306         .dev            = {
307                 .platform_data  = &n35_blue_led_pdata,
308         },
309 };
310
311 static struct platform_device n30_warning_led = {
312         .name           = "s3c24xx_led",
313         .id             = 2,
314         .dev            = {
315                 .platform_data  = &n30_warning_led_pdata,
316         },
317 };
318
319 static struct platform_device n35_warning_led = {
320         .name           = "s3c24xx_led",
321         .id             = 2,
322         .dev            = {
323                 .platform_data  = &n35_warning_led_pdata,
324         },
325 };
326
327 static struct s3c2410fb_display n30_display __initdata = {
328         .type           = S3C2410_LCDCON1_TFT,
329         .width          = 240,
330         .height         = 320,
331         .pixclock       = 170000,
332
333         .xres           = 240,
334         .yres           = 320,
335         .bpp            = 16,
336         .left_margin    = 3,
337         .right_margin   = 40,
338         .hsync_len      = 40,
339         .upper_margin   = 2,
340         .lower_margin   = 3,
341         .vsync_len      = 2,
342
343         .lcdcon5 = S3C2410_LCDCON5_INVVLINE | S3C2410_LCDCON5_INVVFRAME,
344 };
345
346 static struct s3c2410fb_mach_info n30_fb_info __initdata = {
347         .displays       = &n30_display,
348         .num_displays   = 1,
349         .default_display = 0,
350         .lpcsel         = 0x06,
351 };
352
353 static struct platform_device *n30_devices[] __initdata = {
354         &s3c_device_lcd,
355         &s3c_device_wdt,
356         &s3c_device_i2c0,
357         &s3c_device_iis,
358         &s3c_device_ohci,
359         &s3c_device_rtc,
360         &s3c_device_usbgadget,
361         &n30_button_device,
362         &n30_blue_led,
363         &n30_warning_led,
364 };
365
366 static struct platform_device *n35_devices[] __initdata = {
367         &s3c_device_lcd,
368         &s3c_device_wdt,
369         &s3c_device_i2c0,
370         &s3c_device_iis,
371         &s3c_device_rtc,
372         &s3c_device_usbgadget,
373         &n35_button_device,
374         &n35_blue_led,
375         &n35_warning_led,
376 };
377
378 static struct s3c2410_platform_i2c __initdata n30_i2ccfg = {
379         .flags          = 0,
380         .slave_addr     = 0x10,
381         .frequency      = 10*1000,
382 };
383
384 /* Lots of hardcoded stuff, but it sets up the hardware in a useful
385  * state so that we can boot Linux directly from flash. */
386 static void __init n30_hwinit(void)
387 {
388         /* GPA0-11 special functions -- unknown what they do
389          * GPA12 N30 special function -- unknown what it does
390          *       N35/PiN output -- unknown what it does
391          *
392          * A12 is nGCS1 on the N30 and an output on the N35/PiN.  I
393          * don't think it does anything useful on the N30, so I ought
394          * to make it an output there too since it always driven to 0
395          * as far as I can tell. */
396         if (machine_is_n30())
397                 __raw_writel(0x007fffff, S3C2410_GPACON);
398         if (machine_is_n35())
399                 __raw_writel(0x007fefff, S3C2410_GPACON);
400         __raw_writel(0x00000000, S3C2410_GPADAT);
401
402         /* GPB0 TOUT0 backlight level
403          * GPB1 output 1=backlight on
404          * GPB2 output IrDA enable 0=transceiver enabled, 1=disabled
405          * GPB3 output USB D+ pull up 0=disabled, 1=enabled
406          * GPB4 N30 output -- unknown function
407          *      N30/PiN GPS control 0=GPS enabled, 1=GPS disabled
408          * GPB5 output -- unknown function
409          * GPB6 input -- unknown function
410          * GPB7 output -- unknown function
411          * GPB8 output -- probably LCD driver enable
412          * GPB9 output -- probably LCD VSYNC driver enable
413          * GPB10 output -- probably LCD HSYNC driver enable
414          */
415         __raw_writel(0x00154556, S3C2410_GPBCON);
416         __raw_writel(0x00000750, S3C2410_GPBDAT);
417         __raw_writel(0x00000073, S3C2410_GPBUP);
418
419         /* GPC0 input RS232 DCD/DSR/RI
420          * GPC1 LCD
421          * GPC2 output RS232 DTR?
422          * GPC3 input RS232 DCD/DSR/RI
423          * GPC4 LCD
424          * GPC5 output 0=NAND write enabled, 1=NAND write protect
425          * GPC6 input -- unknown function
426          * GPC7 input charger status 0=charger connected
427          *      this input can be triggered by power on the USB device
428          *      port too, but will go back to disconnected soon after.
429          * GPC8 N30/N35 output -- unknown function, always driven to 1
430          *      PiN input -- unknown function, always read as 1
431          *      Make it an input with a pull up for all models.
432          * GPC9-15 LCD
433          */
434         __raw_writel(0xaaa80618, S3C2410_GPCCON);
435         __raw_writel(0x0000014c, S3C2410_GPCDAT);
436         __raw_writel(0x0000fef2, S3C2410_GPCUP);
437
438         /* GPD0 input -- unknown function
439          * GPD1-D7 LCD
440          * GPD8 N30 output -- unknown function
441          *      N35/PiN output 1=GPS LED on
442          * GPD9 output 0=power led blinks red, 1=normal power led function
443          * GPD10 output -- unknown function
444          * GPD11-15 LCD drivers
445          */
446         __raw_writel(0xaa95aaa4, S3C2410_GPDCON);
447         __raw_writel(0x00000601, S3C2410_GPDDAT);
448         __raw_writel(0x0000fbfe, S3C2410_GPDUP);
449
450         /* GPE0-4 I2S audio bus
451          * GPE5-10 SD/MMC bus
452          * E11-13 outputs -- unknown function, probably power management
453          * E14-15 I2C bus connected to the battery controller
454          */
455         __raw_writel(0xa56aaaaa, S3C2410_GPECON);
456         __raw_writel(0x0000efc5, S3C2410_GPEDAT);
457         __raw_writel(0x0000f81f, S3C2410_GPEUP);
458
459         /* GPF0  input 0=power button pressed
460          * GPF1  input SD/MMC switch 0=card present
461          * GPF2  N30 1=reset button pressed (inverted compared to the rest)
462          *       N35/PiN 0=reset button pressed
463          * GPF3  N30/PiN input -- unknown function
464          *       N35 input GPS antenna position, 0=antenna closed, 1=open
465          * GPF4  input 0=button 4 pressed
466          * GPF5  input 0=button 3 pressed
467          * GPF6  input 0=button 2 pressed
468          * GPF7  input 0=button 1 pressed
469          */
470         __raw_writel(0x0000aaaa, S3C2410_GPFCON);
471         __raw_writel(0x00000000, S3C2410_GPFDAT);
472         __raw_writel(0x000000ff, S3C2410_GPFUP);
473
474         /* GPG0  input RS232 DCD/DSR/RI
475          * GPG1  input 1=USB gadget port has power from a host
476          * GPG2  N30 input -- unknown function
477          *       N35/PiN input 0=headphones plugged in, 1=not plugged in
478          * GPG3  N30 output -- unknown function
479          *       N35/PiN input with unknown function
480          * GPG4  N30 output 0=MMC enabled, 1=MMC disabled
481          * GPG5  N30 output 0=BlueTooth chip disabled, 1=enabled
482          *       N35/PiN input joystick right
483          * GPG6  N30 output 0=blue led on, 1=off
484          *       N35/PiN input joystick left
485          * GPG7  input 0=thumbwheel pressed
486          * GPG8  input 0=thumbwheel down
487          * GPG9  input 0=thumbwheel up
488          * GPG10 input SD/MMC write protect switch
489          * GPG11 N30 input -- unknown function
490          *       N35 output 0=GPS antenna powered, 1=not powered
491          *       PiN output -- unknown function
492          * GPG12-15 touch screen functions
493          *
494          * The pullups differ between the models, so enable all
495          * pullups that are enabled on any of the models.
496          */
497         if (machine_is_n30())
498                 __raw_writel(0xff0a956a, S3C2410_GPGCON);
499         if (machine_is_n35())
500                 __raw_writel(0xff4aa92a, S3C2410_GPGCON);
501         __raw_writel(0x0000e800, S3C2410_GPGDAT);
502         __raw_writel(0x0000f86f, S3C2410_GPGUP);
503
504         /* GPH0/1/2/3 RS232 serial port
505          * GPH4/5 IrDA serial port
506          * GPH6/7  N30 BlueTooth serial port
507          *         N35/PiN GPS receiver
508          * GPH8 input -- unknown function
509          * GPH9 CLKOUT0 HCLK -- unknown use
510          * GPH10 CLKOUT1 FCLK -- unknown use
511          *
512          * The pull ups for H6/H7 are enabled on N30 but not on the
513          * N35/PiN.  I suppose is useful for a budget model of the N30
514          * with no bluetooh.  It doesn't hurt to have the pull ups
515          * enabled on the N35, so leave them enabled for all models.
516          */
517         __raw_writel(0x0028aaaa, S3C2410_GPHCON);
518         __raw_writel(0x000005ef, S3C2410_GPHDAT);
519         __raw_writel(0x0000063f, S3C2410_GPHUP);
520 }
521
522 static void __init n30_map_io(void)
523 {
524         s3c24xx_init_io(n30_iodesc, ARRAY_SIZE(n30_iodesc));
525         n30_hwinit();
526         s3c24xx_init_clocks(0);
527         s3c24xx_init_uarts(n30_uartcfgs, ARRAY_SIZE(n30_uartcfgs));
528 }
529
530 static void __init n30_init_irq(void)
531 {
532         s3c24xx_init_irq();
533 }
534
535 /* GPB3 is the line that controls the pull-up for the USB D+ line */
536
537 static void __init n30_init(void)
538 {
539         s3c24xx_fb_set_platdata(&n30_fb_info);
540         s3c24xx_udc_set_platdata(&n30_udc_cfg);
541         s3c_i2c0_set_platdata(&n30_i2ccfg);
542
543         /* Turn off suspend on both USB ports, and switch the
544          * selectable USB port to USB device mode. */
545
546         s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
547                               S3C2410_MISCCR_USBSUSPND0 |
548                               S3C2410_MISCCR_USBSUSPND1, 0x0);
549
550         if (machine_is_n30()) {
551                 /* Turn off suspend on both USB ports, and switch the
552                  * selectable USB port to USB device mode. */
553                 s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
554                                       S3C2410_MISCCR_USBSUSPND0 |
555                                       S3C2410_MISCCR_USBSUSPND1, 0x0);
556
557                 platform_add_devices(n30_devices, ARRAY_SIZE(n30_devices));
558         }
559
560         if (machine_is_n35()) {
561                 /* Turn off suspend and switch the selectable USB port
562                  * to USB device mode.  Turn on suspend for the host
563                  * port since it is not connected on the N35.
564                  *
565                  * Actually, the host port is available at some pads
566                  * on the back of the device, so it would actually be
567                  * possible to add a USB device inside the N35 if you
568                  * are willing to do some hardware modifications. */
569                 s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
570                                       S3C2410_MISCCR_USBSUSPND0 |
571                                       S3C2410_MISCCR_USBSUSPND1,
572                                       S3C2410_MISCCR_USBSUSPND0);
573
574                 platform_add_devices(n35_devices, ARRAY_SIZE(n35_devices));
575         }
576 }
577
578 MACHINE_START(N30, "Acer-N30")
579         /* Maintainer: Christer Weinigel <christer@weinigel.se>,
580                                 Ben Dooks <ben-linux@fluff.org>
581         */
582         .phys_io        = S3C2410_PA_UART,
583         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
584         .boot_params    = S3C2410_SDRAM_PA + 0x100,
585         .timer          = &s3c24xx_timer,
586         .init_machine   = n30_init,
587         .init_irq       = n30_init_irq,
588         .map_io         = n30_map_io,
589 MACHINE_END
590
591 MACHINE_START(N35, "Acer-N35")
592         /* Maintainer: Christer Weinigel <christer@weinigel.se>
593         */
594         .phys_io        = S3C2410_PA_UART,
595         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
596         .boot_params    = S3C2410_SDRAM_PA + 0x100,
597         .timer          = &s3c24xx_timer,
598         .init_machine   = n30_init,
599         .init_irq       = n30_init_irq,
600         .map_io         = n30_map_io,
601 MACHINE_END