Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Pufan Jin <cyan2254650260@gmail.com>
To: Bartosz Golaszewski <brgl@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Linus Walleij <linusw@kernel.org>
Subject: Re: [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices
Date: Thu, 3 Dec 2026 00:53:22 +0800	[thread overview]
Message-ID: <f1e409e6-7a04-4554-92ba-ef15e2e0418a@gmail.com> (raw)
In-Reply-To: <alerrvj5dpuv36yav4snqrupyuitiziaemuewp63cg64yoou3g@zf2j3pyhyh2l>

On 12/3/26 12:28 AM, Bartosz Golaszewski wrote:

> On Wed, Dec 02, 2026 at 04:08:37PM +0800, Pufan Jin wrote:
>> Hi Philipp, Bartosz,
>>
>> Thanks for the review and feedback.
>>
>> Agreed -- calling the deprecated gpio_device_get_chip() and invoking
>> chip->of_xlate() directly in drivers/reset/core.c is not the
>> right approach.
>>
> Sigh... why do I feel like this is an LLM-generated response...
>
>> Before I prepare a v2 series, I would like to check what GPIOLIB
>> interface design you would prefer for this use case.
>>
>> Looking at what __reset_add_reset_gpio_device() needs from a parsed
>> struct fwnode_reference_args *args:
>> 1. The target struct gpio_device * (to set the reset-gpio auxiliary
>>     device's parent via gpio_device_to_device() and obtain parent->fwnode
>>     for PROPERTY_ENTRY_GPIO()).
>> 2. The chip-relative hardware GPIO offset (unsigned int *offset).
>> 3. The translated Linux lookup flags (unsigned long *lflags, using
>>     enum gpio_lookup_flags for PROPERTY_ENTRY_GPIO()).
>>
>> Would an interface along these lines in gpiolib make sense?
>>
>>    struct gpio_device *
>>    gpio_device_find_by_fwnode_args(const struct fwnode_reference_args *args,
>>                                    unsigned int *offset,
>>                                    unsigned long *lflags);
>>
>> Inside gpiolib (with kernel-doc in drivers/gpio/gpiolib.c and prototype
>> in include/linux/gpio/driver.h):
>> - For OF nodes (is_of_node(args->fwnode)):
>>    Convert args to struct of_phandle_args, look up the matching
>>    gpio_device via of_find_gpio_device_by_xlate() (which handles
>>    custom of_xlate() and arbitrary #gpio-cells cleanly), invoke
>>    gc->of_xlate() safely under guard(srcu)(&gdev->srcu) and
>>    srcu_dereference(gdev->chip, &gdev->srcu), and convert the resulting
>>    of_gpio_flags to Linux lookup flags via of_convert_gpio_flags().
>>    This eliminates both the #gpio-cells == 2 restriction (TODO) and the
>>    manual flag matching (FIXME) in drivers/reset/core.c.
>> - For software nodes (is_software_node(args->fwnode)):
>>    Look up via gpio_device_find_by_fwnode(args->fwnode) and extract
>>    args->args[0] / args->args[1] (with nargs == 2 validation).
>> - Return ERR_PTR(-EPROBE_DEFER) if no matching gpio_device is
>>    registered yet, or the corresponding negative errno on invalid args.
>>
>> Two related details I noticed while checking the surrounding code:
>> 1. In drivers/reset/reset-gpio.c, reset_gpio_probe() hardcodes
>>     priv->rc.fwnode_reset_n_cells = 2, which would trigger
>>     WARN_ON(args.nargs != rcdev->fwnode_reset_n_cells) in
>>     __fwnode_reset_control_get() once #gpio-cells != 2 is supported.
>>     Since drivers/reset/core.c already passes &rgpio_dev->ref_args via
>>     adev->dev.platform_data, reset_gpio_probe() can read nargs from
>>     platform_data.
>> 2. In drivers/gpio/gpiolib-shared.c, gpio_shared_dev_is_reset_gpio()
>>     compares ref_args.args[0] from the DT consumer (pre-xlate)
>>     against aux_args.args[0] from the reset-gpio swnode (post-xlate if
>>     translated here), and assumes 2 args. If a shared reset-gpios uses a
>>     custom of_xlate() like tegra186-gpio, that comparison would mismatch
>>     (though that can be tracked/handled separately if appropriate).
>>
>> Bartosz, Philipp: does this API shape (name, signature, and header
>> placement) look reasonable to you, or would you prefer a different
>> naming or design?
> If you're using an LLM, you may as well have it generate the code an
> post it, it will make the discussion easier if we're working with an
> actual implementation.
>
> Bart

Hi Bartosz,

Sorry, English isn't my first language, so I used an AI tool
to translate and polish my wording to avoid misunderstandings, though
the TX2 debugging and ideas were my own.

Makes sense to discuss actual code instead. I'll put together the
gpiolib helper and reset changes, test them on my Jetson TX2 board,
and post an RFC v2 here.

Regards,
Pufan Jin


      reply	other threads:[~2026-12-02 16:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 16:58 [PATCH] reset: core: translate GPIO specifier via of_xlate for reset GPIO devices Pufan Jin
2026-12-01  9:57 ` Philipp Zabel
2026-12-01 13:27   ` Bartosz Golaszewski
2026-12-01 13:49     ` Philipp Zabel
2026-12-02  8:08       ` Pufan Jin
2026-12-02 16:28         ` Bartosz Golaszewski
2026-12-02 16:53           ` Pufan Jin [this message]

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=f1e409e6-7a04-4554-92ba-ef15e2e0418a@gmail.com \
    --to=cyan2254650260@gmail.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=stable@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