Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef __LINUX_GPIO_SHARED_H
4#define __LINUX_GPIO_SHARED_H
5
6#include <linux/cleanup.h>
7#include <linux/lockdep.h>
8#include <linux/mutex.h>
9#include <linux/spinlock.h>
10
11struct gpio_device;
12struct gpio_desc;
13struct device;
14struct fwnode_handle;
15
16#if IS_ENABLED(CONFIG_GPIO_SHARED)
17
18int gpiochip_setup_shared(struct gpio_chip *gc);
19void gpio_device_teardown_shared(struct gpio_device *gdev);
20int gpio_shared_add_proxy_lookup(struct device *consumer,
21 struct fwnode_handle *fwnode,
22 const char *con_id, unsigned long lflags);
23
24#else
25
26static inline int gpiochip_setup_shared(struct gpio_chip *gc)
27{
28 return 0;
29}
30
31static inline void gpio_device_teardown_shared(struct gpio_device *gdev) { }
32
33static inline int gpio_shared_add_proxy_lookup(struct device *consumer,
34 struct fwnode_handle *fwnode,
35 const char *con_id,
36 unsigned long lflags)
37{
38 return 0;
39}
40
41#endif /* CONFIG_GPIO_SHARED */
42
43struct gpio_shared_desc {
44 struct gpio_desc *desc;
45 bool can_sleep;
46 unsigned long cfg;
47 unsigned int usecnt;
48 unsigned int highcnt;
49 union {
50 struct mutex mutex;
51 spinlock_t spinlock;
52 };
53};
54
55struct gpio_shared_desc *devm_gpiod_shared_get(struct device *dev);
56
57DEFINE_LOCK_GUARD_1(gpio_shared_desc_lock, struct gpio_shared_desc,
58 if (_T->lock->can_sleep)
59 mutex_lock(&_T->lock->mutex);
60 else
61 spin_lock_irqsave(&_T->lock->spinlock, _T->flags),
62 if (_T->lock->can_sleep)
63 mutex_unlock(&_T->lock->mutex);
64 else
65 spin_unlock_irqrestore(&_T->lock->spinlock, _T->flags),
66 unsigned long flags)
67
68static inline void gpio_shared_lockdep_assert(struct gpio_shared_desc *shared_desc)
69{
70 if (shared_desc->can_sleep)
71 lockdep_assert_held(&shared_desc->mutex);
72 else
73 lockdep_assert_held(&shared_desc->spinlock);
74}
75
76#endif /* __LINUX_GPIO_SHARED_H */