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>
Acked-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Tested-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
v2:
- Rebase onto v6.18-rc1
- Use dev_err_probe() to simplify the code
- Fix indentation of patch 1
- Collect Acked-by and Tested-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..063202923d95d 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
+ bool "SpacemiT P1 poweroff and reset driver"
+ depends on ARCH_SPACEMIT || COMPILE_TEST
+ select MFD_SPACEMIT_P1
+ default ARCH_SPACEMIT
+ 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
On Sun, 19 Oct 2025 at 22:34, Aurelien Jarno <aurelien@aurel32.net> 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> > Acked-by: Troy Mitchell <troy.mitchell@linux.spacemit.com> > Tested-by: Troy Mitchell <troy.mitchell@linux.spacemit.com> > --- > v2: > - Rebase onto v6.18-rc1 > - Use dev_err_probe() to simplify the code > - Fix indentation of patch 1 > - Collect Acked-by and Tested-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..063202923d95d 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 > + bool "SpacemiT P1 poweroff and reset driver" The driver code looks to be written to work as a module, but here it says "bool" not "tristate". > + depends on ARCH_SPACEMIT || COMPILE_TEST > + select MFD_SPACEMIT_P1 > + default ARCH_SPACEMIT If it does work as a module I'd prefer "default m" here. /Emil
Hi Emil, On 2025-10-19 22:53, Emil Renner Berthing wrote: > On Sun, 19 Oct 2025 at 22:34, Aurelien Jarno <aurelien@aurel32.net> 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> > > Acked-by: Troy Mitchell <troy.mitchell@linux.spacemit.com> > > Tested-by: Troy Mitchell <troy.mitchell@linux.spacemit.com> > > --- > > v2: > > - Rebase onto v6.18-rc1 > > - Use dev_err_probe() to simplify the code > > - Fix indentation of patch 1 > > - Collect Acked-by and Tested-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..063202923d95d 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 > > + bool "SpacemiT P1 poweroff and reset driver" > > The driver code looks to be written to work as a module, but here it > says "bool" not "tristate". I have just tested to build it as a module, and it indeed works that way. I'll change that to tristate in the next version. > > + depends on ARCH_SPACEMIT || COMPILE_TEST > > + select MFD_SPACEMIT_P1 > > + default ARCH_SPACEMIT > > If it does work as a module I'd prefer "default m" here. Do you mean "default m" or "default m if ARCH_SPACEMIT"? Regards Aurelien -- Aurelien Jarno GPG: 4096R/1DDD8C9B aurelien@aurel32.net http://aurel32.net
Quoting Aurelien Jarno (2025-10-20 06:55:37) > Hi Emil, > > On 2025-10-19 22:53, Emil Renner Berthing wrote: > > On Sun, 19 Oct 2025 at 22:34, Aurelien Jarno <aurelien@aurel32.net> wrote: > > > diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig > > > index 8248895ca9038..063202923d95d 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 > > > + bool "SpacemiT P1 poweroff and reset driver" > > > > The driver code looks to be written to work as a module, but here it > > says "bool" not "tristate". > > I have just tested to build it as a module, and it indeed works that > way. I'll change that to tristate in the next version. > > > > + depends on ARCH_SPACEMIT || COMPILE_TEST > > > + select MFD_SPACEMIT_P1 > > > + default ARCH_SPACEMIT > > > > If it does work as a module I'd prefer "default m" here. > > Do you mean "default m" or "default m if ARCH_SPACEMIT"? Just "default m" should be fine since the driver already depends on ARCH_SPACEMIT, but the 2nd version is more explicit. A quick grep doesn't show an overwhelming majority of one over the other, so I guess it's up to the maintainers. /Emil
On Mon, Oct 20, 2025 at 06:55:37AM +0200, Aurelien Jarno wrote:
> Hi Emil,
>
> On 2025-10-19 22:53, Emil Renner Berthing wrote:
> > On Sun, 19 Oct 2025 at 22:34, Aurelien Jarno <aurelien@aurel32.net> 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>
> > > Acked-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> > > Tested-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> > > ---
> > > v2:
> > > - Rebase onto v6.18-rc1
> > > - Use dev_err_probe() to simplify the code
> > > - Fix indentation of patch 1
> > > - Collect Acked-by and Tested-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..063202923d95d 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
> > > + bool "SpacemiT P1 poweroff and reset driver"
> >
> > The driver code looks to be written to work as a module, but here it
> > says "bool" not "tristate".
>
> I have just tested to build it as a module, and it indeed works that
> way. I'll change that to tristate in the next version.
>
> > > + depends on ARCH_SPACEMIT || COMPILE_TEST
> > > + select MFD_SPACEMIT_P1
> > > + default ARCH_SPACEMIT
> >
> > If it does work as a module I'd prefer "default m" here.
>
> Do you mean "default m" or "default m if ARCH_SPACEMIT"?
I think it's "default m if ARCH_SPACEMIT".
because only SpacemiT uses P1.
- Troy
>
> Regards
> Aurelien
>
> --
> Aurelien Jarno GPG: 4096R/1DDD8C9B
> aurelien@aurel32.net http://aurel32.net
>
Hi Aurelien, On 22:53 Sun 19 Oct , Emil Renner Berthing wrote: > On Sun, 19 Oct 2025 at 22:34, Aurelien Jarno <aurelien@aurel32.net> 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> > > Acked-by: Troy Mitchell <troy.mitchell@linux.spacemit.com> > > Tested-by: Troy Mitchell <troy.mitchell@linux.spacemit.com> > > --- > > v2: > > - Rebase onto v6.18-rc1 > > - Use dev_err_probe() to simplify the code > > - Fix indentation of patch 1 > > - Collect Acked-by and Tested-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..063202923d95d 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 > > + bool "SpacemiT P1 poweroff and reset driver" > > The driver code looks to be written to work as a module, but here it > says "bool" not "tristate". > > > + depends on ARCH_SPACEMIT || COMPILE_TEST > > + select MFD_SPACEMIT_P1 > > + default ARCH_SPACEMIT > > If it does work as a module I'd prefer "default m" here. > I second this, you can add my RoB if with it fixed Reviewed-by: Yixun Lan <dlan@gentoo.org> -- Yixun Lan (dlan)
© 2016 - 2026 Red Hat, Inc.