All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] sunxi: Add option to prevent boot on plug-in
@ 2022-01-21 13:37 Andre Przywara
  2022-01-21 13:37 ` [PATCH v2 1/2] pmic: axp: define ALDO_IN startup bit Andre Przywara
  2022-01-21 13:37 ` [PATCH v2 2/2] sunxi: Add option to prevent booting on power plug-in Andre Przywara
  0 siblings, 2 replies; 5+ messages in thread
From: Andre Przywara @ 2022-01-21 13:37 UTC (permalink / raw)
  To: Jagan Teki
  Cc: Chris Morgan, Chris Morgan, Jernej Skrabec, Samuel Holland,
	u-boot, linux-sunxi, Tom Rini

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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] pmic: axp: define ALDO_IN startup bit
  2022-01-21 13:37 [PATCH v2 0/2] sunxi: Add option to prevent boot on plug-in Andre Przywara
@ 2022-01-21 13:37 ` Andre Przywara
  2022-01-21 13:37 ` [PATCH v2 2/2] sunxi: Add option to prevent booting on power plug-in Andre Przywara
  1 sibling, 0 replies; 5+ messages in thread
From: Andre Przywara @ 2022-01-21 13:37 UTC (permalink / raw)
  To: Jagan Teki
  Cc: Chris Morgan, Chris Morgan, Jernej Skrabec, Samuel Holland,
	u-boot, linux-sunxi, Tom Rini

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.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 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(-)

diff --git a/include/axp152.h b/include/axp152.h
index 10d845fec4..bac6526a36 100644
--- a/include/axp152.h
+++ b/include/axp152.h
@@ -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
diff --git a/include/axp209.h b/include/axp209.h
index 30399a8d62..414f88a32c 100644
--- a/include/axp209.h
+++ b/include/axp209.h
@@ -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
diff --git a/include/axp221.h b/include/axp221.h
index a02e9b4f64..8dfcc5b5a2 100644
--- a/include/axp221.h
+++ b/include/axp221.h
@@ -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
diff --git a/include/axp305.h b/include/axp305.h
index 225c5040a3..0a42bc6804 100644
--- a/include/axp305.h
+++ b/include/axp305.h
@@ -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)
diff --git a/include/axp809.h b/include/axp809.h
index 430dbef622..8082e402e2 100644
--- a/include/axp809.h
+++ b/include/axp809.h
@@ -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
diff --git a/include/axp818.h b/include/axp818.h
index 8bac6b67ca..8ac517a2bf 100644
--- a/include/axp818.h
+++ b/include/axp818.h
@@ -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
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] sunxi: Add option to prevent booting on power plug-in
  2022-01-21 13:37 [PATCH v2 0/2] sunxi: Add option to prevent boot on plug-in Andre Przywara
  2022-01-21 13:37 ` [PATCH v2 1/2] pmic: axp: define ALDO_IN startup bit Andre Przywara
@ 2022-01-21 13:37 ` Andre Przywara
  2022-01-21 16:35   ` Chris Morgan
  1 sibling, 1 reply; 5+ messages in thread
From: Andre Przywara @ 2022-01-21 13:37 UTC (permalink / raw)
  To: Jagan Teki
  Cc: Chris Morgan, Chris Morgan, Jernej Skrabec, Samuel Holland,
	u-boot, linux-sunxi, Tom Rini

From: Chris Morgan <macromorgan@hotmail.com>

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.

Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
[Andre: reword to speak of boot, remove #ifdefs]
Signed-off-by: Andre Przywara <andre.przywara@arm.com>

adapt board.c to generic AXP symbols
---
 arch/arm/mach-sunxi/Kconfig | 10 ++++++++++
 board/sunxi/board.c         | 11 +++++++++++
 2 files changed, 21 insertions(+)

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 2c18cf02d1..d7f9a03152 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -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
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index fdbcd40269..3b5e7f3cdc 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -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 defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
 	defined CONFIG_AXP818_POWER
 	power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] sunxi: Add option to prevent booting on power plug-in
  2022-01-21 13:37 ` [PATCH v2 2/2] sunxi: Add option to prevent booting on power plug-in Andre Przywara
@ 2022-01-21 16:35   ` Chris Morgan
  2022-01-21 16:43     ` Andre Przywara
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Morgan @ 2022-01-21 16:35 UTC (permalink / raw)
  To: Andre Przywara
  Cc: Jagan Teki, Chris Morgan, Jernej Skrabec, Samuel Holland, u-boot,
	linux-sunxi, Tom Rini

On Fri, Jan 21, 2022 at 01:37:32PM +0000, Andre Przywara wrote:
> From: Chris Morgan <macromorgan@hotmail.com>
> 
> 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.

Tested-By: Chris Morgan <macromorgan@hotmail.com>

> 
> Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
> [Andre: reword to speak of boot, remove #ifdefs]
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> 
> adapt board.c to generic AXP symbols
> ---
>  arch/arm/mach-sunxi/Kconfig | 10 ++++++++++
>  board/sunxi/board.c         | 11 +++++++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> index 2c18cf02d1..d7f9a03152 100644
> --- a/arch/arm/mach-sunxi/Kconfig
> +++ b/arch/arm/mach-sunxi/Kconfig
> @@ -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
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index fdbcd40269..3b5e7f3cdc 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -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) {

This doesn't work for me unless I change this to
IS_ENABLED(CONFIG_AXP_DISABLE_BOOT_ON_POWERON)

With this change though, it works just fine on my use case.

> +		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 defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
>  	defined CONFIG_AXP818_POWER
>  	power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT);
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] sunxi: Add option to prevent booting on power plug-in
  2022-01-21 16:35   ` Chris Morgan
@ 2022-01-21 16:43     ` Andre Przywara
  0 siblings, 0 replies; 5+ messages in thread
From: Andre Przywara @ 2022-01-21 16:43 UTC (permalink / raw)
  To: Chris Morgan
  Cc: Jagan Teki, Chris Morgan, Jernej Skrabec, Samuel Holland, u-boot,
	linux-sunxi, Tom Rini

On Fri, 21 Jan 2022 10:35:33 -0600
Chris Morgan <macromorgan@hotmail.com> wrote:

Hi Chris,

> On Fri, Jan 21, 2022 at 01:37:32PM +0000, Andre Przywara wrote:
> > From: Chris Morgan <macromorgan@hotmail.com>
> > 
> > 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.  
> 
> Tested-By: Chris Morgan <macromorgan@hotmail.com>

Thanks (although please refrain from using this tag if it's actually
broken, as you point out below)

> 
> > 
> > Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
> > [Andre: reword to speak of boot, remove #ifdefs]
> > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> > 
> > adapt board.c to generic AXP symbols
> > ---
> >  arch/arm/mach-sunxi/Kconfig | 10 ++++++++++
> >  board/sunxi/board.c         | 11 +++++++++++
> >  2 files changed, 21 insertions(+)
> > 
> > diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> > index 2c18cf02d1..d7f9a03152 100644
> > --- a/arch/arm/mach-sunxi/Kconfig
> > +++ b/arch/arm/mach-sunxi/Kconfig
> > @@ -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
> > diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> > index fdbcd40269..3b5e7f3cdc 100644
> > --- a/board/sunxi/board.c
> > +++ b/board/sunxi/board.c
> > @@ -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) {  
> 
> 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.


> 
> With this change though, it works just fine on my use case.
> 
> > +		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 defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
> >  	defined CONFIG_AXP818_POWER
> >  	power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT);
> > -- 
> > 2.25.1
> >   


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-21 16:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-21 13:37 [PATCH v2 0/2] sunxi: Add option to prevent boot on plug-in Andre Przywara
2022-01-21 13:37 ` [PATCH v2 1/2] pmic: axp: define ALDO_IN startup bit Andre Przywara
2022-01-21 13:37 ` [PATCH v2 2/2] sunxi: Add option to prevent booting on power plug-in Andre Przywara
2022-01-21 16:35   ` Chris Morgan
2022-01-21 16:43     ` Andre Przywara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.