Skip to contentSkip to conversation

Add a new poweroff command and implement it for sunxi

PATCH Superseded Hans de Goede 3 participants 7 messages Dec 20, 2015 X-powers multifunction PMIC device drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover 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

#1 lore raw

PATCH 1/4 cmd_boot: Add a poweroff command

From: Michael van Slingerland <[email protected]>

Add a 'poweroff' command to boot commands, this only gets enabled if the board Kconfig does a "select CMD_POWEROFF".

[hdegoede at redhat.com: Make the cmd conditional on a CMD_POWEROFF Kconfig]
---
 common/Kconfig    | 3 +++
 common/cmd_boot.c | 8 ++++++++
 include/command.h | 3 +++
 3 files changed, 14 insertions(+)
common/Kconfig +3 -0
index ccf5475..9d446bf 100644
@@ -184,6 +184,9 @@ config CMD_XIMG
 	help
 	  Extract a part of a multi-image.
 
+config CMD_POWEROFF
+	bool
+
 endmenu
 
 menu "Environment commands"
common/cmd_boot.c +8 -0
index 8f2e070..5a8f912 100644
@@ -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
include/command.h +3 -0
index 2ae9b6c..30bc327 100644
@@ -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
Signature · 1 line
2.5.0
#2 lore raw

PATCH 1/4 cmd_boot: Add a poweroff command

Quoted 33 lines · Hans de Goede

From: Michael van Slingerland <[email protected]>

Add a 'poweroff' command to boot commands, this only gets enabled if the board Kconfig does a "select CMD_POWEROFF".

[hdegoede at redhat.com: Make the cmd conditional on a CMD_POWEROFF Kconfig]
---
 common/Kconfig    | 3 +++
 common/cmd_boot.c | 8 ++++++++
 include/command.h | 3 +++
 3 files changed, 14 insertions(+)
common/Kconfig +3 -0
index ccf5475..9d446bf 100644
@@ -184,6 +184,9 @@ config CMD_XIMG
 	help
 	  Extract a part of a multi-image.
 
+config CMD_POWEROFF
+	bool
+
 endmenu
 
 menu "Environment commands"
common/cmd_boot.c +0 -0
index 8f2e070..5a8f912 100644

common/cmd_boot.c U_BOOT_CMD( · line 68

Quoted 8 lines
common/cmd_boot.c +5 -0
@@ -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"

Quoted 8 lines
common/cmd_boot.c +3 -0
+	""
+);
+#endif
include/command.h +0 -0
index 2ae9b6c..30bc327 100644

include/command.h extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, · line 115

Quoted 6 lines
include/command.h +3 -0
@@ -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!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151220/d735c0f1/attachment.sig>
#3 lore raw

PATCH 2/4 sunxi: Implement poweroff support for axp152 pmic

In reply to Hans de Goede

Adds poweroff support for axp152 pmic.

---
 drivers/power/Kconfig  |  1 +
 drivers/power/axp152.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)
drivers/power/Kconfig +1 -0
index e86dd72..de32828 100644
@@ -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.
drivers/power/axp152.c +12 -0
index 2972586..cd07275 100644
@@ -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;
+}
Signature · 1 line
2.5.0
#4 lore raw

PATCH 3/4 sunxi: Implement poweroff support for axp209 pmic

In reply to Hans de Goede

From: Michael van Slingerland <[email protected]>

Adds poweroff support for axp209 pmic.

---
 drivers/power/Kconfig  |  1 +
 drivers/power/axp209.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)
drivers/power/Kconfig +1 -0
index de32828..52c9e61 100644
@@ -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.
drivers/power/axp209.c +12 -0
index 71aa000..fc162a1 100644
@@ -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;
+}
Signature · 1 line
2.5.0
#5 lore raw

PATCH 4/4 sunxi: Implement poweroff support for axp221 pmic

In reply to Hans de Goede

Adds poweroff support for axp221 pmic.

---
 drivers/power/Kconfig  |  1 +
 drivers/power/axp221.c | 12 ++++++++++++
 include/axp221.h       |  2 ++
 3 files changed, 15 insertions(+)
drivers/power/Kconfig +1 -0
index 52c9e61..dfd60aa 100644
@@ -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.
drivers/power/axp221.c +12 -0
index 65802e4..8acadf0 100644
@@ -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;
+}
include/axp221.h +2 -0
index 0ee21b6..04cd8c2 100644
@@ -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
Signature · 1 line
2.5.0
#6 lore raw

cover Add a new poweroff command and implement it for sunxi

In reply to Hans de Goede
Quoted 8 lines · Hans de Goede

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 <[email protected]>

#1 looks fine to me too, modulo Tom's comments.

Ian.