sunxi: Add option to prevent boot on plug-in
Subsystems (4)
v2 cover sunxi: Add option to prevent boot on plug-in
Sometimes it is desirable to prevent a board from automatically booting as soon as the power cable is plugged in. For boards with an AXP PMIC, we can actually query the power up source.
Add a AXP_DISABLE_BOOT_ON_POWERON Kconfig option to enable this behaviour.
Patch 1 prepares the PMIC header files to export the same symbol, which Chris' patch 2 then uses to do the actual work.
I rearranged Chris' code to get rid of the nasty #ifdef's. This function is already a "good" example of why #ifdefs are bad, we don't need to add to that. I will try to clean that up further, but for now this doesn't need to block this patch.
Cheers,
Andre.
Andre Przywara (1):
pmic: axp: define ALDO_IN startup bit
Chris Morgan (1):
sunxi: Add option to prevent booting on power plug-in
arch/arm/mach-sunxi/Kconfig | 10 ++++++++++ board/sunxi/board.c | 11 +++++++++++ include/axp152.h | 2 ++ include/axp209.h | 3 ++- include/axp221.h | 3 ++- include/axp305.h | 3 +++ include/axp809.h | 3 ++- include/axp818.h | 3 ++- 8 files changed, 34 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 pmic: axp: define ALDO_IN startup bit
Most AXP PMICs feature a "startup source" register, which keeps information about how the PMIC started operation. Bit 0 in there means it has been started by "plugging in the power cable".
Define a symbol in each PMIC's header file to be able to use that register and bit later on.
--- include/axp152.h | 2 ++ include/axp209.h | 3 ++- include/axp221.h | 3 ++- include/axp305.h | 3 +++ include/axp809.h | 3 ++- include/axp818.h | 3 ++- 6 files changed, 13 insertions(+), 4 deletions(-)
include/axp152.h +2 -0
@@ -16,6 +16,8 @@ enum axp152_reg {/* For axp_gpio.c */ #ifdef CONFIG_AXP152_POWER +#define AXP_POWER_STATUS 0x00 +#define AXP_POWER_STATUS_ALDO_IN BIT(0)#define AXP_GPIO0_CTRL 0x90#define AXP_GPIO1_CTRL 0x91#define AXP_GPIO2_CTRL 0x92
include/axp209.h +2 -1
@@ -76,7 +76,8 @@ enum axp209_reg {/* For axp_gpio.c */ #ifdef CONFIG_AXP209_POWER #define AXP_POWER_STATUS 0x00 -#define AXP_POWER_STATUS_VBUS_PRESENT BIT(5) +#define AXP_POWER_STATUS_ALDO_IN BIT(0) +#define AXP_POWER_STATUS_VBUS_PRESENT BIT(5)#define AXP_GPIO0_CTRL 0x90#define AXP_GPIO1_CTRL 0x92#define AXP_GPIO2_CTRL 0x93
include/axp221.h +2 -1
@@ -52,7 +52,8 @@/* For axp_gpio.c */ #ifdef CONFIG_AXP221_POWER #define AXP_POWER_STATUS 0x00 -#define AXP_POWER_STATUS_VBUS_PRESENT (1 << 5) +#define AXP_POWER_STATUS_ALDO_IN BIT(0) +#define AXP_POWER_STATUS_VBUS_PRESENT BIT(5)#define AXP_VBUS_IPSOUT 0x30#define AXP_VBUS_IPSOUT_DRIVEBUS (1 << 2)#define AXP_MISC_CTRL 0x8f
include/axp305.h +3 -0
@@ -15,3 +15,6 @@ enum axp305_reg {#define AXP305_OUTPUT_CTRL1_DCDCD_EN (1 << 3)#define AXP305_POWEROFF (1 << 7) + +#define AXP_POWER_STATUS 0x00 +#define AXP_POWER_STATUS_ALDO_IN BIT(0)
include/axp809.h +2 -1
@@ -46,7 +46,8 @@/* For axp_gpio.c */ #ifdef CONFIG_AXP809_POWER #define AXP_POWER_STATUS 0x00 -#define AXP_POWER_STATUS_VBUS_PRESENT (1 << 5) +#define AXP_POWER_STATUS_ALDO_IN BIT(0) +#define AXP_POWER_STATUS_VBUS_PRESENT BIT(5)#define AXP_VBUS_IPSOUT 0x30#define AXP_VBUS_IPSOUT_DRIVEBUS (1 << 2)#define AXP_MISC_CTRL 0x8f
include/axp818.h +2 -1
@@ -60,7 +60,8 @@/* For axp_gpio.c */ #ifdef CONFIG_AXP818_POWER #define AXP_POWER_STATUS 0x00 -#define AXP_POWER_STATUS_VBUS_PRESENT (1 << 5) +#define AXP_POWER_STATUS_ALDO_IN BIT(0) +#define AXP_POWER_STATUS_VBUS_PRESENT BIT(5)#define AXP_VBUS_IPSOUT 0x30#define AXP_VBUS_IPSOUT_DRIVEBUS (1 << 2)#define AXP_MISC_CTRL 0x8f
Signature · 1 line
2.25.1
PATCH v2 2/2 sunxi: Add option to prevent booting on power plug-in
In reply to Andre PrzywaraFrom: Chris Morgan <[email protected]>
For sunxi boards with the AXP209, AXP221, AXP809, and AXP818 PMICs (plus possibly others, I only confirmed the datasheets for these), it is sometimes desirable to not boot whenever the device is plugged in. An example would be when using the NTC CHIP inside a PocketCHIP.
This provides a configurable option to check if bit 0 of register 0 of the PMIC says it was powered because of a power button press (0) or a plug-in event (1). If the value is 1 and this option is selected, the device shuts down shortly after printing a message to console stating the reason why it's shutting down. Powering up the board with the power button is not affected.
adapt board.c to generic AXP symbols
--- arch/arm/mach-sunxi/Kconfig | 10 ++++++++++ board/sunxi/board.c | 11 +++++++++++ 2 files changed, 21 insertions(+)
arch/arm/mach-sunxi/Kconfig +10 -0
@@ -785,6 +785,16 @@ config AXP_GPIO ---help--- Say Y here to enable support for the gpio pins of the axp PMIC ICs. +config AXP_DISABLE_BOOT_ON_POWERON + bool "Disable device boot on power plug-in" + depends on AXP209_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER + default n + ---help--- + Say Y here to prevent the device from booting up because of a plug-in + event. When set, the device will boot into the SPL briefly to + determine why it was powered on, and if it was determined because of + a plug-in event instead of a button press event it will shut back off. + config VIDEO_SUNXI bool "Enable graphical uboot console on HDMI, LCD or VGA" depends on !MACH_SUN8I_A83T
board/sunxi/board.c +11 -0
@@ -27,6 +27,7 @@#include <asm/arch/dram.h> #include <asm/arch/mmc.h> #include <asm/arch/prcm.h> +#include <asm/arch/pmic_bus.h> #include <asm/arch/spl.h> #include <asm/global_data.h> #include <linux/delay.h>
@@ -601,6 +602,16 @@ void sunxi_board_init(void) defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER power_failed =axp_init (); +if (IS_ENABLED (AXP_DISABLE_BOOT_ON_POWERON ) && !power_failed) { +u8 boot_reason; + +pmic_bus_read (AXP_POWER_STATUS , &boot_reason); +if (boot_reason &AXP_POWER_STATUS_ALDO_IN ) { +printf ("Power on by plug-in, shutting down.\n" ); +pmic_bus_write (0x32 ,BIT (7 )); + } + } +#if definedCONFIG_AXP221_POWER || definedCONFIG_AXP809_POWER || \ definedCONFIG_AXP818_POWER power_failed |=axp_set_dcdc1 (CONFIG_AXP_DCDC1_VOLT );
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] sunxi: Add option to prevent booting on power plug-in
Quoted 13 lines · Andre Przywara
From: Chris Morgan <[email protected]>
For sunxi boards with the AXP209, AXP221, AXP809, and AXP818 PMICs (plus possibly others, I only confirmed the datasheets for these), it is sometimes desirable to not boot whenever the device is plugged in. An example would be when using the NTC CHIP inside a PocketCHIP.
This provides a configurable option to check if bit 0 of register 0 of the PMIC says it was powered because of a power button press (0) or a plug-in event (1). If the value is 1 and this option is selected, the device shuts down shortly after printing a message to console stating the reason why it's shutting down. Powering up the board with the power button is not affected.
Quoted 45 lines
Signed-off-by Chris Morgan <[email protected]>[Andre: reword to speak of boot, remove #ifdefs]Signed-off-by Andre Przywara <[email protected]>adapt
board.cto generic AXP symbols--- arch/arm/mach-sunxi/Kconfig | 10 ++++++++++ board/sunxi/board.c | 11 +++++++++++ 2 files changed, 21 insertions(+)arch/arm/mach-sunxi/Kconfig +10
-0@@ -785,6 +785,16 @@ config AXP_GPIO ---help--- Say Y here to enable support for the gpio pins of the axp PMIC ICs. +config AXP_DISABLE_BOOT_ON_POWERON + bool "Disable device boot on power plug-in" + depends on AXP209_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER + default n + ---help--- + Say Y here to prevent the device from booting up because of a plug-in + event. When set, the device will boot into the SPL briefly to + determine why it was powered on, and if it was determined because of + a plug-in event instead of a button press event it will shut back off. + config VIDEO_SUNXI bool "Enable graphical uboot console on HDMI, LCD or VGA" depends on !MACH_SUN8I_A83Tboard/sunxi/board.c +1
-0@@ -27,6 +27,7 @@#include <asm/arch/dram.h> #include <asm/arch/mmc.h> #include <asm/arch/prcm.h> +#include <asm/arch/pmic_bus.h> #include <asm/arch/spl.h> #include <asm/global_data.h> #include <linux/delay.h>
board/sunxi/board.c void sunxi_board_init(void) · line 605
Quoted 4 lines
board/sunxi/board.c +1
-0@@ -601,6 +602,16 @@ void sunxi_board_init(void) defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER power_failed =axp_init (); +if (IS_ENABLED (AXP_DISABLE_BOOT_ON_POWERON ) && !power_failed) {
This doesn't work for me unless I change this toIS_ENABLED(CONFIG_AXP_DISABLE_BOOT_ON_POWERON)
With this change though, it works just fine on my use case.
Quoted 15 lines
board/sunxi/board.c +9
-0+u8 boot_reason; + +pmic_bus_read (AXP_POWER_STATUS , &boot_reason); +if (boot_reason &AXP_POWER_STATUS_ALDO_IN ) { +printf ("Power on by plug-in, shutting down.\n" ); +pmic_bus_write (0x32 ,BIT (7 )); + } + } +#if definedCONFIG_AXP221_POWER || definedCONFIG_AXP809_POWER || \ definedCONFIG_AXP818_POWER power_failed |=axp_set_dcdc1 (CONFIG_AXP_DCDC1_VOLT );Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] sunxi: Add option to prevent booting on power plug-in
On Fri, 21 Jan 2022 10:35:33 -0600
Chris Morgan <[email protected]> wrote:
Hi Chris,
Quoted 15 lines · Andre Przywara
Quoted 13 lines
From: Chris Morgan <[email protected]>
For sunxi boards with the AXP209, AXP221, AXP809, and AXP818 PMICs (plus possibly others, I only confirmed the datasheets for these), it is sometimes desirable to not boot whenever the device is plugged in. An example would be when using the NTC CHIP inside a PocketCHIP.
This provides a configurable option to check if bit 0 of register 0 of the PMIC says it was powered because of a power button press (0) or a plug-in event (1). If the value is 1 and this option is selected, the device shuts down shortly after printing a message to console stating the reason why it's shutting down. Powering up the board with the power button is not affected.
Quoted 1 line
Tested-by Chris Morgan <[email protected]>
Thanks (although please refrain from using this tag if it's actually broken, as you point out below)
Quoted 49 lines
Quoted 49 lines
Signed-off-by Chris Morgan <[email protected]>[Andre: reword to speak of boot, remove #ifdefs]Signed-off-by Andre Przywara <[email protected]>adapt
board.cto generic AXP symbols--- arch/arm/mach-sunxi/Kconfig | 10 ++++++++++ board/sunxi/board.c | 11 +++++++++++ 2 files changed, 21 insertions(+)arch/arm/mach-sunxi/Kconfig +10
-0@@ -785,6 +785,16 @@ config AXP_GPIO ---help--- Say Y here to enable support for the gpio pins of the axp PMIC ICs. +config AXP_DISABLE_BOOT_ON_POWERON + bool "Disable device boot on power plug-in" + depends on AXP209_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER + default n + ---help--- + Say Y here to prevent the device from booting up because of a plug-in + event. When set, the device will boot into the SPL briefly to + determine why it was powered on, and if it was determined because of + a plug-in event instead of a button press event it will shut back off. + config VIDEO_SUNXI bool "Enable graphical uboot console on HDMI, LCD or VGA" depends on !MACH_SUN8I_A83Tboard/sunxi/board.c +1
-0@@ -27,6 +27,7 @@#include <asm/arch/dram.h> #include <asm/arch/mmc.h> #include <asm/arch/prcm.h> +#include <asm/arch/pmic_bus.h> #include <asm/arch/spl.h> #include <asm/global_data.h> #include <linux/delay.h> @@ -601,6 +602,16 @@ void sunxi_board_init(void) defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER power_failed =axp_init ();
Quoted 4 lines
board/sunxi/board.c void sunxi_board_init(void) · line 605
Quoted 1 line
board/sunxi/board.c +1
-0+if (IS_ENABLED (AXP_DISABLE_BOOT_ON_POWERON ) && !power_failed) {This doesn't work for me unless I change this to
IS_ENABLED(CONFIG_AXP_DISABLE_BOOT_ON_POWERON)
Argh, of course, the usual mix up between CONFIG_IS_ENABLED and IS_ENABLED ;-)
I guess you meant with the rest of the line (&& !power_failed) as well?
I will give it some testing tonight, then queue this, if nobody screams.
Cheers,
Andre.
Quoted 18 lines
With this change though, it works just fine on my use case.
Quoted 15 lines
board/sunxi/board.c +9
-0+u8 boot_reason; + +pmic_bus_read (AXP_POWER_STATUS , &boot_reason); +if (boot_reason &AXP_POWER_STATUS_ALDO_IN ) { +printf ("Power on by plug-in, shutting down.\n" ); +pmic_bus_write (0x32 ,BIT (7 )); + } + } +#if definedCONFIG_AXP221_POWER || definedCONFIG_AXP809_POWER || \ definedCONFIG_AXP818_POWER power_failed |=axp_set_dcdc1 (CONFIG_AXP_DCDC1_VOLT );Signature · 1 line
2.25.1