Commit | Line | Data |
---|---|---|
f348a2a2 BD |
1 | /* linux/arch/arm/plat-s3c24xx/gpiolib.c |
2 | * | |
7ced5eab | 3 | * Copyright (c) 2008-2010 Simtec Electronics |
f348a2a2 BD |
4 | * http://armlinux.simtec.co.uk/ |
5 | * Ben Dooks <ben@simtec.co.uk> | |
6 | * | |
7 | * S3C24XX GPIOlib support | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License. | |
12 | */ | |
13 | ||
14 | #include <linux/kernel.h> | |
15 | #include <linux/init.h> | |
16 | #include <linux/module.h> | |
17 | #include <linux/interrupt.h> | |
86c03c52 | 18 | #include <linux/sysdev.h> |
f348a2a2 BD |
19 | #include <linux/ioport.h> |
20 | #include <linux/io.h> | |
21 | #include <linux/gpio.h> | |
22 | ||
e856bb1f | 23 | #include <plat/gpio-core.h> |
9bbb851c BD |
24 | #include <plat/gpio-cfg.h> |
25 | #include <plat/gpio-cfg-helpers.h> | |
a09e64fb | 26 | #include <mach/hardware.h> |
f348a2a2 | 27 | #include <asm/irq.h> |
d87964c4 | 28 | #include <plat/pm.h> |
f348a2a2 | 29 | |
a09e64fb | 30 | #include <mach/regs-gpio.h> |
f348a2a2 | 31 | |
f348a2a2 BD |
32 | static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset) |
33 | { | |
34 | return -EINVAL; | |
35 | } | |
36 | ||
37 | static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip, | |
38 | unsigned offset, int value) | |
39 | { | |
7db6c82a | 40 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); |
f348a2a2 BD |
41 | void __iomem *base = ourchip->base; |
42 | unsigned long flags; | |
43 | unsigned long dat; | |
44 | unsigned long con; | |
45 | ||
46 | local_irq_save(flags); | |
47 | ||
48 | con = __raw_readl(base + 0x00); | |
49 | dat = __raw_readl(base + 0x04); | |
50 | ||
51 | dat &= ~(1 << offset); | |
52 | if (value) | |
53 | dat |= 1 << offset; | |
54 | ||
55 | __raw_writel(dat, base + 0x04); | |
56 | ||
57 | con &= ~(1 << offset); | |
58 | ||
59 | __raw_writel(con, base + 0x00); | |
60 | __raw_writel(dat, base + 0x04); | |
61 | ||
62 | local_irq_restore(flags); | |
63 | return 0; | |
64 | } | |
65 | ||
43ae6599 BD |
66 | static int s3c24xx_gpiolib_bankf_toirq(struct gpio_chip *chip, unsigned offset) |
67 | { | |
68 | if (offset < 4) | |
69 | return IRQ_EINT0 + offset; | |
70 | ||
71 | if (offset < 8) | |
72 | return IRQ_EINT4 + offset - 4; | |
73 | ||
74 | return -EINVAL; | |
75 | } | |
76 | ||
9bbb851c BD |
77 | static struct s3c_gpio_cfg s3c24xx_gpiocfg_banka = { |
78 | .set_config = s3c_gpio_setcfg_s3c24xx_a, | |
97a33999 | 79 | .get_config = s3c_gpio_getcfg_s3c24xx_a, |
9bbb851c BD |
80 | }; |
81 | ||
82 | struct s3c_gpio_cfg s3c24xx_gpiocfg_default = { | |
83 | .set_config = s3c_gpio_setcfg_s3c24xx, | |
97a33999 | 84 | .get_config = s3c_gpio_getcfg_s3c24xx, |
9bbb851c BD |
85 | }; |
86 | ||
21b23664 | 87 | struct s3c_gpio_chip s3c24xx_gpios[] = { |
f348a2a2 | 88 | [0] = { |
fda7b2b0 | 89 | .base = S3C2410_GPACON, |
d87964c4 | 90 | .pm = __gpio_pm(&s3c_gpio_pm_1bit), |
9bbb851c | 91 | .config = &s3c24xx_gpiocfg_banka, |
f348a2a2 | 92 | .chip = { |
070276d5 | 93 | .base = S3C2410_GPA(0), |
f348a2a2 BD |
94 | .owner = THIS_MODULE, |
95 | .label = "GPIOA", | |
96 | .ngpio = 24, | |
97 | .direction_input = s3c24xx_gpiolib_banka_input, | |
98 | .direction_output = s3c24xx_gpiolib_banka_output, | |
f348a2a2 BD |
99 | }, |
100 | }, | |
101 | [1] = { | |
fda7b2b0 | 102 | .base = S3C2410_GPBCON, |
d87964c4 | 103 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), |
f348a2a2 | 104 | .chip = { |
070276d5 | 105 | .base = S3C2410_GPB(0), |
f348a2a2 BD |
106 | .owner = THIS_MODULE, |
107 | .label = "GPIOB", | |
108 | .ngpio = 16, | |
f348a2a2 BD |
109 | }, |
110 | }, | |
111 | [2] = { | |
fda7b2b0 | 112 | .base = S3C2410_GPCCON, |
d87964c4 | 113 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), |
f348a2a2 | 114 | .chip = { |
070276d5 | 115 | .base = S3C2410_GPC(0), |
f348a2a2 BD |
116 | .owner = THIS_MODULE, |
117 | .label = "GPIOC", | |
118 | .ngpio = 16, | |
f348a2a2 BD |
119 | }, |
120 | }, | |
121 | [3] = { | |
fda7b2b0 | 122 | .base = S3C2410_GPDCON, |
d87964c4 | 123 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), |
f348a2a2 | 124 | .chip = { |
070276d5 | 125 | .base = S3C2410_GPD(0), |
f348a2a2 BD |
126 | .owner = THIS_MODULE, |
127 | .label = "GPIOD", | |
128 | .ngpio = 16, | |
f348a2a2 BD |
129 | }, |
130 | }, | |
131 | [4] = { | |
fda7b2b0 | 132 | .base = S3C2410_GPECON, |
d87964c4 | 133 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), |
f348a2a2 | 134 | .chip = { |
070276d5 | 135 | .base = S3C2410_GPE(0), |
f348a2a2 BD |
136 | .label = "GPIOE", |
137 | .owner = THIS_MODULE, | |
138 | .ngpio = 16, | |
f348a2a2 BD |
139 | }, |
140 | }, | |
141 | [5] = { | |
fda7b2b0 | 142 | .base = S3C2410_GPFCON, |
d87964c4 | 143 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), |
f348a2a2 | 144 | .chip = { |
070276d5 | 145 | .base = S3C2410_GPF(0), |
f348a2a2 BD |
146 | .owner = THIS_MODULE, |
147 | .label = "GPIOF", | |
148 | .ngpio = 8, | |
43ae6599 | 149 | .to_irq = s3c24xx_gpiolib_bankf_toirq, |
f348a2a2 BD |
150 | }, |
151 | }, | |
152 | [6] = { | |
fda7b2b0 | 153 | .base = S3C2410_GPGCON, |
d87964c4 | 154 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), |
8ce14a22 | 155 | .irq_base = IRQ_EINT8, |
f348a2a2 | 156 | .chip = { |
070276d5 | 157 | .base = S3C2410_GPG(0), |
f348a2a2 BD |
158 | .owner = THIS_MODULE, |
159 | .label = "GPIOG", | |
5233c178 | 160 | .ngpio = 16, |
8ce14a22 | 161 | .to_irq = samsung_gpiolib_to_irq, |
f348a2a2 | 162 | }, |
5233c178 BD |
163 | }, { |
164 | .base = S3C2410_GPHCON, | |
165 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), | |
166 | .chip = { | |
167 | .base = S3C2410_GPH(0), | |
168 | .owner = THIS_MODULE, | |
169 | .label = "GPIOH", | |
170 | .ngpio = 11, | |
171 | }, | |
f348a2a2 | 172 | }, |
7ced5eab BD |
173 | /* GPIOS for the S3C2443 and later devices. */ |
174 | { | |
175 | .base = S3C2440_GPJCON, | |
176 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), | |
177 | .chip = { | |
178 | .base = S3C2410_GPJ(0), | |
179 | .owner = THIS_MODULE, | |
180 | .label = "GPIOJ", | |
181 | .ngpio = 16, | |
182 | }, | |
183 | }, { | |
184 | .base = S3C2443_GPKCON, | |
185 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), | |
186 | .chip = { | |
187 | .base = S3C2410_GPK(0), | |
188 | .owner = THIS_MODULE, | |
189 | .label = "GPIOK", | |
190 | .ngpio = 16, | |
191 | }, | |
192 | }, { | |
193 | .base = S3C2443_GPLCON, | |
194 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), | |
195 | .chip = { | |
196 | .base = S3C2410_GPL(0), | |
197 | .owner = THIS_MODULE, | |
198 | .label = "GPIOL", | |
199 | .ngpio = 15, | |
200 | }, | |
201 | }, { | |
202 | .base = S3C2443_GPMCON, | |
203 | .pm = __gpio_pm(&s3c_gpio_pm_2bit), | |
204 | .chip = { | |
205 | .base = S3C2410_GPM(0), | |
206 | .owner = THIS_MODULE, | |
207 | .label = "GPIOM", | |
208 | .ngpio = 2, | |
209 | }, | |
210 | }, | |
f348a2a2 BD |
211 | }; |
212 | ||
7ced5eab | 213 | |
f348a2a2 BD |
214 | static __init int s3c24xx_gpiolib_init(void) |
215 | { | |
21b23664 | 216 | struct s3c_gpio_chip *chip = s3c24xx_gpios; |
f348a2a2 BD |
217 | int gpn; |
218 | ||
9bbb851c BD |
219 | for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++) { |
220 | if (!chip->config) | |
221 | chip->config = &s3c24xx_gpiocfg_default; | |
222 | ||
7db6c82a | 223 | s3c_gpiolib_add(chip); |
9bbb851c | 224 | } |
f348a2a2 BD |
225 | |
226 | return 0; | |
227 | } | |
228 | ||
9c0ec957 | 229 | core_initcall(s3c24xx_gpiolib_init); |