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 <linux/platform_device.h>
21 #define IOP3XX_N_GPIOS 8
28 /* Memory base offset */
29 static void __iomem *base;
31 #define IOP3XX_GPIO_REG(reg) (base + (reg))
32 #define IOP3XX_GPOE (volatile u32 *)IOP3XX_GPIO_REG(0x0000)
33 #define IOP3XX_GPID (volatile u32 *)IOP3XX_GPIO_REG(0x0004)
34 #define IOP3XX_GPOD (volatile u32 *)IOP3XX_GPIO_REG(0x0008)
36 static void gpio_line_config(int line, int direction)
40 local_irq_save(flags);
41 if (direction == GPIO_IN) {
42 *IOP3XX_GPOE |= 1 << line;
43 } else if (direction == GPIO_OUT) {
44 *IOP3XX_GPOE &= ~(1 << line);
46 local_irq_restore(flags);
49 static int gpio_line_get(int line)
51 return !!(*IOP3XX_GPID & (1 << line));
54 static void gpio_line_set(int line, int value)
58 local_irq_save(flags);
59 if (value == GPIO_LOW) {
60 *IOP3XX_GPOD &= ~(1 << line);
61 } else if (value == GPIO_HIGH) {
62 *IOP3XX_GPOD |= 1 << line;
64 local_irq_restore(flags);
67 static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
69 gpio_line_config(gpio, GPIO_IN);
73 static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
75 gpio_line_set(gpio, level);
76 gpio_line_config(gpio, GPIO_OUT);
80 static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
82 return gpio_line_get(gpio);
85 static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
87 gpio_line_set(gpio, value);
90 static struct gpio_chip iop3xx_chip = {
92 .direction_input = iop3xx_gpio_direction_input,
93 .get = iop3xx_gpio_get_value,
94 .direction_output = iop3xx_gpio_direction_output,
95 .set = iop3xx_gpio_set_value,
97 .ngpio = IOP3XX_N_GPIOS,
100 static int iop3xx_gpio_probe(struct platform_device *pdev)
102 struct resource *res;
104 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
105 base = (void *) res->start;
107 return gpiochip_add(&iop3xx_chip);
110 static struct platform_driver iop3xx_gpio_driver = {
113 .owner = THIS_MODULE,
115 .probe = iop3xx_gpio_probe,
118 static int __init iop3xx_gpio_init(void)
120 return platform_driver_register(&iop3xx_gpio_driver);
122 arch_initcall(iop3xx_gpio_init);