common: add command power off - to switch off the device by command
authorPrzemyslaw Marczak <p.marczak@samsung.com>
Mon, 9 Jun 2014 06:25:09 +0000 (08:25 +0200)
committerLukasz Majewski <l.majewski@samsung.com>
Thu, 30 Oct 2014 08:27:14 +0000 (09:27 +0100)
This change introduces new config:
- CONFIG_CMD_POWEROFF - which enables common/cmd_poweroff.c

This requires implementation of function board_poweroff() which
is yet declared in include/common.h

Implementation of board_poweroff() should:
1.a. turn off the device
     or
1.b. print info to user about turn off ability
2.   never back to caller

Usage is simple: "power off"

Change-Id: Ia5fe73250e2ac29d0868b80bcd867bae2aa8d5be
Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
common/Makefile
common/cmd_poweroff.c [new file with mode: 0644]

index b19d379..4f372b6 100644 (file)
@@ -196,6 +196,7 @@ obj-$(CONFIG_YAFFS2) += cmd_yaffs2.o
 obj-$(CONFIG_CMD_SPL) += cmd_spl.o
 obj-$(CONFIG_CMD_ZIP) += cmd_zip.o
 obj-$(CONFIG_CMD_ZFS) += cmd_zfs.o
+obj-$(CONFIG_CMD_POWEROFF) += cmd_poweroff.o
 
 # others
 obj-$(CONFIG_BOOTSTAGE) += bootstage.o
diff --git a/common/cmd_poweroff.c b/common/cmd_poweroff.c
new file mode 100644 (file)
index 0000000..2f310f1
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ * Przemyslaw Marczak <p.marczak@samsung.com>
+ *
+ * Power off command
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+/*
+ * Power off the board by simple command
+ * This requires implementation of function board_poweroff() which is declared
+ * in include/common.h
+ *
+ * Implementation of board_poweroff() should:
+ * 1.a. turn off the device
+ *      or
+ * 1.b. print info to user about turn off ability as it is in few boards
+ * 2.   never back to caller
+ */
+int do_power_off(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       if (argc != 2)
+               return CMD_RET_USAGE;
+
+       if (!strcmp("off", argv[1])) {
+               board_poweroff();
+               /* This function should not back here */
+               return CMD_RET_SUCCESS;
+       }
+
+       return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(power, CONFIG_SYS_MAXARGS, 1, do_power_off,
+       "Device power off",
+       "<off>\n"
+       "It turn off the power supply of the board"
+);