power: pmic: pca9450: Add support for system reset
PATCH v3 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.
---
Changes in v3:
- rebase custodians/u-boot-mmc branch: next
- add Reviewed-by: tags
Link to v2: https://lore.kernel.org/all/[email protected]/
drivers/power/pmic/pca9450.c | 44 ++++++++++++++++++++++++++++++++++++ include/power/pca9450.h | 2 ++ 2 files changed, 46 insertions(+)
drivers/power/pmic/pca9450.c +44 -0
@@ -6,13 +6,17 @@#include <fdtdec.h> #include <errno.h> #include <dm.h> +#include <dm/device_compat.h> +#include <dm/lists.h> #include <i2c.h> #include <log.h> #include <asm/global_data.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 ;
@@ -79,6 +83,15 @@ static int pca9450_bind(struct udevice *dev)static int pca9450_probe (struct udevice *dev) {unsigned int reset_ctrl; +int ret; + +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 ;
@@ -112,3 +125,34 @@ U_BOOT_DRIVER(pmic_pca9450) = { .probe = pca9450_probe, .ops = &pca9450_ops, }; + +#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 v3 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.
---
Changes in v3:
- rebase custodians/u-boot-mmc branch: next
- add Reviewed-by: tags
Link to v2: 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
@@ -146,8 +146,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
Peng Fan (OSS)
AppliedFrom: Peng Fan <[email protected]>
Quoted 10 lines · Primoz Fiser
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.Support in Linux for restarting via PCA9450 PMIC has been added by Linux commit
6157e62b07d9("regulator: pca9450: Add restart handler").[...]
Applied, thanks!
[1/2] power: pmic: pca9450: Add support for system reset
commit: 9065b87f35018a4e993e7dfb8a8ec29474785f76
[2/2] power: pmic: pca9450: Add support for reset status
commit: ad197b31b3f88d53c349995d8bbaeba4b18b8f2bBest regards,
Signature · 1 line
Peng Fan <[email protected]>