From: Grant Likely <grant.likely@secretlab.ca>
To: Darren Hart <dvhart@linux.intel.com>,
"Rafael J. Wysocki" <rafael@kernel.org>
Cc: Aaron Lu <aaron.lu@intel.com>,
Max Eliaser <max.eliaser@intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
linux-acpi@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 6/9] gpiolib: add API to get gpio desc and flags
Date: Sun, 17 Aug 2014 14:00:04 +0100 [thread overview]
Message-ID: <20140817130004.4B9FDC4137F@trevor.secretlab.ca> (raw)
In-Reply-To: <1408255459-17625-7-git-send-email-mika.westerberg@linux.intel.com>
On Sun, 17 Aug 2014 09:04:16 +0300, Mika Westerberg <mika.westerberg@linux.intel.com> wrote:
> From: Aaron Lu <aaron.lu@intel.com>
>
> Add a new API to get the GPIO's description pointer and its flags for
> both OF based system and ACPI based system. This is useful in drivers
> that do not need to care about the underlying firmware interface.
Hi Mika,
I've only looked at this one briefly, and noticed one problem below...
g.
>
> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
> Signed-off-by: Max Eliaser <max.eliaser@intel.com>
> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> ---
> drivers/gpio/gpiolib-acpi.c | 81 ++++++++++++++++++++++++++++++++-----------
> drivers/gpio/gpiolib.c | 18 ++++++++++
> drivers/gpio/gpiolib.h | 8 +++++
> include/linux/gpio/consumer.h | 11 ++++++
> 4 files changed, 97 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index 4a987917c186..f35e88d29a47 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> @@ -293,11 +293,38 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data)
> agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT;
> lookup->info.active_low =
> agpio->polarity == ACPI_ACTIVE_LOW;
> + lookup->info.pin_config = agpio->pin_config;
> }
>
> return 1;
> }
>
> +static struct gpio_desc *
> +__acpi_get_gpiod_by_index(struct acpi_device *adev, int index,
> + struct acpi_gpio_info *info)
> +{
> + struct acpi_gpio_lookup lookup;
> + struct list_head resource_list;
> + int ret;
> +
> + memset(&lookup, 0, sizeof(lookup));
> + lookup.index = index;
> +
> + INIT_LIST_HEAD(&resource_list);
> + ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio,
> + &lookup);
> + if (ret < 0)
> + return ERR_PTR(ret);
> +
> + acpi_dev_free_resource_list(&resource_list);
> +
> + if (lookup.desc && info)
> + *info = lookup.info;
> +
> + return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT);
> +}
> +
> +
> /**
> * acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources
> * @dev: pointer to a device to get GPIO from
> @@ -318,34 +345,46 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data)
> struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
> struct acpi_gpio_info *info)
> {
> - struct acpi_gpio_lookup lookup;
> - struct list_head resource_list;
> - struct acpi_device *adev;
> - acpi_handle handle;
> - int ret;
> -
> - if (!dev)
> + if (!dev || !ACPI_COMPANION(dev))
> return ERR_PTR(-EINVAL);
> + return __acpi_get_gpiod_by_index(ACPI_COMPANION(dev), index, info);
> +}
>
> - handle = ACPI_HANDLE(dev);
> - if (!handle || acpi_bus_get_device(handle, &adev))
> - return ERR_PTR(-ENODEV);
> -
> - memset(&lookup, 0, sizeof(lookup));
> - lookup.index = index;
> +struct gpio_desc *acpi_get_gpiod_flags(struct device *dev, int idx,
> + enum gpio_lookup_flags *flags)
> +{
> + struct acpi_device *adev = ACPI_COMPANION(dev);
> + struct acpi_reference_args args;
> + struct acpi_gpio_info info;
> + struct gpio_desc *desc;
> + bool active_low;
> + int ret;
>
> - INIT_LIST_HEAD(&resource_list);
> - ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio,
> - &lookup);
> - if (ret < 0)
> + ret = acpi_dev_get_property_reference(adev, "gpios", NULL, idx, &args);
> + if (ret)
> return ERR_PTR(ret);
>
> - acpi_dev_free_resource_list(&resource_list);
> + desc = __acpi_get_gpiod_by_index(args.adev, args.args[0], &info);
> + if (IS_ERR(desc))
> + return desc;
>
> - if (lookup.desc && info)
> - *info = lookup.info;
> + /*
> + * The 3rd argument optionally specifies the pin polarity. We
> + * use that if it exists, otherwise we resort to the pin config.
> + * (Note that the first element of the "gpios" package goes into
> + * arg.adev, not args.args.)
> + */
> + if (args.nargs >= 3)
> + active_low = !!args.args[2];
> + else if (info.gpioint)
> + active_low = !!info.active_low;
> + else
> + active_low = !!(info.pin_config & ACPI_PIN_CONFIG_PULLUP);
>
> - return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT);
> + if (active_low)
> + *flags |= GPIO_ACTIVE_LOW;
> +
> + return desc;
> }
>
> static acpi_status
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 2ebc9071e354..e6c2413a6fbf 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2644,6 +2644,24 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id,
> return desc;
> }
>
> +struct gpio_desc *dev_get_gpiod_flags(struct device *dev, unsigned int idx,
> + enum gpio_lookup_flags *flags)
> +{
> + struct gpio_desc *desc = ERR_PTR(-ENOENT);
> +
> + if (!dev || !flags)
> + return ERR_PTR(-EINVAL);
> +
> + /* Using device tree? */
> + if (IS_ENABLED(CONFIG_OF) && dev->of_node)
> + desc = of_find_gpio(dev, NULL, idx, flags);
of_find_gpio() doesn't exist.
> + else if (IS_ENABLED(CONFIG_ACPI) && ACPI_COMPANION(dev))
> + desc = acpi_get_gpiod_flags(dev, idx, flags);
> +
> + return desc;
> +}
> +EXPORT_SYMBOL(dev_get_gpiod_flags);
> +
> static struct gpiod_lookup_table *gpiod_find_lookup_table(struct device *dev)
> {
> const char *dev_id = dev ? dev_name(dev) : NULL;
> diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
> index 1a4103dd38df..a759db968e51 100644
> --- a/drivers/gpio/gpiolib.h
> +++ b/drivers/gpio/gpiolib.h
> @@ -25,6 +25,7 @@ enum of_gpio_flags;
> struct acpi_gpio_info {
> bool gpioint;
> bool active_low;
> + u8 pin_config;
> };
>
> #ifdef CONFIG_ACPI
> @@ -33,6 +34,8 @@ void acpi_gpiochip_remove(struct gpio_chip *chip);
>
> struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
> struct acpi_gpio_info *info);
> +struct gpio_desc *acpi_get_gpiod_flags(struct device *dev, int index,
> + enum gpio_lookup_flags *flags);
> #else
> static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
> static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
> @@ -43,6 +46,11 @@ acpi_get_gpiod_by_index(struct device *dev, int index,
> {
> return ERR_PTR(-ENOSYS);
> }
> +static struct gpio_desc *acpi_get_gpiod_flags(struct device *dev, int index,
> + enum gpio_lookup_flags *flags)
> +{
> + return ERR_PTR(-ENOSYS);
> +}
> #endif
>
> int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label);
> diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
> index 05e53ccb708b..53f422e4f0c9 100644
> --- a/include/linux/gpio/consumer.h
> +++ b/include/linux/gpio/consumer.h
> @@ -7,6 +7,8 @@
>
> struct device;
>
> +enum gpio_lookup_flags;
> +
> /**
> * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
> * preferable to the old integer-based handles.
> @@ -73,6 +75,9 @@ int gpiod_to_irq(const struct gpio_desc *desc);
> struct gpio_desc *gpio_to_desc(unsigned gpio);
> int desc_to_gpio(const struct gpio_desc *desc);
>
> +struct gpio_desc *dev_get_gpiod_flags(struct device *dev, unsigned int idx,
> + enum gpio_lookup_flags *flags);
> +
> #else /* CONFIG_GPIOLIB */
>
> static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
> @@ -254,6 +259,12 @@ static inline int desc_to_gpio(const struct gpio_desc *desc)
> return -EINVAL;
> }
>
> +static inline struct gpio_desc *dev_get_gpiod_flags(struct device *dev,
> + unsigned int idx, enum gpio_lookup_flags *flags)
> +{
> + return ERR_PTR(-ENOSYS);
> +}
> +
>
> #endif /* CONFIG_GPIOLIB */
>
> --
> 2.1.0.rc1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2014-08-17 13:00 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-17 6:04 [RFC PATCH 0/9] Add ACPI _DSD and unified device properties support Mika Westerberg
2014-08-17 6:04 ` [RFC PATCH 1/9] ACPI: Add support for device specific properties Mika Westerberg
2014-08-18 8:13 ` Hanjun Guo
2014-08-18 8:27 ` Mika Westerberg
2014-08-18 8:57 ` Hanjun Guo
2014-08-18 12:37 ` Darren Hart
[not found] ` <1408255459-17625-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-08-17 6:04 ` [RFC PATCH 2/9] ACPI: Document ACPI " Mika Westerberg
2014-08-18 10:54 ` Mark Rutland
2014-08-18 16:05 ` Mika Westerberg
2014-08-19 5:45 ` Darren Hart
2014-08-19 16:51 ` Mark Rutland
2014-08-17 6:04 ` [RFC PATCH 6/9] gpiolib: add API to get gpio desc and flags Mika Westerberg
2014-08-17 13:00 ` Grant Likely [this message]
2014-08-17 17:43 ` Darren Hart
2014-08-18 4:57 ` Rafael J. Wysocki
[not found] ` <1927766.GeLld99ozq-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2014-08-18 7:16 ` Aaron Lu
2014-08-19 15:58 ` Grant Likely
2014-08-17 6:04 ` [RFC PATCH 7/9] gpio: sch: Consolidate core and resume banks Mika Westerberg
2014-08-17 6:04 ` [RFC PATCH 3/9] Driver core: Unified device properties interface for platform firmware Mika Westerberg
2014-08-17 12:49 ` Grant Likely
2014-08-17 17:31 ` Darren Hart
2014-08-18 4:55 ` Rafael J. Wysocki
2014-08-18 4:46 ` Rafael J. Wysocki
2014-08-17 6:04 ` [RFC PATCH 4/9] of: Add property_ops callback for devices with of_node Mika Westerberg
2014-08-17 12:54 ` Grant Likely
2014-08-18 9:29 ` Mika Westerberg
[not found] ` <20140818092937.GT2462-3PARRvDOhMZrdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2014-08-18 12:44 ` Darren Hart
2014-08-18 0:44 ` Rob Herring
2014-08-17 6:04 ` [RFC PATCH 5/9] mfd: Add ACPI support Mika Westerberg
2014-08-28 11:29 ` Lee Jones
2014-08-28 11:45 ` Mika Westerberg
2014-08-17 6:04 ` [RFC PATCH 8/9] Input: gpio_keys_polled - Make use of device property API Mika Westerberg
2014-08-17 6:04 ` [RFC PATCH 9/9] leds: leds-gpio: " Mika Westerberg
-- strict thread matches above, loose matches on Subject: below --
2014-08-16 6:53 [RFC PATCH 0/9] Add ACPI _DSD and unified device properties support Mika Westerberg
2014-08-16 6:53 ` [RFC PATCH 6/9] gpiolib: add API to get gpio desc and flags Mika Westerberg
2014-08-18 16:24 ` Alexandre Courbot
2014-08-19 8:56 ` Mika Westerberg
2014-08-19 9:02 ` Aaron Lu
2014-08-19 17:16 ` Alexandre Courbot
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=20140817130004.4B9FDC4137F@trevor.secretlab.ca \
--to=grant.likely@secretlab.ca \
--cc=aaron.lu@intel.com \
--cc=devicetree@vger.kernel.org \
--cc=dvhart@linux.intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=max.eliaser@intel.com \
--cc=mika.westerberg@linux.intel.com \
--cc=rafael@kernel.org \
/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).