[RFC PATCH 0/5] gpio: add PMIO support to gpio-mmio

Jose Javier Rodriguez Barbarin posted 5 patches 2 months, 1 week ago
There is a newer version of this series
drivers/gpio/gpio-mmio.c     | 277 +++++++++++++++++++++++++----------
include/linux/gpio/generic.h |  49 +++++--
2 files changed, 243 insertions(+), 83 deletions(-)
[RFC PATCH 0/5] gpio: add PMIO support to gpio-mmio
Posted by Jose Javier Rodriguez Barbarin 2 months, 1 week ago
This series is an RFC for adding port-mapped I/O (PMIO) support to
gpio-mmio.

The initial motivation was to add PMIO support to gpio-menz127, as we
plan to support this across MCB client drivers. Since gpio-menz127
currently relies on the gpio_generic_chip API, adding PMIO support only
in that driver would require a significant refactoring, including
separate callbacks for memory-mapped and port-mapped accesses.

While looking into this, I noticed a TODO item added by Linus Walleij
about extending gpio-mmio to support port-mapped devices. Based on that,
this series explores adding PMIO support to gpio-mmio instead of
handling it in individual drivers.

The main goal of this approach is to preserve compatibility with
existing MMIO drivers using gpio_generic_chip while extending the API to
also describe PMIO-backed registers. To achieve that, the series extends
struct gpio_generic_chip_config with dedicated fields for port-mapped
registers.

To handle the different register address types used by MMIO
(void __iomem *) and PMIO (unsigned long), this series introduces a
small wrapper structure that can represent both. The read_reg() and
write_reg() callbacks are then updated to operate on this common
representation.

This series has been tested with gpio-menz127, and the driver worked
correctly with both MMIO and PMIO devices.

This is being sent as RFC because I would like feedback on the overall
approach before proceeding further.

In particular, feedback would be appreciated on:
- whether extending gpio_generic_chip_config is the right direction;
- whether introducing a common MMIO/PMIO register descriptor is
  acceptable;
- whether PMIO support should instead be implemented differently in
  gpio-mmio.

Jose Javier Rodriguez Barbarin (5):
  gpio: generic: add a generic register wrapper for MMIO and PMIO
  gpio: generic: extend gpio_generic_chip_config with PMIO register
    fields
  gpio: generic: add io_port to struct gpio_generic_chip
  gpio: mmio: convert accessors to generic register descriptors
  gpio: mmio: add port-mapped read/write callbacks

 drivers/gpio/gpio-mmio.c     | 277 +++++++++++++++++++++++++----------
 include/linux/gpio/generic.h |  49 +++++--
 2 files changed, 243 insertions(+), 83 deletions(-)

-- 
2.53.0
Re: [RFC PATCH 0/5] gpio: add PMIO support to gpio-mmio
Posted by Linus Walleij 2 months ago
Hi Jose,

thanks for your proposal!!

I'm very happy to see some traction on this. I add WBG to CC because he
wrote so many port-mapped drivers that I think he'll be thrilled to make
use of this as well.

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

> This series is an RFC for adding port-mapped I/O (PMIO) support to
> gpio-mmio.
(...)
> In particular, feedback would be appreciated on:
> - whether extending gpio_generic_chip_config is the right direction;

Pointed out on the patch that you can just create a
gpio_generic_port_chip_config
or something like that, it's only used at config time (usually locally
in probe()) resulting in a transient stack allocation anyway.

Also that makes it easier to see what's going on.

> - whether introducing a common MMIO/PMIO register descriptor is
>   acceptable;
> - whether PMIO support should instead be implemented differently in
>   gpio-mmio.

The main feedback I have is to use a union between port and
MMIO address instead of a struct with both.

It makes it clear that we only ever use one of them and saves
some memory, especially since we use several instances of
it per generic chip later in the code.

Yours,
Linus Walleij
Re: [RFC PATCH 0/5] gpio: add PMIO support to gpio-mmio
Posted by Jose Javier Rodriguez Barbarin 2 months ago
On Thu, Apr 09, 2026 at 10:14:17AM +0200, Linus Walleij wrote:
> Hi Jose,
> 
> thanks for your proposal!!

You are welcome :)

> 
> I'm very happy to see some traction on this. I add WBG to CC because he
> wrote so many port-mapped drivers that I think he'll be thrilled to make
> use of this as well.

I was a bit worried about if my approach was correct or not, so I'm really
glad to hear such positive feedback.

> 
> On Tue, Apr 7, 2026 at 8:49 PM Jose Javier Rodriguez Barbarin
> <dev-josejavier.rodriguez@duagon.com> wrote:
> 
> > This series is an RFC for adding port-mapped I/O (PMIO) support to
> > gpio-mmio.
> (...)
> > In particular, feedback would be appreciated on:
> > - whether extending gpio_generic_chip_config is the right direction;
> 
> Pointed out on the patch that you can just create a
> gpio_generic_port_chip_config
> or something like that, it's only used at config time (usually locally
> in probe()) resulting in a transient stack allocation anyway.
> 
> Also that makes it easier to see what's going on.

Seems interesting.

As you pointed out, creating the new gpio_generic_port_chip_config would
need more refactoring to adapt the new structure. I'm OK with that so I'm
working on it. I will include those changes on v2.

> 
> > - whether introducing a common MMIO/PMIO register descriptor is
> >   acceptable;
> > - whether PMIO support should instead be implemented differently in
> >   gpio-mmio.
> 
> The main feedback I have is to use a union between port and
> MMIO address instead of a struct with both.
> 
> It makes it clear that we only ever use one of them and saves
> some memory, especially since we use several instances of
> it per generic chip later in the code.
> 

Annotated. I will include the union on v2.

> Yours,
> Linus Walleij

Thanks for your review and for your comments/suggestions. I really
appreciate that.

Regards,

Javier R.