17 #include <linux/kernel.h>
23 #include <linux/module.h>
25 #include <linux/device.h>
28 #include <linux/slab.h>
33 #include <mach/hardware.h>
35 #include <mach/regs-clock.h>
36 #include <mach/regs-gpio.h>
46 #define gpio_dbg(x...) do { } while (0)
48 #define gpio_dbg(x...) printk(KERN_DEBUG x)
209 unsigned int off,
unsigned int cfg)
212 unsigned int shift = off * 2;
224 con &= ~(0x3 << shift);
272 unsigned int off,
unsigned int cfg)
275 unsigned int shift = (off & 7) * 4;
278 if (off < 8 && chip->chip.ngpio > 8)
287 con &= ~(0xf << shift);
310 unsigned int shift = (off & 7) * 4;
313 if (off < 8 && chip->chip.ngpio > 8)
324 #ifdef CONFIG_PLAT_S3C24XX
337 unsigned int off,
unsigned int cfg)
340 unsigned int shift = off;
355 con &= ~(0x1 << shift);
388 #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
390 unsigned int off,
unsigned int cfg)
403 shift = (off & 7) * 4;
407 shift = ((off + 1) & 7) * 4;
410 shift = ((off + 1) & 7) * 4;
420 con &= ~(0xf << shift);
431 for (; nr_chips > 0; nr_chips--, chipcfg++) {
433 chipcfg->
set_config = samsung_gpio_setcfg_4bit;
435 chipcfg->
get_config = samsung_gpio_getcfg_4bit;
444 .set_config = samsung_gpio_setcfg_2bit,
445 .get_config = samsung_gpio_getcfg_2bit,
448 #ifdef CONFIG_PLAT_S3C24XX
451 .get_config = s3c24xx_gpio_getcfg_abank,
455 #if defined(CONFIG_ARCH_EXYNOS4) || defined(CONFIG_ARCH_EXYNOS5)
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)
467 .set_config = s5p64x0_gpio_setcfg_rbank,
468 .get_config = samsung_gpio_getcfg_4bit,
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,
529 static int samsung_gpiolib_2bit_input(
struct gpio_chip *chip,
unsigned offset)
539 con &= ~(3 << (offset * 2));
547 static int samsung_gpiolib_2bit_output(
struct gpio_chip *chip,
565 con &= ~(3 << (offset * 2));
566 con |= 1 << (offset * 2);
591 static int samsung_gpiolib_4bit_input(
struct gpio_chip *chip,
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)
630 gpio_dbg(
"%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
657 static int samsung_gpiolib_4bit2_input(
struct gpio_chip *chip,
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)
687 unsigned con_offset =
offset;
709 gpio_dbg(
"%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
714 #ifdef CONFIG_PLAT_S3C24XX
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)
754 static int s5p64x0_gpiolib_rbank_input(
struct gpio_chip *chip,
790 static int s5p64x0_gpiolib_rbank_output(
struct gpio_chip *chip,
791 unsigned int offset,
int value)
799 unsigned con_offset =
offset;
801 switch (con_offset) {
837 static void samsung_gpiolib_set(
struct gpio_chip *chip,
838 unsigned offset,
int value)
856 static int samsung_gpiolib_get(
struct gpio_chip *chip,
unsigned offset)
880 #ifdef CONFIG_S3C_GPIO_TRACK
888 gpn = chip->
chip.base;
889 for (i = 0; i < chip->
chip.ngpio; i++, gpn++) {
891 s3c_gpios[gpn] =
chip;
908 struct gpio_chip *
gc = &chip->
chip;
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;
928 if (!chip->
pm->save || !chip->
pm->resume)
938 s3c_gpiolib_track(chip);
941 #if defined(CONFIG_PLAT_S3C24XX) && defined(CONFIG_OF)
942 static int s3c24xx_gpio_xlate(
struct gpio_chip *gc,
947 if (
WARN_ON(gc->of_gpio_n_cells < 3))
953 if (gpiospec->
args[0] > gc->ngpio)
956 pin = gc->base + gpiospec->
args[0];
959 pr_warn(
"gpio_xlate: failed to set pin function\n");
961 pr_warn(
"gpio_xlate: failed to set pin pull up/down\n");
964 *flags = gpiospec->
args[2] >> 16;
966 return gpiospec->
args[0];
970 { .compatible =
"samsung,s3c24xx-gpio", },
977 struct gpio_chip *gc = &chip->
chip;
980 if (!of_have_populated_dt())
983 address = chip->
base ? base + ((
u32)chip->
base & 0xfff) : base + offset;
985 s3c24xx_gpio_dt_match, address);
987 pr_info(
"gpio: device tree node not found for gpio controller"
988 " with base address %08llx\n", address);
991 gc->of_gpio_n_cells = 3;
992 gc->of_xlate = s3c24xx_gpio_xlate;
1003 int nr_chips,
void __iomem *base)
1006 struct gpio_chip *gc = &chip->
chip;
1008 for (i = 0 ; i < nr_chips; i++, chip++) {
1018 chip->
base = base + ((
i) * 0x10);
1020 if (!gc->direction_input)
1021 gc->direction_input = samsung_gpiolib_2bit_input;
1022 if (!gc->direction_output)
1023 gc->direction_output = samsung_gpiolib_2bit_output;
1025 samsung_gpiolib_add(chip);
1032 int nr_chips,
void __iomem *base,
1033 unsigned int offset)
1037 for (i = 0 ; i < nr_chips; i++, chip++) {
1038 chip->
chip.direction_input = samsung_gpiolib_2bit_input;
1039 chip->
chip.direction_output = samsung_gpiolib_2bit_output;
1042 chip->
config = &samsung_gpio_cfgs[7];
1046 chip->
base = base + ((
i) * offset);
1048 samsung_gpiolib_add(chip);
1069 int nr_chips,
void __iomem *base)
1073 for (i = 0 ; i < nr_chips; i++, chip++) {
1074 chip->
chip.direction_input = samsung_gpiolib_4bit_input;
1075 chip->
chip.direction_output = samsung_gpiolib_4bit_output;
1078 chip->
config = &samsung_gpio_cfgs[2];
1082 chip->
base = base + ((
i) * 0x20);
1084 samsung_gpiolib_add(chip);
1091 for (; nr_chips > 0; nr_chips--, chip++) {
1092 chip->
chip.direction_input = samsung_gpiolib_4bit2_input;
1093 chip->
chip.direction_output = samsung_gpiolib_4bit2_output;
1096 chip->
config = &samsung_gpio_cfgs[2];
1100 samsung_gpiolib_add(chip);
1107 for (; nr_chips > 0; nr_chips--, chip++) {
1108 chip->
chip.direction_input = s5p64x0_gpiolib_rbank_input;
1109 chip->
chip.direction_output = s5p64x0_gpiolib_rbank_output;
1114 samsung_gpiolib_add(chip);
1125 #ifdef CONFIG_PLAT_S3C24XX
1126 static int s3c24xx_gpiolib_fbank_to_irq(
struct gpio_chip *chip,
unsigned offset)
1138 #ifdef CONFIG_PLAT_S3C64XX
1139 static int s3c64xx_gpiolib_mbank_to_irq(
struct gpio_chip *chip,
unsigned pin)
1144 static int s3c64xx_gpiolib_lbank_to_irq(
struct gpio_chip *chip,
unsigned pin)
1151 #ifdef CONFIG_PLAT_S3C24XX
1153 .config = &s3c24xx_gpiocfg_banka,
1159 .direction_input = s3c24xx_gpiolib_banka_input,
1160 .direction_output = s3c24xx_gpiolib_banka_output,
1196 .to_irq = s3c24xx_gpiolib_fbank_to_irq,
1279 #ifdef CONFIG_PLAT_S3C64XX
1305 .config = &samsung_gpio_cfgs[0],
1320 .config = &samsung_gpio_cfgs[1],
1325 .to_irq = s3c64xx_gpiolib_mbank_to_irq,
1332 #ifdef CONFIG_PLAT_S3C64XX
1342 .config = &samsung_gpio_cfgs[0],
1350 .config = &samsung_gpio_cfgs[1],
1355 .to_irq = s3c64xx_gpiolib_lbank_to_irq,
1362 #ifdef CONFIG_PLAT_S3C64XX
1365 .config = &samsung_gpio_cfgs[6],
1372 .config = &samsung_gpio_cfgs[7],
1379 .config = &samsung_gpio_cfgs[7],
1386 .config = &samsung_gpio_cfgs[6],
1393 .config = &samsung_gpio_cfgs[6],
1400 .config = &samsung_gpio_cfgs[6],
1409 .config = &samsung_gpio_cfgs[5],
1438 #ifdef CONFIG_CPU_S5P6440
1469 #ifdef CONFIG_CPU_S5P6440
1482 #ifdef CONFIG_CPU_S5P6440
1485 .config = &s5p64x0_gpio_cfg_rbank,
1496 #ifdef CONFIG_CPU_S5P6440
1499 .config = &samsung_gpio_cfgs[6],
1507 .config = &samsung_gpio_cfgs[4],
1515 .config = &samsung_gpio_cfgs[4],
1523 .config = &samsung_gpio_cfgs[5],
1531 .config = &samsung_gpio_cfgs[6],
1566 #ifdef CONFIG_CPU_S5P6450
1603 #ifdef CONFIG_CPU_S5P6450
1623 #ifdef CONFIG_CPU_S5P6450
1626 .config = &s5p64x0_gpio_cfg_rbank,
1637 #ifdef CONFIG_CPU_S5P6450
1640 .config = &samsung_gpio_cfgs[6],
1648 .config = &samsung_gpio_cfgs[4],
1656 .config = &samsung_gpio_cfgs[4],
1664 .config = &samsung_gpio_cfgs[5],
1672 .config = &samsung_gpio_cfgs[6],
1680 .config = &samsung_gpio_cfgs[5],
1688 .config = &samsung_gpio_cfgs[6],
1738 #ifdef CONFIG_CPU_S5PC100
1971 #ifdef CONFIG_CPU_S5PV210
2191 #ifdef CONFIG_ARCH_EXYNOS4
2293 #ifdef CONFIG_ARCH_EXYNOS4
2350 .config = &samsung_gpio_cfgs[8],
2357 .config = &samsung_gpio_cfgs[8],
2364 .config = &samsung_gpio_cfgs[8],
2371 .config = &samsung_gpio_cfgs[8],
2378 .config = &samsung_gpio_cfgs[8],
2385 .config = &samsung_gpio_cfgs[8],
2392 .config = &samsung_gpio_cfgs[8],
2399 .config = &samsung_gpio_cfgs[9],
2408 .config = &samsung_gpio_cfgs[9],
2417 .config = &samsung_gpio_cfgs[9],
2426 .config = &samsung_gpio_cfgs[9],
2438 #ifdef CONFIG_ARCH_EXYNOS4
2450 #ifdef CONFIG_ARCH_EXYNOS5
2579 .config = &samsung_gpio_cfgs[9],
2588 .config = &samsung_gpio_cfgs[9],
2597 .config = &samsung_gpio_cfgs[9],
2606 .config = &samsung_gpio_cfgs[9],
2618 #ifdef CONFIG_ARCH_EXYNOS5
2679 #ifdef CONFIG_ARCH_EXYNOS5
2715 #ifdef CONFIG_ARCH_EXYNOS5
2728 #if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF)
2729 static int exynos_gpio_xlate(
struct gpio_chip *gc,
2734 if (
WARN_ON(gc->of_gpio_n_cells < 4))
2740 if (gpiospec->
args[0] > gc->ngpio)
2743 pin = gc->base + gpiospec->
args[0];
2746 pr_warn(
"gpio_xlate: failed to set pin function\n");
2748 pr_warn(
"gpio_xlate: failed to set pin pull up/down\n");
2750 pr_warn(
"gpio_xlate: failed to set pin drive strength\n");
2753 *flags = gpiospec->
args[2] >> 16;
2755 return gpiospec->
args[0];
2758 static const struct of_device_id exynos_gpio_dt_match[] __initdata = {
2766 struct gpio_chip *gc = &chip->
chip;
2769 if (!of_have_populated_dt())
2772 address = chip->
base ? base + ((
u32)chip->
base & 0xfff) : base + offset;
2774 exynos_gpio_dt_match, address);
2776 pr_info(
"gpio: device tree node not found for gpio controller"
2777 " with base address %08llx\n", address);
2780 gc->of_gpio_n_cells = 4;
2781 gc->of_xlate = exynos_gpio_xlate;
2783 #elif defined(CONFIG_ARCH_EXYNOS)
2791 static __init void exynos4_gpiolib_init(
void)
2793 #ifdef CONFIG_CPU_EXYNOS4210
2796 void __iomem *gpio_base1, *gpio_base2, *gpio_base3;
2800 #ifdef CONFIG_PINCTRL_SAMSUNG
2814 const char *pctrl_compat =
"samsung,pinctrl-exynos4210";
2823 if (gpio_base1 ==
NULL) {
2824 pr_err(
"unable to ioremap for gpio_base1\n");
2828 chip = exynos4_gpios_1;
2831 for (i = 0; i < nr_chips; i++, chip++) {
2833 chip->
config = &exynos_gpio_cfg;
2834 chip->
group = group++;
2836 exynos_gpiolib_attach_ofnode(chip,
2839 samsung_gpiolib_add_4bit_chips(exynos4_gpios_1,
2840 nr_chips, gpio_base1);
2844 if (gpio_base2 ==
NULL) {
2845 pr_err(
"unable to ioremap for gpio_base2\n");
2850 chip = &exynos4_gpios_2[16];
2851 gpx_base = gpio_base2 + 0xC00;
2852 for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
2853 chip->
base = gpx_base;
2855 chip = exynos4_gpios_2;
2858 for (i = 0; i < nr_chips; i++, chip++) {
2859 if (!chip->config) {
2860 chip->config = &exynos_gpio_cfg;
2861 chip->group = group++;
2863 exynos_gpiolib_attach_ofnode(chip,
2866 samsung_gpiolib_add_4bit_chips(exynos4_gpios_2,
2867 nr_chips, gpio_base2);
2871 if (gpio_base3 ==
NULL) {
2872 pr_err(
"unable to ioremap for gpio_base3\n");
2876 chip = exynos4_gpios_3;
2879 for (i = 0; i < nr_chips; i++, chip++) {
2880 if (!chip->config) {
2881 chip->config = &exynos_gpio_cfg;
2882 chip->group = group++;
2884 exynos_gpiolib_attach_ofnode(chip,
2887 samsung_gpiolib_add_4bit_chips(exynos4_gpios_3,
2888 nr_chips, gpio_base3);
2890 #if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT)
2906 static __init void exynos5_gpiolib_init(
void)
2908 #ifdef CONFIG_SOC_EXYNOS5250
2911 void __iomem *gpio_base1, *gpio_base2, *gpio_base3, *gpio_base4;
2917 if (gpio_base1 ==
NULL) {
2918 pr_err(
"unable to ioremap for gpio_base1\n");
2923 exynos5_gpios_1[20].
base = gpio_base1 + 0x2E0;
2926 chip = &exynos5_gpios_1[21];
2927 gpx_base = gpio_base1 + 0xC00;
2928 for (i = 0; i < 4; i++, chip++, gpx_base += 0x20)
2929 chip->
base = gpx_base;
2931 chip = exynos5_gpios_1;
2934 for (i = 0; i < nr_chips; i++, chip++) {
2935 if (!chip->config) {
2936 chip->config = &exynos_gpio_cfg;
2937 chip->group = group++;
2939 exynos_gpiolib_attach_ofnode(chip,
2942 samsung_gpiolib_add_4bit_chips(exynos5_gpios_1,
2943 nr_chips, gpio_base1);
2947 if (gpio_base2 ==
NULL) {
2948 pr_err(
"unable to ioremap for gpio_base2\n");
2952 chip = exynos5_gpios_2;
2955 for (i = 0; i < nr_chips; i++, chip++) {
2956 if (!chip->config) {
2957 chip->config = &exynos_gpio_cfg;
2958 chip->group = group++;
2960 exynos_gpiolib_attach_ofnode(chip,
2963 samsung_gpiolib_add_4bit_chips(exynos5_gpios_2,
2964 nr_chips, gpio_base2);
2968 if (gpio_base3 ==
NULL) {
2969 pr_err(
"unable to ioremap for gpio_base3\n");
2974 exynos5_gpios_3[0].
base = gpio_base3;
2975 exynos5_gpios_3[1].
base = gpio_base3 + 0x20;
2976 exynos5_gpios_3[2].
base = gpio_base3 + 0x60;
2977 exynos5_gpios_3[3].
base = gpio_base3 + 0x80;
2978 exynos5_gpios_3[4].
base = gpio_base3 + 0xC0;
2980 chip = exynos5_gpios_3;
2983 for (i = 0; i < nr_chips; i++, chip++) {
2984 if (!chip->config) {
2985 chip->config = &exynos_gpio_cfg;
2986 chip->group = group++;
2988 exynos_gpiolib_attach_ofnode(chip,
2991 samsung_gpiolib_add_4bit_chips(exynos5_gpios_3,
2992 nr_chips, gpio_base3);
2996 if (gpio_base4 ==
NULL) {
2997 pr_err(
"unable to ioremap for gpio_base4\n");
3001 chip = exynos5_gpios_4;
3004 for (i = 0; i < nr_chips; i++, chip++) {
3005 if (!chip->config) {
3006 chip->config = &exynos_gpio_cfg;
3007 chip->group = group++;
3009 exynos_gpiolib_attach_ofnode(chip,
3012 samsung_gpiolib_add_4bit_chips(exynos5_gpios_4,
3013 nr_chips, gpio_base4);
3029 static __init int samsung_gpiolib_init(
void)
3035 samsung_gpiolib_set_cfg(samsung_gpio_cfgs,
ARRAY_SIZE(samsung_gpio_cfgs));
3038 s3c24xx_gpiolib_add_chips(s3c24xx_gpios,
3041 samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit,
3044 samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit,
3047 samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
3050 samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit,
3052 samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit,
3054 samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2,
3056 s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank,
3059 samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit,
3061 samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit,
3063 samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2,
3065 s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank,
3069 chip = s5pc100_gpios_4bit;
3072 for (i = 0; i < nr_chips; i++, chip++) {
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)
3084 chip = s5pv210_gpios_4bit;
3087 for (i = 0; i < nr_chips; i++, chip++) {
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)
3098 exynos4_gpiolib_init();
3100 exynos5_gpiolib_init();
3102 WARN(1,
"Unknown SoC in gpio-samsung, no GPIOs added\n");
3113 unsigned long flags;
3120 offset = pin - chip->
chip.base;
3123 ret = samsung_gpio_do_setcfg(chip, offset, config);
3135 for (; nr > 0; nr--, start++) {
3150 for (; nr > 0; nr--, start++) {
3164 unsigned long flags;
3169 offset = pin - chip->
chip.base;
3172 ret = samsung_gpio_do_getcfg(chip, offset);
3183 unsigned long flags;
3189 offset = pin - chip->
chip.base;
3192 ret = samsung_gpio_do_setpull(chip, offset, pull);
3202 unsigned long flags;
3207 offset = pin - chip->
chip.base;
3210 pup = samsung_gpio_do_getpull(chip, offset);
3218 #ifdef CONFIG_S5P_GPIO_DRVSTR
3230 off = pin - chip->
chip.base;
3232 reg = chip->
base + 0x0C;
3235 drvstr = drvstr >> shift;
3253 off = pin - chip->
chip.base;
3255 reg = chip->
base + 0x0C;
3258 tmp &= ~(0x3 << shift);
3259 tmp |= drvstr << shift;
3268 #ifdef CONFIG_PLAT_S3C24XX
3271 unsigned long flags;
3272 unsigned long misccr;