All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] power: reset: sc27xx: Add SC2730 and reboot support
@ 2025-09-26 16:23 Otto Pflüger
  2025-09-26 16:23 ` [PATCH 1/5] dt-bindings: power: reset: Add SC27xx series PMIC poweroff Otto Pflüger
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Otto Pflüger @ 2025-09-26 16:23 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Lee Jones
  Cc: linux-pm, devicetree, linux-kernel, Otto Pflüger

Implement poweroff and reboot support for the SC2730 PMIC in the
existing driver for the SC27xx series. Add missing device tree bindings
and compatibles.

For some reason, a reboot implementation for SC2731 already exists in
the SPI driver used for communicating with the PMIC
(drivers/spi/spi-sprd-adi.c). This obviously does not belong there, but
it appears that SC2731 has no dedicated reboot registers and requires
triggering the PMIC watchdog for a reboot. Since there is no driver for
the PMIC watchdog yet, keep that code unmodified and only implement
reboot for SC2730 here. Once a watchdog driver is implemented, the
duplicate code for setting the reboot mode can be removed from the SPI
driver.

Signed-off-by: Otto Pflüger <otto.pflueger@abscue.de>
---
Otto Pflüger (5):
      dt-bindings: power: reset: Add SC27xx series PMIC poweroff
      dt-bindings: mfd: sc2731: Reference sprd,sc2731-poweroff
      power: reset: sc27xx: Use devm_register_sys_off_handler
      power: reset: sc27xx: Add support for SC2730 and OF match table
      power: reset: sc27xx: Add reboot support for SC2730

 .../devicetree/bindings/mfd/sprd,sc2731.yaml       |   8 +
 .../bindings/power/reset/sprd,sc2731-poweroff.yaml |  22 +++
 drivers/power/reset/sc27xx-poweroff.c              | 170 +++++++++++++++++++--
 3 files changed, 188 insertions(+), 12 deletions(-)
---
base-commit: 8e2755d7779a95dd61d8997ebce33ff8b1efd3fb
change-id: 20250926-sc2730-reboot-7f39a025547d

Best regards,
-- 
Otto Pflüger <otto.pflueger@abscue.de>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/5] dt-bindings: power: reset: Add SC27xx series PMIC poweroff
  2025-09-26 16:23 [PATCH 0/5] power: reset: sc27xx: Add SC2730 and reboot support Otto Pflüger
@ 2025-09-26 16:23 ` Otto Pflüger
  2025-09-26 16:23 ` [PATCH 2/5] dt-bindings: mfd: sc2731: Reference sprd,sc2731-poweroff Otto Pflüger
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Otto Pflüger @ 2025-09-26 16:23 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Lee Jones
  Cc: linux-pm, devicetree, linux-kernel, Otto Pflüger

Add power off bindings for the Unisoc SC27xx series PMICs, such as
SC2731 and SC2730.

Signed-off-by: Otto Pflüger <otto.pflueger@abscue.de>
---
 .../bindings/power/reset/sprd,sc2731-poweroff.yaml | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/Documentation/devicetree/bindings/power/reset/sprd,sc2731-poweroff.yaml b/Documentation/devicetree/bindings/power/reset/sprd,sc2731-poweroff.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..2db8bee47e17863b9a0d7af4945d3c32e67122ce
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/reset/sprd,sc2731-poweroff.yaml
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/reset/sprd,sc2731-poweroff.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc SC27xx series PMIC power off
+
+maintainers:
+  - Otto Pflüger <otto.pflueger@abscue.de>
+
+properties:
+  compatible:
+    enum:
+      - sprd,sc2730-poweroff
+      - sprd,sc2731-poweroff
+
+required:
+  - compatible
+
+additionalProperties: false
+...

-- 
2.50.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/5] dt-bindings: mfd: sc2731: Reference sprd,sc2731-poweroff
  2025-09-26 16:23 [PATCH 0/5] power: reset: sc27xx: Add SC2730 and reboot support Otto Pflüger
  2025-09-26 16:23 ` [PATCH 1/5] dt-bindings: power: reset: Add SC27xx series PMIC poweroff Otto Pflüger
@ 2025-09-26 16:23 ` Otto Pflüger
  2025-10-02  2:53   ` Rob Herring
  2025-09-26 16:23 ` [PATCH 3/5] power: reset: sc27xx: Use devm_register_sys_off_handler Otto Pflüger
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Otto Pflüger @ 2025-09-26 16:23 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Lee Jones
  Cc: linux-pm, devicetree, linux-kernel, Otto Pflüger

Reference the new sprd,sc2731-poweroff bindings and add an example.

Signed-off-by: Otto Pflüger <otto.pflueger@abscue.de>
---
 Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml b/Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml
index b023e1ef8d3ccdb1d82d64ed1a60d5a712a1b910..a78d7e26b3a2c77b84da84fc23e52f3a22ab14df 100644
--- a/Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml
+++ b/Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml
@@ -52,6 +52,10 @@ properties:
   '#size-cells':
     const: 0
 
+  poweroff:
+    type: object
+    $ref: /schemas/power/reset/sprd,sc2731-poweroff.yaml#
+
   regulators:
     type: object
     $ref: /schemas/regulator/sprd,sc2731-regulator.yaml#
@@ -221,6 +225,10 @@ examples:
           reg = <0xec8>;
         };
 
+        poweroff {
+          compatible = "sprd,sc2731-poweroff";
+        };
+
         regulators {
           compatible = "sprd,sc2731-regulator";
 

-- 
2.50.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/5] power: reset: sc27xx: Use devm_register_sys_off_handler
  2025-09-26 16:23 [PATCH 0/5] power: reset: sc27xx: Add SC2730 and reboot support Otto Pflüger
  2025-09-26 16:23 ` [PATCH 1/5] dt-bindings: power: reset: Add SC27xx series PMIC poweroff Otto Pflüger
  2025-09-26 16:23 ` [PATCH 2/5] dt-bindings: mfd: sc2731: Reference sprd,sc2731-poweroff Otto Pflüger
@ 2025-09-26 16:23 ` Otto Pflüger
  2025-09-30  3:23   ` Baolin Wang
  2025-09-26 16:23 ` [PATCH 4/5] power: reset: sc27xx: Add support for SC2730 and OF match table Otto Pflüger
  2025-09-26 16:23 ` [PATCH 5/5] power: reset: sc27xx: Add reboot support for SC2730 Otto Pflüger
  4 siblings, 1 reply; 12+ messages in thread
From: Otto Pflüger @ 2025-09-26 16:23 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Lee Jones
  Cc: linux-pm, devicetree, linux-kernel, Otto Pflüger

Use the new device life-cycle managed register function to remove the
need for global variables in the driver.

Signed-off-by: Otto Pflüger <otto.pflueger@abscue.de>
---
 drivers/power/reset/sc27xx-poweroff.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/power/reset/sc27xx-poweroff.c b/drivers/power/reset/sc27xx-poweroff.c
index 90287c31992c4889f9241e82a21a1949ecca7702..20eb9f32cb2b99adeb16502172adf9d6257cd05f 100644
--- a/drivers/power/reset/sc27xx-poweroff.c
+++ b/drivers/power/reset/sc27xx-poweroff.c
@@ -9,6 +9,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/syscore_ops.h>
 
@@ -17,8 +18,6 @@
 #define SC27XX_SLP_CTRL		0xdf0
 #define SC27XX_LDO_XTL_EN	BIT(3)
 
-static struct regmap *regmap;
-
 /*
  * On Spreadtrum platform, we need power off system through external SC27xx
  * series PMICs, and it is one similar SPI bus mapped by regmap to access PMIC,
@@ -44,26 +43,37 @@ static struct syscore_ops poweroff_syscore_ops = {
 	.shutdown = sc27xx_poweroff_shutdown,
 };
 
-static void sc27xx_poweroff_do_poweroff(void)
+static int sc27xx_poweroff_do_poweroff(struct sys_off_data *off_data)
 {
+	struct regmap *regmap = off_data->cb_data;
+
 	/* Disable the external subsys connection's power firstly */
 	regmap_write(regmap, SC27XX_SLP_CTRL, SC27XX_LDO_XTL_EN);
 
 	regmap_write(regmap, SC27XX_PWR_PD_HW, SC27XX_PWR_OFF_EN);
+
+	mdelay(1000);
+
+	pr_emerg("Unable to poweroff system\n");
+
+	return NOTIFY_DONE;
 }
 
 static int sc27xx_poweroff_probe(struct platform_device *pdev)
 {
-	if (regmap)
-		return -EINVAL;
+	struct regmap *regmap;
 
 	regmap = dev_get_regmap(pdev->dev.parent, NULL);
 	if (!regmap)
 		return -ENODEV;
 
-	pm_power_off = sc27xx_poweroff_do_poweroff;
 	register_syscore_ops(&poweroff_syscore_ops);
-	return 0;
+
+	return devm_register_sys_off_handler(&pdev->dev,
+					     SYS_OFF_MODE_POWER_OFF,
+					     SYS_OFF_PRIO_DEFAULT,
+					     sc27xx_poweroff_do_poweroff,
+					     regmap);
 }
 
 static struct platform_driver sc27xx_poweroff_driver = {

-- 
2.50.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/5] power: reset: sc27xx: Add support for SC2730 and OF match table
  2025-09-26 16:23 [PATCH 0/5] power: reset: sc27xx: Add SC2730 and reboot support Otto Pflüger
                   ` (2 preceding siblings ...)
  2025-09-26 16:23 ` [PATCH 3/5] power: reset: sc27xx: Use devm_register_sys_off_handler Otto Pflüger
@ 2025-09-26 16:23 ` Otto Pflüger
  2025-09-30  3:30   ` Baolin Wang
  2025-09-26 16:23 ` [PATCH 5/5] power: reset: sc27xx: Add reboot support for SC2730 Otto Pflüger
  4 siblings, 1 reply; 12+ messages in thread
From: Otto Pflüger @ 2025-09-26 16:23 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Lee Jones
  Cc: linux-pm, devicetree, linux-kernel, Otto Pflüger

Add register definitions for the SC2730 PMIC. Introduce a new struct
sc27xx_poweroff_data for passing register information to the poweroff
handler. Implement device tree matching to distinguish between SC2730
and SC2731 and to probe the driver automatically.

Signed-off-by: Otto Pflüger <otto.pflueger@abscue.de>
---
 drivers/power/reset/sc27xx-poweroff.c | 67 +++++++++++++++++++++++++++++------
 1 file changed, 57 insertions(+), 10 deletions(-)

diff --git a/drivers/power/reset/sc27xx-poweroff.c b/drivers/power/reset/sc27xx-poweroff.c
index 20eb9f32cb2b99adeb16502172adf9d6257cd05f..5937f40021817ea38453705fcef6485ce79ac14c 100644
--- a/drivers/power/reset/sc27xx-poweroff.c
+++ b/drivers/power/reset/sc27xx-poweroff.c
@@ -7,16 +7,33 @@
 #include <linux/cpu.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/syscore_ops.h>
 
-#define SC27XX_PWR_PD_HW	0xc2c
+#define SC2730_PWR_PD_HW	0x1820
+#define SC2730_SLP_CTRL		0x1a48
+#define SC2730_LDO_XTL_EN	BIT(2)
+
+#define SC2731_PWR_PD_HW	0xc2c
+#define SC2731_SLP_CTRL		0xdf0
+#define SC2731_LDO_XTL_EN	BIT(3)
+
 #define SC27XX_PWR_OFF_EN	BIT(0)
-#define SC27XX_SLP_CTRL		0xdf0
-#define SC27XX_LDO_XTL_EN	BIT(3)
+
+struct sc27xx_poweroff_reg_info {
+	u32 poweroff_reg;
+	u32 slp_ctrl_reg;
+	u32 ldo_xtl_en;
+};
+
+struct sc27xx_poweroff_data {
+	struct regmap *regmap;
+	const struct sc27xx_poweroff_reg_info *regs;
+};
 
 /*
  * On Spreadtrum platform, we need power off system through external SC27xx
@@ -45,12 +62,14 @@ static struct syscore_ops poweroff_syscore_ops = {
 
 static int sc27xx_poweroff_do_poweroff(struct sys_off_data *off_data)
 {
-	struct regmap *regmap = off_data->cb_data;
+	struct sc27xx_poweroff_data *data = off_data->cb_data;
 
 	/* Disable the external subsys connection's power firstly */
-	regmap_write(regmap, SC27XX_SLP_CTRL, SC27XX_LDO_XTL_EN);
+	regmap_write(data->regmap, data->regs->slp_ctrl_reg,
+		     data->regs->ldo_xtl_en);
 
-	regmap_write(regmap, SC27XX_PWR_PD_HW, SC27XX_PWR_OFF_EN);
+	regmap_write(data->regmap, data->regs->poweroff_reg,
+		     SC27XX_PWR_OFF_EN);
 
 	mdelay(1000);
 
@@ -61,10 +80,18 @@ static int sc27xx_poweroff_do_poweroff(struct sys_off_data *off_data)
 
 static int sc27xx_poweroff_probe(struct platform_device *pdev)
 {
-	struct regmap *regmap;
+	struct sc27xx_poweroff_data *data;
 
-	regmap = dev_get_regmap(pdev->dev.parent, NULL);
-	if (!regmap)
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->regs = of_device_get_match_data(&pdev->dev);
+	if (!data->regs)
+		return -EINVAL;
+
+	data->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!data->regmap)
 		return -ENODEV;
 
 	register_syscore_ops(&poweroff_syscore_ops);
@@ -73,13 +100,33 @@ static int sc27xx_poweroff_probe(struct platform_device *pdev)
 					     SYS_OFF_MODE_POWER_OFF,
 					     SYS_OFF_PRIO_DEFAULT,
 					     sc27xx_poweroff_do_poweroff,
-					     regmap);
+					     data);
 }
 
+static const struct sc27xx_poweroff_reg_info sc2730_pwr_regs = {
+	.poweroff_reg = SC2730_PWR_PD_HW,
+	.slp_ctrl_reg = SC2730_SLP_CTRL,
+	.ldo_xtl_en = SC2730_LDO_XTL_EN,
+};
+
+static const struct sc27xx_poweroff_reg_info sc2731_pwr_regs = {
+	.poweroff_reg = SC2731_PWR_PD_HW,
+	.slp_ctrl_reg = SC2731_SLP_CTRL,
+	.ldo_xtl_en = SC2731_LDO_XTL_EN,
+};
+
+static const struct of_device_id sc27xx_poweroff_of_match[] = {
+	{ .compatible = "sprd,sc2730-poweroff", .data = &sc2730_pwr_regs },
+	{ .compatible = "sprd,sc2731-poweroff", .data = &sc2731_pwr_regs },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, sc27xx_poweroff_of_match);
+
 static struct platform_driver sc27xx_poweroff_driver = {
 	.probe = sc27xx_poweroff_probe,
 	.driver = {
 		.name = "sc27xx-poweroff",
+		.of_match_table = sc27xx_poweroff_of_match,
 	},
 };
 module_platform_driver(sc27xx_poweroff_driver);

-- 
2.50.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/5] power: reset: sc27xx: Add reboot support for SC2730
  2025-09-26 16:23 [PATCH 0/5] power: reset: sc27xx: Add SC2730 and reboot support Otto Pflüger
                   ` (3 preceding siblings ...)
  2025-09-26 16:23 ` [PATCH 4/5] power: reset: sc27xx: Add support for SC2730 and OF match table Otto Pflüger
@ 2025-09-26 16:23 ` Otto Pflüger
  4 siblings, 0 replies; 12+ messages in thread
From: Otto Pflüger @ 2025-09-26 16:23 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Lee Jones
  Cc: linux-pm, devicetree, linux-kernel, Otto Pflüger

Unlike SC2731, the SC2730 PMIC also provides dedicated registers for
resetting the hardware. Use them to implement reboot support.

Signed-off-by: Otto Pflüger <otto.pflueger@abscue.de>
---
 drivers/power/reset/sc27xx-poweroff.c | 89 +++++++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/drivers/power/reset/sc27xx-poweroff.c b/drivers/power/reset/sc27xx-poweroff.c
index 5937f40021817ea38453705fcef6485ce79ac14c..1dfa54675b3e7b8b79212dc9950d97b726dd5acc 100644
--- a/drivers/power/reset/sc27xx-poweroff.c
+++ b/drivers/power/reset/sc27xx-poweroff.c
@@ -18,16 +18,42 @@
 #define SC2730_SLP_CTRL		0x1a48
 #define SC2730_LDO_XTL_EN	BIT(2)
 
+#define SC2730_SOFT_RST_HW	0x1824
+#define SC2730_RST_STATUS	0x1bac
+#define SC2730_SWRST_CTRL0	0x1bf8
+
 #define SC2731_PWR_PD_HW	0xc2c
 #define SC2731_SLP_CTRL		0xdf0
 #define SC2731_LDO_XTL_EN	BIT(3)
 
 #define SC27XX_PWR_OFF_EN	BIT(0)
+#define SC27XX_SOFT_RST_EN	BIT(4)
+#define SC27XX_RESET		BIT(0)
+
+#define HWRST_STATUS_SECURITY		0x02
+#define HWRST_STATUS_RECOVERY		0x20
+#define HWRST_STATUS_NORMAL		0x40
+#define HWRST_STATUS_ALARM		0x50
+#define HWRST_STATUS_SLEEP		0x60
+#define HWRST_STATUS_FASTBOOT		0x30
+#define HWRST_STATUS_SPECIAL		0x70
+#define HWRST_STATUS_PANIC		0x80
+#define HWRST_STATUS_CFTREBOOT		0x90
+#define HWRST_STATUS_AUTODLOADER	0xa0
+#define HWRST_STATUS_IQMODE		0xb0
+#define HWRST_STATUS_SPRDISK		0xc0
+#define HWRST_STATUS_FACTORYTEST	0xe0
+#define HWRST_STATUS_WATCHDOG		0xf0
+#define HWRST_STATUS_MASK		0xf0
 
 struct sc27xx_poweroff_reg_info {
 	u32 poweroff_reg;
 	u32 slp_ctrl_reg;
 	u32 ldo_xtl_en;
+
+	u32 reset_reg;
+	u32 rst_sts_reg;
+	u32 swrst_ctrl_reg;
 };
 
 struct sc27xx_poweroff_data {
@@ -78,9 +104,59 @@ static int sc27xx_poweroff_do_poweroff(struct sys_off_data *off_data)
 	return NOTIFY_DONE;
 }
 
+static int sc27xx_restart(struct sys_off_data *off_data)
+{
+	struct sc27xx_poweroff_data *data = off_data->cb_data;
+	u32 reboot_mode = 0;
+
+	if (!off_data->cmd)
+		reboot_mode = HWRST_STATUS_NORMAL;
+	else if (!strcmp(off_data->cmd, "recovery"))
+		reboot_mode = HWRST_STATUS_RECOVERY;
+	else if (!strcmp(off_data->cmd, "alarm"))
+		reboot_mode = HWRST_STATUS_ALARM;
+	else if (!strcmp(off_data->cmd, "fastsleep"))
+		reboot_mode = HWRST_STATUS_SLEEP;
+	else if (!strcmp(off_data->cmd, "bootloader"))
+		reboot_mode = HWRST_STATUS_FASTBOOT;
+	else if (!strcmp(off_data->cmd, "panic"))
+		reboot_mode = HWRST_STATUS_PANIC;
+	else if (!strcmp(off_data->cmd, "special"))
+		reboot_mode = HWRST_STATUS_SPECIAL;
+	else if (!strcmp(off_data->cmd, "cftreboot"))
+		reboot_mode = HWRST_STATUS_CFTREBOOT;
+	else if (!strcmp(off_data->cmd, "autodloader"))
+		reboot_mode = HWRST_STATUS_AUTODLOADER;
+	else if (!strcmp(off_data->cmd, "iqmode"))
+		reboot_mode = HWRST_STATUS_IQMODE;
+	else if (!strcmp(off_data->cmd, "sprdisk"))
+		reboot_mode = HWRST_STATUS_SPRDISK;
+	else if (!strcmp(off_data->cmd, "tospanic"))
+		reboot_mode = HWRST_STATUS_SECURITY;
+	else if (!strcmp(off_data->cmd, "factorytest"))
+		reboot_mode = HWRST_STATUS_FACTORYTEST;
+	else
+		reboot_mode = HWRST_STATUS_NORMAL;
+
+	regmap_update_bits(data->regmap, data->regs->rst_sts_reg,
+			   HWRST_STATUS_MASK, reboot_mode);
+
+	regmap_set_bits(data->regmap, data->regs->swrst_ctrl_reg,
+			SC27XX_SOFT_RST_EN);
+
+	regmap_write(data->regmap, data->regs->reset_reg, SC27XX_RESET);
+
+	mdelay(1000);
+
+	pr_emerg("Unable to restart system\n");
+
+	return NOTIFY_DONE;
+}
+
 static int sc27xx_poweroff_probe(struct platform_device *pdev)
 {
 	struct sc27xx_poweroff_data *data;
+	int ret;
 
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -96,6 +172,15 @@ static int sc27xx_poweroff_probe(struct platform_device *pdev)
 
 	register_syscore_ops(&poweroff_syscore_ops);
 
+	if (data->regs->reset_reg) {
+		ret = devm_register_sys_off_handler(&pdev->dev,
+						    SYS_OFF_MODE_RESTART,
+						    192, sc27xx_restart,
+						    data);
+		if (ret)
+			return ret;
+	}
+
 	return devm_register_sys_off_handler(&pdev->dev,
 					     SYS_OFF_MODE_POWER_OFF,
 					     SYS_OFF_PRIO_DEFAULT,
@@ -107,6 +192,10 @@ static const struct sc27xx_poweroff_reg_info sc2730_pwr_regs = {
 	.poweroff_reg = SC2730_PWR_PD_HW,
 	.slp_ctrl_reg = SC2730_SLP_CTRL,
 	.ldo_xtl_en = SC2730_LDO_XTL_EN,
+
+	.reset_reg = SC2730_SOFT_RST_HW,
+	.rst_sts_reg = SC2730_RST_STATUS,
+	.swrst_ctrl_reg = SC2730_SWRST_CTRL0,
 };
 
 static const struct sc27xx_poweroff_reg_info sc2731_pwr_regs = {

-- 
2.50.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/5] power: reset: sc27xx: Use devm_register_sys_off_handler
  2025-09-26 16:23 ` [PATCH 3/5] power: reset: sc27xx: Use devm_register_sys_off_handler Otto Pflüger
@ 2025-09-30  3:23   ` Baolin Wang
  0 siblings, 0 replies; 12+ messages in thread
From: Baolin Wang @ 2025-09-30  3:23 UTC (permalink / raw)
  To: Otto Pflüger, Sebastian Reichel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Orson Zhai, Chunyan Zhang,
	Lee Jones
  Cc: linux-pm, devicetree, linux-kernel



On 2025/9/27 00:23, Otto Pflüger wrote:
> Use the new device life-cycle managed register function to remove the
> need for global variables in the driver.
> 
> Signed-off-by: Otto Pflüger <otto.pflueger@abscue.de>
> ---

LGTM. Thanks.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

>   drivers/power/reset/sc27xx-poweroff.c | 24 +++++++++++++++++-------
>   1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/power/reset/sc27xx-poweroff.c b/drivers/power/reset/sc27xx-poweroff.c
> index 90287c31992c4889f9241e82a21a1949ecca7702..20eb9f32cb2b99adeb16502172adf9d6257cd05f 100644
> --- a/drivers/power/reset/sc27xx-poweroff.c
> +++ b/drivers/power/reset/sc27xx-poweroff.c
> @@ -9,6 +9,7 @@
>   #include <linux/module.h>
>   #include <linux/platform_device.h>
>   #include <linux/pm.h>
> +#include <linux/reboot.h>
>   #include <linux/regmap.h>
>   #include <linux/syscore_ops.h>
>   
> @@ -17,8 +18,6 @@
>   #define SC27XX_SLP_CTRL		0xdf0
>   #define SC27XX_LDO_XTL_EN	BIT(3)
>   
> -static struct regmap *regmap;
> -
>   /*
>    * On Spreadtrum platform, we need power off system through external SC27xx
>    * series PMICs, and it is one similar SPI bus mapped by regmap to access PMIC,
> @@ -44,26 +43,37 @@ static struct syscore_ops poweroff_syscore_ops = {
>   	.shutdown = sc27xx_poweroff_shutdown,
>   };
>   
> -static void sc27xx_poweroff_do_poweroff(void)
> +static int sc27xx_poweroff_do_poweroff(struct sys_off_data *off_data)
>   {
> +	struct regmap *regmap = off_data->cb_data;
> +
>   	/* Disable the external subsys connection's power firstly */
>   	regmap_write(regmap, SC27XX_SLP_CTRL, SC27XX_LDO_XTL_EN);
>   
>   	regmap_write(regmap, SC27XX_PWR_PD_HW, SC27XX_PWR_OFF_EN);
> +
> +	mdelay(1000);
> +
> +	pr_emerg("Unable to poweroff system\n");
> +
> +	return NOTIFY_DONE;
>   }
>   
>   static int sc27xx_poweroff_probe(struct platform_device *pdev)
>   {
> -	if (regmap)
> -		return -EINVAL;
> +	struct regmap *regmap;
>   
>   	regmap = dev_get_regmap(pdev->dev.parent, NULL);
>   	if (!regmap)
>   		return -ENODEV;
>   
> -	pm_power_off = sc27xx_poweroff_do_poweroff;
>   	register_syscore_ops(&poweroff_syscore_ops);
> -	return 0;
> +
> +	return devm_register_sys_off_handler(&pdev->dev,
> +					     SYS_OFF_MODE_POWER_OFF,
> +					     SYS_OFF_PRIO_DEFAULT,
> +					     sc27xx_poweroff_do_poweroff,
> +					     regmap);
>   }
>   
>   static struct platform_driver sc27xx_poweroff_driver = {
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/5] power: reset: sc27xx: Add support for SC2730 and OF match table
  2025-09-26 16:23 ` [PATCH 4/5] power: reset: sc27xx: Add support for SC2730 and OF match table Otto Pflüger
@ 2025-09-30  3:30   ` Baolin Wang
  2025-09-30  5:30     ` Otto Pflüger
  0 siblings, 1 reply; 12+ messages in thread
From: Baolin Wang @ 2025-09-30  3:30 UTC (permalink / raw)
  To: Otto Pflüger, Sebastian Reichel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Orson Zhai, Chunyan Zhang,
	Lee Jones
  Cc: linux-pm, devicetree, linux-kernel



On 2025/9/27 00:23, Otto Pflüger wrote:
> Add register definitions for the SC2730 PMIC. Introduce a new struct
> sc27xx_poweroff_data for passing register information to the poweroff
> handler. Implement device tree matching to distinguish between SC2730
> and SC2731 and to probe the driver automatically.
> 
> Signed-off-by: Otto Pflüger <otto.pflueger@abscue.de>
> ---

If I remember correctly, the original driver supported SC2730 and SC2731 
chips. Are you sure the current changes are still needed? Have you 
tested them on the SC2730 chip?


config POWER_RESET_SC27XX
         tristate "Spreadtrum SC27xx PMIC power-off driver"
         depends on MFD_SC27XX_PMIC || COMPILE_TEST
         help
           This driver supports powering off a system through
           Spreadtrum SC27xx series PMICs. The SC27xx series
           PMICs includes the SC2720, SC2721, SC2723, SC2730
           and SC2731 chips.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/5] power: reset: sc27xx: Add support for SC2730 and OF match table
  2025-09-30  3:30   ` Baolin Wang
@ 2025-09-30  5:30     ` Otto Pflüger
  2025-10-14  1:44       ` Baolin Wang
  0 siblings, 1 reply; 12+ messages in thread
From: Otto Pflüger @ 2025-09-30  5:30 UTC (permalink / raw)
  To: Baolin Wang
  Cc: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Orson Zhai, Chunyan Zhang, Lee Jones, linux-pm, devicetree,
	linux-kernel

On Tue, Sep 30, 2025 at 11:30:16AM +0800, Baolin Wang wrote:
> 
> If I remember correctly, the original driver supported SC2730 and SC2731
> chips. Are you sure the current changes are still needed? Have you tested
> them on the SC2730 chip?
> 
> 
> config POWER_RESET_SC27XX
>         tristate "Spreadtrum SC27xx PMIC power-off driver"
>         depends on MFD_SC27XX_PMIC || COMPILE_TEST
>         help
>           This driver supports powering off a system through
>           Spreadtrum SC27xx series PMICs. The SC27xx series
>           PMICs includes the SC2720, SC2721, SC2723, SC2730
>           and SC2731 chips.

The driver was hard-coded to use registers 0xc2c and 0xdf0. SC2730 has
different registers, which were added to the downstream version of the
driver in [1]. I have tested this with a UMS9230 phone which has an
SC2730 PMIC according to the device tree.

[1]: https://github.com/MotorolaMobilityLLC/kernel-sprd/commit/6165e1afe3eba33089fecc86767d47af9ab176d6

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/5] dt-bindings: mfd: sc2731: Reference sprd,sc2731-poweroff
  2025-09-26 16:23 ` [PATCH 2/5] dt-bindings: mfd: sc2731: Reference sprd,sc2731-poweroff Otto Pflüger
@ 2025-10-02  2:53   ` Rob Herring
  0 siblings, 0 replies; 12+ messages in thread
From: Rob Herring @ 2025-10-02  2:53 UTC (permalink / raw)
  To: Otto Pflüger
  Cc: Sebastian Reichel, Krzysztof Kozlowski, Conor Dooley, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Lee Jones, linux-pm, devicetree,
	linux-kernel

On Fri, Sep 26, 2025 at 06:23:24PM +0200, Otto Pflüger wrote:
> Reference the new sprd,sc2731-poweroff bindings and add an example.
> 
> Signed-off-by: Otto Pflüger <otto.pflueger@abscue.de>
> ---
>  Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml b/Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml
> index b023e1ef8d3ccdb1d82d64ed1a60d5a712a1b910..a78d7e26b3a2c77b84da84fc23e52f3a22ab14df 100644
> --- a/Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml
> +++ b/Documentation/devicetree/bindings/mfd/sprd,sc2731.yaml
> @@ -52,6 +52,10 @@ properties:
>    '#size-cells':
>      const: 0
>  
> +  poweroff:
> +    type: object
> +    $ref: /schemas/power/reset/sprd,sc2731-poweroff.yaml#

You don't need a child node here as there's no DT resources. Just make 
the parent node the power off provider.

IOW, a node with only a compatible property is pretty much always wrong 
(though yes, you can find examples).

> +
>    regulators:
>      type: object
>      $ref: /schemas/regulator/sprd,sc2731-regulator.yaml#
> @@ -221,6 +225,10 @@ examples:
>            reg = <0xec8>;
>          };
>  
> +        poweroff {
> +          compatible = "sprd,sc2731-poweroff";
> +        };
> +
>          regulators {
>            compatible = "sprd,sc2731-regulator";
>  
> 
> -- 
> 2.50.0
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/5] power: reset: sc27xx: Add support for SC2730 and OF match table
  2025-09-30  5:30     ` Otto Pflüger
@ 2025-10-14  1:44       ` Baolin Wang
  2025-10-14  6:10         ` Otto Pflüger
  0 siblings, 1 reply; 12+ messages in thread
From: Baolin Wang @ 2025-10-14  1:44 UTC (permalink / raw)
  To: Otto Pflüger
  Cc: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Orson Zhai, Chunyan Zhang, Lee Jones, linux-pm, devicetree,
	linux-kernel



On 2025/9/30 13:30, Otto Pflüger wrote:
> On Tue, Sep 30, 2025 at 11:30:16AM +0800, Baolin Wang wrote:
>>
>> If I remember correctly, the original driver supported SC2730 and SC2731
>> chips. Are you sure the current changes are still needed? Have you tested
>> them on the SC2730 chip?
>>
>>
>> config POWER_RESET_SC27XX
>>          tristate "Spreadtrum SC27xx PMIC power-off driver"
>>          depends on MFD_SC27XX_PMIC || COMPILE_TEST
>>          help
>>            This driver supports powering off a system through
>>            Spreadtrum SC27xx series PMICs. The SC27xx series
>>            PMICs includes the SC2720, SC2721, SC2723, SC2730
>>            and SC2731 chips.
> 
> The driver was hard-coded to use registers 0xc2c and 0xdf0. SC2730 has
> different registers, which were added to the downstream version of the
> driver in [1]. I have tested this with a UMS9230 phone which has an
> SC2730 PMIC according to the device tree.
> 
> [1]: https://github.com/MotorolaMobilityLLC/kernel-sprd/commit/6165e1afe3eba33089fecc86767d47af9ab176d6

OK. Thanks.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/5] power: reset: sc27xx: Add support for SC2730 and OF match table
  2025-10-14  1:44       ` Baolin Wang
@ 2025-10-14  6:10         ` Otto Pflüger
  0 siblings, 0 replies; 12+ messages in thread
From: Otto Pflüger @ 2025-10-14  6:10 UTC (permalink / raw)
  To: Baolin Wang
  Cc: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Orson Zhai, Chunyan Zhang, Lee Jones, linux-pm, devicetree,
	linux-kernel

On Tue, Oct 14, 2025 at 09:44:15AM +0800, Baolin Wang wrote:
> [...]
> > 
> > The driver was hard-coded to use registers 0xc2c and 0xdf0. SC2730 has
> > different registers, which were added to the downstream version of the
> > driver in [1]. I have tested this with a UMS9230 phone which has an
> > SC2730 PMIC according to the device tree.
> > 
> > [1]: https://github.com/MotorolaMobilityLLC/kernel-sprd/commit/6165e1afe3eba33089fecc86767d47af9ab176d6
> 
> OK. Thanks.
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

Please note that due to the feedback about the use of empty device tree
nodes, I have switched to a different approach and sent an alternative
patch as a follow-up to this one:

https://lore.kernel.org/all/20251007-sc27xx-mfd-poweroff-v1-0-89a2f919b731@abscue.de/

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-10-14  6:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-26 16:23 [PATCH 0/5] power: reset: sc27xx: Add SC2730 and reboot support Otto Pflüger
2025-09-26 16:23 ` [PATCH 1/5] dt-bindings: power: reset: Add SC27xx series PMIC poweroff Otto Pflüger
2025-09-26 16:23 ` [PATCH 2/5] dt-bindings: mfd: sc2731: Reference sprd,sc2731-poweroff Otto Pflüger
2025-10-02  2:53   ` Rob Herring
2025-09-26 16:23 ` [PATCH 3/5] power: reset: sc27xx: Use devm_register_sys_off_handler Otto Pflüger
2025-09-30  3:23   ` Baolin Wang
2025-09-26 16:23 ` [PATCH 4/5] power: reset: sc27xx: Add support for SC2730 and OF match table Otto Pflüger
2025-09-30  3:30   ` Baolin Wang
2025-09-30  5:30     ` Otto Pflüger
2025-10-14  1:44       ` Baolin Wang
2025-10-14  6:10         ` Otto Pflüger
2025-09-26 16:23 ` [PATCH 5/5] power: reset: sc27xx: Add reboot support for SC2730 Otto Pflüger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.