summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2017-10-16 16:03:24 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-10-23 04:28:23 -0700
commitb6733343abb6d9b7ce7446b94f312dab51d46fac (patch)
treed54387e14251c5285e09225658e79a8822a42554
parent8d639f58ea58c851eb226af9fe676693fbc901f8 (diff)
downloadchrome-ec-b6733343abb6d9b7ce7446b94f312dab51d46fac.tar.gz
power: Add task-safe API to control 5V rail.
For certain cannonlake designs, the 5V rail can be controlled by both the chipset task as well as other tasks such as the USB charger tasks to perform BC1.2 detection. This commit introduces an API that allows the tasks to enable/disable the 5V rail. Enable requests will immediately enable the rail, however, attempting to disable the rail will only result in a request. Once all tasks want to turn off the 5V rail, the rail will be turned off. A bitmask is introduced to keep track of the requests. Index 0 is for the chipset task. All of this is gated behind a config option: CONFIG_POWER_PP5000_CONTROL BUG=b:65991615 BRANCH=None TEST=With other zoombini code, verify that 5V can be enabled and disabled. Change-Id: I1722b4a272c4d6ee24408929f5a7402051bb9cf3 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/722322 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--include/config.h3
-rw-r--r--include/power.h15
-rw-r--r--power/cannonlake.c9
-rw-r--r--power/common.c27
4 files changed, 54 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h
index fefeaaf81d..8156ead7f4 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1970,6 +1970,9 @@
/* Disable the power-on transition when the lid is opened */
#undef CONFIG_POWER_IGNORE_LID_OPEN
+/* Enable a task-safe way to control the PP5000 rail. */
+#undef CONFIG_POWER_PP5000_CONTROL
+
/* Support stopping in S5 on shutdown */
#undef CONFIG_POWER_SHUTDOWN_PAUSE_IN_S5
diff --git a/include/power.h b/include/power.h
index 52316628fd..20b2ee6cf6 100644
--- a/include/power.h
+++ b/include/power.h
@@ -10,6 +10,7 @@
#include "common.h"
#include "gpio.h"
+#include "task_id.h"
enum power_state {
/* Steady states */
@@ -209,4 +210,18 @@ void power_reset_host_sleep_state(enum host_sleep_event sleep_event);
#endif /* CONFIG_POWER_S0IX */
#endif /* CONFIG_POWER_TRACK_HOST_SLEEP_STATE */
+/**
+ * Enable/Disable the PP5000 rail.
+ *
+ * This function will turn on the 5V rail immediately if requested. However,
+ * the rail will not turn off until all tasks want it off.
+ *
+ * NOTE: Be careful when calling from deferred functions, as they will all be
+ * executed within the same task context! (The HOOKS task).
+ *
+ * @param tid: The caller's task ID.
+ * @param enable: 1 to turn on the rail, 0 to request the rail to be turned off.
+ */
+void power_5v_enable(task_id_t tid, int enable);
+
#endif /* __CROS_EC_POWER_H */
diff --git a/power/cannonlake.c b/power/cannonlake.c
index 535010c103..270eba5f35 100644
--- a/power/cannonlake.c
+++ b/power/cannonlake.c
@@ -12,6 +12,7 @@
#include "intel_x86.h"
#include "power.h"
#include "power_button.h"
+#include "task.h"
#include "timer.h"
/* Console output macros */
@@ -104,11 +105,19 @@ enum power_state power_handle_state(enum power_state state)
* In S3, enable 5V rail. Wireless rails are handled by common
* x86 chipset code.
*/
+#ifdef CONFIG_POWER_PP5000_CONTROL
+ power_5v_enable(task_get_current(), 1);
+#else
gpio_set_level(GPIO_EN_PP5000, 1);
+#endif
break;
case POWER_S3S5:
+#ifdef CONFIG_POWER_PP5000_CONTROL
+ power_5v_enable(task_get_current(), 0);
+#else
gpio_set_level(GPIO_EN_PP5000, 0);
+#endif
break;
default:
diff --git a/power/common.c b/power/common.c
index 0a32bb13e1..467f41e9aa 100644
--- a/power/common.c
+++ b/power/common.c
@@ -782,3 +782,30 @@ void power_reset_host_sleep_state(enum host_sleep_event sleep_event)
#endif /* CONFIG_POWER_S0IX */
#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;
+static struct mutex pwr_5v_ctl_mtx;
+
+void __attribute__((weak)) power_5v_enable(task_id_t tid, int enable)
+{
+ mutex_lock(&pwr_5v_ctl_mtx);
+
+ if (enable) /* Set the bit indicating the request. */
+ pwr_5v_en_req |= 1 << tid;
+ else /* Clear the task's request bit. */
+ pwr_5v_en_req &= ~(1 << tid);
+
+ /*
+ * If there are any outstanding requests for the rail to be enabled,
+ * turn on the rail. Otherwise, turn it off.
+ */
+ if (pwr_5v_en_req)
+ gpio_set_level(GPIO_EN_PP5000, 1);
+ else
+ gpio_set_level(GPIO_EN_PP5000, 0);
+
+ mutex_unlock(&pwr_5v_ctl_mtx);
+}
+#endif /* defined(CONFIG_POWER_PP5000_CONTROL) */