Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] gpio: realtek-otto: make the driver work with SWAP_IO_SPACE
@ 2026-08-15  9:44 Rustam Adilov
  2026-08-15  9:44 ` [PATCH v2 1/2] gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr() Rustam Adilov
  2026-08-15  9:44 ` [PATCH v2 2/2] gpio: realtek-otto: make bank_read/write overridable by endian property Rustam Adilov
  0 siblings, 2 replies; 3+ messages in thread
From: Rustam Adilov @ 2026-08-15  9:44 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Sander Vanheule, linux-gpio,
	linux-kernel
  Cc: Rustam Adilov

This patch series changes gpio-realtek-otto to be functional around
SWAP_IO_SPACE config.

Firstly the ioread32 and iowrite32 in realtek_gpio_update_line_imr()
have to be changed to their __raw variants as it is the only point in
the driver where both devices with ports reversed and without meet.

Secondly, the bank_read/write and the flag for generic gpio config
have to be able to be changed to the opposite one when SWAP_IO_SPACE
is enabled. To avoid breaking any existing device tree out in the wild,
make them overridable by endian properties from the device tree node and
keep the current GPIO_PORTS_REVERSED quirk as it is.

I have tested it on my RTL9607C machine with SWAP_IO_SPACE enabled
and with big-endian property set under gpio controller node and it
was working fine.

---
Changes in v2:
 - added the review-by tag from Linus Walleij.
 - changed the patch 1 to instead use endian preprties as overrides on top of existing
   GPIO_PORTS_REVERSED quirk to not break any exsiting device trees as they don't use
   endian properties.
 - Link to v1: https://lore.kernel.org/all/20260511131520.98420-1-adilov@disroot.org/
 
Rustam Adilov (2):
  gpio: realtek-otto: use __raw_readl/writel in
    realtek_gpio_update_line_imr()
  gpio: realtek-otto: make bank_read/write overridable by endian
    property

 drivers/gpio/gpio-realtek-otto.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr()
  2026-08-15  9:44 [PATCH v2 0/2] gpio: realtek-otto: make the driver work with SWAP_IO_SPACE Rustam Adilov
@ 2026-08-15  9:44 ` Rustam Adilov
  2026-08-15  9:44 ` [PATCH v2 2/2] gpio: realtek-otto: make bank_read/write overridable by endian property Rustam Adilov
  1 sibling, 0 replies; 3+ messages in thread
From: Rustam Adilov @ 2026-08-15  9:44 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Sander Vanheule, linux-gpio,
	linux-kernel
  Cc: Rustam Adilov

In preparation for upcoming changes to how bank reads and writes
are defined in this driver, change the ioread32 and iowrite32 to
their __raw variants. The realtek_gpio_update_line_imr() function
is used by all devices regardless of GPIO_PORTS_REVERSED flag and
thus this is the only place where there shouldn't be any byte
swapping whether SWAP_IO_SPACE config is enabled or not and that
is only possible with __raw_readl and __raw_writel.

Reviewed-by: Linus Walleij <linusw@kernel.org>
Signed-off-by: Rustam Adilov <adilov@disroot.org>
---
 drivers/gpio/gpio-realtek-otto.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-realtek-otto.c b/drivers/gpio/gpio-realtek-otto.c
index 4a606bad5848..491fde846d46 100644
--- a/drivers/gpio/gpio-realtek-otto.c
+++ b/drivers/gpio/gpio-realtek-otto.c
@@ -176,10 +176,10 @@ static void realtek_gpio_update_line_imr(struct realtek_gpio_ctrl *ctrl, unsigne
 	u32 reg_val;
 
 	reg += 4 * (line_shift / 32);
-	reg_val = ioread32(reg);
+	reg_val = __raw_readl(reg);
 	reg_val &= ~(REALTEK_GPIO_IMR_LINE_MASK << shift);
 	reg_val |= (irq_type & irq_mask & REALTEK_GPIO_IMR_LINE_MASK) << shift;
-	iowrite32(reg_val, reg);
+	__raw_writel(reg_val, reg);
 }
 
 static void realtek_gpio_irq_ack(struct irq_data *data)
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] gpio: realtek-otto: make bank_read/write overridable by endian property
  2026-08-15  9:44 [PATCH v2 0/2] gpio: realtek-otto: make the driver work with SWAP_IO_SPACE Rustam Adilov
  2026-08-15  9:44 ` [PATCH v2 1/2] gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr() Rustam Adilov
@ 2026-08-15  9:44 ` Rustam Adilov
  1 sibling, 0 replies; 3+ messages in thread
From: Rustam Adilov @ 2026-08-15  9:44 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Sander Vanheule, linux-gpio,
	linux-kernel
  Cc: Rustam Adilov

In order to have a working gpio controller with SWAP_IO_SPACE,
the bank_read/bank_write functions and the gen_gc_flag used for
gpio_generic_chip_config must be able to be changed to their
respective counterparts.

To do that, introduce checks for the presence of endian property
under the device tree node and if so, override what has been
set by GPIO_PORTS_REVERSED quirk flag. This way, existing device
trees are kept working as they were originally.

Both big-endian and little-endian properties must be checked
because there are devices that have GPIO_PORTS_REVERSED flag
and the others that don't.

Signed-off-by: Rustam Adilov <adilov@disroot.org>
---
 drivers/gpio/gpio-realtek-otto.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpio/gpio-realtek-otto.c b/drivers/gpio/gpio-realtek-otto.c
index 491fde846d46..e079b5180760 100644
--- a/drivers/gpio/gpio-realtek-otto.c
+++ b/drivers/gpio/gpio-realtek-otto.c
@@ -405,6 +405,16 @@ static int realtek_gpio_probe(struct platform_device *pdev)
 		ctrl->line_imr_pos = realtek_gpio_line_imr_pos_swapped;
 	}
 
+	if (device_property_read_bool(dev, "little-endian")) {
+		gen_gc_flags = 0;
+		ctrl->bank_read = realtek_gpio_bank_read;
+		ctrl->bank_write = realtek_gpio_bank_write;
+	} else if (device_is_big_endian(dev)) {
+		gen_gc_flags = GPIO_GENERIC_BIG_ENDIAN_BYTE_ORDER;
+		ctrl->bank_read = realtek_gpio_bank_read_swapped;
+		ctrl->bank_write = realtek_gpio_bank_write_swapped;
+	}
+
 	config = (struct gpio_generic_chip_config) {
 		.dev = dev,
 		.sz = 4,
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-15  9:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-15  9:44 [PATCH v2 0/2] gpio: realtek-otto: make the driver work with SWAP_IO_SPACE Rustam Adilov
2026-08-15  9:44 ` [PATCH v2 1/2] gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr() Rustam Adilov
2026-08-15  9:44 ` [PATCH v2 2/2] gpio: realtek-otto: make bank_read/write overridable by endian property Rustam Adilov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox