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