GNU Linux-libre 6.1.90-gnu
[releases.git] / arch / arm / mach-s3c / mach-h1940.c
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Copyright (c) 2003-2005 Simtec Electronics
4 //   Ben Dooks <ben@simtec.co.uk>
5 //
6 // https://www.handhelds.org/projects/h1940.html
7
8 #include <linux/kernel.h>
9 #include <linux/types.h>
10 #include <linux/interrupt.h>
11 #include <linux/list.h>
12 #include <linux/memblock.h>
13 #include <linux/timer.h>
14 #include <linux/init.h>
15 #include <linux/device.h>
16 #include <linux/serial_core.h>
17 #include <linux/serial_s3c.h>
18 #include <linux/platform_device.h>
19 #include <linux/io.h>
20 #include <linux/gpio.h>
21 #include <linux/gpio/machine.h>
22 #include <linux/input.h>
23 #include <linux/gpio_keys.h>
24 #include <linux/pwm.h>
25 #include <linux/pwm_backlight.h>
26 #include <linux/i2c.h>
27 #include <linux/leds.h>
28 #include <linux/pda_power.h>
29 #include <linux/s3c_adc_battery.h>
30 #include <linux/delay.h>
31
32 #include <video/platform_lcd.h>
33
34 #include <linux/mmc/host.h>
35 #include <linux/export.h>
36
37 #include <asm/irq.h>
38 #include <asm/mach-types.h>
39 #include <asm/mach/arch.h>
40 #include <asm/mach/map.h>
41 #include <asm/mach/irq.h>
42
43 #include <linux/platform_data/i2c-s3c2410.h>
44 #include <linux/platform_data/mmc-s3cmci.h>
45 #include <linux/platform_data/touchscreen-s3c2410.h>
46 #include <linux/platform_data/usb-s3c2410_udc.h>
47
48 #include <sound/uda1380.h>
49
50 #include <linux/platform_data/fb-s3c2410.h>
51 #include "map.h"
52 #include "hardware-s3c24xx.h"
53 #include "regs-clock.h"
54 #include "regs-gpio.h"
55 #include "gpio-samsung.h"
56
57 #include "cpu.h"
58 #include "devs.h"
59 #include "gpio-cfg.h"
60 #include "pm.h"
61
62 #include "s3c24xx.h"
63 #include "h1940.h"
64
65 #define H1940_LATCH             ((void __force __iomem *)0xF8000000)
66
67 #define H1940_PA_LATCH          S3C2410_CS2
68
69 #define H1940_LATCH_BIT(x)      (1 << ((x) + 16 - S3C_GPIO_END))
70
71 #define S3C24XX_PLL_MDIV_SHIFT         (12)
72 #define S3C24XX_PLL_PDIV_SHIFT         (4)
73 #define S3C24XX_PLL_SDIV_SHIFT         (0)
74
75 static struct map_desc h1940_iodesc[] __initdata = {
76         [0] = {
77                 .virtual        = (unsigned long)H1940_LATCH,
78                 .pfn            = __phys_to_pfn(H1940_PA_LATCH),
79                 .length         = SZ_16K,
80                 .type           = MT_DEVICE
81         },
82 };
83
84 #define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
85 #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
86 #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
87
88 static struct s3c2410_uartcfg h1940_uartcfgs[] __initdata = {
89         [0] = {
90                 .hwport      = 0,
91                 .flags       = 0,
92                 .ucon        = 0x3c5,
93                 .ulcon       = 0x03,
94                 .ufcon       = 0x51,
95         },
96         [1] = {
97                 .hwport      = 1,
98                 .flags       = 0,
99                 .ucon        = 0x245,
100                 .ulcon       = 0x03,
101                 .ufcon       = 0x00,
102         },
103         /* IR port */
104         [2] = {
105                 .hwport      = 2,
106                 .flags       = 0,
107                 .uart_flags  = UPF_CONS_FLOW,
108                 .ucon        = 0x3c5,
109                 .ulcon       = 0x43,
110                 .ufcon       = 0x51,
111         }
112 };
113
114 /* Board control latch control */
115
116 static unsigned int latch_state;
117
118 static void h1940_latch_control(unsigned int clear, unsigned int set)
119 {
120         unsigned long flags;
121
122         local_irq_save(flags);
123
124         latch_state &= ~clear;
125         latch_state |= set;
126
127         __raw_writel(latch_state, H1940_LATCH);
128
129         local_irq_restore(flags);
130 }
131
132 static inline int h1940_gpiolib_to_latch(int offset)
133 {
134         return 1 << (offset + 16);
135 }
136
137 static void h1940_gpiolib_latch_set(struct gpio_chip *chip,
138                                         unsigned offset, int value)
139 {
140         int latch_bit = h1940_gpiolib_to_latch(offset);
141
142         h1940_latch_control(value ? 0 : latch_bit,
143                 value ? latch_bit : 0);
144 }
145
146 static int h1940_gpiolib_latch_output(struct gpio_chip *chip,
147                                         unsigned offset, int value)
148 {
149         h1940_gpiolib_latch_set(chip, offset, value);
150         return 0;
151 }
152
153 static int h1940_gpiolib_latch_get(struct gpio_chip *chip,
154                                         unsigned offset)
155 {
156         return (latch_state >> (offset + 16)) & 1;
157 }
158
159 static struct gpio_chip h1940_latch_gpiochip = {
160         .base                   = H1940_LATCH_GPIO(0),
161         .owner                  = THIS_MODULE,
162         .label                  = "H1940_LATCH",
163         .ngpio                  = 16,
164         .direction_output       = h1940_gpiolib_latch_output,
165         .set                    = h1940_gpiolib_latch_set,
166         .get                    = h1940_gpiolib_latch_get,
167 };
168
169 static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = {
170 };
171
172 static struct gpiod_lookup_table h1940_udc_gpio_table = {
173         .dev_id = "s3c2410-usbgadget",
174         .table = {
175                 GPIO_LOOKUP("GPIOG", 5, "vbus", GPIO_ACTIVE_LOW),
176                 GPIO_LOOKUP("H1940_LATCH", 7, "pullup", GPIO_ACTIVE_HIGH),
177                 { },
178         },
179 };
180
181 static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = {
182                 .delay = 10000,
183                 .presc = 49,
184                 .oversampling_shift = 2,
185                 .cfg_gpio = s3c24xx_ts_cfg_gpio,
186 };
187
188 /*
189  * Set lcd on or off
190  */
191 static struct s3c2410fb_display h1940_lcd __initdata = {
192         .lcdcon5=       S3C2410_LCDCON5_FRM565 | \
193                         S3C2410_LCDCON5_INVVLINE | \
194                         S3C2410_LCDCON5_HWSWP,
195
196         .type =         S3C2410_LCDCON1_TFT,
197         .width =        240,
198         .height =       320,
199         .pixclock =     260000,
200         .xres =         240,
201         .yres =         320,
202         .bpp =          16,
203         .left_margin =  8,
204         .right_margin = 20,
205         .hsync_len =    4,
206         .upper_margin = 8,
207         .lower_margin = 7,
208         .vsync_len =    1,
209 };
210
211 static struct s3c2410fb_mach_info h1940_fb_info __initdata = {
212         .displays = &h1940_lcd,
213         .num_displays = 1,
214         .default_display = 0,
215
216         .lpcsel =       0x02,
217         .gpccon =       0xaa940659,
218         .gpccon_mask =  0xffffc0f0,
219         .gpccon_reg =   S3C2410_GPCCON,
220         .gpcup =        0x0000ffff,
221         .gpcup_mask =   0xffffffff,
222         .gpcup_reg =    S3C2410_GPCUP,
223         .gpdcon =       0xaa84aaa0,
224         .gpdcon_mask =  0xffffffff,
225         .gpdcon_reg =   S3C2410_GPDCON,
226         .gpdup =        0x0000faff,
227         .gpdup_mask =   0xffffffff,
228         .gpdup_reg =    S3C2410_GPDUP,
229 };
230
231 static int power_supply_init(struct device *dev)
232 {
233         return gpio_request(S3C2410_GPF(2), "cable plugged");
234 }
235
236 static int h1940_is_ac_online(void)
237 {
238         return !gpio_get_value(S3C2410_GPF(2));
239 }
240
241 static void power_supply_exit(struct device *dev)
242 {
243         gpio_free(S3C2410_GPF(2));
244 }
245
246 static char *h1940_supplicants[] = {
247         "main-battery",
248         "backup-battery",
249 };
250
251 static struct pda_power_pdata power_supply_info = {
252         .init                   = power_supply_init,
253         .is_ac_online           = h1940_is_ac_online,
254         .exit                   = power_supply_exit,
255         .supplied_to            = h1940_supplicants,
256         .num_supplicants        = ARRAY_SIZE(h1940_supplicants),
257 };
258
259 static struct resource power_supply_resources[] = {
260         [0] = DEFINE_RES_NAMED(IRQ_EINT2, 1, "ac", IORESOURCE_IRQ \
261                         | IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE),
262 };
263
264 static struct platform_device power_supply = {
265         .name           = "pda-power",
266         .id             = -1,
267         .dev            = {
268                                 .platform_data =
269                                         &power_supply_info,
270         },
271         .resource       = power_supply_resources,
272         .num_resources  = ARRAY_SIZE(power_supply_resources),
273 };
274
275 static const struct s3c_adc_bat_thresh bat_lut_noac[] = {
276         { .volt = 4070, .cur = 162, .level = 100},
277         { .volt = 4040, .cur = 165, .level = 95},
278         { .volt = 4016, .cur = 164, .level = 90},
279         { .volt = 3996, .cur = 166, .level = 85},
280         { .volt = 3971, .cur = 168, .level = 80},
281         { .volt = 3951, .cur = 168, .level = 75},
282         { .volt = 3931, .cur = 170, .level = 70},
283         { .volt = 3903, .cur = 172, .level = 65},
284         { .volt = 3886, .cur = 172, .level = 60},
285         { .volt = 3858, .cur = 176, .level = 55},
286         { .volt = 3842, .cur = 176, .level = 50},
287         { .volt = 3818, .cur = 176, .level = 45},
288         { .volt = 3789, .cur = 180, .level = 40},
289         { .volt = 3769, .cur = 180, .level = 35},
290         { .volt = 3749, .cur = 184, .level = 30},
291         { .volt = 3732, .cur = 184, .level = 25},
292         { .volt = 3716, .cur = 184, .level = 20},
293         { .volt = 3708, .cur = 184, .level = 15},
294         { .volt = 3716, .cur = 96, .level = 10},
295         { .volt = 3700, .cur = 96, .level = 5},
296         { .volt = 3684, .cur = 96, .level = 0},
297 };
298
299 static const struct s3c_adc_bat_thresh bat_lut_acin[] = {
300         { .volt = 4130, .cur = 0, .level = 100},
301         { .volt = 3982, .cur = 0, .level = 50},
302         { .volt = 3854, .cur = 0, .level = 10},
303         { .volt = 3841, .cur = 0, .level = 0},
304 };
305
306 static struct gpiod_lookup_table h1940_bat_gpio_table = {
307         .dev_id = "s3c-adc-battery",
308         .table = {
309                 /* Charge status S3C2410_GPF(3) */
310                 GPIO_LOOKUP("GPIOF", 3, "charge-status", GPIO_ACTIVE_LOW),
311                 { },
312         },
313 };
314
315 static int h1940_bat_init(void)
316 {
317         int ret;
318
319         ret = gpio_request(H1940_LATCH_SM803_ENABLE, "h1940-charger-enable");
320         if (ret)
321                 return ret;
322         gpio_direction_output(H1940_LATCH_SM803_ENABLE, 0);
323
324         return 0;
325
326 }
327
328 static void h1940_bat_exit(void)
329 {
330         gpio_free(H1940_LATCH_SM803_ENABLE);
331 }
332
333 static void h1940_enable_charger(void)
334 {
335         gpio_set_value(H1940_LATCH_SM803_ENABLE, 1);
336 }
337
338 static void h1940_disable_charger(void)
339 {
340         gpio_set_value(H1940_LATCH_SM803_ENABLE, 0);
341 }
342
343 static struct s3c_adc_bat_pdata h1940_bat_cfg = {
344         .init = h1940_bat_init,
345         .exit = h1940_bat_exit,
346         .enable_charger = h1940_enable_charger,
347         .disable_charger = h1940_disable_charger,
348         .lut_noac = bat_lut_noac,
349         .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
350         .lut_acin = bat_lut_acin,
351         .lut_acin_cnt = ARRAY_SIZE(bat_lut_acin),
352         .volt_channel = 0,
353         .current_channel = 1,
354         .volt_mult = 4056,
355         .current_mult = 1893,
356         .internal_impedance = 200,
357         .backup_volt_channel = 3,
358         /* TODO Check backup volt multiplier */
359         .backup_volt_mult = 4056,
360         .backup_volt_min = 0,
361         .backup_volt_max = 4149288
362 };
363
364 static struct platform_device h1940_battery = {
365         .name             = "s3c-adc-battery",
366         .id               = -1,
367         .dev = {
368                 .parent = &s3c_device_adc.dev,
369                 .platform_data = &h1940_bat_cfg,
370         },
371 };
372
373 static DEFINE_SPINLOCK(h1940_blink_spin);
374
375 int h1940_led_blink_set(struct gpio_desc *desc, int state,
376         unsigned long *delay_on, unsigned long *delay_off)
377 {
378         int blink_gpio, check_gpio1, check_gpio2;
379         int gpio = desc ? desc_to_gpio(desc) : -EINVAL;
380
381         switch (gpio) {
382         case H1940_LATCH_LED_GREEN:
383                 blink_gpio = S3C2410_GPA(7);
384                 check_gpio1 = S3C2410_GPA(1);
385                 check_gpio2 = S3C2410_GPA(3);
386                 break;
387         case H1940_LATCH_LED_RED:
388                 blink_gpio = S3C2410_GPA(1);
389                 check_gpio1 = S3C2410_GPA(7);
390                 check_gpio2 = S3C2410_GPA(3);
391                 break;
392         default:
393                 blink_gpio = S3C2410_GPA(3);
394                 check_gpio1 = S3C2410_GPA(1);
395                 check_gpio2 = S3C2410_GPA(7);
396                 break;
397         }
398
399         if (delay_on && delay_off && !*delay_on && !*delay_off)
400                 *delay_on = *delay_off = 500;
401
402         spin_lock(&h1940_blink_spin);
403
404         switch (state) {
405         case GPIO_LED_NO_BLINK_LOW:
406         case GPIO_LED_NO_BLINK_HIGH:
407                 if (!gpio_get_value(check_gpio1) &&
408                     !gpio_get_value(check_gpio2))
409                         gpio_set_value(H1940_LATCH_LED_FLASH, 0);
410                 gpio_set_value(blink_gpio, 0);
411                 if (gpio_is_valid(gpio))
412                         gpio_set_value(gpio, state);
413                 break;
414         case GPIO_LED_BLINK:
415                 if (gpio_is_valid(gpio))
416                         gpio_set_value(gpio, 0);
417                 gpio_set_value(H1940_LATCH_LED_FLASH, 1);
418                 gpio_set_value(blink_gpio, 1);
419                 break;
420         }
421
422         spin_unlock(&h1940_blink_spin);
423
424         return 0;
425 }
426 EXPORT_SYMBOL(h1940_led_blink_set);
427
428 static struct gpio_led h1940_leds_desc[] = {
429         {
430                 .name                   = "Green",
431                 .default_trigger        = "main-battery-full",
432                 .gpio                   = H1940_LATCH_LED_GREEN,
433                 .retain_state_suspended = 1,
434         },
435         {
436                 .name                   = "Red",
437                 .default_trigger
438                         = "main-battery-charging-blink-full-solid",
439                 .gpio                   = H1940_LATCH_LED_RED,
440                 .retain_state_suspended = 1,
441         },
442 };
443
444 static struct gpio_led_platform_data h1940_leds_pdata = {
445         .num_leds       = ARRAY_SIZE(h1940_leds_desc),
446         .leds           = h1940_leds_desc,
447         .gpio_blink_set = h1940_led_blink_set,
448 };
449
450 static struct platform_device h1940_device_leds = {
451         .name   = "leds-gpio",
452         .id     = -1,
453         .dev    = {
454                         .platform_data = &h1940_leds_pdata,
455         },
456 };
457
458 static struct platform_device h1940_device_bluetooth = {
459         .name             = "h1940-bt",
460         .id               = -1,
461 };
462
463 static void h1940_set_mmc_power(unsigned char power_mode, unsigned short vdd)
464 {
465         s3c24xx_mci_def_set_power(power_mode, vdd);
466
467         switch (power_mode) {
468         case MMC_POWER_OFF:
469                 gpio_set_value(H1940_LATCH_SD_POWER, 0);
470                 break;
471         case MMC_POWER_UP:
472         case MMC_POWER_ON:
473                 gpio_set_value(H1940_LATCH_SD_POWER, 1);
474                 break;
475         default:
476                 break;
477         }
478 }
479
480 static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
481         .set_power     = h1940_set_mmc_power,
482         .ocr_avail     = MMC_VDD_32_33,
483 };
484
485 static struct gpiod_lookup_table h1940_mmc_gpio_table = {
486         .dev_id = "s3c2410-sdi",
487         .table = {
488                 /* Card detect S3C2410_GPF(5) */
489                 GPIO_LOOKUP("GPIOF", 5, "cd", GPIO_ACTIVE_LOW),
490                 /* Write protect S3C2410_GPH(8) */
491                 GPIO_LOOKUP("GPIOH", 8, "wp", GPIO_ACTIVE_LOW),
492                 /* bus pins */
493                 GPIO_LOOKUP_IDX("GPIOE",  5, "bus", 0, GPIO_ACTIVE_HIGH),
494                 GPIO_LOOKUP_IDX("GPIOE",  6, "bus", 1, GPIO_ACTIVE_HIGH),
495                 GPIO_LOOKUP_IDX("GPIOE",  7, "bus", 2, GPIO_ACTIVE_HIGH),
496                 GPIO_LOOKUP_IDX("GPIOE",  8, "bus", 3, GPIO_ACTIVE_HIGH),
497                 GPIO_LOOKUP_IDX("GPIOE",  9, "bus", 4, GPIO_ACTIVE_HIGH),
498                 GPIO_LOOKUP_IDX("GPIOE", 10, "bus", 5, GPIO_ACTIVE_HIGH),
499                 { },
500         },
501 };
502
503 static struct gpiod_lookup_table h1940_audio_gpio_table = {
504         .dev_id = "h1940-audio",
505         .table = {
506                 GPIO_LOOKUP("H1940_LATCH",
507                             H1940_LATCH_AUDIO_POWER - H1940_LATCH_GPIO(0),
508                             "speaker-power", GPIO_ACTIVE_HIGH),
509                 GPIO_LOOKUP("GPIOG", 4, "hp", GPIO_ACTIVE_HIGH),
510                 { },
511         },
512 };
513
514 static struct platform_device h1940_audio = {
515         .name = "h1940-audio",
516         .id   = -1,
517 };
518
519 static struct pwm_lookup h1940_pwm_lookup[] = {
520         PWM_LOOKUP("samsung-pwm", 0, "pwm-backlight", NULL, 36296,
521                    PWM_POLARITY_NORMAL),
522 };
523
524 static int h1940_backlight_init(struct device *dev)
525 {
526         gpio_request(S3C2410_GPB(0), "Backlight");
527
528         gpio_direction_output(S3C2410_GPB(0), 0);
529         s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
530         s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
531         gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
532
533         return 0;
534 }
535
536 static int h1940_backlight_notify(struct device *dev, int brightness)
537 {
538         if (!brightness) {
539                 gpio_direction_output(S3C2410_GPB(0), 1);
540                 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
541         } else {
542                 gpio_direction_output(S3C2410_GPB(0), 0);
543                 s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
544                 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
545                 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
546         }
547         return brightness;
548 }
549
550 static void h1940_backlight_exit(struct device *dev)
551 {
552         gpio_direction_output(S3C2410_GPB(0), 1);
553         gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
554 }
555
556
557 static struct platform_pwm_backlight_data backlight_data = {
558         .max_brightness = 100,
559         .dft_brightness = 50,
560         .init           = h1940_backlight_init,
561         .notify         = h1940_backlight_notify,
562         .exit           = h1940_backlight_exit,
563 };
564
565 static struct platform_device h1940_backlight = {
566         .name = "pwm-backlight",
567         .dev  = {
568                 .parent = &samsung_device_pwm.dev,
569                 .platform_data = &backlight_data,
570         },
571         .id   = -1,
572 };
573
574 static void h1940_lcd_power_set(struct plat_lcd_data *pd,
575                                         unsigned int power)
576 {
577         int value, retries = 100;
578
579         if (!power) {
580                 gpio_set_value(S3C2410_GPC(0), 0);
581                 /* wait for 3ac */
582                 do {
583                         value = gpio_get_value(S3C2410_GPC(6));
584                 } while (value && retries--);
585
586                 gpio_set_value(H1940_LATCH_LCD_P2, 0);
587                 gpio_set_value(H1940_LATCH_LCD_P3, 0);
588                 gpio_set_value(H1940_LATCH_LCD_P4, 0);
589
590                 gpio_direction_output(S3C2410_GPC(1), 0);
591                 gpio_direction_output(S3C2410_GPC(4), 0);
592
593                 gpio_set_value(H1940_LATCH_LCD_P1, 0);
594                 gpio_set_value(H1940_LATCH_LCD_P0, 0);
595
596                 gpio_set_value(S3C2410_GPC(5), 0);
597
598         } else {
599                 gpio_set_value(H1940_LATCH_LCD_P0, 1);
600                 gpio_set_value(H1940_LATCH_LCD_P1, 1);
601
602                 gpio_direction_input(S3C2410_GPC(1));
603                 gpio_direction_input(S3C2410_GPC(4));
604                 mdelay(10);
605                 s3c_gpio_cfgpin(S3C2410_GPC(1), S3C_GPIO_SFN(2));
606                 s3c_gpio_cfgpin(S3C2410_GPC(4), S3C_GPIO_SFN(2));
607
608                 gpio_set_value(S3C2410_GPC(5), 1);
609                 gpio_set_value(S3C2410_GPC(0), 1);
610
611                 gpio_set_value(H1940_LATCH_LCD_P3, 1);
612                 gpio_set_value(H1940_LATCH_LCD_P2, 1);
613                 gpio_set_value(H1940_LATCH_LCD_P4, 1);
614         }
615 }
616
617 static struct plat_lcd_data h1940_lcd_power_data = {
618         .set_power      = h1940_lcd_power_set,
619 };
620
621 static struct platform_device h1940_lcd_powerdev = {
622         .name                   = "platform-lcd",
623         .dev.parent             = &s3c_device_lcd.dev,
624         .dev.platform_data      = &h1940_lcd_power_data,
625 };
626
627 static struct uda1380_platform_data uda1380_info = {
628         .gpio_power     = H1940_LATCH_UDA_POWER,
629         .gpio_reset     = S3C2410_GPA(12),
630         .dac_clk        = UDA1380_DAC_CLK_SYSCLK,
631 };
632
633 static struct i2c_board_info h1940_i2c_devices[] = {
634         {
635                 I2C_BOARD_INFO("uda1380", 0x1a),
636                 .platform_data = &uda1380_info,
637         },
638 };
639
640 #define DECLARE_BUTTON(p, k, n, w)      \
641         {                               \
642                 .gpio           = p,    \
643                 .code           = k,    \
644                 .desc           = n,    \
645                 .wakeup         = w,    \
646                 .active_low     = 1,    \
647         }
648
649 static struct gpio_keys_button h1940_buttons[] = {
650         DECLARE_BUTTON(S3C2410_GPF(0),       KEY_POWER,          "Power", 1),
651         DECLARE_BUTTON(S3C2410_GPF(6),       KEY_ENTER,         "Select", 1),
652         DECLARE_BUTTON(S3C2410_GPF(7),      KEY_RECORD,         "Record", 0),
653         DECLARE_BUTTON(S3C2410_GPG(0),         KEY_F11,       "Calendar", 0),
654         DECLARE_BUTTON(S3C2410_GPG(2),         KEY_F12,       "Contacts", 0),
655         DECLARE_BUTTON(S3C2410_GPG(3),        KEY_MAIL,           "Mail", 0),
656         DECLARE_BUTTON(S3C2410_GPG(6),        KEY_LEFT,     "Left_arrow", 0),
657         DECLARE_BUTTON(S3C2410_GPG(7),    KEY_HOMEPAGE,           "Home", 0),
658         DECLARE_BUTTON(S3C2410_GPG(8),       KEY_RIGHT,    "Right_arrow", 0),
659         DECLARE_BUTTON(S3C2410_GPG(9),          KEY_UP,       "Up_arrow", 0),
660         DECLARE_BUTTON(S3C2410_GPG(10),       KEY_DOWN,     "Down_arrow", 0),
661 };
662
663 static struct gpio_keys_platform_data h1940_buttons_data = {
664         .buttons        = h1940_buttons,
665         .nbuttons       = ARRAY_SIZE(h1940_buttons),
666 };
667
668 static struct platform_device h1940_dev_buttons = {
669         .name           = "gpio-keys",
670         .id             = -1,
671         .dev            = {
672                 .platform_data  = &h1940_buttons_data,
673         }
674 };
675
676 static struct platform_device *h1940_devices[] __initdata = {
677         &h1940_dev_buttons,
678         &s3c_device_ohci,
679         &s3c_device_lcd,
680         &s3c_device_wdt,
681         &s3c_device_i2c0,
682         &s3c_device_iis,
683         &s3c_device_usbgadget,
684         &h1940_device_leds,
685         &h1940_device_bluetooth,
686         &s3c_device_sdi,
687         &s3c_device_rtc,
688         &samsung_device_pwm,
689         &h1940_backlight,
690         &h1940_lcd_powerdev,
691         &s3c_device_adc,
692         &s3c_device_ts,
693         &power_supply,
694         &h1940_battery,
695         &h1940_audio,
696 };
697
698 static void __init h1940_map_io(void)
699 {
700         s3c24xx_init_io(h1940_iodesc, ARRAY_SIZE(h1940_iodesc));
701         s3c24xx_init_uarts(h1940_uartcfgs, ARRAY_SIZE(h1940_uartcfgs));
702         s3c24xx_set_timer_source(S3C24XX_PWM3, S3C24XX_PWM4);
703
704         /* setup PM */
705
706 #ifdef CONFIG_PM_H1940
707         memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 1024);
708 #endif
709         s3c_pm_init();
710
711         /* Add latch gpio chip, set latch initial value */
712         h1940_latch_control(0, 0);
713         WARN_ON(gpiochip_add_data(&h1940_latch_gpiochip, NULL));
714 }
715
716 static void __init h1940_init_time(void)
717 {
718         s3c2410_init_clocks(12000000);
719         s3c24xx_timer_init();
720 }
721
722 /* H1940 and RX3715 need to reserve this for suspend */
723 static void __init h1940_reserve(void)
724 {
725         memblock_reserve(0x30003000, 0x1000);
726         memblock_reserve(0x30081000, 0x1000);
727 }
728
729 static void __init h1940_init(void)
730 {
731         u32 tmp;
732
733         s3c24xx_fb_set_platdata(&h1940_fb_info);
734         gpiod_add_lookup_table(&h1940_udc_gpio_table);
735         gpiod_add_lookup_table(&h1940_mmc_gpio_table);
736         gpiod_add_lookup_table(&h1940_audio_gpio_table);
737         gpiod_add_lookup_table(&h1940_bat_gpio_table);
738         /* Configure the I2S pins (GPE0...GPE4) in correct mode */
739         s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
740                               S3C_GPIO_PULL_NONE);
741         s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
742         s3c24xx_udc_set_platdata(&h1940_udc_cfg);
743         s3c24xx_ts_set_platdata(&h1940_ts_cfg);
744         s3c_i2c0_set_platdata(NULL);
745
746         /* Turn off suspend on both USB ports, and switch the
747          * selectable USB port to USB device mode. */
748
749         s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
750                               S3C2410_MISCCR_USBSUSPND0 |
751                               S3C2410_MISCCR_USBSUSPND1, 0x0);
752
753         tmp =   (0x78 << S3C24XX_PLL_MDIV_SHIFT)
754               | (0x02 << S3C24XX_PLL_PDIV_SHIFT)
755               | (0x03 << S3C24XX_PLL_SDIV_SHIFT);
756         writel(tmp, S3C2410_UPLLCON);
757
758         gpio_request(S3C2410_GPC(0), "LCD power");
759         gpio_request(S3C2410_GPC(1), "LCD power");
760         gpio_request(S3C2410_GPC(4), "LCD power");
761         gpio_request(S3C2410_GPC(5), "LCD power");
762         gpio_request(S3C2410_GPC(6), "LCD power");
763         gpio_request(H1940_LATCH_LCD_P0, "LCD power");
764         gpio_request(H1940_LATCH_LCD_P1, "LCD power");
765         gpio_request(H1940_LATCH_LCD_P2, "LCD power");
766         gpio_request(H1940_LATCH_LCD_P3, "LCD power");
767         gpio_request(H1940_LATCH_LCD_P4, "LCD power");
768         gpio_request(H1940_LATCH_MAX1698_nSHUTDOWN, "LCD power");
769         gpio_direction_output(S3C2410_GPC(0), 0);
770         gpio_direction_output(S3C2410_GPC(1), 0);
771         gpio_direction_output(S3C2410_GPC(4), 0);
772         gpio_direction_output(S3C2410_GPC(5), 0);
773         gpio_direction_input(S3C2410_GPC(6));
774         gpio_direction_output(H1940_LATCH_LCD_P0, 0);
775         gpio_direction_output(H1940_LATCH_LCD_P1, 0);
776         gpio_direction_output(H1940_LATCH_LCD_P2, 0);
777         gpio_direction_output(H1940_LATCH_LCD_P3, 0);
778         gpio_direction_output(H1940_LATCH_LCD_P4, 0);
779         gpio_direction_output(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
780
781         gpio_request(H1940_LATCH_SD_POWER, "SD power");
782         gpio_direction_output(H1940_LATCH_SD_POWER, 0);
783
784         pwm_add_table(h1940_pwm_lookup, ARRAY_SIZE(h1940_pwm_lookup));
785         platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));
786
787         gpio_request(S3C2410_GPA(1), "Red LED blink");
788         gpio_request(S3C2410_GPA(3), "Blue LED blink");
789         gpio_request(S3C2410_GPA(7), "Green LED blink");
790         gpio_request(H1940_LATCH_LED_FLASH, "LED blink");
791         gpio_direction_output(S3C2410_GPA(1), 0);
792         gpio_direction_output(S3C2410_GPA(3), 0);
793         gpio_direction_output(S3C2410_GPA(7), 0);
794         gpio_direction_output(H1940_LATCH_LED_FLASH, 0);
795
796         i2c_register_board_info(0, h1940_i2c_devices,
797                 ARRAY_SIZE(h1940_i2c_devices));
798 }
799
800 MACHINE_START(H1940, "IPAQ-H1940")
801         /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
802         .atag_offset    = 0x100,
803         .nr_irqs        = NR_IRQS_S3C2410,
804         .map_io         = h1940_map_io,
805         .reserve        = h1940_reserve,
806         .init_irq       = s3c2410_init_irq,
807         .init_machine   = h1940_init,
808         .init_time      = h1940_init_time,
809 MACHINE_END