summaryrefslogtreecommitdiff
path: root/common/usb_pd_protocol.c
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2014-04-18 11:56:50 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-04-30 09:42:48 +0000
commit439bfbddedde616c3417163a6c018a606281c17d (patch)
tree8f43ad4fa680c70487d6231c63318e67b9ba55f1 /common/usb_pd_protocol.c
parent2457b509cc1a962231a543dff54d1ecd04ee952d (diff)
downloadchrome-ec-439bfbddedde616c3417163a6c018a606281c17d.tar.gz
pd: update policy, timeout and board callbacks
Slightly modify interfaces for better sink-only devices implementation (eg Firefly) update the host mode management and the voltage selection and add a hook for board checks. Simplify the reception timeout and fix other timeout detections. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=none TEST=make buildall and use with the follow-up firefly board configuration CL. Change-Id: I0240295764c8605793dc80a2fc21357af1740744 Reviewed-on: https://chromium-review.googlesource.com/195585 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/usb_pd_protocol.c')
-rw-r--r--common/usb_pd_protocol.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 4d0ef0f90b..b5c64d83f8 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -305,9 +305,11 @@ static int send_validate_message(void *ctxt, uint16_t header, uint8_t cnt,
id == pd_message_id) {
/* got the GoodCRC we were expecting */
inc_id();
+ /* do not catch last edges as a new packet */
+ udelay(10);
return bit_len;
} else {
- CPRINTF("ERR ACK/%d %04x\n", id, head);
+ /* CPRINTF("ERR ACK/%d %04x\n", id, head); */
}
}
}
@@ -626,6 +628,8 @@ void pd_task(void)
while (1) {
/* monitor for incoming packet */
pd_rx_enable_monitoring();
+ /* Verify board specific health status : current, voltages... */
+ pd_board_checks();
/* wait for next event/packet or timeout expiration */
evt = task_wait_event(timeout);
/* incoming packet ? */
@@ -637,7 +641,8 @@ void pd_task(void)
else if (head == PD_ERR_HARD_RESET)
execute_hard_reset();
}
- timeout = -1;
+ /* if nothing to do, verify the state of the world in 500ms */
+ timeout = 500*MSEC;
switch (pd_task_state) {
case PD_STATE_DISABLED:
/* Nothing to do */
@@ -719,6 +724,8 @@ void pd_task(void)
break;
case PD_STATE_SNK_READY:
/* we have power and we are happy */
+ /* check vital parameters from time to time */
+ timeout = 100*MSEC;
break;
#endif /* CONFIG_USB_PD_DUAL_ROLE */
case PD_STATE_HARD_RESET:
@@ -740,6 +747,15 @@ void pd_rx_event(void)
}
#ifdef CONFIG_COMMON_RUNTIME
+void pd_request_source_voltage(int mv)
+{
+ pd_set_max_voltage(mv);
+ pd_role = PD_ROLE_SINK;
+ pd_set_host_mode(0);
+ pd_task_state = PD_STATE_SNK_DISCONNECTED;
+ task_wake(TASK_ID_PD);
+}
+
static int command_pd(int argc, char **argv)
{
if (argc < 2)
@@ -759,18 +775,12 @@ static int command_pd(int argc, char **argv)
pd_task_state = PD_STATE_SRC_DISCONNECTED;
task_wake(TASK_ID_PD);
} else if (!strncasecmp(argv[1], "dev", 3)) {
+ int max_volt = -1;
if (argc >= 3) {
- unsigned max_volt;
char *e;
-
- max_volt = strtoi(argv[2], &e, 10);
- pd_set_max_voltage(max_volt * 1000);
+ max_volt = strtoi(argv[2], &e, 10) * 1000;
}
-
- pd_role = PD_ROLE_SINK;
- pd_set_host_mode(0);
- pd_task_state = PD_STATE_SNK_DISCONNECTED;
- task_wake(TASK_ID_PD);
+ pd_request_source_voltage(max_volt);
} else if (!strcasecmp(argv[1], "clock")) {
int freq;
char *e;