All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Cc: Linus Walleij <linusw@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	Christian Marangi <ansuelsmth@gmail.com>,
	Benjamin Larsson <benjamin.larsson@genexis.eu>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	Markus Gothe <markus.gothe@genexis.eu>,
	Matheus Sampaio Queiroga <srherobrine20@gmail.com>
Subject: Re: [PATCH v7 13/34] pinctrl: airoha: add set_direction() helper for gpio_chip
Date: Mon, 27 Jul 2026 10:06:53 +0200	[thread overview]
Message-ID: <amcRnbBXxOrp8kTh@lore-desk> (raw)
In-Reply-To: <20260727074234.3761170-14-mikhail.kshevetskiy@iopsys.eu>

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

> The patch creates set_direction() helper for gpio_chip abstraction.
> It also implements/reimplements some function using newly defined
> helper.
> 
> This is cosmetic patch used to place gpio_chip specific code together.
> No functional changes.
> 
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> ---
>  drivers/pinctrl/airoha/pinctrl-airoha.c | 59 ++++++++++++++++---------
>  1 file changed, 38 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/pinctrl/airoha/pinctrl-airoha.c b/drivers/pinctrl/airoha/pinctrl-airoha.c
> index b52eb39c55ff3..faad5d3ada31c 100644
> --- a/drivers/pinctrl/airoha/pinctrl-airoha.c
> +++ b/drivers/pinctrl/airoha/pinctrl-airoha.c
> @@ -2523,12 +2523,43 @@ static int airoha_gpio_get_direction(struct gpio_chip *chip, unsigned int gpio)
>  	return (val & mask) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
>  }
>  
> +static int airoha_gpio_set_direction(struct gpio_chip *chip, unsigned int gpio,
> +				     bool input)
> +{
> +	struct airoha_pinctrl *pinctrl = gpiochip_get_data(chip);
> +	u32 mask, index;
> +	int err, field_shift;
> +
> +	/* set output enable */
> +	mask = BIT(gpio % AIROHA_PIN_BANK_SIZE);
> +	index = gpio / AIROHA_PIN_BANK_SIZE;
> +	err = regmap_update_bits(pinctrl->regmap, pinctrl->gpiochip.out[index],
> +				 mask, !input ? mask : 0);
> +	if (err)
> +		return err;
> +
> +	/* set direction */
> +	field_shift = 2 * (gpio % AIROHA_REG_GPIOCTRL_NUM_PIN);
> +	mask = GENMASK(field_shift + 1, field_shift);

same here, why using 2 bits as mask?

> +	index = gpio / AIROHA_REG_GPIOCTRL_NUM_PIN;
> +
> +	return regmap_update_bits(pinctrl->regmap,
> +				  pinctrl->gpiochip.dir[index],
> +				  mask, !input ? BIT(field_shift) : 0);
> +}
> +
> +static int airoha_gpio_direction_input(struct gpio_chip *chip,
> +				       unsigned int gpio)
> +{
> +	return airoha_gpio_set_direction(chip, gpio, true);
> +}
> +
>  static int airoha_gpio_direction_output(struct gpio_chip *chip,
>  					unsigned int gpio, int value)
>  {
>  	int err;
>  
> -	err = pinctrl_gpio_direction_output(chip, gpio);
> +	err = airoha_gpio_set_direction(chip, gpio, false);
>  	if (err)
>  		return err;
>  
> @@ -2667,7 +2698,7 @@ static int airoha_pinctrl_add_gpiochip(struct airoha_pinctrl *pinctrl,
>  	gc->label = dev_name(dev);
>  	gc->request = gpiochip_generic_request;
>  	gc->free = gpiochip_generic_free;
> -	gc->direction_input = pinctrl_gpio_direction_input;
> +	gc->direction_input = airoha_gpio_direction_input;
>  	gc->direction_output = airoha_gpio_direction_output;
>  	gc->get_direction = airoha_gpio_get_direction;
>  	gc->set = airoha_gpio_set;
> @@ -2750,27 +2781,13 @@ static int airoha_pinmux_set_direction(struct pinctrl_dev *pctrl_dev,
>  					unsigned int p, bool input)
>  {
>  	struct airoha_pinctrl *pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
> -	u32 mask, index;
> -	int err, pin;
> +	int gpio;
>  
> -	pin = airoha_convert_pin_to_reg_offset(pctrl_dev, range, p);
> -	if (pin < 0)
> -		return pin;
> -
> -	/* set output enable */
> -	mask = BIT(pin % AIROHA_PIN_BANK_SIZE);
> -	index = pin / AIROHA_PIN_BANK_SIZE;
> -	err = regmap_update_bits(pinctrl->regmap, pinctrl->gpiochip.out[index],
> -				 mask, !input ? mask : 0);
> -	if (err)
> -		return err;
> +	gpio = airoha_convert_pin_to_reg_offset(pctrl_dev, range, p);

same here, if you do not rename pin in gpio the patch will be simpler.

Regards,
Lorenzo

> +	if (gpio < 0)
> +		return gpio;
>  
> -	/* set direction */
> -	mask = BIT(2 * (pin % AIROHA_REG_GPIOCTRL_NUM_PIN));
> -	index = pin / AIROHA_REG_GPIOCTRL_NUM_PIN;
> -	return regmap_update_bits(pinctrl->regmap,
> -				  pinctrl->gpiochip.dir[index], mask,
> -				  !input ? mask : 0);
> +	return airoha_gpio_set_direction(&pinctrl->gpiochip.chip, gpio, input);
>  }
>  
>  static const struct pinmux_ops airoha_pmxops = {
> -- 
> 2.53.0
> 

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

  parent reply	other threads:[~2026-07-27  8:06 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27  7:42 [PATCH v7 00/34] pinctrl: airoha: split on shared and SoC drivers, add more SoCs Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 01/34] dt-bindings: pinctrl: airoha: en7581: fix misprint in i2s function name Mikhail Kshevetskiy
2026-07-27  7:46   ` Lorenzo Bianconi
2026-07-27  7:50   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 02/34] dt-bindings: pinctrl: airoha: en7581: fix pwm pin-groups Mikhail Kshevetskiy
2026-07-27  7:47   ` Lorenzo Bianconi
2026-07-27  7:42 ` [PATCH v7 03/34] dt-bindings: pinctrl: airoha: an7583: fix device tree binding schema Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 04/34] pinctrl: airoha: an7581: fix misprint in bitfield name Mikhail Kshevetskiy
2026-07-27  7:50   ` Lorenzo Bianconi
2026-07-27  7:52   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 05/34] pinctrl: airoha: an7583: fix I2C0_SDA_PD register bit order Mikhail Kshevetskiy
2026-07-27  7:54   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 06/34] pinctrl: airoha: an7583: there are no muxes to enable i2c buses Mikhail Kshevetskiy
2026-07-27  7:53   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 07/34] dt-bindings: pinctrl: airoha: an7583: remove i2c pin function Mikhail Kshevetskiy
2026-07-27  7:51   ` Lorenzo Bianconi
2026-07-27  7:42 ` [PATCH v7 08/34] pinctrl: airoha: an7581: fix mux/conf of pcie_reset pins Mikhail Kshevetskiy
2026-07-27  7:55   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 09/34] dt-bindings: pinctrl: airoha: en7581: allow configuration of pcie_reset pins as gpio or pwm Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 10/34] pinctrl: airoha: an7583: fix muxing of non-gpio default pins Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 11/34] dt-bindings: pinctrl: airoha: an7583: allow configuration of non-gpio default pins as gpio and pwm Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 12/34] pinctrl: airoha: add missed get_direction() function for gpio_chip Mikhail Kshevetskiy
2026-07-27  7:57   ` sashiko-bot
2026-07-27  8:04   ` Lorenzo Bianconi
2026-07-27  9:40     ` Mikhail Kshevetskiy
2026-07-27  9:46       ` Lorenzo Bianconi
2026-07-27  7:42 ` [PATCH v7 13/34] pinctrl: airoha: add set_direction() helper " Mikhail Kshevetskiy
2026-07-27  7:58   ` sashiko-bot
2026-07-27  8:06   ` Lorenzo Bianconi [this message]
2026-07-27  7:42 ` [PATCH v7 14/34] pinctrl: airoha: fix potential kenel panic in IRQ handling code Mikhail Kshevetskiy
2026-07-27  7:55   ` sashiko-bot
2026-07-27  8:31   ` Lorenzo Bianconi
2026-07-27  9:02     ` Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 15/34] pinctrl: airoha: fix IRQ mask/unmask code Mikhail Kshevetskiy
2026-07-27  7:59   ` sashiko-bot
2026-07-27  8:37   ` Lorenzo Bianconi
2026-07-27  7:42 ` [PATCH v7 16/34] pinctrl: airoha: add missed IRQ resource helpers Mikhail Kshevetskiy
2026-07-27  8:02   ` sashiko-bot
2026-07-27  8:34   ` Lorenzo Bianconi
2026-07-27  7:42 ` [PATCH v7 17/34] pinctrl: airoha: fix edge-triggered interrupts handling Mikhail Kshevetskiy
2026-07-27  7:59   ` sashiko-bot
2026-07-27  9:01   ` Lorenzo Bianconi
2026-07-27  7:42 ` [PATCH v7 18/34] pinctrl: airoha: remove not needed irq_type[] array Mikhail Kshevetskiy
2026-07-27  8:00   ` sashiko-bot
2026-07-27  9:03   ` Lorenzo Bianconi
2026-07-27  7:42 ` [PATCH v7 19/34] pinctrl: airoha: move common definitions to the separate header Mikhail Kshevetskiy
2026-07-27  8:04   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 20/34] pinctrl: airoha: split driver on shared code and SoC specific drivers Mikhail Kshevetskiy
2026-07-27  8:19   ` sashiko-bot
2026-07-27  9:14   ` Lorenzo Bianconi
2026-07-27  9:23     ` Mikhail Kshevetskiy
2026-07-27  9:27       ` Lorenzo Bianconi
2026-07-27  9:28         ` Mikhail Kshevetskiy
2026-07-27 12:48           ` Lorenzo Bianconi
2026-07-27  7:42 ` [PATCH v7 21/34] pinctrl: airoha: an7581: remove en7581 prefix from variable names Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 22/34] pinctrl: airoha: an7583: remove an7583 prefix from variable names and definitions Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 23/34] pinctrl: airoha: an7583: rename registers to match its an7583 names Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 24/34] pinctrl: airoha: an7583: add support for npu_uart pinmux Mikhail Kshevetskiy
2026-07-27  8:01   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 25/34] dt-bindings: pinctrl: airoha: an7583: add npu_uart pin group Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 26/34] pinctrl: airoha: an7583: add support for pon_alt pinmux Mikhail Kshevetskiy
2026-07-27  8:05   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 27/34] dt-bindings: pinctrl: airoha: an7583: add pon_alt pin group Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 28/34] pinctrl: airoha: an7583: add support for olt pinmux Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 29/34] dt-bindings: pinctrl: airoha: an7583: add olt function/group Mikhail Kshevetskiy
2026-07-27  7:42 ` [PATCH v7 30/34] pinctrl: airoha: add support of en7523 SoC Mikhail Kshevetskiy
2026-07-27  8:13   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 31/34] pinctrl: airoha: try to find chip scu node by phandle first Mikhail Kshevetskiy
2026-07-27  8:06   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 32/34] dt-bindings: pinctrl: airoha: add support of en7523 pin controller Mikhail Kshevetskiy
2026-07-27  8:06   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 33/34] pinctrl: airoha: add support of an7563 SoC Mikhail Kshevetskiy
2026-07-27  8:07   ` sashiko-bot
2026-07-27  7:42 ` [PATCH v7 34/34] dt-bindings: pinctrl: airoha: add support of an7563 pin controller Mikhail Kshevetskiy
2026-07-27  8:10   ` sashiko-bot

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=amcRnbBXxOrp8kTh@lore-desk \
    --to=lorenzo@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=ansuelsmth@gmail.com \
    --cc=benjamin.larsson@genexis.eu \
    --cc=brgl@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=markus.gothe@genexis.eu \
    --cc=mikhail.kshevetskiy@iopsys.eu \
    --cc=robh@kernel.org \
    --cc=srherobrine20@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.