aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-mxs.c
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2011-06-06 10:31:29 -0400
committerGrant Likely <grant.likely@secretlab.ca>2011-06-07 10:58:16 -0400
commit06f88a8ae9085e555baf81edbf967764d87dc12f (patch)
tree71c2615a492bcc379824e76c722e19c32bf2e58f /drivers/gpio/gpio-mxs.c
parente4ea933363d39b5858f55682550314b4ea1285cc (diff)
gpio/mxs: convert gpio-mxs to use basic_mmio_gpio library
The gpio-mxs controller complies with basic_mmio_gpio library. This patch converts the driver to use the library. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/gpio/gpio-mxs.c')
-rw-r--r--drivers/gpio/gpio-mxs.c80
1 files changed, 18 insertions, 62 deletions
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index a28761428bb0..9d2dba7199c9 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -27,6 +27,7 @@
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/basic_mmio_gpio.h>
30#include <mach/mxs.h> 31#include <mach/mxs.h>
31 32
32#define MXS_SET 0x4 33#define MXS_SET 0x4
@@ -54,7 +55,7 @@ struct mxs_gpio_port {
54 int irq; 55 int irq;
55 int irq_high; 56 int irq_high;
56 int virtual_irq_start; 57 int virtual_irq_start;
57 struct gpio_chip chip; 58 struct bgpio_chip bgc;
58}; 59};
59 60
60/* Note: This driver assumes 32 GPIOs are handled in one register */ 61/* Note: This driver assumes 32 GPIOs are handled in one register */
@@ -99,8 +100,6 @@ static void mxs_gpio_unmask_irq(struct irq_data *d)
99 set_gpio_irqenable(port, gpio & 0x1f, 1); 100 set_gpio_irqenable(port, gpio & 0x1f, 1);
100} 101}
101 102
102static int mxs_gpio_get(struct gpio_chip *chip, unsigned offset);
103
104static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) 103static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type)
105{ 104{
106 u32 gpio = irq_to_gpio(d->irq); 105 u32 gpio = irq_to_gpio(d->irq);
@@ -203,61 +202,15 @@ static struct irq_chip gpio_irq_chip = {
203 .irq_set_wake = mxs_gpio_set_wake_irq, 202 .irq_set_wake = mxs_gpio_set_wake_irq,
204}; 203};
205 204
206static void mxs_set_gpio_direction(struct gpio_chip *chip, unsigned offset, 205static int mxs_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
207 int dir)
208{
209 struct mxs_gpio_port *port =
210 container_of(chip, struct mxs_gpio_port, chip);
211 void __iomem *pin_addr = port->base + PINCTRL_DOE(port->id);
212
213 if (dir)
214 writel(1 << offset, pin_addr + MXS_SET);
215 else
216 writel(1 << offset, pin_addr + MXS_CLR);
217}
218
219static int mxs_gpio_get(struct gpio_chip *chip, unsigned offset)
220{
221 struct mxs_gpio_port *port =
222 container_of(chip, struct mxs_gpio_port, chip);
223
224 return (readl(port->base + PINCTRL_DIN(port->id)) >> offset) & 1;
225}
226
227static void mxs_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
228{
229 struct mxs_gpio_port *port =
230 container_of(chip, struct mxs_gpio_port, chip);
231 void __iomem *pin_addr = port->base + PINCTRL_DOUT(port->id);
232
233 if (value)
234 writel(1 << offset, pin_addr + MXS_SET);
235 else
236 writel(1 << offset, pin_addr + MXS_CLR);
237}
238
239static int mxs_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
240{ 206{
207 struct bgpio_chip *bgc = to_bgpio_chip(gc);
241 struct mxs_gpio_port *port = 208 struct mxs_gpio_port *port =
242 container_of(chip, struct mxs_gpio_port, chip); 209 container_of(bgc, struct mxs_gpio_port, bgc);
243 210
244 return port->virtual_irq_start + offset; 211 return port->virtual_irq_start + offset;
245} 212}
246 213
247static int mxs_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
248{
249 mxs_set_gpio_direction(chip, offset, 0);
250 return 0;
251}
252
253static int mxs_gpio_direction_output(struct gpio_chip *chip,
254 unsigned offset, int value)
255{
256 mxs_gpio_set(chip, offset, value);
257 mxs_set_gpio_direction(chip, offset, 1);
258 return 0;
259}
260
261static int __devinit mxs_gpio_probe(struct platform_device *pdev) 214static int __devinit mxs_gpio_probe(struct platform_device *pdev)
262{ 215{
263 static void __iomem *base; 216 static void __iomem *base;
@@ -322,21 +275,24 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
322 irq_set_chained_handler(port->irq, mxs_gpio_irq_handler); 275 irq_set_chained_handler(port->irq, mxs_gpio_irq_handler);
323 irq_set_handler_data(port->irq, port); 276 irq_set_handler_data(port->irq, port);
324 277
325 /* register gpio chip */ 278 err = bgpio_init(&port->bgc, &pdev->dev, 4,
326 port->chip.direction_input = mxs_gpio_direction_input; 279 port->base + PINCTRL_DIN(port->id),
327 port->chip.direction_output = mxs_gpio_direction_output; 280 port->base + PINCTRL_DOUT(port->id), NULL,
328 port->chip.get = mxs_gpio_get; 281 port->base + PINCTRL_DOE(port->id), NULL, false);
329 port->chip.set = mxs_gpio_set;
330 port->chip.to_irq = mxs_gpio_to_irq;
331 port->chip.base = port->id * 32;
332 port->chip.ngpio = 32;
333
334 err = gpiochip_add(&port->chip);
335 if (err) 282 if (err)
336 goto out_iounmap; 283 goto out_iounmap;
337 284
285 port->bgc.gc.to_irq = mxs_gpio_to_irq;
286 port->bgc.gc.base = port->id * 32;
287
288 err = gpiochip_add(&port->bgc.gc);
289 if (err)
290 goto out_bgpio_remove;
291
338 return 0; 292 return 0;
339 293
294out_bgpio_remove:
295 bgpio_remove(&port->bgc);
340out_iounmap: 296out_iounmap:
341 if (iores) 297 if (iores)
342 iounmap(port->base); 298 iounmap(port->base);