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);
55extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc);
56
57extern void of_gpiochip_add(struct gpio_chip *gc);
58extern void of_gpiochip_remove(struct gpio_chip *gc);
59extern int of_gpio_simple_xlate(struct gpio_chip *gc,
60 const struct of_phandle_args *gpiospec,
61 u32 *flags);
62
63#else
64
65
66static inline int of_get_named_gpio_flags(struct device_node *np,
67 const char *list_name, int index, enum of_gpio_flags *flags)
68{
69 return -ENOSYS;
70}
71
72static inline int of_gpio_simple_xlate(struct gpio_chip *gc,
73 const struct of_phandle_args *gpiospec,
74 u32 *flags)
75{
76 return -ENOSYS;
77}
78
79static inline void of_gpiochip_add(struct gpio_chip *gc) { }
80static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
81
82#endif
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104static inline int of_gpio_named_count(struct device_node *np, const char* propname)
105{
106 return of_count_phandle_with_args(np, propname, "#gpio-cells");
107}
108
109
110
111
112
113
114
115static inline int of_gpio_count(struct device_node *np)
116{
117 return of_gpio_named_count(np, "gpios");
118}
119
120static inline int of_get_gpio_flags(struct device_node *np, int index,
121 enum of_gpio_flags *flags)
122{
123 return of_get_named_gpio_flags(np, "gpios", index, flags);
124}
125
126
127
128
129
130
131
132
133
134
135static inline int of_get_named_gpio(struct device_node *np,
136 const char *propname, int index)
137{
138 return of_get_named_gpio_flags(np, propname, index, NULL);
139}
140
141
142
143
144
145
146
147
148
149static inline int of_get_gpio(struct device_node *np, int index)
150{
151 return of_get_gpio_flags(np, index, NULL);
152}
153
154#endif
155