From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: linux-acpi@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Linus Walleij <linus.walleij@linaro.org>,
Alexandre Courbot <gnurou@gmail.com>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Bryan Wu <cooloney@gmail.com>, Lee Jones <lee.jones@linaro.org>,
Grant Likely <grant.likely@linaro.org>,
Arnd Bergmann <arnd@arndb.de>, Aaron Lu <aaron.lu@intel.com>,
Darren Hart <dvhart@linux.intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [RFC PATCH v2 06/16] gpio / ACPI: Add support for _DSD device properties
Date: Tue, 16 Sep 2014 14:52:37 +0300 [thread overview]
Message-ID: <1410868367-11056-7-git-send-email-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <1410868367-11056-1-git-send-email-mika.westerberg@linux.intel.com>
With release of ACPI 5.1 and _DSD method we can finally name GPIOs (and
other things as well) returned by _CRS. Previously we were only able to
use integer index to find the corresponding GPIO, which is pretty error
prone if the order changes.
With _DSD we can now query GPIOs using name instead of an integer index,
like the below example shows:
// Bluetooth device with reset and shutdown GPIOs
Device (BTH)
{
Name (_HID, ...)
Name (_CRS, ResourceTemplate ()
{
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
"\\_SB.GPO0", 0, ResourceConsumer) {15}
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
"\\_SB.GPO0", 0, ResourceConsumer) {27, 31}
})
Name (_DSD, Package ()
{
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package ()
{
Package () {"reset-gpio", Package() {^BTH, 1, 1, 0 }},
Package () {"shutdown-gpio", Package() {^BTH, 0, 0, 0 }},
}
})
}
The format of the supported GPIO property is:
Package () { "name", Package () { ref, index, pin, active_low }}
ref - The device that has _CRS containing GpioIo()/GpioInt() resources,
typically this is the device itself (BTH in our case).
index - Index of the GpioIo()/GpioInt() resource in _CRS starting from zero.
pin - Pin in the GpioIo()/GpioInt() resource. Typically this is zero.
active_low - If 1 the GPIO is marked as active_low.
Since ACPI GpioIo() resource does not have field saying whether it is
active low or high, the "active_low" argument can be used here. Setting
it to 1 marks the GPIO as active low.
In our Bluetooth example the "reset-gpio" refers to the second GpioIo()
resource, second pin in that resource with the GPIO number of 31.
This patch implements necessary support to gpiolib for extracting GPIOs
using _DSD device properties.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/gpio/gpiolib-acpi.c | 78 +++++++++++++++++++++++++++++++++++++--------
drivers/gpio/gpiolib.c | 30 ++++++++++++++---
drivers/gpio/gpiolib.h | 7 ++--
3 files changed, 94 insertions(+), 21 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index d62eaaa75397..9212cde087b0 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -293,6 +293,7 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
struct acpi_gpio_lookup {
struct acpi_gpio_info info;
int index;
+ int pin_index;
struct gpio_desc *desc;
int n;
};
@@ -306,13 +307,24 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data)
if (lookup->n++ == lookup->index && !lookup->desc) {
const struct acpi_resource_gpio *agpio = &ares->data.gpio;
+ int pin_index = lookup->pin_index;
+
+ if (pin_index >= agpio->pin_table_length)
+ return 1;
lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr,
- agpio->pin_table[0]);
+ agpio->pin_table[pin_index]);
lookup->info.gpioint =
agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT;
- lookup->info.active_low =
- agpio->polarity == ACPI_ACTIVE_LOW;
+
+ /*
+ * ActiveLow is only specified for GpioInt resource. If
+ * GpioIo is used then the only way to set the flag is
+ * to use _DSD "gpios" property.
+ */
+ if (lookup->info.gpioint)
+ lookup->info.active_low =
+ agpio->polarity == ACPI_ACTIVE_LOW;
}
return 1;
@@ -320,40 +332,75 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data)
/**
* acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources
- * @dev: pointer to a device to get GPIO from
+ * @adev: pointer to a ACPI device to get GPIO from
+ * @propname: Property name of the GPIO (optional)
* @index: index of GpioIo/GpioInt resource (starting from %0)
* @info: info pointer to fill in (optional)
*
- * Function goes through ACPI resources for @dev and based on @index looks
+ * Function goes through ACPI resources for @adev and based on @index looks
* up a GpioIo/GpioInt resource, translates it to the Linux GPIO descriptor,
* and returns it. @index matches GpioIo/GpioInt resources only so if there
* are total %3 GPIO resources, the index goes from %0 to %2.
*
+ * If @propname is specified the GPIO is looked using device property. In
+ * that case @index is used to select the GPIO entry in the property value
+ * (in case of multiple).
+ *
* If the GPIO cannot be translated or there is an error an ERR_PTR is
* returned.
*
* Note: if the GPIO resource has multiple entries in the pin list, this
* function only returns the first.
*/
-struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
+struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
+ const char *propname, int index,
struct acpi_gpio_info *info)
{
struct acpi_gpio_lookup lookup;
struct list_head resource_list;
- struct acpi_device *adev;
- acpi_handle handle;
+ bool active_low = false;
int ret;
- if (!dev)
- return ERR_PTR(-EINVAL);
-
- handle = ACPI_HANDLE(dev);
- if (!handle || acpi_bus_get_device(handle, &adev))
+ if (!adev)
return ERR_PTR(-ENODEV);
memset(&lookup, 0, sizeof(lookup));
lookup.index = index;
+ if (propname) {
+ struct acpi_reference_args args;
+
+ dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname);
+
+ memset(&args, 0, sizeof(args));
+ ret = acpi_dev_get_property_reference(adev, propname, NULL,
+ index, &args);
+ if (ret)
+ return ERR_PTR(ret);
+
+ /*
+ * The property was found and resolved so need to
+ * lookup the GPIO based on returned args instead.
+ */
+ adev = args.adev;
+ if (args.nargs >= 2) {
+ lookup.index = args.args[0];
+ lookup.pin_index = args.args[1];
+ /*
+ * 3rd argument, if present is used to
+ * specify active_low.
+ */
+ if (args.nargs >= 3)
+ active_low = !!args.args[2];
+ }
+
+ dev_dbg(&adev->dev, "GPIO: _DSD returned %s %zd %llu %llu %llu\n",
+ dev_name(&adev->dev), args.nargs,
+ args.args[0], args.args[1], args.args[2]);
+ } else {
+ dev_dbg(&adev->dev, "GPIO: looking up %d in _CRS\n", index);
+ }
+
INIT_LIST_HEAD(&resource_list);
ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio,
&lookup);
@@ -362,8 +409,11 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
acpi_dev_free_resource_list(&resource_list);
- if (lookup.desc && info)
+ if (lookup.desc && info) {
*info = lookup.info;
+ if (active_low)
+ info->active_low = active_low;
+ }
return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT);
}
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 15cc0bb65dda..444d43c9fd3e 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1487,14 +1487,36 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id,
unsigned int idx,
enum gpio_lookup_flags *flags)
{
+ static const char * const suffixes[] = { "gpios", "gpio" };
+ struct acpi_device *adev = ACPI_COMPANION(dev);
struct acpi_gpio_info info;
struct gpio_desc *desc;
+ char propname[32];
+ int i;
- desc = acpi_get_gpiod_by_index(dev, idx, &info);
- if (IS_ERR(desc))
- return desc;
+ /* Try first from _DSD */
+ for (i = 0; i < ARRAY_SIZE(suffixes); i++) {
+ if (con_id && strcmp(con_id, "gpios")) {
+ snprintf(propname, sizeof(propname), "%s-%s",
+ con_id, suffixes[i]);
+ } else {
+ snprintf(propname, sizeof(propname), "%s",
+ suffixes[i]);
+ }
+
+ desc = acpi_get_gpiod_by_index(adev, propname, 0, &info);
+ if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER))
+ break;
+ }
+
+ /* Then from plain _CRS GPIOs */
+ if (IS_ERR(desc)) {
+ desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info);
+ if (IS_ERR(desc))
+ return desc;
+ }
- if (info.gpioint && info.active_low)
+ if (info.active_low)
*flags |= GPIO_ACTIVE_LOW;
return desc;
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 9db2b6a71c5d..e3a52113a541 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -34,7 +34,8 @@ void acpi_gpiochip_remove(struct gpio_chip *chip);
void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
-struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
+struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
+ const char *propname, int index,
struct acpi_gpio_info *info);
#else
static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
@@ -47,8 +48,8 @@ static inline void
acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
static inline struct gpio_desc *
-acpi_get_gpiod_by_index(struct device *dev, int index,
- struct acpi_gpio_info *info)
+acpi_get_gpiod_by_index(struct acpi_device *adev, const char *propname,
+ int index, struct acpi_gpio_info *info)
{
return ERR_PTR(-ENOSYS);
}
--
2.1.0
next prev parent reply other threads:[~2014-09-16 11:52 UTC|newest]
Thread overview: 130+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-16 11:52 [RFC PATCH v2 00/16] Add ACPI _DSD and unified device properties support Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 01/16] ACPI: Add support for device specific properties Mika Westerberg
2014-10-06 13:50 ` Grant Likely
[not found] ` <20141006135021.0EB04C43FBE-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-10-06 14:32 ` Mika Westerberg
2014-10-06 16:25 ` Darren Hart
2014-09-16 11:52 ` [RFC PATCH v2 02/16] Driver core: Unified device properties interface for platform firmware Mika Westerberg
2014-09-17 18:28 ` Greg Kroah-Hartman
2014-09-16 11:52 ` [RFC PATCH v2 03/16] ACPI: Allow drivers to match using Device Tree compatible property Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 04/16] ACPI: Document ACPI device specific properties Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 05/16] mfd: Add ACPI support Mika Westerberg
2014-09-16 21:54 ` Lee Jones
2014-09-24 12:00 ` Lee Jones
2014-09-16 11:52 ` Mika Westerberg [this message]
2014-09-23 15:27 ` [RFC PATCH v2 06/16] gpio / ACPI: Add support for _DSD device properties Linus Walleij
2014-09-16 11:52 ` [RFC PATCH v2 07/16] gpio: Add support for unified device properties interface Mika Westerberg
[not found] ` <1410868367-11056-8-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-09-23 15:25 ` Linus Walleij
2014-09-23 15:45 ` Arnd Bergmann
2014-09-23 15:52 ` Mika Westerberg
2014-09-23 16:17 ` Dmitry Torokhov
[not found] ` <20140923161724.GA40700-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2014-09-23 20:31 ` Rafael J. Wysocki
2014-09-23 16:25 ` Rafael J. Wysocki
[not found] ` <2895905.coa5UvrkJk-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-09-23 16:26 ` Arnd Bergmann
2014-09-23 20:47 ` Rafael J. Wysocki
[not found] ` <1579761.oeYleOAY1N-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-09-24 7:55 ` Arnd Bergmann
2014-09-24 14:08 ` Rafael J. Wysocki
2014-09-23 21:15 ` Darren Hart
2014-09-24 9:12 ` Arnd Bergmann
2014-09-24 9:38 ` Mika Westerberg
2014-09-24 14:11 ` Rafael J. Wysocki
2014-09-26 3:21 ` Darren Hart
2014-09-26 8:36 ` Arnd Bergmann
2014-09-26 14:42 ` Rafael J. Wysocki
2014-10-07 13:37 ` Linus Walleij
2014-10-07 15:37 ` Andy Shevchenko
2014-10-07 23:57 ` Rafael J. Wysocki
2014-09-16 11:52 ` [RFC PATCH v2 08/16] gpio: sch: Consolidate core and resume banks Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 09/16] leds: leds-gpio: Add support for GPIO descriptors Mika Westerberg
2014-09-19 8:18 ` Alexandre Courbot
2014-09-24 7:55 ` Linus Walleij
2014-09-24 9:42 ` Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 10/16] leds: leds-gpio: Make use of device property API Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 11/16] leds: leds-gpio: Add ACPI probing support Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 12/16] input: gpio_keys_polled - Add support for GPIO descriptors Mika Westerberg
2014-09-19 8:22 ` Alexandre Courbot
2014-09-24 8:02 ` Linus Walleij
2014-09-16 11:52 ` [RFC PATCH v2 13/16] input: gpio_keys_polled - Make use of device property API Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 14/16] input: gpio_keys_polled - Add ACPI probing support Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 15/16] misc: at25: Make use of device property API Mika Westerberg
2014-09-16 11:52 ` [RFC PATCH v2 16/16] misc: at25: Add ACPI probing support Mika Westerberg
2014-09-21 0:26 ` [RFC PATCH v2 00/16] Add ACPI _DSD and unified device properties support Rafael J. Wysocki
2014-09-24 8:34 ` Lee Jones
2014-09-24 9:45 ` Mika Westerberg
2014-09-22 23:29 ` Bryan Wu
2014-10-01 2:08 ` [PATCH v3 00/15] " Rafael J. Wysocki
2014-10-01 2:08 ` [PATCH v3 01/15] ACPI: Add support for device specific properties Rafael J. Wysocki
2014-10-01 7:38 ` Arnd Bergmann
2014-10-01 2:10 ` [PATCH v3 02/15] Driver core: Unified device properties interface for platform firmware Rafael J. Wysocki
2014-10-01 7:47 ` Arnd Bergmann
2014-10-01 22:09 ` Rafael J. Wysocki
2014-10-01 23:01 ` Rafael J. Wysocki
2014-10-02 7:46 ` Arnd Bergmann
2014-10-02 16:50 ` Rafael J. Wysocki
2014-10-02 0:03 ` Greg Kroah-Hartman
2014-10-01 2:10 ` [PATCH v3 03/15] ACPI: Allow drivers to match using Device Tree compatible property Rafael J. Wysocki
2014-10-01 7:48 ` Arnd Bergmann
2014-10-03 13:43 ` Mark Rutland
2014-10-03 17:59 ` Dmitry Torokhov
2014-10-04 0:02 ` Rafael J. Wysocki
2014-10-01 2:11 ` [PATCH v3 04/15] ACPI: Document ACPI device specific properties Rafael J. Wysocki
2014-10-01 7:59 ` Arnd Bergmann
2014-10-02 10:41 ` Mika Westerberg
2014-10-02 11:51 ` Arnd Bergmann
2014-10-02 12:15 ` Mika Westerberg
2014-10-02 12:46 ` Arnd Bergmann
2014-10-02 13:36 ` Mika Westerberg
2014-10-02 14:29 ` Arnd Bergmann
2014-10-02 14:38 ` Mika Westerberg
2014-10-02 14:55 ` Arnd Bergmann
2014-10-03 13:56 ` Mark Rutland
2014-10-03 15:02 ` Arnd Bergmann
2014-10-03 23:58 ` Rafael J. Wysocki
2014-10-04 10:56 ` Arnd Bergmann
2014-10-05 21:40 ` Rafael J. Wysocki
2014-10-03 2:03 ` Rafael J. Wysocki
2014-10-03 8:12 ` Mika Westerberg
2014-10-03 13:58 ` Mark Rutland
2014-10-03 14:38 ` Rafael J. Wysocki
2014-10-03 14:35 ` Mark Rutland
2014-10-04 0:13 ` Rafael J. Wysocki
[not found] ` <6568619.UkU5qISONv-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-10-04 10:59 ` Arnd Bergmann
2014-10-05 22:26 ` Rafael J. Wysocki
2014-10-03 13:48 ` Mark Rutland
2014-10-04 0:16 ` Rafael J. Wysocki
2014-10-01 2:12 ` [PATCH v3 05/15] gpio / ACPI: Add support for _DSD device properties Rafael J. Wysocki
[not found] ` <4786851.38d7sjpzag-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-10-01 8:03 ` Arnd Bergmann
2014-10-05 10:36 ` Alexandre Courbot
2014-10-05 21:20 ` Rafael J. Wysocki
2014-10-01 2:15 ` [PATCH v3 07/15] gpio: sch: Consolidate core and resume banks Rafael J. Wysocki
2014-10-01 2:15 ` [PATCH v3 08/15] leds: leds-gpio: Add support for GPIO descriptors Rafael J. Wysocki
[not found] ` <1490183.QvrzPxsV7q-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-10-01 8:05 ` Arnd Bergmann
2014-10-01 2:16 ` [PATCH v3 09/15] leds: leds-gpio: Make use of device property API Rafael J. Wysocki
2014-10-03 14:07 ` Mark Rutland
2014-10-04 0:18 ` Rafael J. Wysocki
2014-10-01 2:17 ` [PATCH v3 10/15] leds: leds-gpio: Add ACPI probing support Rafael J. Wysocki
2014-10-01 8:13 ` Arnd Bergmann
2014-10-01 9:13 ` Mika Westerberg
2014-10-01 10:01 ` Arnd Bergmann
2014-10-01 11:59 ` Mika Westerberg
2014-10-01 13:52 ` Arnd Bergmann
2014-10-01 14:04 ` Mika Westerberg
[not found] ` <20141001140441.GF1786-3PARRvDOhMZrdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2014-10-01 14:14 ` Arnd Bergmann
2014-10-02 9:55 ` Mika Westerberg
2014-10-02 10:44 ` Arnd Bergmann
2014-10-01 16:30 ` Dmitry Torokhov
2014-10-01 18:11 ` Darren Hart
2014-10-01 18:21 ` Dmitry Torokhov
2014-10-01 18:22 ` Arnd Bergmann
2014-10-01 2:17 ` [PATCH v3 11/15] input: gpio_keys_polled - Add support for GPIO descriptors Rafael J. Wysocki
2014-10-01 8:13 ` Arnd Bergmann
2014-10-01 2:20 ` [PATCH v3 12/15] input: gpio_keys_polled - Make use of device property API Rafael J. Wysocki
2014-10-01 2:20 ` [PATCH v3 13/15] input: gpio_keys_polled - Add ACPI probing support Rafael J. Wysocki
2014-10-01 7:48 ` Dmitry Torokhov
2014-10-01 9:15 ` Mika Westerberg
2014-10-01 16:28 ` Dmitry Torokhov
2014-10-02 9:53 ` Mika Westerberg
2014-10-01 2:21 ` [PATCH v3 14/15] misc: at25: Make use of device property API Rafael J. Wysocki
[not found] ` <2074642.sV7QBxD3Ne-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-10-01 8:14 ` Arnd Bergmann
[not found] ` <1852462.V1jlbi8OPt-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-10-01 2:14 ` [PATCH v3 06/15] gpio: Support for unified device properties interface Rafael J. Wysocki
2014-10-01 2:22 ` [PATCH v3 15/15] misc: at25: Add ACPI probing support Rafael J. Wysocki
2014-10-01 8:15 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1410868367-11056-7-git-send-email-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=aaron.lu@intel.com \
--cc=arnd@arndb.de \
--cc=cooloney@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=dvhart@linux.intel.com \
--cc=gnurou@gmail.com \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=lee.jones@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rjw@rjwysocki.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).