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>
This commit is contained in:
Vincent Palatin
2014-04-18 11:56:50 -07:00
committed by chrome-internal-fetch
parent 2457b509cc
commit 439bfbdded
6 changed files with 49 additions and 28 deletions

View File

@@ -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 */

View File

@@ -112,3 +112,7 @@ int pd_set_power_supply_ready(void)
void pd_power_supply_reset(void)
{
}
void pd_board_checks(void)
{
}

View File

@@ -106,3 +106,7 @@ void pd_power_supply_reset(void)
set_output_voltage(VO_5V);
/* TODO transition delay */
}
void pd_board_checks(void)
{
}

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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 */
/**