[PATCH] MIPS: RB532: attach the software node to its target GPIO controller

From: Bartosz Golaszewski

Date: Thu Apr 30 2026 - 07:44:57 EST


GPIOLIB wants to remove the software node's name matching against GPIO
controller's label that is going on behind the scenes in software node
lookup. To that end, we need to convert all existing users to using
software nodes actually attached to the GPIO devices they represent.

In order to use an attached software node with the GPIO controller on
rb532: convert the GPIO module into a real platform device, provide
platform device info for it in device.c and assign the software node
using its swnode field.

The software node will get inherited by the GPIO chip from the parent
platform device in devm_gpiochip_add_data() as we don't set the fwnode
using any other of the mechanisms.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
arch/mips/rb532/devices.c | 32 ++++++++++++++++++++++++++------
arch/mips/rb532/gpio.c | 41 +++++++++++++++++++++--------------------
2 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/arch/mips/rb532/devices.c b/arch/mips/rb532/devices.c
index c3d8d96d0ef555d44749c5fd3673b1e5afc407ff..a6e3dc11298b719c64013dc38bcac7cd00e3089e 100644
--- a/arch/mips/rb532/devices.c
+++ b/arch/mips/rb532/devices.c
@@ -240,6 +240,25 @@ static struct platform_device *rb532_devs[] = {
&rb532_wdt
};

+#define GPIOBASE 0x050000
+
+static struct resource rb532_gpio_reg0_res[] = {
+ {
+ .name = "gpio_reg0",
+ .start = REGBASE + GPIOBASE,
+ .end = REGBASE + GPIOBASE + sizeof(struct rb532_gpio_reg) - 1,
+ .flags = IORESOURCE_MEM,
+ }
+};
+
+static struct platform_device_info rb532_gpio_devinfo = {
+ .name = "rb532-gpio",
+ .id = PLATFORM_DEVID_NONE,
+ .res = rb532_gpio_reg0_res,
+ .num_res = ARRAY_SIZE(rb532_gpio_reg0_res),
+ .swnode = &rb532_gpio0_node,
+};
+
static const struct property_entry rb532_button_properties[] = {
PROPERTY_ENTRY_GPIO("button-gpios", &rb532_gpio0_node,
GPIO_BTN_S1, GPIO_ACTIVE_LOW),
@@ -309,17 +328,18 @@ static int __init plat_setup_devices(void)
/* set the uart clock to the current cpu frequency */
rb532_uart_res[0].uartclk = idt_cpu_freq;

+ pd = platform_device_register_full(&rb532_gpio_devinfo);
+ ret = PTR_ERR_OR_ZERO(pd);
+ if (ret) {
+ pr_err("failed to create the GPIO device: %d\n", ret);
+ return ret;
+ }
+
gpiod_add_lookup_table(&cf_slot0_gpio_table);
ret = platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
if (ret)
return ret;

- /*
- * Stack devices using full info and properties here, after we
- * register the node for the GPIO chip.
- */
- software_node_register(&rb532_gpio0_node);
-
pd = platform_device_register_full(&nand0_info);
ret = PTR_ERR_OR_ZERO(pd);
if (ret) {
diff --git a/arch/mips/rb532/gpio.c b/arch/mips/rb532/gpio.c
index 9aa5ef374465c429046c52c5448e2fadfc82e131..49e1a15a3827ea557d4d59ead85a19ecc44cb8e3 100644
--- a/arch/mips/rb532/gpio.c
+++ b/arch/mips/rb532/gpio.c
@@ -37,7 +37,6 @@
#include <asm/mach-rc32434/rb.h>
#include <asm/mach-rc32434/gpio.h>

-#define GPIOBASE 0x050000
/* Offsets relative to GPIOBASE */
#define GPIOFUNC 0x00
#define GPIOCFG 0x04
@@ -52,15 +51,6 @@ struct rb532_gpio_chip {
void __iomem *regbase;
};

-static struct resource rb532_gpio_reg0_res[] = {
- {
- .name = "gpio_reg0",
- .start = REGBASE + GPIOBASE,
- .end = REGBASE + GPIOBASE + sizeof(struct rb532_gpio_reg) - 1,
- .flags = IORESOURCE_MEM,
- }
-};
-
/* rb532_set_bit - sanely set a bit
*
* bitval: new value for the bit
@@ -199,21 +189,32 @@ void rb532_gpio_set_func(unsigned gpio)
}
EXPORT_SYMBOL(rb532_gpio_set_func);

-static int __init rb532_gpio_init(void)
+static int rb532_gpio_probe(struct platform_device *pdev)
{
- struct resource *r;
+ struct device *dev = &pdev->dev;
+ struct resource *res;

- r = rb532_gpio_reg0_res;
- rb532_gpio_chip->regbase = ioremap(r->start, resource_size(r));
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res)
+ return -EINVAL;

- if (!rb532_gpio_chip->regbase) {
- printk(KERN_ERR "rb532: cannot remap GPIO register 0\n");
- return -ENXIO;
- }
+ rb532_gpio_chip->regbase = devm_ioremap_resource(dev, res);
+ if (IS_ERR(rb532_gpio_chip->regbase))
+ return PTR_ERR(rb532_gpio_chip->regbase);

/* Register our GPIO chip */
- gpiochip_add_data(&rb532_gpio_chip->chip, rb532_gpio_chip);
+ return devm_gpiochip_add_data(dev, &rb532_gpio_chip->chip, rb532_gpio_chip);
+}

- return 0;
+static struct platform_driver rb532_gpio_driver = {
+ .driver = {
+ .name = "rb532-gpio",
+ },
+ .probe = rb532_gpio_probe,
+};
+
+static int __init rb532_gpio_init(void)
+{
+ return platform_driver_register(&rb532_gpio_driver);
}
arch_initcall(rb532_gpio_init);

---
base-commit: 70126d34d0d65e2294dee3e5ee9485fd1875e8a4
change-id: 20260430-mips-rb532-gpio-61b3982b4ed6

Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>