vmscan: tracing: add trace events for LRU page isolation
[linux-2.6/next.git] / arch / arm / plat-samsung / gpio-config.c
blob57b68a50f45e93aa14852500ace0df1fdc48da8b
1 /* linux/arch/arm/plat-s3c/gpio-config.c
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008-2010 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>
18 #include <linux/io.h>
20 #include <plat/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);
27 unsigned long flags;
28 int offset;
29 int ret;
31 if (!chip)
32 return -EINVAL;
34 offset = pin - chip->chip.base;
36 s3c_gpio_lock(chip, flags);
37 ret = s3c_gpio_do_setcfg(chip, offset, config);
38 s3c_gpio_unlock(chip, flags);
40 return ret;
42 EXPORT_SYMBOL(s3c_gpio_cfgpin);
44 unsigned s3c_gpio_getcfg(unsigned int pin)
46 struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
47 unsigned long flags;
48 unsigned ret = 0;
49 int offset;
51 if (chip) {
52 offset = pin - chip->chip.base;
54 s3c_gpio_lock(chip, flags);
55 ret = s3c_gpio_do_getcfg(chip, offset);
56 s3c_gpio_unlock(chip, flags);
59 return ret;
61 EXPORT_SYMBOL(s3c_gpio_getcfg);
64 int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull)
66 struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
67 unsigned long flags;
68 int offset, ret;
70 if (!chip)
71 return -EINVAL;
73 offset = pin - chip->chip.base;
75 s3c_gpio_lock(chip, flags);
76 ret = s3c_gpio_do_setpull(chip, offset, pull);
77 s3c_gpio_unlock(chip, flags);
79 return ret;
81 EXPORT_SYMBOL(s3c_gpio_setpull);
83 #ifdef CONFIG_S3C_GPIO_CFG_S3C24XX
84 int s3c_gpio_setcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
85 unsigned int off, unsigned int cfg)
87 void __iomem *reg = chip->base;
88 unsigned int shift = off;
89 u32 con;
91 if (s3c_gpio_is_cfg_special(cfg)) {
92 cfg &= 0xf;
94 /* Map output to 0, and SFN2 to 1 */
95 cfg -= 1;
96 if (cfg > 1)
97 return -EINVAL;
99 cfg <<= shift;
102 con = __raw_readl(reg);
103 con &= ~(0x1 << shift);
104 con |= cfg;
105 __raw_writel(con, reg);
107 return 0;
110 unsigned s3c_gpio_getcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
111 unsigned int off)
113 u32 con;
115 con = __raw_readl(chip->base);
116 con >>= off;
117 con &= 1;
118 con++;
120 return S3C_GPIO_SFN(con);
123 int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
124 unsigned int off, unsigned int cfg)
126 void __iomem *reg = chip->base;
127 unsigned int shift = off * 2;
128 u32 con;
130 if (s3c_gpio_is_cfg_special(cfg)) {
131 cfg &= 0xf;
132 if (cfg > 3)
133 return -EINVAL;
135 cfg <<= shift;
138 con = __raw_readl(reg);
139 con &= ~(0x3 << shift);
140 con |= cfg;
141 __raw_writel(con, reg);
143 return 0;
146 unsigned int s3c_gpio_getcfg_s3c24xx(struct s3c_gpio_chip *chip,
147 unsigned int off)
149 u32 con;
151 con = __raw_readl(chip->base);
152 con >>= off * 2;
153 con &= 3;
155 /* this conversion works for IN and OUT as well as special mode */
156 return S3C_GPIO_SPECIAL(con);
158 #endif
160 #ifdef CONFIG_S3C_GPIO_CFG_S3C64XX
161 int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
162 unsigned int off, unsigned int cfg)
164 void __iomem *reg = chip->base;
165 unsigned int shift = (off & 7) * 4;
166 u32 con;
168 if (off < 8 && chip->chip.ngpio > 8)
169 reg -= 4;
171 if (s3c_gpio_is_cfg_special(cfg)) {
172 cfg &= 0xf;
173 cfg <<= shift;
176 con = __raw_readl(reg);
177 con &= ~(0xf << shift);
178 con |= cfg;
179 __raw_writel(con, reg);
181 return 0;
184 unsigned s3c_gpio_getcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
185 unsigned int off)
187 void __iomem *reg = chip->base;
188 unsigned int shift = (off & 7) * 4;
189 u32 con;
191 if (off < 8 && chip->chip.ngpio > 8)
192 reg -= 4;
194 con = __raw_readl(reg);
195 con >>= shift;
196 con &= 0xf;
198 /* this conversion works for IN and OUT as well as special mode */
199 return S3C_GPIO_SPECIAL(con);
202 #endif /* CONFIG_S3C_GPIO_CFG_S3C64XX */
204 #ifdef CONFIG_S3C_GPIO_PULL_UPDOWN
205 int s3c_gpio_setpull_updown(struct s3c_gpio_chip *chip,
206 unsigned int off, s3c_gpio_pull_t pull)
208 void __iomem *reg = chip->base + 0x08;
209 int shift = off * 2;
210 u32 pup;
212 pup = __raw_readl(reg);
213 pup &= ~(3 << shift);
214 pup |= pull << shift;
215 __raw_writel(pup, reg);
217 return 0;
220 s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
221 unsigned int off)
223 void __iomem *reg = chip->base + 0x08;
224 int shift = off * 2;
225 u32 pup = __raw_readl(reg);
227 pup >>= shift;
228 pup &= 0x3;
229 return (__force s3c_gpio_pull_t)pup;
231 #endif
233 #ifdef CONFIG_S3C_GPIO_PULL_UP
234 int s3c_gpio_setpull_1up(struct s3c_gpio_chip *chip,
235 unsigned int off, s3c_gpio_pull_t pull)
237 void __iomem *reg = chip->base + 0x08;
238 u32 pup = __raw_readl(reg);
240 pup = __raw_readl(reg);
242 if (pup == S3C_GPIO_PULL_UP)
243 pup &= ~(1 << off);
244 else if (pup == S3C_GPIO_PULL_NONE)
245 pup |= (1 << off);
246 else
247 return -EINVAL;
249 __raw_writel(pup, reg);
250 return 0;
253 s3c_gpio_pull_t s3c_gpio_getpull_1up(struct s3c_gpio_chip *chip,
254 unsigned int off)
256 void __iomem *reg = chip->base + 0x08;
257 u32 pup = __raw_readl(reg);
259 pup &= (1 << off);
260 return pup ? S3C_GPIO_PULL_NONE : S3C_GPIO_PULL_UP;
262 #endif /* CONFIG_S3C_GPIO_PULL_UP */
264 #ifdef CONFIG_S5P_GPIO_DRVSTR
265 s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
267 struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
268 unsigned int off;
269 void __iomem *reg;
270 int shift;
271 u32 drvstr;
273 if (!chip)
274 return -EINVAL;
276 off = chip->chip.base - pin;
277 shift = off * 2;
278 reg = chip->base + 0x0C;
280 drvstr = __raw_readl(reg);
281 drvstr = 0xffff & (0x3 << shift);
282 drvstr = drvstr >> shift;
284 return (__force s5p_gpio_drvstr_t)drvstr;
286 EXPORT_SYMBOL(s5p_gpio_get_drvstr);
288 int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
290 struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
291 unsigned int off;
292 void __iomem *reg;
293 int shift;
294 u32 tmp;
296 if (!chip)
297 return -EINVAL;
299 off = chip->chip.base - pin;
300 shift = off * 2;
301 reg = chip->base + 0x0C;
303 tmp = __raw_readl(reg);
304 tmp |= drvstr << shift;
306 __raw_writel(tmp, reg);
308 return 0;
310 EXPORT_SYMBOL(s5p_gpio_set_drvstr);
311 #endif /* CONFIG_S5P_GPIO_DRVSTR */