acpiphp: Execute ACPI _REG method for hotadded devices
[linux/fpc-iii.git] / arch / arm / plat-s3c24xx / gpio.c
blob5467470badfd32ca481074bdfb3910813b9f88ec
1 /* linux/arch/arm/plat-s3c24xx/gpio.c
3 * Copyright (c) 2004-2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * S3C24XX GPIO support
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>
29 #include <linux/io.h>
31 #include <mach/hardware.h>
32 #include <mach/gpio-fns.h>
33 #include <asm/irq.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);
40 unsigned long mask;
41 unsigned long con;
42 unsigned long flags;
44 if (pin < S3C2410_GPIO_BANKB) {
45 mask = 1 << S3C2410_GPIO_OFFSET(pin);
46 } else {
47 mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;
50 switch (function) {
51 case S3C2410_GPIO_LEAVE:
52 mask = 0;
53 function = 0;
54 break;
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) {
61 function -= 1;
62 function &= 1;
63 function <<= S3C2410_GPIO_OFFSET(pin);
64 } else {
65 function &= 3;
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);
75 con &= ~mask;
76 con |= function;
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);
92 val &= 1;
93 val += 1;
94 } else {
95 val >>= S3C2410_GPIO_OFFSET(pin)*2;
96 val &= 3;
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);
108 unsigned long flags;
109 unsigned long up;
111 if (pin < S3C2410_GPIO_BANKB)
112 return;
114 local_irq_save(flags);
116 up = __raw_readl(base + 0x08);
117 up &= ~(1L << offs);
118 up |= to << offs;
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)
132 return -EINVAL;
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);
143 unsigned long flags;
144 unsigned long dat;
146 local_irq_save(flags);
148 dat = __raw_readl(base + 0x04);
149 dat &= ~(1 << offs);
150 dat |= to << offs;
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)
170 unsigned long flags;
171 unsigned long misccr;
173 local_irq_save(flags);
174 misccr = __raw_readl(S3C24XX_MISCCR);
175 misccr &= ~clear;
176 misccr ^= change;
177 __raw_writel(misccr, S3C24XX_MISCCR);
178 local_irq_restore(flags);
180 return misccr;
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);