summaryrefslogtreecommitdiff
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
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>
-rw-r--r--board/fruitpie/usb_pd_config.h5
-rw-r--r--board/fruitpie/usb_pd_policy.c4
-rw-r--r--board/zinger/usb_pd_policy.c4
-rw-r--r--chip/stm32/usb_pd_phy.c11
-rw-r--r--common/usb_pd_protocol.c32
-rw-r--r--include/usb_pd.h21
6 files changed, 49 insertions, 28 deletions
diff --git a/board/fruitpie/usb_pd_config.h b/board/fruitpie/usb_pd_config.h
index 59c9852719..cdbb0f365d 100644
--- a/board/fruitpie/usb_pd_config.h
+++ b/board/fruitpie/usb_pd_config.h
@@ -61,6 +61,11 @@ static inline void pd_tx_init(void)
gpio_config_module(MODULE_USB_PD, 1);
}
+static inline void pd_set_host_mode(int enable)
+{
+ gpio_set_level(GPIO_CC_HOST, enable);
+}
+
/* Standard-current DFP : no-connect voltage is 1.55V */
#define PD_SRC_VNC 1550 /* mV */
diff --git a/board/fruitpie/usb_pd_policy.c b/board/fruitpie/usb_pd_policy.c
index ae57559e6b..c756dcc7bd 100644
--- a/board/fruitpie/usb_pd_policy.c
+++ b/board/fruitpie/usb_pd_policy.c
@@ -112,3 +112,7 @@ int pd_set_power_supply_ready(void)
void pd_power_supply_reset(void)
{
}
+
+void pd_board_checks(void)
+{
+}
diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c
index 5f314185a3..b506c15aec 100644
--- a/board/zinger/usb_pd_policy.c
+++ b/board/zinger/usb_pd_policy.c
@@ -106,3 +106,7 @@ void pd_power_supply_reset(void)
set_output_voltage(VO_5V);
/* TODO transition delay */
}
+
+void pd_board_checks(void)
+{
+}
diff --git a/chip/stm32/usb_pd_phy.c b/chip/stm32/usb_pd_phy.c
index a3e78ef0da..2d33e9f96e 100644
--- a/chip/stm32/usb_pd_phy.c
+++ b/chip/stm32/usb_pd_phy.c
@@ -80,10 +80,8 @@ static int wait_bits(int nb)
avail = dma_bytes_done(rx, PD_MAX_RAW_SIZE);
if (avail < nb) { /* no received yet ... */
- timestamp_t deadline = get_time();
- deadline.val += 4 * MAX_BITS * (nb - avail);
while ((dma_bytes_done(rx, PD_MAX_RAW_SIZE) < nb)
- && get_time().val < deadline.val)
+ && !(STM32_TIM_SR(TIM_RX) & 4))
; /* optimized for latency, not CPU usage ... */
if (dma_bytes_done(rx, PD_MAX_RAW_SIZE) < nb) {
CPRINTF("TMOUT RX %d/%d\n",
@@ -524,10 +522,3 @@ void pd_set_clock(int freq)
{
STM32_TIM_ARR(TIM_TX) = clock_get_freq() / (2*freq);
}
-
-#ifdef CONFIG_USB_PD_DUAL_ROLE
-void pd_set_host_mode(int enable)
-{
- gpio_set_level(GPIO_CC_HOST, enable);
-}
-#endif /* CONFIG_USB_PD_DUAL_ROLE */
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;
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 8c70fe5d50..c3fac8b296 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -142,6 +142,20 @@ void pd_power_supply_reset(void);
*/
int pd_set_power_supply_ready(void);
+/**
+ * Ask the specified voltage from the PD source.
+ *
+ * It triggers a new negotiation sequence with the source.
+ * @param mv request voltage in millivolts.
+ */
+void pd_request_source_voltage(int mv);
+
+/*
+ * Verify board specific health status : current, voltages...
+ *
+ */
+void pd_board_checks(void);
+
/* Power Data Objects for the source and the sink */
extern const uint32_t pd_src_pdo[];
extern const int pd_src_pdo_cnt;
@@ -224,13 +238,6 @@ void pd_dump_packet(void *ctxt, const char *msg);
*/
void pd_set_clock(int freq);
-/**
- * Enable/Disable the host pull-up on CC.
- *
- * @param enable non null if we are a host / power source.
- */
-void pd_set_host_mode(int enable);
-
/* TX/RX callbacks */
/**