pd: add support for suspending the task

used by usb debug, which uses the same spi port

BRANCH=none
BUG=none
TEST=verify PD communication works after suspend with two fruitpies

Change-Id: I9d7e963fc27dc5303a8b87a9ddb68e97600a5a10
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/202992
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Dominic Chen
2014-06-06 14:46:00 -07:00
committed by chrome-internal-fetch
parent 73ad1f30c8
commit bab451bd7c
3 changed files with 39 additions and 1 deletions

View File

@@ -394,6 +394,14 @@ void pd_rx_handler(void)
DECLARE_IRQ(STM32_IRQ_COMP, pd_rx_handler, 1);
#endif
/* --- release hardware --- */
void pd_hw_release(void)
{
__hw_timer_enable_clock(TIM_RX, 0);
__hw_timer_enable_clock(TIM_TX, 0);
dma_disable(DMAC_SPI_TX);
}
/* --- Startup initialization --- */
void *pd_hw_init(void)
{

View File

@@ -197,6 +197,7 @@ static uint8_t pd_polarity;
static enum {
PD_STATE_DISABLED,
#ifdef CONFIG_USB_PD_DUAL_ROLE
PD_STATE_SUSPENDED,
PD_STATE_SNK_DISCONNECTED,
PD_STATE_SNK_DISCOVERY,
PD_STATE_SNK_REQUESTED,
@@ -870,6 +871,17 @@ void pd_task(void)
}
break;
#ifdef CONFIG_USB_PD_DUAL_ROLE
case PD_STATE_SUSPENDED:
pd_rx_disable_monitoring();
pd_hw_release();
pd_power_supply_reset();
/* Wait for resume */
while (pd_task_state == PD_STATE_SUSPENDED)
task_wait_event(-1);
pd_hw_init();
break;
case PD_STATE_SNK_DISCONNECTED:
/* Source connection monitoring */
#ifdef BOARD_SAMUS_PD
@@ -973,6 +985,13 @@ void pd_rx_event(void)
}
#ifdef CONFIG_COMMON_RUNTIME
void pd_set_suspend(int enable)
{
pd_task_state = enable ? PD_STATE_SUSPENDED : PD_DEFAULT_STATE;
task_wake(TASK_ID_PD);
}
void pd_request_source_voltage(int mv)
{
pd_set_max_voltage(mv);
@@ -1029,7 +1048,7 @@ static int command_pd(int argc, char **argv)
task_wake(TASK_ID_PD);
} else if (!strncasecmp(argv[1], "state", 5)) {
const char * const state_names[] = {
"DISABLED",
"DISABLED", "SUSPENDED",
"SNK_DISCONNECTED", "SNK_DISCOVERY", "SNK_REQUESTED",
"SNK_TRANSITION", "SNK_READY",
"SRC_DISCONNECTED", "SRC_DISCOVERY", "SRC_NEGOCIATE",

View File

@@ -316,6 +316,12 @@ void pd_tx_done(int polarity);
*/
int pd_rx_started(void);
/**
* Suspend the PD task.
* @param enable pass 0 to resume, anything else to suspend
*/
void pd_set_suspend(int enable);
/* Callback when the hardware has detected an incoming packet */
void pd_rx_event(void);
/* Start sampling the CC line for reception */
@@ -328,6 +334,11 @@ void pd_rx_enable_monitoring(void);
/* stop listening to the CC wire during transmissions */
void pd_rx_disable_monitoring(void);
/**
* Deinitialize the hardware used for PD.
*/
void pd_hw_release(void);
/**
* Initialize the hardware used for PD RX/TX.
*