diff options
author | Scott <scollyer@chromium.org> | 2015-06-04 16:03:28 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-23 19:18:44 +0000 |
commit | 99e964c018eec1cba83022361866dd0b14d47610 (patch) | |
tree | 67cb7b386101bbd2abf2f45fc66ffdfd8d1bceb9 /board/glados_pd | |
parent | 0e2176304f3af2b78e8e0b12dab8feb82abccd8f (diff) | |
download | chrome-ec-99e964c018eec1cba83022361866dd0b14d47610.tar.gz |
pd: Add support for TCPC Alert and Alert_Mask registers
Changed the alert function to hold the ec_int line until
all of the alert bits are cleared. Added support for the
alert_mask register. In addition, created ec_int_status
variable to distinguish which of 3 ec_int sources is
driving the pd_mcu_int line.
BUG=none
BRANCH=tot
TEST=Tested Zinger to Glados and Zinger to Samus and verified
that it established a power contract in both cases. Did not
test Oak, but put exact same changes in board.c as in glados.
Change-Id: I372e75b8fd5d66a0c01db18b46100b86fd9ac064
Signed-off-by: Scott Collyer <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/278256
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'board/glados_pd')
-rw-r--r-- | board/glados_pd/board.c | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/board/glados_pd/board.c b/board/glados_pd/board.c index 776e30a29b..42e8958538 100644 --- a/board/glados_pd/board.c +++ b/board/glados_pd/board.c @@ -21,17 +21,13 @@ #define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) +static uint32_t ec_int_status; + void pd_send_ec_int(void) { - gpio_set_level(GPIO_EC_INT, 0); - - /* - * Delay long enough to guarantee EC see's the change. - * TODO: make sure this delay is sufficient. - */ - usleep(5); + /* If any of 3 sources are active, then drive the line low */ + gpio_set_level(GPIO_EC_INT, !ec_int_status); - gpio_set_level(GPIO_EC_INT, 1); } void vbus0_evt(enum gpio_signal signal) @@ -84,8 +80,27 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); -void tcpc_alert(void) +void tcpc_alert(int port) { + /* + * This function is called when the TCPC sets one of + * bits in the Alert register and that bit's corresponding + * location in the Alert_Mask register is set. + */ + atomic_or(&ec_int_status, port ? + PD_STATUS_TCPC_ALERT_1 : PD_STATUS_TCPC_ALERT_0); + pd_send_ec_int(); +} + +void tcpc_alert_clear(int port) +{ + /* + * The TCPM has acknowledged all Alert bits and the + * Alert# line needs to be set inactive. Clear + * the corresponding port's bit in the static variable. + */ + atomic_clear(&ec_int_status, port ? + PD_STATUS_TCPC_ALERT_1 : PD_STATUS_TCPC_ALERT_0); pd_send_ec_int(); } @@ -93,6 +108,8 @@ void tcpc_alert(void) /* Console commands */ static int command_ec_int(int argc, char **argv) { + /* Indicate that ec_int gpio is active due to host command */ + atomic_or(&ec_int_status, PD_STATUS_HOST_EVENT); pd_send_ec_int(); return EC_SUCCESS; @@ -107,12 +124,19 @@ static int ec_status_host_cmd(struct host_cmd_handler_args *args) struct ec_response_pd_status *r = args->response; /* - * TODO: use state here to notify EC of host events, tcpc port - * 0 alert and tcpc port 1 alert. + * ec_int_status is used to store state for HOST_EVENT, + * TCPC 0 Alert, and TCPC 1 Alert bits. */ - r->status = 0; + r->status = ec_int_status; args->response_size = sizeof(*r); + /* + * If the source of the EC int line was HOST_EVENT, it has + * been acknowledged so can always clear HOST_EVENT bit + * from the ec_int_status variable + */ + atomic_clear(&ec_int_status, PD_STATUS_HOST_EVENT); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_PD_EXCHANGE_STATUS, ec_status_host_cmd, |