diff options
author | Bill Richardson <wfrichar@chromium.org> | 2014-11-26 12:40:05 -0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-12-11 04:23:33 +0000 |
commit | 401498bb6a1c38771720c84cc1d58f2f5dbf7ac0 (patch) | |
tree | 068ac939a9d941cf25b0a3094308a9917af201fa | |
parent | 1b1c3089afada7b53e7836ce2b98c157f36a44a8 (diff) | |
download | chrome-ec-401498bb6a1c38771720c84cc1d58f2f5dbf7ac0.tar.gz |
lightbar: ask the PD MCU for the charge direction
This exposes the pd_exchange_status() function and lets it
return the charge port that the PD reports, so that the lightbar
TAP sequence can decide which direction to display.
BUG=chrome-os-partner:32227
BRANCH=ToT, samus
TEST=make buildall -j
Change-Id: I78b57fbeaaf38fee15c86eca4d90abce77e2f722
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/232092
Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r-- | common/host_command_pd.c | 15 | ||||
-rw-r--r-- | common/lightbar.c | 20 | ||||
-rw-r--r-- | include/host_command.h | 10 |
3 files changed, 35 insertions, 10 deletions
diff --git a/common/host_command_pd.c b/common/host_command_pd.c index 252ade01b7..5e3494c46e 100644 --- a/common/host_command_pd.c +++ b/common/host_command_pd.c @@ -22,10 +22,13 @@ void host_command_pd_send_status(void) task_set_event(TASK_ID_PDCMD, TASK_EVENT_EXCHANGE_PD_STATUS, 0); } -static void pd_exchange_status(void) +void pd_exchange_status(int *charge_port) { struct ec_params_pd_status ec_status; - struct ec_response_pd_status pd_status; + struct ec_response_pd_status pd_status = { + /* default for when the PD isn't cooperating */ + .active_charge_port = -1, + }; int rv = 0; /* Send battery state of charge */ @@ -38,6 +41,9 @@ static void pd_exchange_status(void) sizeof(struct ec_params_pd_status), &pd_status, sizeof(struct ec_response_pd_status)); + if (charge_port) + *charge_port = pd_status.active_charge_port; + if (rv < 0) { CPRINTS("Host command to PD MCU failed"); return; @@ -57,7 +63,7 @@ static void pd_exchange_status(void) void pd_command_task(void) { /* On startup exchange status with the PD */ - pd_exchange_status(); + pd_exchange_status(0); while (1) { /* Wait for the next command event */ @@ -65,7 +71,6 @@ void pd_command_task(void) /* Process event to send status to PD */ if (evt & TASK_EVENT_EXCHANGE_PD_STATUS) - pd_exchange_status(); + pd_exchange_status(0); } } - diff --git a/common/lightbar.c b/common/lightbar.c index ab4df550d3..bc43a6080e 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -900,15 +900,25 @@ static uint32_t sequence_TAP_inner(int dir) return 0; } -/* TODO(chrome-os-partner:32227): Remove this when it works for real. */ -static int force_dir; +/* Override the tap direction for testing. -1 means ask the PD MCU. */ +static int force_dir = -1; /* Return 0 (left or none) or 1 (right) */ static int get_tap_direction(void) { - /* TODO(chrome-os-partner:32227): Decide which direction to go */ - CPRINTS("LB tap direction %d", force_dir); - return force_dir; + int dir = 0; + + if (force_dir >= 0) + dir = force_dir; +#ifdef HAS_TASK_PDCMD + else + pd_exchange_status(&dir); +#endif + if (dir != 1) + dir = 0; + + CPRINTS("LB tap direction %d", dir); + return dir; } static uint32_t sequence_TAP(void) diff --git a/include/host_command.h b/include/host_command.h index a25f06d10a..e833b96101 100644 --- a/include/host_command.h +++ b/include/host_command.h @@ -214,6 +214,16 @@ void host_throttle_cpu(int throttle); void host_command_pd_send_status(void); /** + * Ask the PD MCU for its status, obtaining the current charge_port as a + * side-effect (-1 means none or don't know). + * + * @param charge_port If present, updated with the current charge port: + * -1 == none/unknown, 0 == left, 1 == right. + */ +void pd_exchange_status(int *charge_port); + + +/** * Send host command to PD MCU. * * @param command Host command number |