Skip to content

Commit 09d71ff

Browse files
broonieglikely
authored andcommitted
gpiolib: Implement devm_gpio_request_one()
Allow drivers to use the modern request and configure idiom together with devres. As with plain gpio_request() and gpio_request_one() we can't implement the old school version in terms of _one() as this would force the explicit selection of a direction in gpio_request() which could break systems if we pick the wrong one. Implementing devm_gpio_request_one() in terms of devm_gpio_request() would needlessly complicate things or lead to duplication from the unmanaged version depending on how it's done. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
1 parent eb1567f commit 09d71ff

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

drivers/gpio/devres.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,35 @@ int devm_gpio_request(struct device *dev, unsigned gpio, const char *label)
7070
}
7171
EXPORT_SYMBOL(devm_gpio_request);
7272

73+
/**
74+
* devm_gpio_request_one - request a single GPIO with initial setup
75+
* @dev: device to request for
76+
* @gpio: the GPIO number
77+
* @flags: GPIO configuration as specified by GPIOF_*
78+
* @label: a literal description string of this GPIO
79+
*/
80+
int devm_gpio_request_one(struct device *dev, unsigned gpio,
81+
unsigned long flags, const char *label)
82+
{
83+
unsigned *dr;
84+
int rc;
85+
86+
dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
87+
if (!dr)
88+
return -ENOMEM;
89+
90+
rc = gpio_request_one(gpio, flags, label);
91+
if (rc) {
92+
devres_free(dr);
93+
return rc;
94+
}
95+
96+
*dr = gpio;
97+
devres_add(dev, dr);
98+
99+
return 0;
100+
}
101+
73102
/**
74103
* devm_gpio_free - free an interrupt
75104
* @dev: device to free gpio for

include/asm-generic/gpio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ extern void gpio_free_array(const struct gpio *array, size_t num);
179179

180180
/* bindings for managed devices that want to request gpios */
181181
int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
182+
int devm_gpio_request_one(struct device *dev, unsigned gpio,
183+
unsigned long flags, const char *label);
182184
void devm_gpio_free(struct device *dev, unsigned int gpio);
183185

184186
#ifdef CONFIG_GPIO_SYSFS

include/linux/gpio.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ static inline int gpio_request_one(unsigned gpio,
106106
return -ENOSYS;
107107
}
108108

109+
static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
110+
unsigned long flags, const char *label)
111+
{
112+
return -ENOSYS;
113+
}
114+
109115
static inline int gpio_request_array(const struct gpio *array, size_t num)
110116
{
111117
return -ENOSYS;

0 commit comments

Comments
 (0)