MANATEE: HACK: platform/chrome: ignore EC_HOST_RESUME_SLEEP_TIMEOUT

In ManaTEE, system may not be able to wakeup from idle sleep.

If the host can't enter s0ix during s2idle, CrOS EC sets
EC_HOST_RESUME_SLEEP_TIMEOUT flag in response to host event
HOST_SLEEP_EVENT_S0IX_RESUME.

Upon wakeup, powerd picks this up from cros_ec/last_resume_result in
sysfs, and tries to suspend the system again, for up to
/usr/share/power_manager/retry_suspend_attempts.

This patch ignores EC_HOST_RESUME_SLEEP_TIMEOUT flag to prevent powerd
from suspend retries.

Additional fix to call cros_ec_fixup_s0ixwake_mask() from CrOS guest
only.

BUG=b:228433429
TEST=idle suspend from powerd and able to wake up even if EC reports
suspend timeout.

Change-Id: Ia7030c8adadb9dbba1880851fe4706268f988fa5
Signed-off-by: Zide Chen <zide.chen@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3580223
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dmytro Maluka <dmy@semihalf.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
index efe6690..4240616 100644
--- a/drivers/platform/chrome/cros_ec.c
+++ b/drivers/platform/chrome/cros_ec.c
@@ -16,6 +16,7 @@
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>
 #include <linux/suspend.h>
+#include <linux/manatee.h>
 
 #include "cros_ec.h"
 
@@ -169,6 +170,16 @@
 		ec_dev->last_resume_result =
 			buf.u.resp1.resume_response.sleep_transitions;
 
+		/*
+		 * At the time CrOS wakes up from idle suspend and if this bit
+		 * is set, powerd daemon determines that AP was waken up due to
+		 * failure of s0ix transition, and wants to suspend the system
+		 * again.  Thus, before AP is able to reliably enter s0ix in
+		 * ManaTEE s2idle, we don't want this bit be visible to powerd.
+		 */
+		if (manatee_chromeos_domain())
+			ec_dev->last_resume_result &= ~EC_HOST_RESUME_SLEEP_TIMEOUT;
+
 		WARN_ONCE(buf.u.resp1.resume_response.sleep_transitions &
 			  EC_HOST_RESUME_SLEEP_TIMEOUT,
 			  "EC detected sleep transition timeout. Total slp_s0 transitions: %d",
@@ -233,10 +244,12 @@
 		return err;
 	}
 
-	err = cros_ec_fixup_s0ixwake_mask(ec_dev);
-	if (err < 0) {
-		dev_err(dev, "Cannot send EC_CMD_HOST_EVENT to EC: error %d\n", err);
-		return err;
+	if (manatee_chromeos_domain()) {
+		err = cros_ec_fixup_s0ixwake_mask(ec_dev);
+		if (err < 0) {
+			dev_err(dev, "Cannot send EC_CMD_HOST_EVENT to EC: error %d\n", err);
+			return err;
+		}
 	}
 
 	if (ec_dev->irq > 0) {