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-gpio.h>
38 #include <plat/gpio-core.h>
39 #include <plat/gpio-cfg.h>
40 #include <plat/gpio-cfg-helpers.h>
41 #include <plat/gpio-fns.h>
44 int samsung_gpio_setpull_updown(struct samsung_gpio_chip
*chip
,
45 unsigned int off
, samsung_gpio_pull_t pull
)
47 void __iomem
*reg
= chip
->base
+ 0x08;
51 pup
= __raw_readl(reg
);
54 __raw_writel(pup
, reg
);
59 samsung_gpio_pull_t
samsung_gpio_getpull_updown(struct samsung_gpio_chip
*chip
,
62 void __iomem
*reg
= chip
->base
+ 0x08;
64 u32 pup
= __raw_readl(reg
);
69 return (__force samsung_gpio_pull_t
)pup
;
72 int s3c2443_gpio_setpull(struct samsung_gpio_chip
*chip
,
73 unsigned int off
, samsung_gpio_pull_t pull
)
76 case S3C_GPIO_PULL_NONE
:
79 case S3C_GPIO_PULL_UP
:
82 case S3C_GPIO_PULL_DOWN
:
86 return samsung_gpio_setpull_updown(chip
, off
, pull
);
89 samsung_gpio_pull_t
s3c2443_gpio_getpull(struct samsung_gpio_chip
*chip
,
92 samsung_gpio_pull_t pull
;
94 pull
= samsung_gpio_getpull_updown(chip
, off
);
98 pull
= S3C_GPIO_PULL_UP
;
102 pull
= S3C_GPIO_PULL_NONE
;
105 pull
= S3C_GPIO_PULL_DOWN
;
112 static int s3c24xx_gpio_setpull_1(struct samsung_gpio_chip
*chip
,
113 unsigned int off
, samsung_gpio_pull_t pull
,
114 samsung_gpio_pull_t updown
)
116 void __iomem
*reg
= chip
->base
+ 0x08;
117 u32 pup
= __raw_readl(reg
);
121 else if (pull
== S3C_GPIO_PULL_NONE
)
126 __raw_writel(pup
, reg
);
130 static samsung_gpio_pull_t
s3c24xx_gpio_getpull_1(struct samsung_gpio_chip
*chip
,
132 samsung_gpio_pull_t updown
)
134 void __iomem
*reg
= chip
->base
+ 0x08;
135 u32 pup
= __raw_readl(reg
);
138 return pup
? S3C_GPIO_PULL_NONE
: updown
;
141 samsung_gpio_pull_t
s3c24xx_gpio_getpull_1up(struct samsung_gpio_chip
*chip
,
144 return s3c24xx_gpio_getpull_1(chip
, off
, S3C_GPIO_PULL_UP
);
147 int s3c24xx_gpio_setpull_1up(struct samsung_gpio_chip
*chip
,
148 unsigned int off
, samsung_gpio_pull_t pull
)
150 return s3c24xx_gpio_setpull_1(chip
, off
, pull
, S3C_GPIO_PULL_UP
);
153 samsung_gpio_pull_t
s3c24xx_gpio_getpull_1down(struct samsung_gpio_chip
*chip
,
156 return s3c24xx_gpio_getpull_1(chip
, off
, S3C_GPIO_PULL_DOWN
);
159 int s3c24xx_gpio_setpull_1down(struct samsung_gpio_chip
*chip
,
160 unsigned int off
, samsung_gpio_pull_t pull
)
162 return s3c24xx_gpio_setpull_1(chip
, off
, pull
, S3C_GPIO_PULL_DOWN
);
165 static int exynos_gpio_setpull(struct samsung_gpio_chip
*chip
,
166 unsigned int off
, samsung_gpio_pull_t pull
)
168 if (pull
== S3C_GPIO_PULL_UP
)
171 return samsung_gpio_setpull_updown(chip
, off
, pull
);
174 static samsung_gpio_pull_t
exynos_gpio_getpull(struct samsung_gpio_chip
*chip
,
177 samsung_gpio_pull_t pull
;
179 pull
= samsung_gpio_getpull_updown(chip
, off
);
182 pull
= S3C_GPIO_PULL_UP
;
188 * samsung_gpio_setcfg_2bit - Samsung 2bit style GPIO configuration.
189 * @chip: The gpio chip that is being configured.
190 * @off: The offset for the GPIO being configured.
191 * @cfg: The configuration value to set.
193 * This helper deal with the GPIO cases where the control register
194 * has two bits of configuration per gpio, which have the following
198 * 1x = special function
201 static int samsung_gpio_setcfg_2bit(struct samsung_gpio_chip
*chip
,
202 unsigned int off
, unsigned int cfg
)
204 void __iomem
*reg
= chip
->base
;
205 unsigned int shift
= off
* 2;
208 if (samsung_gpio_is_cfg_special(cfg
)) {
216 con
= __raw_readl(reg
);
217 con
&= ~(0x3 << shift
);
219 __raw_writel(con
, reg
);
225 * samsung_gpio_getcfg_2bit - Samsung 2bit style GPIO configuration read.
226 * @chip: The gpio chip that is being configured.
227 * @off: The offset for the GPIO being configured.
229 * The reverse of samsung_gpio_setcfg_2bit(). Will return a value which
230 * could be directly passed back to samsung_gpio_setcfg_2bit(), from the
231 * S3C_GPIO_SPECIAL() macro.
234 static unsigned int samsung_gpio_getcfg_2bit(struct samsung_gpio_chip
*chip
,
239 con
= __raw_readl(chip
->base
);
243 /* this conversion works for IN and OUT as well as special mode */
244 return S3C_GPIO_SPECIAL(con
);
248 * samsung_gpio_setcfg_4bit - Samsung 4bit single register GPIO config.
249 * @chip: The gpio chip that is being configured.
250 * @off: The offset for the GPIO being configured.
251 * @cfg: The configuration value to set.
253 * This helper deal with the GPIO cases where the control register has 4 bits
254 * of control per GPIO, generally in the form of:
257 * others = Special functions (dependent on bank)
259 * Note, since the code to deal with the case where there are two control
260 * registers instead of one, we do not have a separate set of functions for
264 static int samsung_gpio_setcfg_4bit(struct samsung_gpio_chip
*chip
,
265 unsigned int off
, unsigned int cfg
)
267 void __iomem
*reg
= chip
->base
;
268 unsigned int shift
= (off
& 7) * 4;
271 if (off
< 8 && chip
->chip
.ngpio
> 8)
274 if (samsung_gpio_is_cfg_special(cfg
)) {
279 con
= __raw_readl(reg
);
280 con
&= ~(0xf << shift
);
282 __raw_writel(con
, reg
);
288 * samsung_gpio_getcfg_4bit - Samsung 4bit single register GPIO config read.
289 * @chip: The gpio chip that is being configured.
290 * @off: The offset for the GPIO being configured.
292 * The reverse of samsung_gpio_setcfg_4bit(), turning a gpio configuration
293 * register setting into a value the software can use, such as could be passed
294 * to samsung_gpio_setcfg_4bit().
296 * @sa samsung_gpio_getcfg_2bit
299 static unsigned samsung_gpio_getcfg_4bit(struct samsung_gpio_chip
*chip
,
302 void __iomem
*reg
= chip
->base
;
303 unsigned int shift
= (off
& 7) * 4;
306 if (off
< 8 && chip
->chip
.ngpio
> 8)
309 con
= __raw_readl(reg
);
313 /* this conversion works for IN and OUT as well as special mode */
314 return S3C_GPIO_SPECIAL(con
);
317 #ifdef CONFIG_PLAT_S3C24XX
319 * s3c24xx_gpio_setcfg_abank - S3C24XX style GPIO configuration (Bank A)
320 * @chip: The gpio chip that is being configured.
321 * @off: The offset for the GPIO being configured.
322 * @cfg: The configuration value to set.
324 * This helper deal with the GPIO cases where the control register
325 * has one bit of configuration for the gpio, where setting the bit
326 * means the pin is in special function mode and unset means output.
329 static int s3c24xx_gpio_setcfg_abank(struct samsung_gpio_chip
*chip
,
330 unsigned int off
, unsigned int cfg
)
332 void __iomem
*reg
= chip
->base
;
333 unsigned int shift
= off
;
336 if (samsung_gpio_is_cfg_special(cfg
)) {
339 /* Map output to 0, and SFN2 to 1 */
347 con
= __raw_readl(reg
);
348 con
&= ~(0x1 << shift
);
350 __raw_writel(con
, reg
);
356 * s3c24xx_gpio_getcfg_abank - S3C24XX style GPIO configuration read (Bank A)
357 * @chip: The gpio chip that is being configured.
358 * @off: The offset for the GPIO being configured.
360 * The reverse of s3c24xx_gpio_setcfg_abank() turning an GPIO into a usable
361 * GPIO configuration value.
363 * @sa samsung_gpio_getcfg_2bit
364 * @sa samsung_gpio_getcfg_4bit
367 static unsigned s3c24xx_gpio_getcfg_abank(struct samsung_gpio_chip
*chip
,
372 con
= __raw_readl(chip
->base
);
377 return S3C_GPIO_SFN(con
);
381 #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
382 static int s5p64x0_gpio_setcfg_rbank(struct samsung_gpio_chip
*chip
,
383 unsigned int off
, unsigned int cfg
)
385 void __iomem
*reg
= chip
->base
;
396 shift
= (off
& 7) * 4;
400 shift
= ((off
+ 1) & 7) * 4;
403 shift
= ((off
+ 1) & 7) * 4;
407 if (samsung_gpio_is_cfg_special(cfg
)) {
412 con
= __raw_readl(reg
);
413 con
&= ~(0xf << shift
);
415 __raw_writel(con
, reg
);
421 static void __init
samsung_gpiolib_set_cfg(struct samsung_gpio_cfg
*chipcfg
,
424 for (; nr_chips
> 0; nr_chips
--, chipcfg
++) {
425 if (!chipcfg
->set_config
)
426 chipcfg
->set_config
= samsung_gpio_setcfg_4bit
;
427 if (!chipcfg
->get_config
)
428 chipcfg
->get_config
= samsung_gpio_getcfg_4bit
;
429 if (!chipcfg
->set_pull
)
430 chipcfg
->set_pull
= samsung_gpio_setpull_updown
;
431 if (!chipcfg
->get_pull
)
432 chipcfg
->get_pull
= samsung_gpio_getpull_updown
;
436 struct samsung_gpio_cfg s3c24xx_gpiocfg_default
= {
437 .set_config
= samsung_gpio_setcfg_2bit
,
438 .get_config
= samsung_gpio_getcfg_2bit
,
441 #ifdef CONFIG_PLAT_S3C24XX
442 static struct samsung_gpio_cfg s3c24xx_gpiocfg_banka
= {
443 .set_config
= s3c24xx_gpio_setcfg_abank
,
444 .get_config
= s3c24xx_gpio_getcfg_abank
,
448 #if defined(CONFIG_ARCH_EXYNOS4) || defined(CONFIG_SOC_EXYNOS5250)
449 static struct samsung_gpio_cfg exynos_gpio_cfg
= {
450 .set_pull
= exynos_gpio_setpull
,
451 .get_pull
= exynos_gpio_getpull
,
452 .set_config
= samsung_gpio_setcfg_4bit
,
453 .get_config
= samsung_gpio_getcfg_4bit
,
457 #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
458 static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank
= {
460 .set_config
= s5p64x0_gpio_setcfg_rbank
,
461 .get_config
= samsung_gpio_getcfg_4bit
,
462 .set_pull
= samsung_gpio_setpull_updown
,
463 .get_pull
= samsung_gpio_getpull_updown
,
467 static struct samsung_gpio_cfg samsung_gpio_cfgs
[] = {
482 .set_config
= samsung_gpio_setcfg_2bit
,
483 .get_config
= samsung_gpio_getcfg_2bit
,
487 .set_config
= samsung_gpio_setcfg_2bit
,
488 .get_config
= samsung_gpio_getcfg_2bit
,
492 .set_config
= samsung_gpio_setcfg_2bit
,
493 .get_config
= samsung_gpio_getcfg_2bit
,
496 .set_config
= samsung_gpio_setcfg_2bit
,
497 .get_config
= samsung_gpio_getcfg_2bit
,
500 .set_pull
= exynos_gpio_setpull
,
501 .get_pull
= exynos_gpio_getpull
,
505 .set_pull
= exynos_gpio_setpull
,
506 .get_pull
= exynos_gpio_getpull
,
511 * Default routines for controlling GPIO, based on the original S3C24XX
512 * GPIO functions which deal with the case where each gpio bank of the
513 * chip is as following:
515 * base + 0x00: Control register, 2 bits per gpio
516 * gpio n: 2 bits starting at (2*n)
517 * 00 = input, 01 = output, others mean special-function
518 * base + 0x04: Data register, 1 bit per gpio
522 static int samsung_gpiolib_2bit_input(struct gpio_chip
*chip
, unsigned offset
)
524 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
525 void __iomem
*base
= ourchip
->base
;
529 samsung_gpio_lock(ourchip
, flags
);
531 con
= __raw_readl(base
+ 0x00);
532 con
&= ~(3 << (offset
* 2));
534 __raw_writel(con
, base
+ 0x00);
536 samsung_gpio_unlock(ourchip
, flags
);
540 static int samsung_gpiolib_2bit_output(struct gpio_chip
*chip
,
541 unsigned offset
, int value
)
543 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
544 void __iomem
*base
= ourchip
->base
;
549 samsung_gpio_lock(ourchip
, flags
);
551 dat
= __raw_readl(base
+ 0x04);
552 dat
&= ~(1 << offset
);
555 __raw_writel(dat
, base
+ 0x04);
557 con
= __raw_readl(base
+ 0x00);
558 con
&= ~(3 << (offset
* 2));
559 con
|= 1 << (offset
* 2);
561 __raw_writel(con
, base
+ 0x00);
562 __raw_writel(dat
, base
+ 0x04);
564 samsung_gpio_unlock(ourchip
, flags
);
569 * The samsung_gpiolib_4bit routines are to control the gpio banks where
570 * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the
573 * base + 0x00: Control register, 4 bits per gpio
574 * gpio n: 4 bits starting at (4*n)
575 * 0000 = input, 0001 = output, others mean special-function
576 * base + 0x04: Data register, 1 bit per gpio
579 * Note, since the data register is one bit per gpio and is at base + 0x4
580 * we can use samsung_gpiolib_get and samsung_gpiolib_set to change the
581 * state of the output.
584 static int samsung_gpiolib_4bit_input(struct gpio_chip
*chip
,
587 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
588 void __iomem
*base
= ourchip
->base
;
591 con
= __raw_readl(base
+ GPIOCON_OFF
);
592 if (ourchip
->bitmap_gpio_int
& BIT(offset
))
593 con
|= 0xf << con_4bit_shift(offset
);
595 con
&= ~(0xf << con_4bit_shift(offset
));
596 __raw_writel(con
, base
+ GPIOCON_OFF
);
598 pr_debug("%s: %p: CON now %08lx\n", __func__
, base
, con
);
603 static int samsung_gpiolib_4bit_output(struct gpio_chip
*chip
,
604 unsigned int offset
, int value
)
606 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
607 void __iomem
*base
= ourchip
->base
;
611 con
= __raw_readl(base
+ GPIOCON_OFF
);
612 con
&= ~(0xf << con_4bit_shift(offset
));
613 con
|= 0x1 << con_4bit_shift(offset
);
615 dat
= __raw_readl(base
+ GPIODAT_OFF
);
620 dat
&= ~(1 << offset
);
622 __raw_writel(dat
, base
+ GPIODAT_OFF
);
623 __raw_writel(con
, base
+ GPIOCON_OFF
);
624 __raw_writel(dat
, base
+ GPIODAT_OFF
);
626 pr_debug("%s: %p: CON %08lx, DAT %08lx\n", __func__
, base
, con
, dat
);
632 * The next set of routines are for the case where the GPIO configuration
633 * registers are 4 bits per GPIO but there is more than one register (the
634 * bank has more than 8 GPIOs.
636 * This case is the similar to the 4 bit case, but the registers are as
639 * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs)
640 * gpio n: 4 bits starting at (4*n)
641 * 0000 = input, 0001 = output, others mean special-function
642 * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs)
643 * gpio n: 4 bits starting at (4*n)
644 * 0000 = input, 0001 = output, others mean special-function
645 * base + 0x08: Data register, 1 bit per gpio
648 * To allow us to use the samsung_gpiolib_get and samsung_gpiolib_set
649 * routines we store the 'base + 0x4' address so that these routines see
650 * the data register at ourchip->base + 0x04.
653 static int samsung_gpiolib_4bit2_input(struct gpio_chip
*chip
,
656 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
657 void __iomem
*base
= ourchip
->base
;
658 void __iomem
*regcon
= base
;
666 con
= __raw_readl(regcon
);
667 con
&= ~(0xf << con_4bit_shift(offset
));
668 __raw_writel(con
, regcon
);
670 pr_debug("%s: %p: CON %08lx\n", __func__
, base
, con
);
675 static int samsung_gpiolib_4bit2_output(struct gpio_chip
*chip
,
676 unsigned int offset
, int value
)
678 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
679 void __iomem
*base
= ourchip
->base
;
680 void __iomem
*regcon
= base
;
683 unsigned con_offset
= offset
;
690 con
= __raw_readl(regcon
);
691 con
&= ~(0xf << con_4bit_shift(con_offset
));
692 con
|= 0x1 << con_4bit_shift(con_offset
);
694 dat
= __raw_readl(base
+ GPIODAT_OFF
);
699 dat
&= ~(1 << offset
);
701 __raw_writel(dat
, base
+ GPIODAT_OFF
);
702 __raw_writel(con
, regcon
);
703 __raw_writel(dat
, base
+ GPIODAT_OFF
);
705 pr_debug("%s: %p: CON %08lx, DAT %08lx\n", __func__
, base
, con
, dat
);
710 #ifdef CONFIG_PLAT_S3C24XX
711 /* The next set of routines are for the case of s3c24xx bank a */
713 static int s3c24xx_gpiolib_banka_input(struct gpio_chip
*chip
, unsigned offset
)
718 static int s3c24xx_gpiolib_banka_output(struct gpio_chip
*chip
,
719 unsigned offset
, int value
)
721 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
722 void __iomem
*base
= ourchip
->base
;
727 local_irq_save(flags
);
729 con
= __raw_readl(base
+ 0x00);
730 dat
= __raw_readl(base
+ 0x04);
732 dat
&= ~(1 << offset
);
736 __raw_writel(dat
, base
+ 0x04);
738 con
&= ~(1 << offset
);
740 __raw_writel(con
, base
+ 0x00);
741 __raw_writel(dat
, base
+ 0x04);
743 local_irq_restore(flags
);
748 /* The next set of routines are for the case of s5p64x0 bank r */
750 static int s5p64x0_gpiolib_rbank_input(struct gpio_chip
*chip
,
753 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
754 void __iomem
*base
= ourchip
->base
;
755 void __iomem
*regcon
= base
;
775 samsung_gpio_lock(ourchip
, flags
);
777 con
= __raw_readl(regcon
);
778 con
&= ~(0xf << con_4bit_shift(offset
));
779 __raw_writel(con
, regcon
);
781 samsung_gpio_unlock(ourchip
, flags
);
786 static int s5p64x0_gpiolib_rbank_output(struct gpio_chip
*chip
,
787 unsigned int offset
, int value
)
789 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
790 void __iomem
*base
= ourchip
->base
;
791 void __iomem
*regcon
= base
;
795 unsigned con_offset
= offset
;
797 switch (con_offset
) {
813 samsung_gpio_lock(ourchip
, flags
);
815 con
= __raw_readl(regcon
);
816 con
&= ~(0xf << con_4bit_shift(con_offset
));
817 con
|= 0x1 << con_4bit_shift(con_offset
);
819 dat
= __raw_readl(base
+ GPIODAT_OFF
);
823 dat
&= ~(1 << offset
);
825 __raw_writel(con
, regcon
);
826 __raw_writel(dat
, base
+ GPIODAT_OFF
);
828 samsung_gpio_unlock(ourchip
, flags
);
833 static void samsung_gpiolib_set(struct gpio_chip
*chip
,
834 unsigned offset
, int value
)
836 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
837 void __iomem
*base
= ourchip
->base
;
841 samsung_gpio_lock(ourchip
, flags
);
843 dat
= __raw_readl(base
+ 0x04);
844 dat
&= ~(1 << offset
);
847 __raw_writel(dat
, base
+ 0x04);
849 samsung_gpio_unlock(ourchip
, flags
);
852 static int samsung_gpiolib_get(struct gpio_chip
*chip
, unsigned offset
)
854 struct samsung_gpio_chip
*ourchip
= to_samsung_gpio(chip
);
857 val
= __raw_readl(ourchip
->base
+ 0x04);
865 * CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios
866 * for use with the configuration calls, and other parts of the s3c gpiolib
869 * Not all s3c support code will need this, as some configurations of cpu
870 * may only support one or two different configuration options and have an
871 * easy gpio to samsung_gpio_chip mapping function. If this is the case, then
872 * the machine support file should provide its own samsung_gpiolib_getchip()
873 * and any other necessary functions.
876 #ifdef CONFIG_S3C_GPIO_TRACK
877 struct samsung_gpio_chip
*s3c_gpios
[S3C_GPIO_END
];
879 static __init
void s3c_gpiolib_track(struct samsung_gpio_chip
*chip
)
884 gpn
= chip
->chip
.base
;
885 for (i
= 0; i
< chip
->chip
.ngpio
; i
++, gpn
++) {
886 BUG_ON(gpn
>= ARRAY_SIZE(s3c_gpios
));
887 s3c_gpios
[gpn
] = chip
;
890 #endif /* CONFIG_S3C_GPIO_TRACK */
893 * samsung_gpiolib_add() - add the Samsung gpio_chip.
894 * @chip: The chip to register
896 * This is a wrapper to gpiochip_add() that takes our specific gpio chip
897 * information and makes the necessary alterations for the platform and
898 * notes the information for use with the configuration systems and any
899 * other parts of the system.
902 static void __init
samsung_gpiolib_add(struct samsung_gpio_chip
*chip
)
904 struct gpio_chip
*gc
= &chip
->chip
;
911 spin_lock_init(&chip
->lock
);
913 if (!gc
->direction_input
)
914 gc
->direction_input
= samsung_gpiolib_2bit_input
;
915 if (!gc
->direction_output
)
916 gc
->direction_output
= samsung_gpiolib_2bit_output
;
918 gc
->set
= samsung_gpiolib_set
;
920 gc
->get
= samsung_gpiolib_get
;
923 if (chip
->pm
!= NULL
) {
924 if (!chip
->pm
->save
|| !chip
->pm
->resume
)
925 pr_err("gpio: %s has missing PM functions\n",
928 pr_err("gpio: %s has no PM function\n", gc
->label
);
931 /* gpiochip_add() prints own failure message on error. */
932 ret
= gpiochip_add(gc
);
934 s3c_gpiolib_track(chip
);
937 #if defined(CONFIG_PLAT_S3C24XX) && defined(CONFIG_OF)
938 static int s3c24xx_gpio_xlate(struct gpio_chip
*gc
,
939 const struct of_phandle_args
*gpiospec
, u32
*flags
)
943 if (WARN_ON(gc
->of_gpio_n_cells
< 3))
946 if (WARN_ON(gpiospec
->args_count
< gc
->of_gpio_n_cells
))
949 if (gpiospec
->args
[0] > gc
->ngpio
)
952 pin
= gc
->base
+ gpiospec
->args
[0];
954 if (s3c_gpio_cfgpin(pin
, S3C_GPIO_SFN(gpiospec
->args
[1])))
955 pr_warn("gpio_xlate: failed to set pin function\n");
956 if (s3c_gpio_setpull(pin
, gpiospec
->args
[2] & 0xffff))
957 pr_warn("gpio_xlate: failed to set pin pull up/down\n");
960 *flags
= gpiospec
->args
[2] >> 16;
962 return gpiospec
->args
[0];
965 static const struct of_device_id s3c24xx_gpio_dt_match
[] __initdata
= {
966 { .compatible
= "samsung,s3c24xx-gpio", },
970 static __init
void s3c24xx_gpiolib_attach_ofnode(struct samsung_gpio_chip
*chip
,
971 u64 base
, u64 offset
)
973 struct gpio_chip
*gc
= &chip
->chip
;
976 if (!of_have_populated_dt())
979 address
= chip
->base
? base
+ ((u32
)chip
->base
& 0xfff) : base
+ offset
;
980 gc
->of_node
= of_find_matching_node_by_address(NULL
,
981 s3c24xx_gpio_dt_match
, address
);
983 pr_info("gpio: device tree node not found for gpio controller"
984 " with base address %08llx\n", address
);
987 gc
->of_gpio_n_cells
= 3;
988 gc
->of_xlate
= s3c24xx_gpio_xlate
;
991 static __init
void s3c24xx_gpiolib_attach_ofnode(struct samsung_gpio_chip
*chip
,
992 u64 base
, u64 offset
)
996 #endif /* defined(CONFIG_PLAT_S3C24XX) && defined(CONFIG_OF) */
998 static void __init
s3c24xx_gpiolib_add_chips(struct samsung_gpio_chip
*chip
,
999 int nr_chips
, void __iomem
*base
)
1002 struct gpio_chip
*gc
= &chip
->chip
;
1004 for (i
= 0 ; i
< nr_chips
; i
++, chip
++) {
1005 /* skip banks not present on SoC */
1006 if (chip
->chip
.base
>= S3C_GPIO_END
)
1010 chip
->config
= &s3c24xx_gpiocfg_default
;
1012 chip
->pm
= __gpio_pm(&samsung_gpio_pm_2bit
);
1013 if ((base
!= NULL
) && (chip
->base
== NULL
))
1014 chip
->base
= base
+ ((i
) * 0x10);
1016 if (!gc
->direction_input
)
1017 gc
->direction_input
= samsung_gpiolib_2bit_input
;
1018 if (!gc
->direction_output
)
1019 gc
->direction_output
= samsung_gpiolib_2bit_output
;
1021 samsung_gpiolib_add(chip
);
1023 s3c24xx_gpiolib_attach_ofnode(chip
, S3C24XX_PA_GPIO
, i
* 0x10);
1027 static void __init
samsung_gpiolib_add_2bit_chips(struct samsung_gpio_chip
*chip
,
1028 int nr_chips
, void __iomem
*base
,
1029 unsigned int offset
)
1033 for (i
= 0 ; i
< nr_chips
; i
++, chip
++) {
1034 chip
->chip
.direction_input
= samsung_gpiolib_2bit_input
;
1035 chip
->chip
.direction_output
= samsung_gpiolib_2bit_output
;
1038 chip
->config
= &samsung_gpio_cfgs
[7];
1040 chip
->pm
= __gpio_pm(&samsung_gpio_pm_2bit
);
1041 if ((base
!= NULL
) && (chip
->base
== NULL
))
1042 chip
->base
= base
+ ((i
) * offset
);
1044 samsung_gpiolib_add(chip
);
1049 * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
1050 * @chip: The gpio chip that is being configured.
1051 * @nr_chips: The no of chips (gpio ports) for the GPIO being configured.
1053 * This helper deal with the GPIO cases where the control register has 4 bits
1054 * of control per GPIO, generally in the form of:
1057 * others = Special functions (dependent on bank)
1059 * Note, since the code to deal with the case where there are two control
1060 * registers instead of one, we do not have a separate set of function
1061 * (samsung_gpiolib_add_4bit2_chips)for each case.
1064 static void __init
samsung_gpiolib_add_4bit_chips(struct samsung_gpio_chip
*chip
,
1065 int nr_chips
, void __iomem
*base
)
1069 for (i
= 0 ; i
< nr_chips
; i
++, chip
++) {
1070 chip
->chip
.direction_input
= samsung_gpiolib_4bit_input
;
1071 chip
->chip
.direction_output
= samsung_gpiolib_4bit_output
;
1074 chip
->config
= &samsung_gpio_cfgs
[2];
1076 chip
->pm
= __gpio_pm(&samsung_gpio_pm_4bit
);
1077 if ((base
!= NULL
) && (chip
->base
== NULL
))
1078 chip
->base
= base
+ ((i
) * 0x20);
1080 chip
->bitmap_gpio_int
= 0;
1082 samsung_gpiolib_add(chip
);
1086 static void __init
samsung_gpiolib_add_4bit2_chips(struct samsung_gpio_chip
*chip
,
1089 for (; nr_chips
> 0; nr_chips
--, chip
++) {
1090 chip
->chip
.direction_input
= samsung_gpiolib_4bit2_input
;
1091 chip
->chip
.direction_output
= samsung_gpiolib_4bit2_output
;
1094 chip
->config
= &samsung_gpio_cfgs
[2];
1096 chip
->pm
= __gpio_pm(&samsung_gpio_pm_4bit
);
1098 samsung_gpiolib_add(chip
);
1102 static void __init
s5p64x0_gpiolib_add_rbank(struct samsung_gpio_chip
*chip
,
1105 for (; nr_chips
> 0; nr_chips
--, chip
++) {
1106 chip
->chip
.direction_input
= s5p64x0_gpiolib_rbank_input
;
1107 chip
->chip
.direction_output
= s5p64x0_gpiolib_rbank_output
;
1110 chip
->pm
= __gpio_pm(&samsung_gpio_pm_4bit
);
1112 samsung_gpiolib_add(chip
);
1116 int samsung_gpiolib_to_irq(struct gpio_chip
*chip
, unsigned int offset
)
1118 struct samsung_gpio_chip
*samsung_chip
= container_of(chip
, struct samsung_gpio_chip
, chip
);
1120 return samsung_chip
->irq_base
+ offset
;
1123 #ifdef CONFIG_PLAT_S3C24XX
1124 static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip
*chip
, unsigned offset
)
1127 return IRQ_EINT0
+ offset
;
1130 return IRQ_EINT4
+ offset
- 4;
1136 #ifdef CONFIG_PLAT_S3C64XX
1137 static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip
*chip
, unsigned pin
)
1139 return pin
< 5 ? IRQ_EINT(23) + pin
: -ENXIO
;
1142 static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip
*chip
, unsigned pin
)
1144 return pin
>= 8 ? IRQ_EINT(16) + pin
- 8 : -ENXIO
;
1148 struct samsung_gpio_chip s3c24xx_gpios
[] = {
1149 #ifdef CONFIG_PLAT_S3C24XX
1151 .config
= &s3c24xx_gpiocfg_banka
,
1153 .base
= S3C2410_GPA(0),
1154 .owner
= THIS_MODULE
,
1157 .direction_input
= s3c24xx_gpiolib_banka_input
,
1158 .direction_output
= s3c24xx_gpiolib_banka_output
,
1162 .base
= S3C2410_GPB(0),
1163 .owner
= THIS_MODULE
,
1169 .base
= S3C2410_GPC(0),
1170 .owner
= THIS_MODULE
,
1176 .base
= S3C2410_GPD(0),
1177 .owner
= THIS_MODULE
,
1183 .base
= S3C2410_GPE(0),
1185 .owner
= THIS_MODULE
,
1190 .base
= S3C2410_GPF(0),
1191 .owner
= THIS_MODULE
,
1194 .to_irq
= s3c24xx_gpiolib_fbank_to_irq
,
1197 .irq_base
= IRQ_EINT8
,
1199 .base
= S3C2410_GPG(0),
1200 .owner
= THIS_MODULE
,
1203 .to_irq
= samsung_gpiolib_to_irq
,
1207 .base
= S3C2410_GPH(0),
1208 .owner
= THIS_MODULE
,
1213 /* GPIOS for the S3C2443 and later devices. */
1215 .base
= S3C2440_GPJCON
,
1217 .base
= S3C2410_GPJ(0),
1218 .owner
= THIS_MODULE
,
1223 .base
= S3C2443_GPKCON
,
1225 .base
= S3C2410_GPK(0),
1226 .owner
= THIS_MODULE
,
1231 .base
= S3C2443_GPLCON
,
1233 .base
= S3C2410_GPL(0),
1234 .owner
= THIS_MODULE
,
1239 .base
= S3C2443_GPMCON
,
1241 .base
= S3C2410_GPM(0),
1242 .owner
= THIS_MODULE
,
1251 * GPIO bank summary:
1253 * Bank GPIOs Style SlpCon ExtInt Group
1259 * F 16 2Bit Yes 4 [1]
1261 * H 10 4Bit[2] Yes 6
1262 * I 16 2Bit Yes None
1263 * J 12 2Bit Yes None
1264 * K 16 4Bit[2] No None
1265 * L 15 4Bit[2] No None
1266 * M 6 4Bit No IRQ_EINT
1267 * N 16 2Bit No IRQ_EINT
1272 * [1] BANKF pins 14,15 do not form part of the external interrupt sources
1273 * [2] BANK has two control registers, GPxCON0 and GPxCON1
1276 static struct samsung_gpio_chip s3c64xx_gpios_4bit
[] = {
1277 #ifdef CONFIG_PLAT_S3C64XX
1280 .base
= S3C64XX_GPA(0),
1281 .ngpio
= S3C64XX_GPIO_A_NR
,
1286 .base
= S3C64XX_GPB(0),
1287 .ngpio
= S3C64XX_GPIO_B_NR
,
1292 .base
= S3C64XX_GPC(0),
1293 .ngpio
= S3C64XX_GPIO_C_NR
,
1298 .base
= S3C64XX_GPD(0),
1299 .ngpio
= S3C64XX_GPIO_D_NR
,
1303 .config
= &samsung_gpio_cfgs
[0],
1305 .base
= S3C64XX_GPE(0),
1306 .ngpio
= S3C64XX_GPIO_E_NR
,
1310 .base
= S3C64XX_GPG_BASE
,
1312 .base
= S3C64XX_GPG(0),
1313 .ngpio
= S3C64XX_GPIO_G_NR
,
1317 .base
= S3C64XX_GPM_BASE
,
1318 .config
= &samsung_gpio_cfgs
[1],
1320 .base
= S3C64XX_GPM(0),
1321 .ngpio
= S3C64XX_GPIO_M_NR
,
1323 .to_irq
= s3c64xx_gpiolib_mbank_to_irq
,
1329 static struct samsung_gpio_chip s3c64xx_gpios_4bit2
[] = {
1330 #ifdef CONFIG_PLAT_S3C64XX
1332 .base
= S3C64XX_GPH_BASE
+ 0x4,
1334 .base
= S3C64XX_GPH(0),
1335 .ngpio
= S3C64XX_GPIO_H_NR
,
1339 .base
= S3C64XX_GPK_BASE
+ 0x4,
1340 .config
= &samsung_gpio_cfgs
[0],
1342 .base
= S3C64XX_GPK(0),
1343 .ngpio
= S3C64XX_GPIO_K_NR
,
1347 .base
= S3C64XX_GPL_BASE
+ 0x4,
1348 .config
= &samsung_gpio_cfgs
[1],
1350 .base
= S3C64XX_GPL(0),
1351 .ngpio
= S3C64XX_GPIO_L_NR
,
1353 .to_irq
= s3c64xx_gpiolib_lbank_to_irq
,
1359 static struct samsung_gpio_chip s3c64xx_gpios_2bit
[] = {
1360 #ifdef CONFIG_PLAT_S3C64XX
1362 .base
= S3C64XX_GPF_BASE
,
1363 .config
= &samsung_gpio_cfgs
[6],
1365 .base
= S3C64XX_GPF(0),
1366 .ngpio
= S3C64XX_GPIO_F_NR
,
1370 .config
= &samsung_gpio_cfgs
[7],
1372 .base
= S3C64XX_GPI(0),
1373 .ngpio
= S3C64XX_GPIO_I_NR
,
1377 .config
= &samsung_gpio_cfgs
[7],
1379 .base
= S3C64XX_GPJ(0),
1380 .ngpio
= S3C64XX_GPIO_J_NR
,
1384 .config
= &samsung_gpio_cfgs
[6],
1386 .base
= S3C64XX_GPO(0),
1387 .ngpio
= S3C64XX_GPIO_O_NR
,
1391 .config
= &samsung_gpio_cfgs
[6],
1393 .base
= S3C64XX_GPP(0),
1394 .ngpio
= S3C64XX_GPIO_P_NR
,
1398 .config
= &samsung_gpio_cfgs
[6],
1400 .base
= S3C64XX_GPQ(0),
1401 .ngpio
= S3C64XX_GPIO_Q_NR
,
1405 .base
= S3C64XX_GPN_BASE
,
1406 .irq_base
= IRQ_EINT(0),
1407 .config
= &samsung_gpio_cfgs
[5],
1409 .base
= S3C64XX_GPN(0),
1410 .ngpio
= S3C64XX_GPIO_N_NR
,
1412 .to_irq
= samsung_gpiolib_to_irq
,
1419 * S5P6440 GPIO bank summary:
1421 * Bank GPIOs Style SlpCon ExtInt Group
1425 * F 2 2Bit Yes 4 [1]
1427 * H 10 4Bit[2] Yes 6
1428 * I 16 2Bit Yes None
1429 * J 12 2Bit Yes None
1430 * N 16 2Bit No IRQ_EINT
1432 * R 15 4Bit[2] Yes 8
1435 static struct samsung_gpio_chip s5p6440_gpios_4bit
[] = {
1436 #ifdef CONFIG_CPU_S5P6440
1439 .base
= S5P6440_GPA(0),
1440 .ngpio
= S5P6440_GPIO_A_NR
,
1445 .base
= S5P6440_GPB(0),
1446 .ngpio
= S5P6440_GPIO_B_NR
,
1451 .base
= S5P6440_GPC(0),
1452 .ngpio
= S5P6440_GPIO_C_NR
,
1456 .base
= S5P64X0_GPG_BASE
,
1458 .base
= S5P6440_GPG(0),
1459 .ngpio
= S5P6440_GPIO_G_NR
,
1466 static struct samsung_gpio_chip s5p6440_gpios_4bit2
[] = {
1467 #ifdef CONFIG_CPU_S5P6440
1469 .base
= S5P64X0_GPH_BASE
+ 0x4,
1471 .base
= S5P6440_GPH(0),
1472 .ngpio
= S5P6440_GPIO_H_NR
,
1479 static struct samsung_gpio_chip s5p6440_gpios_rbank
[] = {
1480 #ifdef CONFIG_CPU_S5P6440
1482 .base
= S5P64X0_GPR_BASE
+ 0x4,
1483 .config
= &s5p64x0_gpio_cfg_rbank
,
1485 .base
= S5P6440_GPR(0),
1486 .ngpio
= S5P6440_GPIO_R_NR
,
1493 static struct samsung_gpio_chip s5p6440_gpios_2bit
[] = {
1494 #ifdef CONFIG_CPU_S5P6440
1496 .base
= S5P64X0_GPF_BASE
,
1497 .config
= &samsung_gpio_cfgs
[6],
1499 .base
= S5P6440_GPF(0),
1500 .ngpio
= S5P6440_GPIO_F_NR
,
1504 .base
= S5P64X0_GPI_BASE
,
1505 .config
= &samsung_gpio_cfgs
[4],
1507 .base
= S5P6440_GPI(0),
1508 .ngpio
= S5P6440_GPIO_I_NR
,
1512 .base
= S5P64X0_GPJ_BASE
,
1513 .config
= &samsung_gpio_cfgs
[4],
1515 .base
= S5P6440_GPJ(0),
1516 .ngpio
= S5P6440_GPIO_J_NR
,
1520 .base
= S5P64X0_GPN_BASE
,
1521 .config
= &samsung_gpio_cfgs
[5],
1523 .base
= S5P6440_GPN(0),
1524 .ngpio
= S5P6440_GPIO_N_NR
,
1528 .base
= S5P64X0_GPP_BASE
,
1529 .config
= &samsung_gpio_cfgs
[6],
1531 .base
= S5P6440_GPP(0),
1532 .ngpio
= S5P6440_GPIO_P_NR
,
1540 * S5P6450 GPIO bank summary:
1542 * Bank GPIOs Style SlpCon ExtInt Group
1548 * G 14 4Bit[2] Yes 5
1549 * H 10 4Bit[2] Yes 6
1550 * I 16 2Bit Yes None
1551 * J 12 2Bit Yes None
1553 * N 16 2Bit No IRQ_EINT
1555 * Q 14 2Bit Yes None
1556 * R 15 4Bit[2] Yes None
1559 * [1] BANKF pins 14,15 do not form part of the external interrupt sources
1560 * [2] BANK has two control registers, GPxCON0 and GPxCON1
1563 static struct samsung_gpio_chip s5p6450_gpios_4bit
[] = {
1564 #ifdef CONFIG_CPU_S5P6450
1567 .base
= S5P6450_GPA(0),
1568 .ngpio
= S5P6450_GPIO_A_NR
,
1573 .base
= S5P6450_GPB(0),
1574 .ngpio
= S5P6450_GPIO_B_NR
,
1579 .base
= S5P6450_GPC(0),
1580 .ngpio
= S5P6450_GPIO_C_NR
,
1585 .base
= S5P6450_GPD(0),
1586 .ngpio
= S5P6450_GPIO_D_NR
,
1590 .base
= S5P6450_GPK_BASE
,
1592 .base
= S5P6450_GPK(0),
1593 .ngpio
= S5P6450_GPIO_K_NR
,
1600 static struct samsung_gpio_chip s5p6450_gpios_4bit2
[] = {
1601 #ifdef CONFIG_CPU_S5P6450
1603 .base
= S5P64X0_GPG_BASE
+ 0x4,
1605 .base
= S5P6450_GPG(0),
1606 .ngpio
= S5P6450_GPIO_G_NR
,
1610 .base
= S5P64X0_GPH_BASE
+ 0x4,
1612 .base
= S5P6450_GPH(0),
1613 .ngpio
= S5P6450_GPIO_H_NR
,
1620 static struct samsung_gpio_chip s5p6450_gpios_rbank
[] = {
1621 #ifdef CONFIG_CPU_S5P6450
1623 .base
= S5P64X0_GPR_BASE
+ 0x4,
1624 .config
= &s5p64x0_gpio_cfg_rbank
,
1626 .base
= S5P6450_GPR(0),
1627 .ngpio
= S5P6450_GPIO_R_NR
,
1634 static struct samsung_gpio_chip s5p6450_gpios_2bit
[] = {
1635 #ifdef CONFIG_CPU_S5P6450
1637 .base
= S5P64X0_GPF_BASE
,
1638 .config
= &samsung_gpio_cfgs
[6],
1640 .base
= S5P6450_GPF(0),
1641 .ngpio
= S5P6450_GPIO_F_NR
,
1645 .base
= S5P64X0_GPI_BASE
,
1646 .config
= &samsung_gpio_cfgs
[4],
1648 .base
= S5P6450_GPI(0),
1649 .ngpio
= S5P6450_GPIO_I_NR
,
1653 .base
= S5P64X0_GPJ_BASE
,
1654 .config
= &samsung_gpio_cfgs
[4],
1656 .base
= S5P6450_GPJ(0),
1657 .ngpio
= S5P6450_GPIO_J_NR
,
1661 .base
= S5P64X0_GPN_BASE
,
1662 .config
= &samsung_gpio_cfgs
[5],
1664 .base
= S5P6450_GPN(0),
1665 .ngpio
= S5P6450_GPIO_N_NR
,
1669 .base
= S5P64X0_GPP_BASE
,
1670 .config
= &samsung_gpio_cfgs
[6],
1672 .base
= S5P6450_GPP(0),
1673 .ngpio
= S5P6450_GPIO_P_NR
,
1677 .base
= S5P6450_GPQ_BASE
,
1678 .config
= &samsung_gpio_cfgs
[5],
1680 .base
= S5P6450_GPQ(0),
1681 .ngpio
= S5P6450_GPIO_Q_NR
,
1685 .base
= S5P6450_GPS_BASE
,
1686 .config
= &samsung_gpio_cfgs
[6],
1688 .base
= S5P6450_GPS(0),
1689 .ngpio
= S5P6450_GPIO_S_NR
,
1697 * S5PC100 GPIO bank summary:
1699 * Bank GPIOs Style INT Type
1700 * A0 8 4Bit GPIO_INT0
1701 * A1 5 4Bit GPIO_INT1
1702 * B 8 4Bit GPIO_INT2
1703 * C 5 4Bit GPIO_INT3
1704 * D 7 4Bit GPIO_INT4
1705 * E0 8 4Bit GPIO_INT5
1706 * E1 6 4Bit GPIO_INT6
1707 * F0 8 4Bit GPIO_INT7
1708 * F1 8 4Bit GPIO_INT8
1709 * F2 8 4Bit GPIO_INT9
1710 * F3 4 4Bit GPIO_INT10
1711 * G0 8 4Bit GPIO_INT11
1712 * G1 3 4Bit GPIO_INT12
1713 * G2 7 4Bit GPIO_INT13
1714 * G3 7 4Bit GPIO_INT14
1715 * H0 8 4Bit WKUP_INT
1716 * H1 8 4Bit WKUP_INT
1717 * H2 8 4Bit WKUP_INT
1718 * H3 8 4Bit WKUP_INT
1719 * I 8 4Bit GPIO_INT15
1720 * J0 8 4Bit GPIO_INT16
1721 * J1 5 4Bit GPIO_INT17
1722 * J2 8 4Bit GPIO_INT18
1723 * J3 8 4Bit GPIO_INT19
1724 * J4 4 4Bit GPIO_INT20
1735 static struct samsung_gpio_chip s5pc100_gpios_4bit
[] = {
1736 #ifdef CONFIG_CPU_S5PC100
1739 .base
= S5PC100_GPA0(0),
1740 .ngpio
= S5PC100_GPIO_A0_NR
,
1745 .base
= S5PC100_GPA1(0),
1746 .ngpio
= S5PC100_GPIO_A1_NR
,
1751 .base
= S5PC100_GPB(0),
1752 .ngpio
= S5PC100_GPIO_B_NR
,
1757 .base
= S5PC100_GPC(0),
1758 .ngpio
= S5PC100_GPIO_C_NR
,
1763 .base
= S5PC100_GPD(0),
1764 .ngpio
= S5PC100_GPIO_D_NR
,
1769 .base
= S5PC100_GPE0(0),
1770 .ngpio
= S5PC100_GPIO_E0_NR
,
1775 .base
= S5PC100_GPE1(0),
1776 .ngpio
= S5PC100_GPIO_E1_NR
,
1781 .base
= S5PC100_GPF0(0),
1782 .ngpio
= S5PC100_GPIO_F0_NR
,
1787 .base
= S5PC100_GPF1(0),
1788 .ngpio
= S5PC100_GPIO_F1_NR
,
1793 .base
= S5PC100_GPF2(0),
1794 .ngpio
= S5PC100_GPIO_F2_NR
,
1799 .base
= S5PC100_GPF3(0),
1800 .ngpio
= S5PC100_GPIO_F3_NR
,
1805 .base
= S5PC100_GPG0(0),
1806 .ngpio
= S5PC100_GPIO_G0_NR
,
1811 .base
= S5PC100_GPG1(0),
1812 .ngpio
= S5PC100_GPIO_G1_NR
,
1817 .base
= S5PC100_GPG2(0),
1818 .ngpio
= S5PC100_GPIO_G2_NR
,
1823 .base
= S5PC100_GPG3(0),
1824 .ngpio
= S5PC100_GPIO_G3_NR
,
1829 .base
= S5PC100_GPI(0),
1830 .ngpio
= S5PC100_GPIO_I_NR
,
1835 .base
= S5PC100_GPJ0(0),
1836 .ngpio
= S5PC100_GPIO_J0_NR
,
1841 .base
= S5PC100_GPJ1(0),
1842 .ngpio
= S5PC100_GPIO_J1_NR
,
1847 .base
= S5PC100_GPJ2(0),
1848 .ngpio
= S5PC100_GPIO_J2_NR
,
1853 .base
= S5PC100_GPJ3(0),
1854 .ngpio
= S5PC100_GPIO_J3_NR
,
1859 .base
= S5PC100_GPJ4(0),
1860 .ngpio
= S5PC100_GPIO_J4_NR
,
1865 .base
= S5PC100_GPK0(0),
1866 .ngpio
= S5PC100_GPIO_K0_NR
,
1871 .base
= S5PC100_GPK1(0),
1872 .ngpio
= S5PC100_GPIO_K1_NR
,
1877 .base
= S5PC100_GPK2(0),
1878 .ngpio
= S5PC100_GPIO_K2_NR
,
1883 .base
= S5PC100_GPK3(0),
1884 .ngpio
= S5PC100_GPIO_K3_NR
,
1889 .base
= S5PC100_GPL0(0),
1890 .ngpio
= S5PC100_GPIO_L0_NR
,
1895 .base
= S5PC100_GPL1(0),
1896 .ngpio
= S5PC100_GPIO_L1_NR
,
1901 .base
= S5PC100_GPL2(0),
1902 .ngpio
= S5PC100_GPIO_L2_NR
,
1907 .base
= S5PC100_GPL3(0),
1908 .ngpio
= S5PC100_GPIO_L3_NR
,
1913 .base
= S5PC100_GPL4(0),
1914 .ngpio
= S5PC100_GPIO_L4_NR
,
1918 .base
= (S5P_VA_GPIO
+ 0xC00),
1919 .irq_base
= IRQ_EINT(0),
1921 .base
= S5PC100_GPH0(0),
1922 .ngpio
= S5PC100_GPIO_H0_NR
,
1924 .to_irq
= samsung_gpiolib_to_irq
,
1927 .base
= (S5P_VA_GPIO
+ 0xC20),
1928 .irq_base
= IRQ_EINT(8),
1930 .base
= S5PC100_GPH1(0),
1931 .ngpio
= S5PC100_GPIO_H1_NR
,
1933 .to_irq
= samsung_gpiolib_to_irq
,
1936 .base
= (S5P_VA_GPIO
+ 0xC40),
1937 .irq_base
= IRQ_EINT(16),
1939 .base
= S5PC100_GPH2(0),
1940 .ngpio
= S5PC100_GPIO_H2_NR
,
1942 .to_irq
= samsung_gpiolib_to_irq
,
1945 .base
= (S5P_VA_GPIO
+ 0xC60),
1946 .irq_base
= IRQ_EINT(24),
1948 .base
= S5PC100_GPH3(0),
1949 .ngpio
= S5PC100_GPIO_H3_NR
,
1951 .to_irq
= samsung_gpiolib_to_irq
,
1958 * Followings are the gpio banks in S5PV210/S5PC110
1960 * The 'config' member when left to NULL, is initialized to the default
1961 * structure samsung_gpio_cfgs[3] in the init function below.
1963 * The 'base' member is also initialized in the init function below.
1964 * Note: The initialization of 'base' member of samsung_gpio_chip structure
1965 * uses the above macro and depends on the banks being listed in order here.
1968 static struct samsung_gpio_chip s5pv210_gpios_4bit
[] = {
1969 #ifdef CONFIG_CPU_S5PV210
1972 .base
= S5PV210_GPA0(0),
1973 .ngpio
= S5PV210_GPIO_A0_NR
,
1978 .base
= S5PV210_GPA1(0),
1979 .ngpio
= S5PV210_GPIO_A1_NR
,
1984 .base
= S5PV210_GPB(0),
1985 .ngpio
= S5PV210_GPIO_B_NR
,
1990 .base
= S5PV210_GPC0(0),
1991 .ngpio
= S5PV210_GPIO_C0_NR
,
1996 .base
= S5PV210_GPC1(0),
1997 .ngpio
= S5PV210_GPIO_C1_NR
,
2002 .base
= S5PV210_GPD0(0),
2003 .ngpio
= S5PV210_GPIO_D0_NR
,
2008 .base
= S5PV210_GPD1(0),
2009 .ngpio
= S5PV210_GPIO_D1_NR
,
2014 .base
= S5PV210_GPE0(0),
2015 .ngpio
= S5PV210_GPIO_E0_NR
,
2020 .base
= S5PV210_GPE1(0),
2021 .ngpio
= S5PV210_GPIO_E1_NR
,
2026 .base
= S5PV210_GPF0(0),
2027 .ngpio
= S5PV210_GPIO_F0_NR
,
2032 .base
= S5PV210_GPF1(0),
2033 .ngpio
= S5PV210_GPIO_F1_NR
,
2038 .base
= S5PV210_GPF2(0),
2039 .ngpio
= S5PV210_GPIO_F2_NR
,
2044 .base
= S5PV210_GPF3(0),
2045 .ngpio
= S5PV210_GPIO_F3_NR
,
2050 .base
= S5PV210_GPG0(0),
2051 .ngpio
= S5PV210_GPIO_G0_NR
,
2056 .base
= S5PV210_GPG1(0),
2057 .ngpio
= S5PV210_GPIO_G1_NR
,
2062 .base
= S5PV210_GPG2(0),
2063 .ngpio
= S5PV210_GPIO_G2_NR
,
2068 .base
= S5PV210_GPG3(0),
2069 .ngpio
= S5PV210_GPIO_G3_NR
,
2074 .base
= S5PV210_GPI(0),
2075 .ngpio
= S5PV210_GPIO_I_NR
,
2080 .base
= S5PV210_GPJ0(0),
2081 .ngpio
= S5PV210_GPIO_J0_NR
,
2086 .base
= S5PV210_GPJ1(0),
2087 .ngpio
= S5PV210_GPIO_J1_NR
,
2092 .base
= S5PV210_GPJ2(0),
2093 .ngpio
= S5PV210_GPIO_J2_NR
,
2098 .base
= S5PV210_GPJ3(0),
2099 .ngpio
= S5PV210_GPIO_J3_NR
,
2104 .base
= S5PV210_GPJ4(0),
2105 .ngpio
= S5PV210_GPIO_J4_NR
,
2110 .base
= S5PV210_MP01(0),
2111 .ngpio
= S5PV210_GPIO_MP01_NR
,
2116 .base
= S5PV210_MP02(0),
2117 .ngpio
= S5PV210_GPIO_MP02_NR
,
2122 .base
= S5PV210_MP03(0),
2123 .ngpio
= S5PV210_GPIO_MP03_NR
,
2128 .base
= S5PV210_MP04(0),
2129 .ngpio
= S5PV210_GPIO_MP04_NR
,
2134 .base
= S5PV210_MP05(0),
2135 .ngpio
= S5PV210_GPIO_MP05_NR
,
2139 .base
= (S5P_VA_GPIO
+ 0xC00),
2140 .irq_base
= IRQ_EINT(0),
2142 .base
= S5PV210_GPH0(0),
2143 .ngpio
= S5PV210_GPIO_H0_NR
,
2145 .to_irq
= samsung_gpiolib_to_irq
,
2148 .base
= (S5P_VA_GPIO
+ 0xC20),
2149 .irq_base
= IRQ_EINT(8),
2151 .base
= S5PV210_GPH1(0),
2152 .ngpio
= S5PV210_GPIO_H1_NR
,
2154 .to_irq
= samsung_gpiolib_to_irq
,
2157 .base
= (S5P_VA_GPIO
+ 0xC40),
2158 .irq_base
= IRQ_EINT(16),
2160 .base
= S5PV210_GPH2(0),
2161 .ngpio
= S5PV210_GPIO_H2_NR
,
2163 .to_irq
= samsung_gpiolib_to_irq
,
2166 .base
= (S5P_VA_GPIO
+ 0xC60),
2167 .irq_base
= IRQ_EINT(24),
2169 .base
= S5PV210_GPH3(0),
2170 .ngpio
= S5PV210_GPIO_H3_NR
,
2172 .to_irq
= samsung_gpiolib_to_irq
,
2179 * Followings are the gpio banks in EXYNOS SoCs
2181 * The 'config' member when left to NULL, is initialized to the default
2182 * structure exynos_gpio_cfg in the init function below.
2184 * The 'base' member is also initialized in the init function below.
2185 * Note: The initialization of 'base' member of samsung_gpio_chip structure
2186 * uses the above macro and depends on the banks being listed in order here.
2189 #ifdef CONFIG_ARCH_EXYNOS4
2190 static struct samsung_gpio_chip exynos4_gpios_1
[] = {
2193 .base
= EXYNOS4_GPA0(0),
2194 .ngpio
= EXYNOS4_GPIO_A0_NR
,
2199 .base
= EXYNOS4_GPA1(0),
2200 .ngpio
= EXYNOS4_GPIO_A1_NR
,
2205 .base
= EXYNOS4_GPB(0),
2206 .ngpio
= EXYNOS4_GPIO_B_NR
,
2211 .base
= EXYNOS4_GPC0(0),
2212 .ngpio
= EXYNOS4_GPIO_C0_NR
,
2217 .base
= EXYNOS4_GPC1(0),
2218 .ngpio
= EXYNOS4_GPIO_C1_NR
,
2223 .base
= EXYNOS4_GPD0(0),
2224 .ngpio
= EXYNOS4_GPIO_D0_NR
,
2229 .base
= EXYNOS4_GPD1(0),
2230 .ngpio
= EXYNOS4_GPIO_D1_NR
,
2235 .base
= EXYNOS4_GPE0(0),
2236 .ngpio
= EXYNOS4_GPIO_E0_NR
,
2241 .base
= EXYNOS4_GPE1(0),
2242 .ngpio
= EXYNOS4_GPIO_E1_NR
,
2247 .base
= EXYNOS4_GPE2(0),
2248 .ngpio
= EXYNOS4_GPIO_E2_NR
,
2253 .base
= EXYNOS4_GPE3(0),
2254 .ngpio
= EXYNOS4_GPIO_E3_NR
,
2259 .base
= EXYNOS4_GPE4(0),
2260 .ngpio
= EXYNOS4_GPIO_E4_NR
,
2265 .base
= EXYNOS4_GPF0(0),
2266 .ngpio
= EXYNOS4_GPIO_F0_NR
,
2271 .base
= EXYNOS4_GPF1(0),
2272 .ngpio
= EXYNOS4_GPIO_F1_NR
,
2277 .base
= EXYNOS4_GPF2(0),
2278 .ngpio
= EXYNOS4_GPIO_F2_NR
,
2283 .base
= EXYNOS4_GPF3(0),
2284 .ngpio
= EXYNOS4_GPIO_F3_NR
,
2291 #ifdef CONFIG_ARCH_EXYNOS4
2292 static struct samsung_gpio_chip exynos4_gpios_2
[] = {
2295 .base
= EXYNOS4_GPJ0(0),
2296 .ngpio
= EXYNOS4_GPIO_J0_NR
,
2301 .base
= EXYNOS4_GPJ1(0),
2302 .ngpio
= EXYNOS4_GPIO_J1_NR
,
2307 .base
= EXYNOS4_GPK0(0),
2308 .ngpio
= EXYNOS4_GPIO_K0_NR
,
2313 .base
= EXYNOS4_GPK1(0),
2314 .ngpio
= EXYNOS4_GPIO_K1_NR
,
2319 .base
= EXYNOS4_GPK2(0),
2320 .ngpio
= EXYNOS4_GPIO_K2_NR
,
2325 .base
= EXYNOS4_GPK3(0),
2326 .ngpio
= EXYNOS4_GPIO_K3_NR
,
2331 .base
= EXYNOS4_GPL0(0),
2332 .ngpio
= EXYNOS4_GPIO_L0_NR
,
2337 .base
= EXYNOS4_GPL1(0),
2338 .ngpio
= EXYNOS4_GPIO_L1_NR
,
2343 .base
= EXYNOS4_GPL2(0),
2344 .ngpio
= EXYNOS4_GPIO_L2_NR
,
2348 .config
= &samsung_gpio_cfgs
[8],
2350 .base
= EXYNOS4_GPY0(0),
2351 .ngpio
= EXYNOS4_GPIO_Y0_NR
,
2355 .config
= &samsung_gpio_cfgs
[8],
2357 .base
= EXYNOS4_GPY1(0),
2358 .ngpio
= EXYNOS4_GPIO_Y1_NR
,
2362 .config
= &samsung_gpio_cfgs
[8],
2364 .base
= EXYNOS4_GPY2(0),
2365 .ngpio
= EXYNOS4_GPIO_Y2_NR
,
2369 .config
= &samsung_gpio_cfgs
[8],
2371 .base
= EXYNOS4_GPY3(0),
2372 .ngpio
= EXYNOS4_GPIO_Y3_NR
,
2376 .config
= &samsung_gpio_cfgs
[8],
2378 .base
= EXYNOS4_GPY4(0),
2379 .ngpio
= EXYNOS4_GPIO_Y4_NR
,
2383 .config
= &samsung_gpio_cfgs
[8],
2385 .base
= EXYNOS4_GPY5(0),
2386 .ngpio
= EXYNOS4_GPIO_Y5_NR
,
2390 .config
= &samsung_gpio_cfgs
[8],
2392 .base
= EXYNOS4_GPY6(0),
2393 .ngpio
= EXYNOS4_GPIO_Y6_NR
,
2397 .config
= &samsung_gpio_cfgs
[9],
2398 .irq_base
= IRQ_EINT(0),
2400 .base
= EXYNOS4_GPX0(0),
2401 .ngpio
= EXYNOS4_GPIO_X0_NR
,
2403 .to_irq
= samsung_gpiolib_to_irq
,
2406 .config
= &samsung_gpio_cfgs
[9],
2407 .irq_base
= IRQ_EINT(8),
2409 .base
= EXYNOS4_GPX1(0),
2410 .ngpio
= EXYNOS4_GPIO_X1_NR
,
2412 .to_irq
= samsung_gpiolib_to_irq
,
2415 .config
= &samsung_gpio_cfgs
[9],
2416 .irq_base
= IRQ_EINT(16),
2418 .base
= EXYNOS4_GPX2(0),
2419 .ngpio
= EXYNOS4_GPIO_X2_NR
,
2421 .to_irq
= samsung_gpiolib_to_irq
,
2424 .config
= &samsung_gpio_cfgs
[9],
2425 .irq_base
= IRQ_EINT(24),
2427 .base
= EXYNOS4_GPX3(0),
2428 .ngpio
= EXYNOS4_GPIO_X3_NR
,
2430 .to_irq
= samsung_gpiolib_to_irq
,
2436 #ifdef CONFIG_ARCH_EXYNOS4
2437 static struct samsung_gpio_chip exynos4_gpios_3
[] = {
2440 .base
= EXYNOS4_GPZ(0),
2441 .ngpio
= EXYNOS4_GPIO_Z_NR
,
2448 #ifdef CONFIG_SOC_EXYNOS5250
2449 static struct samsung_gpio_chip exynos5_gpios_1
[] = {
2452 .base
= EXYNOS5_GPA0(0),
2453 .ngpio
= EXYNOS5_GPIO_A0_NR
,
2458 .base
= EXYNOS5_GPA1(0),
2459 .ngpio
= EXYNOS5_GPIO_A1_NR
,
2464 .base
= EXYNOS5_GPA2(0),
2465 .ngpio
= EXYNOS5_GPIO_A2_NR
,
2470 .base
= EXYNOS5_GPB0(0),
2471 .ngpio
= EXYNOS5_GPIO_B0_NR
,
2476 .base
= EXYNOS5_GPB1(0),
2477 .ngpio
= EXYNOS5_GPIO_B1_NR
,
2482 .base
= EXYNOS5_GPB2(0),
2483 .ngpio
= EXYNOS5_GPIO_B2_NR
,
2488 .base
= EXYNOS5_GPB3(0),
2489 .ngpio
= EXYNOS5_GPIO_B3_NR
,
2494 .base
= EXYNOS5_GPC0(0),
2495 .ngpio
= EXYNOS5_GPIO_C0_NR
,
2500 .base
= EXYNOS5_GPC1(0),
2501 .ngpio
= EXYNOS5_GPIO_C1_NR
,
2506 .base
= EXYNOS5_GPC2(0),
2507 .ngpio
= EXYNOS5_GPIO_C2_NR
,
2512 .base
= EXYNOS5_GPC3(0),
2513 .ngpio
= EXYNOS5_GPIO_C3_NR
,
2518 .base
= EXYNOS5_GPD0(0),
2519 .ngpio
= EXYNOS5_GPIO_D0_NR
,
2524 .base
= EXYNOS5_GPD1(0),
2525 .ngpio
= EXYNOS5_GPIO_D1_NR
,
2530 .base
= EXYNOS5_GPY0(0),
2531 .ngpio
= EXYNOS5_GPIO_Y0_NR
,
2536 .base
= EXYNOS5_GPY1(0),
2537 .ngpio
= EXYNOS5_GPIO_Y1_NR
,
2542 .base
= EXYNOS5_GPY2(0),
2543 .ngpio
= EXYNOS5_GPIO_Y2_NR
,
2548 .base
= EXYNOS5_GPY3(0),
2549 .ngpio
= EXYNOS5_GPIO_Y3_NR
,
2554 .base
= EXYNOS5_GPY4(0),
2555 .ngpio
= EXYNOS5_GPIO_Y4_NR
,
2560 .base
= EXYNOS5_GPY5(0),
2561 .ngpio
= EXYNOS5_GPIO_Y5_NR
,
2566 .base
= EXYNOS5_GPY6(0),
2567 .ngpio
= EXYNOS5_GPIO_Y6_NR
,
2572 .base
= EXYNOS5_GPC4(0),
2573 .ngpio
= EXYNOS5_GPIO_C4_NR
,
2577 .config
= &samsung_gpio_cfgs
[9],
2578 .irq_base
= IRQ_EINT(0),
2580 .base
= EXYNOS5_GPX0(0),
2581 .ngpio
= EXYNOS5_GPIO_X0_NR
,
2583 .to_irq
= samsung_gpiolib_to_irq
,
2586 .config
= &samsung_gpio_cfgs
[9],
2587 .irq_base
= IRQ_EINT(8),
2589 .base
= EXYNOS5_GPX1(0),
2590 .ngpio
= EXYNOS5_GPIO_X1_NR
,
2592 .to_irq
= samsung_gpiolib_to_irq
,
2595 .config
= &samsung_gpio_cfgs
[9],
2596 .irq_base
= IRQ_EINT(16),
2598 .base
= EXYNOS5_GPX2(0),
2599 .ngpio
= EXYNOS5_GPIO_X2_NR
,
2601 .to_irq
= samsung_gpiolib_to_irq
,
2604 .config
= &samsung_gpio_cfgs
[9],
2605 .irq_base
= IRQ_EINT(24),
2607 .base
= EXYNOS5_GPX3(0),
2608 .ngpio
= EXYNOS5_GPIO_X3_NR
,
2610 .to_irq
= samsung_gpiolib_to_irq
,
2616 #ifdef CONFIG_SOC_EXYNOS5250
2617 static struct samsung_gpio_chip exynos5_gpios_2
[] = {
2620 .base
= EXYNOS5_GPE0(0),
2621 .ngpio
= EXYNOS5_GPIO_E0_NR
,
2626 .base
= EXYNOS5_GPE1(0),
2627 .ngpio
= EXYNOS5_GPIO_E1_NR
,
2632 .base
= EXYNOS5_GPF0(0),
2633 .ngpio
= EXYNOS5_GPIO_F0_NR
,
2638 .base
= EXYNOS5_GPF1(0),
2639 .ngpio
= EXYNOS5_GPIO_F1_NR
,
2644 .base
= EXYNOS5_GPG0(0),
2645 .ngpio
= EXYNOS5_GPIO_G0_NR
,
2650 .base
= EXYNOS5_GPG1(0),
2651 .ngpio
= EXYNOS5_GPIO_G1_NR
,
2656 .base
= EXYNOS5_GPG2(0),
2657 .ngpio
= EXYNOS5_GPIO_G2_NR
,
2662 .base
= EXYNOS5_GPH0(0),
2663 .ngpio
= EXYNOS5_GPIO_H0_NR
,
2668 .base
= EXYNOS5_GPH1(0),
2669 .ngpio
= EXYNOS5_GPIO_H1_NR
,
2677 #ifdef CONFIG_SOC_EXYNOS5250
2678 static struct samsung_gpio_chip exynos5_gpios_3
[] = {
2681 .base
= EXYNOS5_GPV0(0),
2682 .ngpio
= EXYNOS5_GPIO_V0_NR
,
2687 .base
= EXYNOS5_GPV1(0),
2688 .ngpio
= EXYNOS5_GPIO_V1_NR
,
2693 .base
= EXYNOS5_GPV2(0),
2694 .ngpio
= EXYNOS5_GPIO_V2_NR
,
2699 .base
= EXYNOS5_GPV3(0),
2700 .ngpio
= EXYNOS5_GPIO_V3_NR
,
2705 .base
= EXYNOS5_GPV4(0),
2706 .ngpio
= EXYNOS5_GPIO_V4_NR
,
2713 #ifdef CONFIG_SOC_EXYNOS5250
2714 static struct samsung_gpio_chip exynos5_gpios_4
[] = {
2717 .base
= EXYNOS5_GPZ(0),
2718 .ngpio
= EXYNOS5_GPIO_Z_NR
,
2726 #if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF)
2727 static int exynos_gpio_xlate(struct gpio_chip
*gc
,
2728 const struct of_phandle_args
*gpiospec
, u32
*flags
)
2732 if (WARN_ON(gc
->of_gpio_n_cells
< 4))
2735 if (WARN_ON(gpiospec
->args_count
< gc
->of_gpio_n_cells
))
2738 if (gpiospec
->args
[0] > gc
->ngpio
)
2741 pin
= gc
->base
+ gpiospec
->args
[0];
2743 if (s3c_gpio_cfgpin(pin
, S3C_GPIO_SFN(gpiospec
->args
[1])))
2744 pr_warn("gpio_xlate: failed to set pin function\n");
2745 if (s3c_gpio_setpull(pin
, gpiospec
->args
[2] & 0xffff))
2746 pr_warn("gpio_xlate: failed to set pin pull up/down\n");
2747 if (s5p_gpio_set_drvstr(pin
, gpiospec
->args
[3]))
2748 pr_warn("gpio_xlate: failed to set pin drive strength\n");
2751 *flags
= gpiospec
->args
[2] >> 16;
2753 return gpiospec
->args
[0];
2756 static const struct of_device_id exynos_gpio_dt_match
[] __initdata
= {
2757 { .compatible
= "samsung,exynos4-gpio", },
2761 static __init
void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip
*chip
,
2762 u64 base
, u64 offset
)
2764 struct gpio_chip
*gc
= &chip
->chip
;
2767 if (!of_have_populated_dt())
2770 address
= chip
->base
? base
+ ((u32
)chip
->base
& 0xfff) : base
+ offset
;
2771 gc
->of_node
= of_find_matching_node_by_address(NULL
,
2772 exynos_gpio_dt_match
, address
);
2774 pr_info("gpio: device tree node not found for gpio controller"
2775 " with base address %08llx\n", address
);
2778 gc
->of_gpio_n_cells
= 4;
2779 gc
->of_xlate
= exynos_gpio_xlate
;
2781 #elif defined(CONFIG_ARCH_EXYNOS)
2782 static __init
void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip
*chip
,
2783 u64 base
, u64 offset
)
2787 #endif /* defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF) */
2789 static __init
void exynos4_gpiolib_init(void)
2791 #ifdef CONFIG_CPU_EXYNOS4210
2792 struct samsung_gpio_chip
*chip
;
2794 void __iomem
*gpio_base1
, *gpio_base2
, *gpio_base3
;
2796 void __iomem
*gpx_base
;
2799 gpio_base1
= ioremap(EXYNOS4_PA_GPIO1
, SZ_4K
);
2800 if (gpio_base1
== NULL
) {
2801 pr_err("unable to ioremap for gpio_base1\n");
2805 chip
= exynos4_gpios_1
;
2806 nr_chips
= ARRAY_SIZE(exynos4_gpios_1
);
2808 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2809 if (!chip
->config
) {
2810 chip
->config
= &exynos_gpio_cfg
;
2811 chip
->group
= group
++;
2813 exynos_gpiolib_attach_ofnode(chip
,
2814 EXYNOS4_PA_GPIO1
, i
* 0x20);
2816 samsung_gpiolib_add_4bit_chips(exynos4_gpios_1
,
2817 nr_chips
, gpio_base1
);
2820 gpio_base2
= ioremap(EXYNOS4_PA_GPIO2
, SZ_4K
);
2821 if (gpio_base2
== NULL
) {
2822 pr_err("unable to ioremap for gpio_base2\n");
2826 /* need to set base address for gpx */
2827 chip
= &exynos4_gpios_2
[16];
2828 gpx_base
= gpio_base2
+ 0xC00;
2829 for (i
= 0; i
< 4; i
++, chip
++, gpx_base
+= 0x20)
2830 chip
->base
= gpx_base
;
2832 chip
= exynos4_gpios_2
;
2833 nr_chips
= ARRAY_SIZE(exynos4_gpios_2
);
2835 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2836 if (!chip
->config
) {
2837 chip
->config
= &exynos_gpio_cfg
;
2838 chip
->group
= group
++;
2840 exynos_gpiolib_attach_ofnode(chip
,
2841 EXYNOS4_PA_GPIO2
, i
* 0x20);
2843 samsung_gpiolib_add_4bit_chips(exynos4_gpios_2
,
2844 nr_chips
, gpio_base2
);
2847 gpio_base3
= ioremap(EXYNOS4_PA_GPIO3
, SZ_256
);
2848 if (gpio_base3
== NULL
) {
2849 pr_err("unable to ioremap for gpio_base3\n");
2853 chip
= exynos4_gpios_3
;
2854 nr_chips
= ARRAY_SIZE(exynos4_gpios_3
);
2856 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2857 if (!chip
->config
) {
2858 chip
->config
= &exynos_gpio_cfg
;
2859 chip
->group
= group
++;
2861 exynos_gpiolib_attach_ofnode(chip
,
2862 EXYNOS4_PA_GPIO3
, i
* 0x20);
2864 samsung_gpiolib_add_4bit_chips(exynos4_gpios_3
,
2865 nr_chips
, gpio_base3
);
2867 #if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT)
2868 s5p_register_gpioint_bank(IRQ_GPIO_XA
, 0, IRQ_GPIO1_NR_GROUPS
);
2869 s5p_register_gpioint_bank(IRQ_GPIO_XB
, IRQ_GPIO1_NR_GROUPS
, IRQ_GPIO2_NR_GROUPS
);
2875 iounmap(gpio_base2
);
2877 iounmap(gpio_base1
);
2880 #endif /* CONFIG_CPU_EXYNOS4210 */
2883 static __init
void exynos5_gpiolib_init(void)
2885 #ifdef CONFIG_SOC_EXYNOS5250
2886 struct samsung_gpio_chip
*chip
;
2888 void __iomem
*gpio_base1
, *gpio_base2
, *gpio_base3
, *gpio_base4
;
2890 void __iomem
*gpx_base
;
2893 gpio_base1
= ioremap(EXYNOS5_PA_GPIO1
, SZ_4K
);
2894 if (gpio_base1
== NULL
) {
2895 pr_err("unable to ioremap for gpio_base1\n");
2899 /* need to set base address for gpc4 */
2900 exynos5_gpios_1
[20].base
= gpio_base1
+ 0x2E0;
2902 /* need to set base address for gpx */
2903 chip
= &exynos5_gpios_1
[21];
2904 gpx_base
= gpio_base1
+ 0xC00;
2905 for (i
= 0; i
< 4; i
++, chip
++, gpx_base
+= 0x20)
2906 chip
->base
= gpx_base
;
2908 chip
= exynos5_gpios_1
;
2909 nr_chips
= ARRAY_SIZE(exynos5_gpios_1
);
2911 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2912 if (!chip
->config
) {
2913 chip
->config
= &exynos_gpio_cfg
;
2914 chip
->group
= group
++;
2916 exynos_gpiolib_attach_ofnode(chip
,
2917 EXYNOS5_PA_GPIO1
, i
* 0x20);
2919 samsung_gpiolib_add_4bit_chips(exynos5_gpios_1
,
2920 nr_chips
, gpio_base1
);
2923 gpio_base2
= ioremap(EXYNOS5_PA_GPIO2
, SZ_4K
);
2924 if (gpio_base2
== NULL
) {
2925 pr_err("unable to ioremap for gpio_base2\n");
2929 chip
= exynos5_gpios_2
;
2930 nr_chips
= ARRAY_SIZE(exynos5_gpios_2
);
2932 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2933 if (!chip
->config
) {
2934 chip
->config
= &exynos_gpio_cfg
;
2935 chip
->group
= group
++;
2937 exynos_gpiolib_attach_ofnode(chip
,
2938 EXYNOS5_PA_GPIO2
, i
* 0x20);
2940 samsung_gpiolib_add_4bit_chips(exynos5_gpios_2
,
2941 nr_chips
, gpio_base2
);
2944 gpio_base3
= ioremap(EXYNOS5_PA_GPIO3
, SZ_4K
);
2945 if (gpio_base3
== NULL
) {
2946 pr_err("unable to ioremap for gpio_base3\n");
2950 /* need to set base address for gpv */
2951 exynos5_gpios_3
[0].base
= gpio_base3
;
2952 exynos5_gpios_3
[1].base
= gpio_base3
+ 0x20;
2953 exynos5_gpios_3
[2].base
= gpio_base3
+ 0x60;
2954 exynos5_gpios_3
[3].base
= gpio_base3
+ 0x80;
2955 exynos5_gpios_3
[4].base
= gpio_base3
+ 0xC0;
2957 chip
= exynos5_gpios_3
;
2958 nr_chips
= ARRAY_SIZE(exynos5_gpios_3
);
2960 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2961 if (!chip
->config
) {
2962 chip
->config
= &exynos_gpio_cfg
;
2963 chip
->group
= group
++;
2965 exynos_gpiolib_attach_ofnode(chip
,
2966 EXYNOS5_PA_GPIO3
, i
* 0x20);
2968 samsung_gpiolib_add_4bit_chips(exynos5_gpios_3
,
2969 nr_chips
, gpio_base3
);
2972 gpio_base4
= ioremap(EXYNOS5_PA_GPIO4
, SZ_4K
);
2973 if (gpio_base4
== NULL
) {
2974 pr_err("unable to ioremap for gpio_base4\n");
2978 chip
= exynos5_gpios_4
;
2979 nr_chips
= ARRAY_SIZE(exynos5_gpios_4
);
2981 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
2982 if (!chip
->config
) {
2983 chip
->config
= &exynos_gpio_cfg
;
2984 chip
->group
= group
++;
2986 exynos_gpiolib_attach_ofnode(chip
,
2987 EXYNOS5_PA_GPIO4
, i
* 0x20);
2989 samsung_gpiolib_add_4bit_chips(exynos5_gpios_4
,
2990 nr_chips
, gpio_base4
);
2994 iounmap(gpio_base3
);
2996 iounmap(gpio_base2
);
2998 iounmap(gpio_base1
);
3002 #endif /* CONFIG_SOC_EXYNOS5250 */
3005 /* TODO: cleanup soc_is_* */
3006 static __init
int samsung_gpiolib_init(void)
3008 struct samsung_gpio_chip
*chip
;
3012 #if defined(CONFIG_PINCTRL_EXYNOS) || defined(CONFIG_PINCTRL_EXYNOS5440)
3014 * This gpio driver includes support for device tree support and there
3015 * are platforms using it. In order to maintain compatibility with those
3016 * platforms, and to allow non-dt Exynos4210 platforms to use this
3017 * gpiolib support, a check is added to find out if there is a active
3018 * pin-controller driver support available. If it is available, this
3019 * gpiolib support is ignored and the gpiolib support available in
3020 * pin-controller driver is used. This is a temporary check and will go
3021 * away when all of the Exynos4210 platforms have switched to using
3022 * device tree and the pin-ctrl driver.
3024 struct device_node
*pctrl_np
;
3025 static const struct of_device_id exynos_pinctrl_ids
[] = {
3026 { .compatible
= "samsung,pinctrl-exynos4210", },
3027 { .compatible
= "samsung,pinctrl-exynos4x12", },
3028 { .compatible
= "samsung,pinctrl-exynos5440", },
3030 for_each_matching_node(pctrl_np
, exynos_pinctrl_ids
)
3031 if (pctrl_np
&& of_device_is_available(pctrl_np
))
3035 samsung_gpiolib_set_cfg(samsung_gpio_cfgs
, ARRAY_SIZE(samsung_gpio_cfgs
));
3037 if (soc_is_s3c24xx()) {
3038 s3c24xx_gpiolib_add_chips(s3c24xx_gpios
,
3039 ARRAY_SIZE(s3c24xx_gpios
), S3C24XX_VA_GPIO
);
3040 } else if (soc_is_s3c64xx()) {
3041 samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit
,
3042 ARRAY_SIZE(s3c64xx_gpios_2bit
),
3043 S3C64XX_VA_GPIO
+ 0xE0, 0x20);
3044 samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit
,
3045 ARRAY_SIZE(s3c64xx_gpios_4bit
),
3047 samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2
,
3048 ARRAY_SIZE(s3c64xx_gpios_4bit2
));
3049 } else if (soc_is_s5p6440()) {
3050 samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit
,
3051 ARRAY_SIZE(s5p6440_gpios_2bit
), NULL
, 0x0);
3052 samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit
,
3053 ARRAY_SIZE(s5p6440_gpios_4bit
), S5P_VA_GPIO
);
3054 samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2
,
3055 ARRAY_SIZE(s5p6440_gpios_4bit2
));
3056 s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank
,
3057 ARRAY_SIZE(s5p6440_gpios_rbank
));
3058 } else if (soc_is_s5p6450()) {
3059 samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit
,
3060 ARRAY_SIZE(s5p6450_gpios_2bit
), NULL
, 0x0);
3061 samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit
,
3062 ARRAY_SIZE(s5p6450_gpios_4bit
), S5P_VA_GPIO
);
3063 samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2
,
3064 ARRAY_SIZE(s5p6450_gpios_4bit2
));
3065 s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank
,
3066 ARRAY_SIZE(s5p6450_gpios_rbank
));
3067 } else if (soc_is_s5pc100()) {
3069 chip
= s5pc100_gpios_4bit
;
3070 nr_chips
= ARRAY_SIZE(s5pc100_gpios_4bit
);
3072 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
3073 if (!chip
->config
) {
3074 chip
->config
= &samsung_gpio_cfgs
[3];
3075 chip
->group
= group
++;
3078 samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit
, nr_chips
, S5P_VA_GPIO
);
3079 #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
3080 s5p_register_gpioint_bank(IRQ_GPIOINT
, 0, S5P_GPIOINT_GROUP_MAXNR
);
3082 } else if (soc_is_s5pv210()) {
3084 chip
= s5pv210_gpios_4bit
;
3085 nr_chips
= ARRAY_SIZE(s5pv210_gpios_4bit
);
3087 for (i
= 0; i
< nr_chips
; i
++, chip
++) {
3088 if (!chip
->config
) {
3089 chip
->config
= &samsung_gpio_cfgs
[3];
3090 chip
->group
= group
++;
3093 samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit
, nr_chips
, S5P_VA_GPIO
);
3094 #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
3095 s5p_register_gpioint_bank(IRQ_GPIOINT
, 0, S5P_GPIOINT_GROUP_MAXNR
);
3097 } else if (soc_is_exynos4210()) {
3098 exynos4_gpiolib_init();
3099 } else if (soc_is_exynos5250()) {
3100 exynos5_gpiolib_init();
3102 WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
3108 core_initcall(samsung_gpiolib_init
);
3110 int s3c_gpio_cfgpin(unsigned int pin
, unsigned int config
)
3112 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3113 unsigned long flags
;
3120 offset
= pin
- chip
->chip
.base
;
3122 samsung_gpio_lock(chip
, flags
);
3123 ret
= samsung_gpio_do_setcfg(chip
, offset
, config
);
3124 samsung_gpio_unlock(chip
, flags
);
3128 EXPORT_SYMBOL(s3c_gpio_cfgpin
);
3130 int s3c_gpio_cfgpin_range(unsigned int start
, unsigned int nr
,
3135 for (; nr
> 0; nr
--, start
++) {
3136 ret
= s3c_gpio_cfgpin(start
, cfg
);
3143 EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range
);
3145 int s3c_gpio_cfgall_range(unsigned int start
, unsigned int nr
,
3146 unsigned int cfg
, samsung_gpio_pull_t pull
)
3150 for (; nr
> 0; nr
--, start
++) {
3151 s3c_gpio_setpull(start
, pull
);
3152 ret
= s3c_gpio_cfgpin(start
, cfg
);
3159 EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range
);
3161 unsigned s3c_gpio_getcfg(unsigned int pin
)
3163 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3164 unsigned long flags
;
3169 offset
= pin
- chip
->chip
.base
;
3171 samsung_gpio_lock(chip
, flags
);
3172 ret
= samsung_gpio_do_getcfg(chip
, offset
);
3173 samsung_gpio_unlock(chip
, flags
);
3178 EXPORT_SYMBOL(s3c_gpio_getcfg
);
3180 int s3c_gpio_setpull(unsigned int pin
, samsung_gpio_pull_t pull
)
3182 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3183 unsigned long flags
;
3189 offset
= pin
- chip
->chip
.base
;
3191 samsung_gpio_lock(chip
, flags
);
3192 ret
= samsung_gpio_do_setpull(chip
, offset
, pull
);
3193 samsung_gpio_unlock(chip
, flags
);
3197 EXPORT_SYMBOL(s3c_gpio_setpull
);
3199 samsung_gpio_pull_t
s3c_gpio_getpull(unsigned int pin
)
3201 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3202 unsigned long flags
;
3207 offset
= pin
- chip
->chip
.base
;
3209 samsung_gpio_lock(chip
, flags
);
3210 pup
= samsung_gpio_do_getpull(chip
, offset
);
3211 samsung_gpio_unlock(chip
, flags
);
3214 return (__force samsung_gpio_pull_t
)pup
;
3216 EXPORT_SYMBOL(s3c_gpio_getpull
);
3218 #ifdef CONFIG_S5P_GPIO_DRVSTR
3219 s5p_gpio_drvstr_t
s5p_gpio_get_drvstr(unsigned int pin
)
3221 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3230 off
= pin
- chip
->chip
.base
;
3232 reg
= chip
->base
+ 0x0C;
3234 drvstr
= __raw_readl(reg
);
3235 drvstr
= drvstr
>> shift
;
3238 return (__force s5p_gpio_drvstr_t
)drvstr
;
3240 EXPORT_SYMBOL(s5p_gpio_get_drvstr
);
3242 int s5p_gpio_set_drvstr(unsigned int pin
, s5p_gpio_drvstr_t drvstr
)
3244 struct samsung_gpio_chip
*chip
= samsung_gpiolib_getchip(pin
);
3253 off
= pin
- chip
->chip
.base
;
3255 reg
= chip
->base
+ 0x0C;
3257 tmp
= __raw_readl(reg
);
3258 tmp
&= ~(0x3 << shift
);
3259 tmp
|= drvstr
<< shift
;
3261 __raw_writel(tmp
, reg
);
3265 EXPORT_SYMBOL(s5p_gpio_set_drvstr
);
3266 #endif /* CONFIG_S5P_GPIO_DRVSTR */
3268 #ifdef CONFIG_PLAT_S3C24XX
3269 unsigned int s3c2410_modify_misccr(unsigned int clear
, unsigned int change
)
3271 unsigned long flags
;
3272 unsigned long misccr
;
3274 local_irq_save(flags
);
3275 misccr
= __raw_readl(S3C24XX_MISCCR
);
3278 __raw_writel(misccr
, S3C24XX_MISCCR
);
3279 local_irq_restore(flags
);
3283 EXPORT_SYMBOL(s3c2410_modify_misccr
);