x86, vsyscall: fix the oops crash with __pa_vsymbol()
[linux/fpc-iii.git] / arch / arm / mach-ks8695 / gpio.c
blobb1aa3cb3d4a3a782132fde8dd0655d94e16dc5c5
1 /*
2 * arch/arm/mach-ks8695/gpio.c
4 * Copyright (C) 2006 Andrew Victor
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/kernel.h>
21 #include <linux/mm.h>
22 #include <linux/init.h>
23 #include <linux/module.h>
25 #include <asm/io.h>
26 #include <asm/hardware.h>
27 #include <asm/mach/irq.h>
29 #include <asm/arch/regs-gpio.h>
30 #include <asm/arch/gpio.h>
33 * Configure a GPIO line for either GPIO function, or its internal
34 * function (Interrupt, Timer, etc).
36 static void __init_or_module ks8695_gpio_mode(unsigned int pin, short gpio)
38 unsigned int enable[] = { IOPC_IOEINT0EN, IOPC_IOEINT1EN, IOPC_IOEINT2EN, IOPC_IOEINT3EN, IOPC_IOTIM0EN, IOPC_IOTIM1EN };
39 unsigned long x, flags;
41 if (pin > KS8695_GPIO_5) /* only GPIO 0..5 have internal functions */
42 return;
44 local_irq_save(flags);
46 x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPC);
47 if (gpio) /* GPIO: set bit to 0 */
48 x &= ~enable[pin];
49 else /* Internal function: set bit to 1 */
50 x |= enable[pin];
51 __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPC);
53 local_irq_restore(flags);
57 static unsigned short gpio_irq[] = { KS8695_IRQ_EXTERN0, KS8695_IRQ_EXTERN1, KS8695_IRQ_EXTERN2, KS8695_IRQ_EXTERN3 };
60 * Configure GPIO pin as external interrupt source.
62 int __init_or_module ks8695_gpio_interrupt(unsigned int pin, unsigned int type)
64 unsigned long x, flags;
66 if (pin > KS8695_GPIO_3) /* only GPIO 0..3 can generate IRQ */
67 return -EINVAL;
69 local_irq_save(flags);
71 /* set pin as input */
72 x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM);
73 x &= ~IOPM_(pin);
74 __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPM);
76 local_irq_restore(flags);
78 /* Set IRQ triggering type */
79 set_irq_type(gpio_irq[pin], type);
81 /* enable interrupt mode */
82 ks8695_gpio_mode(pin, 0);
84 return 0;
86 EXPORT_SYMBOL(ks8695_gpio_interrupt);
90 /* .... Generic GPIO interface .............................................. */
93 * Configure the GPIO line as an input.
95 int __init_or_module gpio_direction_input(unsigned int pin)
97 unsigned long x, flags;
99 if (pin > KS8695_GPIO_15)
100 return -EINVAL;
102 /* set pin to GPIO mode */
103 ks8695_gpio_mode(pin, 1);
105 local_irq_save(flags);
107 /* set pin as input */
108 x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM);
109 x &= ~IOPM_(pin);
110 __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPM);
112 local_irq_restore(flags);
114 return 0;
116 EXPORT_SYMBOL(gpio_direction_input);
120 * Configure the GPIO line as an output, with default state.
122 int __init_or_module gpio_direction_output(unsigned int pin, unsigned int state)
124 unsigned long x, flags;
126 if (pin > KS8695_GPIO_15)
127 return -EINVAL;
129 /* set pin to GPIO mode */
130 ks8695_gpio_mode(pin, 1);
132 local_irq_save(flags);
134 /* set line state */
135 x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD);
136 if (state)
137 x |= (1 << pin);
138 else
139 x &= ~(1 << pin);
140 __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPD);
142 /* set pin as output */
143 x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM);
144 x |= IOPM_(pin);
145 __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPM);
147 local_irq_restore(flags);
149 return 0;
151 EXPORT_SYMBOL(gpio_direction_output);
155 * Set the state of an output GPIO line.
157 void gpio_set_value(unsigned int pin, unsigned int state)
159 unsigned long x, flags;
161 if (pin > KS8695_GPIO_15)
162 return;
164 local_irq_save(flags);
166 /* set output line state */
167 x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD);
168 if (state)
169 x |= (1 << pin);
170 else
171 x &= ~(1 << pin);
172 __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPD);
174 local_irq_restore(flags);
176 EXPORT_SYMBOL(gpio_set_value);
180 * Read the state of a GPIO line.
182 int gpio_get_value(unsigned int pin)
184 unsigned long x;
186 if (pin > KS8695_GPIO_15)
187 return -EINVAL;
189 x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD);
190 return (x & (1 << pin)) != 0;
192 EXPORT_SYMBOL(gpio_get_value);
196 * Map GPIO line to IRQ number.
198 int gpio_to_irq(unsigned int pin)
200 if (pin > KS8695_GPIO_3) /* only GPIO 0..3 can generate IRQ */
201 return -EINVAL;
203 return gpio_irq[pin];
205 EXPORT_SYMBOL(gpio_to_irq);
209 * Map IRQ number to GPIO line.
211 int irq_to_gpio(unsigned int irq)
213 if ((irq < KS8695_IRQ_EXTERN0) || (irq > KS8695_IRQ_EXTERN3))
214 return -EINVAL;
216 return (irq - KS8695_IRQ_EXTERN0);
218 EXPORT_SYMBOL(irq_to_gpio);