linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Daniel Scally <djrscally@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Tomasz Figa <tfiga@chromium.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Rajmohan Mani <rajmohan.mani@intel.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Wolfram Sang <wsa@kernel.org>, Lee Jones <lee.jones@linaro.org>,
	kieran.bingham+renesas@ideasonboard.com,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Hans de Goede <hdegoede@redhat.com>,
	Mark Gross <mgross@linux.intel.com>,
	Maximilian Luz <luzmaximilian@gmail.com>,
	Robert Moore <robert.moore@intel.com>,
	Erik Kaneda <erik.kaneda@intel.com>,
	me@fabwu.ch,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	linux-i2c <linux-i2c@vger.kernel.org>,
	Platform Driver <platform-driver-x86@vger.kernel.org>,
	devel@acpica.org
Subject: Re: [PATCH v3 4/6] gpiolib: acpi: Export acpi_get_gpiod()
Date: Mon, 22 Feb 2021 15:54:09 +0200	[thread overview]
Message-ID: <CAHp75VfQpMJt8t_fOyOO0gPL686egCTnfh1=DZRKTg84Omj8=Q@mail.gmail.com> (raw)
In-Reply-To: <20210222130735.1313443-5-djrscally@gmail.com>

On Mon, Feb 22, 2021 at 3:13 PM Daniel Scally <djrscally@gmail.com> wrote:
>
> I need to be able to translate GPIO resources in an ACPI device's _CRS

I -> we

> into GPIO descriptor array. Those are represented in _CRS as a pathname
> to a GPIO device plus the pin's index number: this function is perfect

Which one? "the acpi_...() function"

> for that purpose.
>
> As it's currently only used internally within the GPIO layer, provide and
> export a wrapper function that additionally holds a reference to the GPIO
> device.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
after addressing above and beyond :-)

>
> Signed-off-by: Daniel Scally <djrscally@gmail.com>
> ---
> Changes in v3:
>
>         - Having realised that it wasn't taking a reference to the GPIO device,
>           I decided the best thing to do was leave the existing function as-is
>           (apart from renaming) and provide a wrapper that simply passes
>           through to the original and takes a reference before returning the
>           struct gpio_desc
>
>           Because of the change to that functionality, I dropped the R-b's from
>           the last version.
>
>  drivers/gpio/gpiolib-acpi.c   | 36 +++++++++++++++++++++++++++++++----
>  include/linux/gpio/consumer.h |  7 +++++++
>  2 files changed, 39 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index e4d728fda982..0cc7cc327757 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> @@ -102,7 +102,8 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
>  }
>
>  /**
> - * acpi_get_gpiod() - Translate ACPI GPIO pin to GPIO descriptor usable with GPIO API
> + * __acpi_get_gpiod() - Translate ACPI GPIO pin to GPIO descriptor usable with

Can we rename it better, i.e. w/o __, like "acpi_gpio_pin_to_gpiod()" or so?

> + *                     GPIO API
>   * @path:      ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
>   * @pin:       ACPI GPIO pin number (0-based, controller-relative)
>   *
> @@ -111,7 +112,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
>   * controller does not have GPIO chip registered at the moment. This is to
>   * support probe deferral.
>   */
> -static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
> +static struct gpio_desc *__acpi_get_gpiod(char *path, int pin)
>  {
>         struct gpio_chip *chip;
>         acpi_handle handle;
> @@ -128,6 +129,33 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
>         return gpiochip_get_desc(chip, pin);
>  }
>
> +/**
> + * acpi_get_gpiod() - Translate ACPI GPIO pin to GPIO descriptor usable with
> + *                   GPIO API, and hold a refcount to the GPIO device.
> + * @path:      ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
> + * @pin:       ACPI GPIO pin number (0-based, controller-relative)
> + * @label:     Label to pass to gpiod_request()
> + *
> + * This function is a simple pass-through to __acpi_get_gpiod(), except that as
> + * it is intended for use outside of the GPIO layer (in a similar fashion to
> + * gpiod_get_index() for example) it also holds a reference to the GPIO device.
> + */
> +struct gpio_desc *acpi_get_gpiod(char *path, int pin, char *label)

Name better to reflect the action, perhaps
"acpi_gpio_get_and_request_desc()" or so.

> +{

> +       struct gpio_desc *gpio = __acpi_get_gpiod(path, pin);

Please, split it, so the assignment goes...

> +       int ret;

...here.

> +       if (IS_ERR(gpio))
> +               return gpio;
> +
> +       ret = gpiod_request(gpio, label);
> +       if (ret)
> +               return ERR_PTR(ret);
> +
> +       return gpio;
> +}
> +EXPORT_SYMBOL_GPL(acpi_get_gpiod);
> +
>  static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
>  {
>         struct acpi_gpio_event *event = data;
> @@ -689,8 +717,8 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
>                 if (pin_index >= agpio->pin_table_length)
>                         return 1;
>
> -               lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr,
> -                                             agpio->pin_table[pin_index]);
> +               lookup->desc = __acpi_get_gpiod(agpio->resource_source.string_ptr,
> +                                               agpio->pin_table[pin_index]);
>                 lookup->info.pin_config = agpio->pin_config;
>                 lookup->info.debounce = agpio->debounce_timeout;
>                 lookup->info.gpioint = gpioint;
> diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
> index ef49307611d2..6eee751f44dd 100644
> --- a/include/linux/gpio/consumer.h
> +++ b/include/linux/gpio/consumer.h
> @@ -690,6 +690,8 @@ int devm_acpi_dev_add_driver_gpios(struct device *dev,
>                                    const struct acpi_gpio_mapping *gpios);
>  void devm_acpi_dev_remove_driver_gpios(struct device *dev);
>
> +struct gpio_desc *acpi_get_gpiod(char *path, int pin, char *label);
> +
>  #else  /* CONFIG_GPIOLIB && CONFIG_ACPI */
>
>  struct acpi_device;
> @@ -708,6 +710,11 @@ static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
>  }
>  static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {}
>
> +struct gpio_desc *acpi_get_gpiod(char *path, int pin, char *label)
> +{
> +       return NULL;
> +}
> +
>  #endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
>
>
> --
> 2.25.1
>


-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2021-02-22 14:21 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-22 13:07 [PATCH v3 0/6] Introduce intel_skl_int3472 module Daniel Scally
2021-02-22 13:07 ` [PATCH v3 1/6] ACPI: scan: Extend acpi_walk_dep_device_list() Daniel Scally
2021-02-22 13:34   ` Andy Shevchenko
2021-03-07 13:36     ` Daniel Scally
2021-03-07 20:39       ` Andy Shevchenko
2021-03-08 13:36         ` Rafael J. Wysocki
2021-03-08 13:57           ` Andy Shevchenko
2021-03-08 15:45             ` Rafael J. Wysocki
2021-03-08 17:23               ` Rafael J. Wysocki
2021-03-08 20:49                 ` Daniel Scally
2021-02-22 13:38   ` Wolfram Sang
2021-03-08 17:46   ` Rafael J. Wysocki
2021-03-08 20:40     ` Daniel Scally
2021-02-22 13:07 ` [PATCH v3 2/6] ACPI: scan: Add function to fetch dependent of acpi device Daniel Scally
2021-02-22 13:41   ` Andy Shevchenko
2021-02-22 13:07 ` [PATCH v3 3/6] i2c: core: Add a format macro for I2C device names Daniel Scally
2021-02-22 13:38   ` Wolfram Sang
2021-02-22 13:07 ` [PATCH v3 4/6] gpiolib: acpi: Export acpi_get_gpiod() Daniel Scally
2021-02-22 13:54   ` Andy Shevchenko [this message]
2021-02-22 13:07 ` [PATCH v3 5/6] platform/x86: Add intel_skl_int3472 driver Daniel Scally
2021-02-22 13:19   ` Daniel Scally
2021-02-22 13:27     ` Hans de Goede
2021-02-22 22:50       ` Daniel Scally
2021-02-22 14:58   ` Andy Shevchenko
2021-02-22 22:35     ` Daniel Scally
2021-02-23 12:01       ` Andy Shevchenko
2021-02-23 13:06         ` Daniel Scally
2021-05-17 21:43     ` Daniel Scally
2021-05-17 21:47       ` Andy Shevchenko
2021-02-23 20:04   ` Laurent Pinchart
2021-02-23 22:36     ` Daniel Scally
2021-02-24 10:13       ` Laurent Pinchart
2021-02-24 10:18         ` Andy Shevchenko
2021-02-24 10:20           ` Daniel Scally
2021-02-22 13:07 ` [PATCH v3 6/6] mfd: tps68470: Remove tps68470 MFD driver Daniel Scally
2021-02-22 14:12   ` Andy Shevchenko
2021-02-22 22:37     ` Daniel Scally
2021-03-10  9:33   ` Lee Jones
2021-02-22 13:11 ` [PATCH v3 0/6] Introduce intel_skl_int3472 module Daniel Scally
2021-02-22 14:15 ` Andy Shevchenko
2021-03-04 13:37 ` Hans de Goede
2021-03-04 13:49   ` Daniel Scally
2021-03-29 15:03     ` Andy Shevchenko
2021-03-29 20:37       ` Daniel Scally

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='CAHp75VfQpMJt8t_fOyOO0gPL686egCTnfh1=DZRKTg84Omj8=Q@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=devel@acpica.org \
    --cc=djrscally@gmail.com \
    --cc=erik.kaneda@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=kieran.bingham+renesas@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=lee.jones@linaro.org \
    --cc=lenb@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luzmaximilian@gmail.com \
    --cc=me@fabwu.ch \
    --cc=mgross@linux.intel.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rajmohan.mani@intel.com \
    --cc=rjw@rjwysocki.net \
    --cc=robert.moore@intel.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tfiga@chromium.org \
    --cc=wsa@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).