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