diff options
author | Marek Szyprowski <m.szyprowski@samsung.com> | 2010-09-30 21:40:37 -0400 |
---|---|---|
committer | Kukjin Kim <kgene.kim@samsung.com> | 2010-10-20 18:54:56 -0400 |
commit | 170a46177094b390299d1206748d7f15cd375dc9 (patch) | |
tree | 81fc5270bbc74d1cf946b2ed265fb85c4dee3ed8 /arch/arm/plat-s5p | |
parent | ca1931ca1e87c32f9abaef378c6996b25774cb02 (diff) |
ARM: S5P: Add common S5P GPIO Interrupt support
This patch adds common code to enable support of GPIO interrupt on
S5P SoCs.
The total number of GPIO pins is quite large on S5P SoCs. Registering
irq support for all of them would be a resource waste. Because of that
the interrupt support for standard GPIO pins is registered dynamically
by the s5p_register_gpio_interrupt() function.
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
[kgene.kim@samsung.com: minor title fixes]
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
Diffstat (limited to 'arch/arm/plat-s5p')
-rw-r--r-- | arch/arm/plat-s5p/Kconfig | 5 | ||||
-rw-r--r-- | arch/arm/plat-s5p/Makefile | 1 | ||||
-rw-r--r-- | arch/arm/plat-s5p/include/plat/irqs.h | 9 | ||||
-rw-r--r-- | arch/arm/plat-s5p/irq-gpioint.c | 242 |
4 files changed, 257 insertions, 0 deletions
diff --git a/arch/arm/plat-s5p/Kconfig b/arch/arm/plat-s5p/Kconfig index 25960966af7c..65dbfa8e0a86 100644 --- a/arch/arm/plat-s5p/Kconfig +++ b/arch/arm/plat-s5p/Kconfig | |||
@@ -32,6 +32,11 @@ config S5P_EXT_INT | |||
32 | Use the external interrupts (other than GPIO interrupts.) | 32 | Use the external interrupts (other than GPIO interrupts.) |
33 | Note: Do not choose this for S5P6440 and S5P6450. | 33 | Note: Do not choose this for S5P6440 and S5P6450. |
34 | 34 | ||
35 | config S5P_GPIO_INT | ||
36 | bool | ||
37 | help | ||
38 | Common code for the GPIO interrupts (other than external interrupts.) | ||
39 | |||
35 | config S5P_DEV_FIMC0 | 40 | config S5P_DEV_FIMC0 |
36 | bool | 41 | bool |
37 | help | 42 | help |
diff --git a/arch/arm/plat-s5p/Makefile b/arch/arm/plat-s5p/Makefile index f3e917e27da8..e0823be3c8b9 100644 --- a/arch/arm/plat-s5p/Makefile +++ b/arch/arm/plat-s5p/Makefile | |||
@@ -18,6 +18,7 @@ obj-y += cpu.o | |||
18 | obj-y += clock.o | 18 | obj-y += clock.o |
19 | obj-y += irq.o | 19 | obj-y += irq.o |
20 | obj-$(CONFIG_S5P_EXT_INT) += irq-eint.o | 20 | obj-$(CONFIG_S5P_EXT_INT) += irq-eint.o |
21 | obj-$(CONFIG_S5P_GPIO_INT) += irq-gpioint.o | ||
21 | 22 | ||
22 | # devices | 23 | # devices |
23 | 24 | ||
diff --git a/arch/arm/plat-s5p/include/plat/irqs.h b/arch/arm/plat-s5p/include/plat/irqs.h index 3fb3a3a17465..23603c7f1943 100644 --- a/arch/arm/plat-s5p/include/plat/irqs.h +++ b/arch/arm/plat-s5p/include/plat/irqs.h | |||
@@ -94,4 +94,13 @@ | |||
94 | ((irq) - S5P_EINT_BASE1) : \ | 94 | ((irq) - S5P_EINT_BASE1) : \ |
95 | ((irq) + 16 - S5P_EINT_BASE2)) | 95 | ((irq) + 16 - S5P_EINT_BASE2)) |
96 | 96 | ||
97 | /* Typically only a few gpio chips require gpio interrupt support. | ||
98 | To avoid memory waste irq descriptors are allocated only for | ||
99 | S5P_GPIOINT_GROUP_COUNT chips, each with total number of | ||
100 | S5P_GPIOINT_GROUP_SIZE pins/irqs. Each GPIOINT group can be assiged | ||
101 | to any gpio chip with the s5p_register_gpio_interrupt() function */ | ||
102 | #define S5P_GPIOINT_GROUP_COUNT 4 | ||
103 | #define S5P_GPIOINT_GROUP_SIZE 8 | ||
104 | #define S5P_GPIOINT_COUNT (S5P_GPIOINT_GROUP_COUNT * S5P_GPIOINT_GROUP_SIZE) | ||
105 | |||
97 | #endif /* __ASM_PLAT_S5P_IRQS_H */ | 106 | #endif /* __ASM_PLAT_S5P_IRQS_H */ |
diff --git a/arch/arm/plat-s5p/irq-gpioint.c b/arch/arm/plat-s5p/irq-gpioint.c new file mode 100644 index 000000000000..32263a306c90 --- /dev/null +++ b/arch/arm/plat-s5p/irq-gpioint.c | |||
@@ -0,0 +1,242 @@ | |||
1 | /* linux/arch/arm/plat-s5p/irq-gpioint.c | ||
2 | * | ||
3 | * Copyright (c) 2010 Samsung Electronics Co., Ltd. | ||
4 | * Author: Kyungmin Park <kyungmin.park@samsung.com> | ||
5 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> | ||
6 | * Author: Marek Szyprowski <m.szyprowski@samsung.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/interrupt.h> | ||
17 | #include <linux/irq.h> | ||
18 | #include <linux/io.h> | ||
19 | #include <linux/gpio.h> | ||
20 | |||
21 | #include <mach/map.h> | ||
22 | #include <plat/gpio-core.h> | ||
23 | #include <plat/gpio-cfg.h> | ||
24 | |||
25 | #define S5P_GPIOREG(x) (S5P_VA_GPIO + (x)) | ||
26 | |||
27 | #define GPIOINT_CON_OFFSET 0x700 | ||
28 | #define GPIOINT_MASK_OFFSET 0x900 | ||
29 | #define GPIOINT_PEND_OFFSET 0xA00 | ||
30 | |||
31 | #define GPIOINT_LEVEL_LOW 0x0 | ||
32 | #define GPIOINT_LEVEL_HIGH 0x1 | ||
33 | #define GPIOINT_EDGE_FALLING 0x2 | ||
34 | #define GPIOINT_EDGE_RISING 0x3 | ||
35 | #define GPIOINT_EDGE_BOTH 0x4 | ||
36 | |||
37 | static struct s3c_gpio_chip *irq_chips[S5P_GPIOINT_GROUP_MAXNR]; | ||
38 | |||
39 | static int s5p_gpioint_get_group(unsigned int irq) | ||
40 | { | ||
41 | struct gpio_chip *chip = get_irq_data(irq); | ||
42 | struct s3c_gpio_chip *s3c_chip = container_of(chip, | ||
43 | struct s3c_gpio_chip, chip); | ||
44 | int group; | ||
45 | |||
46 | for (group = 0; group < S5P_GPIOINT_GROUP_MAXNR; group++) | ||
47 | if (s3c_chip == irq_chips[group]) | ||
48 | break; | ||
49 | |||
50 | return group; | ||
51 | } | ||
52 | |||
53 | static int s5p_gpioint_get_offset(unsigned int irq) | ||
54 | { | ||
55 | struct gpio_chip *chip = get_irq_data(irq); | ||
56 | struct s3c_gpio_chip *s3c_chip = container_of(chip, | ||
57 | struct s3c_gpio_chip, chip); | ||
58 | |||
59 | return irq - s3c_chip->irq_base; | ||
60 | } | ||
61 | |||
62 | static void s5p_gpioint_ack(unsigned int irq) | ||
63 | { | ||
64 | int group, offset, pend_offset; | ||
65 | unsigned int value; | ||
66 | |||
67 | group = s5p_gpioint_get_group(irq); | ||
68 | offset = s5p_gpioint_get_offset(irq); | ||
69 | pend_offset = group << 2; | ||
70 | |||
71 | value = __raw_readl(S5P_GPIOREG(GPIOINT_PEND_OFFSET) + pend_offset); | ||
72 | value |= 1 << offset; | ||
73 | __raw_writel(value, S5P_GPIOREG(GPIOINT_PEND_OFFSET) + pend_offset); | ||
74 | } | ||
75 | |||
76 | static void s5p_gpioint_mask(unsigned int irq) | ||
77 | { | ||
78 | int group, offset, mask_offset; | ||
79 | unsigned int value; | ||
80 | |||
81 | group = s5p_gpioint_get_group(irq); | ||
82 | offset = s5p_gpioint_get_offset(irq); | ||
83 | mask_offset = group << 2; | ||
84 | |||
85 | value = __raw_readl(S5P_GPIOREG(GPIOINT_MASK_OFFSET) + mask_offset); | ||
86 | value |= 1 << offset; | ||
87 | __raw_writel(value, S5P_GPIOREG(GPIOINT_MASK_OFFSET) + mask_offset); | ||
88 | } | ||
89 | |||
90 | static void s5p_gpioint_unmask(unsigned int irq) | ||
91 | { | ||
92 | int group, offset, mask_offset; | ||
93 | unsigned int value; | ||
94 | |||
95 | group = s5p_gpioint_get_group(irq); | ||
96 | offset = s5p_gpioint_get_offset(irq); | ||
97 | mask_offset = group << 2; | ||
98 | |||
99 | value = __raw_readl(S5P_GPIOREG(GPIOINT_MASK_OFFSET) + mask_offset); | ||
100 | value &= ~(1 << offset); | ||
101 | __raw_writel(value, S5P_GPIOREG(GPIOINT_MASK_OFFSET) + mask_offset); | ||
102 | } | ||
103 | |||
104 | static void s5p_gpioint_mask_ack(unsigned int irq) | ||
105 | { | ||
106 | s5p_gpioint_mask(irq); | ||
107 | s5p_gpioint_ack(irq); | ||
108 | } | ||
109 | |||
110 | static int s5p_gpioint_set_type(unsigned int irq, unsigned int type) | ||
111 | { | ||
112 | int group, offset, con_offset; | ||
113 | unsigned int value; | ||
114 | |||
115 | group = s5p_gpioint_get_group(irq); | ||
116 | offset = s5p_gpioint_get_offset(irq); | ||
117 | con_offset = group << 2; | ||
118 | |||
119 | switch (type) { | ||
120 | case IRQ_TYPE_EDGE_RISING: | ||
121 | type = GPIOINT_EDGE_RISING; | ||
122 | break; | ||
123 | case IRQ_TYPE_EDGE_FALLING: | ||
124 | type = GPIOINT_EDGE_FALLING; | ||
125 | break; | ||
126 | case IRQ_TYPE_EDGE_BOTH: | ||
127 | type = GPIOINT_EDGE_BOTH; | ||
128 | break; | ||
129 | case IRQ_TYPE_LEVEL_HIGH: | ||
130 | type = GPIOINT_LEVEL_HIGH; | ||
131 | break; | ||
132 | case IRQ_TYPE_LEVEL_LOW: | ||
133 | type = GPIOINT_LEVEL_LOW; | ||
134 | break; | ||
135 | case IRQ_TYPE_NONE: | ||
136 | default: | ||
137 | printk(KERN_WARNING "No irq type\n"); | ||
138 | return -EINVAL; | ||
139 | } | ||
140 | |||
141 | value = __raw_readl(S5P_GPIOREG(GPIOINT_CON_OFFSET) + con_offset); | ||
142 | value &= ~(0x7 << (offset * 0x4)); | ||
143 | value |= (type << (offset * 0x4)); | ||
144 | __raw_writel(value, S5P_GPIOREG(GPIOINT_CON_OFFSET) + con_offset); | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | struct irq_chip s5p_gpioint = { | ||
150 | .name = "s5p_gpioint", | ||
151 | .ack = s5p_gpioint_ack, | ||
152 | .mask = s5p_gpioint_mask, | ||
153 | .mask_ack = s5p_gpioint_mask_ack, | ||
154 | .unmask = s5p_gpioint_unmask, | ||
155 | .set_type = s5p_gpioint_set_type, | ||
156 | }; | ||
157 | |||
158 | static void s5p_gpioint_handler(unsigned int irq, struct irq_desc *desc) | ||
159 | { | ||
160 | int group, offset, pend_offset, mask_offset; | ||
161 | int real_irq; | ||
162 | unsigned int pend, mask; | ||
163 | |||
164 | for (group = 0; group < S5P_GPIOINT_GROUP_MAXNR; group++) { | ||
165 | pend_offset = group << 2; | ||
166 | pend = __raw_readl(S5P_GPIOREG(GPIOINT_PEND_OFFSET) + | ||
167 | pend_offset); | ||
168 | if (!pend) | ||
169 | continue; | ||
170 | |||
171 | mask_offset = group << 2; | ||
172 | mask = __raw_readl(S5P_GPIOREG(GPIOINT_MASK_OFFSET) + | ||
173 | mask_offset); | ||
174 | pend &= ~mask; | ||
175 | |||
176 | for (offset = 0; offset < 8; offset++) { | ||
177 | if (pend & (1 << offset)) { | ||
178 | struct s3c_gpio_chip *chip = irq_chips[group]; | ||
179 | if (chip) { | ||
180 | real_irq = chip->irq_base + offset; | ||
181 | generic_handle_irq(real_irq); | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | |||
188 | static __init int s5p_gpioint_add(struct s3c_gpio_chip *chip) | ||
189 | { | ||
190 | static int used_gpioint_groups = 0; | ||
191 | static bool handler_registered = 0; | ||
192 | int irq, group = chip->group; | ||
193 | int i; | ||
194 | |||
195 | if (used_gpioint_groups >= S5P_GPIOINT_GROUP_COUNT) | ||
196 | return -ENOMEM; | ||
197 | |||
198 | chip->irq_base = S5P_GPIOINT_BASE + | ||
199 | used_gpioint_groups * S5P_GPIOINT_GROUP_SIZE; | ||
200 | used_gpioint_groups++; | ||
201 | |||
202 | if (!handler_registered) { | ||
203 | set_irq_chained_handler(IRQ_GPIOINT, s5p_gpioint_handler); | ||
204 | handler_registered = 1; | ||
205 | } | ||
206 | |||
207 | irq_chips[group] = chip; | ||
208 | for (i = 0; i < chip->chip.ngpio; i++) { | ||
209 | irq = chip->irq_base + i; | ||
210 | set_irq_chip(irq, &s5p_gpioint); | ||
211 | set_irq_data(irq, &chip->chip); | ||
212 | set_irq_handler(irq, handle_level_irq); | ||
213 | set_irq_flags(irq, IRQF_VALID); | ||
214 | } | ||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | int __init s5p_register_gpio_interrupt(int pin) | ||
219 | { | ||
220 | struct s3c_gpio_chip *my_chip = s3c_gpiolib_getchip(pin); | ||
221 | int offset, group; | ||
222 | int ret; | ||
223 | |||
224 | if (!my_chip) | ||
225 | return -EINVAL; | ||
226 | |||
227 | offset = pin - my_chip->chip.base; | ||
228 | group = my_chip->group; | ||
229 | |||
230 | /* check if the group has been already registered */ | ||
231 | if (my_chip->irq_base) | ||
232 | return my_chip->irq_base + offset; | ||
233 | |||
234 | /* register gpio group */ | ||
235 | ret = s5p_gpioint_add(my_chip); | ||
236 | if (ret == 0) { | ||
237 | printk(KERN_INFO "Registered interrupt support for gpio group %d.\n", | ||
238 | group); | ||
239 | return my_chip->irq_base + offset; | ||
240 | } | ||
241 | return ret; | ||
242 | } | ||