Linux 3.11-rc3
[cris-mirror.git] / arch / arm / plat-iop / gpio.c
blob697de6dc49364fd62611c863ad60f76876b0c30a
1 /*
2 * arch/arm/plat-iop/gpio.c
3 * GPIO handling for Intel IOP3xx processors.
5 * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
13 #include <linux/device.h>
14 #include <linux/init.h>
15 #include <linux/types.h>
16 #include <linux/errno.h>
17 #include <linux/gpio.h>
18 #include <linux/export.h>
19 #include <asm/hardware/iop3xx.h>
20 #include <mach/gpio.h>
22 void gpio_line_config(int line, int direction)
24 unsigned long flags;
26 local_irq_save(flags);
27 if (direction == GPIO_IN) {
28 *IOP3XX_GPOE |= 1 << line;
29 } else if (direction == GPIO_OUT) {
30 *IOP3XX_GPOE &= ~(1 << line);
32 local_irq_restore(flags);
34 EXPORT_SYMBOL(gpio_line_config);
36 int gpio_line_get(int line)
38 return !!(*IOP3XX_GPID & (1 << line));
40 EXPORT_SYMBOL(gpio_line_get);
42 void gpio_line_set(int line, int value)
44 unsigned long flags;
46 local_irq_save(flags);
47 if (value == GPIO_LOW) {
48 *IOP3XX_GPOD &= ~(1 << line);
49 } else if (value == GPIO_HIGH) {
50 *IOP3XX_GPOD |= 1 << line;
52 local_irq_restore(flags);
54 EXPORT_SYMBOL(gpio_line_set);
56 static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
58 gpio_line_config(gpio, GPIO_IN);
59 return 0;
62 static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
64 gpio_line_set(gpio, level);
65 gpio_line_config(gpio, GPIO_OUT);
66 return 0;
69 static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
71 return gpio_line_get(gpio);
74 static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
76 gpio_line_set(gpio, value);
79 static struct gpio_chip iop3xx_chip = {
80 .label = "iop3xx",
81 .direction_input = iop3xx_gpio_direction_input,
82 .get = iop3xx_gpio_get_value,
83 .direction_output = iop3xx_gpio_direction_output,
84 .set = iop3xx_gpio_set_value,
85 .base = 0,
86 .ngpio = IOP3XX_N_GPIOS,
89 static int __init iop3xx_gpio_setup(void)
91 return gpiochip_add(&iop3xx_chip);
93 arch_initcall(iop3xx_gpio_setup);