From d11dcb975807aee28b62098c99800a3d40834955 Mon Sep 17 00:00:00 2001
From: Przemyslaw Marczak
Date: Mon, 9 Jun 2014 08:25:09 +0200
Subject: [PATCH] common: add command power off - to switch off the device by
command
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
---
common/Makefile | 1 +
common/cmd_poweroff.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
create mode 100644 common/cmd_poweroff.c
diff --git a/common/Makefile b/common/Makefile
index b19d379..4f372b6 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -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
index 0000000..2f310f1
--- /dev/null
+++ b/common/cmd_poweroff.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ * Przemyslaw Marczak
+ *
+ * Power off command
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include
+#include
+
+/*
+ * 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",
+ "\n"
+ "It turn off the power supply of the board"
+);
--
2.7.4