1 /* arch/arm/plat-s3c64xx/gpiolib.c
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
8 * S3C64XX - GPIOlib support
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/kernel.h>
16 #include <linux/irq.h>
18 #include <linux/gpio.h>
22 #include <plat/gpio-core.h>
23 #include <plat/gpio-cfg.h>
24 #include <plat/gpio-cfg-helpers.h>
25 #include <mach/regs-gpio.h>
29 * Bank GPIOs Style SlpCon ExtInt Group
40 * K 16 4Bit[2] No None
41 * L 15 4Bit[2] No None
42 * M 6 4Bit No IRQ_EINT
43 * N 16 2Bit No IRQ_EINT
48 * [1] BANKF pins 14,15 do not form part of the external interrupt sources
49 * [2] BANK has two control registers, GPxCON0 and GPxCON1
52 static struct s3c_gpio_cfg gpio_4bit_cfg_noint = {
53 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
54 .get_config = s3c_gpio_getcfg_s3c64xx_4bit,
55 .set_pull = s3c_gpio_setpull_updown,
56 .get_pull = s3c_gpio_getpull_updown,
59 static struct s3c_gpio_cfg gpio_4bit_cfg_eint0111 = {
61 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
62 .get_config = s3c_gpio_getcfg_s3c64xx_4bit,
63 .set_pull = s3c_gpio_setpull_updown,
64 .get_pull = s3c_gpio_getpull_updown,
67 static struct s3c_gpio_cfg gpio_4bit_cfg_eint0011 = {
69 .get_config = s3c_gpio_getcfg_s3c64xx_4bit,
70 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
71 .set_pull = s3c_gpio_setpull_updown,
72 .get_pull = s3c_gpio_getpull_updown,
75 int s3c64xx_gpio2int_gpm(struct gpio_chip *chip, unsigned pin)
77 return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO;
80 static struct s3c_gpio_chip gpio_4bit[] = {
82 .base = S3C64XX_GPA_BASE,
83 .config = &gpio_4bit_cfg_eint0111,
85 .base = S3C64XX_GPA(0),
86 .ngpio = S3C64XX_GPIO_A_NR,
90 .base = S3C64XX_GPB_BASE,
91 .config = &gpio_4bit_cfg_eint0111,
93 .base = S3C64XX_GPB(0),
94 .ngpio = S3C64XX_GPIO_B_NR,
98 .base = S3C64XX_GPC_BASE,
99 .config = &gpio_4bit_cfg_eint0111,
101 .base = S3C64XX_GPC(0),
102 .ngpio = S3C64XX_GPIO_C_NR,
106 .base = S3C64XX_GPD_BASE,
107 .config = &gpio_4bit_cfg_eint0111,
109 .base = S3C64XX_GPD(0),
110 .ngpio = S3C64XX_GPIO_D_NR,
114 .base = S3C64XX_GPE_BASE,
115 .config = &gpio_4bit_cfg_noint,
117 .base = S3C64XX_GPE(0),
118 .ngpio = S3C64XX_GPIO_E_NR,
122 .base = S3C64XX_GPG_BASE,
123 .config = &gpio_4bit_cfg_eint0111,
125 .base = S3C64XX_GPG(0),
126 .ngpio = S3C64XX_GPIO_G_NR,
130 .base = S3C64XX_GPM_BASE,
131 .config = &gpio_4bit_cfg_eint0011,
133 .base = S3C64XX_GPM(0),
134 .ngpio = S3C64XX_GPIO_M_NR,
136 .to_irq = s3c64xx_gpio2int_gpm,
141 int s3c64xx_gpio2int_gpl(struct gpio_chip *chip, unsigned pin)
143 return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO;
146 static struct s3c_gpio_chip gpio_4bit2[] = {
148 .base = S3C64XX_GPH_BASE + 0x4,
149 .config = &gpio_4bit_cfg_eint0111,
151 .base = S3C64XX_GPH(0),
152 .ngpio = S3C64XX_GPIO_H_NR,
156 .base = S3C64XX_GPK_BASE + 0x4,
157 .config = &gpio_4bit_cfg_noint,
159 .base = S3C64XX_GPK(0),
160 .ngpio = S3C64XX_GPIO_K_NR,
164 .base = S3C64XX_GPL_BASE + 0x4,
165 .config = &gpio_4bit_cfg_eint0011,
167 .base = S3C64XX_GPL(0),
168 .ngpio = S3C64XX_GPIO_L_NR,
170 .to_irq = s3c64xx_gpio2int_gpl,
175 static struct s3c_gpio_cfg gpio_2bit_cfg_noint = {
176 .set_config = s3c_gpio_setcfg_s3c24xx,
177 .get_config = s3c_gpio_getcfg_s3c24xx,
178 .set_pull = s3c_gpio_setpull_updown,
179 .get_pull = s3c_gpio_getpull_updown,
182 static struct s3c_gpio_cfg gpio_2bit_cfg_eint10 = {
184 .set_config = s3c_gpio_setcfg_s3c24xx,
185 .get_config = s3c_gpio_getcfg_s3c24xx,
186 .set_pull = s3c_gpio_setpull_updown,
187 .get_pull = s3c_gpio_getpull_updown,
190 static struct s3c_gpio_cfg gpio_2bit_cfg_eint11 = {
192 .set_config = s3c_gpio_setcfg_s3c24xx,
193 .get_config = s3c_gpio_getcfg_s3c24xx,
194 .set_pull = s3c_gpio_setpull_updown,
195 .get_pull = s3c_gpio_getpull_updown,
198 int s3c64xx_gpio2int_gpn(struct gpio_chip *chip, unsigned pin)
200 return IRQ_EINT(0) + pin;
203 static struct s3c_gpio_chip gpio_2bit[] = {
205 .base = S3C64XX_GPF_BASE,
206 .config = &gpio_2bit_cfg_eint11,
208 .base = S3C64XX_GPF(0),
209 .ngpio = S3C64XX_GPIO_F_NR,
213 .base = S3C64XX_GPI_BASE,
214 .config = &gpio_2bit_cfg_noint,
216 .base = S3C64XX_GPI(0),
217 .ngpio = S3C64XX_GPIO_I_NR,
221 .base = S3C64XX_GPJ_BASE,
222 .config = &gpio_2bit_cfg_noint,
224 .base = S3C64XX_GPJ(0),
225 .ngpio = S3C64XX_GPIO_J_NR,
229 .base = S3C64XX_GPN_BASE,
230 .config = &gpio_2bit_cfg_eint10,
232 .base = S3C64XX_GPN(0),
233 .ngpio = S3C64XX_GPIO_N_NR,
235 .to_irq = s3c64xx_gpio2int_gpn,
238 .base = S3C64XX_GPO_BASE,
239 .config = &gpio_2bit_cfg_eint11,
241 .base = S3C64XX_GPO(0),
242 .ngpio = S3C64XX_GPIO_O_NR,
246 .base = S3C64XX_GPP_BASE,
247 .config = &gpio_2bit_cfg_eint11,
249 .base = S3C64XX_GPP(0),
250 .ngpio = S3C64XX_GPIO_P_NR,
254 .base = S3C64XX_GPQ_BASE,
255 .config = &gpio_2bit_cfg_eint11,
257 .base = S3C64XX_GPQ(0),
258 .ngpio = S3C64XX_GPIO_Q_NR,
264 static __init void s3c64xx_gpiolib_add_2bit(struct s3c_gpio_chip *chip)
266 chip->pm = __gpio_pm(&s3c_gpio_pm_2bit);
269 static __init void s3c64xx_gpiolib_add(struct s3c_gpio_chip *chips,
271 void (*fn)(struct s3c_gpio_chip *))
273 for (; nr_chips > 0; nr_chips--, chips++) {
276 s3c_gpiolib_add(chips);
280 static __init int s3c64xx_gpiolib_init(void)
282 s3c64xx_gpiolib_add(gpio_4bit, ARRAY_SIZE(gpio_4bit),
283 samsung_gpiolib_add_4bit);
285 s3c64xx_gpiolib_add(gpio_4bit2, ARRAY_SIZE(gpio_4bit2),
286 samsung_gpiolib_add_4bit2);
288 s3c64xx_gpiolib_add(gpio_2bit, ARRAY_SIZE(gpio_2bit),
289 s3c64xx_gpiolib_add_2bit);
294 core_initcall(s3c64xx_gpiolib_init);