power: pmic: pca9450: Add support for system reset
PATCH v2 1/2 power: pmic: pca9450: Add support for system reset
The family of PCA9450 PMICs have the ability to perform system resets. Restarting via PMIC is preferred method of restarting the system as all the peripherals are brought to a know state after a power-cycle. The PCA9450 features a cold restart procedure which is initiated by an I2C command 0x14 to the SW_RST register.
Support in Linux for restarting via PCA9450 PMIC has been added by Linux commit 6157e62b07d9 ("regulator: pca9450: Add restart handler").
Now add support for it also in the U-Boot via sysreset framework.
---
Change in v2:
- no change
Link to v1: https://lore.kernel.org/all/[email protected]/
drivers/power/pmic/pca9450.c | 42 ++++++++++++++++++++++++++++++++++++ include/power/pca9450.h | 2 ++ 2 files changed, 44 insertions(+)
drivers/power/pmic/pca9450.c +42 -0
@@ -7,15 +7,18 @@#include <errno.h> #include <dm.h> #include <dm/device_compat.h> +#include <dm/lists.h> #include <i2c.h> #include <linux/err.h> #include <log.h> #include <asm/global_data.h> #include <asm-generic/gpio.h> +#include <linux/delay.h> #include <linux/printk.h> #include <power/pmic.h> #include <power/regulator.h> #include <power/pca9450.h> +#include <sysreset.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -101,6 +104,14 @@ static int pca9450_probe(struct udevice *dev) } } +if (CONFIG_IS_ENABLED (SYSRESET )) { + ret =device_bind_driver_to_node (dev,"pca9450_sysreset" , +"pca9450_sysreset" , +dev_ofnode (dev),NULL ); +if (ret) +return ret; + } +if (ofnode_read_bool (dev_ofnode (dev),"nxp,wdog_b-warm-reset" )) reset_ctrl =PCA9450_PMIC_RESET_WDOG_B_CFG_WARM ;else
@@ -134,3 +145,34 @@ U_BOOT_DRIVER(pmic_pca9450) = { .ops = &pca9450_ops, .priv_auto = sizeof(struct pca9450_priv), }; + +#ifdef CONFIG_SYSRESET +static int pca9450_sysreset_request (struct udevice *dev,enum sysreset_t type) +{ +u8 cmd =PCA9450_SW_RST_COLD_RST ; + +if (type !=SYSRESET_COLD ) +return -EPROTONOSUPPORT ; + +if (pmic_write (dev->parent,PCA9450_SW_RST , &cmd,1 )) { +dev_err (dev,"reset command failed\n" ); + }else { +/* tRESTART is 250ms, delay 300ms just to be sure */ +mdelay (300 ); +/* Should not get here, warn if we do */ +dev_warn (dev,"didn't respond to reset command\n" ); + } + +return -EINPROGRESS ; +} + +static struct sysreset_ops pca9450_sysreset_ops = { + .request = pca9450_sysreset_request, +}; + +U_BOOT_DRIVER (pca9450_sysreset) = { + .name ="pca9450_sysreset" , + .id =UCLASS_SYSRESET , + .ops = &pca9450_sysreset_ops, +}; +#endif /* CONFIG_SYSRESET */
include/power/pca9450.h +2 -0
@@ -75,4 +75,6 @@ enum {#define PCA9450_PMIC_RESET_WDOG_B_CFG_WARM 0x40#define PCA9450_PMIC_RESET_WDOG_B_CFG_COLD_LDO12 0x80 +#define PCA9450_SW_RST_COLD_RST 0x14 +#endif
Signature · 1 line
2.34.1
PATCH v2 2/2 power: pmic: pca9450: Add support for reset status
PCA9450 PMIC supports reading the reset status from the PWRON_STAT register. Bits 7-4 give indication of the PMIC reset cause:
- PWRON (BIT7) - Power ON triggered by PMIC_ON_REQ input line,
- WDOGB (BIT6) - Boot after cold reset by WDOGB pin (watchdog reset),
- SW_RST (BIT5) - Boot after cold reset initiated by the software,
- PMIC_RST (BIT4) - Boot after PMIC_RST_B input line trigger.
Add support for reading reset status via the sysreset framework in a convenient printable format.
---
Change in v2:
- new patch as suggested by Paul Geurts
Link to v1: https://lore.kernel.org/all/[email protected]/
drivers/power/pmic/pca9450.c | 38 ++++++++++++++++++++++++++++++++++++ include/power/pca9450.h | 5 +++++ 2 files changed, 43 insertions(+)
drivers/power/pmic/pca9450.c +38 -0
@@ -166,8 +166,46 @@ static int pca9450_sysreset_request(struct udevice *dev, enum sysreset_t type)return -EINPROGRESS ; } +int pca9450_sysreset_get_status (struct udevice *dev,char *buf,int size) +{ +const char *reason; +int ret; +u8 reg; + + ret =pmic_read (dev->parent,PCA9450_PWRON_STAT , ®,1 ); +if (ret) +return ret; + +switch (reg) { +case PCA9450_PWRON_STAT_PWRON_MASK : + reason ="PWRON" ; +break ; +case PCA9450_PWRON_STAT_WDOG_MASK : + reason ="WDOGB" ; +break ; +case PCA9450_PWRON_STAT_SW_RST_MASK : + reason ="SW_RST" ; +break ; +case PCA9450_PWRON_STAT_PMIC_RST_MASK : + reason ="PMIC_RST" ; +break ; +default : + reason ="UNKNOWN" ; +break ; + } + + ret =snprintf (buf, size,"Reset Status: %s\n" , reason); +if (ret <0 ) { +dev_err (dev,"Write reset status error (err = %d)\n" , ret); +return -EIO ; + } + +return 0 ; +} +static struct sysreset_ops pca9450_sysreset_ops = { .request = pca9450_sysreset_request, + .get_status = pca9450_sysreset_get_status, };U_BOOT_DRIVER (pca9450_sysreset) = {
include/power/pca9450.h +5 -0
@@ -75,6 +75,11 @@ enum {#define PCA9450_PMIC_RESET_WDOG_B_CFG_WARM 0x40#define PCA9450_PMIC_RESET_WDOG_B_CFG_COLD_LDO12 0x80 +#define PCA9450_PWRON_STAT_PWRON_MASK 0x80 +#define PCA9450_PWRON_STAT_WDOG_MASK 0x40 +#define PCA9450_PWRON_STAT_SW_RST_MASK 0x20 +#define PCA9450_PWRON_STAT_PMIC_RST_MASK 0x10 +#define PCA9450_SW_RST_COLD_RST 0x14#endif
Signature · 1 line
2.34.1
Re: [PATCH v2 2/2] power: pmic: pca9450: Add support for reset status
Look good, thanks!
br,
Paul
Re: [PATCH v2 2/2] power: pmic: pca9450: Add support for reset status
In reply to Primoz FiserQuoted 8 lines
PCA9450 PMIC supports reading the reset status from the
PWRON_STATregister. Bits 7-4 give indication of the PMIC reset cause:- PWRON (BIT7) - Power ON triggered by
PMIC_ON_REQinput line,
- WDOGB (BIT6) - Boot after cold reset by WDOGB pin (watchdog reset),
-SW_RST(BIT5) - Boot after cold reset initiated by the software,
-PMIC_RST(BIT4) - Boot afterPMIC_RST_Binput line trigger.
Quoted 4 lines
Add support for reading reset status via the sysreset framework in a convenient printable format.
Signed-off-by Primoz Fiser <[email protected]>
Quoted 79 lines
---
Change in v2:
- new patch as suggested by Paul GeurtsLink to v1: https://lore.kernel.org/all/[email protected]/
drivers/power/pmic/pca9450.c | 38 ++++++++++++++++++++++++++++++++++++ include/power/pca9450.h | 5 +++++ 2 files changed, 43 insertions(+)drivers/power/pmic/pca9450.c +38
-0@@ -166,8 +166,46 @@ static int pca9450_sysreset_request(struct udevice *dev, enum sysreset_t type)return -EINPROGRESS ; } +int pca9450_sysreset_get_status (struct udevice *dev,char *buf,int size) +{ +const char *reason; +int ret; +u8 reg; + + ret =pmic_read (dev->parent,PCA9450_PWRON_STAT , ®,1 ); +if (ret) +return ret; + +switch (reg) { +case PCA9450_PWRON_STAT_PWRON_MASK : + reason ="PWRON" ; +break ; +case PCA9450_PWRON_STAT_WDOG_MASK : + reason ="WDOGB" ; +break ; +case PCA9450_PWRON_STAT_SW_RST_MASK : + reason ="SW_RST" ; +break ; +case PCA9450_PWRON_STAT_PMIC_RST_MASK : + reason ="PMIC_RST" ; +break ; +default : + reason ="UNKNOWN" ; +break ; + } + + ret =snprintf (buf, size,"Reset Status: %s\n" , reason); +if (ret <0 ) { +dev_err (dev,"Write reset status error (err = %d)\n" , ret); +return -EIO ; + } + +return 0 ; +} +static struct sysreset_ops pca9450_sysreset_ops = { .request = pca9450_sysreset_request, + .get_status = pca9450_sysreset_get_status, };U_BOOT_DRIVER (pca9450_sysreset) = {include/power/pca9450.h +5
-0@@ -75,6 +75,11 @@ enum {#define PCA9450_PMIC_RESET_WDOG_B_CFG_WARM 0x40#define PCA9450_PMIC_RESET_WDOG_B_CFG_COLD_LDO12 0x80 +#define PCA9450_PWRON_STAT_PWRON_MASK 0x80 +#define PCA9450_PWRON_STAT_WDOG_MASK 0x40 +#define PCA9450_PWRON_STAT_SW_RST_MASK 0x20 +#define PCA9450_PWRON_STAT_PMIC_RST_MASK 0x10 +#define PCA9450_SW_RST_COLD_RST 0x14#endif Signature · 1 line
2.34.1
br,
Paul
Look good, thanks!
br,
Paul
Quoted 6 lines
The family of PCA9450 PMICs have the ability to perform system resets. Restarting via PMIC is preferred method of restarting the system as all the peripherals are brought to a know state after a power-cycle. The PCA9450 features a cold restart procedure which is initiated by an I2C command
0x14to theSW_RSTregister.
Quoted 6 lines
Support in Linux for restarting via PCA9450 PMIC has been added by Linux commit
6157e62b07d9("regulator: pca9450: Add restart handler").Now add support for it also in the U-Boot via sysreset framework.
Signed-off-by Primoz Fiser <[email protected]>
Quoted 96 lines
---
Change in v2:
- no changeLink to v1: https://lore.kernel.org/all/[email protected]/
drivers/power/pmic/pca9450.c | 42 ++++++++++++++++++++++++++++++++++++ include/power/pca9450.h | 2 ++ 2 files changed, 44 insertions(+)drivers/power/pmic/pca9450.c +42
-0@@ -7,15 +7,18 @@#include <errno.h> #include <dm.h> #include <dm/device_compat.h> +#include <dm/lists.h> #include <i2c.h> #include <linux/err.h> #include <log.h> #include <asm/global_data.h> #include <asm-generic/gpio.h> +#include <linux/delay.h> #include <linux/printk.h> #include <power/pmic.h> #include <power/regulator.h> #include <power/pca9450.h> +#include <sysreset.h> DECLARE_GLOBAL_DATA_PTR ;@@ -101,6 +104,14 @@ static int pca9450_probe(struct udevice *dev) } } +if (CONFIG_IS_ENABLED (SYSRESET )) { + ret =device_bind_driver_to_node (dev,"pca9450_sysreset" , +"pca9450_sysreset" , +dev_ofnode (dev),NULL ); +if (ret) +return ret; + } +if (ofnode_read_bool (dev_ofnode (dev),"nxp,wdog_b-warm-reset" )) reset_ctrl =PCA9450_PMIC_RESET_WDOG_B_CFG_WARM ;else @@ -134,3 +145,34 @@ U_BOOT_DRIVER(pmic_pca9450) = { .ops = &pca9450_ops, .priv_auto = sizeof(struct pca9450_priv), }; + +#ifdef CONFIG_SYSRESET +static int pca9450_sysreset_request (struct udevice *dev,enum sysreset_t type) +{ +u8 cmd =PCA9450_SW_RST_COLD_RST ; + +if (type !=SYSRESET_COLD ) +return -EPROTONOSUPPORT ; + +if (pmic_write (dev->parent,PCA9450_SW_RST , &cmd,1 )) { +dev_err (dev,"reset command failed\n" ); + }else { +/* tRESTART is 250ms, delay 300ms just to be sure */ +mdelay (300 ); +/* Should not get here, warn if we do */ +dev_warn (dev,"didn't respond to reset command\n" ); + } + +return -EINPROGRESS ; +} + +static struct sysreset_ops pca9450_sysreset_ops = { + .request = pca9450_sysreset_request, +}; + +U_BOOT_DRIVER (pca9450_sysreset) = { + .name ="pca9450_sysreset" , + .id =UCLASS_SYSRESET , + .ops = &pca9450_sysreset_ops, +}; +#endif /* CONFIG_SYSRESET */ include/power/pca9450.h +2
-0@@ -75,4 +75,6 @@ enum {#define PCA9450_PMIC_RESET_WDOG_B_CFG_WARM 0x40#define PCA9450_PMIC_RESET_WDOG_B_CFG_COLD_LDO12 0x80 +#define PCA9450_SW_RST_COLD_RST 0x14 +#endif Signature · 1 line
2.34.1
br,
Paul
Hi Primoz,
Would you please rebase to
https://source.denx.de/u-boot/custodians/u-boot-mmc.git branch: next
I am collecting the power related patches, but there is conflict when I apply this patchset.
Thanks,
Peng