fixes reset button on atheros platform, ar5312 gpio_irqs will be added later
[openwrt.git] / target / linux / atheros / files / include / asm-mips / mach-atheros / gpio.h
1 #ifndef _ATHEROS_GPIO_H_
2 #define _ATHEROS_GPIO_H_
3
4 #include "ar531x.h"
5
6 /* Common AR531X global variables */
7 /* extern u32 ar531x_gpio_intr_Mask; */
8
9 /* AR5312 exported routines */
10 #ifdef CONFIG_ATHEROS_AR5312
11 asmlinkage void ar5312_gpio_irq_dispatch(void);
12 #endif
13
14 /* AR5315 exported routines */
15 #ifdef CONFIG_ATHEROS_AR5315
16 asmlinkage void ar5315_gpio_irq_dispatch(void);
17 #endif
18
19 /*
20 * Wrappers for the generic GPIO layer
21 */
22
23 /* Sets a gpio to input, or returns ENXIO for non-existent gpio */
24 static inline int gpio_direction_input(unsigned gpio) {
25 DO_AR5312( if (gpio > AR531X_NUM_GPIO) { \
26 return -ENXIO; \
27 } else { \
28 sysRegWrite(AR531X_GPIO_CR, \
29 sysRegRead(AR531X_GPIO_CR) | \
30 AR531X_GPIO_CR_I(gpio) ); \
31 return 0; \
32 } \
33 )
34 DO_AR5315( if (gpio > AR5315_NUM_GPIO) { \
35 return -ENXIO; \
36 } else { \
37 sysRegWrite(AR5315_GPIO_CR, \
38 ( sysRegRead(AR5315_GPIO_CR) & \
39 ~(AR5315_GPIO_CR_M(gpio)) ) | \
40 AR5315_GPIO_CR_I(gpio) ); \
41 return 0; \
42 } \
43 )
44 return -ENXIO;
45 }
46
47 /* Sets a gpio to output with value, or returns ENXIO for non-existent gpio */
48 static inline int gpio_direction_output(unsigned gpio, int value) {
49 DO_AR5312( if (gpio > AR531X_NUM_GPIO) { \
50 return -ENXIO; \
51 } else { \
52 sysRegWrite(AR531X_GPIO_DO, \
53 ( (sysRegRead(AR531X_GPIO_DO) & \
54 ~(1 << gpio) ) | \
55 ((value!=0) << gpio)) ); \
56 sysRegWrite(AR531X_GPIO_CR, \
57 ( sysRegRead(AR531X_GPIO_CR) & \
58 ~(AR531X_GPIO_CR_M(gpio)) )); \
59 return 0; \
60 } \
61 )
62 DO_AR5315( if (gpio > AR5315_NUM_GPIO) { \
63 return -ENXIO; \
64 } else { \
65 sysRegWrite(AR5315_GPIO_DO, \
66 ( (sysRegRead(AR5315_GPIO_DO) & \
67 ~(1 << gpio)) | \
68 ((value!=0) << gpio)) ); \
69 sysRegWrite(AR5315_GPIO_CR, \
70 sysRegRead(AR5315_GPIO_CR) | \
71 AR5315_GPIO_CR_O(gpio) ); \
72 return 0; \
73 } \
74 )
75 return -ENXIO;
76 }
77
78 /* Reads the gpio pin. Unchecked function */
79 static inline int gpio_get_value(unsigned gpio) {
80 DO_AR5312(return (sysRegRead(AR531X_GPIO_DI) & (1 << gpio));)
81 DO_AR5315(return (sysRegRead(AR5315_GPIO_DI) & (1 << gpio));)
82 return 0;
83 }
84
85 /* Writes to the gpio pin. Unchecked function */
86 static inline void gpio_set_value(unsigned gpio, int value) {
87 DO_AR5312( sysRegWrite(AR531X_GPIO_DO, \
88 ( (sysRegRead(AR531X_GPIO_DO) & \
89 ~(1 << gpio)) | \
90 ((value!=0) << gpio)) ); \
91 )
92 DO_AR5315( sysRegWrite(AR5315_GPIO_DO, \
93 ( (sysRegRead(AR5315_GPIO_DO) & \
94 ~(1 << gpio)) | \
95 ((value!=0) << gpio)) ); \
96 )
97 }
98
99 static inline int gpio_request(unsigned gpio, const char *label) {
100 return 0;
101 }
102
103 static inline void gpio_free(unsigned gpio) {
104 }
105
106 /* Returns IRQ to attach for gpio. Unchecked function */
107 static inline int gpio_to_irq(unsigned gpio) {
108 return AR531X_GPIO_IRQ(gpio);
109 }
110
111 /* Returns gpio for IRQ attached. Unchecked function */
112 static inline int irq_to_gpio(unsigned irq) {
113 return (irq - (AR531X_GPIO_IRQ(0)));
114 }
115
116 /* #include <asm-generic/gpio.h> */ /* cansleep wrappers */
117 /* platforms that don't directly support access to GPIOs through I2C, SPI,
118 * or other blocking infrastructure can use these wrappers.
119 */
120
121 static inline int gpio_cansleep(unsigned gpio) {
122 return 0;
123 }
124
125 static inline int gpio_get_value_cansleep(unsigned gpio) {
126 might_sleep();
127 return gpio_get_value(gpio);
128 }
129
130 static inline void gpio_set_value_cansleep(unsigned gpio, int value) {
131 might_sleep();
132 gpio_set_value(gpio, value);
133 }
134
135 #endif
136
This page took 0.068425 seconds and 5 git commands to generate.