blob: 243b6411050d5edfdd587535a65173f9b1343aa7 [file] [log] [blame]
Ben Dooksf348a2a2008-07-03 11:24:25 +01001/* linux/arch/arm/plat-s3c24xx/gpiolib.c
2 *
Ben Dooks7ced5ea2010-05-03 17:19:49 +09003 * Copyright (c) 2008-2010 Simtec Electronics
Ben Dooksf348a2a2008-07-03 11:24:25 +01004 * 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>
Ben Dooks86c03c52009-05-17 22:47:07 +010018#include <linux/sysdev.h>
Ben Dooksf348a2a2008-07-03 11:24:25 +010019#include <linux/ioport.h>
20#include <linux/io.h>
21#include <linux/gpio.h>
22
Ben Dookse856bb12010-01-19 17:14:46 +090023#include <plat/gpio-core.h>
Ben Dooks9bbb8512010-04-30 19:30:35 +090024#include <plat/gpio-cfg.h>
25#include <plat/gpio-cfg-helpers.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
Ben Dooksf348a2a2008-07-03 11:24:25 +010027#include <asm/irq.h>
Ben Dooksd87964c2008-12-12 00:24:30 +000028#include <plat/pm.h>
Ben Dooksf348a2a2008-07-03 11:24:25 +010029
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/regs-gpio.h>
Ben Dooksf348a2a2008-07-03 11:24:25 +010031
Ben Dooksf348a2a2008-07-03 11:24:25 +010032static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
33{
34 return -EINVAL;
35}
36
37static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
38 unsigned offset, int value)
39{
Ben Dooks7db6c822008-10-31 16:14:31 +000040 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
Ben Dooksf348a2a2008-07-03 11:24:25 +010041 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
Ben Dooks43ae6592009-01-08 12:40:50 +000066static 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
Ben Dooks9bbb8512010-04-30 19:30:35 +090077static struct s3c_gpio_cfg s3c24xx_gpiocfg_banka = {
78 .set_config = s3c_gpio_setcfg_s3c24xx_a,
Ben Dooks97a33992010-05-06 10:27:16 +090079 .get_config = s3c_gpio_getcfg_s3c24xx_a,
Ben Dooks9bbb8512010-04-30 19:30:35 +090080};
81
82struct s3c_gpio_cfg s3c24xx_gpiocfg_default = {
83 .set_config = s3c_gpio_setcfg_s3c24xx,
Ben Dooks97a33992010-05-06 10:27:16 +090084 .get_config = s3c_gpio_getcfg_s3c24xx,
Ben Dooks9bbb8512010-04-30 19:30:35 +090085};
86
Ben Dooks21b23662008-10-31 16:14:34 +000087struct s3c_gpio_chip s3c24xx_gpios[] = {
Ben Dooksf348a2a2008-07-03 11:24:25 +010088 [0] = {
Ben Dooksfda7b2b2009-05-17 22:18:27 +010089 .base = S3C2410_GPACON,
Ben Dooksd87964c2008-12-12 00:24:30 +000090 .pm = __gpio_pm(&s3c_gpio_pm_1bit),
Ben Dooks9bbb8512010-04-30 19:30:35 +090091 .config = &s3c24xx_gpiocfg_banka,
Ben Dooksf348a2a2008-07-03 11:24:25 +010092 .chip = {
Ben Dooks070276d2009-05-17 22:32:23 +010093 .base = S3C2410_GPA(0),
Ben Dooksf348a2a2008-07-03 11:24:25 +010094 .owner = THIS_MODULE,
95 .label = "GPIOA",
96 .ngpio = 24,
97 .direction_input = s3c24xx_gpiolib_banka_input,
98 .direction_output = s3c24xx_gpiolib_banka_output,
Ben Dooksf348a2a2008-07-03 11:24:25 +010099 },
100 },
101 [1] = {
Ben Dooksfda7b2b2009-05-17 22:18:27 +0100102 .base = S3C2410_GPBCON,
Ben Dooksd87964c2008-12-12 00:24:30 +0000103 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100104 .chip = {
Ben Dooks070276d2009-05-17 22:32:23 +0100105 .base = S3C2410_GPB(0),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100106 .owner = THIS_MODULE,
107 .label = "GPIOB",
108 .ngpio = 16,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100109 },
110 },
111 [2] = {
Ben Dooksfda7b2b2009-05-17 22:18:27 +0100112 .base = S3C2410_GPCCON,
Ben Dooksd87964c2008-12-12 00:24:30 +0000113 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100114 .chip = {
Ben Dooks070276d2009-05-17 22:32:23 +0100115 .base = S3C2410_GPC(0),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100116 .owner = THIS_MODULE,
117 .label = "GPIOC",
118 .ngpio = 16,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100119 },
120 },
121 [3] = {
Ben Dooksfda7b2b2009-05-17 22:18:27 +0100122 .base = S3C2410_GPDCON,
Ben Dooksd87964c2008-12-12 00:24:30 +0000123 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100124 .chip = {
Ben Dooks070276d2009-05-17 22:32:23 +0100125 .base = S3C2410_GPD(0),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100126 .owner = THIS_MODULE,
127 .label = "GPIOD",
128 .ngpio = 16,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100129 },
130 },
131 [4] = {
Ben Dooksfda7b2b2009-05-17 22:18:27 +0100132 .base = S3C2410_GPECON,
Ben Dooksd87964c2008-12-12 00:24:30 +0000133 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100134 .chip = {
Ben Dooks070276d2009-05-17 22:32:23 +0100135 .base = S3C2410_GPE(0),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100136 .label = "GPIOE",
137 .owner = THIS_MODULE,
138 .ngpio = 16,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100139 },
140 },
141 [5] = {
Ben Dooksfda7b2b2009-05-17 22:18:27 +0100142 .base = S3C2410_GPFCON,
Ben Dooksd87964c2008-12-12 00:24:30 +0000143 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100144 .chip = {
Ben Dooks070276d2009-05-17 22:32:23 +0100145 .base = S3C2410_GPF(0),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100146 .owner = THIS_MODULE,
147 .label = "GPIOF",
148 .ngpio = 8,
Ben Dooks43ae6592009-01-08 12:40:50 +0000149 .to_irq = s3c24xx_gpiolib_bankf_toirq,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100150 },
151 },
152 [6] = {
Ben Dooksfda7b2b2009-05-17 22:18:27 +0100153 .base = S3C2410_GPGCON,
Ben Dooksd87964c2008-12-12 00:24:30 +0000154 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900155 .irq_base = IRQ_EINT8,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100156 .chip = {
Ben Dooks070276d2009-05-17 22:32:23 +0100157 .base = S3C2410_GPG(0),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100158 .owner = THIS_MODULE,
159 .label = "GPIOG",
Ben Dooks5233c172009-05-18 20:10:43 +0100160 .ngpio = 16,
Joonyoung Shim8ce14a22010-10-01 11:24:39 +0900161 .to_irq = samsung_gpiolib_to_irq,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100162 },
Ben Dooks5233c172009-05-18 20:10:43 +0100163 }, {
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 },
Ben Dooksf348a2a2008-07-03 11:24:25 +0100172 },
Ben Dooks7ced5ea2010-05-03 17:19:49 +0900173 /* 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 },
Ben Dooksf348a2a2008-07-03 11:24:25 +0100211};
212
Ben Dooks7ced5ea2010-05-03 17:19:49 +0900213
Ben Dooksf348a2a2008-07-03 11:24:25 +0100214static __init int s3c24xx_gpiolib_init(void)
215{
Ben Dooks21b23662008-10-31 16:14:34 +0000216 struct s3c_gpio_chip *chip = s3c24xx_gpios;
Ben Dooksf348a2a2008-07-03 11:24:25 +0100217 int gpn;
218
Ben Dooks9bbb8512010-04-30 19:30:35 +0900219 for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++) {
220 if (!chip->config)
221 chip->config = &s3c24xx_gpiocfg_default;
222
Ben Dooks7db6c822008-10-31 16:14:31 +0000223 s3c_gpiolib_add(chip);
Ben Dooks9bbb8512010-04-30 19:30:35 +0900224 }
Ben Dooksf348a2a2008-07-03 11:24:25 +0100225
226 return 0;
227}
228
Ben Dooks9c0ec952009-05-18 20:03:23 +0100229core_initcall(s3c24xx_gpiolib_init);