From: Troy Mitchell <troy.mitchell@linux.spacemit.com>
To: Aurelien Jarno <aurelien@aurel32.net>,
linux-kernel@vger.kernel.org, Lee Jones <lee@kernel.org>,
Sebastian Reichel <sre@kernel.org>,
Troy Mitchell <troy.mitchell@linux.spacemit.com>,
Yixun Lan <dlan@gentoo.org>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
"open list:RISC-V ARCHITECTURE:Keyword:riscv"
<linux-riscv@lists.infradead.org>,
"open list:RISC-V SPACEMIT SoC Support:Keyword:spacemit"
<spacemit@lists.linux.dev>,
"open list:SYSTEM RESET/SHUTDOWN DRIVERS"
<linux-pm@vger.kernel.org>
Subject: Re: [PATCH v4 1/2] driver: reset: spacemit-p1: add driver for poweroff/reboot
Date: Mon, 27 Oct 2025 11:20:33 +0800 [thread overview]
Message-ID: <A73D83A7055D782E+aP7lAdAk66slv6l7@kernel.org> (raw)
In-Reply-To: <20251026224424.1891541-2-aurelien@aurel32.net>
On Sun, Oct 26, 2025 at 11:41:14PM +0100, Aurelien Jarno wrote:
> This driver implements poweroff/reboot support for the SpacemiT P1 PMIC
> chip, which is commonly paired with the SpacemiT K1 SoC.
>
> The SpacemiT P1 support is implemented as a MFD driver, so the access is
> done directly through the regmap interface. Reboot or poweroff is
> triggered by setting a specific bit in a control register, which is
> automatically cleared by the hardware afterwards.
>
> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
> ---
> v2:
> - Replace the "select" by a "depends on"
> - Remove outdated Reviewed-by
>
> drivers/power/reset/Kconfig | 9 +++
> drivers/power/reset/Makefile | 1 +
> drivers/power/reset/spacemit-p1-reboot.c | 88 ++++++++++++++++++++++++
> 3 files changed, 98 insertions(+)
> create mode 100644 drivers/power/reset/spacemit-p1-reboot.c
>
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index 8248895ca9038..61c16f3d5abc7 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -283,6 +283,15 @@ config POWER_RESET_KEYSTONE
> help
> Reboot support for the KEYSTONE SoCs.
>
> +config POWER_RESET_SPACEMIT_P1
> + tristate "SpacemiT P1 poweroff and reset driver"
> + depends on ARCH_SPACEMIT || COMPILE_TEST
> + depends on MFD_SPACEMIT_P1
> + default m
default m if ARCH_SPACEMIT? Or default ARCH_SPACEMIT?
I believe that reboot and shutdown are actually essential functionalities,
so it might make more sense: default ARCH_SPACEMIT?
- Troy
> + help
> + This driver supports power-off and reset operations for the SpacemiT
> + P1 PMIC.
> +
> config POWER_RESET_SYSCON
> bool "Generic SYSCON regmap reset driver"
> depends on OF
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index 51da87e05ce76..0e4ae6f6b5c55 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -24,6 +24,7 @@ obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o
> obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
> obj-$(CONFIG_POWER_RESET_REGULATOR) += regulator-poweroff.o
> obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o
> +obj-$(CONFIG_POWER_RESET_SPACEMIT_P1) += spacemit-p1-reboot.o
> obj-$(CONFIG_POWER_RESET_ST) += st-poweroff.o
> obj-$(CONFIG_POWER_RESET_TH1520_AON) += th1520-aon-reboot.o
> obj-$(CONFIG_POWER_RESET_TORADEX_EC) += tdx-ec-poweroff.o
> diff --git a/drivers/power/reset/spacemit-p1-reboot.c b/drivers/power/reset/spacemit-p1-reboot.c
> new file mode 100644
> index 0000000000000..9ec3d1fff8f3d
> --- /dev/null
> +++ b/drivers/power/reset/spacemit-p1-reboot.c
> @@ -0,0 +1,88 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2025 by Aurelien Jarno
> + */
> +
> +#include <linux/bits.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/reboot.h>
> +
> +/* Power Control Register 2 */
> +#define PWR_CTRL2 0x7e
> +#define PWR_CTRL2_SHUTDOWN BIT(2) /* Shutdown request */
> +#define PWR_CTRL2_RST BIT(1) /* Reset request */
> +
> +static int spacemit_p1_pwroff_handler(struct sys_off_data *data)
> +{
> + struct regmap *regmap = data->cb_data;
> + int ret;
> +
> + /* Put the PMIC into shutdown state */
> + ret = regmap_set_bits(regmap, PWR_CTRL2, PWR_CTRL2_SHUTDOWN);
> + if (ret) {
> + dev_err(data->dev, "shutdown failed: %d\n", ret);
> + return notifier_from_errno(ret);
> + }
> +
> + return NOTIFY_DONE;
> +}
> +
> +static int spacemit_p1_restart_handler(struct sys_off_data *data)
> +{
> + struct regmap *regmap = data->cb_data;
> + int ret;
> +
> + /* Put the PMIC into reset state */
> + ret = regmap_set_bits(regmap, PWR_CTRL2, PWR_CTRL2_RST);
> + if (ret) {
> + dev_err(data->dev, "restart failed: %d\n", ret);
> + return notifier_from_errno(ret);
> + }
> +
> + return NOTIFY_DONE;
> +}
> +
> +static int spacemit_p1_reboot_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct regmap *regmap;
> + int ret;
> +
> + regmap = dev_get_regmap(dev->parent, NULL);
> + if (!regmap)
> + return -ENODEV;
> +
> + ret = devm_register_power_off_handler(dev, &spacemit_p1_pwroff_handler,
> + regmap);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Failed to register power off handler\n");
> +
> + ret = devm_register_restart_handler(dev, spacemit_p1_restart_handler,
> + regmap);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Failed to register restart handler\n");
> +
> + return 0;
> +}
> +
> +static const struct platform_device_id spacemit_p1_reboot_id_table[] = {
> + { "spacemit-p1-reboot", },
> + { /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(platform, spacemit_p1_reboot_id_table);
> +
> +static struct platform_driver spacemit_p1_reboot_driver = {
> + .driver = {
> + .name = "spacemit-p1-reboot",
> + },
> + .probe = spacemit_p1_reboot_probe,
> + .id_table = spacemit_p1_reboot_id_table,
> +};
> +module_platform_driver(spacemit_p1_reboot_driver);
> +
> +MODULE_DESCRIPTION("SpacemiT P1 reboot/poweroff driver");
> +MODULE_LICENSE("GPL");
> --
> 2.47.2
>
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-10-27 3:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-26 22:41 [PATCH v4 0/2] driver: reset: spacemit-p1: add driver for poweroff/reboot Aurelien Jarno
2025-10-26 22:41 ` [PATCH v4 1/2] " Aurelien Jarno
2025-10-27 3:20 ` Troy Mitchell [this message]
2025-10-27 6:01 ` Aurelien Jarno
2025-10-27 6:06 ` Troy Mitchell
2025-10-27 6:24 ` Yao Zi
2025-10-27 9:03 ` Andreas Schwab
2025-10-27 9:24 ` Yao Zi
2025-10-27 10:17 ` Emil Renner Berthing
2025-10-27 10:31 ` Yixun Lan
2025-10-27 13:34 ` Aurelien Jarno
2025-10-27 13:56 ` Troy Mitchell
2025-10-26 22:41 ` [PATCH v4 2/2] mfd: simple-mfd-i2c: add a reboot cell for the SpacemiT P1 chip Aurelien Jarno
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=A73D83A7055D782E+aP7lAdAk66slv6l7@kernel.org \
--to=troy.mitchell@linux.spacemit.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=aurelien@aurel32.net \
--cc=dlan@gentoo.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=spacemit@lists.linux.dev \
--cc=sre@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox