1 /* linux/arch/arm/plat-s3c24xx/gpio.c
3 * Copyright (c) 2004-2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/kernel.h>
25 #include <linux/init.h>
26 #include <linux/module.h>
27 #include <linux/interrupt.h>
28 #include <linux/ioport.h>
31 #include <mach/hardware.h>
32 #include <mach/gpio-fns.h>
35 #include <mach/regs-gpio.h>
37 void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function)
39 void __iomem *base = S3C24XX_GPIO_BASE(pin);
44 if (pin < S3C2410_GPIO_BANKB) {
45 mask = 1 << S3C2410_GPIO_OFFSET(pin);
47 mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;
51 case S3C2410_GPIO_LEAVE:
56 case S3C2410_GPIO_INPUT:
57 case S3C2410_GPIO_OUTPUT:
58 case S3C2410_GPIO_SFN2:
59 case S3C2410_GPIO_SFN3:
60 if (pin < S3C2410_GPIO_BANKB) {
63 function <<= S3C2410_GPIO_OFFSET(pin);
66 function <<= S3C2410_GPIO_OFFSET(pin)*2;
70 /* modify the specified register wwith IRQs off */
72 local_irq_save(flags);
74 con = __raw_readl(base + 0x00);
78 __raw_writel(con, base + 0x00);
80 local_irq_restore(flags);
83 EXPORT_SYMBOL(s3c2410_gpio_cfgpin);
85 unsigned int s3c2410_gpio_getcfg(unsigned int pin)
87 void __iomem *base = S3C24XX_GPIO_BASE(pin);
88 unsigned long val = __raw_readl(base);
90 if (pin < S3C2410_GPIO_BANKB) {
91 val >>= S3C2410_GPIO_OFFSET(pin);
95 val >>= S3C2410_GPIO_OFFSET(pin)*2;
99 return val | S3C2410_GPIO_INPUT;
102 EXPORT_SYMBOL(s3c2410_gpio_getcfg);
104 void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
106 void __iomem *base = S3C24XX_GPIO_BASE(pin);
107 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
111 if (pin < S3C2410_GPIO_BANKB)
114 local_irq_save(flags);
116 up = __raw_readl(base + 0x08);
119 __raw_writel(up, base + 0x08);
121 local_irq_restore(flags);
124 EXPORT_SYMBOL(s3c2410_gpio_pullup);
126 int s3c2410_gpio_getpull(unsigned int pin)
128 void __iomem *base = S3C24XX_GPIO_BASE(pin);
129 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
131 if (pin < S3C2410_GPIO_BANKB)
134 return (__raw_readl(base + 0x08) & (1L << offs)) ? 1 : 0;
137 EXPORT_SYMBOL(s3c2410_gpio_getpull);
139 void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
141 void __iomem *base = S3C24XX_GPIO_BASE(pin);
142 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
146 local_irq_save(flags);
148 dat = __raw_readl(base + 0x04);
151 __raw_writel(dat, base + 0x04);
153 local_irq_restore(flags);
156 EXPORT_SYMBOL(s3c2410_gpio_setpin);
158 unsigned int s3c2410_gpio_getpin(unsigned int pin)
160 void __iomem *base = S3C24XX_GPIO_BASE(pin);
161 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
163 return __raw_readl(base + 0x04) & (1<< offs);
166 EXPORT_SYMBOL(s3c2410_gpio_getpin);
168 unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
171 unsigned long misccr;
173 local_irq_save(flags);
174 misccr = __raw_readl(S3C24XX_MISCCR);
177 __raw_writel(misccr, S3C24XX_MISCCR);
178 local_irq_restore(flags);
183 EXPORT_SYMBOL(s3c2410_modify_misccr);
185 int s3c2410_gpio_getirq(unsigned int pin)
187 if (pin < S3C2410_GPF(0) || pin > S3C2410_GPG(15))
188 return -EINVAL; /* not valid interrupts */
190 if (pin < S3C2410_GPG(0) && pin > S3C2410_GPF(7))
191 return -EINVAL; /* not valid pin */
193 if (pin < S3C2410_GPF(4))
194 return (pin - S3C2410_GPF(0)) + IRQ_EINT0;
196 if (pin < S3C2410_GPG(0))
197 return (pin - S3C2410_GPF(4)) + IRQ_EINT4;
199 return (pin - S3C2410_GPG(0)) + IRQ_EINT8;
202 EXPORT_SYMBOL(s3c2410_gpio_getirq);