blob: 7eecf69362ee9d2b96d02fabc0a04ce1bdc8c3c6 [file] [log] [blame]
Dmitry Baryshkov45528e32008-04-10 13:31:47 +01001/*
2 * linux/arch/arm/mach-sa1100/gpio.c
3 *
4 * Generic SA-1100 GPIO handling
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
Russell King2f8163b2011-07-26 10:53:52 +010010#include <linux/gpio.h>
Dmitry Baryshkov45528e32008-04-10 13:31:47 +010011#include <linux/init.h>
12#include <linux/module.h>
13
Russell Kinga09e64f2008-08-05 16:14:15 +010014#include <mach/hardware.h>
Dmitry Baryshkov45528e32008-04-10 13:31:47 +010015
16static int sa1100_gpio_get(struct gpio_chip *chip, unsigned offset)
17{
18 return GPLR & GPIO_GPIO(offset);
19}
20
21static void sa1100_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
22{
23 if (value)
24 GPSR = GPIO_GPIO(offset);
25 else
26 GPCR = GPIO_GPIO(offset);
27}
28
29static int sa1100_direction_input(struct gpio_chip *chip, unsigned offset)
30{
31 unsigned long flags;
32
33 local_irq_save(flags);
34 GPDR &= ~GPIO_GPIO(offset);
35 local_irq_restore(flags);
36 return 0;
37}
38
39static int sa1100_direction_output(struct gpio_chip *chip, unsigned offset, int value)
40{
41 unsigned long flags;
42
43 local_irq_save(flags);
44 sa1100_gpio_set(chip, offset, value);
45 GPDR |= GPIO_GPIO(offset);
46 local_irq_restore(flags);
47 return 0;
48}
49
Russell Kingf408c982011-12-18 18:24:57 +000050static int sa1100_to_irq(struct gpio_chip *chip, unsigned offset)
51{
52 return offset < 11 ? (IRQ_GPIO0 + offset) : (IRQ_GPIO11 - 11 + offset);
53}
54
Dmitry Baryshkov45528e32008-04-10 13:31:47 +010055static struct gpio_chip sa1100_gpio_chip = {
56 .label = "gpio",
57 .direction_input = sa1100_direction_input,
58 .direction_output = sa1100_direction_output,
59 .set = sa1100_gpio_set,
60 .get = sa1100_gpio_get,
Russell Kingf408c982011-12-18 18:24:57 +000061 .to_irq = sa1100_to_irq,
Dmitry Baryshkov45528e32008-04-10 13:31:47 +010062 .base = 0,
63 .ngpio = GPIO_MAX + 1,
64};
65
66void __init sa1100_init_gpio(void)
67{
68 gpiochip_add(&sa1100_gpio_chip);
69}