Lennert Buytenhek | 72edd84 | 2006-09-18 23:23:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/plat-iop/gpio.c |
| 3 | * GPIO handling for Intel IOP3xx processors. |
| 4 | * |
| 5 | * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org> |
| 6 | * |
| 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. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/device.h> |
Arnaud Patard | 63f385c | 2008-07-08 23:07:48 +0100 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include <linux/types.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/gpio.h> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 18 | #include <linux/export.h> |
Linus Walleij | f6ffa5e | 2013-09-09 15:00:40 +0200 | [diff] [blame] | 19 | |
| 20 | #define IOP3XX_N_GPIOS 8 |
Lennert Buytenhek | 72edd84 | 2006-09-18 23:23:07 +0100 | [diff] [blame] | 21 | |
Linus Walleij | 51a97d8 | 2013-09-09 16:07:42 +0200 | [diff] [blame^] | 22 | static void gpio_line_config(int line, int direction) |
Lennert Buytenhek | 72edd84 | 2006-09-18 23:23:07 +0100 | [diff] [blame] | 23 | { |
| 24 | unsigned long flags; |
| 25 | |
| 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); |
| 31 | } |
| 32 | local_irq_restore(flags); |
| 33 | } |
Lennert Buytenhek | 72edd84 | 2006-09-18 23:23:07 +0100 | [diff] [blame] | 34 | |
Linus Walleij | 51a97d8 | 2013-09-09 16:07:42 +0200 | [diff] [blame^] | 35 | static int gpio_line_get(int line) |
Lennert Buytenhek | 72edd84 | 2006-09-18 23:23:07 +0100 | [diff] [blame] | 36 | { |
| 37 | return !!(*IOP3XX_GPID & (1 << line)); |
| 38 | } |
Lennert Buytenhek | 72edd84 | 2006-09-18 23:23:07 +0100 | [diff] [blame] | 39 | |
Linus Walleij | 51a97d8 | 2013-09-09 16:07:42 +0200 | [diff] [blame^] | 40 | static void gpio_line_set(int line, int value) |
Lennert Buytenhek | 72edd84 | 2006-09-18 23:23:07 +0100 | [diff] [blame] | 41 | { |
| 42 | unsigned long flags; |
| 43 | |
| 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; |
| 49 | } |
| 50 | local_irq_restore(flags); |
| 51 | } |
Arnaud Patard | 63f385c | 2008-07-08 23:07:48 +0100 | [diff] [blame] | 52 | |
| 53 | static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) |
| 54 | { |
| 55 | gpio_line_config(gpio, GPIO_IN); |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level) |
| 60 | { |
| 61 | gpio_line_set(gpio, level); |
| 62 | gpio_line_config(gpio, GPIO_OUT); |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio) |
| 67 | { |
| 68 | return gpio_line_get(gpio); |
| 69 | } |
| 70 | |
| 71 | static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value) |
| 72 | { |
| 73 | gpio_line_set(gpio, value); |
| 74 | } |
| 75 | |
| 76 | static struct gpio_chip iop3xx_chip = { |
| 77 | .label = "iop3xx", |
| 78 | .direction_input = iop3xx_gpio_direction_input, |
| 79 | .get = iop3xx_gpio_get_value, |
| 80 | .direction_output = iop3xx_gpio_direction_output, |
| 81 | .set = iop3xx_gpio_set_value, |
| 82 | .base = 0, |
| 83 | .ngpio = IOP3XX_N_GPIOS, |
| 84 | }; |
| 85 | |
| 86 | static int __init iop3xx_gpio_setup(void) |
| 87 | { |
| 88 | return gpiochip_add(&iop3xx_chip); |
| 89 | } |
| 90 | arch_initcall(iop3xx_gpio_setup); |