diff options
author | Aseda Aboagye <aaboagye@google.com> | 2017-10-16 16:03:24 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-10-23 04:28:23 -0700 |
commit | b6733343abb6d9b7ce7446b94f312dab51d46fac (patch) | |
tree | d54387e14251c5285e09225658e79a8822a42554 /power/common.c | |
parent | 8d639f58ea58c851eb226af9fe676693fbc901f8 (diff) | |
download | chrome-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>
Diffstat (limited to 'power/common.c')
-rw-r--r-- | power/common.c | 27 |
1 files changed, 27 insertions, 0 deletions
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) */ |