MERGE-master-patchset-edits
[linux-2.6/openmoko-kernel.git] / arch / arm / plat-s3c / gpio-config.c
blob7642b975a99897467ede259a664da3be02fb230e
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/gpio.h>
17 #include <linux/io.h>
19 #include <mach/gpio-core.h>
20 #include <plat/gpio-cfg.h>
21 #include <plat/gpio-cfg-helpers.h>
23 int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
25 struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
26 unsigned long flags;
27 int offset;
28 int ret;
30 if (!chip)
31 return -EINVAL;
33 offset = pin - chip->chip.base;
35 local_irq_save(flags);
36 ret = s3c_gpio_do_setcfg(chip, offset, config);
37 local_irq_restore(flags);
39 return ret;
42 int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull)
44 struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
45 unsigned long flags;
46 int offset, ret;
48 if (!chip)
49 return -EINVAL;
51 offset = pin - chip->chip.base;
53 local_irq_save(flags);
54 ret = s3c_gpio_do_setpull(chip, offset, pull);
55 local_irq_restore(flags);
57 return ret;
60 #ifdef CONFIG_S3C_GPIO_CFG_S3C24XX
61 int s3c_gpio_setcfg_s3c24xx_banka(struct s3c_gpio_chip *chip,
62 unsigned int off, unsigned int cfg)
64 void __iomem *reg = chip->base;
65 unsigned int shift = off;
66 u32 con;
68 if (s3c_gpio_is_cfg_special(cfg)) {
69 cfg &= 0xf;
71 /* Map output to 0, and SFN2 to 1 */
72 cfg -= 1;
73 if (cfg > 1)
74 return -EINVAL;
76 cfg <<= shift;
79 con = __raw_readl(reg);
80 con &= ~(0x1 << shift);
81 con |= cfg;
82 __raw_writel(con, reg);
84 return 0;
87 int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
88 unsigned int off, unsigned int cfg)
90 void __iomem *reg = chip->base;
91 unsigned int shift = off * 2;
92 u32 con;
94 if (s3c_gpio_is_cfg_special(cfg)) {
95 cfg &= 0xf;
96 if (cfg > 3)
97 return -EINVAL;
99 cfg <<= shift;
102 con = __raw_readl(reg);
103 con &= ~(0x3 << shift);
104 con |= cfg;
105 __raw_writel(con, reg);
107 return 0;
109 #endif
111 #ifdef CONFIG_S3C_GPIO_CFG_S3C64XX
112 int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
113 unsigned int off, unsigned int cfg)
115 void __iomem *reg = chip->base;
116 unsigned int shift = (off & 7) * 4;
117 u32 con;
119 if (off < 8 && chip->chip.ngpio >= 8)
120 reg -= 4;
122 if (s3c_gpio_is_cfg_special(cfg)) {
123 cfg &= 0xf;
124 cfg <<= shift;
127 con = __raw_readl(reg);
128 con &= ~(0xf << shift);
129 con |= cfg;
130 __raw_writel(con, reg);
132 return 0;
134 #endif /* CONFIG_S3C_GPIO_CFG_S3C64XX */
136 #ifdef CONFIG_S3C_GPIO_PULL_UPDOWN
137 int s3c_gpio_setpull_updown(struct s3c_gpio_chip *chip,
138 unsigned int off, s3c_gpio_pull_t pull)
140 void __iomem *reg = chip->base + 0x08;
141 int shift = off * 2;
142 u32 pup;
144 pup = __raw_readl(reg);
145 pup &= ~(3 << shift);
146 pup |= pull << shift;
147 __raw_writel(pup, reg);
149 return 0;
152 s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
153 unsigned int off)
155 void __iomem *reg = chip->base + 0x08;
156 int shift = off * 2;
157 u32 pup = __raw_readl(reg);
159 pup >>= shift;
160 pup &= 0x3;
161 return (__force s3c_gpio_pull_t)pup;
163 #endif