1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef __LINUX_OF_GPIO_H
15#define __LINUX_OF_GPIO_H
16
17#include <linux/compiler.h>
18#include <linux/kernel.h>
19#include <linux/errno.h>
20#include <linux/gpio.h>
21#include <linux/of.h>
22
23struct device_node;
24
25
26
27
28
29
30enum of_gpio_flags {
31 OF_GPIO_ACTIVE_LOW = 0x1,
32};
33
34#ifdef CONFIG_OF_GPIO
35
36
37
38
39struct of_mm_gpio_chip {
40 struct gpio_chip gc;
41 void (*save_regs)(struct of_mm_gpio_chip *mm_gc);
42 void __iomem *regs;
43};
44
45static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
46{
47 return container_of(gc, struct of_mm_gpio_chip, gc);
48}
49
50extern int of_get_named_gpio_flags(struct device_node *np,
51 const char *list_name, int index, enum of_gpio_flags *flags);
52
53extern int of_mm_gpiochip_add(struct device_node *np,
54 struct of_mm_gpio_chip *mm_gc);
55
56extern void of_gpiochip_add(struct gpio_chip *gc);
57extern void of_gpiochip_remove(struct gpio_chip *gc);
58extern int of_gpio_simple_xlate(struct gpio_chip *gc,
59 const struct of_phandle_args *gpiospec,
60 u32 *flags);
61
62#else
63
64
65static inline int of_get_named_gpio_flags(struct device_node *np,
66 const char *list_name, int index, enum of_gpio_flags *flags)
67{
68 return -ENOSYS;
69}
70
71static inline int of_gpio_simple_xlate(struct gpio_chip *gc,
72 const struct of_phandle_args *gpiospec,
73 u32 *flags)
74{
75 return -ENOSYS;
76}
77
78static inline void of_gpiochip_add(struct gpio_chip *gc) { }
79static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
80
81#endif
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103static inline int of_gpio_named_count(struct device_node *np, const char* propname)
104{
105 return of_count_phandle_with_args(np, propname, "#gpio-cells");
106}
107
108
109
110
111
112
113
114static inline int of_gpio_count(struct device_node *np)
115{
116 return of_gpio_named_count(np, "gpios");
117}
118
119
120
121
122
123
124
125
126
127
128
129static inline int of_get_gpio_flags(struct device_node *np, int index,
130 enum of_gpio_flags *flags)
131{
132 return of_get_named_gpio_flags(np, "gpios", index, flags);
133}
134
135
136
137
138
139
140
141
142
143
144static inline int of_get_named_gpio(struct device_node *np,
145 const char *propname, int index)
146{
147 return of_get_named_gpio_flags(np, propname, index, NULL);
148}
149
150
151
152
153
154
155
156
157
158static inline int of_get_gpio(struct device_node *np, int index)
159{
160 return of_get_gpio_flags(np, index, NULL);
161}
162
163#endif
164