Skip to content

Commit d25f9ab

Browse files
andy-shevBartosz Golaszewski
authored andcommitted
gpiolib: legacy: Consolidate devm_gpio_*() with other legacy APIs
There is no reason to keep deprecated legacy API implementations in the gpiolib-devres.c. Consolidate devm_gpio_*() with other legacy APIs. While at it, clean up header inclusion block in gpiolib-devres.c. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20240828151357.2677340-1-andriy.shevchenko@linux.intel.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent 94bd9ce commit d25f9ab

File tree

2 files changed

+94
-74
lines changed

2 files changed

+94
-74
lines changed

drivers/gpio/gpiolib-devres.c

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
* Copyright (c) 2011 John Crispin <john@phrozen.org>
77
*/
88

9-
#include <linux/module.h>
10-
#include <linux/err.h>
11-
#include <linux/gpio.h>
12-
#include <linux/gpio/consumer.h>
139
#include <linux/device.h>
10+
#include <linux/err.h>
11+
#include <linux/export.h>
1412
#include <linux/gfp.h>
13+
#include <linux/types.h>
14+
15+
#include <linux/gpio/consumer.h>
1516

1617
#include "gpiolib.h"
1718

19+
struct fwnode_handle;
20+
struct lock_class_key;
21+
1822
static void devm_gpiod_release(struct device *dev, void *res)
1923
{
2024
struct gpio_desc **desc = res;
@@ -354,76 +358,6 @@ void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs)
354358
}
355359
EXPORT_SYMBOL_GPL(devm_gpiod_put_array);
356360

357-
static void devm_gpio_release(struct device *dev, void *res)
358-
{
359-
unsigned *gpio = res;
360-
361-
gpio_free(*gpio);
362-
}
363-
364-
/**
365-
* devm_gpio_request - request a GPIO for a managed device
366-
* @dev: device to request the GPIO for
367-
* @gpio: GPIO to allocate
368-
* @label: the name of the requested GPIO
369-
*
370-
* Except for the extra @dev argument, this function takes the
371-
* same arguments and performs the same function as
372-
* gpio_request(). GPIOs requested with this function will be
373-
* automatically freed on driver detach.
374-
*/
375-
int devm_gpio_request(struct device *dev, unsigned gpio, const char *label)
376-
{
377-
unsigned *dr;
378-
int rc;
379-
380-
dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
381-
if (!dr)
382-
return -ENOMEM;
383-
384-
rc = gpio_request(gpio, label);
385-
if (rc) {
386-
devres_free(dr);
387-
return rc;
388-
}
389-
390-
*dr = gpio;
391-
devres_add(dev, dr);
392-
393-
return 0;
394-
}
395-
EXPORT_SYMBOL_GPL(devm_gpio_request);
396-
397-
/**
398-
* devm_gpio_request_one - request a single GPIO with initial setup
399-
* @dev: device to request for
400-
* @gpio: the GPIO number
401-
* @flags: GPIO configuration as specified by GPIOF_*
402-
* @label: a literal description string of this GPIO
403-
*/
404-
int devm_gpio_request_one(struct device *dev, unsigned gpio,
405-
unsigned long flags, const char *label)
406-
{
407-
unsigned *dr;
408-
int rc;
409-
410-
dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
411-
if (!dr)
412-
return -ENOMEM;
413-
414-
rc = gpio_request_one(gpio, flags, label);
415-
if (rc) {
416-
devres_free(dr);
417-
return rc;
418-
}
419-
420-
*dr = gpio;
421-
devres_add(dev, dr);
422-
423-
return 0;
424-
}
425-
EXPORT_SYMBOL_GPL(devm_gpio_request_one);
426-
427361
static void devm_gpio_chip_release(void *data)
428362
{
429363
struct gpio_chip *gc = data;

drivers/gpio/gpiolib-legacy.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/bitops.h>
3+
#include <linux/device.h>
4+
#include <linux/errno.h>
5+
#include <linux/export.h>
6+
#include <linux/gfp.h>
7+
28
#include <linux/gpio/consumer.h>
39
#include <linux/gpio/driver.h>
410

@@ -74,3 +80,83 @@ int gpio_request(unsigned gpio, const char *label)
7480
return gpiod_request(desc, label);
7581
}
7682
EXPORT_SYMBOL_GPL(gpio_request);
83+
84+
static void devm_gpio_release(struct device *dev, void *res)
85+
{
86+
unsigned *gpio = res;
87+
88+
gpio_free(*gpio);
89+
}
90+
91+
/**
92+
* devm_gpio_request - request a GPIO for a managed device
93+
* @dev: device to request the GPIO for
94+
* @gpio: GPIO to allocate
95+
* @label: the name of the requested GPIO
96+
*
97+
* Except for the extra @dev argument, this function takes the
98+
* same arguments and performs the same function as gpio_request().
99+
* GPIOs requested with this function will be automatically freed
100+
* on driver detach.
101+
*
102+
* **DEPRECATED** This function is deprecated and must not be used in new code.
103+
*
104+
* Returns:
105+
* 0 on success, or negative errno on failure.
106+
*/
107+
int devm_gpio_request(struct device *dev, unsigned gpio, const char *label)
108+
{
109+
unsigned *dr;
110+
int rc;
111+
112+
dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
113+
if (!dr)
114+
return -ENOMEM;
115+
116+
rc = gpio_request(gpio, label);
117+
if (rc) {
118+
devres_free(dr);
119+
return rc;
120+
}
121+
122+
*dr = gpio;
123+
devres_add(dev, dr);
124+
125+
return 0;
126+
}
127+
EXPORT_SYMBOL_GPL(devm_gpio_request);
128+
129+
/**
130+
* devm_gpio_request_one - request a single GPIO with initial setup
131+
* @dev: device to request for
132+
* @gpio: the GPIO number
133+
* @flags: GPIO configuration as specified by GPIOF_*
134+
* @label: a literal description string of this GPIO
135+
*
136+
* **DEPRECATED** This function is deprecated and must not be used in new code.
137+
*
138+
* Returns:
139+
* 0 on success, or negative errno on failure.
140+
*/
141+
int devm_gpio_request_one(struct device *dev, unsigned gpio,
142+
unsigned long flags, const char *label)
143+
{
144+
unsigned *dr;
145+
int rc;
146+
147+
dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
148+
if (!dr)
149+
return -ENOMEM;
150+
151+
rc = gpio_request_one(gpio, flags, label);
152+
if (rc) {
153+
devres_free(dr);
154+
return rc;
155+
}
156+
157+
*dr = gpio;
158+
devres_add(dev, dr);
159+
160+
return 0;
161+
}
162+
EXPORT_SYMBOL_GPL(devm_gpio_request_one);

0 commit comments

Comments
 (0)