]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
gpio / ACPI: add ACPI support
authorMathias Nyman <mathias.nyman@linux.intel.com>
Fri, 30 Nov 2012 11:37:36 +0000 (12:37 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 30 Nov 2012 11:37:36 +0000 (12:37 +0100)
Add support for translating ACPI GPIO pin numbers to Linux GPIO API pins.
Needs a gpio controller driver with the acpi handler hook set.

Drivers can use acpi_get_gpio() to translate ACPI5 GpioIO and GpioInt
resources to Linux GPIO's.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/gpio/Kconfig
drivers/gpio/Makefile
drivers/gpio/gpiolib-acpi.c [new file with mode: 0644]
include/linux/acpi_gpio.h [new file with mode: 0644]

index f11d8e3b4041b780c8c9f9ec154c3f0878025ec6..5c9b384119b83458850234c2e94c1061fc53a36c 100644 (file)
@@ -49,6 +49,10 @@ config OF_GPIO
        def_bool y
        depends on OF
 
+config GPIO_ACPI
+       def_bool y
+       depends on ACPI
+
 config DEBUG_GPIO
        bool "Debug GPIO calls"
        depends on DEBUG_KERNEL
index 9aeed67073261f94702d8a873542bfff78ab2261..420dbaca05f150290697eba3287e5bf856e8caeb 100644 (file)
@@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_GPIO)    += -DDEBUG
 
 obj-$(CONFIG_GPIOLIB)          += gpiolib.o devres.o
 obj-$(CONFIG_OF_GPIO)          += gpiolib-of.o
+obj-$(CONFIG_GPIO_ACPI)                += gpiolib-acpi.o
 
 # Device drivers. Generally keep list sorted alphabetically
 obj-$(CONFIG_GPIO_GENERIC)     += gpio-generic.o
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
new file mode 100644 (file)
index 0000000..cbad6e9
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * ACPI helpers for GPIO API
+ *
+ * Copyright (C) 2012, Intel Corporation
+ * Authors: Mathias Nyman <mathias.nyman@linux.intel.com>
+ *          Mika Westerberg <mika.westerberg@linux.intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/errno.h>
+#include <linux/gpio.h>
+#include <linux/export.h>
+#include <linux/acpi_gpio.h>
+#include <linux/acpi.h>
+
+static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
+{
+       if (!gc->dev)
+               return false;
+
+       return ACPI_HANDLE(gc->dev) == data;
+}
+
+/**
+ * acpi_get_gpio() - Translate ACPI GPIO pin to GPIO number usable with GPIO API
+ * @path:      ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
+ * @pin:       ACPI GPIO pin number (0-based, controller-relative)
+ *
+ * Returns GPIO number to use with Linux generic GPIO API, or errno error value
+ */
+
+int acpi_get_gpio(char *path, int pin)
+{
+       struct gpio_chip *chip;
+       acpi_handle handle;
+       acpi_status status;
+
+       status = acpi_get_handle(NULL, path, &handle);
+       if (ACPI_FAILURE(status))
+               return -ENODEV;
+
+       chip = gpiochip_find(handle, acpi_gpiochip_find);
+       if (!chip)
+               return -ENODEV;
+
+       if (!gpio_is_valid(chip->base + pin))
+               return -EINVAL;
+
+       return chip->base + pin;
+}
+EXPORT_SYMBOL_GPL(acpi_get_gpio);
diff --git a/include/linux/acpi_gpio.h b/include/linux/acpi_gpio.h
new file mode 100644 (file)
index 0000000..91615a3
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _LINUX_ACPI_GPIO_H_
+#define _LINUX_ACPI_GPIO_H_
+
+#include <linux/errno.h>
+
+#ifdef CONFIG_GPIO_ACPI
+
+int acpi_get_gpio(char *path, int pin);
+
+#else /* CONFIG_GPIO_ACPI */
+
+static inline int acpi_get_gpio(char *path, int pin)
+{
+       return -ENODEV;
+}
+
+#endif /* CONFIG_GPIO_ACPI */
+
+#endif /* _LINUX_ACPI_GPIO_H_ */