1
2
3
4
5
6
7
8#ifndef _GPIO_AU1300_H_
9#define _GPIO_AU1300_H_
10
11#include <asm/addrspace.h>
12#include <asm/io.h>
13#include <asm/mach-au1x00/au1000.h>
14
15struct gpio;
16struct gpio_chip;
17
18
19
20
21
22#define AU1300_GPIO_BASE 0
23#define AU1300_GPIO_NUM 75
24#define AU1300_GPIO_MAX (AU1300_GPIO_BASE + AU1300_GPIO_NUM - 1)
25
26#define AU1300_GPIC_ADDR \
27 (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR)
28
29static inline int au1300_gpio_get_value(unsigned int gpio)
30{
31 void __iomem *roff = AU1300_GPIC_ADDR;
32 int bit;
33
34 gpio -= AU1300_GPIO_BASE;
35 roff += GPIC_GPIO_BANKOFF(gpio);
36 bit = GPIC_GPIO_TO_BIT(gpio);
37 return __raw_readl(roff + AU1300_GPIC_PINVAL) & bit;
38}
39
40static inline int au1300_gpio_direction_input(unsigned int gpio)
41{
42 void __iomem *roff = AU1300_GPIC_ADDR;
43 unsigned long bit;
44
45 gpio -= AU1300_GPIO_BASE;
46
47 roff += GPIC_GPIO_BANKOFF(gpio);
48 bit = GPIC_GPIO_TO_BIT(gpio);
49 __raw_writel(bit, roff + AU1300_GPIC_DEVCLR);
50 wmb();
51
52 return 0;
53}
54
55static inline int au1300_gpio_set_value(unsigned int gpio, int v)
56{
57 void __iomem *roff = AU1300_GPIC_ADDR;
58 unsigned long bit;
59
60 gpio -= AU1300_GPIO_BASE;
61
62 roff += GPIC_GPIO_BANKOFF(gpio);
63 bit = GPIC_GPIO_TO_BIT(gpio);
64 __raw_writel(bit, roff + (v ? AU1300_GPIC_PINVAL
65 : AU1300_GPIC_PINVALCLR));
66 wmb();
67
68 return 0;
69}
70
71static inline int au1300_gpio_direction_output(unsigned int gpio, int v)
72{
73
74 return au1300_gpio_set_value(gpio, v);
75}
76
77static inline int au1300_gpio_to_irq(unsigned int gpio)
78{
79 return AU1300_FIRST_INT + (gpio - AU1300_GPIO_BASE);
80}
81
82static inline int au1300_irq_to_gpio(unsigned int irq)
83{
84 return (irq - AU1300_FIRST_INT) + AU1300_GPIO_BASE;
85}
86
87static inline int au1300_gpio_is_valid(unsigned int gpio)
88{
89 int ret;
90
91 switch (alchemy_get_cputype()) {
92 case ALCHEMY_CPU_AU1300:
93 ret = ((gpio >= AU1300_GPIO_BASE) && (gpio <= AU1300_GPIO_MAX));
94 break;
95 default:
96 ret = 0;
97 }
98 return ret;
99}
100
101static inline int au1300_gpio_cansleep(unsigned int gpio)
102{
103 return 0;
104}
105
106
107static inline int au1300_gpio_getinitlvl(unsigned int gpio)
108{
109 void __iomem *roff = AU1300_GPIC_ADDR;
110 unsigned long v;
111
112 if (unlikely(gpio > 63))
113 return 0;
114 else if (gpio > 31) {
115 gpio -= 32;
116 roff += 4;
117 }
118
119 v = __raw_readl(roff + AU1300_GPIC_RSTVAL);
120 return (v >> gpio) & 1;
121}
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149#ifndef CONFIG_GPIOLIB
150
151#ifdef CONFIG_ALCHEMY_GPIOINT_AU1300
152
153#ifndef CONFIG_ALCHEMY_GPIO_INDIRECT
154
155static inline int gpio_direction_input(unsigned int gpio)
156{
157 return au1300_gpio_direction_input(gpio);
158}
159
160static inline int gpio_direction_output(unsigned int gpio, int v)
161{
162 return au1300_gpio_direction_output(gpio, v);
163}
164
165static inline int gpio_get_value(unsigned int gpio)
166{
167 return au1300_gpio_get_value(gpio);
168}
169
170static inline void gpio_set_value(unsigned int gpio, int v)
171{
172 au1300_gpio_set_value(gpio, v);
173}
174
175static inline int gpio_get_value_cansleep(unsigned gpio)
176{
177 return gpio_get_value(gpio);
178}
179
180static inline void gpio_set_value_cansleep(unsigned gpio, int value)
181{
182 gpio_set_value(gpio, value);
183}
184
185static inline int gpio_is_valid(unsigned int gpio)
186{
187 return au1300_gpio_is_valid(gpio);
188}
189
190static inline int gpio_cansleep(unsigned int gpio)
191{
192 return au1300_gpio_cansleep(gpio);
193}
194
195static inline int gpio_to_irq(unsigned int gpio)
196{
197 return au1300_gpio_to_irq(gpio);
198}
199
200static inline int irq_to_gpio(unsigned int irq)
201{
202 return au1300_irq_to_gpio(irq);
203}
204
205static inline int gpio_request(unsigned int gpio, const char *label)
206{
207 return 0;
208}
209
210static inline int gpio_request_one(unsigned gpio,
211 unsigned long flags, const char *label)
212{
213 return 0;
214}
215
216static inline int gpio_request_array(struct gpio *array, size_t num)
217{
218 return 0;
219}
220
221static inline void gpio_free(unsigned gpio)
222{
223}
224
225static inline void gpio_free_array(struct gpio *array, size_t num)
226{
227}
228
229static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
230{
231 return -ENOSYS;
232}
233
234static inline void gpio_unexport(unsigned gpio)
235{
236}
237
238static inline int gpio_export(unsigned gpio, bool direction_may_change)
239{
240 return -ENOSYS;
241}
242
243static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
244{
245 return -ENOSYS;
246}
247
248static inline int gpio_export_link(struct device *dev, const char *name,
249 unsigned gpio)
250{
251 return -ENOSYS;
252}
253
254#endif
255
256#endif
257
258#endif
259
260#endif
261