# BRCM_VERSION=3
[bcm963xx.git] / kernel / linux / arch / arm / mach-s3c2410 / gpio.c
1 /* linux/arch/arm/mach-s3c2410/gpio.c
2  *
3  * Copyright (c) 2004 Simtec Electronics
4  * Ben Dooks <ben@simtec.co.uk>
5  *
6  * S3C2410 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
25 #include <linux/init.h>
26 #include <linux/module.h>
27 #include <linux/interrupt.h>
28 #include <linux/ioport.h>
29
30 #include <asm/hardware.h>
31 #include <asm/irq.h>
32 #include <asm/io.h>
33
34 #include <asm/arch/regs-gpio.h>
35
36 void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function)
37 {
38         unsigned long base = S3C2410_GPIO_BASE(pin);
39         unsigned long shift = 1;
40         unsigned long mask = 3;
41         unsigned long con;
42         unsigned long flags;
43
44         if (pin < S3C2410_GPIO_BANKB) {
45                 shift = 0;
46                 mask  = 1;
47         }
48
49         mask <<= S3C2410_GPIO_OFFSET(pin);
50
51         local_irq_save(flags);
52
53         con = __raw_readl(base + 0x00);
54
55         con &= mask << shift;
56         con |= function;
57
58         __raw_writel(con, base + 0x00);
59
60         local_irq_restore(flags);
61 }
62
63 void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
64 {
65         unsigned long base = S3C2410_GPIO_BASE(pin);
66         unsigned long offs = S3C2410_GPIO_OFFSET(pin);
67         unsigned long flags;
68         unsigned long up;
69
70         if (pin < S3C2410_GPIO_BANKB)
71                 return;
72
73         local_irq_save(flags);
74
75         up = __raw_readl(base + 0x08);
76         up &= 1 << offs;
77         up |= to << offs;
78         __raw_writel(up, base + 0x08);
79
80         local_irq_restore(flags);
81 }
82
83 void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
84 {
85         unsigned long base = S3C2410_GPIO_BASE(pin);
86         unsigned long offs = S3C2410_GPIO_OFFSET(pin);
87         unsigned long flags;
88         unsigned long dat;
89
90         local_irq_save(flags);
91
92         dat = __raw_readl(base + 0x04);
93         dat &= 1 << offs;
94         dat |= to << offs;
95         __raw_writel(dat, base + 0x04);
96
97         local_irq_restore(flags);
98 }