linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Johan Korsnes <johan.korsnes@remarkable.no>,
	Bough Chen <haibo.chen@nxp.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	imx@lists.linux.dev, linux-gpio@vger.kernel.org
Subject: Re: [PATCH v3 1/2] gpio: mmio: Add flag for calling pinctrl back-end
Date: Mon, 24 Feb 2025 22:32:30 +0200	[thread overview]
Message-ID: <Z7zXXmtuDFWGRmfm@surfacebook.localdomain> (raw)
In-Reply-To: <20250219-vf610-mmio-v3-1-588b64f0b689@linaro.org>

Wed, Feb 19, 2025 at 10:04:33PM +0100, Linus Walleij kirjoitti:
> It turns out that with this flag we can switch over an entire
> driver to use gpio-mmio instead of a bunch of custom code,
> also providing get/set_multiple() to it in the process, so it
> seems like a reasonable feature to add.
> 
> The generic pin control backend requires us to call the
> gpiochip_generic_request(), gpiochip_generic_free(),
> pinctrl_gpio_direction_output() and pinctrl_gpio_direction_input()
> callbacks, so if the new flag for a pin control back-end
> is set, we make sure these functions get called as
> expected.

First of all, I like the series and esp. the second patch, thanks!
One small comment below, though.

...

>  static int bgpio_request(struct gpio_chip *chip, unsigned gpio_pin)
>  {
> -	if (gpio_pin < chip->ngpio)
> -		return 0;
> +	if (gpio_pin >= chip->ngpio)
> +		return -EINVAL;
>  
> -	return -EINVAL;
> +	if (chip->bgpio_pinctrl)
> +		return gpiochip_generic_request(chip, gpio_pin);
> +
> +	return 0;
>  }

While I understand the desire to avoid +LoCs, I still think it's better from
maintenance p.o.v. to have a symmetry in APIs, i.e. providing

bgpio_free()  // or whatever name suits with possibility to change the above
{
	if (chip->bgpio_pinctrl)
		gpiochip_generic_free(...);
}

...

> +	if (flags & BGPIOF_PINCTRL_BACKEND) {
> +		gc->bgpio_pinctrl = true;
> +		/* Currently this callback is only used for pincontrol */
> +		gc->free = gpiochip_generic_free;
> +	}

And

	gc->free = gpiochip_generic_free;
	...
	if (flags & BGPIOF_PINCTRL_BACKEND)
		gc->bgpio_pinctrl = true;

here.

The rationale that if we ever add something to the request part, we won't
forget to call it in the free part.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-02-24 20:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-19 21:04 [PATCH v3 0/2] gpio-mmio: Extend to handle pinctrl back-ends Linus Walleij
2025-02-19 21:04 ` [PATCH v3 1/2] gpio: mmio: Add flag for calling pinctrl back-end Linus Walleij
2025-02-24 20:32   ` Andy Shevchenko [this message]
2025-02-19 21:04 ` [PATCH v3 2/2] gpio: vf610: Switch to gpio-mmio Linus Walleij
2025-02-21  3:57   ` Bough Chen
2025-02-21 10:16     ` Bartosz Golaszewski
2025-02-21 10:54       ` Bough Chen
2025-02-23 13:57   ` Johan Korsnes
2025-02-24 19:50 ` [PATCH v3 0/2] gpio-mmio: Extend to handle pinctrl back-ends Bartosz Golaszewski

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=Z7zXXmtuDFWGRmfm@surfacebook.localdomain \
    --to=andy.shevchenko@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=haibo.chen@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=johan.korsnes@remarkable.no \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.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).