ARM: S3C24XX: Remove s3c2410_gpio_setcfg()
[pandora-kernel.git] / arch / arm / plat-s3c24xx / gpio.c
1 /* linux/arch/arm/plat-s3c24xx/gpio.c
2  *
3  * Copyright (c) 2004-2005 Simtec Electronics
4  *      Ben Dooks <ben@simtec.co.uk>
5  *
6  * S3C24XX GPIO support
7  *
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.
12  *
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.
17  *
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
21 */
22
23
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>
30
31 #include <mach/hardware.h>
32 #include <mach/gpio-fns.h>
33 #include <asm/irq.h>
34
35 #include <mach/regs-gpio.h>
36
37 unsigned int s3c2410_gpio_getcfg(unsigned int pin)
38 {
39         void __iomem *base = S3C24XX_GPIO_BASE(pin);
40         unsigned long val = __raw_readl(base);
41
42         if (pin < S3C2410_GPIO_BANKB) {
43                 val >>= S3C2410_GPIO_OFFSET(pin);
44                 val &= 1;
45                 val += 1;
46         } else {
47                 val >>= S3C2410_GPIO_OFFSET(pin)*2;
48                 val &= 3;
49         }
50
51         return val | S3C2410_GPIO_INPUT;
52 }
53
54 EXPORT_SYMBOL(s3c2410_gpio_getcfg);
55
56 void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
57 {
58         void __iomem *base = S3C24XX_GPIO_BASE(pin);
59         unsigned long offs = S3C2410_GPIO_OFFSET(pin);
60         unsigned long flags;
61         unsigned long up;
62
63         if (pin < S3C2410_GPIO_BANKB)
64                 return;
65
66         local_irq_save(flags);
67
68         up = __raw_readl(base + 0x08);
69         up &= ~(1L << offs);
70         up |= to << offs;
71         __raw_writel(up, base + 0x08);
72
73         local_irq_restore(flags);
74 }
75
76 EXPORT_SYMBOL(s3c2410_gpio_pullup);
77
78 int s3c2410_gpio_getpull(unsigned int pin)
79 {
80         void __iomem *base = S3C24XX_GPIO_BASE(pin);
81         unsigned long offs = S3C2410_GPIO_OFFSET(pin);
82
83         if (pin < S3C2410_GPIO_BANKB)
84                 return -EINVAL;
85
86         return (__raw_readl(base + 0x08) & (1L << offs)) ? 1 : 0;
87 }
88
89 EXPORT_SYMBOL(s3c2410_gpio_getpull);
90
91 void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
92 {
93         void __iomem *base = S3C24XX_GPIO_BASE(pin);
94         unsigned long offs = S3C2410_GPIO_OFFSET(pin);
95         unsigned long flags;
96         unsigned long dat;
97
98         local_irq_save(flags);
99
100         dat = __raw_readl(base + 0x04);
101         dat &= ~(1 << offs);
102         dat |= to << offs;
103         __raw_writel(dat, base + 0x04);
104
105         local_irq_restore(flags);
106 }
107
108 EXPORT_SYMBOL(s3c2410_gpio_setpin);
109
110 unsigned int s3c2410_gpio_getpin(unsigned int pin)
111 {
112         void __iomem *base = S3C24XX_GPIO_BASE(pin);
113         unsigned long offs = S3C2410_GPIO_OFFSET(pin);
114
115         return __raw_readl(base + 0x04) & (1<< offs);
116 }
117
118 EXPORT_SYMBOL(s3c2410_gpio_getpin);
119
120 unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
121 {
122         unsigned long flags;
123         unsigned long misccr;
124
125         local_irq_save(flags);
126         misccr = __raw_readl(S3C24XX_MISCCR);
127         misccr &= ~clear;
128         misccr ^= change;
129         __raw_writel(misccr, S3C24XX_MISCCR);
130         local_irq_restore(flags);
131
132         return misccr;
133 }
134
135 EXPORT_SYMBOL(s3c2410_modify_misccr);
136
137 int s3c2410_gpio_getirq(unsigned int pin)
138 {
139         if (pin < S3C2410_GPF(0) || pin > S3C2410_GPG(15))
140                 return -EINVAL; /* not valid interrupts */
141
142         if (pin < S3C2410_GPG(0) && pin > S3C2410_GPF(7))
143                 return -EINVAL; /* not valid pin */
144
145         if (pin < S3C2410_GPF(4))
146                 return (pin - S3C2410_GPF(0)) + IRQ_EINT0;
147
148         if (pin < S3C2410_GPG(0))
149                 return (pin - S3C2410_GPF(4)) + IRQ_EINT4;
150
151         return (pin - S3C2410_GPG(0)) + IRQ_EINT8;
152 }
153
154 EXPORT_SYMBOL(s3c2410_gpio_getirq);