power: pmic: pca9450: Add support for system reset
PATCH 1/1 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.
--- 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
Quoted 56 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.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]>--- drivers/power/pmic/pca9450.c | 42 ++++++++++++++++++++++++++++++++++++ include/power/pca9450.h | 2 ++ 2 files changed, 44 insertions(+)drivers/power/pmic/pca9450.c +11
-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
drivers/power/pmic/pca9450.c U_BOOT_DRIVER(pmic_pca9450) = { · line 154
Quoted 10 lines
drivers/power/pmic/pca9450.c +7
-0@@ -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 )
The PCA9450 calls it "cold reset", but it is technically SYSRESET_POWER. There is no option for it in the sysreset do_reset, but maybe there should be.
Quoted 6 lines
drivers/power/pmic/pca9450.c +6
-0+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 */
drivers/power/pmic/pca9450.c U_BOOT_DRIVER(pmic_pca9450) = { · line 170
Quoted 10 lines
drivers/power/pmic/pca9450.c +10
-0+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,
When using the PCA9450 to perform a cold reset, the CPU boot status shall _always_ be POR, as that is what the CPU detects. This means the boot status should also come from the PCA9450 when enabling CONFIG_SYSRESET option.
I think implementing pca9450_sysreset_ops.get_status() to read the PWRON_STAT register should do the trick, but I am not that familiar with the sysreset in U-Boot.
Quoted 14 lines
drivers/power/pmic/pca9450.c +8
-0+}; + +U_BOOT_DRIVER (pca9450_sysreset) = { + .name ="pca9450_sysreset" , + .id =UCLASS_SYSRESET , + .ops = &pca9450_sysreset_ops, +}; +#endif /* CONFIG_SYSRESET */ include/power/pca9450.h +0
-0
include/power/pca9450.h enum { · line 80
Quoted 6 lines
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
Thanks for porting it to U-Boot :-)
br,
Paul
Hi Paul,
Quoted 61 lines · Paul Geurts
Quoted 61 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.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]>--- drivers/power/pmic/pca9450.c | 42 ++++++++++++++++++++++++++++++++++++ include/power/pca9450.h | 2 ++ 2 files changed, 44 insertions(+)drivers/power/pmic/pca9450.c +13
-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
Quoted 8 lines
drivers/power/pmic/pca9450.c U_BOOT_DRIVER(pmic_pca9450) = { · line 154
Quoted 5 lines
drivers/power/pmic/pca9450.c +5
-0+static int pca9450_sysreset_request (struct udevice *dev,enum sysreset_t type) +{ +u8 cmd =PCA9450_SW_RST_COLD_RST ; + +if (type !=SYSRESET_COLD )The PCA9450 calls it "cold reset", but it is technically
SYSRESET_POWER. There is no option for it in the sysresetdo_reset, but maybe there should be.
Yeah, the default is SYSRESET_COLD.
Additionally, there is only support for warm rst type (SYSRESET_WARM) in do_reset for now.
I decided not to implement it to keep it as simple as possible and in sync with your Linux support.
Quoted 22 lines
Quoted 7 lines
drivers/power/pmic/pca9450.c +6
-0+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 */ drivers/power/pmic/pca9450.c U_BOOT_DRIVER(pmic_pca9450) = { · line 170
Quoted 10 lines
drivers/power/pmic/pca9450.c +10
-0+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,When using the PCA9450 to perform a cold reset, the CPU boot status shall _always_ be POR, as that is what the CPU detects. This means the boot status should also come from the PCA9450 when enabling
CONFIG_SYSRESEToption.
Quoted 3 lines
I think implementing
pca9450_sysreset_ops.get_status()to read thePWRON_STATregister should do the trick, but I am not that familiar with the sysreset in U-Boot.
You read my mind :)
I have support for get_status() already prepared but I am waiting for this patch to get applied first.
Your Reviewed-by tag would help here if possible?
Quoted 17 lines
Quoted 17 lines
drivers/power/pmic/pca9450.c +8
-0+}; + +U_BOOT_DRIVER (pca9450_sysreset) = { + .name ="pca9450_sysreset" , + .id =UCLASS_SYSRESET , + .ops = &pca9450_sysreset_ops, +}; +#endif /* CONFIG_SYSRESET */ include/power/pca9450.h +0
-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
Quoted 6 lines
include/power/pca9450.h enum { · line 80
Quoted 4 lines
include/power/pca9450.h +2
-0+#define PCA9450_SW_RST_COLD_RST 0x14 +#endif Thanks for porting it to U-Boot :-)
You're welcome.
Thanks for adding support in Linux.
BR,
Primoz
Quoted 3 lines
br,
Paul
Signature · 9 lines
Primoz Fiser phone: +386-41-390-545 email: [email protected] -- Norik systems d.o.o. Your embedded software partner Slovenia, EU phone: +386-41-540-545 email: [email protected]
Hi Primoz,
Quoted 73 lines · Primoz Fiser
Hi Paul,
Quoted 61 lines · Paul Geurts
Quoted 61 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.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]>--- drivers/power/pmic/pca9450.c | 42 ++++++++++++++++++++++++++++++++++++ include/power/pca9450.h | 2 ++ 2 files changed, 44 insertions(+)drivers/power/pmic/pca9450.c +13
-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 Quoted 8 lines
drivers/power/pmic/pca9450.c U_BOOT_DRIVER(pmic_pca9450) = { · line 154
Quoted 5 lines
drivers/power/pmic/pca9450.c +5
-0+static int pca9450_sysreset_request (struct udevice *dev,enum sysreset_t type) +{ +u8 cmd =PCA9450_SW_RST_COLD_RST ; + +if (type !=SYSRESET_COLD )The PCA9450 calls it "cold reset", but it is technically
SYSRESET_POWER. There is no option for it in the sysresetdo_reset, but maybe there should be.
Quoted 7 lines
Yeah, the default is
SYSRESET_COLD.Additionally, there is only support for warm rst type (
SYSRESET_WARM) indo_resetfor now.I decided not to implement it to keep it as simple as possible and in sync with your Linux support.
Understandable. I think it's fine like this too.
Quoted 23 lines
Quoted 23 lines
Quoted 8 lines
drivers/power/pmic/pca9450.c +6
-0+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 */ drivers/power/pmic/pca9450.c U_BOOT_DRIVER(pmic_pca9450) = { · line 170
Quoted 10 lines
drivers/power/pmic/pca9450.c +10
-0+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,When using the PCA9450 to perform a cold reset, the CPU boot status shall _always_ be POR, as that is what the CPU detects. This means the boot status should also come from the PCA9450 when enabling
CONFIG_SYSRESEToption.
Quoted 8 lines
Quoted 3 lines
I think implementing
pca9450_sysreset_ops.get_status()to read thePWRON_STATregister should do the trick, but I am not that familiar with the sysreset in U-Boot.You read my mind :)
I have support for
get_status()already prepared but I am waiting for this patch to get applied first.
I you get this patch applied, you will effectively break the boot status, which would be regression in U-Boot. If you have the commit ready, I think it should be a patch series.
Quoted 2 lines
Your Reviewed-by tag would help here if possible?
Yeah will do.
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
drivers/power/pmic/pca9450.c +8
-0+}; + +U_BOOT_DRIVER (pca9450_sysreset) = { + .name ="pca9450_sysreset" , + .id =UCLASS_SYSRESET , + .ops = &pca9450_sysreset_ops, +}; +#endif /* CONFIG_SYSRESET */ include/power/pca9450.h +0
-0@@ -75,4 +75,6 @@ enum {#define PCA9450_PMIC_RESET_WDOG_B_CFG_WARM 0x40#define PCA9450_PMIC_RESET_WDOG_B_CFG_COLD_LDO12 0x80Quoted 6 lines
include/power/pca9450.h enum { · line 80
Quoted 4 lines
include/power/pca9450.h +2
-0+#define PCA9450_SW_RST_COLD_RST 0x14 +#endif Thanks for porting it to U-Boot :-)
You're welcome.
Quoted 20 lines
Thanks for adding support in Linux.
BR,
PrimozQuoted 3 lines
br,
PaulSignature · 9 lines
Primoz Fiser phone: +386-41-390-545 email: [email protected] -- Norik systems d.o.o. Your embedded software partner Slovenia, EU phone: +386-41-540-545 email: [email protected]
br,
Paul