2 * arch/arm/plat-s5pc1xx/gpiolib.c
4 * Copyright 2009 Samsung Electronics Co
5 * Kyungmin Park <kyungmin.park@samsung.com>
7 * S5PC1XX - GPIOlib support
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.
14 #include <linux/kernel.h>
15 #include <linux/irq.h>
17 #include <linux/gpio.h>
20 #include <mach/regs-gpio.h>
22 #include <plat/gpio-core.h>
23 #include <plat/gpio-cfg.h>
24 #include <plat/gpio-cfg-helpers.h>
26 /* S5PC100 GPIO bank summary:
28 * Bank GPIOs Style INT Type
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
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
65 static int s5pc1xx_gpiolib_to_irq(struct gpio_chip
*chip
, unsigned int offset
)
67 return S3C_IRQ_GPIO(chip
->base
+ offset
);
70 static int s5pc1xx_gpiolib_to_eint(struct gpio_chip
*chip
, unsigned int offset
)
74 base
= chip
->base
- S5PC100_GPH0(0);
76 return IRQ_EINT(offset
);
77 base
= chip
->base
- S5PC100_GPH1(0);
79 return IRQ_EINT(8 + offset
);
80 base
= chip
->base
- S5PC100_GPH2(0);
82 return IRQ_EINT(16 + offset
);
83 base
= chip
->base
- S5PC100_GPH3(0);
85 return IRQ_EINT(24 + offset
);
89 static struct s3c_gpio_cfg gpio_cfg
= {
90 .set_config
= s3c_gpio_setcfg_s3c64xx_4bit
,
91 .set_pull
= s3c_gpio_setpull_updown
,
92 .get_pull
= s3c_gpio_getpull_updown
,
95 static struct s3c_gpio_cfg gpio_cfg_eint
= {
97 .set_config
= s3c_gpio_setcfg_s3c64xx_4bit
,
98 .set_pull
= s3c_gpio_setpull_updown
,
99 .get_pull
= s3c_gpio_getpull_updown
,
102 static struct s3c_gpio_cfg gpio_cfg_noint
= {
103 .set_config
= s3c_gpio_setcfg_s3c64xx_4bit
,
104 .set_pull
= s3c_gpio_setpull_updown
,
105 .get_pull
= s3c_gpio_getpull_updown
,
108 static struct s3c_gpio_chip s5pc100_gpio_chips
[] = {
110 .base
= S5PC100_GPA0_BASE
,
113 .base
= S5PC100_GPA0(0),
114 .ngpio
= S5PC100_GPIO_A0_NR
,
118 .base
= S5PC100_GPA1_BASE
,
121 .base
= S5PC100_GPA1(0),
122 .ngpio
= S5PC100_GPIO_A1_NR
,
126 .base
= S5PC100_GPB_BASE
,
129 .base
= S5PC100_GPB(0),
130 .ngpio
= S5PC100_GPIO_B_NR
,
134 .base
= S5PC100_GPC_BASE
,
137 .base
= S5PC100_GPC(0),
138 .ngpio
= S5PC100_GPIO_C_NR
,
142 .base
= S5PC100_GPD_BASE
,
145 .base
= S5PC100_GPD(0),
146 .ngpio
= S5PC100_GPIO_D_NR
,
150 .base
= S5PC100_GPE0_BASE
,
153 .base
= S5PC100_GPE0(0),
154 .ngpio
= S5PC100_GPIO_E0_NR
,
158 .base
= S5PC100_GPE1_BASE
,
161 .base
= S5PC100_GPE1(0),
162 .ngpio
= S5PC100_GPIO_E1_NR
,
166 .base
= S5PC100_GPF0_BASE
,
169 .base
= S5PC100_GPF0(0),
170 .ngpio
= S5PC100_GPIO_F0_NR
,
174 .base
= S5PC100_GPF1_BASE
,
177 .base
= S5PC100_GPF1(0),
178 .ngpio
= S5PC100_GPIO_F1_NR
,
182 .base
= S5PC100_GPF2_BASE
,
185 .base
= S5PC100_GPF2(0),
186 .ngpio
= S5PC100_GPIO_F2_NR
,
190 .base
= S5PC100_GPF3_BASE
,
193 .base
= S5PC100_GPF3(0),
194 .ngpio
= S5PC100_GPIO_F3_NR
,
198 .base
= S5PC100_GPG0_BASE
,
201 .base
= S5PC100_GPG0(0),
202 .ngpio
= S5PC100_GPIO_G0_NR
,
206 .base
= S5PC100_GPG1_BASE
,
209 .base
= S5PC100_GPG1(0),
210 .ngpio
= S5PC100_GPIO_G1_NR
,
214 .base
= S5PC100_GPG2_BASE
,
217 .base
= S5PC100_GPG2(0),
218 .ngpio
= S5PC100_GPIO_G2_NR
,
222 .base
= S5PC100_GPG3_BASE
,
225 .base
= S5PC100_GPG3(0),
226 .ngpio
= S5PC100_GPIO_G3_NR
,
230 .base
= S5PC100_GPH0_BASE
,
231 .config
= &gpio_cfg_eint
,
233 .base
= S5PC100_GPH0(0),
234 .ngpio
= S5PC100_GPIO_H0_NR
,
238 .base
= S5PC100_GPH1_BASE
,
239 .config
= &gpio_cfg_eint
,
241 .base
= S5PC100_GPH1(0),
242 .ngpio
= S5PC100_GPIO_H1_NR
,
246 .base
= S5PC100_GPH2_BASE
,
247 .config
= &gpio_cfg_eint
,
249 .base
= S5PC100_GPH2(0),
250 .ngpio
= S5PC100_GPIO_H2_NR
,
254 .base
= S5PC100_GPH3_BASE
,
255 .config
= &gpio_cfg_eint
,
257 .base
= S5PC100_GPH3(0),
258 .ngpio
= S5PC100_GPIO_H3_NR
,
262 .base
= S5PC100_GPI_BASE
,
265 .base
= S5PC100_GPI(0),
266 .ngpio
= S5PC100_GPIO_I_NR
,
270 .base
= S5PC100_GPJ0_BASE
,
273 .base
= S5PC100_GPJ0(0),
274 .ngpio
= S5PC100_GPIO_J0_NR
,
278 .base
= S5PC100_GPJ1_BASE
,
281 .base
= S5PC100_GPJ1(0),
282 .ngpio
= S5PC100_GPIO_J1_NR
,
286 .base
= S5PC100_GPJ2_BASE
,
289 .base
= S5PC100_GPJ2(0),
290 .ngpio
= S5PC100_GPIO_J2_NR
,
294 .base
= S5PC100_GPJ3_BASE
,
297 .base
= S5PC100_GPJ3(0),
298 .ngpio
= S5PC100_GPIO_J3_NR
,
302 .base
= S5PC100_GPJ4_BASE
,
305 .base
= S5PC100_GPJ4(0),
306 .ngpio
= S5PC100_GPIO_J4_NR
,
310 .base
= S5PC100_GPK0_BASE
,
311 .config
= &gpio_cfg_noint
,
313 .base
= S5PC100_GPK0(0),
314 .ngpio
= S5PC100_GPIO_K0_NR
,
318 .base
= S5PC100_GPK1_BASE
,
319 .config
= &gpio_cfg_noint
,
321 .base
= S5PC100_GPK1(0),
322 .ngpio
= S5PC100_GPIO_K1_NR
,
326 .base
= S5PC100_GPK2_BASE
,
327 .config
= &gpio_cfg_noint
,
329 .base
= S5PC100_GPK2(0),
330 .ngpio
= S5PC100_GPIO_K2_NR
,
334 .base
= S5PC100_GPK3_BASE
,
335 .config
= &gpio_cfg_noint
,
337 .base
= S5PC100_GPK3(0),
338 .ngpio
= S5PC100_GPIO_K3_NR
,
342 .base
= S5PC100_GPL0_BASE
,
343 .config
= &gpio_cfg_noint
,
345 .base
= S5PC100_GPL0(0),
346 .ngpio
= S5PC100_GPIO_L0_NR
,
350 .base
= S5PC100_GPL1_BASE
,
351 .config
= &gpio_cfg_noint
,
353 .base
= S5PC100_GPL1(0),
354 .ngpio
= S5PC100_GPIO_L1_NR
,
358 .base
= S5PC100_GPL2_BASE
,
359 .config
= &gpio_cfg_noint
,
361 .base
= S5PC100_GPL2(0),
362 .ngpio
= S5PC100_GPIO_L2_NR
,
366 .base
= S5PC100_GPL3_BASE
,
367 .config
= &gpio_cfg_noint
,
369 .base
= S5PC100_GPL3(0),
370 .ngpio
= S5PC100_GPIO_L3_NR
,
374 .base
= S5PC100_GPL4_BASE
,
375 .config
= &gpio_cfg_noint
,
377 .base
= S5PC100_GPL4(0),
378 .ngpio
= S5PC100_GPIO_L4_NR
,
384 /* FIXME move from irq-gpio.c */
385 extern struct irq_chip s5pc1xx_gpioint
;
386 extern void s5pc1xx_irq_gpioint_handler(unsigned int irq
, struct irq_desc
*desc
);
388 static __init
void s5pc100_gpiolib_link(struct s3c_gpio_chip
*chip
)
392 if (chip
->config
== &gpio_cfg
) {
395 chip
->chip
.to_irq
= s5pc1xx_gpiolib_to_irq
;
397 for (i
= 0; i
< chip
->chip
.ngpio
; i
++) {
398 irq
= S3C_IRQ_GPIO_BASE
+ chip
->chip
.base
+ i
;
399 set_irq_chip(irq
, &s5pc1xx_gpioint
);
400 set_irq_data(irq
, &chip
->chip
);
401 set_irq_handler(irq
, handle_level_irq
);
402 set_irq_flags(irq
, IRQF_VALID
);
404 } else if (chip
->config
== &gpio_cfg_eint
)
405 chip
->chip
.to_irq
= s5pc1xx_gpiolib_to_eint
;
409 static __init
int s5pc1xx_gpiolib_init(void)
411 struct s3c_gpio_chip
*chip
;
414 chip
= s5pc100_gpio_chips
;
415 nr_chips
= ARRAY_SIZE(s5pc100_gpio_chips
);
417 for (; nr_chips
> 0; nr_chips
--, chip
++)
418 s5pc100_gpiolib_link(chip
);
420 samsung_gpiolib_add_4bit_chips(s5pc100_gpio_chips
,
421 ARRAY_SIZE(s5pc100_gpio_chips
));
424 set_irq_chained_handler(IRQ_GPIOINT
, s5pc1xx_irq_gpioint_handler
);
428 core_initcall(s5pc1xx_gpiolib_init
);