Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/2] gpio: realtek-otto: make the driver work with SWAP_IO_SPACE
@ 2026-07-10 18:34 Rustam Adilov
  2026-07-10 18:34 ` [PATCH 1/2] gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr() Rustam Adilov
  2026-07-10 18:34 ` [PATCH 2/2] gpio: realtek-otto: decide bank_read/write by device endianness Rustam Adilov
  0 siblings, 2 replies; 5+ messages in thread
From: Rustam Adilov @ 2026-07-10 18:34 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 separated from GPIO_PORTS_REVERSED as they have to be
changed to the opposite one when SWAP_IO_SPACE is enabled. The
device_is_big_endian() function seem to be a good choice for it.
That does mean the rtl838x, rtl839x and rtl931x has to add
big-endian property to their gpio controller nodes for gpio to be
operational without SWAP_IO_SPACE.

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.

Rustam Adilov (2):
  gpio: realtek-otto: use __raw_readl/writel in
    realtek_gpio_update_line_imr()
  gpio: realtek-otto: decide bank_read/write by device endianness

 drivers/gpio/gpio-realtek-otto.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

-- 
2.55.0


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

* [PATCH 1/2] gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr()
  2026-07-10 18:34 [PATCH 0/2] gpio: realtek-otto: make the driver work with SWAP_IO_SPACE Rustam Adilov
@ 2026-07-10 18:34 ` Rustam Adilov
  2026-07-10 18:34 ` [PATCH 2/2] gpio: realtek-otto: decide bank_read/write by device endianness Rustam Adilov
  1 sibling, 0 replies; 5+ messages in thread
From: Rustam Adilov @ 2026-07-10 18:34 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.

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] 5+ messages in thread

* [PATCH 2/2] gpio: realtek-otto: decide bank_read/write by device endianness
  2026-07-10 18:34 [PATCH 0/2] gpio: realtek-otto: make the driver work with SWAP_IO_SPACE Rustam Adilov
  2026-07-10 18:34 ` [PATCH 1/2] gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr() Rustam Adilov
@ 2026-07-10 18:34 ` Rustam Adilov
  2026-07-15  9:39   ` Bartosz Golaszewski
  1 sibling, 1 reply; 5+ messages in thread
From: Rustam Adilov @ 2026-07-10 18:34 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 way bank_read and bank_write are defined must be changed and
separated from GPIO_PORTS_REVERSED flag. That also includes the
flags parameter used by gpio_generic_chip_config.

To achieve it, use the device_is_big_endian() to decide the
bank_read/write parameter and the flag.

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

diff --git a/drivers/gpio/gpio-realtek-otto.c b/drivers/gpio/gpio-realtek-otto.c
index 491fde846d46..f96072fbce92 100644
--- a/drivers/gpio/gpio-realtek-otto.c
+++ b/drivers/gpio/gpio-realtek-otto.c
@@ -393,16 +393,19 @@ static int realtek_gpio_probe(struct platform_device *pdev)
 
 	raw_spin_lock_init(&ctrl->lock);
 
-	if (dev_flags & GPIO_PORTS_REVERSED) {
-		gen_gc_flags = 0;
-		ctrl->bank_read = realtek_gpio_bank_read;
-		ctrl->bank_write = realtek_gpio_bank_write;
+	if (dev_flags & GPIO_PORTS_REVERSED)
 		ctrl->line_imr_pos = realtek_gpio_line_imr_pos;
-	} else {
+	else
+		ctrl->line_imr_pos = realtek_gpio_line_imr_pos_swapped;
+
+	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;
-		ctrl->line_imr_pos = realtek_gpio_line_imr_pos_swapped;
+	} else {
+		gen_gc_flags = 0;
+		ctrl->bank_read = realtek_gpio_bank_read;
+		ctrl->bank_write = realtek_gpio_bank_write;
 	}
 
 	config = (struct gpio_generic_chip_config) {
-- 
2.55.0


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

* Re: [PATCH 2/2] gpio: realtek-otto: decide bank_read/write by device endianness
  2026-07-10 18:34 ` [PATCH 2/2] gpio: realtek-otto: decide bank_read/write by device endianness Rustam Adilov
@ 2026-07-15  9:39   ` Bartosz Golaszewski
  2026-07-15 19:00     ` Rustam Adilov
  0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-07-15  9:39 UTC (permalink / raw)
  To: Rustam Adilov
  Cc: Linus Walleij, Bartosz Golaszewski, Sander Vanheule, linux-gpio,
	linux-kernel

On Fri, 10 Jul 2026 20:34:39 +0200, Rustam Adilov <adilov@disroot.org> said:
> In order to have a working gpio controller with SWAP_IO_SPACE,
> the way bank_read and bank_write are defined must be changed and
> separated from GPIO_PORTS_REVERSED flag. That also includes the
> flags parameter used by gpio_generic_chip_config.
>
> To achieve it, use the device_is_big_endian() to decide the
> bank_read/write parameter and the flag.
>
> Signed-off-by: Rustam Adilov <adilov@disroot.org>
> ---
>  drivers/gpio/gpio-realtek-otto.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpio/gpio-realtek-otto.c b/drivers/gpio/gpio-realtek-otto.c
> index 491fde846d46..f96072fbce92 100644
> --- a/drivers/gpio/gpio-realtek-otto.c
> +++ b/drivers/gpio/gpio-realtek-otto.c
> @@ -393,16 +393,19 @@ static int realtek_gpio_probe(struct platform_device *pdev)
>
>  	raw_spin_lock_init(&ctrl->lock);
>
> -	if (dev_flags & GPIO_PORTS_REVERSED) {
> -		gen_gc_flags = 0;
> -		ctrl->bank_read = realtek_gpio_bank_read;
> -		ctrl->bank_write = realtek_gpio_bank_write;
> +	if (dev_flags & GPIO_PORTS_REVERSED)
>  		ctrl->line_imr_pos = realtek_gpio_line_imr_pos;
> -	} else {
> +	else
> +		ctrl->line_imr_pos = realtek_gpio_line_imr_pos_swapped;
> +
> +	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;
> -		ctrl->line_imr_pos = realtek_gpio_line_imr_pos_swapped;
> +	} else {
> +		gen_gc_flags = 0;
> +		ctrl->bank_read = realtek_gpio_bank_read;
> +		ctrl->bank_write = realtek_gpio_bank_write;
>  	}
>
>  	config = (struct gpio_generic_chip_config) {
> --
> 2.55.0
>
>

Can you look at the sashiko report? I think it's right about this change
possibly breaking existing devicetrees. Can we keep big-endian as the
default?

Bart

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

* Re: [PATCH 2/2] gpio: realtek-otto: decide bank_read/write by device endianness
  2026-07-15  9:39   ` Bartosz Golaszewski
@ 2026-07-15 19:00     ` Rustam Adilov
  0 siblings, 0 replies; 5+ messages in thread
From: Rustam Adilov @ 2026-07-15 19:00 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Sander Vanheule, linux-gpio, linux-kernel

Hello,
On 2026-07-15 09:39, Bartosz Golaszewski wrote:
> On Fri, 10 Jul 2026 20:34:39 +0200, Rustam Adilov <adilov@disroot.org> said:
>> In order to have a working gpio controller with SWAP_IO_SPACE,
>> the way bank_read and bank_write are defined must be changed and
>> separated from GPIO_PORTS_REVERSED flag. That also includes the
>> flags parameter used by gpio_generic_chip_config.
>>
>> To achieve it, use the device_is_big_endian() to decide the
>> bank_read/write parameter and the flag.
>>
>> Signed-off-by: Rustam Adilov <adilov@disroot.org>
>> ---
>>  drivers/gpio/gpio-realtek-otto.c | 15 +++++++++------
>>  1 file changed, 9 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpio/gpio-realtek-otto.c b/drivers/gpio/gpio-realtek-otto.c
>> index 491fde846d46..f96072fbce92 100644
>> --- a/drivers/gpio/gpio-realtek-otto.c
>> +++ b/drivers/gpio/gpio-realtek-otto.c
>> @@ -393,16 +393,19 @@ static int realtek_gpio_probe(struct platform_device *pdev)
>>
>>  	raw_spin_lock_init(&ctrl->lock);
>>
>> -	if (dev_flags & GPIO_PORTS_REVERSED) {
>> -		gen_gc_flags = 0;
>> -		ctrl->bank_read = realtek_gpio_bank_read;
>> -		ctrl->bank_write = realtek_gpio_bank_write;
>> +	if (dev_flags & GPIO_PORTS_REVERSED)
>>  		ctrl->line_imr_pos = realtek_gpio_line_imr_pos;
>> -	} else {
>> +	else
>> +		ctrl->line_imr_pos = realtek_gpio_line_imr_pos_swapped;
>> +
>> +	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;
>> -		ctrl->line_imr_pos = realtek_gpio_line_imr_pos_swapped;
>> +	} else {
>> +		gen_gc_flags = 0;
>> +		ctrl->bank_read = realtek_gpio_bank_read;
>> +		ctrl->bank_write = realtek_gpio_bank_write;
>>  	}
>>
>>  	config = (struct gpio_generic_chip_config) {
>> --
>> 2.55.0
>>
>>
> 
> Can you look at the sashiko report? I think it's right about this change
> possibly breaking existing devicetrees. Can we keep big-endian as the
> default?
> 
> Bart

Oh i didn't know sashiko was looking after this subsystem too.
But yes, it does require the rtl8380-gpio, rtl8390-gpio, rtl9310-gpio
to append big-endian or native-endian (as they are all big endian chips).

I was thinking earlier whatever it is appropriate to make changes to
the arch/mips/boot/dts/realtek in this commit because it is different
subsystem entirely but i guess this (previous sentence) answers the
question, doesn't it.

Also, what exactly do you mean by "Can we keep big-endian as the
default?" ? My only reading off is to change the if statement
so that the big endian flag and the _swapped functions to be
under the else part, is it correct?

Best,
Rustam

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

end of thread, other threads:[~2026-07-15 19:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-10 18:34 [PATCH 0/2] gpio: realtek-otto: make the driver work with SWAP_IO_SPACE Rustam Adilov
2026-07-10 18:34 ` [PATCH 1/2] gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr() Rustam Adilov
2026-07-10 18:34 ` [PATCH 2/2] gpio: realtek-otto: decide bank_read/write by device endianness Rustam Adilov
2026-07-15  9:39   ` Bartosz Golaszewski
2026-07-15 19:00     ` Rustam Adilov

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