Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions drivers/power/reset/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ config NVMEM_REBOOT_MODE
then the bootloader can read it and take different
action according to the mode.

config PSCI_REBOOT_MODE
bool "PSCI reboot mode driver"
depends on OF && ARM_PSCI_FW
select REBOOT_MODE
help
Say y here will enable PSCI reboot mode driver. This gets
the PSCI reboot mode arguments and passes them to psci
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some whitespace issue

driver. psci driver uses these arguments for issuing
device reset into different boot states.

config POWER_MLXBF
tristate "Mellanox BlueField power handling driver"
depends on (GPIO_MLXBF2 || GPIO_MLXBF3) && ACPI
Expand Down
1 change: 1 addition & 0 deletions drivers/power/reset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o
obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o
obj-$(CONFIG_POWER_RESET_SC27XX) += sc27xx-poweroff.o
obj-$(CONFIG_NVMEM_REBOOT_MODE) += nvmem-reboot-mode.o
obj-$(CONFIG_PSCI_REBOOT_MODE) += psci-reboot-mode.o
obj-$(CONFIG_POWER_MLXBF) += pwr-mlxbf.o
92 changes: 92 additions & 0 deletions drivers/power/reset/psci-reboot-mode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
*/

#include <linux/device/faux.h>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like leftover.

#include <linux/device.h>
#include <linux/err.h>
#include <linux/of.h>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't seem to be using this nor err.h

#include <linux/psci.h>
#include <linux/reboot.h>
#include <linux/reboot-mode.h>
#include <linux/types.h>
#include <linux/platform_device.h>
#include <linux/module.h>

/*
* Predefined reboot-modes are defined as per the values
* of enum reboot_mode defined in the kernel: reboot.c.
*/
static struct mode_info psci_resets[] = {
{ .mode = "warm", .magic = REBOOT_WARM},
{ .mode = "soft", .magic = REBOOT_SOFT},
{ .mode = "cold", .magic = REBOOT_COLD},
};

static void psci_reboot_mode_set_predefined_modes(struct reboot_mode_driver *reboot)
{
INIT_LIST_HEAD(&reboot->predefined_modes);
for (u32 i = 0; i < ARRAY_SIZE(psci_resets); i++) {
/* Prepare the magic with arg1 as 0 and arg2 as per pre-defined mode */
psci_resets[i].magic = REBOOT_MODE_MAGIC(0, psci_resets[i].magic);
INIT_LIST_HEAD(&psci_resets[i].list);
list_add_tail(&psci_resets[i].list, &reboot->predefined_modes);
}
}

/*
* arg1 is reset_type(Low 32 bit of magic).
* arg2 is cookie(High 32 bit of magic).
* If reset_type is 0, cookie will be used to decide the reset command.
*/
static int psci_reboot_mode_write(struct reboot_mode_driver *reboot, u64 magic)
{
u32 reset_type = REBOOT_MODE_ARG1(magic);
u32 cookie = REBOOT_MODE_ARG2(magic);

pr_err("DEBUG: PSCI write called");
pr_err("DEBUG: PSCI write called");
pr_err("DEBUG: PSCI write called");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these leftovers from development?

if (reset_type == 0) {
if (cookie == REBOOT_WARM || cookie == REBOOT_SOFT)
psci_set_reset_cmd(true, 0, 0);
else
psci_set_reset_cmd(false, 0, 0);
} else {
psci_set_reset_cmd(true, reset_type, cookie);
}

return NOTIFY_DONE;
}

static int psci_reboot_mode_probe(struct platform_device *pdev)
{
struct reboot_mode_driver *reboot;
int ret;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add struct device *dev = &pdev->dev; for brevity

reboot = devm_kzalloc(&pdev->dev, sizeof(*reboot), GFP_KERNEL);
if (!reboot)
return -ENOMEM;

psci_reboot_mode_set_predefined_modes(reboot);
reboot->write = psci_reboot_mode_write;
reboot->dev = &pdev->dev;

ret = devm_reboot_mode_register(&pdev->dev, reboot);
if (ret) {
dev_err_probe(&pdev->dev, ret, "devm_reboot_mode_register failed %d\n", ret);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return dev_err_probe()

return ret;
}

return 0;
}

static struct platform_driver psci_reboot_mode_driver = {
.probe = psci_reboot_mode_probe,
.driver = {
.name = "psci-reboot-mode",
},
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can drop this newline.

module_platform_driver(psci_reboot_mode_driver);