2 * Copyright (c) 2009-2011 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com/
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
10 * SAMSUNG - GPIOlib support
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.
17 #include <linux/kernel.h>
18 #include <linux/irq.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>
28 #include <linux/slab.h>
29 #include <linux/of_address.h>
33 #include <mach/hardware.h>
35 #include <mach/regs-clock.h>
36 #include <mach/regs-gpio.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>
46 #define gpio_dbg(x...) do { } while (0)
48 #define gpio_dbg(x...) printk(KERN_DEBUG x)
51 int samsung_gpio_setpull_updown(struct samsung_gpio_chip
*chip
,
52 unsigned int off
, samsung_gpio_pull_t pull
)
54 void __iomem
*reg
= chip
->base
+ 0x08;
58 pup
= __raw_readl(reg
);
61 __raw_writel(pup
, reg
);
66 samsung_gpio_pull_t
samsung_gpio_getpull_updown(struct samsung_gpio_chip
*chip
,
69 void __iomem
*reg
= chip
->base
+ 0x08;
71 u32 pup
= __raw_readl(reg
);
76 return (__force samsung_gpio_pull_t
)pup
;
79 int s3c2443_gpio_setpull(struct samsung_gpio_chip
*chip
,
80 unsigned int off
, samsung_gpio_pull_t pull
)
83 case S3C_GPIO_PULL_NONE
:
86 case S3C_GPIO_PULL_UP
:
89 case S3C_GPIO_PULL_DOWN
:
93 return samsung_gpio_setpull_updown(chip
, off
, pull
);
96 samsung_gpio_pull_t
s3c2443_gpio_getpull(struct samsung_gpio_chip
*chip
,
99 samsung_gpio_pull_t pull
;
101 pull
= samsung_gpio_getpull_updown(chip
, off
);
105 pull
= S3C_GPIO_PULL_UP
;
109 pull
= S3C_GPIO_PULL_NONE
;
112 pull
= S3C_GPIO_PULL_DOWN
;
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
)
123 void __iomem
*reg
= chip
->base
+ 0x08;
124 u32 pup
= __raw_readl(reg
);
128 else if (pull
== S3C_GPIO_PULL_NONE
)
133 __raw_writel(pup
, reg
);
137 static samsung_gpio_pull_t
s3c24xx_gpio_getpull_1(struct samsung_gpio_chip
*chip
,
139 samsung_gpio_pull_t updown
)
141 void __iomem
*reg
= chip
->base
+ 0x08;
142 u32 pup
= __raw_readl(reg
);
145 return pup
? S3C_GPIO_PULL_NONE
: updown
;
148 samsung_gpio_pull_t
s3c24xx_gpio_getpull_1up(struct samsung_gpio_chip
*chip
,
151 return s3c24xx_gpio_getpull_1(chip
, off
, S3C_GPIO_PULL_UP
);
154 int s3c24xx_gpio_setpull_1up(struct samsung_gpio_chip
*chip
,
155 unsigned int off
, samsung_gpio_pull_t pull
)
157 return s3c24xx_gpio_setpull_1(chip
, off
, pull
, S3C_GPIO_PULL_UP
);
160 samsung_gpio_pull_t
s3c24xx_gpio_getpull_1down(struct samsung_gpio_chip
*chip
,
163 return s3c24xx_gpio_getpull_1(chip
, off
, S3C_GPIO_PULL_DOWN
);
166 int s3c24xx_gpio_setpull_1down(struct samsung_gpio_chip
*chip
,
167 unsigned int off
, samsung_gpio_pull_t pull
)
169 return s3c24xx_gpio_setpull_1(chip
, off
, pull
, S3C_GPIO_PULL_DOWN
);
172 static int exynos_gpio_setpull(struct samsung_gpio_chip
*chip
,
173 unsigned int off
, samsung_gpio_pull_t pull
)
175 if (pull
== S3C_GPIO_PULL_UP
)
178 return samsung_gpio_setpull_updown(chip
, off
, pull
);
181 static samsung_gpio_pull_t
exynos_gpio_getpull(struct samsung_gpio_chip
*chip
,
184 samsung_gpio_pull_t pull
;
186 pull
= samsung_gpio_getpull_updown(chip
, off
);
189 pull
= S3C_GPIO_PULL_UP
;
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.
200 * This helper deal with the GPIO cases where the control register
201 * has two bits of configuration per gpio, which have the following
205 * 1x = special function
208 static int samsung_gpio_setcfg_2bit(struct samsung_gpio_chip
*chip
,
209 unsigned int off
, unsigned int cfg
)
211 void __iomem
*reg
= chip
->base
;
212 unsigned int shift
= off
* 2;
215 if (samsung_gpio_is_cfg_special(cfg
)) {
223 con
= __raw_readl(reg
);
224 con
&= ~(0x3 << shift
);
226 __raw_writel(con
, reg
);
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.
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.
241 static unsigned int samsung_gpio_getcfg_2bit(struct samsung_gpio_chip
*chip
,
246 con
= __raw_readl(chip
->base
);
250 /* this conversion works for IN and OUT as well as special mode */
251 return S3C_GPIO_SPECIAL(con
);
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.
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:
264 * others = Special functions (dependent on bank)
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
271 static int samsung_gpio_setcfg_4bit(struct samsung_gpio_chip
*chip
,
272 unsigned int off
, unsigned int cfg
)
274 void __iomem
*reg
= chip
->base
;
275 unsigned int shift
= (off
& 7) * 4;
278 if (off
< 8 && chip
->chip
.ngpio
> 8)
281 if (samsung_gpio_is_cfg_special(cfg
)) {
286 con
= __raw_readl(reg
);
287 con
&= ~(0xf << shift
);
289 __raw_writel(con
, reg
);
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.
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().
303 * @sa samsung_gpio_getcfg_2bit
306 static unsigned samsung_gpio_getcfg_4bit(struct samsung_gpio_chip
*chip
,
309 void __iomem
*reg
= chip
->base
;
310 unsigned int shift
= (off
& 7) * 4;
313 if (off
< 8 && chip
->chip
.ngpio
> 8)
316 con
= __raw_readl(reg
);
320 /* this conversion works for IN and OUT as well as special mode */
321 return S3C_GPIO_SPECIAL(con
);
324 #ifdef CONFIG_PLAT_S3C24XX
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.
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.
336 static int s3c24xx_gpio_setcfg_abank(struct samsung_gpio_chip
*chip
,
337 unsigned int off
, unsigned int cfg
)
339 void __iomem
*reg
= chip
->base
;
340 unsigned int shift
= off
;
343 if (samsung_gpio_is_cfg_special(cfg
)) {
346 /* Map output to 0, and SFN2 to 1 */
354 con
= __raw_readl(reg
);
355 con
&= ~(0x1 << shift
);
357 __raw_writel(con
, reg
);
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.
367 * The reverse of s3c24xx_gpio_setcfg_abank() turning an GPIO into a usable
368 * GPIO configuration value.
370 * @sa samsung_gpio_getcfg_2bit
371 * @sa samsung_gpio_getcfg_4bit
374 static unsigned s3c24xx_gpio_getcfg_abank(struct samsung_gpio_chip
*chip
,
379 con
= __raw_readl(chip
->base
);
384 return S3C_GPIO_SFN(con
);
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
)
392 void __iomem
*reg
= chip
->base
;
403 shift
= (off
& 7) * 4;
407 shift
= ((off
+ 1) & 7) * 4;
410 shift
= ((off
+ 1) & 7) * 4;
414 if (samsung_gpio_is_cfg_special(cfg
)) {
419 con
= __raw_readl(reg
);
420 con
&= ~(0xf << shift
);
422 __raw_writel(con
, reg
);
428 static void __init
samsung_gpiolib_set_cfg(struct samsung_gpio_cfg
*chipcfg
,
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
;
443 struct samsung_gpio_cfg s3c24xx_gpiocfg_default
= {
444 .set_config
= samsung_gpio_setcfg_2bit
,
445 .get_config
= samsung_gpio_getcfg_2bit
,
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
,
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
,
464 #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
465 static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank
= {
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
,
474 static struct samsung_gpio_cfg samsung_gpio_cfgs
[] = {
489 .set_config
= samsung_gpio_setcfg_2bit
,
490 .get_config
= samsung_gpio_getcfg_2bit
,
494 .set_config
= samsung_gpio_setcfg_2bit
,
495 .get_config
= samsung_gpio_getcfg_2bit
,
499 .set_config
= samsung_gpio_setcfg_2bit
,
500 .get_config
= samsung_gpio_getcfg_2bit
,
503 .set_config
= samsung_gpio_setcfg_2bit
,
504 .get_config
= samsung_gpio_getcfg_2bit
,
507 .set_pull
= exynos_gpio_setpull
,
508 .get_pull
= exynos_gpio_getpull
,
512 .set_pull
= exynos_gpio_setpull
,
513 .get_pull
= exynos_gpio_getpull
,
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:
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
529 static int samsung_gpiolib_2bit_input(struct gpio_chip
*chip
, unsigned offset
)
531 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
532 void __iomem
*base
= ourchip
->base
;
536 samsung_gpio_lock(ourchip
, flags
);
538 con
= __raw_readl(base
+ 0x00);
539 con
&= ~(3 << (offset
* 2));
541 __raw_writel(con
, base
+ 0x00);
543 samsung_gpio_unlock(ourchip
, flags
);
547 static int samsung_gpiolib_2bit_output(struct gpio_chip
*chip
,
548 unsigned offset
, int value
)
550 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
551 void __iomem
*base
= ourchip
->base
;
556 samsung_gpio_lock(ourchip
, flags
);
558 dat
= __raw_readl(base
+ 0x04);
559 dat
&= ~(1 << offset
);
562 __raw_writel(dat
, base
+ 0x04);
564 con
= __raw_readl(base
+ 0x00);
565 con
&= ~(3 << (offset
* 2));
566 con
|= 1 << (offset
* 2);
568 __raw_writel(con
, base
+ 0x00);
569 __raw_writel(dat
, base
+ 0x04);
571 samsung_gpio_unlock(ourchip
, flags
);
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
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
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.
591 static int samsung_gpiolib_4bit_input(struct gpio_chip
*chip
,
594 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
595 void __iomem
*base
= ourchip
->base
;
598 con
= __raw_readl(base
+ GPIOCON_OFF
);
599 con
&= ~(0xf << con_4bit_shift(offset
));
600 __raw_writel(con
, base
+ GPIOCON_OFF
);
602 gpio_dbg("%s: %p: CON now %08lx\n", __func__
, base
, con
);
607 static int samsung_gpiolib_4bit_output(struct gpio_chip
*chip
,
608 unsigned int offset
, int value
)
610 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
611 void __iomem
*base
= ourchip
->base
;
615 con
= __raw_readl(base
+ GPIOCON_OFF
);
616 con
&= ~(0xf << con_4bit_shift(offset
));
617 con
|= 0x1 << con_4bit_shift(offset
);
619 dat
= __raw_readl(base
+ GPIODAT_OFF
);
624 dat
&= ~(1 << offset
);
626 __raw_writel(dat
, base
+ GPIODAT_OFF
);
627 __raw_writel(con
, base
+ GPIOCON_OFF
);
628 __raw_writel(dat
, base
+ GPIODAT_OFF
);
630 gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__
, base
, con
, dat
);
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.
640 * This case is the similar to the 4 bit case, but the registers are as
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
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.
657 static int samsung_gpiolib_4bit2_input(struct gpio_chip
*chip
,
660 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
661 void __iomem
*base
= ourchip
->base
;
662 void __iomem
*regcon
= base
;
670 con
= __raw_readl(regcon
);
671 con
&= ~(0xf << con_4bit_shift(offset
));
672 __raw_writel(con
, regcon
);
674 gpio_dbg("%s: %p: CON %08lx\n", __func__
, base
, con
);
679 static int samsung_gpiolib_4bit2_output(struct gpio_chip
*chip
,
680 unsigned int offset
, int value
)
682 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
683 void __iomem
*base
= ourchip
->base
;
684 void __iomem
*regcon
= base
;
687 unsigned con_offset
= offset
;
694 con
= __raw_readl(regcon
);
695 con
&= ~(0xf << con_4bit_shift(con_offset
));
696 con
|= 0x1 << con_4bit_shift(con_offset
);
698 dat
= __raw_readl(base
+ GPIODAT_OFF
);
703 dat
&= ~(1 << offset
);
705 __raw_writel(dat
, base
+ GPIODAT_OFF
);
706 __raw_writel(con
, regcon
);
707 __raw_writel(dat
, base
+ GPIODAT_OFF
);
709 gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__
, base
, con
, dat
);
714 #ifdef CONFIG_PLAT_S3C24XX
715 /* The next set of routines are for the case of s3c24xx bank a */
717 static int s3c24xx_gpiolib_banka_input(struct gpio_chip
*chip
, unsigned offset
)
722 static int s3c24xx_gpiolib_banka_output(struct gpio_chip
*chip
,
723 unsigned offset
, int value
)
725 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
726 void __iomem
*base
= ourchip
->base
;
731 local_irq_save(flags
);
733 con
= __raw_readl(base
+ 0x00);
734 dat
= __raw_readl(base
+ 0x04);
736 dat
&= ~(1 << offset
);
740 __raw_writel(dat
, base
+ 0x04);
742 con
&= ~(1 << offset
);
744 __raw_writel(con
, base
+ 0x00);
745 __raw_writel(dat
, base
+ 0x04);
747 local_irq_restore(flags
);
752 /* The next set of routines are for the case of s5p64x0 bank r */
754 static int s5p64x0_gpiolib_rbank_input(struct gpio_chip
*chip
,
757 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
758 void __iomem
*base
= ourchip
->base
;
759 void __iomem
*regcon
= base
;
779 samsung_gpio_lock(ourchip
, flags
);
781 con
= __raw_readl(regcon
);
782 con
&= ~(0xf << con_4bit_shift(offset
));
783 __raw_writel(con
, regcon
);
785 samsung_gpio_unlock(ourchip
, flags
);
790 static int s5p64x0_gpiolib_rbank_output(struct gpio_chip
*chip
,
791 unsigned int offset
, int value
)
793 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
794 void __iomem
*base
= ourchip
->base
;
795 void __iomem
*regcon
= base
;
799 unsigned con_offset
= offset
;
801 switch (con_offset
) {
817 samsung_gpio_lock(ourchip
, flags
);
819 con
= __raw_readl(regcon
);
820 con
&= ~(0xf << con_4bit_shift(con_offset
));
821 con
|= 0x1 << con_4bit_shift(con_offset
);
823 dat
= __raw_readl(base
+ GPIODAT_OFF
);
827 dat
&= ~(1 << offset
);
829 __raw_writel(con
, regcon
);
830 __raw_writel(dat
, base
+ GPIODAT_OFF
);
832 samsung_gpio_unlock(ourchip
, flags
);
837 static void samsung_gpiolib_set(struct gpio_chip
*chip
,
838 unsigned offset
, int value
)
840 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
841 void __iomem
*base
= ourchip
->base
;
845 samsung_gpio_lock(ourchip
, flags
);
847 dat
= __raw_readl(base
+ 0x04);
848 dat
&= ~(1 << offset
);
851 __raw_writel(dat
, base
+ 0x04);
853 samsung_gpio_unlock(ourchip
, flags
);
856 static int samsung_gpiolib_get(struct gpio_chip
*chip
, unsigned offset
)
858 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
861 val
= __raw_readl(ourchip
->base
+ 0x04);
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
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.
880 #ifdef CONFIG_S3C_GPIO_TRACK
881 struct samsung_gpio_chip
*s3c_gpios
[S3C_GPIO_END
];
883 static __init
void s3c_gpiolib_track(struct samsung_gpio_chip
*chip
)
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
;
894 #endif /* CONFIG_S3C_GPIO_TRACK */
897 * samsung_gpiolib_add() - add the Samsung gpio_chip.
898 * @chip: The chip to register
900 * This is a wrapper to gpiochip_add() that takes our specific gpio chip
901 * information and makes the necessary alterations for the platform and
902 * notes the information for use with the configuration systems and any
903 * other parts of the system.
906 static void __init
samsung_gpiolib_add(struct samsung_gpio_chip
*chip
)
908 struct gpio_chip
*gc
= &chip
->chip
;
915 spin_lock_init(&chip
->lock
);
917 if (!gc
->direction_input
)
918 gc
->direction_input
= samsung_gpiolib_2bit_input
;
919 if (!gc
->direction_output
)
920 gc
->direction_output
= samsung_gpiolib_2bit_output
;
922 gc
->set
= samsung_gpiolib_set
;
924 gc
->get
= samsung_gpiolib_get
;
927 if (chip
->pm
!= NULL
) {
928 if (!chip
->pm
->save
|| !chip
->pm
->resume
)
929 printk(KERN_ERR
"gpio: %s has missing PM functions\n",
932 printk(KERN_ERR
"gpio: %s has no PM function\n", gc
->label
);
935 /* gpiochip_add() prints own failure message on error. */
936 ret
= gpiochip_add(gc
);
938 s3c_gpiolib_track(chip
);
941 static void __init
s3c24xx_gpiolib_add_chips(struct samsung_gpio_chip
*chip
,
942 int nr_chips
, void __iomem
*base
)
945 struct gpio_chip
*gc
= &chip
->chip
;
947 for (i
= 0 ; i
< nr_chips
; i
++, chip
++) {
948 /* skip banks not present on SoC */
949 if (chip
->chip
.base
>= S3C_GPIO_END
)
953 chip
->config
= &s3c24xx_gpiocfg_default
;
955 chip
->pm
= __gpio_pm(&samsung_gpio_pm_2bit
);
956 if ((base
!= NULL
) && (chip
->base
== NULL
))
957 chip
->base
= base
+ ((i
) * 0x10);
959 if (!gc
->direction_input
)
960 gc
->direction_input
= samsung_gpiolib_2bit_input
;
961 if (!gc
->direction_output
)
962 gc
->direction_output
= samsung_gpiolib_2bit_output
;
964 samsung_gpiolib_add(chip
);
968 static void __init
samsung_gpiolib_add_2bit_chips(struct samsung_gpio_chip
*chip
,
969 int nr_chips
, void __iomem
*base
,
974 for (i
= 0 ; i
< nr_chips
; i
++, chip
++) {
975 chip
->chip
.direction_input
= samsung_gpiolib_2bit_input
;
976 chip
->chip
.direction_output
= samsung_gpiolib_2bit_output
;
979 chip
->config
= &samsung_gpio_cfgs
[7];
981 chip
->pm
= __gpio_pm(&samsung_gpio_pm_2bit
);
982 if ((base
!= NULL
) && (chip
->base
== NULL
))
983 chip
->base
= base
+ ((i
) * offset
);
985 samsung_gpiolib_add(chip
);
990 * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
991 * @chip: The gpio chip that is being configured.
992 * @nr_chips: The no of chips (gpio ports) for the GPIO being configured.
994 * This helper deal with the GPIO cases where the control register has 4 bits
995 * of control per GPIO, generally in the form of:
998 * others = Special functions (dependent on bank)
1000 * Note, since the code to deal with the case where there are two control
1001 * registers instead of one, we do not have a separate set of function
1002 * (samsung_gpiolib_add_4bit2_chips)for each case.
1005 static void __init
samsung_gpiolib_add_4bit_chips(struct samsung_gpio_chip
*chip
,
1006 int nr_chips
, void __iomem
*base
)
1010 for (i
= 0 ; i
< nr_chips
; i
++, chip
++) {
1011 chip
->chip
.direction_input
= samsung_gpiolib_4bit_input
;
1012 chip
->chip
.direction_output
= samsung_gpiolib_4bit_output
;
1015 chip
->config
= &samsung_gpio_cfgs
[2];
1017 chip
->pm
= __gpio_pm(&samsung_gpio_pm_4bit
);
1018 if ((base
!= NULL
) && (chip
->base
== NULL
))
1019 chip
->base
= base
+ ((i
) * 0x20);
1021 samsung_gpiolib_add(chip
);
1025 static void __init
samsung_gpiolib_add_4bit2_chips(struct samsung_gpio_chip
*chip
,
1028 for (; nr_chips
> 0; nr_chips
--, chip
++) {
1029 chip
->chip
.direction_input
= samsung_gpiolib_4bit2_input
;
1030 chip
->chip
.direction_output
= samsung_gpiolib_4bit2_output
;
1033 chip
->config
= &samsung_gpio_cfgs
[2];
1035 chip
->pm
= __gpio_pm(&samsung_gpio_pm_4bit
);
1037 samsung_gpiolib_add(chip
);
1041 static void __init
s5p64x0_gpiolib_add_rbank(struct samsung_gpio_chip
*chip
,
1044 for (; nr_chips
> 0; nr_chips
--, chip
++) {
1045 chip
->chip
.direction_input
= s5p64x0_gpiolib_rbank_input
;
1046 chip
->chip
.direction_output
= s5p64x0_gpiolib_rbank_output
;
1049 chip
->pm
= __gpio_pm(&samsung_gpio_pm_4bit
);
1051 samsung_gpiolib_add(chip
);
1055 int samsung_gpiolib_to_irq(struct gpio_chip
*chip
, unsigned int offset
)
1057 struct samsung_gpio_chip
*samsung_chip
= container_of(chip
, struct samsung_gpio_chip
, chip
);
1059 return samsung_chip
->irq_base
+ offset
;
1062 #ifdef CONFIG_PLAT_S3C24XX
1063 static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip
*chip
, unsigned offset
)
1066 return IRQ_EINT0
+ offset
;
1069 return IRQ_EINT4
+ offset
- 4;
1075 #ifdef CONFIG_PLAT_S3C64XX
1076 static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip
*chip
, unsigned pin
)
1078 return pin
< 5 ? IRQ_EINT(23) + pin
: -ENXIO
;
1081 static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip
*chip
, unsigned pin
)
1083 return pin
>= 8 ? IRQ_EINT(16) + pin
- 8 : -ENXIO
;
1087 struct samsung_gpio_chip s3c24xx_gpios
[] = {
1088 #ifdef CONFIG_PLAT_S3C24XX
1090 .config
= &s3c24xx_gpiocfg_banka
,
1092 .base
= S3C2410_GPA(0),
1093 .owner
= THIS_MODULE
,
1096 .direction_input
= s3c24xx_gpiolib_banka_input
,
1097 .direction_output
= s3c24xx_gpiolib_banka_output
,
1101 .base
= S3C2410_GPB(0),
1102 .owner
= THIS_MODULE
,
1108 .base
= S3C2410_GPC(0),
1109 .owner
= THIS_MODULE
,
1115 .base
= S3C2410_GPD(0),
1116 .owner
= THIS_MODULE
,
1122 .base
= S3C2410_GPE(0),
1124 .owner
= THIS_MODULE
,
1129 .base
= S3C2410_GPF(0),
1130 .owner
= THIS_MODULE
,
1133 .to_irq
= s3c24xx_gpiolib_fbank_to_irq
,
1136 .irq_base
= IRQ_EINT8
,
1138 .base
= S3C2410_GPG(0),
1139 .owner
= THIS_MODULE
,
1142 .to_irq
= samsung_gpiolib_to_irq
,
1146 .base
= S3C2410_GPH(0),
1147 .owner
= THIS_MODULE
,
1152 /* GPIOS for the S3C2443 and later devices. */
1154 .base
= S3C2440_GPJCON
,
1156 .base
= S3C2410_GPJ(0),
1157 .owner
= THIS_MODULE
,
1162 .base
= S3C2443_GPKCON
,
1164 .base
= S3C2410_GPK(0),
1165 .owner
= THIS_MODULE
,
1170 .base
= S3C2443_GPLCON
,
1172 .base
= S3C2410_GPL(0),
1173 .owner
= THIS_MODULE
,
1178 .base
= S3C2443_GPMCON
,
1180 .base
= S3C2410_GPM(0),
1181 .owner
= THIS_MODULE
,
1190 * GPIO bank summary:
1192 * Bank GPIOs Style SlpCon ExtInt Group
1198 * F 16 2Bit Yes 4 [1]
1200 * H 10 4Bit[2] Yes 6
1201 * I 16 2Bit Yes None
1202 * J 12 2Bit Yes None
1203 * K 16 4Bit[2] No None
1204 * L 15 4Bit[2] No None
1205 * M 6 4Bit No IRQ_EINT
1206 * N 16 2Bit No IRQ_EINT
1211 * [1] BANKF pins 14,15 do not form part of the external interrupt sources
1212 * [2] BANK has two control registers, GPxCON0 and GPxCON1
1215 static struct samsung_gpio_chip s3c64xx_gpios_4bit
[] = {
1216 #ifdef CONFIG_PLAT_S3C64XX
1219 .base
= S3C64XX_GPA(0),
1220 .ngpio
= S3C64XX_GPIO_A_NR
,
1225 .base
= S3C64XX_GPB(0),
1226 .ngpio
= S3C64XX_GPIO_B_NR
,
1231 .base
= S3C64XX_GPC(0),
1232 .ngpio
= S3C64XX_GPIO_C_NR
,
1237 .base
= S3C64XX_GPD(0),
1238 .ngpio
= S3C64XX_GPIO_D_NR
,
1242 .config
= &samsung_gpio_cfgs
[0],
1244 .base
= S3C64XX_GPE(0),
1245 .ngpio
= S3C64XX_GPIO_E_NR
,
1249 .base
= S3C64XX_GPG_BASE
,
1251 .base
= S3C64XX_GPG(0),
1252 .ngpio
= S3C64XX_GPIO_G_NR
,
1256 .base
= S3C64XX_GPM_BASE
,
1257 .config
= &samsung_gpio_cfgs
[1],
1259 .base
= S3C64XX_GPM(0),
1260 .ngpio
= S3C64XX_GPIO_M_NR
,
1262 .to_irq
= s3c64xx_gpiolib_mbank_to_irq
,
1268 static struct samsung_gpio_chip s3c64xx_gpios_4bit2
[] = {
1269 #ifdef CONFIG_PLAT_S3C64XX
1271 .base
= S3C64XX_GPH_BASE
+ 0x4,
1273 .base
= S3C64XX_GPH(0),
1274 .ngpio
= S3C64XX_GPIO_H_NR
,
1278 .base
= S3C64XX_GPK_BASE
+ 0x4,
1279 .config
= &samsung_gpio_cfgs
[0],
1281 .base
= S3C64XX_GPK(0),
1282 .ngpio
= S3C64XX_GPIO_K_NR
,
1286 .base
= S3C64XX_GPL_BASE
+ 0x4,
1287 .config
= &samsung_gpio_cfgs
[1],
1289 .base
= S3C64XX_GPL(0),
1290 .ngpio
= S3C64XX_GPIO_L_NR
,
1292 .to_irq
= s3c64xx_gpiolib_lbank_to_irq
,
1298 static struct samsung_gpio_chip s3c64xx_gpios_2bit
[] = {
1299 #ifdef CONFIG_PLAT_S3C64XX
1301 .base
= S3C64XX_GPF_BASE
,
1302 .config
= &samsung_gpio_cfgs
[6],
1304 .base
= S3C64XX_GPF(0),
1305 .ngpio
= S3C64XX_GPIO_F_NR
,
1309 .config
= &samsung_gpio_cfgs
[7],
1311 .base
= S3C64XX_GPI(0),
1312 .ngpio
= S3C64XX_GPIO_I_NR
,
1316 .config
= &samsung_gpio_cfgs
[7],
1318 .base
= S3C64XX_GPJ(0),
1319 .ngpio
= S3C64XX_GPIO_J_NR
,
1323 .config
= &samsung_gpio_cfgs
[6],
1325 .base
= S3C64XX_GPO(0),
1326 .ngpio
= S3C64XX_GPIO_O_NR
,
1330 .config
= &samsung_gpio_cfgs
[6],
1332 .base
= S3C64XX_GPP(0),
1333 .ngpio
= S3C64XX_GPIO_P_NR
,
1337 .config
= &samsung_gpio_cfgs
[6],
1339 .base
= S3C64XX_GPQ(0),
1340 .ngpio
= S3C64XX_GPIO_Q_NR
,
1344 .base
= S3C64XX_GPN_BASE
,
1345 .irq_base
= IRQ_EINT(0),
1346 .config
= &samsung_gpio_cfgs
[5],
1348 .base
= S3C64XX_GPN(0),
1349 .ngpio
= S3C64XX_GPIO_N_NR
,
1351 .to_irq
= samsung_gpiolib_to_irq
,
1358 * S5P6440 GPIO bank summary:
1360 * Bank GPIOs Style SlpCon ExtInt Group
1364 * F 2 2Bit Yes 4 [1]
1366 * H 10 4Bit[2] Yes 6
1367 * I 16 2Bit Yes None
1368 * J 12 2Bit Yes None
1369 * N 16 2Bit No IRQ_EINT
1371 * R 15 4Bit[2] Yes 8
1374 static struct samsung_gpio_chip s5p6440_gpios_4bit
[] = {
1375 #ifdef CONFIG_CPU_S5P6440
1378 .base
= S5P6440_GPA(0),
1379 .ngpio
= S5P6440_GPIO_A_NR
,
1384 .base
= S5P6440_GPB(0),
1385 .ngpio
= S5P6440_GPIO_B_NR
,
1390 .base
= S5P6440_GPC(0),
1391 .ngpio
= S5P6440_GPIO_C_NR
,
1395 .base
= S5P64X0_GPG_BASE
,
1397 .base
= S5P6440_GPG(0),
1398 .ngpio
= S5P6440_GPIO_G_NR
,
1405 static struct samsung_gpio_chip s5p6440_gpios_4bit2
[] = {
1406 #ifdef CONFIG_CPU_S5P6440
1408 .base
= S5P64X0_GPH_BASE
+ 0x4,
1410 .base
= S5P6440_GPH(0),
1411 .ngpio
= S5P6440_GPIO_H_NR
,
1418 static struct samsung_gpio_chip s5p6440_gpios_rbank
[] = {
1419 #ifdef CONFIG_CPU_S5P6440
1421 .base
= S5P64X0_GPR_BASE
+ 0x4,
1422 .config
= &s5p64x0_gpio_cfg_rbank
,
1424 .base
= S5P6440_GPR(0),
1425 .ngpio
= S5P6440_GPIO_R_NR
,
1432 static struct samsung_gpio_chip s5p6440_gpios_2bit
[] = {
1433 #ifdef CONFIG_CPU_S5P6440
1435 .base
= S5P64X0_GPF_BASE
,
1436 .config
= &samsung_gpio_cfgs
[6],
1438 .base
= S5P6440_GPF(0),
1439 .ngpio
= S5P6440_GPIO_F_NR
,
1443 .base
= S5P64X0_GPI_BASE
,
1444 .config
= &samsung_gpio_cfgs
[4],
1446 .base
= S5P6440_GPI(0),
1447 .ngpio
= S5P6440_GPIO_I_NR
,
1451 .base
= S5P64X0_GPJ_BASE
,
1452 .config
= &samsung_gpio_cfgs
[4],
1454 .base
= S5P6440_GPJ(0),
1455 .ngpio
= S5P6440_GPIO_J_NR
,
1459 .base
= S5P64X0_GPN_BASE
,
1460 .config
= &samsung_gpio_cfgs
[5],
1462 .base
= S5P6440_GPN(0),
1463 .ngpio
= S5P6440_GPIO_N_NR
,
1467 .base
= S5P64X0_GPP_BASE
,
1468 .config
= &samsung_gpio_cfgs
[6],
1470 .base
= S5P6440_GPP(0),
1471 .ngpio
= S5P6440_GPIO_P_NR
,
1479 * S5P6450 GPIO bank summary:
1481 * Bank GPIOs Style SlpCon ExtInt Group
1487 * G 14 4Bit[2] Yes 5
1488 * H 10 4Bit[2] Yes 6
1489 * I 16 2Bit Yes None
1490 * J 12 2Bit Yes None
1492 * N 16 2Bit No IRQ_EINT
1494 * Q 14 2Bit Yes None
1495 * R 15 4Bit[2] Yes None
1498 * [1] BANKF pins 14,15 do not form part of the external interrupt sources
1499 * [2] BANK has two control registers, GPxCON0 and GPxCON1
1502 static struct samsung_gpio_chip s5p6450_gpios_4bit
[] = {
1503 #ifdef CONFIG_CPU_S5P6450
1506 .base
= S5P6450_GPA(0),
1507 .ngpio
= S5P6450_GPIO_A_NR
,
1512 .base
= S5P6450_GPB(0),
1513 .ngpio
= S5P6450_GPIO_B_NR
,
1518 .base
= S5P6450_GPC(0),
1519 .ngpio
= S5P6450_GPIO_C_NR
,
1524 .base
= S5P6450_GPD(0),
1525 .ngpio
= S5P6450_GPIO_D_NR
,
1529 .base
= S5P6450_GPK_BASE
,
1531 .base
= S5P6450_GPK(0),
1532 .ngpio
= S5P6450_GPIO_K_NR
,
1539 static struct samsung_gpio_chip s5p6450_gpios_4bit2
[] = {
1540 #ifdef CONFIG_CPU_S5P6450
1542 .base
= S5P64X0_GPG_BASE
+ 0x4,
1544 .base
= S5P6450_GPG(0),
1545 .ngpio
= S5P6450_GPIO_G_NR
,
1549 .base
= S5P64X0_GPH_BASE
+ 0x4,
1551 .base
= S5P6450_GPH(0),
1552 .ngpio
= S5P6450_GPIO_H_NR
,
1559 static struct samsung_gpio_chip s5p6450_gpios_rbank
[] = {
1560 #ifdef CONFIG_CPU_S5P6450
1562 .base
= S5P64X0_GPR_BASE
+ 0x4,
1563 .config
= &s5p64x0_gpio_cfg_rbank
,
1565 .base
= S5P6450_GPR(0),
1566 .ngpio
= S5P6450_GPIO_R_NR
,
1573 static struct samsung_gpio_chip s5p6450_gpios_2bit
[] = {
1574 #ifdef CONFIG_CPU_S5P6450
1576 .base
= S5P64X0_GPF_BASE
,
1577 .config
= &samsung_gpio_cfgs
[6],
1579 .base
= S5P6450_GPF(0),
1580 .ngpio
= S5P6450_GPIO_F_NR
,
1584 .base
= S5P64X0_GPI_BASE
,
1585 .config
= &samsung_gpio_cfgs
[4],
1587 .base
= S5P6450_GPI(0),
1588 .ngpio
= S5P6450_GPIO_I_NR
,
1592 .base
= S5P64X0_GPJ_BASE
,
1593 .config
= &samsung_gpio_cfgs
[4],
1595 .base
= S5P6450_GPJ(0),
1596 .ngpio
= S5P6450_GPIO_J_NR
,
1600 .base
= S5P64X0_GPN_BASE
,
1601 .config
= &samsung_gpio_cfgs
[5],
1603 .base
= S5P6450_GPN(0),
1604 .ngpio
= S5P6450_GPIO_N_NR
,
1608 .base
= S5P64X0_GPP_BASE
,
1609 .config
= &samsung_gpio_cfgs
[6],
1611 .base
= S5P6450_GPP(0),
1612 .ngpio
= S5P6450_GPIO_P_NR
,
1616 .base
= S5P6450_GPQ_BASE
,
1617 .config
= &samsung_gpio_cfgs
[5],
1619 .base
= S5P6450_GPQ(0),
1620 .ngpio
= S5P6450_GPIO_Q_NR
,
1624 .base
= S5P6450_GPS_BASE
,
1625 .config
= &samsung_gpio_cfgs
[6],
1627 .base
= S5P6450_GPS(0),
1628 .ngpio
= S5P6450_GPIO_S_NR
,
1636 * S5PC100 GPIO bank summary:
1638 * Bank GPIOs Style INT Type
1639 * A0 8 4Bit GPIO_INT0
1640 * A1 5 4Bit GPIO_INT1
1641 * B 8 4Bit GPIO_INT2
1642 * C 5 4Bit GPIO_INT3
1643 * D 7 4Bit GPIO_INT4
1644 * E0 8 4Bit GPIO_INT5
1645 * E1 6 4Bit GPIO_INT6
1646 * F0 8 4Bit GPIO_INT7
1647 * F1 8 4Bit GPIO_INT8
1648 * F2 8 4Bit GPIO_INT9
1649 * F3 4 4Bit GPIO_INT10
1650 * G0 8 4Bit GPIO_INT11
1651 * G1 3 4Bit GPIO_INT12
1652 * G2 7 4Bit GPIO_INT13
1653 * G3 7 4Bit GPIO_INT14
1654 * H0 8 4Bit WKUP_INT
1655 * H1 8 4Bit WKUP_INT
1656 * H2 8 4Bit WKUP_INT
1657 * H3 8 4Bit WKUP_INT
1658 * I 8 4Bit GPIO_INT15
1659 * J0 8 4Bit GPIO_INT16
1660 * J1 5 4Bit GPIO_INT17
1661 * J2 8 4Bit GPIO_INT18
1662 * J3 8 4Bit GPIO_INT19
1663 * J4 4 4Bit GPIO_INT20
1674 static struct samsung_gpio_chip s5pc100_gpios_4bit
[] = {
1675 #ifdef CONFIG_CPU_S5PC100
1678 .base
= S5PC100_GPA0(0),
1679 .ngpio
= S5PC100_GPIO_A0_NR
,
1684 .base
= S5PC100_GPA1(0),
1685 .ngpio
= S5PC100_GPIO_A1_NR
,
1690 .base
= S5PC100_GPB(0),
1691 .ngpio
= S5PC100_GPIO_B_NR
,
1696 .base
= S5PC100_GPC(0),
1697 .ngpio
= S5PC100_GPIO_C_NR
,
1702 .base
= S5PC100_GPD(0),
1703 .ngpio
= S5PC100_GPIO_D_NR
,
1708 .base
= S5PC100_GPE0(0),
1709 .ngpio
= S5PC100_GPIO_E0_NR
,
1714 .base
= S5PC100_GPE1(0),
1715 .ngpio
= S5PC100_GPIO_E1_NR
,
1720 .base
= S5PC100_GPF0(0),
1721 .ngpio
= S5PC100_GPIO_F0_NR
,
1726 .base
= S5PC100_GPF1(0),
1727 .ngpio
= S5PC100_GPIO_F1_NR
,
1732 .base
= S5PC100_GPF2(0),
1733 .ngpio
= S5PC100_GPIO_F2_NR
,
1738 .base
= S5PC100_GPF3(0),
1739 .ngpio
= S5PC100_GPIO_F3_NR
,
1744 .base
= S5PC100_GPG0(0),
1745 .ngpio
= S5PC100_GPIO_G0_NR
,
1750 .base
= S5PC100_GPG1(0),
1751 .ngpio
= S5PC100_GPIO_G1_NR
,
1756 .base
= S5PC100_GPG2(0),
1757 .ngpio
= S5PC100_GPIO_G2_NR
,
1762 .base
= S5PC100_GPG3(0),
1763 .ngpio
= S5PC100_GPIO_G3_NR
,
1768 .base
= S5PC100_GPI(0),
1769 .ngpio
= S5PC100_GPIO_I_NR
,
1774 .base
= S5PC100_GPJ0(0),
1775 .ngpio
= S5PC100_GPIO_J0_NR
,
1780 .base
= S5PC100_GPJ1(0),
1781 .ngpio
= S5PC100_GPIO_J1_NR
,
1786 .base
= S5PC100_GPJ2(0),
1787 .ngpio
= S5PC100_GPIO_J2_NR
,
1792 .base
= S5PC100_GPJ3(0),
1793 .ngpio
= S5PC100_GPIO_J3_NR
,
1798 .base
= S5PC100_GPJ4(0),
1799 .ngpio
= S5PC100_GPIO_J4_NR
,
1804 .base
= S5PC100_GPK0(0),
1805 .ngpio
= S5PC100_GPIO_K0_NR
,
1810 .base
= S5PC100_GPK1(0),
1811 .ngpio
= S5PC100_GPIO_K1_NR
,
1816 .base
= S5PC100_GPK2(0),
1817 .ngpio
= S5PC100_GPIO_K2_NR
,
1822 .base
= S5PC100_GPK3(0),
1823 .ngpio
= S5PC100_GPIO_K3_NR
,
1828 .base
= S5PC100_GPL0(0),
1829 .ngpio
= S5PC100_GPIO_L0_NR
,
1834 .base
= S5PC100_GPL1(0),
1835 .ngpio
= S5PC100_GPIO_L1_NR
,
1840 .base
= S5PC100_GPL2(0),
1841 .ngpio
= S5PC100_GPIO_L2_NR
,
1846 .base
= S5PC100_GPL3(0),
1847 .ngpio
= S5PC100_GPIO_L3_NR
,
1852 .base
= S5PC100_GPL4(0),
1853 .ngpio
= S5PC100_GPIO_L4_NR
,
1857 .base
= (S5P_VA_GPIO
+ 0xC00),
1858 .irq_base
= IRQ_EINT(0),
1860 .base
= S5PC100_GPH0(0),
1861 .ngpio
= S5PC100_GPIO_H0_NR
,
1863 .to_irq
= samsung_gpiolib_to_irq
,
1866 .base
= (S5P_VA_GPIO
+ 0xC20),
1867 .irq_base
= IRQ_EINT(8),
1869 .base
= S5PC100_GPH1(0),
1870 .ngpio
= S5PC100_GPIO_H1_NR
,
1872 .to_irq
= samsung_gpiolib_to_irq
,
1875 .base
= (S5P_VA_GPIO
+ 0xC40),
1876 .irq_base
= IRQ_EINT(16),
1878 .base
= S5PC100_GPH2(0),
1879 .ngpio
= S5PC100_GPIO_H2_NR
,
1881 .to_irq
= samsung_gpiolib_to_irq
,
1884 .base
= (S5P_VA_GPIO
+ 0xC60),
1885 .irq_base
= IRQ_EINT(24),
1887 .base
= S5PC100_GPH3(0),
1888 .ngpio
= S5PC100_GPIO_H3_NR
,
1890 .to_irq
= samsung_gpiolib_to_irq
,
1897 * Followings are the gpio banks in S5PV210/S5PC110
1899 * The 'config' member when left to NULL, is initialized to the default
1900 * structure samsung_gpio_cfgs[3] in the init function below.
1902 * The 'base' member is also initialized in the init function below.
1903 * Note: The initialization of 'base' member of samsung_gpio_chip structure
1904 * uses the above macro and depends on the banks being listed in order here.
1907 static struct samsung_gpio_chip s5pv210_gpios_4bit
[] = {
1908 #ifdef CONFIG_CPU_S5PV210
1911 .base
= S5PV210_GPA0(0),
1912 .ngpio
= S5PV210_GPIO_A0_NR
,
1917 .base
= S5PV210_GPA1(0),
1918 .ngpio
= S5PV210_GPIO_A1_NR
,
1923 .base
= S5PV210_GPB(0),
1924 .ngpio
= S5PV210_GPIO_B_NR
,
1929 .base
= S5PV210_GPC0(0),
1930 .ngpio
= S5PV210_GPIO_C0_NR
,
1935 .base
= S5PV210_GPC1(0),
1936 .ngpio
= S5PV210_GPIO_C1_NR
,
1941 .base
= S5PV210_GPD0(0),
1942 .ngpio
= S5PV210_GPIO_D0_NR
,
1947 .base
= S5PV210_GPD1(0),
1948 .ngpio
= S5PV210_GPIO_D1_NR
,
1953 .base
= S5PV210_GPE0(0),
1954 .ngpio
= S5PV210_GPIO_E0_NR
,
1959 .base
= S5PV210_GPE1(0),
1960 .ngpio
= S5PV210_GPIO_E1_NR
,
1965 .base
= S5PV210_GPF0(0),
1966 .ngpio
= S5PV210_GPIO_F0_NR
,
1971 .base
= S5PV210_GPF1(0),
1972 .ngpio
= S5PV210_GPIO_F1_NR
,
1977 .base
= S5PV210_GPF2(0),
1978 .ngpio
= S5PV210_GPIO_F2_NR
,
1983 .base
= S5PV210_GPF3(0),
1984 .ngpio
= S5PV210_GPIO_F3_NR
,
1989 .base
= S5PV210_GPG0(0),
1990 .ngpio
= S5PV210_GPIO_G0_NR
,
1995 .base
= S5PV210_GPG1(0),
1996 .ngpio
= S5PV210_GPIO_G1_NR
,
2001 .base
= S5PV210_GPG2(0),
2002 .ngpio
= S5PV210_GPIO_G2_NR
,
2007 .base
= S5PV210_GPG3(0),
2008 .ngpio
= S5PV210_GPIO_G3_NR
,
2013 .base
= S5PV210_GPI(0),
2014 .ngpio
= S5PV210_GPIO_I_NR
,
2019 .base
= S5PV210_GPJ0(0),
2020 .ngpio
= S5PV210_GPIO_J0_NR
,
2025 .base
= S5PV210_GPJ1(0),
2026 .ngpio
= S5PV210_GPIO_J1_NR
,
2031 .base
= S5PV210_GPJ2(0),
2032 .ngpio
= S5PV210_GPIO_J2_NR
,
2037 .base
= S5PV210_GPJ3(0),
2038 .ngpio
= S5PV210_GPIO_J3_NR
,
2043 .base
= S5PV210_GPJ4(0),
2044 .ngpio
= S5PV210_GPIO_J4_NR
,
2049 .base
= S5PV210_MP01(0),
2050 .ngpio
= S5PV210_GPIO_MP01_NR
,
2055 .base
= S5PV210_MP02(0),
2056 .ngpio
= S5PV210_GPIO_MP02_NR
,
2061 .base
= S5PV210_MP03(0),
2062 .ngpio
= S5PV210_GPIO_MP03_NR
,
2067 .base
= S5PV210_MP04(0),
2068 .ngpio
= S5PV210_GPIO_MP04_NR
,
2073 .base
= S5PV210_MP05(0),
2074 .ngpio
= S5PV210_GPIO_MP05_NR
,
2078 .base
= (S5P_VA_GPIO
+ 0xC00),
2079 .irq_base
= IRQ_EINT(0),
2081 .base
= S5PV210_GPH0(0),
2082 .ngpio
= S5PV210_GPIO_H0_NR
,
2084 .to_irq
= samsung_gpiolib_to_irq
,
2087 .base
= (S5P_VA_GPIO
+ 0xC20),
2088 .irq_base
= IRQ_EINT(8),
2090 .base
= S5PV210_GPH1(0),
2091 .ngpio
= S5PV210_GPIO_H1_NR
,
2093 .to_irq
= samsung_gpiolib_to_irq
,
2096 .base
= (S5P_VA_GPIO
+ 0xC40),
2097 .irq_base
= IRQ_EINT(16),
2099 .base
= S5PV210_GPH2(0),
2100 .ngpio
= S5PV210_GPIO_H2_NR
,
2102 .to_irq
= samsung_gpiolib_to_irq
,
2105 .base
= (S5P_VA_GPIO
+ 0xC60),
2106 .irq_base
= IRQ_EINT(24),
2108 .base
= S5PV210_GPH3(0),
2109 .ngpio
= S5PV210_GPIO_H3_NR
,
2111 .to_irq
= samsung_gpiolib_to_irq
,
2118 * Followings are the gpio banks in EXYNOS SoCs
2120 * The 'config' member when left to NULL, is initialized to the default
2121 * structure exynos_gpio_cfg in the init function below.
2123 * The 'base' member is also initialized in the init function below.
2124 * Note: The initialization of 'base' member of samsung_gpio_chip structure
2125 * uses the above macro and depends on the banks being listed in order here.
2128 #ifdef CONFIG_ARCH_EXYNOS4
2129 static struct samsung_gpio_chip exynos4_gpios_1
[] = {
2132 .base
= EXYNOS4_GPA0(0),
2133 .ngpio
= EXYNOS4_GPIO_A0_NR
,
2138 .base
= EXYNOS4_GPA1(0),
2139 .ngpio
= EXYNOS4_GPIO_A1_NR
,
2144 .base
= EXYNOS4_GPB(0),
2145 .ngpio
= EXYNOS4_GPIO_B_NR
,
2150 .base
= EXYNOS4_GPC0(0),
2151 .ngpio
= EXYNOS4_GPIO_C0_NR
,
2156 .base
= EXYNOS4_GPC1(0),
2157 .ngpio
= EXYNOS4_GPIO_C1_NR
,
2162 .base
= EXYNOS4_GPD0(0),
2163 .ngpio
= EXYNOS4_GPIO_D0_NR
,
2168 .base
= EXYNOS4_GPD1(0),
2169 .ngpio
= EXYNOS4_GPIO_D1_NR
,
2174 .base
= EXYNOS4_GPE0(0),
2175 .ngpio
= EXYNOS4_GPIO_E0_NR
,
2180 .base
= EXYNOS4_GPE1(0),
2181 .ngpio
= EXYNOS4_GPIO_E1_NR
,
2186 .base
= EXYNOS4_GPE2(0),
2187 .ngpio
= EXYNOS4_GPIO_E2_NR
,
2192 .base
= EXYNOS4_GPE3(0),
2193 .ngpio
= EXYNOS4_GPIO_E3_NR
,
2198 .base
= EXYNOS4_GPE4(0),
2199 .ngpio
= EXYNOS4_GPIO_E4_NR
,
2204 .base
= EXYNOS4_GPF0(0),
2205 .ngpio
= EXYNOS4_GPIO_F0_NR
,
2210 .base
= EXYNOS4_GPF1(0),
2211 .ngpio
= EXYNOS4_GPIO_F1_NR
,
2216 .base
= EXYNOS4_GPF2(0),
2217 .ngpio
= EXYNOS4_GPIO_F2_NR
,
2222 .base
= EXYNOS4_GPF3(0),
2223 .ngpio
= EXYNOS4_GPIO_F3_NR
,
2230 #ifdef CONFIG_ARCH_EXYNOS4
2231 static struct samsung_gpio_chip exynos4_gpios_2
[] = {
2234 .base
= EXYNOS4_GPJ0(0),
2235 .ngpio
= EXYNOS4_GPIO_J0_NR
,
2240 .base
= EXYNOS4_GPJ1(0),
2241 .ngpio
= EXYNOS4_GPIO_J1_NR
,
2246 .base
= EXYNOS4_GPK0(0),
2247 .ngpio
= EXYNOS4_GPIO_K0_NR
,
2252 .base
= EXYNOS4_GPK1(0),
2253 .ngpio
= EXYNOS4_GPIO_K1_NR
,
2258 .base
= EXYNOS4_GPK2(0),
2259 .ngpio
= EXYNOS4_GPIO_K2_NR
,
2264 .base
= EXYNOS4_GPK3(0),
2265 .ngpio
= EXYNOS4_GPIO_K3_NR
,
2270 .base
= EXYNOS4_GPL0(0),
2271 .ngpio
= EXYNOS4_GPIO_L0_NR
,
2276 .base
= EXYNOS4_GPL1(0),
2277 .ngpio
= EXYNOS4_GPIO_L1_NR
,
2282 .base
= EXYNOS4_GPL2(0),
2283 .ngpio
= EXYNOS4_GPIO_L2_NR
,
2287 .config
= &samsung_gpio_cfgs
[8],
2289 .base
= EXYNOS4_GPY0(0),
2290 .ngpio
= EXYNOS4_GPIO_Y0_NR
,
2294 .config
= &samsung_gpio_cfgs
[8],
2296 .base
= EXYNOS4_GPY1(0),
2297 .ngpio
= EXYNOS4_GPIO_Y1_NR
,
2301 .config
= &samsung_gpio_cfgs
[8],
2303 .base
= EXYNOS4_GPY2(0),
2304 .ngpio
= EXYNOS4_GPIO_Y2_NR
,
2308 .config
= &samsung_gpio_cfgs
[8],
2310 .base
= EXYNOS4_GPY3(0),
2311 .ngpio
= EXYNOS4_GPIO_Y3_NR
,
2315 .config
= &samsung_gpio_cfgs
[8],
2317 .base
= EXYNOS4_GPY4(0),
2318 .ngpio
= EXYNOS4_GPIO_Y4_NR
,
2322 .config
= &samsung_gpio_cfgs
[8],
2324 .base
= EXYNOS4_GPY5(0),
2325 .ngpio
= EXYNOS4_GPIO_Y5_NR
,
2329 .config
= &samsung_gpio_cfgs
[8],
2331 .base
= EXYNOS4_GPY6(0),
2332 .ngpio
= EXYNOS4_GPIO_Y6_NR
,
2336 .config
= &samsung_gpio_cfgs
[9],
2337 .irq_base
= IRQ_EINT(0),
2339 .base
= EXYNOS4_GPX0(0),
2340 .ngpio
= EXYNOS4_GPIO_X0_NR
,
2342 .to_irq
= samsung_gpiolib_to_irq
,
2345 .config
= &samsung_gpio_cfgs
[9],
2346 .irq_base
= IRQ_EINT(8),
2348 .base
= EXYNOS4_GPX1(0),
2349 .ngpio
= EXYNOS4_GPIO_X1_NR
,
2351 .to_irq
= samsung_gpiolib_to_irq
,
2354 .config
= &samsung_gpio_cfgs
[9],
2355 .irq_base
= IRQ_EINT(16),
2357 .base
= EXYNOS4_GPX2(0),
2358 .ngpio
= EXYNOS4_GPIO_X2_NR
,
2360 .to_irq
= samsung_gpiolib_to_irq
,
2363 .config
= &samsung_gpio_cfgs
[9],
2364 .irq_base
= IRQ_EINT(24),
2366 .base
= EXYNOS4_GPX3(0),
2367 .ngpio
= EXYNOS4_GPIO_X3_NR
,
2369 .to_irq
= samsung_gpiolib_to_irq
,
2375 #ifdef CONFIG_ARCH_EXYNOS4
2376 static struct samsung_gpio_chip exynos4_gpios_3
[] = {
2379 .base
= EXYNOS4_GPZ(0),
2380 .ngpio
= EXYNOS4_GPIO_Z_NR
,
2387 #ifdef CONFIG_ARCH_EXYNOS5
2388 static struct samsung_gpio_chip exynos5_gpios_1
[] = {
2391 .base
= EXYNOS5_GPA0(0),
2392 .ngpio
= EXYNOS5_GPIO_A0_NR
,
2397 .base
= EXYNOS5_GPA1(0),
2398 .ngpio
= EXYNOS5_GPIO_A1_NR
,
2403 .base
= EXYNOS5_GPA2(0),
2404 .ngpio
= EXYNOS5_GPIO_A2_NR
,
2409 .base
= EXYNOS5_GPB0(0),
2410 .ngpio
= EXYNOS5_GPIO_B0_NR
,
2415 .base
= EXYNOS5_GPB1(0),
2416 .ngpio
= EXYNOS5_GPIO_B1_NR
,
2421 .base
= EXYNOS5_GPB2(0),
2422 .ngpio
= EXYNOS5_GPIO_B2_NR
,
2427 .base
= EXYNOS5_GPB3(0),
2428 .ngpio
= EXYNOS5_GPIO_B3_NR
,
2433 .base
= EXYNOS5_GPC0(0),
2434 .ngpio
= EXYNOS5_GPIO_C0_NR
,
2439 .base
= EXYNOS5_GPC1(0),
2440 .ngpio
= EXYNOS5_GPIO_C1_NR
,
2445 .base
= EXYNOS5_GPC2(0),
2446 .ngpio
= EXYNOS5_GPIO_C2_NR
,
2451 .base
= EXYNOS5_GPC3(0),
2452 .ngpio
= EXYNOS5_GPIO_C3_NR
,
2457 .base
= EXYNOS5_GPD0(0),
2458 .ngpio
= EXYNOS5_GPIO_D0_NR
,
2463 .base
= EXYNOS5_GPD1(0),
2464 .ngpio
= EXYNOS5_GPIO_D1_NR
,
2469 .base
= EXYNOS5_GPY0(0),
2470 .ngpio
= EXYNOS5_GPIO_Y0_NR
,
2475 .base
= EXYNOS5_GPY1(0),
2476 .ngpio
= EXYNOS5_GPIO_Y1_NR
,
2481 .base
= EXYNOS5_GPY2(0),
2482 .ngpio
= EXYNOS5_GPIO_Y2_NR
,
2487 .base
= EXYNOS5_GPY3(0),
2488 .ngpio
= EXYNOS5_GPIO_Y3_NR
,
2493 .base
= EXYNOS5_GPY4(0),
2494 .ngpio
= EXYNOS5_GPIO_Y4_NR
,
2499 .base
= EXYNOS5_GPY5(0),
2500 .ngpio
= EXYNOS5_GPIO_Y5_NR
,
2505 .base
= EXYNOS5_GPY6(0),
2506 .ngpio
= EXYNOS5_GPIO_Y6_NR
,
2511 .base
= EXYNOS5_GPC4(0),
2512 .ngpio
= EXYNOS5_GPIO_C4_NR
,
2516 .config
= &samsung_gpio_cfgs
[9],
2517 .irq_base
= IRQ_EINT(0),
2519 .base
= EXYNOS5_GPX0(0),
2520 .ngpio
= EXYNOS5_GPIO_X0_NR
,
2522 .to_irq
= samsung_gpiolib_to_irq
,
2525 .config
= &samsung_gpio_cfgs
[9],
2526 .irq_base
= IRQ_EINT(8),
2528 .base
= EXYNOS5_GPX1(0),
2529 .ngpio
= EXYNOS5_GPIO_X1_NR
,
2531 .to_irq
= samsung_gpiolib_to_irq
,
2534 .config
= &samsung_gpio_cfgs
[9],
2535 .irq_base
= IRQ_EINT(16),
2537 .base
= EXYNOS5_GPX2(0),
2538 .ngpio
= EXYNOS5_GPIO_X2_NR
,
2540 .to_irq
= samsung_gpiolib_to_irq
,
2543 .config
= &samsung_gpio_cfgs
[9],
2544 .irq_base
= IRQ_EINT(24),
2546 .base
= EXYNOS5_GPX3(0),
2547 .ngpio
= EXYNOS5_GPIO_X3_NR
,
2549 .to_irq
= samsung_gpiolib_to_irq
,
2555 #ifdef CONFIG_ARCH_EXYNOS5
2556 static struct samsung_gpio_chip exynos5_gpios_2
[] = {
2559 .base
= EXYNOS5_GPE0(0),
2560 .ngpio
= EXYNOS5_GPIO_E0_NR
,
2565 .base
= EXYNOS5_GPE1(0),
2566 .ngpio
= EXYNOS5_GPIO_E1_NR
,
2571 .base
= EXYNOS5_GPF0(0),
2572 .ngpio
= EXYNOS5_GPIO_F0_NR
,
2577 .base
= EXYNOS5_GPF1(0),
2578 .ngpio
= EXYNOS5_GPIO_F1_NR
,
2583 .base
= EXYNOS5_GPG0(0),
2584 .ngpio
= EXYNOS5_GPIO_G0_NR
,
2589 .base
= EXYNOS5_GPG1(0),
2590 .ngpio
= EXYNOS5_GPIO_G1_NR
,
2595 .base
= EXYNOS5_GPG2(0),
2596 .ngpio
= EXYNOS5_GPIO_G2_NR
,
2601 .base
= EXYNOS5_GPH0(0),
2602 .ngpio
= EXYNOS5_GPIO_H0_NR
,
2607 .base
= EXYNOS5_GPH1(0),
2608 .ngpio
= EXYNOS5_GPIO_H1_NR
,
2616 #ifdef CONFIG_ARCH_EXYNOS5
2617 static struct samsung_gpio_chip exynos5_gpios_3
[] = {
2620 .base
= EXYNOS5_GPV0(0),
2621 .ngpio
= EXYNOS5_GPIO_V0_NR
,
2626 .base
= EXYNOS5_GPV1(0),
2627 .ngpio
= EXYNOS5_GPIO_V1_NR
,
2632 .base
= EXYNOS5_GPV2(0),
2633 .ngpio
= EXYNOS5_GPIO_V2_NR
,
2638 .base
= EXYNOS5_GPV3(0),
2639 .ngpio
= EXYNOS5_GPIO_V3_NR
,
2644 .base
= EXYNOS5_GPV4(0),
2645 .ngpio
= EXYNOS5_GPIO_V4_NR
,
2652 #ifdef CONFIG_ARCH_EXYNOS5
2653 static struct samsung_gpio_chip exynos5_gpios_4
[] = {
2656 .base
= EXYNOS5_GPZ(0),
2657 .ngpio
= EXYNOS5_GPIO_Z_NR
,
2665 #if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF)
2666 static int exynos_gpio_xlate(struct gpio_chip
*gc
,
2667 const struct of_phandle_args
*gpiospec
, u32
*flags
)
2671 if (WARN_ON(gc
->of_gpio_n_cells
< 4))
2674 if (WARN_ON(gpiospec
->args_count
< gc
->of_gpio_n_cells
))
2677 if (gpiospec
->args
[0] > gc
->ngpio
)
2680 pin
= gc
->base
+ gpiospec
->args
[0];
2682 if (s3c_gpio_cfgpin(pin
, S3C_GPIO_SFN(gpiospec
->args
[1])))
2683 pr_warn("gpio_xlate: failed to set pin function\n");
2684 if (s3c_gpio_setpull(pin
, gpiospec
->args
[2] & 0xffff))
2685 pr_warn("gpio_xlate: failed to set pin pull up/down\n");
2686 if (s5p_gpio_set_drvstr(pin
, gpiospec
->args
[3]))
2687 pr_warn("gpio_xlate: failed to set pin drive strength\n");
2690 *flags
= gpiospec
->args
[2] >> 16;
2692 return gpiospec
->args
[0];
2695 static const struct of_device_id exynos_gpio_dt_match
[] __initdata
= {
2696 { .compatible
= "samsung,exynos4-gpio", },
2700 static __init
void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip
*chip
,
2701 u64 base
, u64 offset
)
2703 struct gpio_chip
*gc
= &chip
->chip
;
2706 if (!of_have_populated_dt())
2709 address
= chip
->base
? base
+ ((u32
)chip
->base
& 0xfff) : base
+ offset
;
2710 gc
->of_node
= of_find_matching_node_by_address(NULL
,
2711 exynos_gpio_dt_match
, address
);
2713 pr_info("gpio: device tree node not found for gpio controller"
2714 " with base address %08llx\n", address
);
2717 gc
->of_gpio_n_cells
= 4;
2718 gc
->of_xlate
= exynos_gpio_xlate
;
2720 #elif defined(CONFIG_ARCH_EXYNOS)
2721 static __init
void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip
*chip
,
2722 u64 base
, u64 offset
)
2726 #endif /* defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF) */
2728 static __init
void exynos4_gpiolib_init(void)
2730 #ifdef CONFIG_CPU_EXYNOS4210
2731 struct samsung_gpio_chip
*chip
;
2733 void __iomem
*gpio_base1
, *gpio_base2
, *gpio_base3
;
2735 void __iomem
*gpx_base
;
2738 gpio_base1
= ioremap(EXYNOS4_PA_GPIO1
, SZ_4K
);
2739 if (gpio_base1
== NULL
) {
2740 pr_err("unable to ioremap for gpio_base1\n");
2744 chip
= exynos4_gpios_1
;
2745 nr_chips
= ARRAY_SIZE(exynos4_gpios_1
);
2747 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2748 if (!chip
->config
) {
2749 chip
->config
= &exynos_gpio_cfg
;
2750 chip
->group
= group
++;
2752 exynos_gpiolib_attach_ofnode(chip
,
2753 EXYNOS4_PA_GPIO1
, i
* 0x20);
2755 samsung_gpiolib_add_4bit_chips(exynos4_gpios_1
,
2756 nr_chips
, gpio_base1
);
2759 gpio_base2
= ioremap(EXYNOS4_PA_GPIO2
, SZ_4K
);
2760 if (gpio_base2
== NULL
) {
2761 pr_err("unable to ioremap for gpio_base2\n");
2765 /* need to set base address for gpx */
2766 chip
= &exynos4_gpios_2
[16];
2767 gpx_base
= gpio_base2
+ 0xC00;
2768 for (i
= 0; i
< 4; i
++, chip
++, gpx_base
+= 0x20)
2769 chip
->base
= gpx_base
;
2771 chip
= exynos4_gpios_2
;
2772 nr_chips
= ARRAY_SIZE(exynos4_gpios_2
);
2774 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2775 if (!chip
->config
) {
2776 chip
->config
= &exynos_gpio_cfg
;
2777 chip
->group
= group
++;
2779 exynos_gpiolib_attach_ofnode(chip
,
2780 EXYNOS4_PA_GPIO2
, i
* 0x20);
2782 samsung_gpiolib_add_4bit_chips(exynos4_gpios_2
,
2783 nr_chips
, gpio_base2
);
2786 gpio_base3
= ioremap(EXYNOS4_PA_GPIO3
, SZ_256
);
2787 if (gpio_base3
== NULL
) {
2788 pr_err("unable to ioremap for gpio_base3\n");
2792 chip
= exynos4_gpios_3
;
2793 nr_chips
= ARRAY_SIZE(exynos4_gpios_3
);
2795 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2796 if (!chip
->config
) {
2797 chip
->config
= &exynos_gpio_cfg
;
2798 chip
->group
= group
++;
2800 exynos_gpiolib_attach_ofnode(chip
,
2801 EXYNOS4_PA_GPIO3
, i
* 0x20);
2803 samsung_gpiolib_add_4bit_chips(exynos4_gpios_3
,
2804 nr_chips
, gpio_base3
);
2806 #if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT)
2807 s5p_register_gpioint_bank(IRQ_GPIO_XA
, 0, IRQ_GPIO1_NR_GROUPS
);
2808 s5p_register_gpioint_bank(IRQ_GPIO_XB
, IRQ_GPIO1_NR_GROUPS
, IRQ_GPIO2_NR_GROUPS
);
2814 iounmap(gpio_base2
);
2816 iounmap(gpio_base1
);
2819 #endif /* CONFIG_CPU_EXYNOS4210 */
2822 static __init
void exynos5_gpiolib_init(void)
2824 #ifdef CONFIG_SOC_EXYNOS5250
2825 struct samsung_gpio_chip
*chip
;
2827 void __iomem
*gpio_base1
, *gpio_base2
, *gpio_base3
, *gpio_base4
;
2829 void __iomem
*gpx_base
;
2832 gpio_base1
= ioremap(EXYNOS5_PA_GPIO1
, SZ_4K
);
2833 if (gpio_base1
== NULL
) {
2834 pr_err("unable to ioremap for gpio_base1\n");
2838 /* need to set base address for gpc4 */
2839 exynos5_gpios_1
[20].base
= gpio_base1
+ 0x2E0;
2841 /* need to set base address for gpx */
2842 chip
= &exynos5_gpios_1
[21];
2843 gpx_base
= gpio_base1
+ 0xC00;
2844 for (i
= 0; i
< 4; i
++, chip
++, gpx_base
+= 0x20)
2845 chip
->base
= gpx_base
;
2847 chip
= exynos5_gpios_1
;
2848 nr_chips
= ARRAY_SIZE(exynos5_gpios_1
);
2850 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2851 if (!chip
->config
) {
2852 chip
->config
= &exynos_gpio_cfg
;
2853 chip
->group
= group
++;
2855 exynos_gpiolib_attach_ofnode(chip
,
2856 EXYNOS5_PA_GPIO1
, i
* 0x20);
2858 samsung_gpiolib_add_4bit_chips(exynos5_gpios_1
,
2859 nr_chips
, gpio_base1
);
2862 gpio_base2
= ioremap(EXYNOS5_PA_GPIO2
, SZ_4K
);
2863 if (gpio_base2
== NULL
) {
2864 pr_err("unable to ioremap for gpio_base2\n");
2868 chip
= exynos5_gpios_2
;
2869 nr_chips
= ARRAY_SIZE(exynos5_gpios_2
);
2871 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2872 if (!chip
->config
) {
2873 chip
->config
= &exynos_gpio_cfg
;
2874 chip
->group
= group
++;
2876 exynos_gpiolib_attach_ofnode(chip
,
2877 EXYNOS5_PA_GPIO2
, i
* 0x20);
2879 samsung_gpiolib_add_4bit_chips(exynos5_gpios_2
,
2880 nr_chips
, gpio_base2
);
2883 gpio_base3
= ioremap(EXYNOS5_PA_GPIO3
, SZ_4K
);
2884 if (gpio_base3
== NULL
) {
2885 pr_err("unable to ioremap for gpio_base3\n");
2889 /* need to set base address for gpv */
2890 exynos5_gpios_3
[0].base
= gpio_base3
;
2891 exynos5_gpios_3
[1].base
= gpio_base3
+ 0x20;
2892 exynos5_gpios_3
[2].base
= gpio_base3
+ 0x60;
2893 exynos5_gpios_3
[3].base
= gpio_base3
+ 0x80;
2894 exynos5_gpios_3
[4].base
= gpio_base3
+ 0xC0;
2896 chip
= exynos5_gpios_3
;
2897 nr_chips
= ARRAY_SIZE(exynos5_gpios_3
);
2899 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2900 if (!chip
->config
) {
2901 chip
->config
= &exynos_gpio_cfg
;
2902 chip
->group
= group
++;
2904 exynos_gpiolib_attach_ofnode(chip
,
2905 EXYNOS5_PA_GPIO3
, i
* 0x20);
2907 samsung_gpiolib_add_4bit_chips(exynos5_gpios_3
,
2908 nr_chips
, gpio_base3
);
2911 gpio_base4
= ioremap(EXYNOS5_PA_GPIO4
, SZ_4K
);
2912 if (gpio_base4
== NULL
) {
2913 pr_err("unable to ioremap for gpio_base4\n");
2917 chip
= exynos5_gpios_4
;
2918 nr_chips
= ARRAY_SIZE(exynos5_gpios_4
);
2920 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2921 if (!chip
->config
) {
2922 chip
->config
= &exynos_gpio_cfg
;
2923 chip
->group
= group
++;
2925 exynos_gpiolib_attach_ofnode(chip
,
2926 EXYNOS5_PA_GPIO4
, i
* 0x20);
2928 samsung_gpiolib_add_4bit_chips(exynos5_gpios_4
,
2929 nr_chips
, gpio_base4
);
2933 iounmap(gpio_base3
);
2935 iounmap(gpio_base2
);
2937 iounmap(gpio_base1
);
2941 #endif /* CONFIG_SOC_EXYNOS5250 */
2944 /* TODO: cleanup soc_is_* */
2945 static __init
int samsung_gpiolib_init(void)
2947 struct samsung_gpio_chip
*chip
;
2951 samsung_gpiolib_set_cfg(samsung_gpio_cfgs
, ARRAY_SIZE(samsung_gpio_cfgs
));
2953 if (soc_is_s3c24xx()) {
2954 s3c24xx_gpiolib_add_chips(s3c24xx_gpios
,
2955 ARRAY_SIZE(s3c24xx_gpios
), S3C24XX_VA_GPIO
);
2956 } else if (soc_is_s3c64xx()) {
2957 samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit
,
2958 ARRAY_SIZE(s3c64xx_gpios_2bit
),
2959 S3C64XX_VA_GPIO
+ 0xE0, 0x20);
2960 samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit
,
2961 ARRAY_SIZE(s3c64xx_gpios_4bit
),
2963 samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2
,
2964 ARRAY_SIZE(s3c64xx_gpios_4bit2
));
2965 } else if (soc_is_s5p6440()) {
2966 samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit
,
2967 ARRAY_SIZE(s5p6440_gpios_2bit
), NULL
, 0x0);
2968 samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit
,
2969 ARRAY_SIZE(s5p6440_gpios_4bit
), S5P_VA_GPIO
);
2970 samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2
,
2971 ARRAY_SIZE(s5p6440_gpios_4bit2
));
2972 s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank
,
2973 ARRAY_SIZE(s5p6440_gpios_rbank
));
2974 } else if (soc_is_s5p6450()) {
2975 samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit
,
2976 ARRAY_SIZE(s5p6450_gpios_2bit
), NULL
, 0x0);
2977 samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit
,
2978 ARRAY_SIZE(s5p6450_gpios_4bit
), S5P_VA_GPIO
);
2979 samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2
,
2980 ARRAY_SIZE(s5p6450_gpios_4bit2
));
2981 s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank
,
2982 ARRAY_SIZE(s5p6450_gpios_rbank
));
2983 } else if (soc_is_s5pc100()) {
2985 chip
= s5pc100_gpios_4bit
;
2986 nr_chips
= ARRAY_SIZE(s5pc100_gpios_4bit
);
2988 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2989 if (!chip
->config
) {
2990 chip
->config
= &samsung_gpio_cfgs
[3];
2991 chip
->group
= group
++;
2994 samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit
, nr_chips
, S5P_VA_GPIO
);
2995 #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
2996 s5p_register_gpioint_bank(IRQ_GPIOINT
, 0, S5P_GPIOINT_GROUP_MAXNR
);
2998 } else if (soc_is_s5pv210()) {
3000 chip
= s5pv210_gpios_4bit
;
3001 nr_chips
= ARRAY_SIZE(s5pv210_gpios_4bit
);
3003 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
3004 if (!chip
->config
) {
3005 chip
->config
= &samsung_gpio_cfgs
[3];
3006 chip
->group
= group
++;
3009 samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit
, nr_chips
, S5P_VA_GPIO
);
3010 #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
3011 s5p_register_gpioint_bank(IRQ_GPIOINT
, 0, S5P_GPIOINT_GROUP_MAXNR
);
3013 } else if (soc_is_exynos4210()) {
3014 exynos4_gpiolib_init();
3015 } else if (soc_is_exynos5250()) {
3016 exynos5_gpiolib_init();
3018 WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
3024 core_initcall(samsung_gpiolib_init
);
3026 int s3c_gpio_cfgpin(unsigned int pin
, unsigned int config
)
3028 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3029 unsigned long flags
;
3036 offset
= pin
- chip
->chip
.base
;
3038 samsung_gpio_lock(chip
, flags
);
3039 ret
= samsung_gpio_do_setcfg(chip
, offset
, config
);
3040 samsung_gpio_unlock(chip
, flags
);
3044 EXPORT_SYMBOL(s3c_gpio_cfgpin
);
3046 int s3c_gpio_cfgpin_range(unsigned int start
, unsigned int nr
,
3051 for (; nr
> 0; nr
--, start
++) {
3052 ret
= s3c_gpio_cfgpin(start
, cfg
);
3059 EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range
);
3061 int s3c_gpio_cfgall_range(unsigned int start
, unsigned int nr
,
3062 unsigned int cfg
, samsung_gpio_pull_t pull
)
3066 for (; nr
> 0; nr
--, start
++) {
3067 s3c_gpio_setpull(start
, pull
);
3068 ret
= s3c_gpio_cfgpin(start
, cfg
);
3075 EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range
);
3077 unsigned s3c_gpio_getcfg(unsigned int pin
)
3079 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3080 unsigned long flags
;
3085 offset
= pin
- chip
->chip
.base
;
3087 samsung_gpio_lock(chip
, flags
);
3088 ret
= samsung_gpio_do_getcfg(chip
, offset
);
3089 samsung_gpio_unlock(chip
, flags
);
3094 EXPORT_SYMBOL(s3c_gpio_getcfg
);
3096 int s3c_gpio_setpull(unsigned int pin
, samsung_gpio_pull_t pull
)
3098 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3099 unsigned long flags
;
3105 offset
= pin
- chip
->chip
.base
;
3107 samsung_gpio_lock(chip
, flags
);
3108 ret
= samsung_gpio_do_setpull(chip
, offset
, pull
);
3109 samsung_gpio_unlock(chip
, flags
);
3113 EXPORT_SYMBOL(s3c_gpio_setpull
);
3115 samsung_gpio_pull_t
s3c_gpio_getpull(unsigned int pin
)
3117 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3118 unsigned long flags
;
3123 offset
= pin
- chip
->chip
.base
;
3125 samsung_gpio_lock(chip
, flags
);
3126 pup
= samsung_gpio_do_getpull(chip
, offset
);
3127 samsung_gpio_unlock(chip
, flags
);
3130 return (__force samsung_gpio_pull_t
)pup
;
3132 EXPORT_SYMBOL(s3c_gpio_getpull
);
3134 /* gpiolib wrappers until these are totally eliminated */
3136 void s3c2410_gpio_pullup(unsigned int pin
, unsigned int to
)
3140 WARN_ON(to
); /* should be none of these left */
3143 /* if pull is enabled, try first with up, and if that
3144 * fails, try using down */
3146 ret
= s3c_gpio_setpull(pin
, S3C_GPIO_PULL_UP
);
3148 s3c_gpio_setpull(pin
, S3C_GPIO_PULL_DOWN
);
3150 s3c_gpio_setpull(pin
, S3C_GPIO_PULL_NONE
);
3153 EXPORT_SYMBOL(s3c2410_gpio_pullup
);
3155 void s3c2410_gpio_setpin(unsigned int pin
, unsigned int to
)
3157 /* do this via gpiolib until all users removed */
3159 gpio_request(pin
, "temporary");
3160 gpio_set_value(pin
, to
);
3163 EXPORT_SYMBOL(s3c2410_gpio_setpin
);
3165 unsigned int s3c2410_gpio_getpin(unsigned int pin
)
3167 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3168 unsigned long offs
= pin
- chip
->chip
.base
;
3170 return __raw_readl(chip
->base
+ 0x04) & (1 << offs
);
3172 EXPORT_SYMBOL(s3c2410_gpio_getpin
);
3174 #ifdef CONFIG_S5P_GPIO_DRVSTR
3175 s5p_gpio_drvstr_t
s5p_gpio_get_drvstr(unsigned int pin
)
3177 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3186 off
= pin
- chip
->chip
.base
;
3188 reg
= chip
->base
+ 0x0C;
3190 drvstr
= __raw_readl(reg
);
3191 drvstr
= drvstr
>> shift
;
3194 return (__force s5p_gpio_drvstr_t
)drvstr
;
3196 EXPORT_SYMBOL(s5p_gpio_get_drvstr
);
3198 int s5p_gpio_set_drvstr(unsigned int pin
, s5p_gpio_drvstr_t drvstr
)
3200 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3209 off
= pin
- chip
->chip
.base
;
3211 reg
= chip
->base
+ 0x0C;
3213 tmp
= __raw_readl(reg
);
3214 tmp
&= ~(0x3 << shift
);
3215 tmp
|= drvstr
<< shift
;
3217 __raw_writel(tmp
, reg
);
3221 EXPORT_SYMBOL(s5p_gpio_set_drvstr
);
3222 #endif /* CONFIG_S5P_GPIO_DRVSTR */
3224 #ifdef CONFIG_PLAT_S3C24XX
3225 unsigned int s3c2410_modify_misccr(unsigned int clear
, unsigned int change
)
3227 unsigned long flags
;
3228 unsigned long misccr
;
3230 local_irq_save(flags
);
3231 misccr
= __raw_readl(S3C24XX_MISCCR
);
3234 __raw_writel(misccr
, S3C24XX_MISCCR
);
3235 local_irq_restore(flags
);
3239 EXPORT_SYMBOL(s3c2410_modify_misccr
);