* [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming
@ 2023-04-28 11:28 Sean Nyekjaer
2023-04-28 11:28 ` [PATCH 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler Sean Nyekjaer
2023-05-15 12:43 ` [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming Lee Jones
0 siblings, 2 replies; 6+ messages in thread
From: Sean Nyekjaer @ 2023-04-28 11:28 UTC (permalink / raw)
To: Lee Jones; +Cc: p.paillet, Sean Nyekjaer, linux-kernel
Fixup main control register and bits naming so the match the naming from
the datasheet.
https://www.st.com/resource/en/datasheet/stpmic1.pdf
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
drivers/mfd/stpmic1.c | 4 ++--
include/linux/mfd/stpmic1.h | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
index 8db1530d9bac..4c9b18d9dec8 100644
--- a/drivers/mfd/stpmic1.c
+++ b/drivers/mfd/stpmic1.c
@@ -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),
diff --git a/include/linux/mfd/stpmic1.h b/include/linux/mfd/stpmic1.h
index fa3f99f7e9a1..dc00bac24f5a 100644
--- a/include/linux/mfd/stpmic1.h
+++ b/include/linux/mfd/stpmic1.h
@@ -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
--
2.40.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler
2023-04-28 11:28 [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming Sean Nyekjaer
@ 2023-04-28 11:28 ` Sean Nyekjaer
2023-05-02 6:17 ` Sean Nyekjær
2023-05-15 12:46 ` Lee Jones
2023-05-15 12:43 ` [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming Lee Jones
1 sibling, 2 replies; 6+ messages in thread
From: Sean Nyekjaer @ 2023-04-28 11:28 UTC (permalink / raw)
To: Lee Jones; +Cc: p.paillet, Sean Nyekjaer, linux-kernel
Use devm_register_sys_off_handler() that allows to register multiple
power-off handlers.
This can be enabled by adding "st,pmic-poweroff" to device-tree.
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
drivers/mfd/stpmic1.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
index 4c9b18d9dec8..c628141eb03c 100644
--- a/drivers/mfd/stpmic1.c
+++ b/drivers/mfd/stpmic1.c
@@ -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,33 @@ 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_power_off_prepare_init(struct stpmic1 *ddata)
+{
+ int 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 0;
+}
+
static int stpmic1_probe(struct i2c_client *i2c)
{
struct stpmic1 *ddata;
@@ -159,6 +187,12 @@ static int stpmic1_probe(struct i2c_client *i2c)
return ret;
}
+ if (of_property_read_bool(i2c->dev.of_node, "st,pmic-poweroff")) {
+ ret = stpmic1_power_off_prepare_init(ddata);
+ if (ret)
+ return ret;
+ }
+
return devm_of_platform_populate(dev);
}
--
2.40.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler
2023-04-28 11:28 ` [PATCH 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler Sean Nyekjaer
@ 2023-05-02 6:17 ` Sean Nyekjær
2023-05-15 12:46 ` Lee Jones
1 sibling, 0 replies; 6+ messages in thread
From: Sean Nyekjær @ 2023-05-02 6:17 UTC (permalink / raw)
To: Lee Jones; +Cc: p.paillet, linux-kernel
> On 28 Apr 2023, at 13.28, Sean Nyekjaer <sean@geanix.com> wrote:
>
> Use devm_register_sys_off_handler() that allows to register multiple
> power-off handlers.
>
> This can be enabled by adding "st,pmic-poweroff" to device-tree.
>
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
> ---
Oh, I forgot the device-tree documentation.
Will add that after review…
/Sean
> drivers/mfd/stpmic1.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
> index 4c9b18d9dec8..c628141eb03c 100644
> --- a/drivers/mfd/stpmic1.c
> +++ b/drivers/mfd/stpmic1.c
> @@ -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,33 @@ 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_power_off_prepare_init(struct stpmic1 *ddata)
> +{
> + int 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 0;
> +}
> +
> static int stpmic1_probe(struct i2c_client *i2c)
> {
> struct stpmic1 *ddata;
> @@ -159,6 +187,12 @@ static int stpmic1_probe(struct i2c_client *i2c)
> return ret;
> }
>
> + if (of_property_read_bool(i2c->dev.of_node, "st,pmic-poweroff")) {
> + ret = stpmic1_power_off_prepare_init(ddata);
> + if (ret)
> + return ret;
> + }
> +
> return devm_of_platform_populate(dev);
> }
>
> --
> 2.40.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler
2023-04-28 11:28 ` [PATCH 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler Sean Nyekjaer
2023-05-02 6:17 ` Sean Nyekjær
@ 2023-05-15 12:46 ` Lee Jones
1 sibling, 0 replies; 6+ messages in thread
From: Lee Jones @ 2023-05-15 12:46 UTC (permalink / raw)
To: Sean Nyekjaer; +Cc: p.paillet, linux-kernel
On Fri, 28 Apr 2023, Sean Nyekjaer wrote:
> Use devm_register_sys_off_handler() that allows to register multiple
> power-off handlers.
>
> This can be enabled by adding "st,pmic-poweroff" to device-tree.
>
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
> ---
> drivers/mfd/stpmic1.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
You need to submit the Device Tree binding with this patch.
> diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
> index 4c9b18d9dec8..c628141eb03c 100644
> --- a/drivers/mfd/stpmic1.c
> +++ b/drivers/mfd/stpmic1.c
> @@ -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,33 @@ 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_power_off_prepare_init(struct stpmic1 *ddata)
This function looks superfluous.
Why not just call devm_register_sys_off_handler() inside the if?
> +{
> + int 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 0;
> +}
> +
> static int stpmic1_probe(struct i2c_client *i2c)
> {
> struct stpmic1 *ddata;
> @@ -159,6 +187,12 @@ static int stpmic1_probe(struct i2c_client *i2c)
> return ret;
> }
>
> + if (of_property_read_bool(i2c->dev.of_node, "st,pmic-poweroff")) {
> + ret = stpmic1_power_off_prepare_init(ddata);
> + if (ret)
> + return ret;
> + }
> +
> return devm_of_platform_populate(dev);
> }
>
> --
> 2.40.0
>
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming
2023-04-28 11:28 [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming Sean Nyekjaer
2023-04-28 11:28 ` [PATCH 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler Sean Nyekjaer
@ 2023-05-15 12:43 ` Lee Jones
2023-05-16 6:52 ` Sean Nyekjær
1 sibling, 1 reply; 6+ messages in thread
From: Lee Jones @ 2023-05-15 12:43 UTC (permalink / raw)
To: Sean Nyekjaer; +Cc: p.paillet, linux-kernel
On Fri, 28 Apr 2023, Sean Nyekjaer wrote:
> Fixup main control register and bits naming so the match the naming from
> the datasheet.
I'm in two minds about this.
On one hand using the names from the datasheet in the right thing to
do, however, on the other hand, the current nomenclature appears clearer.
> https://www.st.com/resource/en/datasheet/stpmic1.pdf
>
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
> ---
> drivers/mfd/stpmic1.c | 4 ++--
> include/linux/mfd/stpmic1.h | 12 ++++++------
> 2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
> index 8db1530d9bac..4c9b18d9dec8 100644
> --- a/drivers/mfd/stpmic1.c
> +++ b/drivers/mfd/stpmic1.c
> @@ -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),
> diff --git a/include/linux/mfd/stpmic1.h b/include/linux/mfd/stpmic1.h
> index fa3f99f7e9a1..dc00bac24f5a 100644
> --- a/include/linux/mfd/stpmic1.h
> +++ b/include/linux/mfd/stpmic1.h
> @@ -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
> --
> 2.40.0
>
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming
2023-05-15 12:43 ` [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming Lee Jones
@ 2023-05-16 6:52 ` Sean Nyekjær
0 siblings, 0 replies; 6+ messages in thread
From: Sean Nyekjær @ 2023-05-16 6:52 UTC (permalink / raw)
To: Lee Jones; +Cc: p.paillet, linux-kernel
Hi Lee,
> On 15 May 2023, at 14.43, Lee Jones <lee@kernel.org> wrote:
>
> On Fri, 28 Apr 2023, Sean Nyekjaer wrote:
>
>> Fixup main control register and bits naming so the match the naming from
>> the datasheet.
>
> I'm in two minds about this.
>
> On one hand using the names from the datasheet in the right thing to
> do, however, on the other hand, the current nomenclature appears clearer.
If you like me, tries to understand what’s happening inside the PMIC. It’s really nice to have the same naming in the software as in the datasheet.
It looks like the naming was updated in the datasheet version 9.
>
>> https://www.st.com/resource/en/datasheet/stpmic1.pdf
>>
>>
[ … ]
>>
>
> --
> Lee Jones [李琼斯]
/Sean
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-05-16 6:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-28 11:28 [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming Sean Nyekjaer
2023-04-28 11:28 ` [PATCH 2/2] mfd: stpmic1: add pmic poweroff via sys-off handler Sean Nyekjaer
2023-05-02 6:17 ` Sean Nyekjær
2023-05-15 12:46 ` Lee Jones
2023-05-15 12:43 ` [PATCH 1/2] mfd: stpmic1: fixup main control register and bits naming Lee Jones
2023-05-16 6:52 ` Sean Nyekjær
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox