[media] v4l2: mem2mem: save irq flags correctly
[cascardo/linux.git] / drivers / gpio / gpio-samsung.c
1 /*
2  * Copyright (c) 2009-2011 Samsung Electronics Co., Ltd.
3  *              http://www.samsung.com/
4  *
5  * Copyright 2008 Openmoko, Inc.
6  * Copyright 2008 Simtec Electronics
7  *      Ben Dooks <ben@simtec.co.uk>
8  *      http://armlinux.simtec.co.uk/
9  *
10  * SAMSUNG - GPIOlib support
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/irq.h>
19 #include <linux/io.h>
20 #include <linux/gpio.h>
21 #include <linux/init.h>
22 #include <linux/spinlock.h>
23 #include <linux/module.h>
24 #include <linux/interrupt.h>
25 #include <linux/device.h>
26 #include <linux/ioport.h>
27 #include <linux/of.h>
28 #include <linux/slab.h>
29 #include <linux/of_address.h>
30
31 #include <asm/irq.h>
32
33 #include <mach/hardware.h>
34 #include <mach/map.h>
35 #include <mach/regs-clock.h>
36 #include <mach/regs-gpio.h>
37
38 #include <plat/cpu.h>
39 #include <plat/gpio-core.h>
40 #include <plat/gpio-cfg.h>
41 #include <plat/gpio-cfg-helpers.h>
42 #include <plat/gpio-fns.h>
43 #include <plat/pm.h>
44
45 #ifndef DEBUG_GPIO
46 #define gpio_dbg(x...) do { } while (0)
47 #else
48 #define gpio_dbg(x...) printk(KERN_DEBUG x)
49 #endif
50
51 int samsung_gpio_setpull_updown(struct samsung_gpio_chip *chip,
52                                 unsigned int off, samsung_gpio_pull_t pull)
53 {
54         void __iomem *reg = chip->base + 0x08;
55         int shift = off * 2;
56         u32 pup;
57
58         pup = __raw_readl(reg);
59         pup &= ~(3 << shift);
60         pup |= pull << shift;
61         __raw_writel(pup, reg);
62
63         return 0;
64 }
65
66 samsung_gpio_pull_t samsung_gpio_getpull_updown(struct samsung_gpio_chip *chip,
67                                                 unsigned int off)
68 {
69         void __iomem *reg = chip->base + 0x08;
70         int shift = off * 2;
71         u32 pup = __raw_readl(reg);
72
73         pup >>= shift;
74         pup &= 0x3;
75
76         return (__force samsung_gpio_pull_t)pup;
77 }
78
79 int s3c2443_gpio_setpull(struct samsung_gpio_chip *chip,
80                          unsigned int off, samsung_gpio_pull_t pull)
81 {
82         switch (pull) {
83         case S3C_GPIO_PULL_NONE:
84                 pull = 0x01;
85                 break;
86         case S3C_GPIO_PULL_UP:
87                 pull = 0x00;
88                 break;
89         case S3C_GPIO_PULL_DOWN:
90                 pull = 0x02;
91                 break;
92         }
93         return samsung_gpio_setpull_updown(chip, off, pull);
94 }
95
96 samsung_gpio_pull_t s3c2443_gpio_getpull(struct samsung_gpio_chip *chip,
97                                          unsigned int off)
98 {
99         samsung_gpio_pull_t pull;
100
101         pull = samsung_gpio_getpull_updown(chip, off);
102
103         switch (pull) {
104         case 0x00:
105                 pull = S3C_GPIO_PULL_UP;
106                 break;
107         case 0x01:
108         case 0x03:
109                 pull = S3C_GPIO_PULL_NONE;
110                 break;
111         case 0x02:
112                 pull = S3C_GPIO_PULL_DOWN;
113                 break;
114         }
115
116         return pull;
117 }
118
119 static int s3c24xx_gpio_setpull_1(struct samsung_gpio_chip *chip,
120                                   unsigned int off, samsung_gpio_pull_t pull,
121                                   samsung_gpio_pull_t updown)
122 {
123         void __iomem *reg = chip->base + 0x08;
124         u32 pup = __raw_readl(reg);
125
126         if (pull == updown)
127                 pup &= ~(1 << off);
128         else if (pull == S3C_GPIO_PULL_NONE)
129                 pup |= (1 << off);
130         else
131                 return -EINVAL;
132
133         __raw_writel(pup, reg);
134         return 0;
135 }
136
137 static samsung_gpio_pull_t s3c24xx_gpio_getpull_1(struct samsung_gpio_chip *chip,
138                                                   unsigned int off,
139                                                   samsung_gpio_pull_t updown)
140 {
141         void __iomem *reg = chip->base + 0x08;
142         u32 pup = __raw_readl(reg);
143
144         pup &= (1 << off);
145         return pup ? S3C_GPIO_PULL_NONE : updown;
146 }
147
148 samsung_gpio_pull_t s3c24xx_gpio_getpull_1up(struct samsung_gpio_chip *chip,
149                                              unsigned int off)
150 {
151         return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_UP);
152 }
153
154 int s3c24xx_gpio_setpull_1up(struct samsung_gpio_chip *chip,
155                              unsigned int off, samsung_gpio_pull_t pull)
156 {
157         return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_UP);
158 }
159
160 samsung_gpio_pull_t s3c24xx_gpio_getpull_1down(struct samsung_gpio_chip *chip,
161                                                unsigned int off)
162 {
163         return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_DOWN);
164 }
165
166 int s3c24xx_gpio_setpull_1down(struct samsung_gpio_chip *chip,
167                                unsigned int off, samsung_gpio_pull_t pull)
168 {
169         return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_DOWN);
170 }
171
172 static int exynos_gpio_setpull(struct samsung_gpio_chip *chip,
173                                 unsigned int off, samsung_gpio_pull_t pull)
174 {
175         if (pull == S3C_GPIO_PULL_UP)
176                 pull = 3;
177
178         return samsung_gpio_setpull_updown(chip, off, pull);
179 }
180
181 static samsung_gpio_pull_t exynos_gpio_getpull(struct samsung_gpio_chip *chip,
182                                                 unsigned int off)
183 {
184         samsung_gpio_pull_t pull;
185
186         pull = samsung_gpio_getpull_updown(chip, off);
187
188         if (pull == 3)
189                 pull = S3C_GPIO_PULL_UP;
190
191         return pull;
192 }
193
194 /*
195  * samsung_gpio_setcfg_2bit - Samsung 2bit style GPIO configuration.
196  * @chip: The gpio chip that is being configured.
197  * @off: The offset for the GPIO being configured.
198  * @cfg: The configuration value to set.
199  *
200  * This helper deal with the GPIO cases where the control register
201  * has two bits of configuration per gpio, which have the following
202  * functions:
203  *      00 = input
204  *      01 = output
205  *      1x = special function
206  */
207
208 static int samsung_gpio_setcfg_2bit(struct samsung_gpio_chip *chip,
209                                     unsigned int off, unsigned int cfg)
210 {
211         void __iomem *reg = chip->base;
212         unsigned int shift = off * 2;
213         u32 con;
214
215         if (samsung_gpio_is_cfg_special(cfg)) {
216                 cfg &= 0xf;
217                 if (cfg > 3)
218                         return -EINVAL;
219
220                 cfg <<= shift;
221         }
222
223         con = __raw_readl(reg);
224         con &= ~(0x3 << shift);
225         con |= cfg;
226         __raw_writel(con, reg);
227
228         return 0;
229 }
230
231 /*
232  * samsung_gpio_getcfg_2bit - Samsung 2bit style GPIO configuration read.
233  * @chip: The gpio chip that is being configured.
234  * @off: The offset for the GPIO being configured.
235  *
236  * The reverse of samsung_gpio_setcfg_2bit(). Will return a value which
237  * could be directly passed back to samsung_gpio_setcfg_2bit(), from the
238  * S3C_GPIO_SPECIAL() macro.
239  */
240
241 static unsigned int samsung_gpio_getcfg_2bit(struct samsung_gpio_chip *chip,
242                                              unsigned int off)
243 {
244         u32 con;
245
246         con = __raw_readl(chip->base);
247         con >>= off * 2;
248         con &= 3;
249
250         /* this conversion works for IN and OUT as well as special mode */
251         return S3C_GPIO_SPECIAL(con);
252 }
253
254 /*
255  * samsung_gpio_setcfg_4bit - Samsung 4bit single register GPIO config.
256  * @chip: The gpio chip that is being configured.
257  * @off: The offset for the GPIO being configured.
258  * @cfg: The configuration value to set.
259  *
260  * This helper deal with the GPIO cases where the control register has 4 bits
261  * of control per GPIO, generally in the form of:
262  *      0000 = Input
263  *      0001 = Output
264  *      others = Special functions (dependent on bank)
265  *
266  * Note, since the code to deal with the case where there are two control
267  * registers instead of one, we do not have a separate set of functions for
268  * each case.
269  */
270
271 static int samsung_gpio_setcfg_4bit(struct samsung_gpio_chip *chip,
272                                     unsigned int off, unsigned int cfg)
273 {
274         void __iomem *reg = chip->base;
275         unsigned int shift = (off & 7) * 4;
276         u32 con;
277
278         if (off < 8 && chip->chip.ngpio > 8)
279                 reg -= 4;
280
281         if (samsung_gpio_is_cfg_special(cfg)) {
282                 cfg &= 0xf;
283                 cfg <<= shift;
284         }
285
286         con = __raw_readl(reg);
287         con &= ~(0xf << shift);
288         con |= cfg;
289         __raw_writel(con, reg);
290
291         return 0;
292 }
293
294 /*
295  * samsung_gpio_getcfg_4bit - Samsung 4bit single register GPIO config read.
296  * @chip: The gpio chip that is being configured.
297  * @off: The offset for the GPIO being configured.
298  *
299  * The reverse of samsung_gpio_setcfg_4bit(), turning a gpio configuration
300  * register setting into a value the software can use, such as could be passed
301  * to samsung_gpio_setcfg_4bit().
302  *
303  * @sa samsung_gpio_getcfg_2bit
304  */
305
306 static unsigned samsung_gpio_getcfg_4bit(struct samsung_gpio_chip *chip,
307                                          unsigned int off)
308 {
309         void __iomem *reg = chip->base;
310         unsigned int shift = (off & 7) * 4;
311         u32 con;
312
313         if (off < 8 && chip->chip.ngpio > 8)
314                 reg -= 4;
315
316         con = __raw_readl(reg);
317         con >>= shift;
318         con &= 0xf;
319
320         /* this conversion works for IN and OUT as well as special mode */
321         return S3C_GPIO_SPECIAL(con);
322 }
323
324 #ifdef CONFIG_PLAT_S3C24XX
325 /*
326  * s3c24xx_gpio_setcfg_abank - S3C24XX style GPIO configuration (Bank A)
327  * @chip: The gpio chip that is being configured.
328  * @off: The offset for the GPIO being configured.
329  * @cfg: The configuration value to set.
330  *
331  * This helper deal with the GPIO cases where the control register
332  * has one bit of configuration for the gpio, where setting the bit
333  * means the pin is in special function mode and unset means output.
334  */
335
336 static int s3c24xx_gpio_setcfg_abank(struct samsung_gpio_chip *chip,
337                                      unsigned int off, unsigned int cfg)
338 {
339         void __iomem *reg = chip->base;
340         unsigned int shift = off;
341         u32 con;
342
343         if (samsung_gpio_is_cfg_special(cfg)) {
344                 cfg &= 0xf;
345
346                 /* Map output to 0, and SFN2 to 1 */
347                 cfg -= 1;
348                 if (cfg > 1)
349                         return -EINVAL;
350
351                 cfg <<= shift;
352         }
353
354         con = __raw_readl(reg);
355         con &= ~(0x1 << shift);
356         con |= cfg;
357         __raw_writel(con, reg);
358
359         return 0;
360 }
361
362 /*
363  * s3c24xx_gpio_getcfg_abank - S3C24XX style GPIO configuration read (Bank A)
364  * @chip: The gpio chip that is being configured.
365  * @off: The offset for the GPIO being configured.
366  *
367  * The reverse of s3c24xx_gpio_setcfg_abank() turning an GPIO into a usable
368  * GPIO configuration value.
369  *
370  * @sa samsung_gpio_getcfg_2bit
371  * @sa samsung_gpio_getcfg_4bit
372  */
373
374 static unsigned s3c24xx_gpio_getcfg_abank(struct samsung_gpio_chip *chip,
375                                           unsigned int off)
376 {
377         u32 con;
378
379         con = __raw_readl(chip->base);
380         con >>= off;
381         con &= 1;
382         con++;
383
384         return S3C_GPIO_SFN(con);
385 }
386 #endif
387
388 #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
389 static int s5p64x0_gpio_setcfg_rbank(struct samsung_gpio_chip *chip,
390                                      unsigned int off, unsigned int cfg)
391 {
392         void __iomem *reg = chip->base;
393         unsigned int shift;
394         u32 con;
395
396         switch (off) {
397         case 0:
398         case 1:
399         case 2:
400         case 3:
401         case 4:
402         case 5:
403                 shift = (off & 7) * 4;
404                 reg -= 4;
405                 break;
406         case 6:
407                 shift = ((off + 1) & 7) * 4;
408                 reg -= 4;
409         default:
410                 shift = ((off + 1) & 7) * 4;
411                 break;
412         }
413
414         if (samsung_gpio_is_cfg_special(cfg)) {
415                 cfg &= 0xf;
416                 cfg <<= shift;
417         }
418
419         con = __raw_readl(reg);
420         con &= ~(0xf << shift);
421         con |= cfg;
422         __raw_writel(con, reg);
423
424         return 0;
425 }
426 #endif
427
428 static void __init samsung_gpiolib_set_cfg(struct samsung_gpio_cfg *chipcfg,
429                                            int nr_chips)
430 {
431         for (; nr_chips > 0; nr_chips--, chipcfg++) {
432                 if (!chipcfg->set_config)
433                         chipcfg->set_config = samsung_gpio_setcfg_4bit;
434                 if (!chipcfg->get_config)
435                         chipcfg->get_config = samsung_gpio_getcfg_4bit;
436                 if (!chipcfg->set_pull)
437                         chipcfg->set_pull = samsung_gpio_setpull_updown;
438                 if (!chipcfg->get_pull)
439                         chipcfg->get_pull = samsung_gpio_getpull_updown;
440         }
441 }
442
443 struct samsung_gpio_cfg s3c24xx_gpiocfg_default = {
444         .set_config     = samsung_gpio_setcfg_2bit,
445         .get_config     = samsung_gpio_getcfg_2bit,
446 };
447
448 #ifdef CONFIG_PLAT_S3C24XX
449 static struct samsung_gpio_cfg s3c24xx_gpiocfg_banka = {
450         .set_config     = s3c24xx_gpio_setcfg_abank,
451         .get_config     = s3c24xx_gpio_getcfg_abank,
452 };
453 #endif
454
455 #if defined(CONFIG_ARCH_EXYNOS4) || defined(CONFIG_ARCH_EXYNOS5)
456 static struct samsung_gpio_cfg exynos_gpio_cfg = {
457         .set_pull       = exynos_gpio_setpull,
458         .get_pull       = exynos_gpio_getpull,
459         .set_config     = samsung_gpio_setcfg_4bit,
460         .get_config     = samsung_gpio_getcfg_4bit,
461 };
462 #endif
463
464 #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
465 static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank = {
466         .cfg_eint       = 0x3,
467         .set_config     = s5p64x0_gpio_setcfg_rbank,
468         .get_config     = samsung_gpio_getcfg_4bit,
469         .set_pull       = samsung_gpio_setpull_updown,
470         .get_pull       = samsung_gpio_getpull_updown,
471 };
472 #endif
473
474 static struct samsung_gpio_cfg samsung_gpio_cfgs[] = {
475         [0] = {
476                 .cfg_eint       = 0x0,
477         },
478         [1] = {
479                 .cfg_eint       = 0x3,
480         },
481         [2] = {
482                 .cfg_eint       = 0x7,
483         },
484         [3] = {
485                 .cfg_eint       = 0xF,
486         },
487         [4] = {
488                 .cfg_eint       = 0x0,
489                 .set_config     = samsung_gpio_setcfg_2bit,
490                 .get_config     = samsung_gpio_getcfg_2bit,
491         },
492         [5] = {
493                 .cfg_eint       = 0x2,
494                 .set_config     = samsung_gpio_setcfg_2bit,
495                 .get_config     = samsung_gpio_getcfg_2bit,
496         },
497         [6] = {
498                 .cfg_eint       = 0x3,
499                 .set_config     = samsung_gpio_setcfg_2bit,
500                 .get_config     = samsung_gpio_getcfg_2bit,
501         },
502         [7] = {
503                 .set_config     = samsung_gpio_setcfg_2bit,
504                 .get_config     = samsung_gpio_getcfg_2bit,
505         },
506         [8] = {
507                 .set_pull       = exynos_gpio_setpull,
508                 .get_pull       = exynos_gpio_getpull,
509         },
510         [9] = {
511                 .cfg_eint       = 0x3,
512                 .set_pull       = exynos_gpio_setpull,
513                 .get_pull       = exynos_gpio_getpull,
514         }
515 };
516
517 /*
518  * Default routines for controlling GPIO, based on the original S3C24XX
519  * GPIO functions which deal with the case where each gpio bank of the
520  * chip is as following:
521  *
522  * base + 0x00: Control register, 2 bits per gpio
523  *              gpio n: 2 bits starting at (2*n)
524  *              00 = input, 01 = output, others mean special-function
525  * base + 0x04: Data register, 1 bit per gpio
526  *              bit n: data bit n
527 */
528
529 static int samsung_gpiolib_2bit_input(struct gpio_chip *chip, unsigned offset)
530 {
531         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
532         void __iomem *base = ourchip->base;
533         unsigned long flags;
534         unsigned long con;
535
536         samsung_gpio_lock(ourchip, flags);
537
538         con = __raw_readl(base + 0x00);
539         con &= ~(3 << (offset * 2));
540
541         __raw_writel(con, base + 0x00);
542
543         samsung_gpio_unlock(ourchip, flags);
544         return 0;
545 }
546
547 static int samsung_gpiolib_2bit_output(struct gpio_chip *chip,
548                                        unsigned offset, int value)
549 {
550         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
551         void __iomem *base = ourchip->base;
552         unsigned long flags;
553         unsigned long dat;
554         unsigned long con;
555
556         samsung_gpio_lock(ourchip, flags);
557
558         dat = __raw_readl(base + 0x04);
559         dat &= ~(1 << offset);
560         if (value)
561                 dat |= 1 << offset;
562         __raw_writel(dat, base + 0x04);
563
564         con = __raw_readl(base + 0x00);
565         con &= ~(3 << (offset * 2));
566         con |= 1 << (offset * 2);
567
568         __raw_writel(con, base + 0x00);
569         __raw_writel(dat, base + 0x04);
570
571         samsung_gpio_unlock(ourchip, flags);
572         return 0;
573 }
574
575 /*
576  * The samsung_gpiolib_4bit routines are to control the gpio banks where
577  * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the
578  * following example:
579  *
580  * base + 0x00: Control register, 4 bits per gpio
581  *              gpio n: 4 bits starting at (4*n)
582  *              0000 = input, 0001 = output, others mean special-function
583  * base + 0x04: Data register, 1 bit per gpio
584  *              bit n: data bit n
585  *
586  * Note, since the data register is one bit per gpio and is at base + 0x4
587  * we can use samsung_gpiolib_get and samsung_gpiolib_set to change the
588  * state of the output.
589  */
590
591 static int samsung_gpiolib_4bit_input(struct gpio_chip *chip,
592                                       unsigned int offset)
593 {
594         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
595         void __iomem *base = ourchip->base;
596         unsigned long con;
597
598         con = __raw_readl(base + GPIOCON_OFF);
599         con &= ~(0xf << con_4bit_shift(offset));
600         __raw_writel(con, base + GPIOCON_OFF);
601
602         gpio_dbg("%s: %p: CON now %08lx\n", __func__, base, con);
603
604         return 0;
605 }
606
607 static int samsung_gpiolib_4bit_output(struct gpio_chip *chip,
608                                        unsigned int offset, int value)
609 {
610         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
611         void __iomem *base = ourchip->base;
612         unsigned long con;
613         unsigned long dat;
614
615         con = __raw_readl(base + GPIOCON_OFF);
616         con &= ~(0xf << con_4bit_shift(offset));
617         con |= 0x1 << con_4bit_shift(offset);
618
619         dat = __raw_readl(base + GPIODAT_OFF);
620
621         if (value)
622                 dat |= 1 << offset;
623         else
624                 dat &= ~(1 << offset);
625
626         __raw_writel(dat, base + GPIODAT_OFF);
627         __raw_writel(con, base + GPIOCON_OFF);
628         __raw_writel(dat, base + GPIODAT_OFF);
629
630         gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
631
632         return 0;
633 }
634
635 /*
636  * The next set of routines are for the case where the GPIO configuration
637  * registers are 4 bits per GPIO but there is more than one register (the
638  * bank has more than 8 GPIOs.
639  *
640  * This case is the similar to the 4 bit case, but the registers are as
641  * follows:
642  *
643  * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs)
644  *              gpio n: 4 bits starting at (4*n)
645  *              0000 = input, 0001 = output, others mean special-function
646  * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs)
647  *              gpio n: 4 bits starting at (4*n)
648  *              0000 = input, 0001 = output, others mean special-function
649  * base + 0x08: Data register, 1 bit per gpio
650  *              bit n: data bit n
651  *
652  * To allow us to use the samsung_gpiolib_get and samsung_gpiolib_set
653  * routines we store the 'base + 0x4' address so that these routines see
654  * the data register at ourchip->base + 0x04.
655  */
656
657 static int samsung_gpiolib_4bit2_input(struct gpio_chip *chip,
658                                        unsigned int offset)
659 {
660         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
661         void __iomem *base = ourchip->base;
662         void __iomem *regcon = base;
663         unsigned long con;
664
665         if (offset > 7)
666                 offset -= 8;
667         else
668                 regcon -= 4;
669
670         con = __raw_readl(regcon);
671         con &= ~(0xf << con_4bit_shift(offset));
672         __raw_writel(con, regcon);
673
674         gpio_dbg("%s: %p: CON %08lx\n", __func__, base, con);
675
676         return 0;
677 }
678
679 static int samsung_gpiolib_4bit2_output(struct gpio_chip *chip,
680                                         unsigned int offset, int value)
681 {
682         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
683         void __iomem *base = ourchip->base;
684         void __iomem *regcon = base;
685         unsigned long con;
686         unsigned long dat;
687         unsigned con_offset = offset;
688
689         if (con_offset > 7)
690                 con_offset -= 8;
691         else
692                 regcon -= 4;
693
694         con = __raw_readl(regcon);
695         con &= ~(0xf << con_4bit_shift(con_offset));
696         con |= 0x1 << con_4bit_shift(con_offset);
697
698         dat = __raw_readl(base + GPIODAT_OFF);
699
700         if (value)
701                 dat |= 1 << offset;
702         else
703                 dat &= ~(1 << offset);
704
705         __raw_writel(dat, base + GPIODAT_OFF);
706         __raw_writel(con, regcon);
707         __raw_writel(dat, base + GPIODAT_OFF);
708
709         gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
710
711         return 0;
712 }
713
714 #ifdef CONFIG_PLAT_S3C24XX
715 /* The next set of routines are for the case of s3c24xx bank a */
716
717 static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
718 {
719         return -EINVAL;
720 }
721
722 static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
723                                         unsigned offset, int value)
724 {
725         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
726         void __iomem *base = ourchip->base;
727         unsigned long flags;
728         unsigned long dat;
729         unsigned long con;
730
731         local_irq_save(flags);
732
733         con = __raw_readl(base + 0x00);
734         dat = __raw_readl(base + 0x04);
735
736         dat &= ~(1 << offset);
737         if (value)
738                 dat |= 1 << offset;
739
740         __raw_writel(dat, base + 0x04);
741
742         con &= ~(1 << offset);
743
744         __raw_writel(con, base + 0x00);
745         __raw_writel(dat, base + 0x04);
746
747         local_irq_restore(flags);
748         return 0;
749 }
750 #endif
751
752 /* The next set of routines are for the case of s5p64x0 bank r */
753
754 static int s5p64x0_gpiolib_rbank_input(struct gpio_chip *chip,
755                                        unsigned int offset)
756 {
757         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
758         void __iomem *base = ourchip->base;
759         void __iomem *regcon = base;
760         unsigned long con;
761         unsigned long flags;
762
763         switch (offset) {
764         case 6:
765                 offset += 1;
766         case 0:
767         case 1:
768         case 2:
769         case 3:
770         case 4:
771         case 5:
772                 regcon -= 4;
773                 break;
774         default:
775                 offset -= 7;
776                 break;
777         }
778
779         samsung_gpio_lock(ourchip, flags);
780
781         con = __raw_readl(regcon);
782         con &= ~(0xf << con_4bit_shift(offset));
783         __raw_writel(con, regcon);
784
785         samsung_gpio_unlock(ourchip, flags);
786
787         return 0;
788 }
789
790 static int s5p64x0_gpiolib_rbank_output(struct gpio_chip *chip,
791                                         unsigned int offset, int value)
792 {
793         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
794         void __iomem *base = ourchip->base;
795         void __iomem *regcon = base;
796         unsigned long con;
797         unsigned long dat;
798         unsigned long flags;
799         unsigned con_offset  = offset;
800
801         switch (con_offset) {
802         case 6:
803                 con_offset += 1;
804         case 0:
805         case 1:
806         case 2:
807         case 3:
808         case 4:
809         case 5:
810                 regcon -= 4;
811                 break;
812         default:
813                 con_offset -= 7;
814                 break;
815         }
816
817         samsung_gpio_lock(ourchip, flags);
818
819         con = __raw_readl(regcon);
820         con &= ~(0xf << con_4bit_shift(con_offset));
821         con |= 0x1 << con_4bit_shift(con_offset);
822
823         dat = __raw_readl(base + GPIODAT_OFF);
824         if (value)
825                 dat |= 1 << offset;
826         else
827                 dat &= ~(1 << offset);
828
829         __raw_writel(con, regcon);
830         __raw_writel(dat, base + GPIODAT_OFF);
831
832         samsung_gpio_unlock(ourchip, flags);
833
834         return 0;
835 }
836
837 static void samsung_gpiolib_set(struct gpio_chip *chip,
838                                 unsigned offset, int value)
839 {
840         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
841         void __iomem *base = ourchip->base;
842         unsigned long flags;
843         unsigned long dat;
844
845         samsung_gpio_lock(ourchip, flags);
846
847         dat = __raw_readl(base + 0x04);
848         dat &= ~(1 << offset);
849         if (value)
850                 dat |= 1 << offset;
851         __raw_writel(dat, base + 0x04);
852
853         samsung_gpio_unlock(ourchip, flags);
854 }
855
856 static int samsung_gpiolib_get(struct gpio_chip *chip, unsigned offset)
857 {
858         struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
859         unsigned long val;
860
861         val = __raw_readl(ourchip->base + 0x04);
862         val >>= offset;
863         val &= 1;
864
865         return val;
866 }
867
868 /*
869  * CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios
870  * for use with the configuration calls, and other parts of the s3c gpiolib
871  * support code.
872  *
873  * Not all s3c support code will need this, as some configurations of cpu
874  * may only support one or two different configuration options and have an
875  * easy gpio to samsung_gpio_chip mapping function. If this is the case, then
876  * the machine support file should provide its own samsung_gpiolib_getchip()
877  * and any other necessary functions.
878  */
879
880 #ifdef CONFIG_S3C_GPIO_TRACK
881 struct samsung_gpio_chip *s3c_gpios[S3C_GPIO_END];
882
883 static __init void s3c_gpiolib_track(struct samsung_gpio_chip *chip)
884 {
885         unsigned int gpn;
886         int i;
887
888         gpn = chip->chip.base;
889         for (i = 0; i < chip->chip.ngpio; i++, gpn++) {
890                 BUG_ON(gpn >= ARRAY_SIZE(s3c_gpios));
891                 s3c_gpios[gpn] = chip;
892         }
893 }
894 #endif /* CONFIG_S3C_GPIO_TRACK */
895
896 static __init void exynos_gpiolib_powerdown_cfg(struct samsung_gpio_chip *chip)
897 {
898         struct property *prop;
899         int i, prop_count;
900         const __be32 *val_ptr;
901         u32 con_pdn, pud_pdn;
902
903         if (!of_find_property(chip->chip.of_node, "powerdown-support", NULL))
904                 return;
905
906         chip->pdn_supported = true; /* Indicate this chip supports saving */
907         prop = of_find_property(chip->chip.of_node, "powerdown-settings", NULL);
908         if (!prop)
909                 return;
910
911         prop_count = prop->length / sizeof(u32);
912         if (prop_count != chip->chip.ngpio) {
913                 pr_warn("%s: powerdown-settings has %d entries, %d expected\n",
914                         chip->chip.label, prop_count, chip->chip.ngpio);
915                 return;
916         }
917         if (prop_count > 16) {
918                 pr_warn("%s: powerdown-settings has %d entries (max 16)\n",
919                         chip->chip.label, prop_count);
920                 return;
921         }
922
923         val_ptr = prop->value;
924         con_pdn = __raw_readl(chip->base + GPIOCONPDN_OFF);
925         pud_pdn = __raw_readl(chip->base + GPIOPUDPDN_OFF);
926
927         for (i = 0; i < prop_count; i++) {
928                 u32 value = be32_to_cpup(val_ptr++);
929                 if (!value)
930                         continue; /* 0 = use existing */
931                 con_pdn &= ~(0x3 << (i * 2));
932                 pud_pdn &= ~(0x3 << (i * 2));
933                 switch (value) {
934                 case 1: /* Float */
935                         con_pdn |= 0x2 << (i * 2);
936                         /* pud_pdn |= 0x0 << (i * 2); */
937                         break;
938                 case 2: /* Pull up */
939                         con_pdn |= 0x2 << (i * 2);
940                         pud_pdn |= 0x3 << (i * 2);
941                         break;
942                 case 3: /* Pull down */
943                         con_pdn |= 0x2 << (i * 2);
944                         pud_pdn |= 0x1 << (i * 2);
945                         break;
946                 case 4: /* Drive high */
947                         con_pdn |= 0x1 << (i * 2);
948                         /* pud_pdn |= 0x0 << (i * 2); */
949                         break;
950                 case 5: /* Drive low */
951                         /* con_pdn |= 0x0 << (i * 2); */
952                         /* pud_pdn |= 0x0 << (i * 2); */
953                         break;
954                 case 6: /* Maintain powerup settings */
955                         con_pdn |= 0x3 << (i * 2);
956                         /* pud_pdn |= 0x0 << (i * 2); */
957                         break;
958                 default:
959                         pr_warn("%s(%d): powerdown-settings illegal value %d\n",
960                                 chip->chip.label, i, value);
961                 }
962         }
963         __raw_writel(con_pdn, chip->base + GPIOCONPDN_OFF);
964         __raw_writel(pud_pdn, chip->base + GPIOPUDPDN_OFF);
965 }
966
967 /*
968  * samsung_gpiolib_add() - add the Samsung gpio_chip.
969  * @chip: The chip to register
970  *
971  * This is a wrapper to gpiochip_add() that takes our specific gpio chip
972  * information and makes the necessary alterations for the platform and
973  * notes the information for use with the configuration systems and any
974  * other parts of the system.
975  */
976
977 static void __init samsung_gpiolib_add(struct samsung_gpio_chip *chip)
978 {
979         struct gpio_chip *gc = &chip->chip;
980         int ret;
981
982         BUG_ON(!chip->base);
983         BUG_ON(!gc->label);
984         BUG_ON(!gc->ngpio);
985
986         spin_lock_init(&chip->lock);
987
988         if (!gc->direction_input)
989                 gc->direction_input = samsung_gpiolib_2bit_input;
990         if (!gc->direction_output)
991                 gc->direction_output = samsung_gpiolib_2bit_output;
992         if (!gc->set)
993                 gc->set = samsung_gpiolib_set;
994         if (!gc->get)
995                 gc->get = samsung_gpiolib_get;
996
997 #ifdef CONFIG_PM
998         if (chip->pm != NULL) {
999                 if (!chip->pm->save || !chip->pm->resume)
1000                         printk(KERN_ERR "gpio: %s has missing PM functions\n",
1001                                gc->label);
1002         } else
1003                 printk(KERN_ERR "gpio: %s has no PM function\n", gc->label);
1004 #endif
1005 #ifdef CONFIG_OF
1006         exynos_gpiolib_powerdown_cfg(chip);
1007 #endif
1008
1009         /* gpiochip_add() prints own failure message on error. */
1010         ret = gpiochip_add(gc);
1011         if (ret >= 0)
1012                 s3c_gpiolib_track(chip);
1013 }
1014
1015 static void __init s3c24xx_gpiolib_add_chips(struct samsung_gpio_chip *chip,
1016                                              int nr_chips, void __iomem *base)
1017 {
1018         int i;
1019         struct gpio_chip *gc = &chip->chip;
1020
1021         for (i = 0 ; i < nr_chips; i++, chip++) {
1022                 /* skip banks not present on SoC */
1023                 if (chip->chip.base >= S3C_GPIO_END)
1024                         continue;
1025
1026                 if (!chip->config)
1027                         chip->config = &s3c24xx_gpiocfg_default;
1028                 if (!chip->pm)
1029                         chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
1030                 if ((base != NULL) && (chip->base == NULL))
1031                         chip->base = base + ((i) * 0x10);
1032
1033                 if (!gc->direction_input)
1034                         gc->direction_input = samsung_gpiolib_2bit_input;
1035                 if (!gc->direction_output)
1036                         gc->direction_output = samsung_gpiolib_2bit_output;
1037
1038                 samsung_gpiolib_add(chip);
1039         }
1040 }
1041
1042 static void __init samsung_gpiolib_add_2bit_chips(struct samsung_gpio_chip *chip,
1043                                                   int nr_chips, void __iomem *base,
1044                                                   unsigned int offset)
1045 {
1046         int i;
1047
1048         for (i = 0 ; i < nr_chips; i++, chip++) {
1049                 chip->chip.direction_input = samsung_gpiolib_2bit_input;
1050                 chip->chip.direction_output = samsung_gpiolib_2bit_output;
1051
1052                 if (!chip->config)
1053                         chip->config = &samsung_gpio_cfgs[7];
1054                 if (!chip->pm)
1055                         chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
1056                 if ((base != NULL) && (chip->base == NULL))
1057                         chip->base = base + ((i) * offset);
1058
1059                 samsung_gpiolib_add(chip);
1060         }
1061 }
1062
1063 /*
1064  * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
1065  * @chip: The gpio chip that is being configured.
1066  * @nr_chips: The no of chips (gpio ports) for the GPIO being configured.
1067  *
1068  * This helper deal with the GPIO cases where the control register has 4 bits
1069  * of control per GPIO, generally in the form of:
1070  * 0000 = Input
1071  * 0001 = Output
1072  * others = Special functions (dependent on bank)
1073  *
1074  * Note, since the code to deal with the case where there are two control
1075  * registers instead of one, we do not have a separate set of function
1076  * (samsung_gpiolib_add_4bit2_chips)for each case.
1077  */
1078
1079 static void __init samsung_gpiolib_add_4bit_chips(struct samsung_gpio_chip *chip,
1080                                                   int nr_chips, void __iomem *base)
1081 {
1082         int i;
1083
1084         for (i = 0 ; i < nr_chips; i++, chip++) {
1085                 chip->chip.direction_input = samsung_gpiolib_4bit_input;
1086                 chip->chip.direction_output = samsung_gpiolib_4bit_output;
1087
1088                 if (!chip->config)
1089                         chip->config = &samsung_gpio_cfgs[2];
1090                 if (!chip->pm)
1091                         chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
1092                 if ((base != NULL) && (chip->base == NULL))
1093                         chip->base = base + ((i) * 0x20);
1094
1095                 samsung_gpiolib_add(chip);
1096         }
1097 }
1098
1099 static void __init samsung_gpiolib_add_4bit2_chips(struct samsung_gpio_chip *chip,
1100                                                    int nr_chips)
1101 {
1102         for (; nr_chips > 0; nr_chips--, chip++) {
1103                 chip->chip.direction_input = samsung_gpiolib_4bit2_input;
1104                 chip->chip.direction_output = samsung_gpiolib_4bit2_output;
1105
1106                 if (!chip->config)
1107                         chip->config = &samsung_gpio_cfgs[2];
1108                 if (!chip->pm)
1109                         chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
1110
1111                 samsung_gpiolib_add(chip);
1112         }
1113 }
1114
1115 static void __init s5p64x0_gpiolib_add_rbank(struct samsung_gpio_chip *chip,
1116                                              int nr_chips)
1117 {
1118         for (; nr_chips > 0; nr_chips--, chip++) {
1119                 chip->chip.direction_input = s5p64x0_gpiolib_rbank_input;
1120                 chip->chip.direction_output = s5p64x0_gpiolib_rbank_output;
1121
1122                 if (!chip->pm)
1123                         chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
1124
1125                 samsung_gpiolib_add(chip);
1126         }
1127 }
1128
1129 int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)
1130 {
1131         struct samsung_gpio_chip *samsung_chip = container_of(chip, struct samsung_gpio_chip, chip);
1132
1133         return samsung_chip->irq_base + offset;
1134 }
1135
1136 #ifdef CONFIG_PLAT_S3C24XX
1137 static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip *chip, unsigned offset)
1138 {
1139         if (offset < 4)
1140                 return IRQ_EINT0 + offset;
1141
1142         if (offset < 8)
1143                 return IRQ_EINT4 + offset - 4;
1144
1145         return -EINVAL;
1146 }
1147 #endif
1148
1149 #ifdef CONFIG_PLAT_S3C64XX
1150 static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip *chip, unsigned pin)
1151 {
1152         return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO;
1153 }
1154
1155 static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip *chip, unsigned pin)
1156 {
1157         return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO;
1158 }
1159 #endif
1160
1161 struct samsung_gpio_chip s3c24xx_gpios[] = {
1162 #ifdef CONFIG_PLAT_S3C24XX
1163         {
1164                 .config = &s3c24xx_gpiocfg_banka,
1165                 .chip   = {
1166                         .base                   = S3C2410_GPA(0),
1167                         .owner                  = THIS_MODULE,
1168                         .label                  = "GPIOA",
1169                         .ngpio                  = 24,
1170                         .direction_input        = s3c24xx_gpiolib_banka_input,
1171                         .direction_output       = s3c24xx_gpiolib_banka_output,
1172                 },
1173         }, {
1174                 .chip   = {
1175                         .base   = S3C2410_GPB(0),
1176                         .owner  = THIS_MODULE,
1177                         .label  = "GPIOB",
1178                         .ngpio  = 16,
1179                 },
1180         }, {
1181                 .chip   = {
1182                         .base   = S3C2410_GPC(0),
1183                         .owner  = THIS_MODULE,
1184                         .label  = "GPIOC",
1185                         .ngpio  = 16,
1186                 },
1187         }, {
1188                 .chip   = {
1189                         .base   = S3C2410_GPD(0),
1190                         .owner  = THIS_MODULE,
1191                         .label  = "GPIOD",
1192                         .ngpio  = 16,
1193                 },
1194         }, {
1195                 .chip   = {
1196                         .base   = S3C2410_GPE(0),
1197                         .label  = "GPIOE",
1198                         .owner  = THIS_MODULE,
1199                         .ngpio  = 16,
1200                 },
1201         }, {
1202                 .chip   = {
1203                         .base   = S3C2410_GPF(0),
1204                         .owner  = THIS_MODULE,
1205                         .label  = "GPIOF",
1206                         .ngpio  = 8,
1207                         .to_irq = s3c24xx_gpiolib_fbank_to_irq,
1208                 },
1209         }, {
1210                 .irq_base = IRQ_EINT8,
1211                 .chip   = {
1212                         .base   = S3C2410_GPG(0),
1213                         .owner  = THIS_MODULE,
1214                         .label  = "GPIOG",
1215                         .ngpio  = 16,
1216                         .to_irq = samsung_gpiolib_to_irq,
1217                 },
1218         }, {
1219                 .chip   = {
1220                         .base   = S3C2410_GPH(0),
1221                         .owner  = THIS_MODULE,
1222                         .label  = "GPIOH",
1223                         .ngpio  = 11,
1224                 },
1225         },
1226                 /* GPIOS for the S3C2443 and later devices. */
1227         {
1228                 .base   = S3C2440_GPJCON,
1229                 .chip   = {
1230                         .base   = S3C2410_GPJ(0),
1231                         .owner  = THIS_MODULE,
1232                         .label  = "GPIOJ",
1233                         .ngpio  = 16,
1234                 },
1235         }, {
1236                 .base   = S3C2443_GPKCON,
1237                 .chip   = {
1238                         .base   = S3C2410_GPK(0),
1239                         .owner  = THIS_MODULE,
1240                         .label  = "GPIOK",
1241                         .ngpio  = 16,
1242                 },
1243         }, {
1244                 .base   = S3C2443_GPLCON,
1245                 .chip   = {
1246                         .base   = S3C2410_GPL(0),
1247                         .owner  = THIS_MODULE,
1248                         .label  = "GPIOL",
1249                         .ngpio  = 15,
1250                 },
1251         }, {
1252                 .base   = S3C2443_GPMCON,
1253                 .chip   = {
1254                         .base   = S3C2410_GPM(0),
1255                         .owner  = THIS_MODULE,
1256                         .label  = "GPIOM",
1257                         .ngpio  = 2,
1258                 },
1259         },
1260 #endif
1261 };
1262
1263 /*
1264  * GPIO bank summary:
1265  *
1266  * Bank GPIOs   Style   SlpCon  ExtInt Group
1267  * A    8       4Bit    Yes     1
1268  * B    7       4Bit    Yes     1
1269  * C    8       4Bit    Yes     2
1270  * D    5       4Bit    Yes     3
1271  * E    5       4Bit    Yes     None
1272  * F    16      2Bit    Yes     4 [1]
1273  * G    7       4Bit    Yes     5
1274  * H    10      4Bit[2] Yes     6
1275  * I    16      2Bit    Yes     None
1276  * J    12      2Bit    Yes     None
1277  * K    16      4Bit[2] No      None
1278  * L    15      4Bit[2] No      None
1279  * M    6       4Bit    No      IRQ_EINT
1280  * N    16      2Bit    No      IRQ_EINT
1281  * O    16      2Bit    Yes     7
1282  * P    15      2Bit    Yes     8
1283  * Q    9       2Bit    Yes     9
1284  *
1285  * [1] BANKF pins 14,15 do not form part of the external interrupt sources
1286  * [2] BANK has two control registers, GPxCON0 and GPxCON1
1287  */
1288
1289 static struct samsung_gpio_chip s3c64xx_gpios_4bit[] = {
1290 #ifdef CONFIG_PLAT_S3C64XX
1291         {
1292                 .chip   = {
1293                         .base   = S3C64XX_GPA(0),
1294                         .ngpio  = S3C64XX_GPIO_A_NR,
1295                         .label  = "GPA",
1296                 },
1297         }, {
1298                 .chip   = {
1299                         .base   = S3C64XX_GPB(0),
1300                         .ngpio  = S3C64XX_GPIO_B_NR,
1301                         .label  = "GPB",
1302                 },
1303         }, {
1304                 .chip   = {
1305                         .base   = S3C64XX_GPC(0),
1306                         .ngpio  = S3C64XX_GPIO_C_NR,
1307                         .label  = "GPC",
1308                 },
1309         }, {
1310                 .chip   = {
1311                         .base   = S3C64XX_GPD(0),
1312                         .ngpio  = S3C64XX_GPIO_D_NR,
1313                         .label  = "GPD",
1314                 },
1315         }, {
1316                 .config = &samsung_gpio_cfgs[0],
1317                 .chip   = {
1318                         .base   = S3C64XX_GPE(0),
1319                         .ngpio  = S3C64XX_GPIO_E_NR,
1320                         .label  = "GPE",
1321                 },
1322         }, {
1323                 .base   = S3C64XX_GPG_BASE,
1324                 .chip   = {
1325                         .base   = S3C64XX_GPG(0),
1326                         .ngpio  = S3C64XX_GPIO_G_NR,
1327                         .label  = "GPG",
1328                 },
1329         }, {
1330                 .base   = S3C64XX_GPM_BASE,
1331                 .config = &samsung_gpio_cfgs[1],
1332                 .chip   = {
1333                         .base   = S3C64XX_GPM(0),
1334                         .ngpio  = S3C64XX_GPIO_M_NR,
1335                         .label  = "GPM",
1336                         .to_irq = s3c64xx_gpiolib_mbank_to_irq,
1337                 },
1338         },
1339 #endif
1340 };
1341
1342 static struct samsung_gpio_chip s3c64xx_gpios_4bit2[] = {
1343 #ifdef CONFIG_PLAT_S3C64XX
1344         {
1345                 .base   = S3C64XX_GPH_BASE + 0x4,
1346                 .chip   = {
1347                         .base   = S3C64XX_GPH(0),
1348                         .ngpio  = S3C64XX_GPIO_H_NR,
1349                         .label  = "GPH",
1350                 },
1351         }, {
1352                 .base   = S3C64XX_GPK_BASE + 0x4,
1353                 .config = &samsung_gpio_cfgs[0],
1354                 .chip   = {
1355                         .base   = S3C64XX_GPK(0),
1356                         .ngpio  = S3C64XX_GPIO_K_NR,
1357                         .label  = "GPK",
1358                 },
1359         }, {
1360                 .base   = S3C64XX_GPL_BASE + 0x4,
1361                 .config = &samsung_gpio_cfgs[1],
1362                 .chip   = {
1363                         .base   = S3C64XX_GPL(0),
1364                         .ngpio  = S3C64XX_GPIO_L_NR,
1365                         .label  = "GPL",
1366                         .to_irq = s3c64xx_gpiolib_lbank_to_irq,
1367                 },
1368         },
1369 #endif
1370 };
1371
1372 static struct samsung_gpio_chip s3c64xx_gpios_2bit[] = {
1373 #ifdef CONFIG_PLAT_S3C64XX
1374         {
1375                 .base   = S3C64XX_GPF_BASE,
1376                 .config = &samsung_gpio_cfgs[6],
1377                 .chip   = {
1378                         .base   = S3C64XX_GPF(0),
1379                         .ngpio  = S3C64XX_GPIO_F_NR,
1380                         .label  = "GPF",
1381                 },
1382         }, {
1383                 .config = &samsung_gpio_cfgs[7],
1384                 .chip   = {
1385                         .base   = S3C64XX_GPI(0),
1386                         .ngpio  = S3C64XX_GPIO_I_NR,
1387                         .label  = "GPI",
1388                 },
1389         }, {
1390                 .config = &samsung_gpio_cfgs[7],
1391                 .chip   = {
1392                         .base   = S3C64XX_GPJ(0),
1393                         .ngpio  = S3C64XX_GPIO_J_NR,
1394                         .label  = "GPJ",
1395                 },
1396         }, {
1397                 .config = &samsung_gpio_cfgs[6],
1398                 .chip   = {
1399                         .base   = S3C64XX_GPO(0),
1400                         .ngpio  = S3C64XX_GPIO_O_NR,
1401                         .label  = "GPO",
1402                 },
1403         }, {
1404                 .config = &samsung_gpio_cfgs[6],
1405                 .chip   = {
1406                         .base   = S3C64XX_GPP(0),
1407                         .ngpio  = S3C64XX_GPIO_P_NR,
1408                         .label  = "GPP",
1409                 },
1410         }, {
1411                 .config = &samsung_gpio_cfgs[6],
1412                 .chip   = {
1413                         .base   = S3C64XX_GPQ(0),
1414                         .ngpio  = S3C64XX_GPIO_Q_NR,
1415                         .label  = "GPQ",
1416                 },
1417         }, {
1418                 .base   = S3C64XX_GPN_BASE,
1419                 .irq_base = IRQ_EINT(0),
1420                 .config = &samsung_gpio_cfgs[5],
1421                 .chip   = {
1422                         .base   = S3C64XX_GPN(0),
1423                         .ngpio  = S3C64XX_GPIO_N_NR,
1424                         .label  = "GPN",
1425                         .to_irq = samsung_gpiolib_to_irq,
1426                 },
1427         },
1428 #endif
1429 };
1430
1431 /*
1432  * S5P6440 GPIO bank summary:
1433  *
1434  * Bank GPIOs   Style   SlpCon  ExtInt Group
1435  * A    6       4Bit    Yes     1
1436  * B    7       4Bit    Yes     1
1437  * C    8       4Bit    Yes     2
1438  * F    2       2Bit    Yes     4 [1]
1439  * G    7       4Bit    Yes     5
1440  * H    10      4Bit[2] Yes     6
1441  * I    16      2Bit    Yes     None
1442  * J    12      2Bit    Yes     None
1443  * N    16      2Bit    No      IRQ_EINT
1444  * P    8       2Bit    Yes     8
1445  * R    15      4Bit[2] Yes     8
1446  */
1447
1448 static struct samsung_gpio_chip s5p6440_gpios_4bit[] = {
1449 #ifdef CONFIG_CPU_S5P6440
1450         {
1451                 .chip   = {
1452                         .base   = S5P6440_GPA(0),
1453                         .ngpio  = S5P6440_GPIO_A_NR,
1454                         .label  = "GPA",
1455                 },
1456         }, {
1457                 .chip   = {
1458                         .base   = S5P6440_GPB(0),
1459                         .ngpio  = S5P6440_GPIO_B_NR,
1460                         .label  = "GPB",
1461                 },
1462         }, {
1463                 .chip   = {
1464                         .base   = S5P6440_GPC(0),
1465                         .ngpio  = S5P6440_GPIO_C_NR,
1466                         .label  = "GPC",
1467                 },
1468         }, {
1469                 .base   = S5P64X0_GPG_BASE,
1470                 .chip   = {
1471                         .base   = S5P6440_GPG(0),
1472                         .ngpio  = S5P6440_GPIO_G_NR,
1473                         .label  = "GPG",
1474                 },
1475         },
1476 #endif
1477 };
1478
1479 static struct samsung_gpio_chip s5p6440_gpios_4bit2[] = {
1480 #ifdef CONFIG_CPU_S5P6440
1481         {
1482                 .base   = S5P64X0_GPH_BASE + 0x4,
1483                 .chip   = {
1484                         .base   = S5P6440_GPH(0),
1485                         .ngpio  = S5P6440_GPIO_H_NR,
1486                         .label  = "GPH",
1487                 },
1488         },
1489 #endif
1490 };
1491
1492 static struct samsung_gpio_chip s5p6440_gpios_rbank[] = {
1493 #ifdef CONFIG_CPU_S5P6440
1494         {
1495                 .base   = S5P64X0_GPR_BASE + 0x4,
1496                 .config = &s5p64x0_gpio_cfg_rbank,
1497                 .chip   = {
1498                         .base   = S5P6440_GPR(0),
1499                         .ngpio  = S5P6440_GPIO_R_NR,
1500                         .label  = "GPR",
1501                 },
1502         },
1503 #endif
1504 };
1505
1506 static struct samsung_gpio_chip s5p6440_gpios_2bit[] = {
1507 #ifdef CONFIG_CPU_S5P6440
1508         {
1509                 .base   = S5P64X0_GPF_BASE,
1510                 .config = &samsung_gpio_cfgs[6],
1511                 .chip   = {
1512                         .base   = S5P6440_GPF(0),
1513                         .ngpio  = S5P6440_GPIO_F_NR,
1514                         .label  = "GPF",
1515                 },
1516         }, {
1517                 .base   = S5P64X0_GPI_BASE,
1518                 .config = &samsung_gpio_cfgs[4],
1519                 .chip   = {
1520                         .base   = S5P6440_GPI(0),
1521                         .ngpio  = S5P6440_GPIO_I_NR,
1522                         .label  = "GPI",
1523                 },
1524         }, {
1525                 .base   = S5P64X0_GPJ_BASE,
1526                 .config = &samsung_gpio_cfgs[4],
1527                 .chip   = {
1528                         .base   = S5P6440_GPJ(0),
1529                         .ngpio  = S5P6440_GPIO_J_NR,
1530                         .label  = "GPJ",
1531                 },
1532         }, {
1533                 .base   = S5P64X0_GPN_BASE,
1534                 .config = &samsung_gpio_cfgs[5],
1535                 .chip   = {
1536                         .base   = S5P6440_GPN(0),
1537                         .ngpio  = S5P6440_GPIO_N_NR,
1538                         .label  = "GPN",
1539                 },
1540         }, {
1541                 .base   = S5P64X0_GPP_BASE,
1542                 .config = &samsung_gpio_cfgs[6],
1543                 .chip   = {
1544                         .base   = S5P6440_GPP(0),
1545                         .ngpio  = S5P6440_GPIO_P_NR,
1546                         .label  = "GPP",
1547                 },
1548         },
1549 #endif
1550 };
1551
1552 /*
1553  * S5P6450 GPIO bank summary:
1554  *
1555  * Bank GPIOs   Style   SlpCon  ExtInt Group
1556  * A    6       4Bit    Yes     1
1557  * B    7       4Bit    Yes     1
1558  * C    8       4Bit    Yes     2
1559  * D    8       4Bit    Yes     None
1560  * F    2       2Bit    Yes     None
1561  * G    14      4Bit[2] Yes     5
1562  * H    10      4Bit[2] Yes     6
1563  * I    16      2Bit    Yes     None
1564  * J    12      2Bit    Yes     None
1565  * K    5       4Bit    Yes     None
1566  * N    16      2Bit    No      IRQ_EINT
1567  * P    11      2Bit    Yes     8
1568  * Q    14      2Bit    Yes     None
1569  * R    15      4Bit[2] Yes     None
1570  * S    8       2Bit    Yes     None
1571  *
1572  * [1] BANKF pins 14,15 do not form part of the external interrupt sources
1573  * [2] BANK has two control registers, GPxCON0 and GPxCON1
1574  */
1575
1576 static struct samsung_gpio_chip s5p6450_gpios_4bit[] = {
1577 #ifdef CONFIG_CPU_S5P6450
1578         {
1579                 .chip   = {
1580                         .base   = S5P6450_GPA(0),
1581                         .ngpio  = S5P6450_GPIO_A_NR,
1582                         .label  = "GPA",
1583                 },
1584         }, {
1585                 .chip   = {
1586                         .base   = S5P6450_GPB(0),
1587                         .ngpio  = S5P6450_GPIO_B_NR,
1588                         .label  = "GPB",
1589                 },
1590         }, {
1591                 .chip   = {
1592                         .base   = S5P6450_GPC(0),
1593                         .ngpio  = S5P6450_GPIO_C_NR,
1594                         .label  = "GPC",
1595                 },
1596         }, {
1597                 .chip   = {
1598                         .base   = S5P6450_GPD(0),
1599                         .ngpio  = S5P6450_GPIO_D_NR,
1600                         .label  = "GPD",
1601                 },
1602         }, {
1603                 .base   = S5P6450_GPK_BASE,
1604                 .chip   = {
1605                         .base   = S5P6450_GPK(0),
1606                         .ngpio  = S5P6450_GPIO_K_NR,
1607                         .label  = "GPK",
1608                 },
1609         },
1610 #endif
1611 };
1612
1613 static struct samsung_gpio_chip s5p6450_gpios_4bit2[] = {
1614 #ifdef CONFIG_CPU_S5P6450
1615         {
1616                 .base   = S5P64X0_GPG_BASE + 0x4,
1617                 .chip   = {
1618                         .base   = S5P6450_GPG(0),
1619                         .ngpio  = S5P6450_GPIO_G_NR,
1620                         .label  = "GPG",
1621                 },
1622         }, {
1623                 .base   = S5P64X0_GPH_BASE + 0x4,
1624                 .chip   = {
1625                         .base   = S5P6450_GPH(0),
1626                         .ngpio  = S5P6450_GPIO_H_NR,
1627                         .label  = "GPH",
1628                 },
1629         },
1630 #endif
1631 };
1632
1633 static struct samsung_gpio_chip s5p6450_gpios_rbank[] = {
1634 #ifdef CONFIG_CPU_S5P6450
1635         {
1636                 .base   = S5P64X0_GPR_BASE + 0x4,
1637                 .config = &s5p64x0_gpio_cfg_rbank,
1638                 .chip   = {
1639                         .base   = S5P6450_GPR(0),
1640                         .ngpio  = S5P6450_GPIO_R_NR,
1641                         .label  = "GPR",
1642                 },
1643         },
1644 #endif
1645 };
1646
1647 static struct samsung_gpio_chip s5p6450_gpios_2bit[] = {
1648 #ifdef CONFIG_CPU_S5P6450
1649         {
1650                 .base   = S5P64X0_GPF_BASE,
1651                 .config = &samsung_gpio_cfgs[6],
1652                 .chip   = {
1653                         .base   = S5P6450_GPF(0),
1654                         .ngpio  = S5P6450_GPIO_F_NR,
1655                         .label  = "GPF",
1656                 },
1657         }, {
1658                 .base   = S5P64X0_GPI_BASE,
1659                 .config = &samsung_gpio_cfgs[4],
1660                 .chip   = {
1661                         .base   = S5P6450_GPI(0),
1662                         .ngpio  = S5P6450_GPIO_I_NR,
1663                         .label  = "GPI",
1664                 },
1665         }, {
1666                 .base   = S5P64X0_GPJ_BASE,
1667                 .config = &samsung_gpio_cfgs[4],
1668                 .chip   = {
1669                         .base   = S5P6450_GPJ(0),
1670                         .ngpio  = S5P6450_GPIO_J_NR,
1671                         .label  = "GPJ",
1672                 },
1673         }, {
1674                 .base   = S5P64X0_GPN_BASE,
1675                 .config = &samsung_gpio_cfgs[5],
1676                 .chip   = {
1677                         .base   = S5P6450_GPN(0),
1678                         .ngpio  = S5P6450_GPIO_N_NR,
1679                         .label  = "GPN",
1680                 },
1681         }, {
1682                 .base   = S5P64X0_GPP_BASE,
1683                 .config = &samsung_gpio_cfgs[6],
1684                 .chip   = {
1685                         .base   = S5P6450_GPP(0),
1686                         .ngpio  = S5P6450_GPIO_P_NR,
1687                         .label  = "GPP",
1688                 },
1689         }, {
1690                 .base   = S5P6450_GPQ_BASE,
1691                 .config = &samsung_gpio_cfgs[5],
1692                 .chip   = {
1693                         .base   = S5P6450_GPQ(0),
1694                         .ngpio  = S5P6450_GPIO_Q_NR,
1695                         .label  = "GPQ",
1696                 },
1697         }, {
1698                 .base   = S5P6450_GPS_BASE,
1699                 .config = &samsung_gpio_cfgs[6],
1700                 .chip   = {
1701                         .base   = S5P6450_GPS(0),
1702                         .ngpio  = S5P6450_GPIO_S_NR,
1703                         .label  = "GPS",
1704                 },
1705         },
1706 #endif
1707 };
1708
1709 /*
1710  * S5PC100 GPIO bank summary:
1711  *
1712  * Bank GPIOs   Style   INT Type
1713  * A0   8       4Bit    GPIO_INT0
1714  * A1   5       4Bit    GPIO_INT1
1715  * B    8       4Bit    GPIO_INT2
1716  * C    5       4Bit    GPIO_INT3
1717  * D    7       4Bit    GPIO_INT4
1718  * E0   8       4Bit    GPIO_INT5
1719  * E1   6       4Bit    GPIO_INT6
1720  * F0   8       4Bit    GPIO_INT7
1721  * F1   8       4Bit    GPIO_INT8
1722  * F2   8       4Bit    GPIO_INT9
1723  * F3   4       4Bit    GPIO_INT10
1724  * G0   8       4Bit    GPIO_INT11
1725  * G1   3       4Bit    GPIO_INT12
1726  * G2   7       4Bit    GPIO_INT13
1727  * G3   7       4Bit    GPIO_INT14
1728  * H0   8       4Bit    WKUP_INT
1729  * H1   8       4Bit    WKUP_INT
1730  * H2   8       4Bit    WKUP_INT
1731  * H3   8       4Bit    WKUP_INT
1732  * I    8       4Bit    GPIO_INT15
1733  * J0   8       4Bit    GPIO_INT16
1734  * J1   5       4Bit    GPIO_INT17
1735  * J2   8       4Bit    GPIO_INT18
1736  * J3   8       4Bit    GPIO_INT19
1737  * J4   4       4Bit    GPIO_INT20
1738  * K0   8       4Bit    None
1739  * K1   6       4Bit    None
1740  * K2   8       4Bit    None
1741  * K3   8       4Bit    None
1742  * L0   8       4Bit    None
1743  * L1   8       4Bit    None
1744  * L2   8       4Bit    None
1745  * L3   8       4Bit    None
1746  */
1747
1748 static struct samsung_gpio_chip s5pc100_gpios_4bit[] = {
1749 #ifdef CONFIG_CPU_S5PC100
1750         {
1751                 .chip   = {
1752                         .base   = S5PC100_GPA0(0),
1753                         .ngpio  = S5PC100_GPIO_A0_NR,
1754                         .label  = "GPA0",
1755                 },
1756         }, {
1757                 .chip   = {
1758                         .base   = S5PC100_GPA1(0),
1759                         .ngpio  = S5PC100_GPIO_A1_NR,
1760                         .label  = "GPA1",
1761                 },
1762         }, {
1763                 .chip   = {
1764                         .base   = S5PC100_GPB(0),
1765                         .ngpio  = S5PC100_GPIO_B_NR,
1766                         .label  = "GPB",
1767                 },
1768         }, {
1769                 .chip   = {
1770                         .base   = S5PC100_GPC(0),
1771                         .ngpio  = S5PC100_GPIO_C_NR,
1772                         .label  = "GPC",
1773                 },
1774         }, {
1775                 .chip   = {
1776                         .base   = S5PC100_GPD(0),
1777                         .ngpio  = S5PC100_GPIO_D_NR,
1778                         .label  = "GPD",
1779                 },
1780         }, {
1781                 .chip   = {
1782                         .base   = S5PC100_GPE0(0),
1783                         .ngpio  = S5PC100_GPIO_E0_NR,
1784                         .label  = "GPE0",
1785                 },
1786         }, {
1787                 .chip   = {
1788                         .base   = S5PC100_GPE1(0),
1789                         .ngpio  = S5PC100_GPIO_E1_NR,
1790                         .label  = "GPE1",
1791                 },
1792         }, {
1793                 .chip   = {
1794                         .base   = S5PC100_GPF0(0),
1795                         .ngpio  = S5PC100_GPIO_F0_NR,
1796                         .label  = "GPF0",
1797                 },
1798         }, {
1799                 .chip   = {
1800                         .base   = S5PC100_GPF1(0),
1801                         .ngpio  = S5PC100_GPIO_F1_NR,
1802                         .label  = "GPF1",
1803                 },
1804         }, {
1805                 .chip   = {
1806                         .base   = S5PC100_GPF2(0),
1807                         .ngpio  = S5PC100_GPIO_F2_NR,
1808                         .label  = "GPF2",
1809                 },
1810         }, {
1811                 .chip   = {
1812                         .base   = S5PC100_GPF3(0),
1813                         .ngpio  = S5PC100_GPIO_F3_NR,
1814                         .label  = "GPF3",
1815                 },
1816         }, {
1817                 .chip   = {
1818                         .base   = S5PC100_GPG0(0),
1819                         .ngpio  = S5PC100_GPIO_G0_NR,
1820                         .label  = "GPG0",
1821                 },
1822         }, {
1823                 .chip   = {
1824                         .base   = S5PC100_GPG1(0),
1825                         .ngpio  = S5PC100_GPIO_G1_NR,
1826                         .label  = "GPG1",
1827                 },
1828         }, {
1829                 .chip   = {
1830                         .base   = S5PC100_GPG2(0),
1831                         .ngpio  = S5PC100_GPIO_G2_NR,
1832                         .label  = "GPG2",
1833                 },
1834         }, {
1835                 .chip   = {
1836                         .base   = S5PC100_GPG3(0),
1837                         .ngpio  = S5PC100_GPIO_G3_NR,
1838                         .label  = "GPG3",
1839                 },
1840         }, {
1841                 .chip   = {
1842                         .base   = S5PC100_GPI(0),
1843                         .ngpio  = S5PC100_GPIO_I_NR,
1844                         .label  = "GPI",
1845                 },
1846         }, {
1847                 .chip   = {
1848                         .base   = S5PC100_GPJ0(0),
1849                         .ngpio  = S5PC100_GPIO_J0_NR,
1850                         .label  = "GPJ0",
1851                 },
1852         }, {
1853                 .chip   = {
1854                         .base   = S5PC100_GPJ1(0),
1855                         .ngpio  = S5PC100_GPIO_J1_NR,
1856                         .label  = "GPJ1",
1857                 },
1858         }, {
1859                 .chip   = {
1860                         .base   = S5PC100_GPJ2(0),
1861                         .ngpio  = S5PC100_GPIO_J2_NR,
1862                         .label  = "GPJ2",
1863                 },
1864         }, {
1865                 .chip   = {
1866                         .base   = S5PC100_GPJ3(0),
1867                         .ngpio  = S5PC100_GPIO_J3_NR,
1868                         .label  = "GPJ3",
1869                 },
1870         }, {
1871                 .chip   = {
1872                         .base   = S5PC100_GPJ4(0),
1873                         .ngpio  = S5PC100_GPIO_J4_NR,
1874                         .label  = "GPJ4",
1875                 },
1876         }, {
1877                 .chip   = {
1878                         .base   = S5PC100_GPK0(0),
1879                         .ngpio  = S5PC100_GPIO_K0_NR,
1880                         .label  = "GPK0",
1881                 },
1882         }, {
1883                 .chip   = {
1884                         .base   = S5PC100_GPK1(0),
1885                         .ngpio  = S5PC100_GPIO_K1_NR,
1886                         .label  = "GPK1",
1887                 },
1888         }, {
1889                 .chip   = {
1890                         .base   = S5PC100_GPK2(0),
1891                         .ngpio  = S5PC100_GPIO_K2_NR,
1892                         .label  = "GPK2",
1893                 },
1894         }, {
1895                 .chip   = {
1896                         .base   = S5PC100_GPK3(0),
1897                         .ngpio  = S5PC100_GPIO_K3_NR,
1898                         .label  = "GPK3",
1899                 },
1900         }, {
1901                 .chip   = {
1902                         .base   = S5PC100_GPL0(0),
1903                         .ngpio  = S5PC100_GPIO_L0_NR,
1904                         .label  = "GPL0",
1905                 },
1906         }, {
1907                 .chip   = {
1908                         .base   = S5PC100_GPL1(0),
1909                         .ngpio  = S5PC100_GPIO_L1_NR,
1910                         .label  = "GPL1",
1911                 },
1912         }, {
1913                 .chip   = {
1914                         .base   = S5PC100_GPL2(0),
1915                         .ngpio  = S5PC100_GPIO_L2_NR,
1916                         .label  = "GPL2",
1917                 },
1918         }, {
1919                 .chip   = {
1920                         .base   = S5PC100_GPL3(0),
1921                         .ngpio  = S5PC100_GPIO_L3_NR,
1922                         .label  = "GPL3",
1923                 },
1924         }, {
1925                 .chip   = {
1926                         .base   = S5PC100_GPL4(0),
1927                         .ngpio  = S5PC100_GPIO_L4_NR,
1928                         .label  = "GPL4",
1929                 },
1930         }, {
1931                 .base   = (S5P_VA_GPIO + 0xC00),
1932                 .irq_base = IRQ_EINT(0),
1933                 .chip   = {
1934                         .base   = S5PC100_GPH0(0),
1935                         .ngpio  = S5PC100_GPIO_H0_NR,
1936                         .label  = "GPH0",
1937                         .to_irq = samsung_gpiolib_to_irq,
1938                 },
1939         }, {
1940                 .base   = (S5P_VA_GPIO + 0xC20),
1941                 .irq_base = IRQ_EINT(8),
1942                 .chip   = {
1943                         .base   = S5PC100_GPH1(0),
1944                         .ngpio  = S5PC100_GPIO_H1_NR,
1945                         .label  = "GPH1",
1946                         .to_irq = samsung_gpiolib_to_irq,
1947                 },
1948         }, {
1949                 .base   = (S5P_VA_GPIO + 0xC40),
1950                 .irq_base = IRQ_EINT(16),
1951                 .chip   = {
1952                         .base   = S5PC100_GPH2(0),
1953                         .ngpio  = S5PC100_GPIO_H2_NR,
1954                         .label  = "GPH2",
1955                         .to_irq = samsung_gpiolib_to_irq,
1956                 },
1957         }, {
1958                 .base   = (S5P_VA_GPIO + 0xC60),
1959                 .irq_base = IRQ_EINT(24),
1960                 .chip   = {
1961                         .base   = S5PC100_GPH3(0),
1962                         .ngpio  = S5PC100_GPIO_H3_NR,
1963                         .label  = "GPH3",
1964                         .to_irq = samsung_gpiolib_to_irq,
1965                 },
1966         },
1967 #endif
1968 };
1969
1970 /*
1971  * Followings are the gpio banks in S5PV210/S5PC110
1972  *
1973  * The 'config' member when left to NULL, is initialized to the default
1974  * structure samsung_gpio_cfgs[3] in the init function below.
1975  *
1976  * The 'base' member is also initialized in the init function below.
1977  * Note: The initialization of 'base' member of samsung_gpio_chip structure
1978  * uses the above macro and depends on the banks being listed in order here.
1979  */
1980
1981 static struct samsung_gpio_chip s5pv210_gpios_4bit[] = {
1982 #ifdef CONFIG_CPU_S5PV210
1983         {
1984                 .chip   = {
1985                         .base   = S5PV210_GPA0(0),
1986                         .ngpio  = S5PV210_GPIO_A0_NR,
1987                         .label  = "GPA0",
1988                 },
1989         }, {
1990                 .chip   = {
1991                         .base   = S5PV210_GPA1(0),
1992                         .ngpio  = S5PV210_GPIO_A1_NR,
1993                         .label  = "GPA1",
1994                 },
1995         }, {
1996                 .chip   = {
1997                         .base   = S5PV210_GPB(0),
1998                         .ngpio  = S5PV210_GPIO_B_NR,
1999                         .label  = "GPB",
2000                 },
2001         }, {
2002                 .chip   = {
2003                         .base   = S5PV210_GPC0(0),
2004                         .ngpio  = S5PV210_GPIO_C0_NR,
2005                         .label  = "GPC0",
2006                 },
2007         }, {
2008                 .chip   = {
2009                         .base   = S5PV210_GPC1(0),
2010                         .ngpio  = S5PV210_GPIO_C1_NR,
2011                         .label  = "GPC1",
2012                 },
2013         }, {
2014                 .chip   = {
2015                         .base   = S5PV210_GPD0(0),
2016                         .ngpio  = S5PV210_GPIO_D0_NR,
2017                         .label  = "GPD0",
2018                 },
2019         }, {
2020                 .chip   = {
2021                         .base   = S5PV210_GPD1(0),
2022                         .ngpio  = S5PV210_GPIO_D1_NR,
2023                         .label  = "GPD1",
2024                 },
2025         }, {
2026                 .chip   = {
2027                         .base   = S5PV210_GPE0(0),
2028                         .ngpio  = S5PV210_GPIO_E0_NR,
2029                         .label  = "GPE0",
2030                 },
2031         }, {
2032                 .chip   = {
2033                         .base   = S5PV210_GPE1(0),
2034                         .ngpio  = S5PV210_GPIO_E1_NR,
2035                         .label  = "GPE1",
2036                 },
2037         }, {
2038                 .chip   = {
2039                         .base   = S5PV210_GPF0(0),
2040                         .ngpio  = S5PV210_GPIO_F0_NR,
2041                         .label  = "GPF0",
2042                 },
2043         }, {
2044                 .chip   = {
2045                         .base   = S5PV210_GPF1(0),
2046                         .ngpio  = S5PV210_GPIO_F1_NR,
2047                         .label  = "GPF1",
2048                 },
2049         }, {
2050                 .chip   = {
2051                         .base   = S5PV210_GPF2(0),
2052                         .ngpio  = S5PV210_GPIO_F2_NR,
2053                         .label  = "GPF2",
2054                 },
2055         }, {
2056                 .chip   = {
2057                         .base   = S5PV210_GPF3(0),
2058                         .ngpio  = S5PV210_GPIO_F3_NR,
2059                         .label  = "GPF3",
2060                 },
2061         }, {
2062                 .chip   = {
2063                         .base   = S5PV210_GPG0(0),
2064                         .ngpio  = S5PV210_GPIO_G0_NR,
2065                         .label  = "GPG0",
2066                 },
2067         }, {
2068                 .chip   = {
2069                         .base   = S5PV210_GPG1(0),
2070                         .ngpio  = S5PV210_GPIO_G1_NR,
2071                         .label  = "GPG1",
2072                 },
2073         }, {
2074                 .chip   = {
2075                         .base   = S5PV210_GPG2(0),
2076                         .ngpio  = S5PV210_GPIO_G2_NR,
2077                         .label  = "GPG2",
2078                 },
2079         }, {
2080                 .chip   = {
2081                         .base   = S5PV210_GPG3(0),
2082                         .ngpio  = S5PV210_GPIO_G3_NR,
2083                         .label  = "GPG3",
2084                 },
2085         }, {
2086                 .chip   = {
2087                         .base   = S5PV210_GPI(0),
2088                         .ngpio  = S5PV210_GPIO_I_NR,
2089                         .label  = "GPI",
2090                 },
2091         }, {
2092                 .chip   = {
2093                         .base   = S5PV210_GPJ0(0),
2094                         .ngpio  = S5PV210_GPIO_J0_NR,
2095                         .label  = "GPJ0",
2096                 },
2097         }, {
2098                 .chip   = {
2099                         .base   = S5PV210_GPJ1(0),
2100                         .ngpio  = S5PV210_GPIO_J1_NR,
2101                         .label  = "GPJ1",
2102                 },
2103         }, {
2104                 .chip   = {
2105                         .base   = S5PV210_GPJ2(0),
2106                         .ngpio  = S5PV210_GPIO_J2_NR,
2107                         .label  = "GPJ2",
2108                 },
2109         }, {
2110                 .chip   = {
2111                         .base   = S5PV210_GPJ3(0),
2112                         .ngpio  = S5PV210_GPIO_J3_NR,
2113                         .label  = "GPJ3",
2114                 },
2115         }, {
2116                 .chip   = {
2117                         .base   = S5PV210_GPJ4(0),
2118                         .ngpio  = S5PV210_GPIO_J4_NR,
2119                         .label  = "GPJ4",
2120                 },
2121         }, {
2122                 .chip   = {
2123                         .base   = S5PV210_MP01(0),
2124                         .ngpio  = S5PV210_GPIO_MP01_NR,
2125                         .label  = "MP01",
2126                 },
2127         }, {
2128                 .chip   = {
2129                         .base   = S5PV210_MP02(0),
2130                         .ngpio  = S5PV210_GPIO_MP02_NR,
2131                         .label  = "MP02",
2132                 },
2133         }, {
2134                 .chip   = {
2135                         .base   = S5PV210_MP03(0),
2136                         .ngpio  = S5PV210_GPIO_MP03_NR,
2137                         .label  = "MP03",
2138                 },
2139         }, {
2140                 .chip   = {
2141                         .base   = S5PV210_MP04(0),
2142                         .ngpio  = S5PV210_GPIO_MP04_NR,
2143                         .label  = "MP04",
2144                 },
2145         }, {
2146                 .chip   = {
2147                         .base   = S5PV210_MP05(0),
2148                         .ngpio  = S5PV210_GPIO_MP05_NR,
2149                         .label  = "MP05",
2150                 },
2151         }, {
2152                 .base   = (S5P_VA_GPIO + 0xC00),
2153                 .irq_base = IRQ_EINT(0),
2154                 .chip   = {
2155                         .base   = S5PV210_GPH0(0),
2156                         .ngpio  = S5PV210_GPIO_H0_NR,
2157                         .label  = "GPH0",
2158                         .to_irq = samsung_gpiolib_to_irq,
2159                 },
2160         }, {
2161                 .base   = (S5P_VA_GPIO + 0xC20),
2162                 .irq_base = IRQ_EINT(8),
2163                 .chip   = {
2164                         .base   = S5PV210_GPH1(0),
2165                         .ngpio  = S5PV210_GPIO_H1_NR,
2166                         .label  = "GPH1",
2167                         .to_irq = samsung_gpiolib_to_irq,
2168                 },
2169         }, {
2170                 .base   = (S5P_VA_GPIO + 0xC40),
2171                 .irq_base = IRQ_EINT(16),
2172                 .chip   = {
2173                         .base   = S5PV210_GPH2(0),
2174                         .ngpio  = S5PV210_GPIO_H2_NR,
2175                         .label  = "GPH2",
2176                         .to_irq = samsung_gpiolib_to_irq,
2177                 },
2178         }, {
2179                 .base   = (S5P_VA_GPIO + 0xC60),
2180                 .irq_base = IRQ_EINT(24),
2181                 .chip   = {
2182                         .base   = S5PV210_GPH3(0),
2183                         .ngpio  = S5PV210_GPIO_H3_NR,
2184                         .label  = "GPH3",
2185                         .to_irq = samsung_gpiolib_to_irq,
2186                 },
2187         },
2188 #endif
2189 };
2190
2191 /*
2192  * Followings are the gpio banks in EXYNOS SoCs
2193  *
2194  * The 'config' member when left to NULL, is initialized to the default
2195  * structure exynos_gpio_cfg in the init function below.
2196  *
2197  * The 'base' member is also initialized in the init function below.
2198  * Note: The initialization of 'base' member of samsung_gpio_chip structure
2199  * uses the above macro and depends on the banks being listed in order here.
2200  */
2201
2202 #ifdef CONFIG_ARCH_EXYNOS4
2203 static struct samsung_gpio_chip exynos4_gpios_1[] = {
2204         {
2205                 .chip   = {
2206                         .base   = EXYNOS4_GPA0(0),
2207                         .ngpio  = EXYNOS4_GPIO_A0_NR,
2208                         .label  = "GPA0",
2209                 },
2210         }, {
2211                 .chip   = {
2212                         .base   = EXYNOS4_GPA1(0),
2213                         .ngpio  = EXYNOS4_GPIO_A1_NR,
2214                         .label  = "GPA1",
2215                 },
2216         }, {
2217                 .chip   = {
2218                         .base   = EXYNOS4_GPB(0),
2219                         .ngpio  = EXYNOS4_GPIO_B_NR,
2220                         .label  = "GPB",
2221                 },
2222         }, {
2223                 .chip   = {
2224                         .base   = EXYNOS4_GPC0(0),
2225                         .ngpio  = EXYNOS4_GPIO_C0_NR,
2226                         .label  = "GPC0",
2227                 },
2228         }, {
2229                 .chip   = {
2230                         .base   = EXYNOS4_GPC1(0),
2231                         .ngpio  = EXYNOS4_GPIO_C1_NR,
2232                         .label  = "GPC1",
2233                 },
2234         }, {
2235                 .chip   = {
2236                         .base   = EXYNOS4_GPD0(0),
2237                         .ngpio  = EXYNOS4_GPIO_D0_NR,
2238                         .label  = "GPD0",
2239                 },
2240         }, {
2241                 .chip   = {
2242                         .base   = EXYNOS4_GPD1(0),
2243                         .ngpio  = EXYNOS4_GPIO_D1_NR,
2244                         .label  = "GPD1",
2245                 },
2246         }, {
2247                 .chip   = {
2248                         .base   = EXYNOS4_GPE0(0),
2249                         .ngpio  = EXYNOS4_GPIO_E0_NR,
2250                         .label  = "GPE0",
2251                 },
2252         }, {
2253                 .chip   = {
2254                         .base   = EXYNOS4_GPE1(0),
2255                         .ngpio  = EXYNOS4_GPIO_E1_NR,
2256                         .label  = "GPE1",
2257                 },
2258         }, {
2259                 .chip   = {
2260                         .base   = EXYNOS4_GPE2(0),
2261                         .ngpio  = EXYNOS4_GPIO_E2_NR,
2262                         .label  = "GPE2",
2263                 },
2264         }, {
2265                 .chip   = {
2266                         .base   = EXYNOS4_GPE3(0),
2267                         .ngpio  = EXYNOS4_GPIO_E3_NR,
2268                         .label  = "GPE3",
2269                 },
2270         }, {
2271                 .chip   = {
2272                         .base   = EXYNOS4_GPE4(0),
2273                         .ngpio  = EXYNOS4_GPIO_E4_NR,
2274                         .label  = "GPE4",
2275                 },
2276         }, {
2277                 .chip   = {
2278                         .base   = EXYNOS4_GPF0(0),
2279                         .ngpio  = EXYNOS4_GPIO_F0_NR,
2280                         .label  = "GPF0",
2281                 },
2282         }, {
2283                 .chip   = {
2284                         .base   = EXYNOS4_GPF1(0),
2285                         .ngpio  = EXYNOS4_GPIO_F1_NR,
2286                         .label  = "GPF1",
2287                 },
2288         }, {
2289                 .chip   = {
2290                         .base   = EXYNOS4_GPF2(0),
2291                         .ngpio  = EXYNOS4_GPIO_F2_NR,
2292                         .label  = "GPF2",
2293                 },
2294         }, {
2295                 .chip   = {
2296                         .base   = EXYNOS4_GPF3(0),
2297                         .ngpio  = EXYNOS4_GPIO_F3_NR,
2298                         .label  = "GPF3",
2299                 },
2300         },
2301 };
2302 #endif
2303
2304 #ifdef CONFIG_ARCH_EXYNOS4
2305 static struct samsung_gpio_chip exynos4_gpios_2[] = {
2306         {
2307                 .chip   = {
2308                         .base   = EXYNOS4_GPJ0(0),
2309                         .ngpio  = EXYNOS4_GPIO_J0_NR,
2310                         .label  = "GPJ0",
2311                 },
2312         }, {
2313                 .chip   = {
2314                         .base   = EXYNOS4_GPJ1(0),
2315                         .ngpio  = EXYNOS4_GPIO_J1_NR,
2316                         .label  = "GPJ1",
2317                 },
2318         }, {
2319                 .chip   = {
2320                         .base   = EXYNOS4_GPK0(0),
2321                         .ngpio  = EXYNOS4_GPIO_K0_NR,
2322                         .label  = "GPK0",
2323                 },
2324         }, {
2325                 .chip   = {
2326                         .base   = EXYNOS4_GPK1(0),
2327                         .ngpio  = EXYNOS4_GPIO_K1_NR,
2328                         .label  = "GPK1",
2329                 },
2330         }, {
2331                 .chip   = {
2332                         .base   = EXYNOS4_GPK2(0),
2333                         .ngpio  = EXYNOS4_GPIO_K2_NR,
2334                         .label  = "GPK2",
2335                 },
2336         }, {
2337                 .chip   = {
2338                         .base   = EXYNOS4_GPK3(0),
2339                         .ngpio  = EXYNOS4_GPIO_K3_NR,
2340                         .label  = "GPK3",
2341                 },
2342         }, {
2343                 .chip   = {
2344                         .base   = EXYNOS4_GPL0(0),
2345                         .ngpio  = EXYNOS4_GPIO_L0_NR,
2346                         .label  = "GPL0",
2347                 },
2348         }, {
2349                 .chip   = {
2350                         .base   = EXYNOS4_GPL1(0),
2351                         .ngpio  = EXYNOS4_GPIO_L1_NR,
2352                         .label  = "GPL1",
2353                 },
2354         }, {
2355                 .chip   = {
2356                         .base   = EXYNOS4_GPL2(0),
2357                         .ngpio  = EXYNOS4_GPIO_L2_NR,
2358                         .label  = "GPL2",
2359                 },
2360         }, {
2361                 .config = &samsung_gpio_cfgs[8],
2362                 .chip   = {
2363                         .base   = EXYNOS4_GPY0(0),
2364                         .ngpio  = EXYNOS4_GPIO_Y0_NR,
2365                         .label  = "GPY0",
2366                 },
2367         }, {
2368                 .config = &samsung_gpio_cfgs[8],
2369                 .chip   = {
2370                         .base   = EXYNOS4_GPY1(0),
2371                         .ngpio  = EXYNOS4_GPIO_Y1_NR,
2372                         .label  = "GPY1",
2373                 },
2374         }, {
2375                 .config = &samsung_gpio_cfgs[8],
2376                 .chip   = {
2377                         .base   = EXYNOS4_GPY2(0),
2378                         .ngpio  = EXYNOS4_GPIO_Y2_NR,
2379                         .label  = "GPY2",
2380                 },
2381         }, {
2382                 .config = &samsung_gpio_cfgs[8],
2383                 .chip   = {
2384                         .base   = EXYNOS4_GPY3(0),
2385                         .ngpio  = EXYNOS4_GPIO_Y3_NR,
2386                         .label  = "GPY3",
2387                 },
2388         }, {
2389                 .config = &samsung_gpio_cfgs[8],
2390                 .chip   = {
2391                         .base   = EXYNOS4_GPY4(0),
2392                         .ngpio  = EXYNOS4_GPIO_Y4_NR,
2393                         .label  = "GPY4",
2394                 },
2395         }, {
2396                 .config = &samsung_gpio_cfgs[8],
2397                 .chip   = {
2398                         .base   = EXYNOS4_GPY5(0),
2399                         .ngpio  = EXYNOS4_GPIO_Y5_NR,
2400                         .label  = "GPY5",
2401                 },
2402         }, {
2403                 .config = &samsung_gpio_cfgs[8],
2404                 .chip   = {
2405                         .base   = EXYNOS4_GPY6(0),
2406                         .ngpio  = EXYNOS4_GPIO_Y6_NR,
2407                         .label  = "GPY6",
2408                 },
2409         }, {
2410                 .config = &samsung_gpio_cfgs[9],
2411                 .irq_base = IRQ_EINT(0),
2412                 .chip   = {
2413                         .base   = EXYNOS4_GPX0(0),
2414                         .ngpio  = EXYNOS4_GPIO_X0_NR,
2415                         .label  = "GPX0",
2416                         .to_irq = samsung_gpiolib_to_irq,
2417                 },
2418         }, {
2419                 .config = &samsung_gpio_cfgs[9],
2420                 .irq_base = IRQ_EINT(8),
2421                 .chip   = {
2422                         .base   = EXYNOS4_GPX1(0),
2423                         .ngpio  = EXYNOS4_GPIO_X1_NR,
2424                         .label  = "GPX1",
2425                         .to_irq = samsung_gpiolib_to_irq,
2426                 },
2427         }, {
2428                 .config = &samsung_gpio_cfgs[9],
2429                 .irq_base = IRQ_EINT(16),
2430                 .chip   = {
2431                         .base   = EXYNOS4_GPX2(0),
2432                         .ngpio  = EXYNOS4_GPIO_X2_NR,
2433                         .label  = "GPX2",
2434                         .to_irq = samsung_gpiolib_to_irq,
2435                 },
2436         }, {
2437                 .config = &samsung_gpio_cfgs[9],
2438                 .irq_base = IRQ_EINT(24),
2439                 .chip   = {
2440                         .base   = EXYNOS4_GPX3(0),
2441                         .ngpio  = EXYNOS4_GPIO_X3_NR,
2442                         .label  = "GPX3",
2443                         .to_irq = samsung_gpiolib_to_irq,
2444                 },
2445         },
2446 };
2447 #endif
2448
2449 #ifdef CONFIG_ARCH_EXYNOS4
2450 static struct samsung_gpio_chip exynos4_gpios_3[] = {
2451         {
2452                 .chip   = {
2453                         .base   = EXYNOS4_GPZ(0),
2454                         .ngpio  = EXYNOS4_GPIO_Z_NR,
2455                         .label  = "GPZ",
2456                 },
2457         },
2458 };
2459 #endif
2460
2461 #ifdef CONFIG_ARCH_EXYNOS5
2462 static struct samsung_gpio_chip exynos5_gpios_1[] = {
2463         {
2464                 .chip   = {
2465                         .base   = EXYNOS5_GPA0(0),
2466                         .ngpio  = EXYNOS5_GPIO_A0_NR,
2467                         .label  = "GPA0",
2468                 },
2469         }, {
2470                 .chip   = {
2471                         .base   = EXYNOS5_GPA1(0),
2472                         .ngpio  = EXYNOS5_GPIO_A1_NR,
2473                         .label  = "GPA1",
2474                 },
2475         }, {
2476                 .chip   = {
2477                         .base   = EXYNOS5_GPA2(0),
2478                         .ngpio  = EXYNOS5_GPIO_A2_NR,
2479                         .label  = "GPA2",
2480                 },
2481         }, {
2482                 .chip   = {
2483                         .base   = EXYNOS5_GPB0(0),
2484                         .ngpio  = EXYNOS5_GPIO_B0_NR,
2485                         .label  = "GPB0",
2486                 },
2487         }, {
2488                 .chip   = {
2489                         .base   = EXYNOS5_GPB1(0),
2490                         .ngpio  = EXYNOS5_GPIO_B1_NR,
2491                         .label  = "GPB1",
2492                 },
2493         }, {
2494                 .chip   = {
2495                         .base   = EXYNOS5_GPB2(0),
2496                         .ngpio  = EXYNOS5_GPIO_B2_NR,
2497                         .label  = "GPB2",
2498                 },
2499         }, {
2500                 .chip   = {
2501                         .base   = EXYNOS5_GPB3(0),
2502                         .ngpio  = EXYNOS5_GPIO_B3_NR,
2503                         .label  = "GPB3",
2504                 },
2505         }, {
2506                 .chip   = {
2507                         .base   = EXYNOS5_GPC0(0),
2508                         .ngpio  = EXYNOS5_GPIO_C0_NR,
2509                         .label  = "GPC0",
2510                 },
2511         }, {
2512                 .chip   = {
2513                         .base   = EXYNOS5_GPC1(0),
2514                         .ngpio  = EXYNOS5_GPIO_C1_NR,
2515                         .label  = "GPC1",
2516                 },
2517         }, {
2518                 .chip   = {
2519                         .base   = EXYNOS5_GPC2(0),
2520                         .ngpio  = EXYNOS5_GPIO_C2_NR,
2521                         .label  = "GPC2",
2522                 },
2523         }, {
2524                 .chip   = {
2525                         .base   = EXYNOS5_GPC3(0),
2526                         .ngpio  = EXYNOS5_GPIO_C3_NR,
2527                         .label  = "GPC3",
2528                 },
2529         }, {
2530                 .chip   = {
2531                         .base   = EXYNOS5_GPD0(0),
2532                         .ngpio  = EXYNOS5_GPIO_D0_NR,
2533                         .label  = "GPD0",
2534                 },
2535         }, {
2536                 .chip   = {
2537                         .base   = EXYNOS5_GPD1(0),
2538                         .ngpio  = EXYNOS5_GPIO_D1_NR,
2539                         .label  = "GPD1",
2540                 },
2541         }, {
2542                 .chip   = {
2543                         .base   = EXYNOS5_GPY0(0),
2544                         .ngpio  = EXYNOS5_GPIO_Y0_NR,
2545                         .label  = "GPY0",
2546                 },
2547         }, {
2548                 .chip   = {
2549                         .base   = EXYNOS5_GPY1(0),
2550                         .ngpio  = EXYNOS5_GPIO_Y1_NR,
2551                         .label  = "GPY1",
2552                 },
2553         }, {
2554                 .chip   = {
2555                         .base   = EXYNOS5_GPY2(0),
2556                         .ngpio  = EXYNOS5_GPIO_Y2_NR,
2557                         .label  = "GPY2",
2558                 },
2559         }, {
2560                 .chip   = {
2561                         .base   = EXYNOS5_GPY3(0),
2562                         .ngpio  = EXYNOS5_GPIO_Y3_NR,
2563                         .label  = "GPY3",
2564                 },
2565         }, {
2566                 .chip   = {
2567                         .base   = EXYNOS5_GPY4(0),
2568                         .ngpio  = EXYNOS5_GPIO_Y4_NR,
2569                         .label  = "GPY4",
2570                 },
2571         }, {
2572                 .chip   = {
2573                         .base   = EXYNOS5_GPY5(0),
2574                         .ngpio  = EXYNOS5_GPIO_Y5_NR,
2575                         .label  = "GPY5",
2576                 },
2577         }, {
2578                 .chip   = {
2579                         .base   = EXYNOS5_GPY6(0),
2580                         .ngpio  = EXYNOS5_GPIO_Y6_NR,
2581                         .label  = "GPY6",
2582                 },
2583         }, {
2584                 .chip   = {
2585                         .base   = EXYNOS5_GPC4(0),
2586                         .ngpio  = EXYNOS5_GPIO_C4_NR,
2587                         .label  = "GPC4",
2588                 },
2589         }, {
2590                 .config = &samsung_gpio_cfgs[9],
2591                 .irq_base = IRQ_EINT(0),
2592                 .chip   = {
2593                         .base   = EXYNOS5_GPX0(0),
2594                         .ngpio  = EXYNOS5_GPIO_X0_NR,
2595                         .label  = "GPX0",
2596                         .to_irq = samsung_gpiolib_to_irq,
2597                 },
2598         }, {
2599                 .config = &samsung_gpio_cfgs[9],
2600                 .irq_base = IRQ_EINT(8),
2601                 .chip   = {
2602                         .base   = EXYNOS5_GPX1(0),
2603                         .ngpio  = EXYNOS5_GPIO_X1_NR,
2604                         .label  = "GPX1",
2605                         .to_irq = samsung_gpiolib_to_irq,
2606                 },
2607         }, {
2608                 .config = &samsung_gpio_cfgs[9],
2609                 .irq_base = IRQ_EINT(16),
2610                 .chip   = {
2611                         .base   = EXYNOS5_GPX2(0),
2612                         .ngpio  = EXYNOS5_GPIO_X2_NR,
2613                         .label  = "GPX2",
2614                         .to_irq = samsung_gpiolib_to_irq,
2615                 },
2616         }, {
2617                 .config = &samsung_gpio_cfgs[9],
2618                 .irq_base = IRQ_EINT(24),
2619                 .chip   = {
2620                         .base   = EXYNOS5_GPX3(0),
2621                         .ngpio  = EXYNOS5_GPIO_X3_NR,
2622                         .label  = "GPX3",
2623                         .to_irq = samsung_gpiolib_to_irq,
2624                 },
2625         },
2626 };
2627 #endif
2628
2629 #ifdef CONFIG_ARCH_EXYNOS5
2630 static struct samsung_gpio_chip exynos5_gpios_2[] = {
2631         {
2632                 .chip   = {
2633                         .base   = EXYNOS5_GPE0(0),
2634                         .ngpio  = EXYNOS5_GPIO_E0_NR,
2635                         .label  = "GPE0",
2636                 },
2637         }, {
2638                 .chip   = {
2639                         .base   = EXYNOS5_GPE1(0),
2640                         .ngpio  = EXYNOS5_GPIO_E1_NR,
2641                         .label  = "GPE1",
2642                 },
2643         }, {
2644                 .chip   = {
2645                         .base   = EXYNOS5_GPF0(0),
2646                         .ngpio  = EXYNOS5_GPIO_F0_NR,
2647                         .label  = "GPF0",
2648                 },
2649         }, {
2650                 .chip   = {
2651                         .base   = EXYNOS5_GPF1(0),
2652                         .ngpio  = EXYNOS5_GPIO_F1_NR,
2653                         .label  = "GPF1",
2654                 },
2655         }, {
2656                 .chip   = {
2657                         .base   = EXYNOS5_GPG0(0),
2658                         .ngpio  = EXYNOS5_GPIO_G0_NR,
2659                         .label  = "GPG0",
2660                 },
2661         }, {
2662                 .chip   = {
2663                         .base   = EXYNOS5_GPG1(0),
2664                         .ngpio  = EXYNOS5_GPIO_G1_NR,
2665                         .label  = "GPG1",
2666                 },
2667         }, {
2668                 .chip   = {
2669                         .base   = EXYNOS5_GPG2(0),
2670                         .ngpio  = EXYNOS5_GPIO_G2_NR,
2671                         .label  = "GPG2",
2672                 },
2673         }, {
2674                 .chip   = {
2675                         .base   = EXYNOS5_GPH0(0),
2676                         .ngpio  = EXYNOS5_GPIO_H0_NR,
2677                         .label  = "GPH0",
2678                 },
2679         }, {
2680                 .chip   = {
2681                         .base   = EXYNOS5_GPH1(0),
2682                         .ngpio  = EXYNOS5_GPIO_H1_NR,
2683                         .label  = "GPH1",
2684
2685                 },
2686         },
2687 };
2688 #endif
2689
2690 #ifdef CONFIG_ARCH_EXYNOS5
2691 static struct samsung_gpio_chip exynos5_gpios_3[] = {
2692         {
2693                 .chip   = {
2694                         .base   = EXYNOS5_GPV0(0),
2695                         .ngpio  = EXYNOS5_GPIO_V0_NR,
2696                         .label  = "GPV0",
2697                 },
2698         }, {
2699                 .chip   = {
2700                         .base   = EXYNOS5_GPV1(0),
2701                         .ngpio  = EXYNOS5_GPIO_V1_NR,
2702                         .label  = "GPV1",
2703                 },
2704         }, {
2705                 .chip   = {
2706                         .base   = EXYNOS5_GPV2(0),
2707                         .ngpio  = EXYNOS5_GPIO_V2_NR,
2708                         .label  = "GPV2",
2709                 },
2710         }, {
2711                 .chip   = {
2712                         .base   = EXYNOS5_GPV3(0),
2713                         .ngpio  = EXYNOS5_GPIO_V3_NR,
2714                         .label  = "GPV3",
2715                 },
2716         }, {
2717                 .chip   = {
2718                         .base   = EXYNOS5_GPV4(0),
2719                         .ngpio  = EXYNOS5_GPIO_V4_NR,
2720                         .label  = "GPV4",
2721                 },
2722         },
2723 };
2724 #endif
2725
2726 #ifdef CONFIG_ARCH_EXYNOS5
2727 static struct samsung_gpio_chip exynos5_gpios_4[] = {
2728         {
2729                 .chip   = {
2730                         .base   = EXYNOS5_GPZ(0),
2731                         .ngpio  = EXYNOS5_GPIO_Z_NR,
2732                         .label  = "GPZ",
2733                 },
2734         },
2735 };
2736 #endif
2737
2738
2739 #if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF)
2740 static int exynos_gpio_xlate(struct gpio_chip *gc,
2741                         const struct of_phandle_args *gpiospec, u32 *flags)
2742 {
2743         unsigned int pin;
2744
2745         if (WARN_ON(gc->of_gpio_n_cells < 4))
2746                 return -EINVAL;
2747
2748         if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
2749                 return -EINVAL;
2750
2751         if (gpiospec->args[0] > gc->ngpio)
2752                 return -EINVAL;
2753
2754         pin = gc->base + gpiospec->args[0];
2755
2756         if (s3c_gpio_cfgpin(pin, S3C_GPIO_SFN(gpiospec->args[1])))
2757                 pr_warn("gpio_xlate: failed to set pin function\n");
2758         if (s3c_gpio_setpull(pin, gpiospec->args[2] & 0xffff))
2759                 pr_warn("gpio_xlate: failed to set pin pull up/down\n");
2760         if (s5p_gpio_set_drvstr(pin, gpiospec->args[3]))
2761                 pr_warn("gpio_xlate: failed to set pin drive strength\n");
2762
2763         /* flags are the upper 16 bits of the pull up/down cell, and currently
2764          * they correspond to the of_gpio_flags so we can just do a straight
2765          * assignment here.
2766          */
2767         if (flags)
2768                 *flags = gpiospec->args[2] >> 16;
2769
2770         return gpiospec->args[0];
2771 }
2772
2773 static const struct of_device_id exynos_gpio_dt_match[] __initdata = {
2774         { .compatible = "samsung,exynos4-gpio", },
2775         {}
2776 };
2777
2778 static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
2779                                                 u64 base, u64 offset)
2780 {
2781         struct gpio_chip *gc =  &chip->chip;
2782         u64 address;
2783
2784         if (!of_have_populated_dt())
2785                 return;
2786
2787         address = chip->base ? base + ((u32)chip->base & 0xfff) : base + offset;
2788         gc->of_node = of_find_matching_node_by_address(NULL,
2789                         exynos_gpio_dt_match, address);
2790         if (!gc->of_node) {
2791                 pr_info("gpio: device tree node not found for gpio controller"
2792                         " with base address %08llx\n", address);
2793                 return;
2794         }
2795         gc->of_gpio_n_cells = 4;
2796         gc->of_xlate = exynos_gpio_xlate;
2797 }
2798 #elif defined(CONFIG_ARCH_EXYNOS)
2799 static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip,
2800                                                 u64 base, u64 offset)
2801 {
2802         return;
2803 }
2804 #endif /* defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF) */
2805
2806 /* TODO: cleanup soc_is_* */
2807 static __init int samsung_gpiolib_init(void)
2808 {
2809         struct samsung_gpio_chip *chip;
2810         int i, nr_chips;
2811 #if defined(CONFIG_CPU_EXYNOS4210) || defined(CONFIG_SOC_EXYNOS5250)
2812         void __iomem *gpio_base1, *gpio_base2, *gpio_base3, *gpio_base4;
2813 #endif
2814         int group = 0;
2815
2816         samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs));
2817
2818         if (soc_is_s3c24xx()) {
2819                 s3c24xx_gpiolib_add_chips(s3c24xx_gpios,
2820                                 ARRAY_SIZE(s3c24xx_gpios), S3C24XX_VA_GPIO);
2821         } else if (soc_is_s3c64xx()) {
2822                 samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit,
2823                                 ARRAY_SIZE(s3c64xx_gpios_2bit),
2824                                 S3C64XX_VA_GPIO + 0xE0, 0x20);
2825                 samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit,
2826                                 ARRAY_SIZE(s3c64xx_gpios_4bit),
2827                                 S3C64XX_VA_GPIO);
2828                 samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
2829                                 ARRAY_SIZE(s3c64xx_gpios_4bit2));
2830         } else if (soc_is_s5p6440()) {
2831                 samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit,
2832                                 ARRAY_SIZE(s5p6440_gpios_2bit), NULL, 0x0);
2833                 samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit,
2834                                 ARRAY_SIZE(s5p6440_gpios_4bit), S5P_VA_GPIO);
2835                 samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2,
2836                                 ARRAY_SIZE(s5p6440_gpios_4bit2));
2837                 s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank,
2838                                 ARRAY_SIZE(s5p6440_gpios_rbank));
2839         } else if (soc_is_s5p6450()) {
2840                 samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit,
2841                                 ARRAY_SIZE(s5p6450_gpios_2bit), NULL, 0x0);
2842                 samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit,
2843                                 ARRAY_SIZE(s5p6450_gpios_4bit), S5P_VA_GPIO);
2844                 samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2,
2845                                 ARRAY_SIZE(s5p6450_gpios_4bit2));
2846                 s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank,
2847                                 ARRAY_SIZE(s5p6450_gpios_rbank));
2848         } else if (soc_is_s5pc100()) {
2849                 group = 0;
2850                 chip = s5pc100_gpios_4bit;
2851                 nr_chips = ARRAY_SIZE(s5pc100_gpios_4bit);
2852
2853                 for (i = 0; i < nr_chips; i++, chip++) {
2854                         if (!chip->config) {
2855                                 chip->config = &samsung_gpio_cfgs[3];
2856                                 chip->group = group++;
2857                         }
2858                 }
2859                 samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit, nr_chips, S5P_VA_GPIO);
2860 #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
2861                 s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
2862 #endif
2863         } else if (soc_is_s5pv210()) {
2864                 group = 0;
2865                 chip = s5pv210_gpios_4bit;
2866                 nr_chips = ARRAY_SIZE(s5pv210_gpios_4bit);
2867
2868                 for (i = 0; i < nr_chips; i++, chip++) {
2869                         if (!chip->config) {
2870                                 chip->config = &samsung_gpio_cfgs[3];
2871                                 chip->group = group++;
2872                         }
2873                 }
2874                 samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit, nr_chips, S5P_VA_GPIO);
2875 #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
2876                 s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
2877 #endif
2878         } else if (soc_is_exynos4210()) {
2879 #ifdef CONFIG_CPU_EXYNOS4210
2880                 void __iomem *gpx_base;
2881
2882                 /* gpio part1 */
2883                 gpio_base1 = ioremap(EXYNOS4_PA_GPIO1, SZ_4K);
2884                 if (gpio_base1 == NULL) {
2885                         pr_err("unable to ioremap for gpio_base1\n");
2886                         goto err_ioremap1;
2887                 }
2888
2889                 chip = exynos4_gpios_1;
2890                 nr_chips = ARRAY_SIZE(exynos4_gpios_1);
2891
2892                 for (i = 0; i < nr_chips; i++, chip++) {
2893                         if (!chip->config) {
2894                                 chip->config = &exynos_gpio_cfg;
2895                                 chip->group = group++;
2896                         }
2897                         exynos_gpiolib_attach_ofnode(chip,
2898                                         EXYNOS4_PA_GPIO1, i * 0x20);
2899                 }
2900                 samsung_gpiolib_add_4bit_chips(exynos4_gpios_1,
2901                                                nr_chips, gpio_base1);
2902
2903                 /* gpio part2 */
2904                 gpio_base2 = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
2905                 if (gpio_base2 == NULL) {
2906                         pr_err("unable to ioremap for gpio_base2\n");
2907                         goto err_ioremap2;
2908                 }
2909
2910                 /* need to set base address for gpx */
2911                 chip = &exynos4_gpios_2[16];
2912                 gpx_base = gpio_base2 + 0xC00;
2913                 for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
2914                         chip->base = gpx_base;
2915
2916                 chip = exynos4_gpios_2;
2917                 nr_chips = ARRAY_SIZE(exynos4_gpios_2);
2918
2919                 for (i = 0; i < nr_chips; i++, chip++) {
2920                         if (!chip->config) {
2921                                 chip->config = &exynos_gpio_cfg;
2922                                 chip->group = group++;
2923                         }
2924                         exynos_gpiolib_attach_ofnode(chip,
2925                                         EXYNOS4_PA_GPIO2, i * 0x20);
2926                 }
2927                 samsung_gpiolib_add_4bit_chips(exynos4_gpios_2,
2928                                                nr_chips, gpio_base2);
2929
2930                 /* gpio part3 */
2931                 gpio_base3 = ioremap(EXYNOS4_PA_GPIO3, SZ_256);
2932                 if (gpio_base3 == NULL) {
2933                         pr_err("unable to ioremap for gpio_base3\n");
2934                         goto err_ioremap3;
2935                 }
2936
2937                 chip = exynos4_gpios_3;
2938                 nr_chips = ARRAY_SIZE(exynos4_gpios_3);
2939
2940                 for (i = 0; i < nr_chips; i++, chip++) {
2941                         if (!chip->config) {
2942                                 chip->config = &exynos_gpio_cfg;
2943                                 chip->group = group++;
2944                         }
2945                         exynos_gpiolib_attach_ofnode(chip,
2946                                         EXYNOS4_PA_GPIO3, i * 0x20);
2947                 }
2948                 samsung_gpiolib_add_4bit_chips(exynos4_gpios_3,
2949                                                nr_chips, gpio_base3);
2950
2951 #if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT)
2952                 s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
2953                 s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
2954 #endif
2955
2956 #endif  /* CONFIG_CPU_EXYNOS4210 */
2957         } else if (soc_is_exynos5250()) {
2958 #ifdef CONFIG_SOC_EXYNOS5250
2959                 void __iomem *gpx_base;
2960
2961                 /* gpio part1 */
2962                 gpio_base1 = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
2963                 if (gpio_base1 == NULL) {
2964                         pr_err("unable to ioremap for gpio_base1\n");
2965                         goto err_ioremap1;
2966                 }
2967
2968                 /* need to set base address for gpc4 */
2969                 exynos5_gpios_1[20].base = gpio_base1 + 0x2E0;
2970
2971                 /* need to set base address for gpx */
2972                 chip = &exynos5_gpios_1[21];
2973                 gpx_base = gpio_base1 + 0xC00;
2974                 for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
2975                         chip->base = gpx_base;
2976
2977                 chip = exynos5_gpios_1;
2978                 nr_chips = ARRAY_SIZE(exynos5_gpios_1);
2979
2980                 for (i = 0; i < nr_chips; i++, chip++) {
2981                         if (!chip->config) {
2982                                 chip->config = &exynos_gpio_cfg;
2983                                 chip->group = group++;
2984                         }
2985                         exynos_gpiolib_attach_ofnode(chip,
2986                                         EXYNOS5_PA_GPIO1, i * 0x20);
2987                 }
2988                 samsung_gpiolib_add_4bit_chips(exynos5_gpios_1,
2989                                                nr_chips, gpio_base1);
2990
2991                 /* gpio part2 */
2992                 gpio_base2 = ioremap(EXYNOS5_PA_GPIO2, SZ_4K);
2993                 if (gpio_base2 == NULL) {
2994                         pr_err("unable to ioremap for gpio_base2\n");
2995                         goto err_ioremap2;
2996                 }
2997
2998                 chip = exynos5_gpios_2;
2999                 nr_chips = ARRAY_SIZE(exynos5_gpios_2);
3000
3001                 for (i = 0; i < nr_chips; i++, chip++) {
3002                         if (!chip->config) {
3003                                 chip->config = &exynos_gpio_cfg;
3004                                 chip->group = group++;
3005                         }
3006                         exynos_gpiolib_attach_ofnode(chip,
3007                                         EXYNOS5_PA_GPIO2, i * 0x20);
3008                 }
3009                 samsung_gpiolib_add_4bit_chips(exynos5_gpios_2,
3010                                                nr_chips, gpio_base2);
3011
3012                 /* gpio part3 */
3013                 gpio_base3 = ioremap(EXYNOS5_PA_GPIO3, SZ_4K);
3014                 if (gpio_base3 == NULL) {
3015                         pr_err("unable to ioremap for gpio_base3\n");
3016                         goto err_ioremap3;
3017                 }
3018
3019                 /* need to set base address for gpv */
3020                 exynos5_gpios_3[0].base = gpio_base3;
3021                 exynos5_gpios_3[1].base = gpio_base3 + 0x20;
3022                 exynos5_gpios_3[2].base = gpio_base3 + 0x60;
3023                 exynos5_gpios_3[3].base = gpio_base3 + 0x80;
3024                 exynos5_gpios_3[4].base = gpio_base3 + 0xC0;
3025
3026                 chip = exynos5_gpios_3;
3027                 nr_chips = ARRAY_SIZE(exynos5_gpios_3);
3028
3029                 for (i = 0; i < nr_chips; i++, chip++) {
3030                         if (!chip->config) {
3031                                 chip->config = &exynos_gpio_cfg;
3032                                 chip->group = group++;
3033                         }
3034                         exynos_gpiolib_attach_ofnode(chip,
3035                                         EXYNOS5_PA_GPIO3, i * 0x20);
3036                 }
3037                 samsung_gpiolib_add_4bit_chips(exynos5_gpios_3,
3038                                                nr_chips, gpio_base3);
3039
3040                 /* gpio part4 */
3041                 gpio_base4 = ioremap(EXYNOS5_PA_GPIO4, SZ_4K);
3042                 if (gpio_base4 == NULL) {
3043                         pr_err("unable to ioremap for gpio_base4\n");
3044                         goto err_ioremap4;
3045                 }
3046
3047                 chip = exynos5_gpios_4;
3048                 nr_chips = ARRAY_SIZE(exynos5_gpios_4);
3049
3050                 for (i = 0; i < nr_chips; i++, chip++) {
3051                         if (!chip->config) {
3052                                 chip->config = &exynos_gpio_cfg;
3053                                 chip->group = group++;
3054                         }
3055                         exynos_gpiolib_attach_ofnode(chip,
3056                                         EXYNOS5_PA_GPIO4, i * 0x20);
3057                 }
3058                 samsung_gpiolib_add_4bit_chips(exynos5_gpios_4,
3059                                                nr_chips, gpio_base4);
3060 #ifdef CONFIG_S5P_GPIO_INT
3061                 s5p_register_gpioint_bank(EXYNOS5_IRQ_GPIO_XA, 0,
3062                                           EXYNOS5_IRQ_GPIO1_NR_GROUPS);
3063                 s5p_register_gpioint_bank(EXYNOS5_IRQ_GPIO_XB,
3064                                           EXYNOS5_IRQ_GPIO1_NR_GROUPS,
3065                                           EXYNOS5_IRQ_GPIO2_NR_GROUPS);
3066 #endif
3067 #endif  /* CONFIG_SOC_EXYNOS5250 */
3068         } else {
3069                 WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
3070                 return -ENODEV;
3071         }
3072
3073         return 0;
3074
3075 #if defined(CONFIG_CPU_EXYNOS4210) || defined(CONFIG_SOC_EXYNOS5250)
3076 err_ioremap4:
3077         iounmap(gpio_base3);
3078 err_ioremap3:
3079         iounmap(gpio_base2);
3080 err_ioremap2:
3081         iounmap(gpio_base1);
3082 err_ioremap1:
3083         return -ENOMEM;
3084 #endif
3085 }
3086 core_initcall(samsung_gpiolib_init);
3087
3088 int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
3089 {
3090         struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
3091         unsigned long flags;
3092         int offset;
3093         int ret;
3094
3095         if (!chip)
3096                 return -EINVAL;
3097
3098         offset = pin - chip->chip.base;
3099
3100         samsung_gpio_lock(chip, flags);
3101         ret = samsung_gpio_do_setcfg(chip, offset, config);
3102         samsung_gpio_unlock(chip, flags);
3103
3104         return ret;
3105 }
3106 EXPORT_SYMBOL(s3c_gpio_cfgpin);
3107
3108 int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
3109                           unsigned int cfg)
3110 {
3111         int ret;
3112
3113         for (; nr > 0; nr--, start++) {
3114                 ret = s3c_gpio_cfgpin(start, cfg);
3115                 if (ret != 0)
3116                         return ret;
3117         }
3118
3119         return 0;
3120 }
3121 EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range);
3122
3123 int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
3124                           unsigned int cfg, samsung_gpio_pull_t pull)
3125 {
3126         int ret;
3127
3128         for (; nr > 0; nr--, start++) {
3129                 s3c_gpio_setpull(start, pull);
3130                 ret = s3c_gpio_cfgpin(start, cfg);
3131                 if (ret != 0)
3132                         return ret;
3133         }
3134
3135         return 0;
3136 }
3137 EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range);
3138
3139 unsigned s3c_gpio_getcfg(unsigned int pin)
3140 {
3141         struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
3142         unsigned long flags;
3143         unsigned ret = 0;
3144         int offset;
3145
3146         if (chip) {
3147                 offset = pin - chip->chip.base;
3148
3149                 samsung_gpio_lock(chip, flags);
3150                 ret = samsung_gpio_do_getcfg(chip, offset);
3151                 samsung_gpio_unlock(chip, flags);
3152         }
3153
3154         return ret;
3155 }
3156 EXPORT_SYMBOL(s3c_gpio_getcfg);
3157
3158 int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull)
3159 {
3160         struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
3161         unsigned long flags;
3162         int offset, ret;
3163
3164         if (!chip)
3165                 return -EINVAL;
3166
3167         offset = pin - chip->chip.base;
3168
3169         samsung_gpio_lock(chip, flags);
3170         ret = samsung_gpio_do_setpull(chip, offset, pull);
3171         samsung_gpio_unlock(chip, flags);
3172
3173         return ret;
3174 }
3175 EXPORT_SYMBOL(s3c_gpio_setpull);
3176
3177 samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin)
3178 {
3179         struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
3180         unsigned long flags;
3181         int offset;
3182         u32 pup = 0;
3183
3184         if (chip) {
3185                 offset = pin - chip->chip.base;
3186
3187                 samsung_gpio_lock(chip, flags);
3188                 pup = samsung_gpio_do_getpull(chip, offset);
3189                 samsung_gpio_unlock(chip, flags);
3190         }
3191
3192         return (__force samsung_gpio_pull_t)pup;
3193 }
3194 EXPORT_SYMBOL(s3c_gpio_getpull);
3195
3196 /* gpiolib wrappers until these are totally eliminated */
3197
3198 void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
3199 {
3200         int ret;
3201
3202         WARN_ON(to);    /* should be none of these left */
3203
3204         if (!to) {
3205                 /* if pull is enabled, try first with up, and if that
3206                  * fails, try using down */
3207
3208                 ret = s3c_gpio_setpull(pin, S3C_GPIO_PULL_UP);
3209                 if (ret)
3210                         s3c_gpio_setpull(pin, S3C_GPIO_PULL_DOWN);
3211         } else {
3212                 s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
3213         }
3214 }
3215 EXPORT_SYMBOL(s3c2410_gpio_pullup);
3216
3217 void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
3218 {
3219         /* do this via gpiolib until all users removed */
3220
3221         gpio_request(pin, "temporary");
3222         gpio_set_value(pin, to);
3223         gpio_free(pin);
3224 }
3225 EXPORT_SYMBOL(s3c2410_gpio_setpin);
3226
3227 unsigned int s3c2410_gpio_getpin(unsigned int pin)
3228 {
3229         struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
3230         unsigned long offs = pin - chip->chip.base;
3231
3232         return __raw_readl(chip->base + 0x04) & (1 << offs);
3233 }
3234 EXPORT_SYMBOL(s3c2410_gpio_getpin);
3235
3236 #ifdef CONFIG_S5P_GPIO_DRVSTR
3237 s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
3238 {
3239         struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
3240         unsigned int off;
3241         void __iomem *reg;
3242         int shift;
3243         u32 drvstr;
3244
3245         if (!chip)
3246                 return -EINVAL;
3247
3248         off = pin - chip->chip.base;
3249         shift = off * 2;
3250         reg = chip->base + 0x0C;
3251
3252         drvstr = __raw_readl(reg);
3253         drvstr = drvstr >> shift;
3254         drvstr &= 0x3;
3255
3256         return (__force s5p_gpio_drvstr_t)drvstr;
3257 }
3258 EXPORT_SYMBOL(s5p_gpio_get_drvstr);
3259
3260 int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
3261 {
3262         struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
3263         unsigned int off;
3264         void __iomem *reg;
3265         int shift;
3266         u32 tmp;
3267
3268         if (!chip)
3269                 return -EINVAL;
3270
3271         off = pin - chip->chip.base;
3272         shift = off * 2;
3273         reg = chip->base + 0x0C;
3274
3275         tmp = __raw_readl(reg);
3276         tmp &= ~(0x3 << shift);
3277         tmp |= drvstr << shift;
3278
3279         __raw_writel(tmp, reg);
3280
3281         return 0;
3282 }
3283 EXPORT_SYMBOL(s5p_gpio_set_drvstr);
3284 #endif  /* CONFIG_S5P_GPIO_DRVSTR */
3285
3286 #ifdef CONFIG_PLAT_S3C24XX
3287 unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
3288 {
3289         unsigned long flags;
3290         unsigned long misccr;
3291
3292         local_irq_save(flags);
3293         misccr = __raw_readl(S3C24XX_MISCCR);
3294         misccr &= ~clear;
3295         misccr ^= change;
3296         __raw_writel(misccr, S3C24XX_MISCCR);
3297         local_irq_restore(flags);
3298
3299         return misccr;
3300 }
3301 EXPORT_SYMBOL(s3c2410_modify_misccr);
3302 #endif