mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jules Maselbas <jmaselbas@kalray.eu>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 10/10] gpiolib: add of_xlate support
Date: Fri, 2 Jun 2023 10:11:17 +0200	[thread overview]
Message-ID: <ZHmkJeexhHCQ0JP0@tellis.lin.mbt.kalray.eu> (raw)
In-Reply-To: <20230602074921.2687669-11-m.felsch@pengutronix.de>

Hi Marco,

On Fri, Jun 02, 2023 at 09:49:21AM +0200, Marco Felsch wrote:
> The of_xlate function can be used to by drivers which need a other gpio
> encoding than:
> 
>   gpio = <&phandle gpio-nr gpio-flags>;
> 
> The of_xlate code is as close as possible to the kernel counter part
> which makes it easier to add 'struct gpio_desc' support later on.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
>  drivers/gpio/gpiolib.c | 51 ++++++++++++++++++++++++++++++++++++++
>  drivers/of/of_gpio.c   | 56 +++++++++++++++++++++++++++++++++---------
>  include/gpio.h         | 25 +++++++++++++++++++
>  3 files changed, 120 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index d1087aa583..ab9a0e30be 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -592,6 +592,43 @@ static int of_gpiochip_set_names(struct gpio_chip *chip)
>  	return 0;
>  }
>  
> +/**
> + * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags
> + * @gc:		pointer to the gpio_chip structure
> + * @gpiospec:	GPIO specifier as found in the device tree
> + * @flags:	a flags pointer to fill in
> + *
> + * This is simple translation function, suitable for the most 1:1 mapped
> + * GPIO chips. This function performs only one sanity check: whether GPIO
> + * is less than ngpios (that is specified in the gpio_chip).
> + */
> +static int of_gpio_simple_xlate(struct gpio_chip *gc,
> +				const struct of_phandle_args *gpiospec,
> +				u32 *flags)
> +{
> +	/*
> +	 * We're discouraging gpio_cells < 2, since that way you'll have to
> +	 * write your own xlate function (that will have to retrieve the GPIO
> +	 * number and the flags from a single gpio cell -- this is possible,
> +	 * but not recommended).
> +	 */
> +	if (gc->of_gpio_n_cells < 2) {
> +		WARN_ON(1);
> +		return -EINVAL;
> +	}
> +
> +	if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
> +		return -EINVAL;
> +
> +	if (gpiospec->args[0] >= gc->ngpio)
> +		return -EINVAL;
> +
> +	if (flags)
> +		*flags = gpiospec->args[1];
> +
> +	return gc->base + gpiospec->args[0];
> +}
> +
>  static int of_gpiochip_add(struct gpio_chip *chip)
>  {
>  	struct device_node *np;
> @@ -601,6 +638,20 @@ static int of_gpiochip_add(struct gpio_chip *chip)
>  	if (!np)
>  		return 0;
>  
> +	if (!chip->ops->of_xlate)
> +		chip->ops->of_xlate = of_gpio_simple_xlate;
> +
> +	/*
> +	 * Seperate check since the 'struct gpio_ops' is alawys the same for
typos: s/Seperate/Separate/  and s/alawys/always/

> +	 * every 'struct gpio_chip' of the same instance (e.g. 'struct
> +	 * imx_gpio_chip').
> +	 */
> +	if (chip->ops->of_xlate == of_gpio_simple_xlate)
> +		chip->of_gpio_n_cells = 2;
> +
> +	if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS)
> +		return -EINVAL;
> +
>  	ret = of_gpiochip_set_names(chip);
>  	if (ret)
>  		return ret;

Thanks :)







  reply	other threads:[~2023-06-02  8:21 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02  7:49 [PATCH 00/10] Fix gpio-hogs and sync with Linux gpiolib Marco Felsch
2023-06-02  7:49 ` [PATCH 01/10] gpiolib: fix gpio-hog functionality Marco Felsch
2023-06-13  7:36   ` Ahmad Fatoum
2023-06-02  7:49 ` [PATCH 02/10] gpiolib: simplify for loop break condition Marco Felsch
2023-06-13  7:37   ` Ahmad Fatoum
2023-06-02  7:49 ` [PATCH 03/10] gpiolib: rename local gpio-line-names variable Marco Felsch
2023-06-13  7:38   ` Ahmad Fatoum
2023-06-02  7:49 ` [PATCH 04/10] gpiolib: fix gpio name memory leak Marco Felsch
2023-06-13  7:39   ` Ahmad Fatoum
2023-06-02  7:49 ` [PATCH 05/10] gpiolib: fix missing error check while query gpio-line-names Marco Felsch
2023-06-13  7:43   ` Ahmad Fatoum
2023-06-02  7:49 ` [PATCH 06/10] gpiolib: refactor gpio-line-names parsing Marco Felsch
2023-06-13  7:44   ` Ahmad Fatoum
2023-06-02  7:49 ` [PATCH 07/10] gpiolib: introduce of_gpiochip_add to bundle all of functions Marco Felsch
2023-06-13  7:46   ` Ahmad Fatoum
2023-06-02  7:49 ` [PATCH 08/10] OF: gpio: snyc of_get_named_gpio_flags variable with kernel Marco Felsch
2023-06-02  8:04   ` Jules Maselbas
2023-06-13  7:46   ` Ahmad Fatoum
2023-06-02  7:49 ` [PATCH 09/10] OF: gpio: fix device_node leakage Marco Felsch
2023-06-13  7:49   ` Ahmad Fatoum
2023-06-13  8:22     ` Marco Felsch
2023-06-02  7:49 ` [PATCH 10/10] gpiolib: add of_xlate support Marco Felsch
2023-06-02  8:11   ` Jules Maselbas [this message]
2023-06-05  7:49   ` Jules Maselbas
2023-06-05  9:51     ` Marco Felsch
2023-06-13  7:58   ` Ahmad Fatoum
2023-06-13 13:05   ` Ahmad Fatoum

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=ZHmkJeexhHCQ0JP0@tellis.lin.mbt.kalray.eu \
    --to=jmaselbas@kalray.eu \
    --cc=barebox@lists.infradead.org \
    --cc=m.felsch@pengutronix.de \
    /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