The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Marcos Del Sol Vives <marcos@orca.pet>
Cc: linux-kernel@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Michael Walle <mwalle@kernel.org>, Lee Jones <lee@kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-gpio@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 1/3] gpio: gpio-regmap: add flags to control some behaviour
Date: Thu, 21 Aug 2025 09:32:20 -0500	[thread overview]
Message-ID: <20250821143220.GA672670@bhelgaas> (raw)
In-Reply-To: <20250821101902.626329-2-marcos@orca.pet>

Not my area, but consider making the subject more specific, e.g.,
"add flag to set direction before value"

On Thu, Aug 21, 2025 at 12:18:57PM +0200, Marcos Del Sol Vives wrote:
> The Vortex86 family of SoCs need the direction set before the value, else
> writes to the DATA ports are ignored.
> 
> This commit adds a new "flags" field plus a flag to change the default
> behaviour, which is to set first the direction and then the value.

This sounds like the default behavior is to set direction, then value.
But from the patch, it looks like:

  - default: set value, then direction

  - with GPIO_REGMAP_DIR_BEFORE_SET: set direction, then value

> Signed-off-by: Marcos Del Sol Vives <marcos@orca.pet>
> ---
>  drivers/gpio/gpio-regmap.c  | 17 ++++++++++++++++-
>  include/linux/gpio/regmap.h | 17 +++++++++++++++++
>  2 files changed, 33 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
> index e8a32dfebdcb..24cefbd57637 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 int flags;
>  
>  	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
>  			      unsigned int offset, unsigned int *reg,
> @@ -196,7 +197,20 @@ static int gpio_regmap_direction_input(struct gpio_chip *chip,
>  static int gpio_regmap_direction_output(struct gpio_chip *chip,
>  					unsigned int offset, int value)
>  {
> -	gpio_regmap_set(chip, offset, value);
> +	struct gpio_regmap *gpio = gpiochip_get_data(chip);
> +	int ret;
> +
> +	if (gpio->flags & GPIO_REGMAP_DIR_BEFORE_SET) {
> +		ret = gpio_regmap_set_direction(chip, offset, true);
> +		if (ret)
> +			return ret;
> +
> +		return gpio_regmap_set(chip, offset, value);
> +	}
> +
> +	ret = gpio_regmap_set(chip, offset, value);
> +	if (ret)
> +		return ret;
>  
>  	return gpio_regmap_set_direction(chip, offset, true);
>  }
> @@ -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->flags = config->flags;
>  
>  	chip = &gpio->gpio_chip;
>  	chip->parent = config->parent;
> diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
> index c722c67668c6..aea107e71fec 100644
> --- a/include/linux/gpio/regmap.h
> +++ b/include/linux/gpio/regmap.h
> @@ -12,6 +12,20 @@ struct regmap;
>  #define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1))
>  #define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
>  
> +
> +/**
> + * enum gpio_regmap_flags - flags to control GPIO operation
> + */
> +enum gpio_regmap_flags {
> +	/**
> +	 * @GPIO_REGMAP_DIR_BEFORE_SET: when setting a pin as an output, set
> +	 * its direction before the value. The output value will be undefined
> +	 * for a short time which may have unwanted side effects, but some
> +	 * hardware requires this.
> +	 */
> +	GPIO_REGMAP_DIR_BEFORE_SET	= BIT(0),
> +};
> +
>  /**
>   * struct gpio_regmap_config - Description of a generic regmap gpio_chip.
>   * @parent:		The parent device
> @@ -23,6 +37,8 @@ struct regmap;
>   *			If not given, the name of the device is used.
>   * @ngpio:		(Optional) Number of GPIOs
>   * @names:		(Optional) Array of names for gpios
> + * @flags:		(Optional) A bitmask of flags from
> + * 			&enum gpio_regmap_flags
>   * @reg_dat_base:	(Optional) (in) register base address
>   * @reg_set_base:	(Optional) set register base address
>   * @reg_clr_base:	(Optional) clear register base address
> @@ -68,6 +84,7 @@ struct gpio_regmap_config {
>  	const char *label;
>  	int ngpio;
>  	const char *const *names;
> +	unsigned int flags;
>  
>  	unsigned int reg_dat_base;
>  	unsigned int reg_set_base;
> -- 
> 2.34.1
> 

  reply	other threads:[~2025-08-21 14:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21 10:18 [PATCH v3 0/3] Introduce support for Vortex GPIO pins Marcos Del Sol Vives
2025-08-21 10:18 ` [PATCH v3 1/3] gpio: gpio-regmap: add flags to control some behaviour Marcos Del Sol Vives
2025-08-21 14:32   ` Bjorn Helgaas [this message]
2025-08-21 17:14     ` Marcos Del Sol Vives
2025-08-21 16:40   ` Linus Walleij
2025-08-22  7:07     ` Michael Walle
2025-08-22 11:04       ` Marcos Del Sol Vives
2025-08-22  3:27   ` kernel test robot
2025-08-22 11:11     ` Marcos Del Sol Vives
2025-08-21 10:18 ` [PATCH v3 2/3] gpio: vortex: add new GPIO device driver Marcos Del Sol Vives
2025-08-21 16:48   ` Linus Walleij
2025-08-21 17:05   ` Marcos Del Sol Vives
2025-08-22 15:47     ` Bjorn Helgaas
2025-08-22 15:49       ` Bjorn Helgaas
2025-08-22 16:08         ` Marcos Del Sol Vives
2025-08-21 10:18 ` [PATCH v3 3/3] mfd: vortex: implement new driver for Vortex southbridges Marcos Del Sol Vives

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=20250821143220.GA672670@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=brgl@bgdev.pl \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=marcos@orca.pet \
    --cc=mwalle@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