gpio: realtek-otto: make the driver work with SWAP_IO_SPACE
v2 cover gpio: realtek-otto: make the driver work with SWAP_IO_SPACE
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/[email protected]/
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(-)
Signature · 1 line
2.55.0
PATCH v2 1/2 gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr()
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.
--- drivers/gpio/gpio-realtek-otto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpio-realtek-otto.c +2 -2
@@ -176,10 +176,10 @@ static void realtek_gpio_update_line_imr(struct realtek_gpio_ctrl *ctrl, unsigneu32 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)
Signature · 1 line
2.55.0
PATCH v2 2/2 gpio: realtek-otto: make bank_read/write overridable by endian property
In reply to Rustam AdilovIn 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.
--- drivers/gpio/gpio-realtek-otto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpio/gpio-realtek-otto.c +10 -0
@@ -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 ,
Signature · 1 line
2.55.0
Bartosz Golaszewski
AppliedQuoted 8 lines · Rustam Adilov
This patch series changes gpio-realtek-otto to be functional around
SWAP_IO_SPACEconfig.Firstly the ioread32 and iowrite32 in
realtek_gpio_update_line_imr()have to be changed to their__rawvariants as it is the only point in the driver where both devices with ports reversed and without meet.[...]
Applied, thanks!
[1/2] gpio: realtek-otto: use __raw_readl/writel in realtek_gpio_update_line_imr()
https://git.kernel.org/brgl/c/61ef599b782e776437886f2be0623b3c9055e5d3 [2/2] gpio: realtek-otto: make bank_read/write overridable by endian property https://git.kernel.org/brgl/c/785ec26c37e56ee5f142b6684f7c15c7ca7430a3
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
Quoted 13 lines · Rustam Adilov
This patch series changes gpio-realtek-otto to be functional around
SWAP_IO_SPACEconfig.Firstly the ioread32 and iowrite32 in
realtek_gpio_update_line_imr()have to be changed to their__rawvariants 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_SPACEis 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 currentGPIO_PORTS_REVERSEDquirk as it is.
Quoted 3 lines
I have tested it on my RTL9607C machine with
SWAP_IO_SPACEenabled and with big-endian property set under gpio controller node and it was working fine.
Convert the driver to use regmap MMIO and most of the code in this series won't be needed. Also it will give some benefits (like register caching and debugfs monitoring).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Linus Walleij
maintainerQuoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rustam Adilov
This patch series changes gpio-realtek-otto to be functional around
SWAP_IO_SPACEconfig.
(...)
Quoted 3 lines
Convert the driver to use regmap MMIO and most of the code in this series won't be needed. Also it will give some benefits (like register caching and debugfs monitoring).
Andy is right.
Make an attempt on top of the merged patches to convert this to regmap MMIO and see what happens, and if that works consider regmap GPIO as well.
Everyone will be happier, because less code.
Yours,
Linus Walleij
Quoted 10 lines · Linus Walleij
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rustam Adilov
This patch series changes gpio-realtek-otto to be functional around
SWAP_IO_SPACEconfig.(...)
Quoted 3 lines
Convert the driver to use regmap MMIO and most of the code in this series won't be needed. Also it will give some benefits (like register caching and debugfs monitoring).
Quoted 7 lines
Andy is right.
Make an attempt on top of the merged patches to convert this to regmap MMIO and see what happens, and if that works consider regmap GPIO as well.
Everyone will be happier, because less code.
As far as i remember, i thought of using regmap earlier but got stuck because the regmap has to not swap in realtek_gpio_update_line_imr() but potentially swap in other places by bank_read/write.
Maybe i am missing something but i just couldn't figure it out.
Best,
Rustam
Linus Walleij
maintainerQuoted 18 lines · Rustam Adilov
Quoted 16 lines · Linus Walleij
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rustam Adilov
This patch series changes gpio-realtek-otto to be functional around
SWAP_IO_SPACEconfig.(...)
Quoted 3 lines
Convert the driver to use regmap MMIO and most of the code in this series won't be needed. Also it will give some benefits (like register caching and debugfs monitoring).
Andy is right.
Make an attempt on top of the merged patches to convert this to regmap MMIO and see what happens, and if that works consider regmap GPIO as well.
Quoted 6 lines
Quoted 1 line
Everyone will be happier, because less code.
As far as i remember, i thought of using regmap earlier but got stuck because the regmap has to not swap in
realtek_gpio_update_line_imr()but potentially swap in other places by bank_read/write.
Maybe i am missing something but i just couldn't figure it out.
Regmap can do any kind of cherry-picked exceptions in the callbacks, so I think it can deal with that, you just need a more custom than average regmap set-up.
Yours,
Linus Walleij