blob: def4ff83e0518d939e02db15647935587f536bd9 [file] [log] [blame]
Kyungmin Parkb0d52172009-11-17 08:41:16 +01001/*
Marek Szyprowskiacc84702010-05-20 07:51:08 +02002 * arch/arm/plat-s5pc100/gpiolib.c
Kyungmin Parkb0d52172009-11-17 08:41:16 +01003 *
4 * Copyright 2009 Samsung Electronics Co
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 *
Marek Szyprowskiacc84702010-05-20 07:51:08 +02007 * S5PC100 - GPIOlib support
Kyungmin Parkb0d52172009-11-17 08:41:16 +01008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/kernel.h>
15#include <linux/irq.h>
16#include <linux/io.h>
17#include <linux/gpio.h>
18
19#include <mach/map.h>
Marek Szyprowski79044492010-05-18 12:38:41 +020020#include <mach/regs-gpio.h>
Kyungmin Parkb0d52172009-11-17 08:41:16 +010021
Ben Dookse856bb12010-01-19 17:14:46 +090022#include <plat/gpio-core.h>
Kyungmin Parkb0d52172009-11-17 08:41:16 +010023#include <plat/gpio-cfg.h>
24#include <plat/gpio-cfg-helpers.h>
Kyungmin Parkb0d52172009-11-17 08:41:16 +010025
26/* S5PC100 GPIO bank summary:
27 *
28 * Bank GPIOs Style INT Type
29 * A0 8 4Bit GPIO_INT0
30 * A1 5 4Bit GPIO_INT1
31 * B 8 4Bit GPIO_INT2
32 * C 5 4Bit GPIO_INT3
33 * D 7 4Bit GPIO_INT4
34 * E0 8 4Bit GPIO_INT5
35 * E1 6 4Bit GPIO_INT6
36 * F0 8 4Bit GPIO_INT7
37 * F1 8 4Bit GPIO_INT8
38 * F2 8 4Bit GPIO_INT9
39 * F3 4 4Bit GPIO_INT10
40 * G0 8 4Bit GPIO_INT11
41 * G1 3 4Bit GPIO_INT12
42 * G2 7 4Bit GPIO_INT13
43 * G3 7 4Bit GPIO_INT14
44 * H0 8 4Bit WKUP_INT
45 * H1 8 4Bit WKUP_INT
46 * H2 8 4Bit WKUP_INT
47 * H3 8 4Bit WKUP_INT
48 * I 8 4Bit GPIO_INT15
49 * J0 8 4Bit GPIO_INT16
50 * J1 5 4Bit GPIO_INT17
51 * J2 8 4Bit GPIO_INT18
52 * J3 8 4Bit GPIO_INT19
53 * J4 4 4Bit GPIO_INT20
54 * K0 8 4Bit None
55 * K1 6 4Bit None
56 * K2 8 4Bit None
57 * K3 8 4Bit None
58 * L0 8 4Bit None
59 * L1 8 4Bit None
60 * L2 8 4Bit None
61 * L3 8 4Bit None
62 */
63
Kyungmin Parkb0d52172009-11-17 08:41:16 +010064static struct s3c_gpio_cfg gpio_cfg = {
65 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
66 .set_pull = s3c_gpio_setpull_updown,
67 .get_pull = s3c_gpio_getpull_updown,
68};
69
70static struct s3c_gpio_cfg gpio_cfg_eint = {
71 .cfg_eint = 0xf,
72 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
73 .set_pull = s3c_gpio_setpull_updown,
74 .get_pull = s3c_gpio_getpull_updown,
75};
76
77static struct s3c_gpio_cfg gpio_cfg_noint = {
78 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
79 .set_pull = s3c_gpio_setpull_updown,
80 .get_pull = s3c_gpio_getpull_updown,
81};
82
83static struct s3c_gpio_chip s5pc100_gpio_chips[] = {
84 {
85 .base = S5PC100_GPA0_BASE,
86 .config = &gpio_cfg,
87 .chip = {
88 .base = S5PC100_GPA0(0),
89 .ngpio = S5PC100_GPIO_A0_NR,
90 .label = "GPA0",
91 },
92 }, {
93 .base = S5PC100_GPA1_BASE,
94 .config = &gpio_cfg,
95 .chip = {
96 .base = S5PC100_GPA1(0),
97 .ngpio = S5PC100_GPIO_A1_NR,
98 .label = "GPA1",
99 },
100 }, {
101 .base = S5PC100_GPB_BASE,
102 .config = &gpio_cfg,
103 .chip = {
104 .base = S5PC100_GPB(0),
105 .ngpio = S5PC100_GPIO_B_NR,
106 .label = "GPB",
107 },
108 }, {
109 .base = S5PC100_GPC_BASE,
110 .config = &gpio_cfg,
111 .chip = {
112 .base = S5PC100_GPC(0),
113 .ngpio = S5PC100_GPIO_C_NR,
114 .label = "GPC",
115 },
116 }, {
117 .base = S5PC100_GPD_BASE,
118 .config = &gpio_cfg,
119 .chip = {
120 .base = S5PC100_GPD(0),
121 .ngpio = S5PC100_GPIO_D_NR,
122 .label = "GPD",
123 },
124 }, {
125 .base = S5PC100_GPE0_BASE,
126 .config = &gpio_cfg,
127 .chip = {
128 .base = S5PC100_GPE0(0),
129 .ngpio = S5PC100_GPIO_E0_NR,
130 .label = "GPE0",
131 },
132 }, {
133 .base = S5PC100_GPE1_BASE,
134 .config = &gpio_cfg,
135 .chip = {
136 .base = S5PC100_GPE1(0),
137 .ngpio = S5PC100_GPIO_E1_NR,
138 .label = "GPE1",
139 },
140 }, {
141 .base = S5PC100_GPF0_BASE,
142 .config = &gpio_cfg,
143 .chip = {
144 .base = S5PC100_GPF0(0),
145 .ngpio = S5PC100_GPIO_F0_NR,
146 .label = "GPF0",
147 },
148 }, {
149 .base = S5PC100_GPF1_BASE,
150 .config = &gpio_cfg,
151 .chip = {
152 .base = S5PC100_GPF1(0),
153 .ngpio = S5PC100_GPIO_F1_NR,
154 .label = "GPF1",
155 },
156 }, {
157 .base = S5PC100_GPF2_BASE,
158 .config = &gpio_cfg,
159 .chip = {
160 .base = S5PC100_GPF2(0),
161 .ngpio = S5PC100_GPIO_F2_NR,
162 .label = "GPF2",
163 },
164 }, {
165 .base = S5PC100_GPF3_BASE,
166 .config = &gpio_cfg,
167 .chip = {
168 .base = S5PC100_GPF3(0),
169 .ngpio = S5PC100_GPIO_F3_NR,
170 .label = "GPF3",
171 },
172 }, {
173 .base = S5PC100_GPG0_BASE,
174 .config = &gpio_cfg,
175 .chip = {
176 .base = S5PC100_GPG0(0),
177 .ngpio = S5PC100_GPIO_G0_NR,
178 .label = "GPG0",
179 },
180 }, {
181 .base = S5PC100_GPG1_BASE,
182 .config = &gpio_cfg,
183 .chip = {
184 .base = S5PC100_GPG1(0),
185 .ngpio = S5PC100_GPIO_G1_NR,
186 .label = "GPG1",
187 },
188 }, {
189 .base = S5PC100_GPG2_BASE,
190 .config = &gpio_cfg,
191 .chip = {
192 .base = S5PC100_GPG2(0),
193 .ngpio = S5PC100_GPIO_G2_NR,
194 .label = "GPG2",
195 },
196 }, {
197 .base = S5PC100_GPG3_BASE,
198 .config = &gpio_cfg,
199 .chip = {
200 .base = S5PC100_GPG3(0),
201 .ngpio = S5PC100_GPIO_G3_NR,
202 .label = "GPG3",
203 },
204 }, {
205 .base = S5PC100_GPH0_BASE,
206 .config = &gpio_cfg_eint,
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900207 .irq_base = IRQ_EINT(0),
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100208 .chip = {
209 .base = S5PC100_GPH0(0),
210 .ngpio = S5PC100_GPIO_H0_NR,
211 .label = "GPH0",
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900212 .to_irq = samsung_gpiolib_to_irq,
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100213 },
214 }, {
215 .base = S5PC100_GPH1_BASE,
216 .config = &gpio_cfg_eint,
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900217 .irq_base = IRQ_EINT(8),
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100218 .chip = {
219 .base = S5PC100_GPH1(0),
220 .ngpio = S5PC100_GPIO_H1_NR,
221 .label = "GPH1",
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900222 .to_irq = samsung_gpiolib_to_irq,
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100223 },
224 }, {
225 .base = S5PC100_GPH2_BASE,
226 .config = &gpio_cfg_eint,
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900227 .irq_base = IRQ_EINT(16),
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100228 .chip = {
229 .base = S5PC100_GPH2(0),
230 .ngpio = S5PC100_GPIO_H2_NR,
231 .label = "GPH2",
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900232 .to_irq = samsung_gpiolib_to_irq,
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100233 },
234 }, {
235 .base = S5PC100_GPH3_BASE,
236 .config = &gpio_cfg_eint,
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900237 .irq_base = IRQ_EINT(24),
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100238 .chip = {
239 .base = S5PC100_GPH3(0),
240 .ngpio = S5PC100_GPIO_H3_NR,
241 .label = "GPH3",
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900242 .to_irq = samsung_gpiolib_to_irq,
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100243 },
244 }, {
245 .base = S5PC100_GPI_BASE,
246 .config = &gpio_cfg,
247 .chip = {
248 .base = S5PC100_GPI(0),
249 .ngpio = S5PC100_GPIO_I_NR,
250 .label = "GPI",
251 },
252 }, {
253 .base = S5PC100_GPJ0_BASE,
254 .config = &gpio_cfg,
255 .chip = {
256 .base = S5PC100_GPJ0(0),
257 .ngpio = S5PC100_GPIO_J0_NR,
258 .label = "GPJ0",
259 },
260 }, {
261 .base = S5PC100_GPJ1_BASE,
262 .config = &gpio_cfg,
263 .chip = {
264 .base = S5PC100_GPJ1(0),
265 .ngpio = S5PC100_GPIO_J1_NR,
266 .label = "GPJ1",
267 },
268 }, {
269 .base = S5PC100_GPJ2_BASE,
270 .config = &gpio_cfg,
271 .chip = {
272 .base = S5PC100_GPJ2(0),
273 .ngpio = S5PC100_GPIO_J2_NR,
274 .label = "GPJ2",
275 },
276 }, {
277 .base = S5PC100_GPJ3_BASE,
278 .config = &gpio_cfg,
279 .chip = {
280 .base = S5PC100_GPJ3(0),
281 .ngpio = S5PC100_GPIO_J3_NR,
282 .label = "GPJ3",
283 },
284 }, {
285 .base = S5PC100_GPJ4_BASE,
286 .config = &gpio_cfg,
287 .chip = {
288 .base = S5PC100_GPJ4(0),
289 .ngpio = S5PC100_GPIO_J4_NR,
290 .label = "GPJ4",
291 },
292 }, {
293 .base = S5PC100_GPK0_BASE,
294 .config = &gpio_cfg_noint,
295 .chip = {
296 .base = S5PC100_GPK0(0),
297 .ngpio = S5PC100_GPIO_K0_NR,
298 .label = "GPK0",
299 },
300 }, {
301 .base = S5PC100_GPK1_BASE,
302 .config = &gpio_cfg_noint,
303 .chip = {
304 .base = S5PC100_GPK1(0),
305 .ngpio = S5PC100_GPIO_K1_NR,
306 .label = "GPK1",
307 },
308 }, {
309 .base = S5PC100_GPK2_BASE,
310 .config = &gpio_cfg_noint,
311 .chip = {
312 .base = S5PC100_GPK2(0),
313 .ngpio = S5PC100_GPIO_K2_NR,
314 .label = "GPK2",
315 },
316 }, {
317 .base = S5PC100_GPK3_BASE,
318 .config = &gpio_cfg_noint,
319 .chip = {
320 .base = S5PC100_GPK3(0),
321 .ngpio = S5PC100_GPIO_K3_NR,
322 .label = "GPK3",
323 },
324 }, {
325 .base = S5PC100_GPL0_BASE,
326 .config = &gpio_cfg_noint,
327 .chip = {
328 .base = S5PC100_GPL0(0),
329 .ngpio = S5PC100_GPIO_L0_NR,
330 .label = "GPL0",
331 },
332 }, {
333 .base = S5PC100_GPL1_BASE,
334 .config = &gpio_cfg_noint,
335 .chip = {
336 .base = S5PC100_GPL1(0),
337 .ngpio = S5PC100_GPIO_L1_NR,
338 .label = "GPL1",
339 },
340 }, {
341 .base = S5PC100_GPL2_BASE,
342 .config = &gpio_cfg_noint,
343 .chip = {
344 .base = S5PC100_GPL2(0),
345 .ngpio = S5PC100_GPIO_L2_NR,
346 .label = "GPL2",
347 },
348 }, {
349 .base = S5PC100_GPL3_BASE,
350 .config = &gpio_cfg_noint,
351 .chip = {
352 .base = S5PC100_GPL3(0),
353 .ngpio = S5PC100_GPIO_L3_NR,
354 .label = "GPL3",
355 },
356 }, {
357 .base = S5PC100_GPL4_BASE,
358 .config = &gpio_cfg_noint,
359 .chip = {
360 .base = S5PC100_GPL4(0),
361 .ngpio = S5PC100_GPIO_L4_NR,
362 .label = "GPL4",
363 },
364 },
365};
366
Marek Szyprowskiacc84702010-05-20 07:51:08 +0200367static __init int s5pc100_gpiolib_init(void)
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100368{
Marek Szyprowski252b8ef2010-05-18 12:38:40 +0200369 struct s3c_gpio_chip *chip;
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100370 int nr_chips;
Joonyoung Shim7e479352010-10-01 11:18:05 +0900371 int gpioint_group = 0;
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100372
Marek Szyprowski252b8ef2010-05-18 12:38:40 +0200373 chip = s5pc100_gpio_chips;
374 nr_chips = ARRAY_SIZE(s5pc100_gpio_chips);
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100375
Joonyoung Shim7e479352010-10-01 11:18:05 +0900376 for (; nr_chips > 0; nr_chips--, chip++) {
377 if (chip->config == &gpio_cfg) {
378 /* gpio interrupts */
379 chip->group = gpioint_group++;
380 }
381 }
Marek Szyprowski252b8ef2010-05-18 12:38:40 +0200382
383 samsung_gpiolib_add_4bit_chips(s5pc100_gpio_chips,
384 ARRAY_SIZE(s5pc100_gpio_chips));
Marek Szyprowski23686a02010-05-20 07:51:09 +0200385
Kyungmin Parkb0d52172009-11-17 08:41:16 +0100386 return 0;
387}
Marek Szyprowskiacc84702010-05-20 07:51:08 +0200388core_initcall(s5pc100_gpiolib_init);