Thread (32 messages) 32 messages, 6 authors, 2025-07-15

Re: [PATCH 4/9] gpio: regmap: add the .get_direction() callback

From: Ioana Ciornei <ioana.ciornei@nxp.com>
Date: 2025-07-15 11:38:21
Also in: linux-devicetree, linux-gpio, lkml

On Mon, Jul 14, 2025 at 08:36:03AM +0200, Michael Walle wrote:
On Fri Jul 11, 2025 at 8:06 PM CEST, Linus Walleij wrote:
quoted
On Fri, Jul 11, 2025 at 7:45 PM Andrew Lunn [off-list ref] wrote:
quoted
On Fri, Jul 11, 2025 at 07:43:13PM +0200, Linus Walleij wrote:
quoted
On Wed, Jul 9, 2025 at 5:09 PM Andrew Lunn [off-list ref] wrote:
quoted
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.
This callback should return the current direction as set up
in the hardware.

A major usecase is that this is called when the gpiochip is
registered to read out all the current directions of the GPIO
lines, so the kernel has a clear idea of the state of the
hardware.

Calling this should ideally result in a read of the status from
a hardware register.
O.K, so completely different to what is proposed in this patch.

Maybe you can suggest a better name.
If the hardware only supports one direction, then .get_direction()
should return that direction.

What the patch does is to
read the direction from the hardware and use that in the
set_direction() callback, as if all regmapped hardware in the
world had fixed direction, that's wrong.

I'd just add something custom in gpio-regmap if this is
something reoccuring in regmapped GPIO drivers.

bool is_fixed_direction(struct gpio_regmap *gpio, unsigned int offset)

or so?

Then the core can use is_fixed_direction() together
with gpio_get_direction() to check if it can do
a certain set_direction().

Pseudocode:

mydir = get_direction(line)
if (is_fixed_direction(line) && (mydir != requested_dir)
  return -ERROR;
You don't need a .is_fixed_direction(). You can deduce that if only
.get_direction() is set in the gpio-regmap config.

mydir = get_direction(line)
if (!config->set_direction && mydir != requested_dir)
  return -ERROR;
This implies that gpio_regmap_config gets two new callbacks
.get_direction() and .set_direction() and that in case .set_direction()
is set in gpio-regmap config, then its used directly from
gpio_regmap_set_direction(), right?
That or either Andrew's idea of setting a bitmap within the
gpio-regmap config which already tells the gpio-regmap core and then
amend gpio_regmap_get_direction() to return that fixed direction if
that bitmap is not NULL.
Even though at first glance I was under the impression that the bitmap
solution is cleaner, how big should the bitmap be knows only the final
gpio driver. Without this information, we cannot know the bitmap size so
that we can use the DECLARE_BITMAP macro in gpio-regmap config.

Ioana
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help