PCI / PM: Block races between runtime PM and system sleep
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / plat-iop / gpio.c
blob640e498c12efcc1c1bd6a5234b8de0756376a46b
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 <asm/hardware/iop3xx.h>
20 void gpio_line_config(int line, int direction)
22 unsigned long flags;
24 local_irq_save(flags);
25 if (direction == GPIO_IN) {
26 *IOP3XX_GPOE |= 1 << line;
27 } else if (direction == GPIO_OUT) {
28 *IOP3XX_GPOE &= ~(1 << line);
30 local_irq_restore(flags);
32 EXPORT_SYMBOL(gpio_line_config);
34 int gpio_line_get(int line)
36 return !!(*IOP3XX_GPID & (1 << line));
38 EXPORT_SYMBOL(gpio_line_get);
40 void gpio_line_set(int line, int value)
42 unsigned long flags;
44 local_irq_save(flags);
45 if (value == GPIO_LOW) {
46 *IOP3XX_GPOD &= ~(1 << line);
47 } else if (value == GPIO_HIGH) {
48 *IOP3XX_GPOD |= 1 << line;
50 local_irq_restore(flags);
52 EXPORT_SYMBOL(gpio_line_set);
54 static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
56 gpio_line_config(gpio, GPIO_IN);
57 return 0;
60 static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
62 gpio_line_set(gpio, level);
63 gpio_line_config(gpio, GPIO_OUT);
64 return 0;
67 static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
69 return gpio_line_get(gpio);
72 static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
74 gpio_line_set(gpio, value);
77 static struct gpio_chip iop3xx_chip = {
78 .label = "iop3xx",
79 .direction_input = iop3xx_gpio_direction_input,
80 .get = iop3xx_gpio_get_value,
81 .direction_output = iop3xx_gpio_direction_output,
82 .set = iop3xx_gpio_set_value,
83 .base = 0,
84 .ngpio = IOP3XX_N_GPIOS,
87 static int __init iop3xx_gpio_setup(void)
89 return gpiochip_add(&iop3xx_chip);
91 arch_initcall(iop3xx_gpio_setup);