Re: [PATCH 4/9] gpio: regmap: add the .get_direction() callback
From: Ioana Ciornei <ioana.ciornei@nxp.com>
Date: 2025-07-10 09:23:46
Also in:
linux-devicetree, linux-gpio, lkml
On Wed, Jul 09, 2025 at 05:09:17PM +0200, Andrew Lunn wrote:
On Wed, Jul 09, 2025 at 02:26:53PM +0300, Ioana Ciornei wrote:quoted
There are GPIO controllers such as the one present in the LX2160ARDB QIXIS CPLD which are single register fixed-direction. This cannot be modeled using the gpio-regmap as-is since there is no way to present the true direction of a GPIO line. In order to make this use case possible, add a new callback to the gpio_config structure - .get_direction() - which can be used by user drivers to provide the fixed direction per GPIO line. Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com> --- drivers/gpio/gpio-regmap.c | 17 ++++++++++++++++- include/linux/gpio/regmap.h | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-)diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 87c4225784cf..dac2acb26655 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c@@ -32,6 +32,8 @@ struct gpio_regmap { unsigned int reg_dir_in_base; unsigned int reg_dir_out_base; + int (*get_direction)(struct gpio_regmap *gpio, unsigned int offset); +This is not my area, so i will deffer to the GPIO Maintainers. However, it is not clear to me what get_direction() should return. Is it the current direction, or the supported directions? Maybe it should be called get_fixed_direction()? I then wounder how it will be implemented. Since it is fixed, it is probably just a constant bitmap, and you look at the offset bit in this batmap? At minimum a ready made helper could be provided, or rather than have this op, just provide the bitmap, and gpio-regmap.c can look at the bit in the bitmap?
That is indeed possible and would save us from an extra callback that doesn't do much, it just looks into the same kind of bitmap that gpio-regmap could just have access to directly. I will wait for feedback from the GPIO maintainers but I do like the idea. Thanks!