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 unsigned int s3c2410_gpio_getcfg(unsigned int pin)
39 void __iomem *base = S3C24XX_GPIO_BASE(pin);
40 unsigned long val = __raw_readl(base);
42 if (pin < S3C2410_GPIO_BANKB) {
43 val >>= S3C2410_GPIO_OFFSET(pin);
47 val >>= S3C2410_GPIO_OFFSET(pin)*2;
51 return val | S3C2410_GPIO_INPUT;
54 EXPORT_SYMBOL(s3c2410_gpio_getcfg);
56 void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
58 void __iomem *base = S3C24XX_GPIO_BASE(pin);
59 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
63 if (pin < S3C2410_GPIO_BANKB)
66 local_irq_save(flags);
68 up = __raw_readl(base + 0x08);
71 __raw_writel(up, base + 0x08);
73 local_irq_restore(flags);
76 EXPORT_SYMBOL(s3c2410_gpio_pullup);
78 int s3c2410_gpio_getpull(unsigned int pin)
80 void __iomem *base = S3C24XX_GPIO_BASE(pin);
81 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
83 if (pin < S3C2410_GPIO_BANKB)
86 return (__raw_readl(base + 0x08) & (1L << offs)) ? 1 : 0;
89 EXPORT_SYMBOL(s3c2410_gpio_getpull);
91 void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
93 void __iomem *base = S3C24XX_GPIO_BASE(pin);
94 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
98 local_irq_save(flags);
100 dat = __raw_readl(base + 0x04);
103 __raw_writel(dat, base + 0x04);
105 local_irq_restore(flags);
108 EXPORT_SYMBOL(s3c2410_gpio_setpin);
110 unsigned int s3c2410_gpio_getpin(unsigned int pin)
112 void __iomem *base = S3C24XX_GPIO_BASE(pin);
113 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
115 return __raw_readl(base + 0x04) & (1<< offs);
118 EXPORT_SYMBOL(s3c2410_gpio_getpin);
120 unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
123 unsigned long misccr;
125 local_irq_save(flags);
126 misccr = __raw_readl(S3C24XX_MISCCR);
129 __raw_writel(misccr, S3C24XX_MISCCR);
130 local_irq_restore(flags);
135 EXPORT_SYMBOL(s3c2410_modify_misccr);
137 int s3c2410_gpio_getirq(unsigned int pin)
139 if (pin < S3C2410_GPF(0) || pin > S3C2410_GPG(15))
140 return -EINVAL; /* not valid interrupts */
142 if (pin < S3C2410_GPG(0) && pin > S3C2410_GPF(7))
143 return -EINVAL; /* not valid pin */
145 if (pin < S3C2410_GPF(4))
146 return (pin - S3C2410_GPF(0)) + IRQ_EINT0;
148 if (pin < S3C2410_GPG(0))
149 return (pin - S3C2410_GPF(4)) + IRQ_EINT4;
151 return (pin - S3C2410_GPG(0)) + IRQ_EINT8;
154 EXPORT_SYMBOL(s3c2410_gpio_getirq);