devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael Walle" <mwalle@kernel.org>
To: "Ioana Ciornei" <ioana.ciornei@nxp.com>,
	"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>,
	<devicetree@vger.kernel.org>, <linux-gpio@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: "Frank Li" <Frank.Li@nxp.com>
Subject: Re: [PATCH v2 4/9] gpio: regmap: add the .fixed_direction_output configuration parameter
Date: Mon, 15 Sep 2025 14:45:58 +0200	[thread overview]
Message-ID: <DCTDUJO0PS8B.1LD03WTEMNRVP@kernel.org> (raw)
In-Reply-To: <20250915122354.217720-5-ioana.ciornei@nxp.com>

[-- Attachment #1: Type: text/plain, Size: 3505 bytes --]

Hi Ioana,

On Mon Sep 15, 2025 at 2:23 PM CEST, Ioana Ciornei wrote:
> There are GPIO controllers such as the one present in the LX2160ARDB
> QIXIS FPGA which have fixed-direction input and output GPIO lines mixed
> together in a single register. This cannot be modeled using the
> gpio-regmap as-is since there is no way to present the true direction of
> a GPIO line.
>
> In order to make this use case possible, add a new configuration
> parameter - fixed_direction_output - into the gpio_regmap_config
> structure. This will enable user drivers to provide a bitmap that
> represents the fixed direction of the GPIO lines.

I wonder about the ownership of that allocated memory in the config
structure (and btw, I guess you leak the memory in your driver) and
if it's not better and more error proof to allocate and copy the
bitmap in gpio-regmap too (and maybe use devm_bitmap_alloc()) and
leave it to the caller to handle the passed bitmap. I.e. it could
also be on the stack.

Otherwise, this looks good.

> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> ---
> Changes in v2:
> - Add the fixed_direction_output bitmap to the gpio_regmap_config
>
>  drivers/gpio/gpio-regmap.c  | 12 ++++++++++++
>  include/linux/gpio/regmap.h |  2 ++
>  2 files changed, 14 insertions(+)
>
> diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
> index e8a32dfebdcb..2489768686d3 100644
> --- a/drivers/gpio/gpio-regmap.c
> +++ b/drivers/gpio/gpio-regmap.c
> @@ -31,6 +31,7 @@ struct gpio_regmap {
>  	unsigned int reg_clr_base;
>  	unsigned int reg_dir_in_base;
>  	unsigned int reg_dir_out_base;
> +	unsigned long *fixed_direction_output;
>  
>  	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
>  			      unsigned int offset, unsigned int *reg,
> @@ -129,6 +130,16 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip,
>  	unsigned int base, val, reg, mask;
>  	int invert, ret;
>  
> +	if (offset >= chip->ngpio)
> +		return -EINVAL;

Not sure this can happen. I tried to look into gpiolib.c but
couldn't find anything obvious that it can't happen. Maybe Linus or
Bartosz can comment on that.

> +
> +	if (gpio->fixed_direction_output) {
> +		if (test_bit(offset, gpio->fixed_direction_output))
> +			return GPIO_LINE_DIRECTION_OUT;
> +		else
> +			return GPIO_LINE_DIRECTION_IN;
> +	}
> +
>  	if (gpio->reg_dat_base && !gpio->reg_set_base)
>  		return GPIO_LINE_DIRECTION_IN;
>  	if (gpio->reg_set_base && !gpio->reg_dat_base)
> @@ -247,6 +258,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->fixed_direction_output = config->fixed_direction_output;
>  
>  	chip = &gpio->gpio_chip;
>  	chip->parent = config->parent;
> diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
> index c722c67668c6..34c143aca42d 100644
> --- a/include/linux/gpio/regmap.h
> +++ b/include/linux/gpio/regmap.h
> @@ -78,6 +78,8 @@ struct gpio_regmap_config {
>  	int ngpio_per_reg;
>  	struct irq_domain *irq_domain;
>  
> +	unsigned long *fixed_direction_output;

Please add some documentation.

-michael

> +
>  	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
>  			      unsigned int offset, unsigned int *reg,
>  			      unsigned int *mask);


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 297 bytes --]

  reply	other threads:[~2025-09-15 12:46 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15 12:23 [PATCH v2 0/9] drivers: gpio: and the QIXIS FPGA GPIO controller Ioana Ciornei
2025-09-15 12:23 ` [PATCH v2 1/9] dt-bindings: gpio: add QIXIS FPGA based " Ioana Ciornei
2025-09-15 20:29   ` Rob Herring
2025-09-16 16:07   ` Frank Li
2025-09-15 12:23 ` [PATCH v2 2/9] dt-bindings: fsl,fpga-qixis-i2c: extend support to also cover the LX2160ARDB FPGA Ioana Ciornei
2025-09-15 17:01   ` Rob Herring (Arm)
2025-09-15 20:27   ` Rob Herring
2025-09-16 12:45     ` Ioana Ciornei
2025-09-16 16:18   ` Frank Li
2025-09-17  7:15     ` Ioana Ciornei
2025-09-15 12:23 ` [PATCH v2 3/9] mfd: simple-mfd-i2c: add compatible string for LX2160ARDB Ioana Ciornei
2025-09-16 16:20   ` Frank Li
2025-09-17  7:21     ` Ioana Ciornei
2025-09-15 12:23 ` [PATCH v2 4/9] gpio: regmap: add the .fixed_direction_output configuration parameter Ioana Ciornei
2025-09-15 12:45   ` Michael Walle [this message]
2025-09-15 13:55     ` Ioana Ciornei
2025-09-15 14:01       ` Michael Walle
2025-09-16  9:52     ` Bartosz Golaszewski
2025-09-15 12:23 ` [PATCH v2 5/9] drivers: gpio: add QIXIS FPGA GPIO controller Ioana Ciornei
2025-09-16 16:39   ` Frank Li
2025-09-17  7:40     ` Ioana Ciornei
2025-09-17  8:08       ` Bartosz Golaszewski
2025-09-15 12:23 ` [PATCH v2 6/9] arm64: dts: lx2160a-rdb: describe the QIXIS FPGA and two child GPIO controllers Ioana Ciornei
2025-09-16 16:40   ` Frank Li
2025-09-15 12:23 ` [PATCH v2 7/9] arm64: dts: ls1046a-qds: describe the FPGA based GPIO controller Ioana Ciornei
2025-09-16 16:43   ` Frank Li
2025-09-15 12:23 ` [PATCH v2 8/9] arm64: dts: lx2160a-rdb: fully describe the two SFP+ cages Ioana Ciornei
2025-09-16 16:46   ` Frank Li
2025-09-17  7:42     ` Ioana Ciornei
2025-09-15 12:23 ` [PATCH v2 9/9] arm64: dts: ls1046a-qds: describe the two on-board " Ioana Ciornei
2025-09-16 16:47   ` Frank Li

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=DCTDUJO0PS8B.1LD03WTEMNRVP@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-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;
as well as URLs for NNTP newsgroup(s).