1 /* linux/arch/arm/plat-s3c/gpio-config.c
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
8 * S3C series GPIO configuration core
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/gpio.h>
20 #include <mach/gpio-core.h>
21 #include <plat/gpio-cfg.h>
22 #include <plat/gpio-cfg-helpers.h>
24 int s3c_gpio_cfgpin(unsigned int pin
, unsigned int config
)
26 struct s3c_gpio_chip
*chip
= s3c_gpiolib_getchip(pin
);
34 offset
= pin
- chip
->chip
.base
;
36 local_irq_save(flags
);
37 ret
= s3c_gpio_do_setcfg(chip
, offset
, config
);
38 local_irq_restore(flags
);
42 EXPORT_SYMBOL(s3c_gpio_cfgpin
);
44 int s3c_gpio_setpull(unsigned int pin
, s3c_gpio_pull_t pull
)
46 struct s3c_gpio_chip
*chip
= s3c_gpiolib_getchip(pin
);
53 offset
= pin
- chip
->chip
.base
;
55 local_irq_save(flags
);
56 ret
= s3c_gpio_do_setpull(chip
, offset
, pull
);
57 local_irq_restore(flags
);
61 EXPORT_SYMBOL(s3c_gpio_setpull
);
63 #ifdef CONFIG_S3C_GPIO_CFG_S3C24XX
64 int s3c_gpio_setcfg_s3c24xx_banka(struct s3c_gpio_chip
*chip
,
65 unsigned int off
, unsigned int cfg
)
67 void __iomem
*reg
= chip
->base
;
68 unsigned int shift
= off
;
71 if (s3c_gpio_is_cfg_special(cfg
)) {
74 /* Map output to 0, and SFN2 to 1 */
82 con
= __raw_readl(reg
);
83 con
&= ~(0x1 << shift
);
85 __raw_writel(con
, reg
);
90 int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip
*chip
,
91 unsigned int off
, unsigned int cfg
)
93 void __iomem
*reg
= chip
->base
;
94 unsigned int shift
= off
* 2;
97 if (s3c_gpio_is_cfg_special(cfg
)) {
105 con
= __raw_readl(reg
);
106 con
&= ~(0x3 << shift
);
108 __raw_writel(con
, reg
);
114 #ifdef CONFIG_S3C_GPIO_CFG_S3C64XX
115 int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip
*chip
,
116 unsigned int off
, unsigned int cfg
)
118 void __iomem
*reg
= chip
->base
;
119 unsigned int shift
= (off
& 7) * 4;
122 if (off
< 8 && chip
->chip
.ngpio
>= 8)
125 if (s3c_gpio_is_cfg_special(cfg
)) {
130 con
= __raw_readl(reg
);
131 con
&= ~(0xf << shift
);
133 __raw_writel(con
, reg
);
137 #endif /* CONFIG_S3C_GPIO_CFG_S3C64XX */
139 #ifdef CONFIG_S3C_GPIO_PULL_UPDOWN
140 int s3c_gpio_setpull_updown(struct s3c_gpio_chip
*chip
,
141 unsigned int off
, s3c_gpio_pull_t pull
)
143 void __iomem
*reg
= chip
->base
+ 0x08;
147 pup
= __raw_readl(reg
);
148 pup
&= ~(3 << shift
);
149 pup
|= pull
<< shift
;
150 __raw_writel(pup
, reg
);
155 s3c_gpio_pull_t
s3c_gpio_getpull_updown(struct s3c_gpio_chip
*chip
,
158 void __iomem
*reg
= chip
->base
+ 0x08;
160 u32 pup
= __raw_readl(reg
);
164 return (__force s3c_gpio_pull_t
)pup
;