If we are resuming NSLEEP triggers bits of PMIC-A and PMIC-B shall be set
to prevent transition to S2R state while clearing interrupts.
For example PMIC RTC Linux driver accesses to interrupt registers, in this
case if NSLEEP triggers bits are not set it triggers a S2R transition.

Suggested-by: Thomas Richard (TI) <[email protected]>
Signed-off-by: Richard Genoud (TI) <[email protected]>
---
 arch/arm/mach-k3/r5/lpm-common.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-k3/r5/lpm-common.c b/arch/arm/mach-k3/r5/lpm-common.c
index 6595f0caebcf..bf74507a4127 100644
--- a/arch/arm/mach-k3/r5/lpm-common.c
+++ b/arch/arm/mach-k3/r5/lpm-common.c
@@ -27,6 +27,9 @@
 /* PMIC register where the magic value resides */
 #define K3_LPM_SCRATCH_PAD_REG_3 0xcb
 
+/* PMIC NSLEEP register */
+#define K3_LPM_NSLEEP_TRIGGER_REG 0x86
+
 /* Wake-up source IDs */
 #define K3_LPM_WAKE_SOURCE_MAIN_IO 0x80
 #define K3_LPM_WAKE_SOURCE_MCU_IO 0x81
@@ -92,7 +95,7 @@ bool j7xx_board_is_resuming(void)
 {
        static enum k3_resume_state k3_resuming;
        struct lpm_scratch_space *lpm_scratch;
-       struct udevice *pmic;
+       struct udevice *pmic, *pmic_b;
        u32 pmctrl_val = 0;
        int ret, magic;
 
@@ -142,6 +145,25 @@ bool j7xx_board_is_resuming(void)
 
                if (ret)
                        printf("Failed to clean magic value for suspend 
detection in PMIC\n");
+
+               /*
+                * Ensure that NSLEEP triggers bits are set to prevent a
+                * suspend/resume transition when accessing PMIC interrupt
+                * registers.
+                */
+
+               /* Some boards may have more than one pmic */
+               ret = uclass_get_device_by_name(UCLASS_PMIC, "pmic@4c", 
&pmic_b);
+               if (ret == 0) {
+                       ret = pmic_reg_write(pmic_b, K3_LPM_NSLEEP_TRIGGER_REG, 
0x03);
+                       if (ret)
+                               printf("Failed to set NSLEEP triggers bits on 
PMIC-B\n");
+               }
+
+               ret = pmic_reg_write(pmic, K3_LPM_NSLEEP_TRIGGER_REG, 0x3);
+               if (ret)
+                       printf("Failed to set PMIC NSLEEP triggers. Spurious 
suspend/resume may happen.\n");
+
                /*
                 * For robustness, the DM should also clean the magic value at
                 * startup.
-- 
2.55.0

Reply via email to