Re: [RFC PATCH 1/5] gpio: generic: add a generic register wrapper for MMIO and PMIO

From: Linus Walleij

Date: Thu Apr 09 2026 - 03:54:22 EST


Hi Jose,

thanks for your patch!

On Tue, Apr 7, 2026 at 8:49 PM Jose Javier Rodriguez Barbarin
<dev-josejavier.rodriguez@xxxxxxxxxx> wrote:

> For adding support to port-mapped devices within gpio_generic_chip, a new
> data type is required for passing to read_reg() and write_reg()
> callbacks as I/O port-mapped and memory-mapped registers use different
> data types.
>
> Introduce a new struct gpio_chip_reg to encapsulate mmio addresses and
> I/O port numbers.
>
> Signed-off-by: Jose Javier Rodriguez Barbarin <dev-josejavier.rodriguez@xxxxxxxxxx>

Overall this is just fine, but I have one idea:

> +struct gpio_chip_reg {
> + void __iomem *mmio;
> + unsigned long port;
> +};

Since you're always using one or the other, can we use a union?

union gpio_chip_reg {
void __iomem *mmio;
unsigned long port;
};

This way it will use the same amount of memory no matter which version is
used.

OK it's a micro-optimization but also elegant because it reflects the fact that
we just use one or the other.

Yours,
Linus Walleij