Re: [PATCH v3 10/10] pinctrl: Add pin controller driver for AAEON UP boards

Andy Shevchenko
2025-04-22T15:24:27Z

On Tue, Apr 22, 2025 at 04:36:33PM +0200, Thomas Richard wrote:

...

> >> +static int upboard_gpio_request(struct gpio_chip *gc, unsigned int offset)
> >> +{
> >> + struct gpiochip_fwd *fwd = container_of(gc, struct gpiochip_fwd, chip);
> >> + struct upboard_pinctrl *pctrl = fwd->data;
> >
> > Yeah, something like
> >
> > struct upboard_pinctrl *pctrl = gpio_fwd_get_data(fwd);
> >
> >> + unsigned int pin = pctrl->pctrl_data->pin_header[offset];
> >> + struct gpio_desc *desc;
> >> + int ret;
> >> +
> >> + ret = pinctrl_gpio_request(gc, offset);
> >> + if (ret)
> >> + return ret;
> >
> >> + /* GPIO desc is already registered */
> >> + if (fwd->descs[offset])
> >> + return 0;
> >
> > As mentioned in another reply, why 0 and even though, why can't it be simply
> > filtered by EEXIST from the below?
> >
> > In worst scenario, you can add an API gpio_fwd_is_registered(fwd, offset).
>
> I cannot filter using EEXIST, because I have to get the GPIO desc first.
> And using the retcode of gpiod_get_index() I cannot detect that I
> already requested the GPIO.
>
> As now gpiochip_fwd is an opaque pointer, I will add the
> gpio_fwd_is_registered() helper.
>
> It is due to the fact that the forwarder never releases a GPIO desc. An
> other solution could be to add the possibility to remove a GPIO desc.
> In upboard_gpio_free() the GPIO desc is free, and we can remove the check.
>
> upboard_gpio_free()
> {
> gpio_fwd_free_desc(fwd, offset);
> pinctrl_gpio_free(gc, offset);
> }

From given options I prefer to have the _gpio_free(), i.e. the latter one.

--
With Best Regards,
Andy Shevchenko