diff options
author | Diana Z <dzigterman@chromium.org> | 2020-09-25 11:46:22 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-05 18:11:32 +0000 |
commit | b0ae00fee75611adf4e265b67d3773b8bc371e50 (patch) | |
tree | 27916dd4622d15c4b19f95ff48e34adfbd260f05 | |
parent | 0d33970abab4369391ae6636537d1904592adca5 (diff) | |
download | chrome-ec-b0ae00fee75611adf4e265b67d3773b8bc371e50.tar.gz |
TCPMv2: Add framework for per-port events
The AP would like to retrieve events on a per-port basis, so add new
tracking for those events, as well as the capability for non-PD tasks to
retrieve and set those events. For the moment, the code just clears
events on startup and event flags will be added in subsequent CLs.
BRANCH=None
BUG=b:148816435
TEST=make -j buildall
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I9c2644141b4f5277ee54b4bf2c30087b51a87d8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2432454
-rw-r--r-- | common/usbc/usb_pe_drp_sm.c | 31 | ||||
-rw-r--r-- | include/usb_pd.h | 20 | ||||
-rw-r--r-- | include/usb_pe_sm.h | 8 |
3 files changed, 59 insertions, 0 deletions
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index 7f8127b1b9..cbad15eba0 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -569,6 +569,12 @@ static struct policy_engine { /* last requested voltage PDO index */ int requested_idx; + /* + * Port events - PD_STATUS_EVENT_* values + * Set from PD task but may be cleared by host command + */ + uint32_t events; + /* port address where soft resets are sent */ enum tcpm_transmit_type soft_reset_sop; @@ -841,6 +847,7 @@ static void pe_init(int port) pe[port].no_response_timer = TIMER_DISABLED; pe[port].data_role = pd_get_data_role(port); pe[port].tx_type = TCPC_TX_INVALID; + pe[port].events = 0; tc_pd_connection(port, 0); @@ -1016,6 +1023,27 @@ void pe_invalidate_explicit_contract(int port) typec_update_cc(port); } +void pe_notify_event(int port, uint32_t event_mask) +{ + /* Events may only be set from the PD task */ + assert(port == TASK_ID_TO_PD_PORT(task_get_current())); + + deprecated_atomic_or(&pe[port].events, event_mask); + + /* Notify the host that new events are available to read */ + pd_send_host_event(PD_EVENT_TYPEC); +} + +void pd_clear_events(int port, uint32_t clear_mask) +{ + deprecated_atomic_clear(&pe[port].events, clear_mask); +} + +uint32_t pd_get_events(int port) +{ + return pe[port].events; +} + /* * Determine if this port may communicate with the cable plug. * @@ -1228,6 +1256,9 @@ static void pe_handle_detach(void) * Note: The HardResetCounter is reset on a power cycle or Detach. */ pe[port].hard_reset_counter = 0; + + /* Reset port events */ + pd_clear_events(port, GENMASK(31, 0)); } DECLARE_HOOK(HOOK_USB_PD_DISCONNECT, pe_handle_detach, HOOK_PRIO_DEFAULT); diff --git a/include/usb_pd.h b/include/usb_pd.h index c14c2acfbb..46222ea14a 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -2293,6 +2293,10 @@ extern const int pd_snk_pdo_cnt; /** * Request that a host event be sent to notify the AP of a PD power event. * + * Note: per-port events should be retrieved through pd_get_events(), but this + * function still notifies the AP there are events to retrieve, and directs it + * to the per-port events through PD_EVENT_TYPEC + * * @param mask host event mask. */ #if defined(HAS_TASK_HOSTCMD) && !defined(TEST_BUILD) @@ -2584,6 +2588,22 @@ void pd_transmit_complete(int port, int status); enum tcpc_cc_polarity pd_get_polarity(int port); /** + * Get the port events. + * + * @param port USB-C port number + * @return PD_STATUS_EVENT_* bitmask + */ +uint32_t pd_get_events(int port); + +/** + * Clear selected port events + * + * @param port USB-C port number + * @param clear_mask bitmask of events to clear (PD_STATUS_EVENT_* bitmask) + */ +void pd_clear_events(int port, uint32_t clear_mask); + +/** * Get port partner data swap capable status * * @param port USB-C port number diff --git a/include/usb_pe_sm.h b/include/usb_pe_sm.h index 0cd3bd86da..6a4aea5415 100644 --- a/include/usb_pe_sm.h +++ b/include/usb_pe_sm.h @@ -166,5 +166,13 @@ const char *pe_get_current_state(int port); */ uint32_t pe_get_flags(int port); +/** + * Sets event for PE layer to report and triggers a notification up to the AP. + * + * @param port USB-C port number + * @param event_mask of bits to set (PD_STATUS_EVENT_* events in ec_commands.h) + */ +void pe_notify_event(int port, uint32_t event_mask); + #endif /* __CROS_EC_USB_PE_H */ |