blob: e4de9be78feb1c857cd22d0b2e17918fc0dda8f8 [file] [log] [blame]
Lennert Buytenhek72edd842006-09-18 23:23:07 +01001/*
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 Patard63f385c2008-07-08 23:07:48 +010014#include <linux/init.h>
15#include <linux/types.h>
16#include <linux/errno.h>
17#include <linux/gpio.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040018#include <linux/export.h>
Lennert Buytenhek72edd842006-09-18 23:23:07 +010019#include <asm/hardware/iop3xx.h>
20
21void gpio_line_config(int line, int direction)
22{
23 unsigned long flags;
24
25 local_irq_save(flags);
26 if (direction == GPIO_IN) {
27 *IOP3XX_GPOE |= 1 << line;
28 } else if (direction == GPIO_OUT) {
29 *IOP3XX_GPOE &= ~(1 << line);
30 }
31 local_irq_restore(flags);
32}
33EXPORT_SYMBOL(gpio_line_config);
34
35int gpio_line_get(int line)
36{
37 return !!(*IOP3XX_GPID & (1 << line));
38}
39EXPORT_SYMBOL(gpio_line_get);
40
41void gpio_line_set(int line, int value)
42{
43 unsigned long flags;
44
45 local_irq_save(flags);
46 if (value == GPIO_LOW) {
47 *IOP3XX_GPOD &= ~(1 << line);
48 } else if (value == GPIO_HIGH) {
49 *IOP3XX_GPOD |= 1 << line;
50 }
51 local_irq_restore(flags);
52}
53EXPORT_SYMBOL(gpio_line_set);
Arnaud Patard63f385c2008-07-08 23:07:48 +010054
55static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
56{
57 gpio_line_config(gpio, GPIO_IN);
58 return 0;
59}
60
61static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
62{
63 gpio_line_set(gpio, level);
64 gpio_line_config(gpio, GPIO_OUT);
65 return 0;
66}
67
68static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
69{
70 return gpio_line_get(gpio);
71}
72
73static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
74{
75 gpio_line_set(gpio, value);
76}
77
78static struct gpio_chip iop3xx_chip = {
79 .label = "iop3xx",
80 .direction_input = iop3xx_gpio_direction_input,
81 .get = iop3xx_gpio_get_value,
82 .direction_output = iop3xx_gpio_direction_output,
83 .set = iop3xx_gpio_set_value,
84 .base = 0,
85 .ngpio = IOP3XX_N_GPIOS,
86};
87
88static int __init iop3xx_gpio_setup(void)
89{
90 return gpiochip_add(&iop3xx_chip);
91}
92arch_initcall(iop3xx_gpio_setup);