summaryrefslogtreecommitdiff
path: root/common/host_command_pd.c
diff options
context:
space:
mode:
authorScott <scollyer@chromium.org>2015-06-04 16:03:28 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-23 19:18:44 +0000
commit99e964c018eec1cba83022361866dd0b14d47610 (patch)
tree67cb7b386101bbd2abf2f45fc66ffdfd8d1bceb9 /common/host_command_pd.c
parent0e2176304f3af2b78e8e0b12dab8feb82abccd8f (diff)
downloadchrome-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 'common/host_command_pd.c')
-rw-r--r--common/host_command_pd.c58
1 files changed, 48 insertions, 10 deletions
diff --git a/common/host_command_pd.c b/common/host_command_pd.c
index 33bdb52745..a10a591637 100644
--- a/common/host_command_pd.c
+++ b/common/host_command_pd.c
@@ -8,6 +8,7 @@
#include "charge_state.h"
#include "common.h"
#include "console.h"
+#include "gpio.h"
#include "host_command.h"
#include "lightbar.h"
#include "panic.h"
@@ -45,11 +46,31 @@ void host_command_pd_send_status(enum pd_charge_state new_chg_state)
task_set_event(TASK_ID_PDCMD, TASK_EVENT_EXCHANGE_PD_STATUS, 0);
}
+static int pd_send_host_command(struct ec_params_pd_status *ec_status,
+ struct ec_response_pd_status *pd_status)
+{
+ int rv;
+
+ rv = pd_host_command(EC_CMD_PD_EXCHANGE_STATUS, 1, ec_status,
+ sizeof(struct ec_params_pd_status), pd_status,
+ sizeof(struct ec_response_pd_status));
+
+ /* If PD doesn't support new command version, try old version */
+ if (rv == -EC_RES_INVALID_VERSION)
+ rv = pd_host_command(EC_CMD_PD_EXCHANGE_STATUS, 0, ec_status,
+ sizeof(struct ec_params_pd_status), pd_status,
+ sizeof(struct ec_response_pd_status));
+ return rv;
+}
+
static void pd_exchange_status(void)
{
struct ec_params_pd_status ec_status;
struct ec_response_pd_status pd_status;
int rv = 0;
+#ifdef CONFIG_USB_PD_TCPM_TCPCI
+ int loop_count;
+#endif
#ifdef CONFIG_HOSTCMD_PD_PANIC
static int pd_in_rw;
#endif
@@ -63,15 +84,7 @@ static void pd_exchange_status(void)
else
ec_status.batt_soc = -1;
- rv = pd_host_command(EC_CMD_PD_EXCHANGE_STATUS, 1, &ec_status,
- sizeof(struct ec_params_pd_status), &pd_status,
- sizeof(struct ec_response_pd_status));
-
- /* If PD doesn't support new command version, try old version */
- if (rv == -EC_RES_INVALID_VERSION)
- rv = pd_host_command(EC_CMD_PD_EXCHANGE_STATUS, 0, &ec_status,
- sizeof(struct ec_params_pd_status), &pd_status,
- sizeof(struct ec_response_pd_status));
+ rv = pd_send_host_command(&ec_status, &pd_status);
if (rv < 0) {
CPRINTS("Host command to PD MCU failed");
@@ -124,7 +137,32 @@ static void pd_exchange_status(void)
host_set_single_event(EC_HOST_EVENT_PD_MCU);
#ifdef CONFIG_USB_PD_TCPM_TCPCI
- tcpc_alert();
+ /*
+ * Loop here until all Alerts from either port have been handled.
+ * This is necessary to prevent the case where Alert bits are set
+ * and the GPIO line is held low, which would prevent a new edge
+ * event which prevents tcpc_alert() from being called and that
+ * in turn prevents the GPIO line from being released.
+ */
+ while (!gpio_get_level(GPIO_PD_MCU_INT)) {
+ /*
+ * If TCPC is not present on this MCU, then check
+ * to see if either PD port is signallng an
+ * Alert# to the TCPM.
+ */
+ if (pd_status.status & PD_STATUS_TCPC_ALERT_0)
+ tcpc_alert(0);
+ if (pd_status.status & PD_STATUS_TCPC_ALERT_1)
+ tcpc_alert(1);
+ if (loop_count++) {
+ usleep(50*MSEC);
+ rv = pd_send_host_command(&ec_status, &pd_status);
+ if (rv < 0) {
+ CPRINTS("Host command to PD MCU failed");
+ return;
+ }
+ }
+ }
#endif
}