mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Walleij <linusw@kernel.org>
To: Adrian Ambrozewicz <aambrozewicz@nvidia.com>
Cc: Bartosz Golaszewski <brgl@kernel.org>,
	Donald Shannon <donalds@nvidia.com>,
	 Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	 Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	linux-kernel@vger.kernel.org,  linux-gpio@vger.kernel.org,
	linux-usb@vger.kernel.org, llvm@lists.linux.dev,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH 06/11] gpio: Add NVIDIA LSTP GPIO driver
Date: Wed, 14 Oct 2026 01:25:00 +0200	[thread overview]
Message-ID: <CAD++jLkru2AL2_7ieOdbYrePAhNSFaa3wwEzCagiPsALgG2GwQ@mail.gmail.com> (raw)
In-Reply-To: <20261012-lstp-usb-adapter-v1-6-aambrozewicz@nvidia.com>

Hi Adrian,

thanks for your patch!

On Mon, Oct 12, 2026 at 7:37 PM Adrian Ambrozewicz
<aambrozewicz@nvidia.com> wrote:

> Add a driver for the GPIO channels of NVIDIA LSTP USB adapters. Each
> channel is registered as a GPIO chip with an interrupt controller for
> its pins; every line access is a USB transaction, so the chip can
> sleep. Pins the firmware reports as LEDs are not GPIO lines: the driver
> hands them to the LED driver as an auxiliary device.
>
> At probe the driver reads each pin's interrupt configuration from the
> device. A reply that misses the response timeout can answer a later
> request and shift every following pin's state by one, so a single read
> cannot simply be retried. After a timeout the driver reads all pins
> again, alternating ascending and descending order, until two
> consecutive passes without a timeout agree: at most five passes, ending
> within 10 s of the first timeout, after which the probe fails as
> before. The probe runs in the context that added the device, often the
> hub's worker, hence the bound.
>
> Signed-off-by: Adrian Ambrozewicz <aambrozewicz@nvidia.com>
(...)
> +++ b/drivers/gpio/Kconfig
> @@ -2051,6 +2051,20 @@ config GPIO_USBIO
>           This driver can also be built as a module. If so, the module
>           will be called gpio_usbio.
>
> +config GPIO_LSTP

GPIO_USBIO ... GPIO_LSTP?

These should be in alphabetical order.

> +#include <linux/atomic.h>
> +#include <linux/bitmap.h>
> +#include <linux/build_bug.h>
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/gpio/driver.h>
> +#include <linux/irq.h>
> +#include <linux/jiffies.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/seq_file.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <linux/wait_bit.h>
> +#include <linux/workqueue.h>
> +#include <uapi/linux/gpio.h>

Do you really need all this?
Certainly <uapi/linux/gpio.h> is a mistake, look over all of these.

> +/* clang-format off */

I beg your pardon? What is this?

> +enum lstp_gpio_direction {
> +       LSTP_GPIO_OUTPUT = 0x00,
> +       LSTP_GPIO_INPUT = 0x01
> +} __packed;
> +enum lstp_gpio_pin_state {
> +       LSTP_GPIO_LOW = 0x00,
> +       LSTP_GPIO_HIGH = 0x01
> +} __packed;
> +enum lstp_gpio_drive_config {
> +       LSTP_GPIO_PUSH_PULL = 0x00,
> +       LSTP_GPIO_OPEN_DRAIN = 0x01,
> +       LSTP_GPIO_OPEN_SOURCE = 0x02
> +} __packed;
> +enum lstp_gpio_bias_config {
> +       LSTP_GPIO_NO_PULL = 0x00,
> +       LSTP_GPIO_PULL_UP = 0x01,
> +       LSTP_GPIO_PULL_DOWN = 0x02
> +} __packed;
> +enum lstp_gpio_led_support {
> +       LSTP_GPIO_NOT_LED = 0x00,
> +       LSTP_GPIO_LED_MODE_HOLD = 0x01, /* pattern brightness jumps between steps */
> +       LSTP_GPIO_LED_MODE_INTERPOLATE = 0x02, /* pattern brightness interpolates between steps */
> +} __packed; /* clang-format on */

This  looks very dense too..

At least a newline between the enums?

What's with the clang-format thing? I don't get it.

> +struct lstp_gpio_priv {

Just call it lstp_gpio

> +       struct lstp_channel *ch;
> +       struct gpio_chip gc;

Why? Normally drivers get the state container from the
chip not the other way around.

> +static int lstp_gpio_get_direction(struct gpio_chip *gc, unsigned int pin)
> +{
> +       struct lstp_gpio_priv *priv = gpiochip_get_data(gc);
> +       u8 direction;
> +
> +       int ret = lstp_gpio_read_direction(priv, pin, &direction);
> +
> +       if (ret)
> +               return ret;
> +
> +       if (direction == LSTP_GPIO_INPUT)
> +               return GPIO_LINE_DIRECTION_IN;
> +
> +       return GPIO_LINE_DIRECTION_OUT;
> +}
> +
> +static int lstp_gpio_direction_input(struct gpio_chip *gc, unsigned int pin)
> +{
> +       struct lstp_gpio_priv *priv = gpiochip_get_data(gc);
> +
> +       return lstp_gpio_require_direction(priv, pin, LSTP_GPIO_INPUT);
> +}
> +
> +static int lstp_gpio_direction_output(struct gpio_chip *gc, unsigned int pin, int value)
> +{
> +       struct lstp_gpio_priv *priv = gpiochip_get_data(gc);
> +       int ret = lstp_gpio_require_direction(priv, pin, LSTP_GPIO_OUTPUT);
> +
> +       if (ret)
> +               return ret;
> +
> +       return lstp_gpio_set_value(gc, pin, value);
> +}

It seems some pins are only input and some are only output.

Have you considered using serialized register access over
regmap and use regmap-gpio with fixed direction bitmaps?

Yours,
Linus Walleij

  reply	other threads:[~2026-10-13 23:25 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 17:35 [PATCH 00/11] Add NVIDIA LSTP USB adapter drivers Adrian Ambrozewicz
2026-10-12 17:35 ` [PATCH 01/11] dt-bindings: gpio: Add NVIDIA LSTP GPIO Adrian Ambrozewicz
2026-10-13  6:09   ` Krzysztof Kozlowski
2026-10-16  8:44     ` Adrian Ambrozewicz
2026-10-12 17:36 ` [PATCH 02/11] dt-bindings: i2c: Add NVIDIA LSTP I2C Adrian Ambrozewicz
2026-10-13  6:11   ` Krzysztof Kozlowski
2026-10-12 17:36 ` [PATCH 03/11] dt-bindings: spi: Add NVIDIA LSTP SPI Adrian Ambrozewicz
2026-10-13  6:11   ` Krzysztof Kozlowski
2026-10-12 17:36 ` [PATCH 04/11] dt-bindings: usb: Add NVIDIA LSTP USB adapter Adrian Ambrozewicz
2026-10-13  6:13   ` Krzysztof Kozlowski
2026-10-13  6:17   ` Krzysztof Kozlowski
2026-10-22 10:40     ` Adrian Ambrozewicz
2026-10-12 17:36 ` [PATCH 05/11] usb: misc: Add NVIDIA LSTP USB adapter driver Adrian Ambrozewicz
2026-10-12 17:36 ` [PATCH 06/11] gpio: Add NVIDIA LSTP GPIO driver Adrian Ambrozewicz
2026-10-13 23:25   ` Linus Walleij [this message]
2026-10-16  8:19     ` Adrian Ambrozewicz
2026-10-16 21:14       ` Linus Walleij
2026-10-20 13:53         ` Adrian Ambrozewicz
2026-10-12 17:36 ` [PATCH 07/11] leds: Add NVIDIA LSTP LED driver Adrian Ambrozewicz
2026-10-12 17:36 ` [PATCH 08/11] i2c: Add NVIDIA LSTP I2C driver Adrian Ambrozewicz
2026-10-12 17:36 ` [PATCH 09/11] spi: Add NVIDIA LSTP SPI driver Adrian Ambrozewicz
2026-10-12 17:36 ` [PATCH 10/11] tty: Add NVIDIA LSTP UART driver Adrian Ambrozewicz
2026-10-13  5:49   ` Jiri Slaby
2026-10-16  8:19     ` Adrian Ambrozewicz
2026-10-15  1:25   ` kernel test robot
2026-10-16  7:43   ` kernel test robot
2026-10-12 17:36 ` [PATCH 11/11] ipmi: Add NVIDIA LSTP IPMI BMC driver Adrian Ambrozewicz
2026-10-12 21:10   ` Corey Minyard
2026-10-16  8:19     ` Adrian Ambrozewicz
2026-10-16 12:26       ` Corey Minyard
2026-10-20 13:53         ` Adrian Ambrozewicz
2026-10-13 11:37 ` [PATCH 00/11] Add NVIDIA LSTP USB adapter drivers Greg Kroah-Hartman
2026-10-16  8:44   ` Adrian Ambrozewicz
2026-10-22 10:40   ` Adrian Ambrozewicz
2026-10-22 13:29     ` Greg Kroah-Hartman
2026-10-13 11:39 ` Greg Kroah-Hartman
2026-10-14  3:38   ` Jeremy Kerr
2026-10-14  4:53     ` Greg Kroah-Hartman
2026-10-16  8:19       ` Adrian Ambrozewicz
2026-10-30  4:06     ` Jeremy Kerr
2026-10-30  5:32       ` Greg Kroah-Hartman
2026-11-02  5:55         ` Jeremy Kerr

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=CAD++jLkru2AL2_7ieOdbYrePAhNSFaa3wwEzCagiPsALgG2GwQ@mail.gmail.com \
    --to=linusw@kernel.org \
    --cc=aambrozewicz@nvidia.com \
    --cc=brgl@kernel.org \
    --cc=donalds@nvidia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=justinstitt@google.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.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 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®