gpio: reorganize drivers
[linux-2.6.git] / drivers / gpio / gpio-exynos4.c
blob6093a14037c38a0ba0705943e8b5f1c5dce5d44c
1 /*
2 * EXYNOS4 - GPIOlib support
4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/irq.h>
14 #include <linux/io.h>
15 #include <linux/gpio.h>
17 #include <mach/map.h>
19 #include <plat/gpio-core.h>
20 #include <plat/gpio-cfg.h>
21 #include <plat/gpio-cfg-helpers.h>
23 static struct s3c_gpio_cfg gpio_cfg = {
24 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
25 .set_pull = s3c_gpio_setpull_updown,
26 .get_pull = s3c_gpio_getpull_updown,
29 static struct s3c_gpio_cfg gpio_cfg_noint = {
30 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
31 .set_pull = s3c_gpio_setpull_updown,
32 .get_pull = s3c_gpio_getpull_updown,
36 * Following are the gpio banks in v310.
38 * The 'config' member when left to NULL, is initialized to the default
39 * structure gpio_cfg in the init function below.
41 * The 'base' member is also initialized in the init function below.
42 * Note: The initialization of 'base' member of s3c_gpio_chip structure
43 * uses the above macro and depends on the banks being listed in order here.
45 static struct s3c_gpio_chip exynos4_gpio_part1_4bit[] = {
47 .chip = {
48 .base = EXYNOS4_GPA0(0),
49 .ngpio = EXYNOS4_GPIO_A0_NR,
50 .label = "GPA0",
52 }, {
53 .chip = {
54 .base = EXYNOS4_GPA1(0),
55 .ngpio = EXYNOS4_GPIO_A1_NR,
56 .label = "GPA1",
58 }, {
59 .chip = {
60 .base = EXYNOS4_GPB(0),
61 .ngpio = EXYNOS4_GPIO_B_NR,
62 .label = "GPB",
64 }, {
65 .chip = {
66 .base = EXYNOS4_GPC0(0),
67 .ngpio = EXYNOS4_GPIO_C0_NR,
68 .label = "GPC0",
70 }, {
71 .chip = {
72 .base = EXYNOS4_GPC1(0),
73 .ngpio = EXYNOS4_GPIO_C1_NR,
74 .label = "GPC1",
76 }, {
77 .chip = {
78 .base = EXYNOS4_GPD0(0),
79 .ngpio = EXYNOS4_GPIO_D0_NR,
80 .label = "GPD0",
82 }, {
83 .chip = {
84 .base = EXYNOS4_GPD1(0),
85 .ngpio = EXYNOS4_GPIO_D1_NR,
86 .label = "GPD1",
88 }, {
89 .chip = {
90 .base = EXYNOS4_GPE0(0),
91 .ngpio = EXYNOS4_GPIO_E0_NR,
92 .label = "GPE0",
94 }, {
95 .chip = {
96 .base = EXYNOS4_GPE1(0),
97 .ngpio = EXYNOS4_GPIO_E1_NR,
98 .label = "GPE1",
100 }, {
101 .chip = {
102 .base = EXYNOS4_GPE2(0),
103 .ngpio = EXYNOS4_GPIO_E2_NR,
104 .label = "GPE2",
106 }, {
107 .chip = {
108 .base = EXYNOS4_GPE3(0),
109 .ngpio = EXYNOS4_GPIO_E3_NR,
110 .label = "GPE3",
112 }, {
113 .chip = {
114 .base = EXYNOS4_GPE4(0),
115 .ngpio = EXYNOS4_GPIO_E4_NR,
116 .label = "GPE4",
118 }, {
119 .chip = {
120 .base = EXYNOS4_GPF0(0),
121 .ngpio = EXYNOS4_GPIO_F0_NR,
122 .label = "GPF0",
124 }, {
125 .chip = {
126 .base = EXYNOS4_GPF1(0),
127 .ngpio = EXYNOS4_GPIO_F1_NR,
128 .label = "GPF1",
130 }, {
131 .chip = {
132 .base = EXYNOS4_GPF2(0),
133 .ngpio = EXYNOS4_GPIO_F2_NR,
134 .label = "GPF2",
136 }, {
137 .chip = {
138 .base = EXYNOS4_GPF3(0),
139 .ngpio = EXYNOS4_GPIO_F3_NR,
140 .label = "GPF3",
145 static struct s3c_gpio_chip exynos4_gpio_part2_4bit[] = {
147 .chip = {
148 .base = EXYNOS4_GPJ0(0),
149 .ngpio = EXYNOS4_GPIO_J0_NR,
150 .label = "GPJ0",
152 }, {
153 .chip = {
154 .base = EXYNOS4_GPJ1(0),
155 .ngpio = EXYNOS4_GPIO_J1_NR,
156 .label = "GPJ1",
158 }, {
159 .chip = {
160 .base = EXYNOS4_GPK0(0),
161 .ngpio = EXYNOS4_GPIO_K0_NR,
162 .label = "GPK0",
164 }, {
165 .chip = {
166 .base = EXYNOS4_GPK1(0),
167 .ngpio = EXYNOS4_GPIO_K1_NR,
168 .label = "GPK1",
170 }, {
171 .chip = {
172 .base = EXYNOS4_GPK2(0),
173 .ngpio = EXYNOS4_GPIO_K2_NR,
174 .label = "GPK2",
176 }, {
177 .chip = {
178 .base = EXYNOS4_GPK3(0),
179 .ngpio = EXYNOS4_GPIO_K3_NR,
180 .label = "GPK3",
182 }, {
183 .chip = {
184 .base = EXYNOS4_GPL0(0),
185 .ngpio = EXYNOS4_GPIO_L0_NR,
186 .label = "GPL0",
188 }, {
189 .chip = {
190 .base = EXYNOS4_GPL1(0),
191 .ngpio = EXYNOS4_GPIO_L1_NR,
192 .label = "GPL1",
194 }, {
195 .chip = {
196 .base = EXYNOS4_GPL2(0),
197 .ngpio = EXYNOS4_GPIO_L2_NR,
198 .label = "GPL2",
200 }, {
201 .config = &gpio_cfg_noint,
202 .chip = {
203 .base = EXYNOS4_GPY0(0),
204 .ngpio = EXYNOS4_GPIO_Y0_NR,
205 .label = "GPY0",
207 }, {
208 .config = &gpio_cfg_noint,
209 .chip = {
210 .base = EXYNOS4_GPY1(0),
211 .ngpio = EXYNOS4_GPIO_Y1_NR,
212 .label = "GPY1",
214 }, {
215 .config = &gpio_cfg_noint,
216 .chip = {
217 .base = EXYNOS4_GPY2(0),
218 .ngpio = EXYNOS4_GPIO_Y2_NR,
219 .label = "GPY2",
221 }, {
222 .config = &gpio_cfg_noint,
223 .chip = {
224 .base = EXYNOS4_GPY3(0),
225 .ngpio = EXYNOS4_GPIO_Y3_NR,
226 .label = "GPY3",
228 }, {
229 .config = &gpio_cfg_noint,
230 .chip = {
231 .base = EXYNOS4_GPY4(0),
232 .ngpio = EXYNOS4_GPIO_Y4_NR,
233 .label = "GPY4",
235 }, {
236 .config = &gpio_cfg_noint,
237 .chip = {
238 .base = EXYNOS4_GPY5(0),
239 .ngpio = EXYNOS4_GPIO_Y5_NR,
240 .label = "GPY5",
242 }, {
243 .config = &gpio_cfg_noint,
244 .chip = {
245 .base = EXYNOS4_GPY6(0),
246 .ngpio = EXYNOS4_GPIO_Y6_NR,
247 .label = "GPY6",
249 }, {
250 .base = (S5P_VA_GPIO2 + 0xC00),
251 .config = &gpio_cfg_noint,
252 .irq_base = IRQ_EINT(0),
253 .chip = {
254 .base = EXYNOS4_GPX0(0),
255 .ngpio = EXYNOS4_GPIO_X0_NR,
256 .label = "GPX0",
257 .to_irq = samsung_gpiolib_to_irq,
259 }, {
260 .base = (S5P_VA_GPIO2 + 0xC20),
261 .config = &gpio_cfg_noint,
262 .irq_base = IRQ_EINT(8),
263 .chip = {
264 .base = EXYNOS4_GPX1(0),
265 .ngpio = EXYNOS4_GPIO_X1_NR,
266 .label = "GPX1",
267 .to_irq = samsung_gpiolib_to_irq,
269 }, {
270 .base = (S5P_VA_GPIO2 + 0xC40),
271 .config = &gpio_cfg_noint,
272 .irq_base = IRQ_EINT(16),
273 .chip = {
274 .base = EXYNOS4_GPX2(0),
275 .ngpio = EXYNOS4_GPIO_X2_NR,
276 .label = "GPX2",
277 .to_irq = samsung_gpiolib_to_irq,
279 }, {
280 .base = (S5P_VA_GPIO2 + 0xC60),
281 .config = &gpio_cfg_noint,
282 .irq_base = IRQ_EINT(24),
283 .chip = {
284 .base = EXYNOS4_GPX3(0),
285 .ngpio = EXYNOS4_GPIO_X3_NR,
286 .label = "GPX3",
287 .to_irq = samsung_gpiolib_to_irq,
292 static struct s3c_gpio_chip exynos4_gpio_part3_4bit[] = {
294 .chip = {
295 .base = EXYNOS4_GPZ(0),
296 .ngpio = EXYNOS4_GPIO_Z_NR,
297 .label = "GPZ",
302 static __init int exynos4_gpiolib_init(void)
304 struct s3c_gpio_chip *chip;
305 int i;
306 int group = 0;
307 int nr_chips;
309 /* GPIO part 1 */
311 chip = exynos4_gpio_part1_4bit;
312 nr_chips = ARRAY_SIZE(exynos4_gpio_part1_4bit);
314 for (i = 0; i < nr_chips; i++, chip++) {
315 if (chip->config == NULL) {
316 chip->config = &gpio_cfg;
317 /* Assign the GPIO interrupt group */
318 chip->group = group++;
320 if (chip->base == NULL)
321 chip->base = S5P_VA_GPIO1 + (i) * 0x20;
324 samsung_gpiolib_add_4bit_chips(exynos4_gpio_part1_4bit, nr_chips);
326 /* GPIO part 2 */
328 chip = exynos4_gpio_part2_4bit;
329 nr_chips = ARRAY_SIZE(exynos4_gpio_part2_4bit);
331 for (i = 0; i < nr_chips; i++, chip++) {
332 if (chip->config == NULL) {
333 chip->config = &gpio_cfg;
334 /* Assign the GPIO interrupt group */
335 chip->group = group++;
337 if (chip->base == NULL)
338 chip->base = S5P_VA_GPIO2 + (i) * 0x20;
341 samsung_gpiolib_add_4bit_chips(exynos4_gpio_part2_4bit, nr_chips);
343 /* GPIO part 3 */
345 chip = exynos4_gpio_part3_4bit;
346 nr_chips = ARRAY_SIZE(exynos4_gpio_part3_4bit);
348 for (i = 0; i < nr_chips; i++, chip++) {
349 if (chip->config == NULL) {
350 chip->config = &gpio_cfg;
351 /* Assign the GPIO interrupt group */
352 chip->group = group++;
354 if (chip->base == NULL)
355 chip->base = S5P_VA_GPIO3 + (i) * 0x20;
358 samsung_gpiolib_add_4bit_chips(exynos4_gpio_part3_4bit, nr_chips);
359 s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
360 s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
362 return 0;
364 core_initcall(exynos4_gpiolib_init);