* [PATCH 0/2] MIPS RB532 GPIO descriptor conversion
@ 2026-03-28 15:55 Linus Walleij
2026-03-28 15:55 ` [PATCH 1/2] MIPS/input: Move RB532 button to GPIO descriptors Linus Walleij
2026-03-28 15:55 ` [PATCH 2/2] MIPS/mtd: Handle READY GPIO in generic NAND platform data Linus Walleij
0 siblings, 2 replies; 3+ messages in thread
From: Linus Walleij @ 2026-03-28 15:55 UTC (permalink / raw)
To: Thomas Bogendoerfer, Dmitry Torokhov, Bartosz Golaszewski,
Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
Cc: linux-mips, linux-input, linux-gpio, linux-mtd, Linus Walleij
This moves the MIPS Mikrotik RouterBoard RB532 over to using
GPIO descriptors by augmenting the two remaining drivers using
GPIOs to use software nodes and device properties.
This is part of the pull to get rid of the legacy GPIO API
inside the kernel.
It would be nice if someone can test of this actually works,
I've only compile-tested it.
If we can agree on this method to move forward with this machine
it would be nice if the MIPS maintainer could merge the end
result with ACKs from the input and MTD maintainers.
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
Linus Walleij (2):
MIPS/input: Move RB532 button to GPIO descriptors
MIPS/mtd: Handle READY GPIO in generic NAND platform data
arch/mips/rb532/devices.c | 83 ++++++++++++++++++++++++++++-----------
drivers/input/misc/rb532_button.c | 35 ++++++++++++++---
drivers/mtd/nand/raw/plat_nand.c | 24 ++++++++++-
3 files changed, 113 insertions(+), 29 deletions(-)
---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260327-mips-input-rb532-button-39e44085a2f9
Best regards,
--
Linus Walleij <linusw@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] MIPS/input: Move RB532 button to GPIO descriptors
2026-03-28 15:55 [PATCH 0/2] MIPS RB532 GPIO descriptor conversion Linus Walleij
@ 2026-03-28 15:55 ` Linus Walleij
2026-03-28 15:55 ` [PATCH 2/2] MIPS/mtd: Handle READY GPIO in generic NAND platform data Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2026-03-28 15:55 UTC (permalink / raw)
To: Thomas Bogendoerfer, Dmitry Torokhov, Bartosz Golaszewski,
Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
Cc: linux-mips, linux-input, linux-gpio, linux-mtd, Linus Walleij
Convert the Mikrotik RouterBoard RB532 to use GPIO descriptors
by defining a software node for the GPIO chip, then register
the button platform device with full info passing the GPIO
as a device property.
This can be used as a base to move more of the RB532 devices
over to passing GPIOs using device properties.
Use the GPIO_ACTIVE_LOW flag and drop the inversion in the
rb532_button_pressed() function.
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
arch/mips/rb532/devices.c | 47 +++++++++++++++++++++++++++++++++------
drivers/input/misc/rb532_button.c | 35 ++++++++++++++++++++++++-----
2 files changed, 69 insertions(+), 13 deletions(-)
diff --git a/arch/mips/rb532/devices.c b/arch/mips/rb532/devices.c
index 4f027efbf27b..3f56d9feb73a 100644
--- a/arch/mips/rb532/devices.c
+++ b/arch/mips/rb532/devices.c
@@ -16,8 +16,10 @@
#include <linux/mtd/mtd.h>
#include <linux/gpio.h>
#include <linux/gpio/machine.h>
+#include <linux/gpio/property.h>
#include <linux/gpio_keys.h>
#include <linux/input.h>
+#include <linux/property.h>
#include <linux/serial_8250.h>
#include <asm/bootinfo.h>
@@ -38,6 +40,10 @@ extern unsigned int idt_cpu_freq;
static struct mpmc_device dev3;
+static const struct software_node rb532_gpio0_node = {
+ .name = "gpio0",
+};
+
void set_latch_u5(unsigned char or_mask, unsigned char nand_mask)
{
unsigned long flags;
@@ -189,11 +195,6 @@ static struct platform_device rb532_led = {
.id = -1,
};
-static struct platform_device rb532_button = {
- .name = "rb532-button",
- .id = -1,
-};
-
static struct resource rb532_wdt_res[] = {
{
.name = "rb532_wdt_res",
@@ -236,11 +237,23 @@ static struct platform_device *rb532_devs[] = {
&nand_slot0,
&cf_slot0,
&rb532_led,
- &rb532_button,
&rb532_uart,
&rb532_wdt
};
+static const struct property_entry rb532_button_properties[] = {
+ PROPERTY_ENTRY_GPIO("button-gpios", &rb532_gpio0_node,
+ GPIO_BTN_S1, GPIO_ACTIVE_LOW),
+ { }
+};
+
+static const struct platform_device_info rb532_button_info __initconst = {
+ .name = "rb532-button",
+ .id = PLATFORM_DEVID_NONE,
+ .properties = rb532_button_properties,
+};
+
+
/* NAND definitions */
#define NAND_CHIP_DELAY 25
@@ -267,6 +280,9 @@ static void __init rb532_nand_setup(void)
static int __init plat_setup_devices(void)
{
+ struct platform_device *pd;
+ int ret;
+
/* Look for the CF card reader */
if (!readl(IDT434_REG_BASE + DEV1MASK))
rb532_devs[2] = NULL; /* disable cf_slot0 at index 2 */
@@ -295,7 +311,24 @@ static int __init plat_setup_devices(void)
rb532_uart_res[0].uartclk = idt_cpu_freq;
gpiod_add_lookup_table(&cf_slot0_gpio_table);
- return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
+ 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(&rb532_button_info);
+ ret = PTR_ERR_OR_ZERO(pd);
+ if (ret) {
+ pr_err("failed to create RB532 button device: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
}
#ifdef CONFIG_NET
diff --git a/drivers/input/misc/rb532_button.c b/drivers/input/misc/rb532_button.c
index 190a80e1e2c1..40173bf7a235 100644
--- a/drivers/input/misc/rb532_button.c
+++ b/drivers/input/misc/rb532_button.c
@@ -8,7 +8,7 @@
#include <linux/input.h>
#include <linux/module.h>
#include <linux/platform_device.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
#include <asm/mach-rc32434/gpio.h>
#include <asm/mach-rc32434/rb.h>
@@ -18,6 +18,14 @@
#define RB532_BTN_RATE 100 /* msec */
#define RB532_BTN_KSYM BTN_0
+/**
+ * struct rb532_button - RB532 button information
+ * @gpio: GPIO connected to the button
+ */
+struct rb532_button {
+ struct gpio_desc *gpio;
+};
+
/* The S1 button state is provided by GPIO pin 1. But as this
* pin is also used for uart input as alternate function, the
* operational modes must be switched first:
@@ -31,35 +39,48 @@
* The GPIO value occurs to be inverted, so pin high means
* button is not pressed.
*/
-static bool rb532_button_pressed(void)
+static bool rb532_button_pressed(struct rb532_button *button)
{
int val;
set_latch_u5(0, LO_FOFF);
- gpio_direction_input(GPIO_BTN_S1);
+ gpiod_direction_input(button->gpio);
- val = gpio_get_value(GPIO_BTN_S1);
+ val = gpiod_get_value(button->gpio);
rb532_gpio_set_func(GPIO_BTN_S1);
set_latch_u5(LO_FOFF, 0);
- return !val;
+ return val;
}
static void rb532_button_poll(struct input_dev *input)
{
- input_report_key(input, RB532_BTN_KSYM, rb532_button_pressed());
+ struct rb532_button *button = input_get_drvdata(input);
+
+ input_report_key(input, RB532_BTN_KSYM, rb532_button_pressed(button));
input_sync(input);
}
static int rb532_button_probe(struct platform_device *pdev)
{
+ struct rb532_button *button;
struct input_dev *input;
int error;
+ button = devm_kzalloc(&pdev->dev, sizeof(*button), GFP_KERNEL);
+ if (!button)
+ return -ENOMEM;
+
+ button->gpio = devm_gpiod_get(&pdev->dev, "button", GPIOD_IN);
+ if (IS_ERR(button->gpio))
+ return dev_err_probe(&pdev->dev, PTR_ERR(button->gpio),
+ "error getting button GPIO\n");
+
input = devm_input_allocate_device(&pdev->dev);
if (!input)
return -ENOMEM;
+ input_set_drvdata(input, button);
input->name = "rb532 button";
input->phys = "rb532/button0";
@@ -77,6 +98,8 @@ static int rb532_button_probe(struct platform_device *pdev)
if (error)
return error;
+ platform_set_drvdata(pdev, button);
+
return 0;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] MIPS/mtd: Handle READY GPIO in generic NAND platform data
2026-03-28 15:55 [PATCH 0/2] MIPS RB532 GPIO descriptor conversion Linus Walleij
2026-03-28 15:55 ` [PATCH 1/2] MIPS/input: Move RB532 button to GPIO descriptors Linus Walleij
@ 2026-03-28 15:55 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2026-03-28 15:55 UTC (permalink / raw)
To: Thomas Bogendoerfer, Dmitry Torokhov, Bartosz Golaszewski,
Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
Cc: linux-mips, linux-input, linux-gpio, linux-mtd, Linus Walleij
The callbacks into the MIPS RB532 platform to read the GPIO pin
indicating that the NAND chip is ready are oldschool and does
not assign GPIOs as properties to the NAND device.
Add a capability to the generic platform NAND chip driver to use
a GPIO line to detect if a NAND chip is ready and override the
platform-local drv_ready() callback with this check if the GPIO
is present.
This makes it possible to drop the legacy include header
<linux/gpio.h> from the RB532 devices.
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
arch/mips/rb532/devices.c | 36 +++++++++++++++++++++---------------
drivers/mtd/nand/raw/plat_nand.c | 24 +++++++++++++++++++++++-
2 files changed, 44 insertions(+), 16 deletions(-)
diff --git a/arch/mips/rb532/devices.c b/arch/mips/rb532/devices.c
index 3f56d9feb73a..c3d8d96d0ef5 100644
--- a/arch/mips/rb532/devices.c
+++ b/arch/mips/rb532/devices.c
@@ -14,7 +14,6 @@
#include <linux/platform_device.h>
#include <linux/mtd/platnand.h>
#include <linux/mtd/mtd.h>
-#include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/gpio/property.h>
#include <linux/gpio_keys.h>
@@ -135,12 +134,6 @@ static struct platform_device cf_slot0 = {
.num_resources = ARRAY_SIZE(cf_slot0_res),
};
-/* Resources and device for NAND */
-static int rb532_dev_ready(struct nand_chip *chip)
-{
- return gpio_get_value(GPIO_RDY);
-}
-
static void rb532_cmd_ctrl(struct nand_chip *chip, int cmd, unsigned int ctrl)
{
unsigned char orbits, nandbits;
@@ -166,16 +159,23 @@ static struct resource nand_slot0_res[] = {
};
static struct platform_nand_data rb532_nand_data = {
- .ctrl.dev_ready = rb532_dev_ready,
.ctrl.cmd_ctrl = rb532_cmd_ctrl,
};
-static struct platform_device nand_slot0 = {
- .name = "gen_nand",
- .id = -1,
- .resource = nand_slot0_res,
- .num_resources = ARRAY_SIZE(nand_slot0_res),
- .dev.platform_data = &rb532_nand_data,
+static const struct property_entry nand0_properties[] = {
+ PROPERTY_ENTRY_GPIO("ready-gpios", &rb532_gpio0_node,
+ GPIO_RDY, GPIO_ACTIVE_HIGH),
+ { }
+};
+
+static const struct platform_device_info nand0_info __initconst = {
+ .name = "gen_nand",
+ .id = PLATFORM_DEVID_NONE,
+ .res = nand_slot0_res,
+ .num_res = ARRAY_SIZE(nand_slot0_res),
+ .data = &rb532_nand_data,
+ .size_data = sizeof(struct platform_nand_data),
+ .properties = nand0_properties,
};
static struct mtd_partition rb532_partition_info[] = {
@@ -234,7 +234,6 @@ static struct platform_device rb532_uart = {
static struct platform_device *rb532_devs[] = {
&korina_dev0,
- &nand_slot0,
&cf_slot0,
&rb532_led,
&rb532_uart,
@@ -321,6 +320,13 @@ static int __init plat_setup_devices(void)
*/
software_node_register(&rb532_gpio0_node);
+ pd = platform_device_register_full(&nand0_info);
+ ret = PTR_ERR_OR_ZERO(pd);
+ if (ret) {
+ pr_err("failed to create NAND slot0 device: %d\n", ret);
+ return ret;
+ }
+
pd = platform_device_register_full(&rb532_button_info);
ret = PTR_ERR_OR_ZERO(pd);
if (ret) {
diff --git a/drivers/mtd/nand/raw/plat_nand.c b/drivers/mtd/nand/raw/plat_nand.c
index 0bcd455328ef..fe31551bcf5f 100644
--- a/drivers/mtd/nand/raw/plat_nand.c
+++ b/drivers/mtd/nand/raw/plat_nand.c
@@ -6,6 +6,7 @@
*/
#include <linux/err.h>
+#include <linux/gpio/consumer.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/platform_device.h>
@@ -17,6 +18,7 @@ struct plat_nand_data {
struct nand_controller controller;
struct nand_chip chip;
void __iomem *io_base;
+ struct gpio_desc *ready_gpio;
};
static int plat_nand_attach_chip(struct nand_chip *chip)
@@ -32,6 +34,14 @@ static const struct nand_controller_ops plat_nand_ops = {
.attach_chip = plat_nand_attach_chip,
};
+/* Resources and device for NAND */
+static int plat_nand_gpio_dev_ready(struct nand_chip *chip)
+{
+ struct plat_nand_data *data = nand_get_controller_data(chip);
+
+ return gpiod_get_value(data->ready_gpio);
+}
+
/*
* Probe for the NAND device.
*/
@@ -41,6 +51,7 @@ static int plat_nand_probe(struct platform_device *pdev)
struct plat_nand_data *data;
struct mtd_info *mtd;
const char **part_types;
+ struct nand_chip *chip;
int err = 0;
if (!pdata) {
@@ -59,9 +70,17 @@ static int plat_nand_probe(struct platform_device *pdev)
if (!data)
return -ENOMEM;
+ data->ready_gpio = devm_gpiod_get_optional(&pdev->dev, "ready",
+ GPIOD_IN);
+ if (IS_ERR(data->ready_gpio))
+ return dev_err_probe(&pdev->dev, PTR_ERR(data->ready_gpio),
+ "could not get READY GPIO\n");
+
data->controller.ops = &plat_nand_ops;
nand_controller_init(&data->controller);
data->chip.controller = &data->controller;
+ chip = &data->chip;
+ nand_set_controller_data(chip, data);
data->io_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(data->io_base))
@@ -74,7 +93,10 @@ static int plat_nand_probe(struct platform_device *pdev)
data->chip.legacy.IO_ADDR_R = data->io_base;
data->chip.legacy.IO_ADDR_W = data->io_base;
data->chip.legacy.cmd_ctrl = pdata->ctrl.cmd_ctrl;
- data->chip.legacy.dev_ready = pdata->ctrl.dev_ready;
+ if (data->ready_gpio)
+ data->chip.legacy.dev_ready = plat_nand_gpio_dev_ready;
+ else
+ data->chip.legacy.dev_ready = pdata->ctrl.dev_ready;
data->chip.legacy.select_chip = pdata->ctrl.select_chip;
data->chip.legacy.write_buf = pdata->ctrl.write_buf;
data->chip.legacy.read_buf = pdata->ctrl.read_buf;
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-28 15:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-28 15:55 [PATCH 0/2] MIPS RB532 GPIO descriptor conversion Linus Walleij
2026-03-28 15:55 ` [PATCH 1/2] MIPS/input: Move RB532 button to GPIO descriptors Linus Walleij
2026-03-28 15:55 ` [PATCH 2/2] MIPS/mtd: Handle READY GPIO in generic NAND platform data Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox