xref: /linux/drivers/gpio/gpiolib-shared.h (revision 59e6295fac26b8e85c1ea859cdd89fa1e47519d7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef __LINUX_GPIO_SHARED_H
4 #define __LINUX_GPIO_SHARED_H
5 
6 #include <linux/mutex.h>
7 
8 struct gpio_device;
9 struct gpio_desc;
10 struct device;
11 struct fwnode_handle;
12 
13 #if IS_ENABLED(CONFIG_GPIO_SHARED)
14 
15 int gpiochip_setup_shared(struct gpio_chip *gc);
16 void gpio_device_teardown_shared(struct gpio_device *gdev);
17 int gpio_shared_add_proxy_lookup(struct device *consumer,
18 				 struct fwnode_handle *fwnode,
19 				 const char *con_id, unsigned long lflags);
20 
21 #else
22 
23 static inline int gpiochip_setup_shared(struct gpio_chip *gc)
24 {
25 	return 0;
26 }
27 
28 static inline void gpio_device_teardown_shared(struct gpio_device *gdev) { }
29 
30 static inline int gpio_shared_add_proxy_lookup(struct device *consumer,
31 					       struct fwnode_handle *fwnode,
32 					       const char *con_id,
33 					       unsigned long lflags)
34 {
35 	return 0;
36 }
37 
38 #endif /* CONFIG_GPIO_SHARED */
39 
40 struct gpio_shared_desc {
41 	struct gpio_desc *desc;
42 	unsigned long cfg;
43 	unsigned int usecnt;
44 	unsigned int votecnt;
45 	int def_val;
46 	struct mutex mutex; /* serializes all proxy operations on this descriptor */
47 };
48 
49 struct gpio_shared_desc *devm_gpiod_shared_get(struct device *dev);
50 
51 #endif /* __LINUX_GPIO_SHARED_H */
52