[PATCH v21 03/13] power: reset: reboot-mode: Add support for predefined reboot modes

Shivendra Pratap
2026-04-27T17:35:46Z

reboot-mode based drivers can define a reboot-mode by adding it under
the reboot-mode node in device tree. This limits such drivers, to define
any predefined reboot-modes statically within the driver and creates a
dependency on device-tree.

Introduce a list for predefined modes in the reboot-mode framework and
process the predefined reboot-modes along with the device-tree defined
reboot-modes. Modify existing reboot-mode based drivers to initialize
the predefined list-head as empty.

This patch enables a reboot mode driver to define reboot-modes through a
predefined static list, in addition to the device-tree based reboot-modes.

Signed-off-by: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
---
drivers/power/reset/nvmem-reboot-mode.c | 1 +
drivers/power/reset/qcom-pon.c | 1 +
drivers/power/reset/reboot-mode.c | 66 ++++++++++++++++++++------------
drivers/power/reset/syscon-reboot-mode.c | 1 +
include/linux/reboot-mode.h | 8 ++++
5 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/drivers/power/reset/nvmem-reboot-mode.c b/drivers/power/reset/nvmem-reboot-mode.c
index bd05d660490c686b43134f82f1eadd7665403d20..83a8d80fd7d1ccb1b736aee5f2d675246a63b8f8 100644
--- a/drivers/power/reset/nvmem-reboot-mode.c
+++ b/drivers/power/reset/nvmem-reboot-mode.c
@@ -53,6 +53,7 @@ static int nvmem_reboot_mode_probe(struct platform_device *pdev)

nvmem_rbm->reboot.dev = &pdev->dev;
nvmem_rbm->reboot.write = nvmem_reboot_mode_write;
+ INIT_LIST_HEAD(&nvmem_rbm->reboot.predefined_modes);

nvmem_rbm->cell = devm_nvmem_cell_get(&pdev->dev, "reboot-mode");
if (IS_ERR(nvmem_rbm->cell)) {
diff --git a/drivers/power/reset/qcom-pon.c b/drivers/power/reset/qcom-pon.c
index 57b36e6186f80aff947fd7f5aae5ce280c65dc6b..9d0e3fc621a6173438c6da4cce38394199451881 100644
--- a/drivers/power/reset/qcom-pon.c
+++ b/drivers/power/reset/qcom-pon.c
@@ -73,6 +73,7 @@ static int qcom_pon_probe(struct platform_device *pdev)
pon->reboot_mode.dev = &pdev->dev;
pon->reason_shift = reason_shift;
pon->reboot_mode.write = qcom_pon_reboot_mode_write;
+ INIT_LIST_HEAD(&pon->reboot_mode.predefined_modes);
error = devm_reboot_mode_register(&pdev->dev, &pon->reboot_mode);
if (error) {
dev_err(&pdev->dev, "can't register reboot mode\n");
diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
index f1372dc700e48043320812c3d3619ab1539e1854..a84f7c67a4746d4d5c932d4df018aae10bd5518c 100644
--- a/drivers/power/reset/reboot-mode.c
+++ b/drivers/power/reset/reboot-mode.c
@@ -20,12 +20,6 @@

#define PREFIX "mode-"

-struct mode_info {
- const char *mode;
- u64 magic;
- struct list_head list;
-};
-
struct reboot_mode_sysfs_data {
struct device *reboot_mode_device;
struct list_head head;
@@ -116,6 +110,33 @@ static int reboot_mode_notify(struct notifier_block *this,
return NOTIFY_DONE;
}

+static int reboot_mode_add_mode(struct reboot_mode_driver *reboot,
+ const char *mode, u64 magic,
+ const char *name)
+{
+ struct mode_info *info;
+
+ if (!mode || mode[0] == '\0') {
+ pr_err("invalid mode name(%s): too short!\n", name);
+ return -EINVAL;
+ }
+
+ info = kzalloc_obj(*info, GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
+
+ info->mode = kstrdup_const(mode, GFP_KERNEL);
+ if (!info->mode) {
+ kfree(info);
+ return -ENOMEM;
+ }
+
+ info->magic = magic;
+ list_add_tail(&info->list, &reboot->head);
+
+ return 0;
+}
+
static int reboot_mode_create_device(struct reboot_mode_driver *reboot)
{
struct reboot_mode_sysfs_data *priv;
@@ -180,9 +201,11 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)

INIT_LIST_HEAD(&reboot->head);

+ if (!np)
+ goto predefined_modes;
+
for_each_property_of_node(np, prop) {
memset(magic, 0, sizeof(magic));
-
if (strncmp(prop->name, PREFIX, len))
continue;

@@ -194,26 +217,20 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
continue;
}

- info = kzalloc(sizeof(*info), GFP_KERNEL);
- if (!info) {
- ret = -ENOMEM;
+ ret = reboot_mode_add_mode(reboot, prop->name + len,
+ REBOOT_MODE_MAGIC(magic[0], magic[1]),
+ prop->name);
+ if (ret)
goto error;
- }
+ }

- info->magic = REBOOT_MODE_MAGIC(magic[0], magic[1]);
- info->mode = kstrdup_const(prop->name + len, GFP_KERNEL);
- if (!info->mode) {
- ret = -ENOMEM;
+predefined_modes:
+ list_for_each_entry(info, &reboot->predefined_modes, list) {
+ ret = reboot_mode_add_mode(reboot, info->mode,
+ info->magic,
+ info->mode);
+ if (ret)
goto error;
- } else if (info->mode[0] == '\0') {
- kfree_const(info->mode);
- ret = -EINVAL;
- pr_err("invalid mode name(%s): too short!\n", prop->name);
- goto error;
- }
-
- list_add_tail(&info->list, &reboot->head);
- info = NULL;
}

reboot->reboot_notifier.notifier_call = reboot_mode_notify;
@@ -226,7 +243,6 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
return 0;

error:
- kfree(info);
reboot_mode_unregister(reboot);
return ret;
}
diff --git a/drivers/power/reset/syscon-reboot-mode.c b/drivers/power/reset/syscon-reboot-mode.c
index 9f4b18c5e46f6a8bf197773ceceb80b250f57541..0218b71541a0cefe1534e306f956ae51ea9ee870 100644
--- a/drivers/power/reset/syscon-reboot-mode.c
+++ b/drivers/power/reset/syscon-reboot-mode.c
@@ -48,6 +48,7 @@ static int syscon_reboot_mode_probe(struct platform_device *pdev)
syscon_rbm->reboot.dev = &pdev->dev;
syscon_rbm->reboot.write = syscon_reboot_mode_write;
syscon_rbm->mask = 0xffffffff;
+ INIT_LIST_HEAD(&syscon_rbm->reboot.predefined_modes);

syscon_rbm->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
if (IS_ERR(syscon_rbm->map))
diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
index 2ce189fdfff4b396d7cc6f175b30016781ae4fe9..f4518528fcc1fac49209de91cec7e050088ef8ec 100644
--- a/include/linux/reboot-mode.h
+++ b/include/linux/reboot-mode.h
@@ -15,9 +15,17 @@
/* Get 32 bit arg2 from 64 bit magic */
#define REBOOT_MODE_ARG2(magic) FIELD_GET(GENMASK_ULL(63, 32), magic)

+struct mode_info {
+ const char *mode;
+ u64 magic;
+ struct list_head list;
+};
+
struct reboot_mode_driver {
struct device *dev;
struct list_head head;
+ /* List of predefined reboot-modes, a reboot-mode-driver may populate. */
+ struct list_head predefined_modes;
int (*write)(struct reboot_mode_driver *reboot, u64 magic);
struct notifier_block reboot_notifier;
};

--
2.34.1