diff mbox

[U-Boot,11/12] sniper: Power off when the power on reason is not a valid one

Message ID 1437398238-27912-12-git-send-email-contact@paulk.fr
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Paul Kocialkowski July 20, 2015, 1:17 p.m. UTC
In most cases, userspace will attempt to power off the device with HALT instead
of POWER_OFF, which triggers a reset instead of a proper power off from the
TWL4030. Hence, it is up to the bootloader to actually turn the device off when
there is no reason to turn it on.

A reboot identified with the OMAP reboot mode bits set is acceptable, as well as
a power on reason from either the power button, USB or charger plug.

Other cases should trigger a power off. Note that for the U-Boot reset command
to take effect, we have to fill-in the OMAP reboot bits.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 board/lge/sniper/sniper.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Tom Rini Aug. 4, 2015, 2:08 a.m. UTC | #1
On Mon, Jul 20, 2015 at 03:17:17PM +0200, Paul Kocialkowski wrote:

> In most cases, userspace will attempt to power off the device with HALT instead
> of POWER_OFF, which triggers a reset instead of a proper power off from the
> TWL4030. Hence, it is up to the bootloader to actually turn the device off when
> there is no reason to turn it on.
> 
> A reboot identified with the OMAP reboot mode bits set is acceptable, as well as
> a power on reason from either the power button, USB or charger plug.
> 
> Other cases should trigger a power off. Note that for the U-Boot reset command
> to take effect, we have to fill-in the OMAP reboot bits.
> 
> Signed-off-by: Paul Kocialkowski <contact@paulk.fr>

Reviewed-by: Tom Rini <trini@konsulko.com>
Tom Rini Aug. 13, 2015, 1:18 p.m. UTC | #2
On Mon, Jul 20, 2015 at 03:17:17PM +0200, Paul Kocialkowski wrote:

> In most cases, userspace will attempt to power off the device with HALT instead
> of POWER_OFF, which triggers a reset instead of a proper power off from the
> TWL4030. Hence, it is up to the bootloader to actually turn the device off when
> there is no reason to turn it on.
> 
> A reboot identified with the OMAP reboot mode bits set is acceptable, as well as
> a power on reason from either the power button, USB or charger plug.
> 
> Other cases should trigger a power off. Note that for the U-Boot reset command
> to take effect, we have to fill-in the OMAP reboot bits.
> 
> Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/board/lge/sniper/sniper.c b/board/lge/sniper/sniper.c
index 97c2ed0..c94a3fa 100644
--- a/board/lge/sniper/sniper.c
+++ b/board/lge/sniper/sniper.c
@@ -94,6 +94,7 @@  int misc_init_r(void)
 	char serial_string[17] = { 0 };
 	char reboot_mode[2] = { 0 };
 	u32 dieid[4] = { 0 };
+	unsigned char data = 0;
 
 	/* Power button reset init */
 
@@ -107,6 +108,18 @@  int misc_init_r(void)
 			setenv("reboot-mode", (char *)reboot_mode);
 
 		omap_reboot_mode_clear();
+	} else {
+		/*
+		 * When not rebooting, valid power on reasons are either the
+		 * power button, charger plug or USB plug.
+		 */
+
+		data |= twl4030_input_power_button();
+		data |= twl4030_input_charger();
+		data |= twl4030_input_usb();
+
+		if (!data)
+			twl4030_power_off();
 	}
 
 	/* Serial number */
@@ -145,6 +158,11 @@  void get_board_serial(struct tag_serialnr *serialnr)
 	}
 }
 
+void reset_misc(void)
+{
+	omap_reboot_mode_store('u');
+}
+
 int fb_set_reboot_flag(void)
 {
 	return omap_reboot_mode_store('b');