Skip to content

Commit 43582f2

Browse files
djrscallyandy-shev
authored andcommitted
gpiolib: acpi: Introduce acpi_get_and_request_gpiod() helper
We need to be able to translate GPIO resources in an ACPI device's _CRS into GPIO descriptor array. Those are represented in _CRS as a pathname to a GPIO device plus the pin's index number: the acpi_get_gpiod() function is perfect for that purpose. As it's currently only used internally within the GPIO layer, provide and export a wrapper function that additionally holds a reference to the GPIO device. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Daniel Scally <djrscally@gmail.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent 2b71b66 commit 43582f2

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎drivers/gpio/gpiolib-acpi.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,34 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
128128
return gpiochip_get_desc(chip, pin);
129129
}
130130

131+
/**
132+
* acpi_get_and_request_gpiod - Translate ACPI GPIO pin to GPIO descriptor and
133+
* hold a refcount to the GPIO device.
134+
* @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
135+
* @pin: ACPI GPIO pin number (0-based, controller-relative)
136+
* @label: Label to pass to gpiod_request()
137+
*
138+
* This function is a simple pass-through to acpi_get_gpiod(), except that
139+
* as it is intended for use outside of the GPIO layer (in a similar fashion to
140+
* gpiod_get_index() for example) it also holds a reference to the GPIO device.
141+
*/
142+
struct gpio_desc *acpi_get_and_request_gpiod(char *path, int pin, char *label)
143+
{
144+
struct gpio_desc *gpio;
145+
int ret;
146+
147+
gpio = acpi_get_gpiod(path, pin);
148+
if (IS_ERR(gpio))
149+
return gpio;
150+
151+
ret = gpiod_request(gpio, label);
152+
if (ret)
153+
return ERR_PTR(ret);
154+
155+
return gpio;
156+
}
157+
EXPORT_SYMBOL_GPL(acpi_get_and_request_gpiod);
158+
131159
static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
132160
{
133161
struct acpi_gpio_event *event = data;

‎include/linux/gpio/consumer.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,8 @@ int devm_acpi_dev_add_driver_gpios(struct device *dev,
692692
const struct acpi_gpio_mapping *gpios);
693693
void devm_acpi_dev_remove_driver_gpios(struct device *dev);
694694

695+
struct gpio_desc *acpi_get_and_request_gpiod(char *path, int pin, char *label);
696+
695697
#else /* CONFIG_GPIOLIB && CONFIG_ACPI */
696698

697699
struct acpi_device;

0 commit comments

Comments
 (0)