[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250721-arm-psci-system_reset2-vendor-reboots-v12-1-87bac3ec422e@oss.qualcomm.com>
Date: Mon, 21 Jul 2025 23:58:48 +0530
From: Shivendra Pratap <shivendra.pratap@....qualcomm.com>
To: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>,
Bjorn Andersson <andersson@...nel.org>,
Sebastian Reichel <sre@...nel.org>, Rob Herring <robh@...nel.org>,
Sudeep Holla <sudeep.holla@....com>,
Souvik Chakravarty <Souvik.Chakravarty@....com>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Andy Yan <andy.yan@...k-chips.com>,
Mark Rutland <mark.rutland@....com>,
Lorenzo Pieralisi <lpieralisi@...nel.org>,
Arnd Bergmann <arnd@...db.de>, Konrad Dybcio <konradybcio@...nel.org>,
cros-qcom-dts-watchers@...omium.org, Vinod Koul <vkoul@...nel.org>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
Florian Fainelli <florian.fainelli@...adcom.com>
Cc: Dmitry Baryshkov <dmitry.baryshkov@....qualcomm.com>,
Mukesh Ojha <mukesh.ojha@....qualcomm.com>,
Stephen Boyd <swboyd@...omium.org>,
Andre Draszik <andre.draszik@...aro.org>, linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org, devicetree@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-arm-msm@...r.kernel.org,
Elliot Berman <quic_eberman@...cinc.com>,
Shivendra Pratap <shivendra.pratap@....qualcomm.com>,
Srinivas Kandagatla <srini@...nel.org>
Subject: [PATCH v12 1/8] power: reset: reboot-mode: Add device tree
node-based registration
The reboot-mode driver does not have a strict requirement for
device-based registration. It primarily uses the device's of_node
to read mode-<cmd> properties and the device pointer for logging.
Remove the dependency on struct device and introduce support for
Device Tree (DT) node-based registration. This enables drivers
that are not associated with a struct device to leverage the
reboot-mode framework.
Signed-off-by: Shivendra Pratap <shivendra.pratap@....qualcomm.com>
---
drivers/power/reset/reboot-mode.c | 45 +++++++++++++++++++++++++++++----------
include/linux/reboot-mode.h | 6 +++++-
2 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
index fba53f638da04655e756b5f8b7d2d666d1379535..5dd3f06ca88cb28606d9fd2100ce03383c14d215 100644
--- a/drivers/power/reset/reboot-mode.c
+++ b/drivers/power/reset/reboot-mode.c
@@ -3,13 +3,17 @@
* Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd
*/
+#define pr_fmt(fmt) "reboot-mode: " fmt
+
#include <linux/device.h>
#include <linux/init.h>
#include <linux/kernel.h>
+#include <linux/list.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/reboot.h>
#include <linux/reboot-mode.h>
+#include <linux/slab.h>
#define PREFIX "mode-"
@@ -55,7 +59,9 @@ static int reboot_mode_notify(struct notifier_block *this,
unsigned int magic;
reboot = container_of(this, struct reboot_mode_driver, reboot_notifier);
+ mutex_lock(&reboot->rb_lock);
magic = get_reboot_mode_magic(reboot, cmd);
+ mutex_unlock(&reboot->rb_lock);
if (magic)
reboot->write(reboot, magic);
@@ -65,45 +71,51 @@ static int reboot_mode_notify(struct notifier_block *this,
/**
* reboot_mode_register - register a reboot mode driver
* @reboot: reboot mode driver
+ * @np: Pointer to device tree node
*
* Returns: 0 on success or a negative error code on failure.
*/
-int reboot_mode_register(struct reboot_mode_driver *reboot)
+int reboot_mode_register(struct reboot_mode_driver *reboot, struct device_node *np)
{
struct mode_info *info;
+ struct mode_info *next;
struct property *prop;
- struct device_node *np = reboot->dev->of_node;
size_t len = strlen(PREFIX);
int ret;
+ if (!np)
+ return -EINVAL;
+
INIT_LIST_HEAD(&reboot->head);
+ mutex_init(&reboot->rb_lock);
+ mutex_lock(&reboot->rb_lock);
for_each_property_of_node(np, prop) {
if (strncmp(prop->name, PREFIX, len))
continue;
- info = devm_kzalloc(reboot->dev, sizeof(*info), GFP_KERNEL);
+ info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info) {
ret = -ENOMEM;
goto error;
}
if (of_property_read_u32(np, prop->name, &info->magic)) {
- dev_err(reboot->dev, "reboot mode %s without magic number\n",
- info->mode);
- devm_kfree(reboot->dev, info);
+ pr_err("reboot mode %s without magic number\n", info->mode);
+ kfree(info);
continue;
}
info->mode = kstrdup_const(prop->name + len, GFP_KERNEL);
if (!info->mode) {
ret = -ENOMEM;
+ kfree(info);
goto error;
} else if (info->mode[0] == '\0') {
kfree_const(info->mode);
+ kfree(info);
ret = -EINVAL;
- dev_err(reboot->dev, "invalid mode name(%s): too short!\n",
- prop->name);
+ pr_err("invalid mode name(%s): too short!\n", prop->name);
goto error;
}
@@ -113,12 +125,17 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
reboot->reboot_notifier.notifier_call = reboot_mode_notify;
register_reboot_notifier(&reboot->reboot_notifier);
+ mutex_unlock(&reboot->rb_lock);
return 0;
error:
- list_for_each_entry(info, &reboot->head, list)
+ list_for_each_entry_safe(info, next, &reboot->head, list) {
+ list_del(&info->list);
kfree_const(info->mode);
+ kfree(info);
+ }
+ mutex_unlock(&reboot->rb_lock);
return ret;
}
EXPORT_SYMBOL_GPL(reboot_mode_register);
@@ -130,11 +147,17 @@ EXPORT_SYMBOL_GPL(reboot_mode_register);
int reboot_mode_unregister(struct reboot_mode_driver *reboot)
{
struct mode_info *info;
+ struct mode_info *next;
unregister_reboot_notifier(&reboot->reboot_notifier);
- list_for_each_entry(info, &reboot->head, list)
+ mutex_lock(&reboot->rb_lock);
+ list_for_each_entry_safe(info, next, &reboot->head, list) {
+ list_del(&info->list);
kfree_const(info->mode);
+ kfree(info);
+ }
+ mutex_unlock(&reboot->rb_lock);
return 0;
}
@@ -162,7 +185,7 @@ int devm_reboot_mode_register(struct device *dev,
if (!dr)
return -ENOMEM;
- rc = reboot_mode_register(reboot);
+ rc = reboot_mode_register(reboot, reboot->dev->of_node);
if (rc) {
devres_free(dr);
return rc;
diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
index 4a2abb38d1d612ec0fdf05eb18c98b210f631b7f..98f68f95c9e8460be23282c51ef7fcbed73887bd 100644
--- a/include/linux/reboot-mode.h
+++ b/include/linux/reboot-mode.h
@@ -2,14 +2,18 @@
#ifndef __REBOOT_MODE_H__
#define __REBOOT_MODE_H__
+#include <linux/mutex.h>
+
struct reboot_mode_driver {
struct device *dev;
struct list_head head;
int (*write)(struct reboot_mode_driver *reboot, unsigned int magic);
struct notifier_block reboot_notifier;
+ /*Protects access to reboot mode list*/
+ struct mutex rb_lock;
};
-int reboot_mode_register(struct reboot_mode_driver *reboot);
+int reboot_mode_register(struct reboot_mode_driver *reboot, struct device_node *np);
int reboot_mode_unregister(struct reboot_mode_driver *reboot);
int devm_reboot_mode_register(struct device *dev,
struct reboot_mode_driver *reboot);
--
2.34.1
Powered by blists - more mailing lists