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
23 * 13-Sep-2004 BJD Implemented change of MISCCR
24 * 14-Sep-2004 BJD Added getpin call
25 * 14-Sep-2004 BJD Fixed bug in setpin() call
26 * 30-Sep-2004 BJD Fixed cfgpin() mask bug
27 * 01-Oct-2004 BJD Added getcfg() to get pin configuration
28 * 01-Oct-2004 BJD Fixed mask bug in pullup() call
29 * 01-Oct-2004 BJD Added getirq() to turn pin into irqno
30 * 04-Oct-2004 BJD Added irq filter controls for GPIO
31 * 05-Nov-2004 BJD EXPORT_SYMBOL() added for all code
32 * 13-Mar-2005 BJD Updates for __iomem
33 * 26-Oct-2005 BJD Added generic configuration types
37 #include <linux/kernel.h>
38 #include <linux/init.h>
39 #include <linux/module.h>
40 #include <linux/interrupt.h>
41 #include <linux/ioport.h>
43 #include <asm/hardware.h>
47 #include <asm/arch/regs-gpio.h>
49 void s3c2410_gpio_cfgpin(unsigned int pin
, unsigned int function
)
51 void __iomem
*base
= S3C2410_GPIO_BASE(pin
);
56 if (pin
< S3C2410_GPIO_BANKB
) {
57 mask
= 1 << S3C2410_GPIO_OFFSET(pin
);
59 mask
= 3 << S3C2410_GPIO_OFFSET(pin
)*2;
63 case S3C2410_GPIO_LEAVE
:
68 case S3C2410_GPIO_INPUT
:
69 case S3C2410_GPIO_OUTPUT
:
70 case S3C2410_GPIO_SFN2
:
71 case S3C2410_GPIO_SFN3
:
72 if (pin
< S3C2410_GPIO_BANKB
) {
74 function
<<= S3C2410_GPIO_OFFSET(pin
);
77 function
<<= S3C2410_GPIO_OFFSET(pin
)*2;
81 /* modify the specified register wwith IRQs off */
83 local_irq_save(flags
);
85 con
= __raw_readl(base
+ 0x00);
89 __raw_writel(con
, base
+ 0x00);
91 local_irq_restore(flags
);
94 EXPORT_SYMBOL(s3c2410_gpio_cfgpin
);
96 unsigned int s3c2410_gpio_getcfg(unsigned int pin
)
98 void __iomem
*base
= S3C2410_GPIO_BASE(pin
);
101 if (pin
< S3C2410_GPIO_BANKB
) {
102 mask
= 1 << S3C2410_GPIO_OFFSET(pin
);
104 mask
= 3 << S3C2410_GPIO_OFFSET(pin
)*2;
107 return __raw_readl(base
) & mask
;
110 EXPORT_SYMBOL(s3c2410_gpio_getcfg
);
112 void s3c2410_gpio_pullup(unsigned int pin
, unsigned int to
)
114 void __iomem
*base
= S3C2410_GPIO_BASE(pin
);
115 unsigned long offs
= S3C2410_GPIO_OFFSET(pin
);
119 if (pin
< S3C2410_GPIO_BANKB
)
122 local_irq_save(flags
);
124 up
= __raw_readl(base
+ 0x08);
127 __raw_writel(up
, base
+ 0x08);
129 local_irq_restore(flags
);
132 EXPORT_SYMBOL(s3c2410_gpio_pullup
);
134 void s3c2410_gpio_setpin(unsigned int pin
, unsigned int to
)
136 void __iomem
*base
= S3C2410_GPIO_BASE(pin
);
137 unsigned long offs
= S3C2410_GPIO_OFFSET(pin
);
141 local_irq_save(flags
);
143 dat
= __raw_readl(base
+ 0x04);
146 __raw_writel(dat
, base
+ 0x04);
148 local_irq_restore(flags
);
151 EXPORT_SYMBOL(s3c2410_gpio_setpin
);
153 unsigned int s3c2410_gpio_getpin(unsigned int pin
)
155 void __iomem
*base
= S3C2410_GPIO_BASE(pin
);
156 unsigned long offs
= S3C2410_GPIO_OFFSET(pin
);
158 return __raw_readl(base
+ 0x04) & (1<< offs
);
161 EXPORT_SYMBOL(s3c2410_gpio_getpin
);
163 unsigned int s3c2410_modify_misccr(unsigned int clear
, unsigned int change
)
166 unsigned long misccr
;
168 local_irq_save(flags
);
169 misccr
= __raw_readl(S3C2410_MISCCR
);
172 __raw_writel(misccr
, S3C2410_MISCCR
);
173 local_irq_restore(flags
);
178 EXPORT_SYMBOL(s3c2410_modify_misccr
);
180 int s3c2410_gpio_getirq(unsigned int pin
)
182 if (pin
< S3C2410_GPF0
|| pin
> S3C2410_GPG15_EINT23
)
183 return -1; /* not valid interrupts */
185 if (pin
< S3C2410_GPG0
&& pin
> S3C2410_GPF7
)
186 return -1; /* not valid pin */
188 if (pin
< S3C2410_GPF4
)
189 return (pin
- S3C2410_GPF0
) + IRQ_EINT0
;
191 if (pin
< S3C2410_GPG0
)
192 return (pin
- S3C2410_GPF4
) + IRQ_EINT4
;
194 return (pin
- S3C2410_GPG0
) + IRQ_EINT8
;
197 EXPORT_SYMBOL(s3c2410_gpio_getirq
);
199 int s3c2410_gpio_irqfilter(unsigned int pin
, unsigned int on
,
202 void __iomem
*reg
= S3C2410_EINFLT0
;
206 if (pin
< S3C2410_GPG8
|| pin
> S3C2410_GPG15
)
211 pin
-= S3C2410_GPG8_EINT16
;
214 local_irq_save(flags
);
216 /* update filter width and clock source */
218 val
= __raw_readl(reg
);
219 val
&= ~(0xff << ((pin
& 3) * 8));
220 val
|= config
<< ((pin
& 3) * 8);
221 __raw_writel(val
, reg
);
223 /* update filter enable */
225 val
= __raw_readl(S3C2410_EXTINT2
);
226 val
&= ~(1 << ((pin
* 4) + 3));
227 val
|= on
<< ((pin
* 4) + 3);
228 __raw_writel(val
, S3C2410_EXTINT2
);
230 local_irq_restore(flags
);
235 EXPORT_SYMBOL(s3c2410_gpio_irqfilter
);