From 1d0f58a303f8eb57d4c9fdec406f6f09918547cc Mon Sep 17 00:00:00 2001 From: Yilun Lin Date: Tue, 20 Aug 2019 13:54:00 +0800 Subject: power: Make HC host_sleep_event independent from power common. host_sleep_event provides the AP power state information to EC, and this is not necessary bound to CONFIG_POWER_COMMON. This CL moves the HC out of CONFIG_POWER_COMMON. TEST=1. make buildall -j 2. #define CONFIG_POWER_TRACK_HOST_SLEEP_STATE kukui_scp, and see it build successfully. BUG=b:136240895 BRANCH=none Cq-Depend: chromium:1760656 Change-Id: I5555c7ba8b97547ce9fc0ff8e2bff14ef3da8fe7 Signed-off-by: Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1753563 Reviewed-by: Jett Rink --- power/build.mk | 1 + power/common.c | 71 ------------------------------------------------- power/host_sleep.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 71 deletions(-) create mode 100644 power/host_sleep.c (limited to 'power') diff --git a/power/build.mk b/power/build.mk index 0134b01744..3b001e3596 100644 --- a/power/build.mk +++ b/power/build.mk @@ -20,3 +20,4 @@ power-$(CONFIG_CHIPSET_SDM845)+=sdm845.o power-$(CONFIG_CHIPSET_SKYLAKE)+=skylake.o intel_x86.o power-$(CONFIG_CHIPSET_STONEY)+=stoney.o power-$(CONFIG_POWER_COMMON)+=common.o +power-$(CONFIG_POWER_TRACK_HOST_SLEEP_STATE)+=host_sleep.o diff --git a/power/common.c b/power/common.c index f0fc3117d3..5128f46ac8 100644 --- a/power/common.c +++ b/power/common.c @@ -877,77 +877,6 @@ DECLARE_CONSOLE_COMMAND(pause_in_s5, command_pause_in_s5, "Should the AP pause in S5 during shutdown?"); #endif /* CONFIG_POWER_SHUTDOWN_PAUSE_IN_S5 */ -#ifdef CONFIG_POWER_TRACK_HOST_SLEEP_STATE -/* Track last reported sleep event */ -static enum host_sleep_event host_sleep_state; - -__overridable void power_chipset_handle_host_sleep_event( - enum host_sleep_event state, struct host_sleep_event_context *ctx) -{ - /* Default weak implementation -- no action required. */ -} - -static int host_command_host_sleep_event(struct host_cmd_handler_args *args) -{ - const struct ec_params_host_sleep_event_v1 *p = args->params; - struct ec_response_host_sleep_event_v1 *r = args->response; - struct host_sleep_event_context ctx; - enum host_sleep_event state = p->sleep_event; - - host_sleep_state = state; - ctx.sleep_transitions = 0; - switch (state) { - case HOST_SLEEP_EVENT_S3_SUSPEND: - case HOST_SLEEP_EVENT_S0IX_SUSPEND: - case HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND: - ctx.sleep_timeout_ms = EC_HOST_SLEEP_TIMEOUT_DEFAULT; - - /* The original version contained only state. */ - if (args->version >= 1) - ctx.sleep_timeout_ms = - p->suspend_params.sleep_timeout_ms; - - break; - - default: - break; - } - - power_chipset_handle_host_sleep_event(host_sleep_state, &ctx); - switch (state) { - case HOST_SLEEP_EVENT_S3_RESUME: - case HOST_SLEEP_EVENT_S0IX_RESUME: - if (args->version >= 1) { - r->resume_response.sleep_transitions = - ctx.sleep_transitions; - - args->response_size = sizeof(*r); - } - - break; - - default: - break; - } - - return EC_RES_SUCCESS; -} -DECLARE_HOST_COMMAND(EC_CMD_HOST_SLEEP_EVENT, - host_command_host_sleep_event, - EC_VER_MASK(0) | EC_VER_MASK(1)); - -enum host_sleep_event power_get_host_sleep_state(void) -{ - return host_sleep_state; -} - -void power_set_host_sleep_state(enum host_sleep_event state) -{ - host_sleep_state = state; -} - -#endif /* CONFIG_POWER_TRACK_HOST_SLEEP_STATE */ - #ifdef CONFIG_POWER_PP5000_CONTROL /* 5V enable request bitmask from various tasks. */ static uint32_t pwr_5v_en_req; diff --git a/power/host_sleep.c b/power/host_sleep.c new file mode 100644 index 0000000000..7d342441eb --- /dev/null +++ b/power/host_sleep.c @@ -0,0 +1,78 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "ec_commands.h" +#include "host_command.h" +#include "power.h" + +/* Track last reported sleep event */ +static enum host_sleep_event host_sleep_state; + +__overridable void power_chipset_handle_host_sleep_event( + enum host_sleep_event state, + struct host_sleep_event_context *ctx) +{ + /* Default weak implementation -- no action required. */ +} + +static int host_command_host_sleep_event(struct host_cmd_handler_args *args) +{ + const struct ec_params_host_sleep_event_v1 *p = args->params; + struct ec_response_host_sleep_event_v1 *r = args->response; + struct host_sleep_event_context ctx; + enum host_sleep_event state = p->sleep_event; + + host_sleep_state = state; + ctx.sleep_transitions = 0; + switch (state) { + case HOST_SLEEP_EVENT_S0IX_SUSPEND: + case HOST_SLEEP_EVENT_S3_SUSPEND: + case HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND: + ctx.sleep_timeout_ms = EC_HOST_SLEEP_TIMEOUT_DEFAULT; + + /* The original version contained only state. */ + if (args->version >= 1) + ctx.sleep_timeout_ms = + p->suspend_params.sleep_timeout_ms; + + break; + + default: + break; + } + + power_chipset_handle_host_sleep_event(host_sleep_state, &ctx); + switch (state) { + case HOST_SLEEP_EVENT_S0IX_RESUME: + case HOST_SLEEP_EVENT_S3_RESUME: + if (args->version >= 1) { + r->resume_response.sleep_transitions = + ctx.sleep_transitions; + + args->response_size = sizeof(*r); + } + + break; + + default: + break; + } + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_HOST_SLEEP_EVENT, + host_command_host_sleep_event, + EC_VER_MASK(0) | EC_VER_MASK(1)); + +enum host_sleep_event power_get_host_sleep_state(void) +{ + return host_sleep_state; +} + +void power_set_host_sleep_state(enum host_sleep_event state) +{ + host_sleep_state = state; +} + -- cgit v1.2.1