Restore the gpio.h file, platform.c uses the generic GPIO API
[openwrt-10.03/.git] / target / linux / ar7-2.6 / files / include / asm-mips / ar7 / gpio.h
1 /*
2  * $Id: gpio.h 6693 2007-03-25 05:42:16Z ejka $
3  * 
4  * Copyright (C) 2007 OpenWrt.org
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #ifndef __AR7_GPIO_H__
22 #define __AR7_GPIO_H__
23 #include <asm/ar7/ar7.h>
24
25 #define AR7_GPIO_MAX 32
26
27 extern int gpio_request(unsigned gpio, char *label);
28 extern void gpio_free(unsigned gpio);
29
30 /* Common GPIO layer */
31 static inline int gpio_direction_input(unsigned gpio)
32 {
33         void __iomem *gpio_dir = (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
34
35         if (gpio >= AR7_GPIO_MAX)
36                 return -EINVAL;
37
38         writel(readl(gpio_dir) | (1 << gpio), gpio_dir);
39
40         return 0;
41 }
42
43 static inline int gpio_direction_output(unsigned gpio)
44 {
45         void __iomem *gpio_dir = (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
46
47         if (gpio >= AR7_GPIO_MAX)
48                 return -EINVAL;
49
50         writel(readl(gpio_dir) & ~(1 << gpio), gpio_dir);
51
52         return 0;
53 }
54
55 static inline int gpio_get_value(unsigned gpio)
56 {
57         void __iomem *gpio_in = (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_INPUT);
58
59         if (gpio >= AR7_GPIO_MAX)
60                 return -EINVAL;
61
62         return ((readl(gpio_in) & (1 << gpio)) != 0);
63 }
64
65 static inline void gpio_set_value(unsigned gpio, int value)
66 {
67         void __iomem *gpio_out = (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_OUTPUT);
68         volatile unsigned tmp;
69
70         if (gpio >= AR7_GPIO_MAX)
71                 return;
72
73         tmp = readl(gpio_out) & ~(1 << gpio);
74         if (value) 
75                 tmp |= 1 << gpio;
76         writel(tmp, gpio_out);
77 }
78
79 static inline int gpio_to_irq(unsigned gpio)
80 {
81         return -EINVAL;
82 }
83
84 static inline int irq_to_gpio(unsigned irq)
85 {
86         return -EINVAL;
87 }
88
89 /* Board specific GPIO functions */
90 static inline int ar7_gpio_enable(unsigned gpio)
91 {
92         void __iomem *gpio_en = (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
93
94         if (gpio >= AR7_GPIO_MAX)
95                 return -EINVAL;
96
97         writel(readl(gpio_en) | (1 << gpio), gpio_en);
98
99         return 0;
100 }
101
102 static inline int ar7_gpio_disable(unsigned gpio)
103 {
104         void __iomem *gpio_en = (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
105
106         if (gpio >= AR7_GPIO_MAX)
107                 return -EINVAL;
108
109         writel(readl(gpio_en) & ~(1 << gpio), gpio_en);
110
111         return 0;
112 }
113
114 #include <asm-generic/gpio.h>
115
116 #endif