aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-09-05 11:04:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-09-05 11:04:29 -0400
commit5e6c72396c2c514a761d990011ce1560f0eb71c9 (patch)
tree99ccd36c79fee77d9a7187b3c63aa6256f5dd30a
parentcaa552358eb3de5d1cb0f473e92c91d8a875b7f3 (diff)
parent0dbc8b7afef6e4fddcfebcbacbeb269a0a3b06d5 (diff)
Merge tag 'gpio-v3.17-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: - some documentation sync - resource leak in the bt8xx driver - again fix the way varargs are used to handle the optional flags on the gpiod_* accessors. Now hopefully nailed the entire problem. * tag 'gpio-v3.17-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpio: move varargs hack outside #ifdef GPIOLIB gpio: bt8xx: fix release of managed resources Documentation: gpio: documentation for optional getters functions
-rw-r--r--Documentation/gpio/consumer.txt24
-rw-r--r--drivers/gpio/gpio-bt8xx.c3
-rw-r--r--include/linux/gpio/consumer.h105
3 files changed, 83 insertions, 49 deletions
diff --git a/Documentation/gpio/consumer.txt b/Documentation/gpio/consumer.txt
index 76546324e968..6ce544191ca6 100644
--- a/Documentation/gpio/consumer.txt
+++ b/Documentation/gpio/consumer.txt
@@ -53,7 +53,20 @@ with IS_ERR() (they will never return a NULL pointer). -ENOENT will be returned
53if and only if no GPIO has been assigned to the device/function/index triplet, 53if and only if no GPIO has been assigned to the device/function/index triplet,
54other error codes are used for cases where a GPIO has been assigned but an error 54other error codes are used for cases where a GPIO has been assigned but an error
55occurred while trying to acquire it. This is useful to discriminate between mere 55occurred while trying to acquire it. This is useful to discriminate between mere
56errors and an absence of GPIO for optional GPIO parameters. 56errors and an absence of GPIO for optional GPIO parameters. For the common
57pattern where a GPIO is optional, the gpiod_get_optional() and
58gpiod_get_index_optional() functions can be used. These functions return NULL
59instead of -ENOENT if no GPIO has been assigned to the requested function:
60
61
62 struct gpio_desc *gpiod_get_optional(struct device *dev,
63 const char *con_id,
64 enum gpiod_flags flags)
65
66 struct gpio_desc *gpiod_get_index_optional(struct device *dev,
67 const char *con_id,
68 unsigned int index,
69 enum gpiod_flags flags)
57 70
58Device-managed variants of these functions are also defined: 71Device-managed variants of these functions are also defined:
59 72
@@ -65,6 +78,15 @@ Device-managed variants of these functions are also defined:
65 unsigned int idx, 78 unsigned int idx,
66 enum gpiod_flags flags) 79 enum gpiod_flags flags)
67 80
81 struct gpio_desc *devm_gpiod_get_optional(struct device *dev,
82 const char *con_id,
83 enum gpiod_flags flags)
84
85 struct gpio_desc * devm_gpiod_get_index_optional(struct device *dev,
86 const char *con_id,
87 unsigned int index,
88 enum gpiod_flags flags)
89
68A GPIO descriptor can be disposed of using the gpiod_put() function: 90A GPIO descriptor can be disposed of using the gpiod_put() function:
69 91
70 void gpiod_put(struct gpio_desc *desc) 92 void gpiod_put(struct gpio_desc *desc)
diff --git a/drivers/gpio/gpio-bt8xx.c b/drivers/gpio/gpio-bt8xx.c
index 6557147d9331..7e4c43c18960 100644
--- a/drivers/gpio/gpio-bt8xx.c
+++ b/drivers/gpio/gpio-bt8xx.c
@@ -241,9 +241,6 @@ static void bt8xxgpio_remove(struct pci_dev *pdev)
241 bgwrite(~0x0, BT848_INT_STAT); 241 bgwrite(~0x0, BT848_INT_STAT);
242 bgwrite(0x0, BT848_GPIO_OUT_EN); 242 bgwrite(0x0, BT848_GPIO_OUT_EN);
243 243
244 iounmap(bg->mmio);
245 release_mem_region(pci_resource_start(pdev, 0),
246 pci_resource_len(pdev, 0));
247 pci_disable_device(pdev); 244 pci_disable_device(pdev);
248} 245}
249 246
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index c7e17de732f3..12f146fa6604 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -38,60 +38,32 @@ enum gpiod_flags {
38struct gpio_desc *__must_check __gpiod_get(struct device *dev, 38struct gpio_desc *__must_check __gpiod_get(struct device *dev,
39 const char *con_id, 39 const char *con_id,
40 enum gpiod_flags flags); 40 enum gpiod_flags flags);
41#define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
42#define gpiod_get(varargs...) __gpiod_get(varargs, 0)
43struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, 41struct gpio_desc *__must_check __gpiod_get_index(struct device *dev,
44 const char *con_id, 42 const char *con_id,
45 unsigned int idx, 43 unsigned int idx,
46 enum gpiod_flags flags); 44 enum gpiod_flags flags);
47#define __gpiod_get_index(dev, con_id, index, flags, ...) \
48 __gpiod_get_index(dev, con_id, index, flags)
49#define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0)
50struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, 45struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev,
51 const char *con_id, 46 const char *con_id,
52 enum gpiod_flags flags); 47 enum gpiod_flags flags);
53#define __gpiod_get_optional(dev, con_id, flags, ...) \
54 __gpiod_get_optional(dev, con_id, flags)
55#define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0)
56struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, 48struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev,
57 const char *con_id, 49 const char *con_id,
58 unsigned int index, 50 unsigned int index,
59 enum gpiod_flags flags); 51 enum gpiod_flags flags);
60#define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
61 __gpiod_get_index_optional(dev, con_id, index, flags)
62#define gpiod_get_index_optional(varargs...) \
63 __gpiod_get_index_optional(varargs, 0)
64
65void gpiod_put(struct gpio_desc *desc); 52void gpiod_put(struct gpio_desc *desc);
66 53
67struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, 54struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev,
68 const char *con_id, 55 const char *con_id,
69 enum gpiod_flags flags); 56 enum gpiod_flags flags);
70#define __devm_gpiod_get(dev, con_id, flags, ...) \
71 __devm_gpiod_get(dev, con_id, flags)
72#define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0)
73struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, 57struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev,
74 const char *con_id, 58 const char *con_id,
75 unsigned int idx, 59 unsigned int idx,
76 enum gpiod_flags flags); 60 enum gpiod_flags flags);
77#define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
78 __devm_gpiod_get_index(dev, con_id, index, flags)
79#define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0)
80struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, 61struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev,
81 const char *con_id, 62 const char *con_id,
82 enum gpiod_flags flags); 63 enum gpiod_flags flags);
83#define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
84 __devm_gpiod_get_optional(dev, con_id, flags)
85#define devm_gpiod_get_optional(varargs...) \
86 __devm_gpiod_get_optional(varargs, 0)
87struct gpio_desc *__must_check 64struct gpio_desc *__must_check
88__devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 65__devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
89 unsigned int index, enum gpiod_flags flags); 66 unsigned int index, enum gpiod_flags flags);
90#define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
91 __devm_gpiod_get_index_optional(dev, con_id, index, flags)
92#define devm_gpiod_get_index_optional(varargs...) \
93 __devm_gpiod_get_index_optional(varargs, 0)
94
95void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); 67void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
96 68
97int gpiod_get_direction(const struct gpio_desc *desc); 69int gpiod_get_direction(const struct gpio_desc *desc);
@@ -124,27 +96,31 @@ int desc_to_gpio(const struct gpio_desc *desc);
124 96
125#else /* CONFIG_GPIOLIB */ 97#else /* CONFIG_GPIOLIB */
126 98
127static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, 99static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev,
128 const char *con_id) 100 const char *con_id,
101 enum gpiod_flags flags)
129{ 102{
130 return ERR_PTR(-ENOSYS); 103 return ERR_PTR(-ENOSYS);
131} 104}
132static inline struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 105static inline struct gpio_desc *__must_check
133 const char *con_id, 106__gpiod_get_index(struct device *dev,
134 unsigned int idx) 107 const char *con_id,
108 unsigned int idx,
109 enum gpiod_flags flags)
135{ 110{
136 return ERR_PTR(-ENOSYS); 111 return ERR_PTR(-ENOSYS);
137} 112}
138 113
139static inline struct gpio_desc *__must_check 114static inline struct gpio_desc *__must_check
140gpiod_get_optional(struct device *dev, const char *con_id) 115__gpiod_get_optional(struct device *dev, const char *con_id,
116 enum gpiod_flags flags)
141{ 117{
142 return ERR_PTR(-ENOSYS); 118 return ERR_PTR(-ENOSYS);
143} 119}
144 120
145static inline struct gpio_desc *__must_check 121static inline struct gpio_desc *__must_check
146gpiod_get_index_optional(struct device *dev, const char *con_id, 122__gpiod_get_index_optional(struct device *dev, const char *con_id,
147 unsigned int index) 123 unsigned int index, enum gpiod_flags flags)
148{ 124{
149 return ERR_PTR(-ENOSYS); 125 return ERR_PTR(-ENOSYS);
150} 126}
@@ -157,28 +133,33 @@ static inline void gpiod_put(struct gpio_desc *desc)
157 WARN_ON(1); 133 WARN_ON(1);
158} 134}
159 135
160static inline struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 136static inline struct gpio_desc *__must_check
161 const char *con_id) 137__devm_gpiod_get(struct device *dev,
138 const char *con_id,
139 enum gpiod_flags flags)
162{ 140{
163 return ERR_PTR(-ENOSYS); 141 return ERR_PTR(-ENOSYS);
164} 142}
165static inline 143static inline
166struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 144struct gpio_desc *__must_check
167 const char *con_id, 145__devm_gpiod_get_index(struct device *dev,
168 unsigned int idx) 146 const char *con_id,
147 unsigned int idx,
148 enum gpiod_flags flags)
169{ 149{
170 return ERR_PTR(-ENOSYS); 150 return ERR_PTR(-ENOSYS);
171} 151}
172 152
173static inline struct gpio_desc *__must_check 153static inline struct gpio_desc *__must_check
174devm_gpiod_get_optional(struct device *dev, const char *con_id) 154__devm_gpiod_get_optional(struct device *dev, const char *con_id,
155 enum gpiod_flags flags)
175{ 156{
176 return ERR_PTR(-ENOSYS); 157 return ERR_PTR(-ENOSYS);
177} 158}
178 159
179static inline struct gpio_desc *__must_check 160static inline struct gpio_desc *__must_check
180devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 161__devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
181 unsigned int index) 162 unsigned int index, enum gpiod_flags flags)
182{ 163{
183 return ERR_PTR(-ENOSYS); 164 return ERR_PTR(-ENOSYS);
184} 165}
@@ -303,9 +284,43 @@ static inline int desc_to_gpio(const struct gpio_desc *desc)
303 return -EINVAL; 284 return -EINVAL;
304} 285}
305 286
306
307#endif /* CONFIG_GPIOLIB */ 287#endif /* CONFIG_GPIOLIB */
308 288
289/*
290 * Vararg-hacks! This is done to transition the kernel to always pass
291 * the options flags argument to the below functions. During a transition
292 * phase these vararg macros make both old-and-newstyle code compile,
293 * but when all calls to the elder API are removed, these should go away
294 * and the __gpiod_get() etc functions above be renamed just gpiod_get()
295 * etc.
296 */
297#define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
298#define gpiod_get(varargs...) __gpiod_get(varargs, 0)
299#define __gpiod_get_index(dev, con_id, index, flags, ...) \
300 __gpiod_get_index(dev, con_id, index, flags)
301#define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0)
302#define __gpiod_get_optional(dev, con_id, flags, ...) \
303 __gpiod_get_optional(dev, con_id, flags)
304#define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0)
305#define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
306 __gpiod_get_index_optional(dev, con_id, index, flags)
307#define gpiod_get_index_optional(varargs...) \
308 __gpiod_get_index_optional(varargs, 0)
309#define __devm_gpiod_get(dev, con_id, flags, ...) \
310 __devm_gpiod_get(dev, con_id, flags)
311#define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0)
312#define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
313 __devm_gpiod_get_index(dev, con_id, index, flags)
314#define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0)
315#define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
316 __devm_gpiod_get_optional(dev, con_id, flags)
317#define devm_gpiod_get_optional(varargs...) \
318 __devm_gpiod_get_optional(varargs, 0)
319#define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
320 __devm_gpiod_get_index_optional(dev, con_id, index, flags)
321#define devm_gpiod_get_index_optional(varargs...) \
322 __devm_gpiod_get_index_optional(varargs, 0)
323
309#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) 324#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
310 325
311int gpiod_export(struct gpio_desc *desc, bool direction_may_change); 326int gpiod_export(struct gpio_desc *desc, bool direction_may_change);