mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Michael Walle" <mwalle@kernel.org>
To: "Ioana Ciornei" <ioana.ciornei@nxp.com>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-gpio@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>
Cc: "Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Shawn Guo" <shawnguo@kernel.org>, "Lee Jones" <lee@kernel.org>,
	"Frank Li" <Frank.Li@nxp.com>
Subject: Re: [PATCH 4/9] gpio: regmap: add the .get_direction() callback
Date: Wed, 09 Jul 2025 17:01:38 +0200	[thread overview]
Message-ID: <DB7M5DTXEACR.3N7DO1DM0PZB1@kernel.org> (raw)
In-Reply-To: <20250709112658.1987608-5-ioana.ciornei@nxp.com>

Hi Ioana,

great to see another user of gpio-regmap.

On Wed Jul 9, 2025 at 1:26 PM CEST, Ioana Ciornei wrote:
> There are GPIO controllers such as the one present in the LX2160ARDB
> QIXIS CPLD which are single register fixed-direction. This cannot be
> modeled using the gpio-regmap as-is since there is no way to
> present the true direction of a GPIO line.

You mean input and output mixed together in one register? At least
to me, that wasn't so obvious by the commit message, I had to look
at the actual driver.

> In order to make this use case possible, add a new callback to the
> gpio_config structure - .get_direction() - which can be used by user
> drivers to provide the fixed direction per GPIO line.
>
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> ---
>  drivers/gpio/gpio-regmap.c  | 17 ++++++++++++++++-
>  include/linux/gpio/regmap.h |  3 +++
>  2 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
> index 87c4225784cf..dac2acb26655 100644
> --- a/drivers/gpio/gpio-regmap.c
> +++ b/drivers/gpio/gpio-regmap.c
> @@ -32,6 +32,8 @@ struct gpio_regmap {
>  	unsigned int reg_dir_in_base;
>  	unsigned int reg_dir_out_base;
>  
> +	int (*get_direction)(struct gpio_regmap *gpio, unsigned int offset);
> +
>  	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
>  			      unsigned int offset, unsigned int *reg,
>  			      unsigned int *mask);
> @@ -129,6 +131,9 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip,
>  	unsigned int base, val, reg, mask;
>  	int invert, ret;
>  
> +	if (gpio->get_direction)
> +		return gpio->get_direction(gpio, offset);
> +
>  	if (gpio->reg_dat_base && !gpio->reg_set_base)
>  		return GPIO_LINE_DIRECTION_IN;
>  	if (gpio->reg_set_base && !gpio->reg_dat_base)
> @@ -163,7 +168,16 @@ static int gpio_regmap_set_direction(struct gpio_chip *chip,
>  {
>  	struct gpio_regmap *gpio = gpiochip_get_data(chip);
>  	unsigned int base, val, reg, mask;
> -	int invert, ret;
> +	int invert, ret, dir;
> +
> +	if (gpio->get_direction) {
> +		dir = gpio->get_direction(gpio, offset);
> +		if (dir == GPIO_LINE_DIRECTION_IN && output)
> +			return -EOPNOTSUPP;
> +		if (dir == GPIO_LINE_DIRECTION_OUT && !output)
> +			return -EOPNOTSUPP;
> +		return 0;
> +	}

What is the intention here? Shouldn't there be just a .set_direction
op and if there isn't one, return EOPNOTSUPP?

In any case, that is unused code for your driver as far as I see,
because you neither set .reg_dir_in_base nor .reg_dir_out_base and
thus, .direction_input nor .direction_output are set within the
gpio_chip struct (see gpio_regmap_register()).

>  	if (gpio->reg_dir_out_base) {
>  		base = gpio_regmap_addr(gpio->reg_dir_out_base);
> @@ -247,6 +261,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
>  	gpio->reg_clr_base = config->reg_clr_base;
>  	gpio->reg_dir_in_base = config->reg_dir_in_base;
>  	gpio->reg_dir_out_base = config->reg_dir_out_base;
> +	gpio->get_direction = config->get_direction;
>  
>  	chip = &gpio->gpio_chip;
>  	chip->parent = config->parent;
> diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
> index c722c67668c6..99fd973e61fa 100644
> --- a/include/linux/gpio/regmap.h
> +++ b/include/linux/gpio/regmap.h
> @@ -37,6 +37,8 @@ struct regmap;
>   *			offset to a register/bitmask pair. If not
>   *			given the default gpio_regmap_simple_xlate()
>   *			is used.
> + * @get_direction:	(Optional) Callback to the user driver to return the
> + *			fixed direction of the GPIO line
>   * @drvdata:		(Optional) Pointer to driver specific data which is
>   *			not used by gpio-remap but is provided "as is" to the
>   *			driver callback(s).
> @@ -81,6 +83,7 @@ struct gpio_regmap_config {
>  	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
>  			      unsigned int offset, unsigned int *reg,
>  			      unsigned int *mask);
> +	int (*get_direction)(struct gpio_regmap *gpio, unsigned int offset);
>  
>  	void *drvdata;
>  };


  reply	other threads:[~2025-07-09 15:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 11:26 [PATCH 0/9] drivers: gpio: and the QIXIS FPGA GPIO controller Ioana Ciornei
2025-07-09 11:26 ` [PATCH 1/9] dt-bindings: gpio: add bindings for the QIXIS FPGA based " Ioana Ciornei
2025-07-09 12:14   ` Krzysztof Kozlowski
2025-07-09 13:55     ` Ioana Ciornei
2025-07-09 14:11       ` Krzysztof Kozlowski
2025-07-10 22:01   ` Rob Herring
2025-07-15 12:19     ` Ioana Ciornei
2025-07-09 11:26 ` [PATCH 2/9] dt-bindings: fsl,fpga-qixis-i2c: extend support to also cover the LX2160ARDB FPGA Ioana Ciornei
2025-07-09 12:17   ` Krzysztof Kozlowski
2025-07-09 14:31     ` Ioana Ciornei
2025-07-10 22:04     ` Rob Herring
2025-07-09 11:26 ` [PATCH 3/9] mfd: simple-mfd-i2c: add compatible string for LX2160ARDB Ioana Ciornei
2025-07-09 11:26 ` [PATCH 4/9] gpio: regmap: add the .get_direction() callback Ioana Ciornei
2025-07-09 15:01   ` Michael Walle [this message]
2025-07-14 13:17     ` Ioana Ciornei
2025-07-09 15:09   ` Andrew Lunn
2025-07-09 15:36     ` Michael Walle
2025-07-10  9:23     ` Ioana Ciornei
2025-07-11 17:43     ` Linus Walleij
2025-07-11 17:45       ` Andrew Lunn
2025-07-11 18:06         ` Linus Walleij
2025-07-14  6:36           ` Michael Walle
2025-07-15 11:38             ` Ioana Ciornei
2025-07-15 12:51               ` Michael Walle
2025-07-09 11:26 ` [PATCH 5/9] drivers: gpio: add QIXIS FPGA GPIO controller Ioana Ciornei
2025-07-09 15:17   ` Andrew Lunn
2025-07-10 10:01     ` Ioana Ciornei
2025-07-10 14:12       ` Andrew Lunn
2025-07-09 11:26 ` [PATCH 6/9] arm64: dts: lx2160a-rdb: describe the QIXIS FPGA and two child GPIO controllers Ioana Ciornei
2025-07-09 11:26 ` [PATCH 7/9] arm64: dts: ls1046a-qds: describe the FPGA based GPIO controller Ioana Ciornei
2025-07-09 11:26 ` [PATCH 8/9] arm64: dts: lx2160a-rdb: fully describe the two SFP+ cages Ioana Ciornei
2025-07-09 11:26 ` [PATCH 9/9] arm64: dts: ls1046a-qds: describe the two on-board " Ioana Ciornei

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=DB7M5DTXEACR.3N7DO1DM0PZB1@kernel.org \
    --to=mwalle@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=ioana.ciornei@nxp.com \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=shawnguo@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

all inboxes | Powered by JetHome®