1 /* linux/arch/arm/mach-exynos4/gpiolib.c
3 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * EXYNOS4 - GPIOlib support
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/kernel.h>
14 #include <linux/irq.h>
16 #include <linux/gpio.h>
20 #include <plat/gpio-core.h>
21 #include <plat/gpio-cfg.h>
22 #include <plat/gpio-cfg-helpers.h>
24 int s3c_gpio_setpull_exynos4(struct s3c_gpio_chip *chip,
25 unsigned int off, s3c_gpio_pull_t pull)
27 if (pull == S3C_GPIO_PULL_UP)
30 return s3c_gpio_setpull_updown(chip, off, pull);
33 s3c_gpio_pull_t s3c_gpio_getpull_exynos4(struct s3c_gpio_chip *chip,
38 pull = s3c_gpio_getpull_updown(chip, off);
40 pull = S3C_GPIO_PULL_UP;
45 static struct s3c_gpio_cfg gpio_cfg = {
46 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
47 .set_pull = s3c_gpio_setpull_exynos4,
48 .get_pull = s3c_gpio_getpull_exynos4,
51 static struct s3c_gpio_cfg gpio_cfg_noint = {
52 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
53 .set_pull = s3c_gpio_setpull_exynos4,
54 .get_pull = s3c_gpio_getpull_exynos4,
58 * Following are the gpio banks in v310.
60 * The 'config' member when left to NULL, is initialized to the default
61 * structure gpio_cfg in the init function below.
63 * The 'base' member is also initialized in the init function below.
64 * Note: The initialization of 'base' member of s3c_gpio_chip structure
65 * uses the above macro and depends on the banks being listed in order here.
67 static struct s3c_gpio_chip exynos4_gpio_part1_4bit[] = {
70 .base = EXYNOS4_GPA0(0),
71 .ngpio = EXYNOS4_GPIO_A0_NR,
76 .base = EXYNOS4_GPA1(0),
77 .ngpio = EXYNOS4_GPIO_A1_NR,
82 .base = EXYNOS4_GPB(0),
83 .ngpio = EXYNOS4_GPIO_B_NR,
88 .base = EXYNOS4_GPC0(0),
89 .ngpio = EXYNOS4_GPIO_C0_NR,
94 .base = EXYNOS4_GPC1(0),
95 .ngpio = EXYNOS4_GPIO_C1_NR,
100 .base = EXYNOS4_GPD0(0),
101 .ngpio = EXYNOS4_GPIO_D0_NR,
106 .base = EXYNOS4_GPD1(0),
107 .ngpio = EXYNOS4_GPIO_D1_NR,
112 .base = EXYNOS4_GPE0(0),
113 .ngpio = EXYNOS4_GPIO_E0_NR,
118 .base = EXYNOS4_GPE1(0),
119 .ngpio = EXYNOS4_GPIO_E1_NR,
124 .base = EXYNOS4_GPE2(0),
125 .ngpio = EXYNOS4_GPIO_E2_NR,
130 .base = EXYNOS4_GPE3(0),
131 .ngpio = EXYNOS4_GPIO_E3_NR,
136 .base = EXYNOS4_GPE4(0),
137 .ngpio = EXYNOS4_GPIO_E4_NR,
142 .base = EXYNOS4_GPF0(0),
143 .ngpio = EXYNOS4_GPIO_F0_NR,
148 .base = EXYNOS4_GPF1(0),
149 .ngpio = EXYNOS4_GPIO_F1_NR,
154 .base = EXYNOS4_GPF2(0),
155 .ngpio = EXYNOS4_GPIO_F2_NR,
160 .base = EXYNOS4_GPF3(0),
161 .ngpio = EXYNOS4_GPIO_F3_NR,
167 static struct s3c_gpio_chip exynos4_gpio_part2_4bit[] = {
170 .base = EXYNOS4_GPJ0(0),
171 .ngpio = EXYNOS4_GPIO_J0_NR,
176 .base = EXYNOS4_GPJ1(0),
177 .ngpio = EXYNOS4_GPIO_J1_NR,
182 .base = EXYNOS4_GPK0(0),
183 .ngpio = EXYNOS4_GPIO_K0_NR,
188 .base = EXYNOS4_GPK1(0),
189 .ngpio = EXYNOS4_GPIO_K1_NR,
194 .base = EXYNOS4_GPK2(0),
195 .ngpio = EXYNOS4_GPIO_K2_NR,
200 .base = EXYNOS4_GPK3(0),
201 .ngpio = EXYNOS4_GPIO_K3_NR,
206 .base = EXYNOS4_GPL0(0),
207 .ngpio = EXYNOS4_GPIO_L0_NR,
212 .base = EXYNOS4_GPL1(0),
213 .ngpio = EXYNOS4_GPIO_L1_NR,
218 .base = EXYNOS4_GPL2(0),
219 .ngpio = EXYNOS4_GPIO_L2_NR,
223 .config = &gpio_cfg_noint,
225 .base = EXYNOS4_GPY0(0),
226 .ngpio = EXYNOS4_GPIO_Y0_NR,
230 .config = &gpio_cfg_noint,
232 .base = EXYNOS4_GPY1(0),
233 .ngpio = EXYNOS4_GPIO_Y1_NR,
237 .config = &gpio_cfg_noint,
239 .base = EXYNOS4_GPY2(0),
240 .ngpio = EXYNOS4_GPIO_Y2_NR,
244 .config = &gpio_cfg_noint,
246 .base = EXYNOS4_GPY3(0),
247 .ngpio = EXYNOS4_GPIO_Y3_NR,
251 .config = &gpio_cfg_noint,
253 .base = EXYNOS4_GPY4(0),
254 .ngpio = EXYNOS4_GPIO_Y4_NR,
258 .config = &gpio_cfg_noint,
260 .base = EXYNOS4_GPY5(0),
261 .ngpio = EXYNOS4_GPIO_Y5_NR,
265 .config = &gpio_cfg_noint,
267 .base = EXYNOS4_GPY6(0),
268 .ngpio = EXYNOS4_GPIO_Y6_NR,
272 .base = (S5P_VA_GPIO2 + 0xC00),
273 .config = &gpio_cfg_noint,
274 .irq_base = IRQ_EINT(0),
276 .base = EXYNOS4_GPX0(0),
277 .ngpio = EXYNOS4_GPIO_X0_NR,
279 .to_irq = samsung_gpiolib_to_irq,
282 .base = (S5P_VA_GPIO2 + 0xC20),
283 .config = &gpio_cfg_noint,
284 .irq_base = IRQ_EINT(8),
286 .base = EXYNOS4_GPX1(0),
287 .ngpio = EXYNOS4_GPIO_X1_NR,
289 .to_irq = samsung_gpiolib_to_irq,
292 .base = (S5P_VA_GPIO2 + 0xC40),
293 .config = &gpio_cfg_noint,
294 .irq_base = IRQ_EINT(16),
296 .base = EXYNOS4_GPX2(0),
297 .ngpio = EXYNOS4_GPIO_X2_NR,
299 .to_irq = samsung_gpiolib_to_irq,
302 .base = (S5P_VA_GPIO2 + 0xC60),
303 .config = &gpio_cfg_noint,
304 .irq_base = IRQ_EINT(24),
306 .base = EXYNOS4_GPX3(0),
307 .ngpio = EXYNOS4_GPIO_X3_NR,
309 .to_irq = samsung_gpiolib_to_irq,
314 static struct s3c_gpio_chip exynos4_gpio_part3_4bit[] = {
317 .base = EXYNOS4_GPZ(0),
318 .ngpio = EXYNOS4_GPIO_Z_NR,
324 static __init int exynos4_gpiolib_init(void)
326 struct s3c_gpio_chip *chip;
333 chip = exynos4_gpio_part1_4bit;
334 nr_chips = ARRAY_SIZE(exynos4_gpio_part1_4bit);
336 for (i = 0; i < nr_chips; i++, chip++) {
337 if (chip->config == NULL) {
338 chip->config = &gpio_cfg;
339 /* Assign the GPIO interrupt group */
340 chip->group = group++;
342 if (chip->base == NULL)
343 chip->base = S5P_VA_GPIO1 + (i) * 0x20;
346 samsung_gpiolib_add_4bit_chips(exynos4_gpio_part1_4bit, nr_chips);
350 chip = exynos4_gpio_part2_4bit;
351 nr_chips = ARRAY_SIZE(exynos4_gpio_part2_4bit);
353 for (i = 0; i < nr_chips; i++, chip++) {
354 if (chip->config == NULL) {
355 chip->config = &gpio_cfg;
356 /* Assign the GPIO interrupt group */
357 chip->group = group++;
359 if (chip->base == NULL)
360 chip->base = S5P_VA_GPIO2 + (i) * 0x20;
363 samsung_gpiolib_add_4bit_chips(exynos4_gpio_part2_4bit, nr_chips);
367 chip = exynos4_gpio_part3_4bit;
368 nr_chips = ARRAY_SIZE(exynos4_gpio_part3_4bit);
370 for (i = 0; i < nr_chips; i++, chip++) {
371 if (chip->config == NULL) {
372 chip->config = &gpio_cfg;
373 /* Assign the GPIO interrupt group */
374 chip->group = group++;
376 if (chip->base == NULL)
377 chip->base = S5P_VA_GPIO3 + (i) * 0x20;
380 samsung_gpiolib_add_4bit_chips(exynos4_gpio_part3_4bit, nr_chips);
381 s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
382 s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
386 core_initcall(exynos4_gpiolib_init);