From fe4b71b2373cf0627fbd9d9767fb66059e67eea7 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Sun, 20 Dec 2015 16:14:31 +0100
Subject: [PATCH] sunxi: Implement poweroff support for axp221 pmic

Adds poweroff support for axp221 pmic.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
---
 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 52c9e61f24..dfd60aa3fa 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 65802e4a71..8acadf0f9c 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 0ee21b6280..04cd8c2be4 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
-- 
2.39.5