Full support for Ginger Console
[linux-ginger.git] / arch / arm / plat-s3c / gpio-config.c
blob456969b6fa0d6670a989d1d28d85b214d9d9bf1d
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>
18 #include <linux/io.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);
27 unsigned long flags;
28 int offset;
29 int ret;
31 if (!chip)
32 return -EINVAL;
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);
40 return ret;
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);
47 unsigned long flags;
48 int offset, ret;
50 if (!chip)
51 return -EINVAL;
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);
59 return ret;
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;
69 u32 con;
71 if (s3c_gpio_is_cfg_special(cfg)) {
72 cfg &= 0xf;
74 /* Map output to 0, and SFN2 to 1 */
75 cfg -= 1;
76 if (cfg > 1)
77 return -EINVAL;
79 cfg <<= shift;
82 con = __raw_readl(reg);
83 con &= ~(0x1 << shift);
84 con |= cfg;
85 __raw_writel(con, reg);
87 return 0;
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;
95 u32 con;
97 if (s3c_gpio_is_cfg_special(cfg)) {
98 cfg &= 0xf;
99 if (cfg > 3)
100 return -EINVAL;
102 cfg <<= shift;
105 con = __raw_readl(reg);
106 con &= ~(0x3 << shift);
107 con |= cfg;
108 __raw_writel(con, reg);
110 return 0;
112 #endif
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;
120 u32 con;
122 if (off < 8 && chip->chip.ngpio > 8)
123 reg -= 4;
125 if (s3c_gpio_is_cfg_special(cfg)) {
126 cfg &= 0xf;
127 cfg <<= shift;
130 con = __raw_readl(reg);
131 con &= ~(0xf << shift);
132 con |= cfg;
133 __raw_writel(con, reg);
135 return 0;
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;
144 int shift = off * 2;
145 u32 pup;
147 pup = __raw_readl(reg);
148 pup &= ~(3 << shift);
149 pup |= pull << shift;
150 __raw_writel(pup, reg);
152 return 0;
155 s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
156 unsigned int off)
158 void __iomem *reg = chip->base + 0x08;
159 int shift = off * 2;
160 u32 pup = __raw_readl(reg);
162 pup >>= shift;
163 pup &= 0x3;
164 return (__force s3c_gpio_pull_t)pup;
166 #endif