summaryrefslogtreecommitdiff
path: root/common/host_command_pd.c
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-06-17 15:23:25 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-23 20:41:03 +0000
commit43db8410667de672369c794fd9b16e40fcded85c (patch)
treedc8092f50fe082fc61c1985884680df377e1341e /common/host_command_pd.c
parent0c46bcc3e77c3e7049e1354e0a4802d6bba8c9e2 (diff)
downloadchrome-ec-43db8410667de672369c794fd9b16e40fcded85c.tar.gz
pd: allow pdcmd task to check TCPC alert status w/o sending HC
Modify PDCMD task to allow for TCPCs that do not support host commands. CONFIG_HOSTCMD_PD is a new config option to be used by TCPCs that implement our host command protocol such as the PD MCU on glados and oak. Otherwise, the PDCMD task will not send host commands and will be used simply to check TCPC interrupt status. BUG=none BRANCH=none TEST=test on glados and samus and make sure we can send host commands from the EC to the PD and that we can negotiate a PD contract. Change-Id: I618badb5db3f9e490ae4eedfdb2a0c54513496ff Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/278215 Reviewed-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/host_command_pd.c')
-rw-r--r--common/host_command_pd.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/common/host_command_pd.c b/common/host_command_pd.c
index a10a591637..0ece50a468 100644
--- a/common/host_command_pd.c
+++ b/common/host_command_pd.c
@@ -22,7 +22,7 @@
#define TASK_EVENT_EXCHANGE_PD_STATUS TASK_EVENT_CUSTOM(1)
-#ifdef CONFIG_USB_PD_MCU_CHG_CTRL
+#ifdef CONFIG_HOSTCMD_PD_CHG_CTRL
/* By default allow 5V charging only for the dead battery case */
static enum pd_charge_state charge_state = PD_CHARGE_5V;
@@ -37,7 +37,7 @@ int pd_get_active_charge_port(void)
void host_command_pd_send_status(enum pd_charge_state new_chg_state)
{
-#ifdef CONFIG_USB_PD_MCU_CHG_CTRL
+#ifdef CONFIG_HOSTCMD_PD_CHG_CTRL
/* Update PD MCU charge state if necessary */
if (new_chg_state != PD_CHARGE_NO_CHANGE)
charge_state = new_chg_state;
@@ -46,6 +46,7 @@ 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);
}
+#ifdef CONFIG_HOSTCMD_PD
static int pd_send_host_command(struct ec_params_pd_status *ec_status,
struct ec_response_pd_status *pd_status)
{
@@ -62,21 +63,20 @@ static int pd_send_host_command(struct ec_params_pd_status *ec_status,
sizeof(struct ec_response_pd_status));
return rv;
}
+#endif
static void pd_exchange_status(void)
{
+#ifdef CONFIG_HOSTCMD_PD
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
/* Send PD charge state and battery state of charge */
-#ifdef CONFIG_USB_PD_MCU_CHG_CTRL
+#ifdef CONFIG_HOSTCMD_PD_CHG_CTRL
ec_status.charge_state = charge_state;
#endif
if (charge_get_flags() & CHARGE_FLAG_BATT_RESPONSIVE)
@@ -106,7 +106,7 @@ static void pd_exchange_status(void)
}
#endif
-#ifdef CONFIG_USB_PD_MCU_CHG_CTRL
+#ifdef CONFIG_HOSTCMD_PD_CHG_CTRL
#ifdef HAS_TASK_LIGHTBAR
/*
* If charge port has changed, and it was initialized, then show
@@ -130,13 +130,18 @@ static void pd_exchange_status(void)
CONFIG_CHARGER_INPUT_CURRENT));
if (rv < 0)
CPRINTS("Failed to set input current limit from PD MCU");
-#endif /* CONFIG_USB_PD_MCU_CHG_CTRL */
+#endif /* CONFIG_HOSTCMD_PD_CHG_CTRL */
/* If PD is signalling host event, then pass it up to AP */
if (pd_status.status & PD_STATUS_HOST_EVENT)
host_set_single_event(EC_HOST_EVENT_PD_MCU);
+#endif /* CONFIG_HOSTCMD_PD */
-#ifdef CONFIG_USB_PD_TCPM_TCPCI
+ /*
+ * If we are TCPM, connected to an off chip TCPC, then check
+ * TCPC alert status.
+ */
+#if defined(CONFIG_USB_POWER_DELIVERY) && !defined(CONFIG_USB_PD_TCPM_STUB)
/*
* Loop here until all Alerts from either port have been handled.
* This is necessary to prevent the case where Alert bits are set
@@ -145,22 +150,30 @@ static void pd_exchange_status(void)
* in turn prevents the GPIO line from being released.
*/
while (!gpio_get_level(GPIO_PD_MCU_INT)) {
+ int loop_count = 0;
/*
* If TCPC is not present on this MCU, then check
* to see if either PD port is signallng an
* Alert# to the TCPM.
*/
+#ifdef CONFIG_HOSTCMD_PD
if (pd_status.status & PD_STATUS_TCPC_ALERT_0)
tcpc_alert(0);
if (pd_status.status & PD_STATUS_TCPC_ALERT_1)
tcpc_alert(1);
+#else
+ tcpc_alert(0);
+ tcpc_alert(1);
+#endif
if (loop_count++) {
usleep(50*MSEC);
+#ifdef CONFIG_HOSTCMD_PD
rv = pd_send_host_command(&ec_status, &pd_status);
if (rv < 0) {
CPRINTS("Host command to PD MCU failed");
return;
}
+#endif
}
}
#endif