xref: /linux/drivers/gpio/gpiolib-of.h (revision 53597deca0e38c30e6cd4ba2114fa42d2bcd85bb)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef GPIOLIB_OF_H
4 #define GPIOLIB_OF_H
5 
6 #include <linux/err.h>
7 #include <linux/types.h>
8 
9 #include <linux/notifier.h>
10 
11 struct device_node;
12 struct fwnode_handle;
13 struct fwnode_reference_args;
14 
15 struct gpio_chip;
16 struct gpio_desc;
17 struct gpio_device;
18 
19 #ifdef CONFIG_OF_GPIO
20 struct gpio_desc *of_find_gpio(struct device_node *np,
21 			       const char *con_id,
22 			       unsigned int idx,
23 			       unsigned long *lookupflags);
24 int of_gpiochip_add(struct gpio_chip *gc);
25 void of_gpiochip_remove(struct gpio_chip *gc);
26 bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index);
27 int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id);
28 int of_gpiochip_get_lflags(struct gpio_chip *chip,
29 			   struct fwnode_reference_args *gpiospec,
30 			   unsigned long *lflags);
31 #else
32 static inline struct gpio_desc *of_find_gpio(struct device_node *np,
33 					     const char *con_id,
34 					     unsigned int idx,
35 					     unsigned long *lookupflags)
36 {
37 	return ERR_PTR(-ENOENT);
38 }
39 static inline int of_gpiochip_add(struct gpio_chip *gc) { return 0; }
40 static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
41 static inline bool of_gpiochip_instance_match(struct gpio_chip *gc,
42 					      unsigned int index)
43 {
44 	return false;
45 }
46 static inline int of_gpio_count(const struct fwnode_handle *fwnode,
47 				const char *con_id)
48 {
49 	return 0;
50 }
51 static inline int of_gpiochip_get_lflags(struct gpio_chip *chip,
52 					 struct fwnode_reference_args *gpiospec,
53 					 unsigned long *lflags)
54 {
55 	return -ENOENT;
56 }
57 #endif /* CONFIG_OF_GPIO */
58 
59 extern struct notifier_block gpio_of_notifier;
60 
61 #endif /* GPIOLIB_OF_H */
62