summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorLinus Walleij <linusw@kernel.org>2026-03-28 16:55:47 +0100
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>2026-04-13 15:41:56 +0200
commit42671e9c1e40032f982d2163ba4867dc85e23832 (patch)
tree5683e253f2455d2d203f6af6f2a8161478d81ad1 /drivers
parentf992846d0b45691a02d0a9775c5c2a50956e62a5 (diff)
downloadlwn-42671e9c1e40032f982d2163ba4867dc85e23832.tar.gz
lwn-42671e9c1e40032f982d2163ba4867dc85e23832.zip
MIPS/input: Move RB532 button to GPIO descriptors
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> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/input/misc/rb532_button.c35
1 files changed, 29 insertions, 6 deletions
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;
}