[v5,4/6] gpiolib: acpi: Add acpi_gpio_get_io_resource()

Message ID 20210603224007.120560-5-djrscally@gmail.com
State New
Headers show
Series
  • Introduce intel_skl_int3472 module
Related show

Commit Message

Daniel Scally June 3, 2021, 10:40 p.m.
Add a function to verify that a given acpi_resource represents an IO
type GPIO resource, and return it if so.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Daniel Scally <djrscally@gmail.com>
---
Changes since v4:
	- None

 drivers/gpio/gpiolib-acpi.c | 23 +++++++++++++++++++++++
 include/linux/acpi.h        |  7 +++++++
 2 files changed, 30 insertions(+)

Comments

Daniel Scally June 4, 2021, 2:09 p.m. | #1
On 04/06/2021 14:01, Andy Shevchenko wrote:
> On Thu, Jun 03, 2021 at 11:40:05PM +0100, Daniel Scally wrote:
>> Add a function to verify that a given acpi_resource represents an IO
>> type GPIO resource, and return it if so.
> I would rephrase this to something like:
>
> "Add a function to verify that a given ACPI resource represents a GpioIo() type
> of resource, and return it if so."
>
> I can amend when applying to my branch.
>
That wording is perfectly fine by me
Andy Shevchenko June 4, 2021, 2:33 p.m. | #2
On Fri, Jun 04, 2021 at 03:09:43PM +0100, Daniel Scally wrote:
> On 04/06/2021 14:01, Andy Shevchenko wrote:
> > On Thu, Jun 03, 2021 at 11:40:05PM +0100, Daniel Scally wrote:
> >> Add a function to verify that a given acpi_resource represents an IO
> >> type GPIO resource, and return it if so.
> > I would rephrase this to something like:
> >
> > "Add a function to verify that a given ACPI resource represents a GpioIo() type
> > of resource, and return it if so."
> >
> > I can amend when applying to my branch.
> >
> That wording is perfectly fine by me

These two patches (with mentioned amendments) pushed to my review and testing
queue, thanks!

I'll send PR next week to all stakeholders.

Patch

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 684ddb35d83b..9887bb684575 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -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)
 {
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 170b9bebdb2b..e8ba7063c000 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -1098,6 +1098,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,
@@ -1105,6 +1107,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)
 {