Skip to contentSkip to conversation

mfd: stpmic1: fixup main control register and bits naming

PATCH Applied Sean Nyekjaer 2 participants 4 messages Jun 2, 2023 – Jun 8, 2023 Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 mfd: stpmic1: fixup main control register and bits naming

Fixup main control register and bits naming so the match the naming from the datasheet.

https://www.st.com/resource/en/datasheet/stpmic1.pdf

---
Changes since v1:
- None

Changes since v2:
- None

 drivers/mfd/stpmic1.c       |  4 ++--
 include/linux/mfd/stpmic1.h | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/mfd/stpmic1.c +2 -2
index 8db1530d9bac..4c9b18d9dec8 100644
@@ -19,7 +19,7 @@
 
 static const struct regmap_range stpmic1_readable_ranges[] = {
 	regmap_reg_range(TURN_ON_SR, VERSION_SR),
-	regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+	regmap_reg_range(MAIN_CR, LDO6_STDBY_CR),
 	regmap_reg_range(BST_SW_CR, BST_SW_CR),
 	regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
 	regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
@@ -30,7 +30,7 @@ static const struct regmap_range stpmic1_readable_ranges[] = {
 };
 
 static const struct regmap_range stpmic1_writeable_ranges[] = {
-	regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+	regmap_reg_range(MAIN_CR, LDO6_STDBY_CR),
 	regmap_reg_range(BST_SW_CR, BST_SW_CR),
 	regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
 	regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
include/linux/mfd/stpmic1.h +6 -6
index fa3f99f7e9a1..dc00bac24f5a 100644
@@ -15,7 +15,7 @@
 #define RREQ_STATE_SR		0x5
 #define VERSION_SR		0x6
 
-#define SWOFF_PWRCTRL_CR	0x10
+#define MAIN_CR			0x10
 #define PADS_PULL_CR		0x11
 #define BUCKS_PD_CR		0x12
 #define LDO14_PD_CR		0x13
@@ -148,14 +148,14 @@
 #define LDO_BYPASS_MASK			BIT(7)
 
 /* Main PMIC Control Register
- * SWOFF_PWRCTRL_CR
+ * MAIN_CR
  * Address : 0x10
  */
-#define ICC_EVENT_ENABLED		BIT(4)
+#define OCP_OFF_DBG			BIT(4)
 #define PWRCTRL_POLARITY_HIGH		BIT(3)
-#define PWRCTRL_PIN_VALID		BIT(2)
-#define RESTART_REQUEST_ENABLED		BIT(1)
-#define SOFTWARE_SWITCH_OFF_ENABLED	BIT(0)
+#define PWRCTRL_ENABLE			BIT(2)
+#define RESTART_REQUEST_ENABLE		BIT(1)
+#define SOFTWARE_SWITCH_OFF		BIT(0)
 
 /* Main PMIC PADS Control Register
  * PADS_PULL_CR
Signature · 1 line
2.40.0
#1 lore raw

PATCH v3 2/2 mfd: stpmic1: add pmic poweroff via sys-off handler

Use devm_register_sys_off_handler() that allows to register multiple power-off handlers.
This will allow boards using the stpmic1 to power-off.

---
Changes since v1:
- Removed superfluous function

Changes since v2:
- Removed the devicetree option to turn the power-off functionality on and off.

 drivers/mfd/stpmic1.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/mfd/stpmic1.c +21 -0
index 4c9b18d9dec8..9c7d1c3b8dfd 100644
@@ -7,6 +7,7 @@
 #include <linux/mfd/core.h>
 #include <linux/mfd/stpmic1.h>
 #include <linux/module.h>
+#include <linux/reboot.h>
 #include <linux/of.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
@@ -117,6 +118,16 @@ static const struct regmap_irq_chip stpmic1_regmap_irq_chip = {
 	.num_irqs = ARRAY_SIZE(stpmic1_irqs),
 };
 
+static int stpmic1_power_off(struct sys_off_data *data)
+{
+	struct stpmic1 *ddata = data->cb_data;
+
+	regmap_update_bits(ddata->regmap, MAIN_CR,
+			   SOFTWARE_SWITCH_OFF, SOFTWARE_SWITCH_OFF);
+
+	return NOTIFY_DONE;
+}
+
 static int stpmic1_probe(struct i2c_client *i2c)
 {
 	struct stpmic1 *ddata;
@@ -159,6 +170,16 @@ static int stpmic1_probe(struct i2c_client *i2c)
 		return ret;
 	}
 
+	ret = devm_register_sys_off_handler(ddata->dev,
+					    SYS_OFF_MODE_POWER_OFF,
+					    SYS_OFF_PRIO_DEFAULT,
+					    stpmic1_power_off,
+					    ddata);
+	if (ret) {
+		dev_err(ddata->dev, "failed to register sys-off handler: %d\n", ret);
+		return ret;
+	}
+
 	return devm_of_platform_populate(dev);
 }
 
Signature · 1 line
2.40.0
maintainer Applied
#2 lore raw

Re: [PATCH v3 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler

Quoted 9 lines · Sean Nyekjaer

Use devm_register_sys_off_handler() that allows to register multiple power-off handlers.
This will allow boards using the stpmic1 to power-off.

---
Changes since v1:
- Removed superfluous function

Quoted 5 lines

Changes since v2:
- Removed the devicetree option to turn the power-off functionality on and off.

 drivers/mfd/stpmic1.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Applied, thanks

Signature · 1 line
Lee Jones [李琼斯]
maintainer Applied
#3 lore raw
In reply to Sean Nyekjaer
Quoted 11 lines · Sean Nyekjaer

Fixup main control register and bits naming so the match the naming from the datasheet.

https://www.st.com/resource/en/datasheet/stpmic1.pdf

---
Changes since v1:
- None

Quoted 6 lines

Changes since v2:
- None

 drivers/mfd/stpmic1.c       |  4 ++--
 include/linux/mfd/stpmic1.h | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

Applied, thanks

Signature · 1 line
Lee Jones [李琼斯]