diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-05-02 07:46:46 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2012-05-18 18:48:35 -0400 |
commit | 09d71ff19404b3957fab6de942fb8026ccfd8524 (patch) | |
tree | ba3680f5b79ea1fbeae073ab7cb28c9bdcad7e60 /drivers/gpio | |
parent | eb1567f7ad0032ba7b02b878e352f191d53dc228 (diff) |
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>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/devres.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c index 3dd29399cef5..d21a9ff38551 100644 --- a/drivers/gpio/devres.c +++ b/drivers/gpio/devres.c | |||
@@ -71,6 +71,35 @@ int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) | |||
71 | EXPORT_SYMBOL(devm_gpio_request); | 71 | EXPORT_SYMBOL(devm_gpio_request); |
72 | 72 | ||
73 | /** | 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 | |||
102 | /** | ||
74 | * devm_gpio_free - free an interrupt | 103 | * devm_gpio_free - free an interrupt |
75 | * @dev: device to free gpio for | 104 | * @dev: device to free gpio for |
76 | * @gpio: gpio to free | 105 | * @gpio: gpio to free |