gpiolib: acpi: Add acpi_gpio_get_io_resource()
authorDaniel Scally <djrscally@gmail.com>
Thu, 3 Jun 2021 22:40:05 +0000 (23:40 +0100)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 4 Jun 2021 13:24:19 +0000 (16:24 +0300)
Add a function to verify that a given ACPI resource represents a GpioIo()
type of resource, and return it if so.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Daniel Scally <djrscally@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/gpio/gpiolib-acpi.c
include/linux/acpi.h

index 75cd0c5..cf99a57 100644 (file)
@@ -196,6 +196,29 @@ bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
 }
 EXPORT_SYMBOL_GPL(acpi_gpio_get_irq_resource);
 
+/**
+ * acpi_gpio_get_io_resource - Fetch details of an ACPI resource if it is a GPIO
+ *                            I/O resource or return False if not.
+ * @ares:      Pointer to the ACPI resource to fetch
+ * @agpio:     Pointer to a &struct acpi_resource_gpio to store the output pointer
+ */
+bool acpi_gpio_get_io_resource(struct acpi_resource *ares,
+                              struct acpi_resource_gpio **agpio)
+{
+       struct acpi_resource_gpio *gpio;
+
+       if (ares->type != ACPI_RESOURCE_TYPE_GPIO)
+               return false;
+
+       gpio = &ares->data.gpio;
+       if (gpio->connection_type != ACPI_RESOURCE_GPIO_TYPE_IO)
+               return false;
+
+       *agpio = gpio;
+       return true;
+}
+EXPORT_SYMBOL_GPL(acpi_gpio_get_io_resource);
+
 static void acpi_gpiochip_request_irq(struct acpi_gpio_chip *acpi_gpio,
                                      struct acpi_gpio_event *event)
 {
index c60745f..a74d37a 100644 (file)
@@ -1096,6 +1096,8 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c
 #if defined(CONFIG_ACPI) && defined(CONFIG_GPIOLIB)
 bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
                                struct acpi_resource_gpio **agpio);
+bool acpi_gpio_get_io_resource(struct acpi_resource *ares,
+                              struct acpi_resource_gpio **agpio);
 int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int index);
 #else
 static inline bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
@@ -1103,6 +1105,11 @@ static inline bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
 {
        return false;
 }
+static inline bool acpi_gpio_get_io_resource(struct acpi_resource *ares,
+                                            struct acpi_resource_gpio **agpio)
+{
+       return false;
+}
 static inline int acpi_dev_gpio_irq_get_by(struct acpi_device *adev,
                                           const char *name, int index)
 {