1 /* linux/arch/arm/mach-s3c2410/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>
30 #include <asm/hardware.h>
34 #include <asm/arch/regs-gpio.h>
36 void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function)
38 void __iomem *base = S3C24XX_GPIO_BASE(pin);
43 if (pin < S3C2410_GPIO_BANKB) {
44 mask = 1 << S3C2410_GPIO_OFFSET(pin);
46 mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;
50 case S3C2410_GPIO_LEAVE:
55 case S3C2410_GPIO_INPUT:
56 case S3C2410_GPIO_OUTPUT:
57 case S3C2410_GPIO_SFN2:
58 case S3C2410_GPIO_SFN3:
59 if (pin < S3C2410_GPIO_BANKB) {
61 function <<= S3C2410_GPIO_OFFSET(pin);
64 function <<= S3C2410_GPIO_OFFSET(pin)*2;
68 /* modify the specified register wwith IRQs off */
70 local_irq_save(flags);
72 con = __raw_readl(base + 0x00);
76 __raw_writel(con, base + 0x00);
78 local_irq_restore(flags);
81 EXPORT_SYMBOL(s3c2410_gpio_cfgpin);
83 unsigned int s3c2410_gpio_getcfg(unsigned int pin)
85 void __iomem *base = S3C24XX_GPIO_BASE(pin);
88 if (pin < S3C2410_GPIO_BANKB) {
89 mask = 1 << S3C2410_GPIO_OFFSET(pin);
91 mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;
94 return __raw_readl(base) & mask;
97 EXPORT_SYMBOL(s3c2410_gpio_getcfg);
99 void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
101 void __iomem *base = S3C24XX_GPIO_BASE(pin);
102 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
106 if (pin < S3C2410_GPIO_BANKB)
109 local_irq_save(flags);
111 up = __raw_readl(base + 0x08);
114 __raw_writel(up, base + 0x08);
116 local_irq_restore(flags);
119 EXPORT_SYMBOL(s3c2410_gpio_pullup);
121 void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
123 void __iomem *base = S3C24XX_GPIO_BASE(pin);
124 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
128 local_irq_save(flags);
130 dat = __raw_readl(base + 0x04);
133 __raw_writel(dat, base + 0x04);
135 local_irq_restore(flags);
138 EXPORT_SYMBOL(s3c2410_gpio_setpin);
140 unsigned int s3c2410_gpio_getpin(unsigned int pin)
142 void __iomem *base = S3C24XX_GPIO_BASE(pin);
143 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
145 return __raw_readl(base + 0x04) & (1<< offs);
148 EXPORT_SYMBOL(s3c2410_gpio_getpin);
150 unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
153 unsigned long misccr;
155 local_irq_save(flags);
156 misccr = __raw_readl(S3C24XX_MISCCR);
159 __raw_writel(misccr, S3C24XX_MISCCR);
160 local_irq_restore(flags);
165 EXPORT_SYMBOL(s3c2410_modify_misccr);
167 int s3c2410_gpio_getirq(unsigned int pin)
169 if (pin < S3C2410_GPF0 || pin > S3C2410_GPG15)
170 return -1; /* not valid interrupts */
172 if (pin < S3C2410_GPG0 && pin > S3C2410_GPF7)
173 return -1; /* not valid pin */
175 if (pin < S3C2410_GPF4)
176 return (pin - S3C2410_GPF0) + IRQ_EINT0;
178 if (pin < S3C2410_GPG0)
179 return (pin - S3C2410_GPF4) + IRQ_EINT4;
181 return (pin - S3C2410_GPG0) + IRQ_EINT8;
184 EXPORT_SYMBOL(s3c2410_gpio_getirq);