diff options
Diffstat (limited to 'arch/arm/plat-s3c24xx/gpiolib.c')
-rw-r--r-- | arch/arm/plat-s3c24xx/gpiolib.c | 130 |
1 files changed, 6 insertions, 124 deletions
diff --git a/arch/arm/plat-s3c24xx/gpiolib.c b/arch/arm/plat-s3c24xx/gpiolib.c index 3caec6bad3eb..f95c6c9d9f1a 100644 --- a/arch/arm/plat-s3c24xx/gpiolib.c +++ b/arch/arm/plat-s3c24xx/gpiolib.c | |||
@@ -19,104 +19,12 @@ | |||
19 | #include <linux/io.h> | 19 | #include <linux/io.h> |
20 | #include <linux/gpio.h> | 20 | #include <linux/gpio.h> |
21 | 21 | ||
22 | #include <plat/gpio-core.h> | ||
22 | #include <mach/hardware.h> | 23 | #include <mach/hardware.h> |
23 | #include <asm/irq.h> | 24 | #include <asm/irq.h> |
24 | 25 | ||
25 | #include <mach/regs-gpio.h> | 26 | #include <mach/regs-gpio.h> |
26 | 27 | ||
27 | struct s3c24xx_gpio_chip { | ||
28 | struct gpio_chip chip; | ||
29 | void __iomem *base; | ||
30 | }; | ||
31 | |||
32 | static inline struct s3c24xx_gpio_chip *to_s3c_chip(struct gpio_chip *gpc) | ||
33 | { | ||
34 | return container_of(gpc, struct s3c24xx_gpio_chip, chip); | ||
35 | } | ||
36 | |||
37 | /* these routines are exported for use by other parts of the platform | ||
38 | * and system support, but are not intended to be used directly by the | ||
39 | * drivers themsevles. | ||
40 | */ | ||
41 | |||
42 | static int s3c24xx_gpiolib_input(struct gpio_chip *chip, unsigned offset) | ||
43 | { | ||
44 | struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip); | ||
45 | void __iomem *base = ourchip->base; | ||
46 | unsigned long flags; | ||
47 | unsigned long con; | ||
48 | |||
49 | local_irq_save(flags); | ||
50 | |||
51 | con = __raw_readl(base + 0x00); | ||
52 | con &= ~(3 << (offset * 2)); | ||
53 | con |= (S3C2410_GPIO_OUTPUT & 0xf) << (offset * 2); | ||
54 | |||
55 | __raw_writel(con, base + 0x00); | ||
56 | |||
57 | local_irq_restore(flags); | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | static int s3c24xx_gpiolib_output(struct gpio_chip *chip, | ||
62 | unsigned offset, int value) | ||
63 | { | ||
64 | struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip); | ||
65 | void __iomem *base = ourchip->base; | ||
66 | unsigned long flags; | ||
67 | unsigned long dat; | ||
68 | unsigned long con; | ||
69 | |||
70 | local_irq_save(flags); | ||
71 | |||
72 | dat = __raw_readl(base + 0x04); | ||
73 | dat &= ~(1 << offset); | ||
74 | if (value) | ||
75 | dat |= 1 << offset; | ||
76 | __raw_writel(dat, base + 0x04); | ||
77 | |||
78 | con = __raw_readl(base + 0x00); | ||
79 | con &= ~(3 << (offset * 2)); | ||
80 | con |= (S3C2410_GPIO_OUTPUT & 0xf) << (offset * 2); | ||
81 | |||
82 | __raw_writel(con, base + 0x00); | ||
83 | __raw_writel(dat, base + 0x04); | ||
84 | |||
85 | local_irq_restore(flags); | ||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | static void s3c24xx_gpiolib_set(struct gpio_chip *chip, | ||
90 | unsigned offset, int value) | ||
91 | { | ||
92 | struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip); | ||
93 | void __iomem *base = ourchip->base; | ||
94 | unsigned long flags; | ||
95 | unsigned long dat; | ||
96 | |||
97 | local_irq_save(flags); | ||
98 | |||
99 | dat = __raw_readl(base + 0x04); | ||
100 | dat &= ~(1 << offset); | ||
101 | if (value) | ||
102 | dat |= 1 << offset; | ||
103 | __raw_writel(dat, base + 0x04); | ||
104 | |||
105 | local_irq_restore(flags); | ||
106 | } | ||
107 | |||
108 | static int s3c24xx_gpiolib_get(struct gpio_chip *chip, unsigned offset) | ||
109 | { | ||
110 | struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip); | ||
111 | unsigned long val; | ||
112 | |||
113 | val = __raw_readl(ourchip->base + 0x04); | ||
114 | val >>= offset; | ||
115 | val &= 1; | ||
116 | |||
117 | return val; | ||
118 | } | ||
119 | |||
120 | static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset) | 28 | static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset) |
121 | { | 29 | { |
122 | return -EINVAL; | 30 | return -EINVAL; |
@@ -125,7 +33,7 @@ static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset) | |||
125 | static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip, | 33 | static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip, |
126 | unsigned offset, int value) | 34 | unsigned offset, int value) |
127 | { | 35 | { |
128 | struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip); | 36 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); |
129 | void __iomem *base = ourchip->base; | 37 | void __iomem *base = ourchip->base; |
130 | unsigned long flags; | 38 | unsigned long flags; |
131 | unsigned long dat; | 39 | unsigned long dat; |
@@ -151,7 +59,7 @@ static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip, | |||
151 | return 0; | 59 | return 0; |
152 | } | 60 | } |
153 | 61 | ||
154 | static struct s3c24xx_gpio_chip gpios[] = { | 62 | struct s3c_gpio_chip s3c24xx_gpios[] = { |
155 | [0] = { | 63 | [0] = { |
156 | .base = S3C24XX_GPIO_BASE(S3C2410_GPA0), | 64 | .base = S3C24XX_GPIO_BASE(S3C2410_GPA0), |
157 | .chip = { | 65 | .chip = { |
@@ -161,8 +69,6 @@ static struct s3c24xx_gpio_chip gpios[] = { | |||
161 | .ngpio = 24, | 69 | .ngpio = 24, |
162 | .direction_input = s3c24xx_gpiolib_banka_input, | 70 | .direction_input = s3c24xx_gpiolib_banka_input, |
163 | .direction_output = s3c24xx_gpiolib_banka_output, | 71 | .direction_output = s3c24xx_gpiolib_banka_output, |
164 | .set = s3c24xx_gpiolib_set, | ||
165 | .get = s3c24xx_gpiolib_get, | ||
166 | }, | 72 | }, |
167 | }, | 73 | }, |
168 | [1] = { | 74 | [1] = { |
@@ -172,10 +78,6 @@ static struct s3c24xx_gpio_chip gpios[] = { | |||
172 | .owner = THIS_MODULE, | 78 | .owner = THIS_MODULE, |
173 | .label = "GPIOB", | 79 | .label = "GPIOB", |
174 | .ngpio = 16, | 80 | .ngpio = 16, |
175 | .direction_input = s3c24xx_gpiolib_input, | ||
176 | .direction_output = s3c24xx_gpiolib_output, | ||
177 | .set = s3c24xx_gpiolib_set, | ||
178 | .get = s3c24xx_gpiolib_get, | ||
179 | }, | 81 | }, |
180 | }, | 82 | }, |
181 | [2] = { | 83 | [2] = { |
@@ -185,10 +87,6 @@ static struct s3c24xx_gpio_chip gpios[] = { | |||
185 | .owner = THIS_MODULE, | 87 | .owner = THIS_MODULE, |
186 | .label = "GPIOC", | 88 | .label = "GPIOC", |
187 | .ngpio = 16, | 89 | .ngpio = 16, |
188 | .direction_input = s3c24xx_gpiolib_input, | ||
189 | .direction_output = s3c24xx_gpiolib_output, | ||
190 | .set = s3c24xx_gpiolib_set, | ||
191 | .get = s3c24xx_gpiolib_get, | ||
192 | }, | 90 | }, |
193 | }, | 91 | }, |
194 | [3] = { | 92 | [3] = { |
@@ -198,10 +96,6 @@ static struct s3c24xx_gpio_chip gpios[] = { | |||
198 | .owner = THIS_MODULE, | 96 | .owner = THIS_MODULE, |
199 | .label = "GPIOD", | 97 | .label = "GPIOD", |
200 | .ngpio = 16, | 98 | .ngpio = 16, |
201 | .direction_input = s3c24xx_gpiolib_input, | ||
202 | .direction_output = s3c24xx_gpiolib_output, | ||
203 | .set = s3c24xx_gpiolib_set, | ||
204 | .get = s3c24xx_gpiolib_get, | ||
205 | }, | 99 | }, |
206 | }, | 100 | }, |
207 | [4] = { | 101 | [4] = { |
@@ -211,10 +105,6 @@ static struct s3c24xx_gpio_chip gpios[] = { | |||
211 | .label = "GPIOE", | 105 | .label = "GPIOE", |
212 | .owner = THIS_MODULE, | 106 | .owner = THIS_MODULE, |
213 | .ngpio = 16, | 107 | .ngpio = 16, |
214 | .direction_input = s3c24xx_gpiolib_input, | ||
215 | .direction_output = s3c24xx_gpiolib_output, | ||
216 | .set = s3c24xx_gpiolib_set, | ||
217 | .get = s3c24xx_gpiolib_get, | ||
218 | }, | 108 | }, |
219 | }, | 109 | }, |
220 | [5] = { | 110 | [5] = { |
@@ -224,10 +114,6 @@ static struct s3c24xx_gpio_chip gpios[] = { | |||
224 | .owner = THIS_MODULE, | 114 | .owner = THIS_MODULE, |
225 | .label = "GPIOF", | 115 | .label = "GPIOF", |
226 | .ngpio = 8, | 116 | .ngpio = 8, |
227 | .direction_input = s3c24xx_gpiolib_input, | ||
228 | .direction_output = s3c24xx_gpiolib_output, | ||
229 | .set = s3c24xx_gpiolib_set, | ||
230 | .get = s3c24xx_gpiolib_get, | ||
231 | }, | 117 | }, |
232 | }, | 118 | }, |
233 | [6] = { | 119 | [6] = { |
@@ -237,21 +123,17 @@ static struct s3c24xx_gpio_chip gpios[] = { | |||
237 | .owner = THIS_MODULE, | 123 | .owner = THIS_MODULE, |
238 | .label = "GPIOG", | 124 | .label = "GPIOG", |
239 | .ngpio = 10, | 125 | .ngpio = 10, |
240 | .direction_input = s3c24xx_gpiolib_input, | ||
241 | .direction_output = s3c24xx_gpiolib_output, | ||
242 | .set = s3c24xx_gpiolib_set, | ||
243 | .get = s3c24xx_gpiolib_get, | ||
244 | }, | 126 | }, |
245 | }, | 127 | }, |
246 | }; | 128 | }; |
247 | 129 | ||
248 | static __init int s3c24xx_gpiolib_init(void) | 130 | static __init int s3c24xx_gpiolib_init(void) |
249 | { | 131 | { |
250 | struct s3c24xx_gpio_chip *chip = gpios; | 132 | struct s3c_gpio_chip *chip = s3c24xx_gpios; |
251 | int gpn; | 133 | int gpn; |
252 | 134 | ||
253 | for (gpn = 0; gpn < ARRAY_SIZE(gpios); gpn++, chip++) | 135 | for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++) |
254 | gpiochip_add(&chip->chip); | 136 | s3c_gpiolib_add(chip); |
255 | 137 | ||
256 | return 0; | 138 | return 0; |
257 | } | 139 | } |