[U-Boot] [PATCH 0/4] Add a new poweroff command and implement it for sunxi

Hi All,
I've had this idea that it would be good to have a poweroff command in u-boot in my head for a while now. The reason being that during u-boot development one often stays in just u-boot (e.g. when testing usb kbd support), when I'm then done testing having a poweroff command would be useful, esp. on devices with builtin batteries like tablets where one cannot just pull the powerplug.
So when Michael (in the Cc, author of 2 of the patches) asked me if there was a simple u-boot task he could help with I suggested adding a poweroff command, the result of which is this patch-set.
Tom, can you review the non sunxi specific cmd_boot patch (patch 1/4) please ?
Regards,
Hans

From: Michael van Slingerland michael@deviousops.nl
Add a 'poweroff' command to boot commands, this only gets enabled if the board Kconfig does a "select CMD_POWEROFF".
Signed-off-by: Michael van Slingerland michael@deviousops.nl [hdegoede@redhat.com: Make the cmd conditional on a CMD_POWEROFF Kconfig] Signed-off-by: Hans de Goede hdegoede@redhat.com --- common/Kconfig | 3 +++ common/cmd_boot.c | 8 ++++++++ include/command.h | 3 +++ 3 files changed, 14 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig index ccf5475..9d446bf 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -184,6 +184,9 @@ config CMD_XIMG help Extract a part of a multi-image.
+config CMD_POWEROFF + bool + endmenu
menu "Environment commands" diff --git a/common/cmd_boot.c b/common/cmd_boot.c index 8f2e070..5a8f912 100644 --- a/common/cmd_boot.c +++ b/common/cmd_boot.c @@ -61,3 +61,11 @@ U_BOOT_CMD( "Perform RESET of the CPU", "" ); + +#ifdef CONFIG_CMD_POWEROFF +U_BOOT_CMD( + poweroff, 1, 0, do_poweroff, + "Perform POWEROFF", + "" +); +#endif diff --git a/include/command.h b/include/command.h index 2ae9b6c..30bc327 100644 --- a/include/command.h +++ b/include/command.h @@ -110,6 +110,9 @@ extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, char *const argv[]);
extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); +#ifdef CONFIG_CMD_POWEROFF +extern int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); +#endif
/* * Error codes that commands return to cmd_process(). We use the standard 0

On Sun, Dec 20, 2015 at 04:41:32PM +0100, Hans de Goede wrote:
From: Michael van Slingerland michael@deviousops.nl
Add a 'poweroff' command to boot commands, this only gets enabled if the board Kconfig does a "select CMD_POWEROFF".
Signed-off-by: Michael van Slingerland michael@deviousops.nl [hdegoede@redhat.com: Make the cmd conditional on a CMD_POWEROFF Kconfig] Signed-off-by: Hans de Goede hdegoede@redhat.com
common/Kconfig | 3 +++ common/cmd_boot.c | 8 ++++++++ include/command.h | 3 +++ 3 files changed, 14 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig index ccf5475..9d446bf 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -184,6 +184,9 @@ config CMD_XIMG help Extract a part of a multi-image.
+config CMD_POWEROFF
- bool
endmenu
menu "Environment commands" diff --git a/common/cmd_boot.c b/common/cmd_boot.c index 8f2e070..5a8f912 100644 --- a/common/cmd_boot.c +++ b/common/cmd_boot.c @@ -61,3 +61,11 @@ U_BOOT_CMD( "Perform RESET of the CPU", "" );
+#ifdef CONFIG_CMD_POWEROFF +U_BOOT_CMD(
- poweroff, 1, 0, do_poweroff,
- "Perform POWEROFF",
" of the device"
- ""
+); +#endif diff --git a/include/command.h b/include/command.h index 2ae9b6c..30bc327 100644 --- a/include/command.h +++ b/include/command.h @@ -110,6 +110,9 @@ extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, char *const argv[]);
extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); +#ifdef CONFIG_CMD_POWEROFF +extern int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); +#endif
No need for ifdef/endif (yes, there's others in the file like that but that's something to fix sometime). Thanks!

Adds poweroff support for axp152 pmic.
Signed-off-by: Hans de Goede hdegoede@redhat.com --- drivers/power/Kconfig | 1 + drivers/power/axp152.c | 12 ++++++++++++ 2 files changed, 13 insertions(+)
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index e86dd72..de32828 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -20,6 +20,7 @@ config SUNXI_NO_PMIC config AXP152_POWER boolean "axp152 pmic support" depends on MACH_SUN5I + select CMD_POWEROFF ---help--- Select this to enable support for the axp152 pmic found on most A10s boards. diff --git a/drivers/power/axp152.c b/drivers/power/axp152.c index 2972586..cd07275 100644 --- a/drivers/power/axp152.c +++ b/drivers/power/axp152.c @@ -5,6 +5,7 @@ * SPDX-License-Identifier: GPL-2.0+ */ #include <common.h> +#include <command.h> #include <asm/arch/pmic_bus.h> #include <axp_pmic.h>
@@ -78,3 +79,14 @@ int axp_init(void)
return 0; } + +int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + pmic_bus_write(AXP152_SHUTDOWN, AXP152_POWEROFF); + + /* infinite loop during shutdown */ + while (1) {} + + /* not reached */ + return 0; +}

From: Michael van Slingerland michael@deviousops.nl
Adds poweroff support for axp209 pmic.
Signed-off-by: Michael van Slingerland michael@deviousops.nl Signed-off-by: Hans de Goede hdegoede@redhat.com --- drivers/power/Kconfig | 1 + drivers/power/axp209.c | 12 ++++++++++++ 2 files changed, 13 insertions(+)
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index de32828..52c9e61 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -28,6 +28,7 @@ config AXP152_POWER config AXP209_POWER boolean "axp209 pmic support" depends on MACH_SUN4I || MACH_SUN5I || MACH_SUN7I + select CMD_POWEROFF ---help--- Select this to enable support for the axp209 pmic found on most A10, A13 and A20 boards. diff --git a/drivers/power/axp209.c b/drivers/power/axp209.c index 71aa000..fc162a1 100644 --- a/drivers/power/axp209.c +++ b/drivers/power/axp209.c @@ -6,6 +6,7 @@ */
#include <common.h> +#include <command.h> #include <asm/arch/pmic_bus.h> #include <axp_pmic.h>
@@ -168,3 +169,14 @@ int axp_init(void)
return 0; } + +int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + pmic_bus_write(AXP209_SHUTDOWN, AXP209_POWEROFF); + + /* infinite loop during shutdown */ + while (1) {} + + /* not reached */ + return 0; +}

Adds poweroff support for axp221 pmic.
Signed-off-by: Hans de Goede hdegoede@redhat.com --- drivers/power/Kconfig | 1 + drivers/power/axp221.c | 12 ++++++++++++ include/axp221.h | 2 ++ 3 files changed, 15 insertions(+)
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 52c9e61..dfd60aa 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -36,6 +36,7 @@ config AXP209_POWER config AXP221_POWER boolean "axp221 / axp223 pmic support" depends on MACH_SUN6I || MACH_SUN8I_A23 || MACH_SUN8I_A33 + select CMD_POWEROFF ---help--- Select this to enable support for the axp221/axp223 pmic found on most A23 and A31 boards. diff --git a/drivers/power/axp221.c b/drivers/power/axp221.c index 65802e4..8acadf0 100644 --- a/drivers/power/axp221.c +++ b/drivers/power/axp221.c @@ -11,6 +11,7 @@ */
#include <common.h> +#include <command.h> #include <errno.h> #include <asm/arch/pmic_bus.h> #include <axp_pmic.h> @@ -312,3 +313,14 @@ int axp_get_sid(unsigned int *sid)
return 0; } + +int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + pmic_bus_write(AXP221_SHUTDOWN, AXP221_SHUTDOWN_POWEROFF); + + /* infinite loop during shutdown */ + while (1) {} + + /* not reached */ + return 0; +} diff --git a/include/axp221.h b/include/axp221.h index 0ee21b6..04cd8c2 100644 --- a/include/axp221.h +++ b/include/axp221.h @@ -45,6 +45,8 @@ #define AXP221_ALDO3_CTRL 0x2a #define AXP221_VBUS_IPSOUT 0x30 #define AXP221_VBUS_IPSOUT_DRIVEBUS (1 << 2) +#define AXP221_SHUTDOWN 0x32 +#define AXP221_SHUTDOWN_POWEROFF (1 << 7) #define AXP221_MISC_CTRL 0x8f #define AXP221_MISC_CTRL_N_VBUSEN_FUNC (1 << 4) #define AXP221_PAGE 0xff

On Sun, 2015-12-20 at 16:41 +0100, Hans de Goede wrote:
Hi All,
I've had this idea that it would be good to have a poweroff command in u-boot in my head for a while now. The reason being that during u-boot development one often stays in just u-boot (e.g. when testing usb kbd support), when I'm then done testing having a poweroff command would be useful, esp. on devices with builtin batteries like tablets where one cannot just pull the powerplug.
Patches #2..#4: Acked-by: Ian Campbell ijc@hellion.org.uk
#1 looks fine to me too, modulo Tom's comments.
Ian.
participants (3)
-
Hans de Goede
-
Ian Campbell
-
Tom Rini