ARM: at91: pm: change BU Power Switch to automatic mode
[email protected]
maintainerPATCH 1/1 ARM: at91: pm: change BU Power Switch to automatic mode
From: Nicolas Ferre <[email protected]>
Change how the Backup Unit Power is configured and force the automatic/hardware mode.
This change eliminates the need for software management of the power switch, ensuring it transitions to the backup power source before entering low power modes.
This is done in the only locaton where this swich was configured. It's usually done in the bootloader.
Previously, the loss of the VDDANA (or VDDIN33) power source was not automatically compensated by an alternative power source. This resulted in the loss of Backup Unit content, including Backup Self-refresh low power mode information, OTP emulation configuration, and boot configuration, for instance.
--- arch/arm/mach-at91/pm.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
arch/arm/mach-at91/pm.c +20 -11
@@ -598,7 +598,21 @@ static int at91_suspend_finish(unsigned long val)return 0 ; } -static void at91_pm_switch_ba_to_vbat (void ) +/** +* at91_pm_switch_ba_to_auto() - Configure Backup Unit Power Switch +* to automatic/hardware mode. +* +* The Backup Unit Power Switch can be managed either by software or hardware. +* Enabling hardware mode allows the automatic transition of power between +* VDDANA (or VDDIN33) and VDDBU (or VBAT, respectively), based on the +* availability of these power sources. +* +* If the Backup Unit Power Switch is already in automatic mode, no action is +* required. If it is in software-controlled mode, it is switched to automatic +* mode to enhance safety and eliminate the need for toggling between power +* sources. +*/ +static void at91_pm_switch_ba_to_auto (void ) {unsigned int offset = offsetof(struct at91_pm_sfrbu_regs , pswbu);unsigned int val;
@@ -609,24 +623,19 @@ static void at91_pm_switch_ba_to_vbat(void) val =readl (soc_pm.data.sfrbu + offset); -/* Already on VBAT. */ -if (!(val & soc_pm.sfrbu_regs.pswbu.state)) +/* Already on auto/hardware. */ +if (!(val & soc_pm.sfrbu_regs.pswbu.ctrl))return ; - val &= ~soc_pm.sfrbu_regs.pswbu.softsw; - val |= soc_pm.sfrbu_regs.pswbu.key | soc_pm.sfrbu_regs.pswbu.ctrl; + val &= ~soc_pm.sfrbu_regs.pswbu.ctrl; + val |= soc_pm.sfrbu_regs.pswbu.key;writel (val, soc_pm.data.sfrbu + offset); - -/* Wait for update. */ - val =readl (soc_pm.data.sfrbu + offset); -while (val & soc_pm.sfrbu_regs.pswbu.state) - val =readl (soc_pm.data.sfrbu + offset); }static void at91_pm_suspend (suspend_state_t state) {if (soc_pm.data.mode ==AT91_PM_BACKUP ) { -at91_pm_switch_ba_to_vbat (); +at91_pm_switch_ba_to_auto ();cpu_suspend (0 , at91_suspend_finish);
Signature · 1 line
2.39.2
Claudiu Beznea
maintainerHi, Nicolas,
Quoted 9 lines · On 25.11.2024 18:56, [email protected] wrote:
From: Nicolas Ferre <[email protected]>
Change how the Backup Unit Power is configured and force the automatic/hardware mode.
This change eliminates the need for software management of the power switch, ensuring it transitions to the backup power source before entering low power modes.This is done in the only locaton where this swich was configured. It's
s/locaton/location
Quoted 7 lines
usually done in the bootloader.
Previously, the loss of the VDDANA (or VDDIN33) power source was not automatically compensated by an alternative power source. This resulted in the loss of Backup Unit content, including Backup Self-refresh low power mode information, OTP emulation configuration, and boot configuration, for instance.
Should we add a fixes for this?
Quoted 34 lines
Signed-off-by Nicolas Ferre <[email protected]>--- arch/arm/mach-at91/pm.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)arch/arm/mach-at91/pm.c +15
-1@@ -598,7 +598,21 @@ static int at91_suspend_finish(unsigned long val)return 0 ; } -static void at91_pm_switch_ba_to_vbat (void ) +/** +* at91_pm_switch_ba_to_auto() - Configure Backup Unit Power Switch +* to automatic/hardware mode. +* +* The Backup Unit Power Switch can be managed either by software or hardware. +* Enabling hardware mode allows the automatic transition of power between +* VDDANA (or VDDIN33) and VDDBU (or VBAT, respectively), based on the +* availability of these power sources. +* +* If the Backup Unit Power Switch is already in automatic mode, no action is +* required. If it is in software-controlled mode, it is switched to automatic +* mode to enhance safety and eliminate the need for toggling between power +* sources. +*/ +static void at91_pm_switch_ba_to_auto (void ) {unsigned int offset = offsetof(struct at91_pm_sfrbu_regs , pswbu);unsigned int val;
arch/arm/mach-at91/pm.c static void at91_pm_switch_ba_to_vbat(void) · line 616
Quoted 10 lines
arch/arm/mach-at91/pm.c +2
-3@@ -609,24 +623,19 @@ static void at91_pm_switch_ba_to_vbat(void) val =readl (soc_pm.data.sfrbu + offset); -/* Already on VBAT. */ -if (!(val & soc_pm.sfrbu_regs.pswbu.state)) +/* Already on auto/hardware. */ +if (!(val & soc_pm.sfrbu_regs.pswbu.ctrl))return ; - val &= ~soc_pm.sfrbu_regs.pswbu.softsw;
It seems that softsw and state members of at91_pm_sfrbu_regs.pswbu along with their initialization could be dropped. What do you think?
I can do it while applying, if any.
Thank you,
Claudiu
Quoted 19 lines
arch/arm/mach-at91/pm.c +3
-7- val |= soc_pm.sfrbu_regs.pswbu.key | soc_pm.sfrbu_regs.pswbu.ctrl; + val &= ~soc_pm.sfrbu_regs.pswbu.ctrl; + val |= soc_pm.sfrbu_regs.pswbu.key;writel (val, soc_pm.data.sfrbu + offset); - -/* Wait for update. */ - val =readl (soc_pm.data.sfrbu + offset); -while (val & soc_pm.sfrbu_regs.pswbu.state) - val =readl (soc_pm.data.sfrbu + offset); }static void at91_pm_suspend (suspend_state_t state) {if (soc_pm.data.mode ==AT91_PM_BACKUP ) { -at91_pm_switch_ba_to_vbat (); +at91_pm_switch_ba_to_auto ();cpu_suspend (0 , at91_suspend_finish);
Nicolas Ferre
maintainerQuoted 17 lines · Claudiu Beznea
Hi, Nicolas,
Quoted 9 lines · On 25.11.2024 18:56, [email protected] wrote:
From: Nicolas Ferre <[email protected]>
Change how the Backup Unit Power is configured and force the automatic/hardware mode.
This change eliminates the need for software management of the power switch, ensuring it transitions to the backup power source before entering low power modes.This is done in the only locaton where this swich was configured. It's
s/locaton/location
Quoted 2 lines
usually done in the bootloader.
Quoted 7 lines
Quoted 5 lines
Previously, the loss of the VDDANA (or VDDIN33) power source was not automatically compensated by an alternative power source. This resulted in the loss of Backup Unit content, including Backup Self-refresh low power mode information, OTP emulation configuration, and boot configuration, for instance.
Should we add a fixes for this?
Not so easy to tell as there's a loose dependency with the bootloader. But it's true that switching to automatic never harm. So probably yes.
Quoted 42 lines
Quoted 42 lines
Signed-off-by Nicolas Ferre <[email protected]>--- arch/arm/mach-at91/pm.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)arch/arm/mach-at91/pm.c +17
-3@@ -598,7 +598,21 @@ static int at91_suspend_finish(unsigned long val)return 0 ; } -static void at91_pm_switch_ba_to_vbat (void ) +/** +* at91_pm_switch_ba_to_auto() - Configure Backup Unit Power Switch +* to automatic/hardware mode. +* +* The Backup Unit Power Switch can be managed either by software or hardware. +* Enabling hardware mode allows the automatic transition of power between +* VDDANA (or VDDIN33) and VDDBU (or VBAT, respectively), based on the +* availability of these power sources. +* +* If the Backup Unit Power Switch is already in automatic mode, no action is +* required. If it is in software-controlled mode, it is switched to automatic +* mode to enhance safety and eliminate the need for toggling between power +* sources. +*/ +static void at91_pm_switch_ba_to_auto (void ) {unsigned int offset = offsetof(struct at91_pm_sfrbu_regs , pswbu);unsigned int val;@@ -609,24 +623,19 @@ static void at91_pm_switch_ba_to_vbat(void) val =readl (soc_pm.data.sfrbu + offset); -/* Already on VBAT. */ -if (!(val & soc_pm.sfrbu_regs.pswbu.state)) +/* Already on auto/hardware. */ +if (!(val & soc_pm.sfrbu_regs.pswbu.ctrl))return ;
Quoted 4 lines
arch/arm/mach-at91/pm.c static void at91_pm_switch_ba_to_vbat(void) · line 616
Quoted 1 line
arch/arm/mach-at91/pm.c +0
-1- val &= ~soc_pm.sfrbu_regs.pswbu.softsw;It seems that softsw and state members of at91_pm_sfrbu_regs.pswbu along with their initialization could be dropped. What do you think?
I think that I tried when writing the patch but I think that there's a little difference with sama5d2 register layout. Give me a couple more days to come back to this and verify.
Quoted 25 lines
I can do it while applying, if any.
Thank you,
ClaudiuQuoted 19 lines
arch/arm/mach-at91/pm.c +3
-7- val |= soc_pm.sfrbu_regs.pswbu.key | soc_pm.sfrbu_regs.pswbu.ctrl; + val &= ~soc_pm.sfrbu_regs.pswbu.ctrl; + val |= soc_pm.sfrbu_regs.pswbu.key;writel (val, soc_pm.data.sfrbu + offset); - -/* Wait for update. */ - val =readl (soc_pm.data.sfrbu + offset); -while (val & soc_pm.sfrbu_regs.pswbu.state) - val =readl (soc_pm.data.sfrbu + offset); }static void at91_pm_suspend (suspend_state_t state) {if (soc_pm.data.mode ==AT91_PM_BACKUP ) { -at91_pm_switch_ba_to_vbat (); +at91_pm_switch_ba_to_auto ();cpu_suspend (0 , at91_suspend_finish);
Nicolas Ferre
maintainerClaudiu,
Quoted 71 lines · Nicolas Ferre
Quoted 17 lines · Claudiu Beznea
Hi, Nicolas,
Quoted 9 lines · On 25.11.2024 18:56, [email protected] wrote:
From: Nicolas Ferre <[email protected]>
Change how the Backup Unit Power is configured and force the automatic/hardware mode.
This change eliminates the need for software management of the power switch, ensuring it transitions to the backup power source before entering low power modes.This is done in the only locaton where this swich was configured. It's
s/locaton/location
Quoted 2 lines
usually done in the bootloader.
Quoted 7 lines
Quoted 5 lines
Previously, the loss of the VDDANA (or VDDIN33) power source was not automatically compensated by an alternative power source. This resulted in the loss of Backup Unit content, including Backup Self-refresh low power mode information, OTP emulation configuration, and boot configuration, for instance.
Should we add a fixes for this?
Not so easy to tell as there's a loose dependency with the bootloader. But it's true that switching to automatic never harm. So probably yes.
Quoted 42 lines
Quoted 42 lines
Signed-off-by Nicolas Ferre <[email protected]>--- arch/arm/mach-at91/pm.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)arch/arm/mach-at91/pm.c +17
-3@@ -598,7 +598,21 @@ static int at91_suspend_finish(unsigned long val)return 0 ; } -static void at91_pm_switch_ba_to_vbat (void ) +/** +* at91_pm_switch_ba_to_auto() - Configure Backup Unit Power Switch +* to automatic/hardware mode. +* +* The Backup Unit Power Switch can be managed either by software or hardware. +* Enabling hardware mode allows the automatic transition of power between +* VDDANA (or VDDIN33) and VDDBU (or VBAT, respectively), based on the +* availability of these power sources. +* +* If the Backup Unit Power Switch is already in automatic mode, no action is +* required. If it is in software-controlled mode, it is switched to automatic +* mode to enhance safety and eliminate the need for toggling between power +* sources. +*/ +static void at91_pm_switch_ba_to_auto (void ) {unsigned int offset = offsetof(struct at91_pm_sfrbu_regs , pswbu);unsigned int val;@@ -609,24 +623,19 @@ static void at91_pm_switch_ba_to_vbat(void) val =readl (soc_pm.data.sfrbu + offset); -/* Already on VBAT. */ -if (!(val & soc_pm.sfrbu_regs.pswbu.state)) +/* Already on auto/hardware. */ +if (!(val & soc_pm.sfrbu_regs.pswbu.ctrl))return ;
Quoted 8 lines
Quoted 4 lines
arch/arm/mach-at91/pm.c static void at91_pm_switch_ba_to_vbat(void) · line 616
Quoted 1 line
arch/arm/mach-at91/pm.c +0
-1- val &= ~soc_pm.sfrbu_regs.pswbu.softsw;It seems that softsw and state members of at91_pm_sfrbu_regs.pswbu along with their initialization could be dropped. What do you think?
I think that I tried when writing the patch but I think that there's a little difference with sama5d2 register layout. Give me a couple more days to come back to this and verify.
Ok, I remember now: I was wondering if I needed to remove the whole sfrbu_regs.xxx mechanism and define more generically the content of include/soc/at91/sama7-sfrbu.h for sama5d2, but if we need one day to use the STATE bit or even the SMCTRL bit of sama5d2, then it should be kept.
So, now that the mechanism is in place, I would prefer that we keep it: okay for you?
Do you want me to re-spin a v2 for the rest?
Best regards,
Nicolas
Quoted 27 lines
Quoted 25 lines
I can do it while applying, if any.
Thank you,
ClaudiuQuoted 19 lines
arch/arm/mach-at91/pm.c +3
-7- val |= soc_pm.sfrbu_regs.pswbu.key | soc_pm.sfrbu_regs.pswbu.ctrl; + val &= ~soc_pm.sfrbu_regs.pswbu.ctrl; + val |= soc_pm.sfrbu_regs.pswbu.key;writel (val, soc_pm.data.sfrbu + offset); - -/* Wait for update. */ - val =readl (soc_pm.data.sfrbu + offset); -while (val & soc_pm.sfrbu_regs.pswbu.state) - val =readl (soc_pm.data.sfrbu + offset); }static void at91_pm_suspend (suspend_state_t state) {if (soc_pm.data.mode ==AT91_PM_BACKUP ) { -at91_pm_switch_ba_to_vbat (); +at91_pm_switch_ba_to_auto ();cpu_suspend (0 , at91_suspend_finish);
Claudiu Beznea
maintainerHi, Nicolas,
Quoted 88 lines · Nicolas Ferre
Claudiu,
Quoted 76 lines · Nicolas Ferre
Quoted 17 lines · Claudiu Beznea
Hi, Nicolas,
Quoted 9 lines · On 25.11.2024 18:56, [email protected] wrote:
From: Nicolas Ferre <[email protected]>
Change how the Backup Unit Power is configured and force the automatic/hardware mode.
This change eliminates the need for software management of the power switch, ensuring it transitions to the backup power source before entering low power modes.This is done in the only locaton where this swich was configured. It's
s/locaton/location
Quoted 2 lines
usually done in the bootloader.
Quoted 7 lines
Quoted 5 lines
Previously, the loss of the VDDANA (or VDDIN33) power source was not automatically compensated by an alternative power source. This resulted in the loss of Backup Unit content, including Backup Self-refresh low power mode information, OTP emulation configuration, and boot configuration, for instance.
Should we add a fixes for this?
Not so easy to tell as there's a loose dependency with the bootloader. But it's true that switching to automatic never harm. So probably yes.
Quoted 47 lines
Quoted 47 lines
Signed-off-by Nicolas Ferre <[email protected]>---
arch/arm/mach-at91/pm.c| 31 ++++++++++++++++++++-----------1 file changed, 20 insertions(+), 11 deletions(-)arch/arm/mach-at91/pm.c +5
-1@@ -598,7 +598,21 @@ static int at91_suspend_finish(unsigned long val) return 0; } -static void at91_pm_switch_ba_to_vbat (void ) +/** +* at91_pm_switch_ba_to_auto() - Configure Backup Unit Power Switch +* to automatic/hardware mode. +* +* The Backup Unit Power Switch can be managed either by software or hardware.
+ * Enabling hardware mode allows the automatic transition of power between
+ * VDDANA (or VDDIN33) and VDDBU (or VBAT, respectively), based on the
+ * availability of these power sources.
+ *
+ * If the Backup Unit Power Switch is already in automatic mode, no action is
+ * required. If it is in software-controlled mode, it is switched to automatic
+ * mode to enhance safety and eliminate the need for toggling between power
+ * sources.
+ */
+static voidat91_pm_switch_ba_to_auto(void)
{
unsigned int offset =offsetof(struct at91_pm_sfrbu_regs, pswbu); unsigned int val;arch/arm/mach-at91/pm.c +2
-2@@ -609,24 +623,19 @@ static void at91_pm_switch_ba_to_vbat(void) val = readl(soc_pm.data.sfrbu + offset); - /* Already on VBAT. */ - if (!(val & soc_pm.sfrbu_regs.pswbu.state)) + /* Already on auto/hardware. */ + if (!(val & soc_pm.sfrbu_regs.pswbu.ctrl)) return;Quoted 8 lines
Quoted 4 lines
arch/arm/mach-at91/pm.c static void at91_pm_switch_ba_to_vbat(void) · line 616
Quoted 1 line
arch/arm/mach-at91/pm.c +0
-1- val &= ~soc_pm.sfrbu_regs.pswbu.softsw;It seems that softsw and state members of at91_pm_sfrbu_regs.pswbu along with their initialization could be dropped. What do you think?
I think that I tried when writing the patch but I think that there's a little difference with sama5d2 register layout. Give me a couple more days to come back to this and verify.
Quoted 7 lines
Ok, I remember now: I was wondering if I needed to remove the whole sfrbu_regs.xxx mechanism and define more generically the content of
include/soc/at91/sama7-sfrbu.hfor sama5d2, but if we need one day to use the STATE bit or even the SMCTRL bit of sama5d2, then it should be kept.So, now that the mechanism is in place, I would prefer that we keep it:
okay for you?
OK
Quoted 2 lines
Do you want me to re-spin a v2 for the rest?
No, I can handle the insignificant typo while applying.
Thank you,
Claudiu
Quoted 32 lines
Best regards,
NicolasQuoted 27 lines
Quoted 25 lines
I can do it while applying, if any.
Thank you,
ClaudiuQuoted 19 lines
arch/arm/mach-at91/pm.c +3
-7- val |= soc_pm.sfrbu_regs.pswbu.key | soc_pm.sfrbu_regs.pswbu.ctrl; + val &= ~soc_pm.sfrbu_regs.pswbu.ctrl; + val |= soc_pm.sfrbu_regs.pswbu.key; writel(val, soc_pm.data.sfrbu + offset); - - /* Wait for update. */ - val = readl(soc_pm.data.sfrbu + offset); - while (val & soc_pm.sfrbu_regs.pswbu.state) - val = readl(soc_pm.data.sfrbu + offset); } static void at91_pm_suspend(suspend_state_t state) { if (soc_pm.data.mode == AT91_PM_BACKUP) { - at91_pm_switch_ba_to_vbat(); + at91_pm_switch_ba_to_auto(); cpu_suspend(0, at91_suspend_finish);
Quoted 11 lines · On 25.11.2024 18:56, [email protected] wrote:
From: Nicolas Ferre <[email protected]>
Change how the Backup Unit Power is configured and force the automatic/hardware mode.
This change eliminates the need for software management of the power switch, ensuring it transitions to the backup power source before entering low power modes.This is done in the only locaton where this swich was configured. It's usually done in the bootloader.
Quoted 7 lines
Previously, the loss of the VDDANA (or VDDIN33) power source was not automatically compensated by an alternative power source. This resulted in the loss of Backup Unit content, including Backup Self-refresh low power mode information, OTP emulation configuration, and boot configuration, for instance.
Signed-off-by Nicolas Ferre <[email protected]>
I've added the fixes tag, s/locaton/location, s/swich/switch.
Applied to at91-soc, thanks!
Nicolas Ferre
maintainerQuoted 18 lines · Claudiu Beznea
Quoted 17 lines · On 25.11.2024 18:56, [email protected] wrote:
From: Nicolas Ferre <[email protected]>
Change how the Backup Unit Power is configured and force the automatic/hardware mode.
This change eliminates the need for software management of the power switch, ensuring it transitions to the backup power source before entering low power modes.This is done in the only locaton where this swich was configured. It's usually done in the bootloader.
Previously, the loss of the VDDANA (or VDDIN33) power source was not automatically compensated by an alternative power source. This resulted in the loss of Backup Unit content, including Backup Self-refresh low power mode information, OTP emulation configuration, and boot configuration, for instance.
Quoted 3 lines
Quoted 1 line
Signed-off-by Nicolas Ferre <[email protected]>I've added the fixes tag, s/locaton/location, s/swich/switch.
Thanks for your help Claudiu. Regards,
Nicolas
Quoted 2 lines
Applied to at91-soc, thanks!