mbox series

[v1,0/2] Fix Nvidia BlueField-3 GPIO access

Message ID 20230816135839.24011-1-asmaa@nvidia.com
Headers show
Series Fix Nvidia BlueField-3 GPIO access | expand

Message

Asmaa Mnebhi Aug. 16, 2023, 1:58 p.m. UTC
Fix Nvidia BlueField-3 GPIO access via libgpiod gpioset tool.
gpioset tool fails to modify the GPIO value due to the following:
1) the pinctrl-mlxbf3 driver defines mlxbf3_gpio_request_enable()
   to enable software to take control over a gpio. Only then can
   the gpio-mlxbf3 driver modify the direction and value of the
   gpio. mlxbf3_gpio_disable_free() gives control back to hardware
   and is called when the "gpioset" command is invoked.
   This cancels out the effort to change the GPIO value and
   direction. So mlxbf3_gpio_disable_free() needs to be removed.
2) the gpio-mlxbf3 driver calls gpiochip_generic_request() which
   calls mlxbf3_gpio_request_enable(). "pin_ranges" needs not to be
   empty for mlxbf3_gpio_request_enable() to be invoked. So
   gpio-mlxbf3 needs to populate "pin_ranges".

Asmaa Mnebhi (2):
  pinctrl: mlxbf3: Remove gpio_disable_free()
  gpio: mlxbf3: Support add_pin_ranges()

 drivers/gpio/gpio-mlxbf3.c       | 20 ++++++++++++++++++++
 drivers/pinctrl/pinctrl-mlxbf3.c | 14 --------------
 2 files changed, 20 insertions(+), 14 deletions(-)

Comments

Andy Shevchenko Aug. 16, 2023, 2:40 p.m. UTC | #1
On Wed, Aug 16, 2023 at 4:59 PM Asmaa Mnebhi <asmaa@nvidia.com> wrote:
>
> Support add_pin_ranges() so that pinctrl_gpio_request() can be called.
> The GPIO value is not modified when the user runs the "gpioset" tool.
> This is because when gpiochip_generic_request is invoked by the gpio-mlxbf3
> driver, "pin_ranges" is empty so it skips "pinctrl_gpio_request()".
> pinctrl_gpio_request() is essential in the code flow because it changes the
> mux value so that software has control over modifying the GPIO value.
> Adding add_pin_ranges() creates a dependency on the pinctrl-mlxbf3.c driver.

...

> +static int mlxbf3_gpio_add_pin_ranges(struct gpio_chip *chip)
> +{
> +       int ret;
> +       int id = 0;

Redundant assignment.

> +       id = !!(chip->ngpio % MLXBF3_GPIO_MAX_PINS_PER_BLOCK);

Using int as boolean. Seems to me you wanted something different here.

> +       ret = gpiochip_add_pin_range(chip,
> +                       "MLNXBF34:00",
> +                       chip->base,
> +                       id * MLXBF3_GPIO_MAX_PINS_PER_BLOCK,
> +                       chip->ngpio);
> +       if (ret)
> +               return ret;
> +
> +       return 0;

You can return directly:

  return gpiochip_add_pin_range(...);

> +}