113 lines
3.3 KiB
Diff
113 lines
3.3 KiB
Diff
From 1c8a28a552950fa3b4180c1e86e76e0ddcb140f8 Mon Sep 17 00:00:00 2001
|
|
From: Teguh Sobirin <[email protected]>
|
|
Date: Mon, 21 Apr 2025 18:16:35 +0800
|
|
Subject: [PATCH] input: RSInput: Add regulator
|
|
|
|
Signed-off-by: Teguh Sobirin <[email protected]>
|
|
---
|
|
drivers/input/joystick/rsinput.c | 48 ++++++++++++++++++++------------
|
|
1 file changed, 30 insertions(+), 18 deletions(-)
|
|
|
|
diff --git a/drivers/input/joystick/rsinput.c b/drivers/input/joystick/rsinput.c
|
|
index 4a70964077129b..12ba7a99422fda 100644
|
|
--- a/drivers/input/joystick/rsinput.c
|
|
+++ b/drivers/input/joystick/rsinput.c
|
|
@@ -5,8 +5,6 @@
|
|
* Copyright (C) 2024 Teguh Sobirin <[email protected]>
|
|
*
|
|
*/
|
|
-#define DEBUG
|
|
-
|
|
#include <linux/errno.h>
|
|
#include <linux/gpio/consumer.h>
|
|
#include <linux/init.h>
|
|
@@ -14,6 +12,7 @@
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
+#include <linux/regulator/consumer.h>
|
|
#include <linux/serdev.h>
|
|
#include <linux/slab.h>
|
|
#include <uapi/linux/sched/types.h>
|
|
@@ -55,6 +54,7 @@
|
|
struct rsinput_driver {
|
|
struct serdev_device *serdev;
|
|
struct input_dev *input;
|
|
+ struct regulator *vdd;
|
|
struct gpio_desc *boot_gpio;
|
|
struct gpio_desc *enable_gpio;
|
|
struct gpio_desc *reset_gpio;
|
|
@@ -111,7 +111,22 @@ static int rsinput_send_command(struct rsinput_driver *drv, uint8_t cmd, const u
|
|
static int rsinput_init_commands(struct rsinput_driver *drv) {
|
|
int error;
|
|
|
|
+ if (drv->boot_gpio)
|
|
+ gpiod_set_value_cansleep(drv->boot_gpio, 0);
|
|
+
|
|
+ if (drv->reset_gpio)
|
|
+ gpiod_set_value_cansleep(drv->reset_gpio, 0);
|
|
+
|
|
+ msleep(100);
|
|
+
|
|
+ if (drv->enable_gpio)
|
|
+ gpiod_set_value_cansleep(drv->enable_gpio, 1);
|
|
+
|
|
+ if (drv->reset_gpio)
|
|
+ gpiod_set_value_cansleep(drv->reset_gpio, 1);
|
|
+
|
|
msleep(100);
|
|
+
|
|
uint8_t version_request[] = {DATA_COMMOD_VERSION};
|
|
error = rsinput_send_command(drv, CMD_COMMOD, version_request, sizeof(version_request));
|
|
if (error < 0) {
|
|
@@ -284,6 +299,17 @@ static int rsinput_probe(struct serdev_device *serdev) {
|
|
if (!drv)
|
|
return -ENOMEM;
|
|
|
|
+ drv->vdd = devm_regulator_get(&serdev->dev, "vdd");
|
|
+ if (IS_ERR(drv->vdd)) {
|
|
+ error = PTR_ERR(drv->vdd);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ error = regulator_enable(drv->vdd);
|
|
+ if (error < 0) {
|
|
+ return error;
|
|
+ }
|
|
+
|
|
drv->boot_gpio =
|
|
devm_gpiod_get_optional(&serdev->dev, "boot", GPIOD_OUT_HIGH);
|
|
if (IS_ERR(drv->boot_gpio)) {
|
|
@@ -305,22 +331,6 @@ static int rsinput_probe(struct serdev_device *serdev) {
|
|
dev_warn(&serdev->dev, "Unable to get reset gpio: %d\n", error);
|
|
}
|
|
|
|
- if (drv->boot_gpio)
|
|
- gpiod_set_value_cansleep(drv->boot_gpio, 0);
|
|
-
|
|
- if (drv->reset_gpio)
|
|
- gpiod_set_value_cansleep(drv->reset_gpio, 0);
|
|
-
|
|
- msleep(100);
|
|
-
|
|
- if (drv->enable_gpio)
|
|
- gpiod_set_value_cansleep(drv->enable_gpio, 1);
|
|
-
|
|
- if (drv->reset_gpio)
|
|
- gpiod_set_value_cansleep(drv->reset_gpio, 1);
|
|
-
|
|
- msleep(100);
|
|
-
|
|
error = serdev_device_open(serdev);
|
|
if (error)
|
|
return dev_err_probe(&serdev->dev, error, "Unable to open UART device\n");
|
|
@@ -394,6 +404,8 @@ static void rsinput_remove(struct serdev_device *serdev) {
|
|
|
|
if (drv->reset_gpio)
|
|
gpiod_set_value_cansleep(drv->reset_gpio, 0);
|
|
+
|
|
+ regulator_disable(drv->vdd);
|
|
}
|
|
|
|
static const struct of_device_id rsinput_of_match[] = {
|