Re: [PATCH v2 2/2] gpio: add gpio-line-mux driver

From: Jonas Jelonek
Date: Tue Nov 04 2025 - 10:04:24 EST


Hi Thomas,


On 28.10.25 10:45, Thomas Richard wrote:
> On 10/27/25 12:17 AM, Jonas Jelonek wrote:
>> +
>> + struct mutex lock;
>> +
>> + struct gpio_desc *shared_gpio;
>> + /* dynamically sized, must be last */
>> + unsigned int gpio_mux_states[];
>> +};
>> +
>> +DEFINE_GUARD(gpio_lmux, struct gpio_lmux *, mutex_lock(&_T->lock), mutex_unlock(&_T->lock))
>> +
>> +static int gpio_lmux_gpio_get(struct gpio_chip *gc, unsigned int offset)
>> +{
>> + struct gpio_lmux *glm = (struct gpio_lmux *)gpiochip_get_data(gc);
>> + int ret;
>> +
>> + if (offset > gc->ngpio)
>> + return -EINVAL;
>> +
>> + guard(gpio_lmux)(glm);
>> +
>> + ret = mux_control_select(glm->mux, glm->gpio_mux_states[offset]);
>> + if (ret < 0)
>> + return ret;
>> +
>> + ret = gpiod_get_raw_value_cansleep(glm->shared_gpio);
> Why ignoring ACTIVE_LOW status ?

I think this would be rather error-prone and doesn't make sense to me. The
consumer of this driver should decide about whether it uses ACTIVE_HIGH or
ACTIVE_LOW for each one of the virtual GPIOs separately. This should then be
applied as if this was a real GPIO. Following the ACTIVE_* that is given in
the 'shared-gpio' property then would interfere again.

> [...]
>

Thanks for all the suggested simplifications, I'll incorporate them.

> The advantage of the forwarder is that it handles if the shared GPIO is
> sleeping or not.
> But I think the forwarder shall have ngpio, not 1. You will have to add
> ngpio times the same GPIO desc. Also unsupported operations shall be unset.
> So I don't really know if it shall be used in this case.

I agree. As Peter mentioned, I need to use "can_sleep" anyway because of the mux.
So there's not really an argument left to use the forwarder.

> Best Regards,
>
> Thomas

Best regards,
Jonas