usb_c: run clang-format
Run clang-format Signed-off-by: Sam Hurst <sbh1187@gmail.com>
This commit is contained in:
parent
7910c617be
commit
914fed36d5
12 changed files with 152 additions and 237 deletions
|
@ -50,8 +50,7 @@ void pe_suspend(const struct device *dev);
|
||||||
* @param dev Pointer to the device structure for the driver instance
|
* @param dev Pointer to the device structure for the driver instance
|
||||||
* @param dpm_request Device Policy Manager request
|
* @param dpm_request Device Policy Manager request
|
||||||
*/
|
*/
|
||||||
void pe_run(const struct device *dev,
|
void pe_run(const struct device *dev, const int32_t dpm_request);
|
||||||
const int32_t dpm_request);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Query if the Policy Engine is running
|
* @brief Query if the Policy Engine is running
|
||||||
|
@ -77,8 +76,7 @@ void pe_message_sent(const struct device *dev);
|
||||||
* @param e policy error
|
* @param e policy error
|
||||||
* @param type port partner address where error was generated
|
* @param type port partner address where error was generated
|
||||||
*/
|
*/
|
||||||
void pe_report_error(const struct device *dev,
|
void pe_report_error(const struct device *dev, const enum pe_error e,
|
||||||
const enum pe_error e,
|
|
||||||
const enum pd_packet_type type);
|
const enum pd_packet_type type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -118,8 +118,7 @@ bool pe_is_running(const struct device *dev)
|
||||||
/**
|
/**
|
||||||
* @brief Run the Policy Engine layer
|
* @brief Run the Policy Engine layer
|
||||||
*/
|
*/
|
||||||
void pe_run(const struct device *dev,
|
void pe_run(const struct device *dev, const int32_t dpm_request)
|
||||||
const int32_t dpm_request)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
struct policy_engine *pe = data->pe;
|
struct policy_engine *pe = data->pe;
|
||||||
|
@ -218,8 +217,7 @@ void pe_message_sent(const struct device *dev)
|
||||||
/**
|
/**
|
||||||
* @brief Informs the Policy Engine of an error.
|
* @brief Informs the Policy Engine of an error.
|
||||||
*/
|
*/
|
||||||
void pe_report_error(const struct device *dev,
|
void pe_report_error(const struct device *dev, const enum pe_error e,
|
||||||
const enum pe_error e,
|
|
||||||
const enum pd_packet_type type)
|
const enum pd_packet_type type)
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
@ -250,10 +248,9 @@ void pe_report_error(const struct device *dev,
|
||||||
* response.
|
* response.
|
||||||
*/
|
*/
|
||||||
/* All error types besides transmit errors are Protocol Errors. */
|
/* All error types besides transmit errors are Protocol Errors. */
|
||||||
if ((e != ERR_XMIT &&
|
if ((e != ERR_XMIT && atomic_test_bit(&pe->flags, PE_FLAGS_INTERRUPTIBLE_AMS) == false) ||
|
||||||
atomic_test_bit(&pe->flags, PE_FLAGS_INTERRUPTIBLE_AMS) == false) ||
|
e == ERR_XMIT ||
|
||||||
e == ERR_XMIT ||
|
(atomic_test_bit(&pe->flags, PE_FLAGS_EXPLICIT_CONTRACT) == false &&
|
||||||
(atomic_test_bit(&pe->flags, PE_FLAGS_EXPLICIT_CONTRACT) == false &&
|
|
||||||
type == PD_PACKET_SOP)) {
|
type == PD_PACKET_SOP)) {
|
||||||
policy_notify(dev, PROTOCOL_ERROR);
|
policy_notify(dev, PROTOCOL_ERROR);
|
||||||
pe_send_soft_reset(dev, type);
|
pe_send_soft_reset(dev, type);
|
||||||
|
@ -342,8 +339,7 @@ bool pe_dpm_initiated_ams(const struct device *dev)
|
||||||
/**
|
/**
|
||||||
* @brief Sets a Policy Engine state
|
* @brief Sets a Policy Engine state
|
||||||
*/
|
*/
|
||||||
void pe_set_state(const struct device *dev,
|
void pe_set_state(const struct device *dev, const enum usbc_pe_state state)
|
||||||
const enum usbc_pe_state state)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -373,8 +369,7 @@ enum usbc_pe_state pe_get_last_state(const struct device *dev)
|
||||||
/**
|
/**
|
||||||
* @brief Send a soft reset message
|
* @brief Send a soft reset message
|
||||||
*/
|
*/
|
||||||
void pe_send_soft_reset(const struct device *dev,
|
void pe_send_soft_reset(const struct device *dev, const enum pd_packet_type type)
|
||||||
const enum pd_packet_type type)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -385,9 +380,8 @@ void pe_send_soft_reset(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Send a Power Delivery Data Message
|
* @brief Send a Power Delivery Data Message
|
||||||
*/
|
*/
|
||||||
void pe_send_data_msg(const struct device *dev,
|
void pe_send_data_msg(const struct device *dev, const enum pd_packet_type type,
|
||||||
const enum pd_packet_type type,
|
const enum pd_data_msg_type msg)
|
||||||
const enum pd_data_msg_type msg)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
struct policy_engine *pe = data->pe;
|
struct policy_engine *pe = data->pe;
|
||||||
|
@ -400,9 +394,8 @@ void pe_send_data_msg(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Send a Power Delivery Control Message
|
* @brief Send a Power Delivery Control Message
|
||||||
*/
|
*/
|
||||||
void pe_send_ctrl_msg(const struct device *dev,
|
void pe_send_ctrl_msg(const struct device *dev, const enum pd_packet_type type,
|
||||||
const enum pd_packet_type type,
|
const enum pd_ctrl_msg_type msg)
|
||||||
const enum pd_ctrl_msg_type msg)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
struct policy_engine *pe = data->pe;
|
struct policy_engine *pe = data->pe;
|
||||||
|
@ -415,8 +408,7 @@ void pe_send_ctrl_msg(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Request desired voltage from source.
|
* @brief Request desired voltage from source.
|
||||||
*/
|
*/
|
||||||
void pe_send_request_msg(const struct device *dev,
|
void pe_send_request_msg(const struct device *dev, const uint32_t rdo)
|
||||||
const uint32_t rdo)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
struct protocol_layer_tx_t *prl_tx = data->prl_tx;
|
struct protocol_layer_tx_t *prl_tx = data->prl_tx;
|
||||||
|
@ -441,8 +433,7 @@ void extended_message_not_supported(const struct device *dev)
|
||||||
|
|
||||||
ext_header.raw_value = *payload;
|
ext_header.raw_value = *payload;
|
||||||
|
|
||||||
if (ext_header.chunked &&
|
if (ext_header.chunked && ext_header.data_size > PD_MAX_EXTENDED_MSG_CHUNK_LEN) {
|
||||||
ext_header.data_size > PD_MAX_EXTENDED_MSG_CHUNK_LEN) {
|
|
||||||
pe_set_state(dev, PE_SNK_CHUNK_RECEIVED);
|
pe_set_state(dev, PE_SNK_CHUNK_RECEIVED);
|
||||||
} else {
|
} else {
|
||||||
pe_set_state(dev, PE_SEND_NOT_SUPPORTED);
|
pe_set_state(dev, PE_SEND_NOT_SUPPORTED);
|
||||||
|
@ -452,16 +443,13 @@ void extended_message_not_supported(const struct device *dev)
|
||||||
/**
|
/**
|
||||||
* @brief Check if a specific control message was received
|
* @brief Check if a specific control message was received
|
||||||
*/
|
*/
|
||||||
bool received_control_message(const struct device *dev,
|
bool received_control_message(const struct device *dev, const union pd_header header,
|
||||||
const union pd_header header,
|
const enum pd_ctrl_msg_type mt)
|
||||||
const enum pd_ctrl_msg_type mt)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
struct protocol_layer_rx_t *prl_rx = data->prl_rx;
|
struct protocol_layer_rx_t *prl_rx = data->prl_rx;
|
||||||
|
|
||||||
if (prl_rx->emsg.len == 0 &&
|
if (prl_rx->emsg.len == 0 && header.message_type == mt && header.extended == 0) {
|
||||||
header.message_type == mt &&
|
|
||||||
header.extended == 0) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,16 +459,13 @@ bool received_control_message(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Check if a specific data message was received
|
* @brief Check if a specific data message was received
|
||||||
*/
|
*/
|
||||||
bool received_data_message(const struct device *dev,
|
bool received_data_message(const struct device *dev, const union pd_header header,
|
||||||
const union pd_header header,
|
const enum pd_data_msg_type mt)
|
||||||
const enum pd_data_msg_type mt)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
struct protocol_layer_rx_t *prl_rx = data->prl_rx;
|
struct protocol_layer_rx_t *prl_rx = data->prl_rx;
|
||||||
|
|
||||||
if (prl_rx->emsg.len > 0 &&
|
if (prl_rx->emsg.len > 0 && header.message_type == mt && header.extended == 0) {
|
||||||
header.message_type == mt &&
|
|
||||||
header.extended == 0) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,8 +475,7 @@ bool received_data_message(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Check a DPM policy
|
* @brief Check a DPM policy
|
||||||
*/
|
*/
|
||||||
bool policy_check(const struct device *dev,
|
bool policy_check(const struct device *dev, const enum usbc_policy_check_t pc)
|
||||||
const enum usbc_policy_check_t pc)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -505,8 +489,7 @@ bool policy_check(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Notify the DPM of a policy change
|
* @brief Notify the DPM of a policy change
|
||||||
*/
|
*/
|
||||||
void policy_notify(const struct device *dev,
|
void policy_notify(const struct device *dev, const enum usbc_policy_notify_t notify)
|
||||||
const enum usbc_policy_notify_t notify)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -518,8 +501,7 @@ void policy_notify(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Notify the DPM of a WAIT message reception
|
* @brief Notify the DPM of a WAIT message reception
|
||||||
*/
|
*/
|
||||||
bool policy_wait_notify(const struct device *dev,
|
bool policy_wait_notify(const struct device *dev, const enum usbc_policy_wait_t notify)
|
||||||
const enum usbc_policy_wait_t notify)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -533,9 +515,7 @@ bool policy_wait_notify(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Send the received source caps to the DPM
|
* @brief Send the received source caps to the DPM
|
||||||
*/
|
*/
|
||||||
void policy_set_src_cap(const struct device *dev,
|
void policy_set_src_cap(const struct device *dev, const uint32_t *pdos, const int num_pdos)
|
||||||
const uint32_t *pdos,
|
|
||||||
const int num_pdos)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -552,8 +532,7 @@ uint32_t policy_get_request_data_object(const struct device *dev)
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
/* This callback must be implemented */
|
/* This callback must be implemented */
|
||||||
__ASSERT(data->policy_cb_get_rdo != NULL,
|
__ASSERT(data->policy_cb_get_rdo != NULL, "Callback pointer should not be NULL");
|
||||||
"Callback pointer should not be NULL");
|
|
||||||
|
|
||||||
return data->policy_cb_get_rdo(dev);
|
return data->policy_cb_get_rdo(dev);
|
||||||
}
|
}
|
||||||
|
@ -575,15 +554,12 @@ bool policy_is_snk_at_default(const struct device *dev)
|
||||||
/**
|
/**
|
||||||
* @brief Get sink caps from the DPM
|
* @brief Get sink caps from the DPM
|
||||||
*/
|
*/
|
||||||
void policy_get_snk_cap(const struct device *dev,
|
void policy_get_snk_cap(const struct device *dev, uint32_t **pdos, int *num_pdos)
|
||||||
uint32_t **pdos,
|
|
||||||
int *num_pdos)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
/* This callback must be implemented */
|
/* This callback must be implemented */
|
||||||
__ASSERT(data->policy_cb_get_snk_cap != NULL,
|
__ASSERT(data->policy_cb_get_snk_cap != NULL, "Callback pointer should not be NULL");
|
||||||
"Callback pointer should not be NULL");
|
|
||||||
|
|
||||||
data->policy_cb_get_snk_cap(dev, pdos, num_pdos);
|
data->policy_cb_get_snk_cap(dev, pdos, num_pdos);
|
||||||
}
|
}
|
||||||
|
@ -597,8 +573,8 @@ void pe_drs_evaluate_swap_entry(void *obj)
|
||||||
const struct device *dev = pe->dev;
|
const struct device *dev = pe->dev;
|
||||||
|
|
||||||
/* Get evaluation of Data Role Swap request from Device Policy Manager */
|
/* Get evaluation of Data Role Swap request from Device Policy Manager */
|
||||||
if (policy_check(dev, (pe->data_role == TC_ROLE_UFP) ?
|
if (policy_check(dev, (pe->data_role == TC_ROLE_UFP) ? CHECK_DATA_ROLE_SWAP_TO_DFP
|
||||||
CHECK_DATA_ROLE_SWAP_TO_DFP : CHECK_DATA_ROLE_SWAP_TO_UFP)) {
|
: CHECK_DATA_ROLE_SWAP_TO_UFP)) {
|
||||||
/*
|
/*
|
||||||
* PE_DRS_DFP_UFP_Accept_Swap and PE_DRS_UFP_DFP_Accept_Swap
|
* PE_DRS_DFP_UFP_Accept_Swap and PE_DRS_UFP_DFP_Accept_Swap
|
||||||
* State embedded here
|
* State embedded here
|
||||||
|
@ -634,8 +610,8 @@ void pe_drs_evaluate_swap_run(void *obj)
|
||||||
/* Notify TCPC of role update */
|
/* Notify TCPC of role update */
|
||||||
tcpc_set_roles(data->tcpc, pe->power_role, pe->data_role);
|
tcpc_set_roles(data->tcpc, pe->power_role, pe->data_role);
|
||||||
/* Inform Device Policy Manager of Data Role Change */
|
/* Inform Device Policy Manager of Data Role Change */
|
||||||
policy_notify(dev, (pe->data_role == TC_ROLE_UFP) ?
|
policy_notify(dev, (pe->data_role == TC_ROLE_UFP) ? DATA_ROLE_IS_UFP
|
||||||
DATA_ROLE_IS_UFP : DATA_ROLE_IS_DFP);
|
: DATA_ROLE_IS_DFP);
|
||||||
}
|
}
|
||||||
pe_set_state(dev, PE_SNK_READY);
|
pe_set_state(dev, PE_SNK_READY);
|
||||||
} else if (atomic_test_and_clear_bit(&pe->flags, PE_FLAGS_MSG_DISCARDED)) {
|
} else if (atomic_test_and_clear_bit(&pe->flags, PE_FLAGS_MSG_DISCARDED)) {
|
||||||
|
@ -699,8 +675,8 @@ void pe_drs_send_swap_run(void *obj)
|
||||||
/* Notify TCPC of role update */
|
/* Notify TCPC of role update */
|
||||||
tcpc_set_roles(data->tcpc, pe->power_role, pe->data_role);
|
tcpc_set_roles(data->tcpc, pe->power_role, pe->data_role);
|
||||||
/* Inform Device Policy Manager of Data Role Change */
|
/* Inform Device Policy Manager of Data Role Change */
|
||||||
policy_notify(dev, (pe->data_role == TC_ROLE_UFP) ?
|
policy_notify(dev, (pe->data_role == TC_ROLE_UFP) ? DATA_ROLE_IS_UFP
|
||||||
DATA_ROLE_IS_UFP : DATA_ROLE_IS_DFP);
|
: DATA_ROLE_IS_DFP);
|
||||||
} else {
|
} else {
|
||||||
/* Protocol Error */
|
/* Protocol Error */
|
||||||
policy_notify(dev, PROTOCOL_ERROR);
|
policy_notify(dev, PROTOCOL_ERROR);
|
||||||
|
|
|
@ -62,52 +62,52 @@ enum usbc_pe_state {
|
||||||
*/
|
*/
|
||||||
enum pe_flags {
|
enum pe_flags {
|
||||||
/** Accept message received from port partner */
|
/** Accept message received from port partner */
|
||||||
PE_FLAGS_ACCEPT = 0,
|
PE_FLAGS_ACCEPT = 0,
|
||||||
/**
|
/**
|
||||||
* Protocol Error was determined based on error recovery
|
* Protocol Error was determined based on error recovery
|
||||||
* current state
|
* current state
|
||||||
*/
|
*/
|
||||||
PE_FLAGS_PROTOCOL_ERROR = 1,
|
PE_FLAGS_PROTOCOL_ERROR = 1,
|
||||||
/** A message we requested to be sent has been transmitted */
|
/** A message we requested to be sent has been transmitted */
|
||||||
PE_FLAGS_TX_COMPLETE = 2,
|
PE_FLAGS_TX_COMPLETE = 2,
|
||||||
/** A message sent by a port partner has been received */
|
/** A message sent by a port partner has been received */
|
||||||
PE_FLAGS_MSG_RECEIVED = 3,
|
PE_FLAGS_MSG_RECEIVED = 3,
|
||||||
/**
|
/**
|
||||||
* A hard reset has been requested by the DPM but has not been sent,
|
* A hard reset has been requested by the DPM but has not been sent,
|
||||||
* not currently used
|
* not currently used
|
||||||
*/
|
*/
|
||||||
PE_FLAGS_HARD_RESET_PENDING = 4,
|
PE_FLAGS_HARD_RESET_PENDING = 4,
|
||||||
/** An explicit contract is in place with our port partner */
|
/** An explicit contract is in place with our port partner */
|
||||||
PE_FLAGS_EXPLICIT_CONTRACT = 5,
|
PE_FLAGS_EXPLICIT_CONTRACT = 5,
|
||||||
/**
|
/**
|
||||||
* Waiting for Sink Capabailities timed out. Used for retry error
|
* Waiting for Sink Capabailities timed out. Used for retry error
|
||||||
* handling
|
* handling
|
||||||
*/
|
*/
|
||||||
PE_FLAGS_SNK_WAIT_CAP_TIMEOUT = 6,
|
PE_FLAGS_SNK_WAIT_CAP_TIMEOUT = 6,
|
||||||
/**
|
/**
|
||||||
* Flag to note current Atomic Message Sequence (AMS) is interruptible.
|
* Flag to note current Atomic Message Sequence (AMS) is interruptible.
|
||||||
* If this flag is not set the AMS is non-interruptible. This flag must
|
* If this flag is not set the AMS is non-interruptible. This flag must
|
||||||
* be set in the interruptible's message state entry.
|
* be set in the interruptible's message state entry.
|
||||||
*/
|
*/
|
||||||
PE_FLAGS_INTERRUPTIBLE_AMS = 7,
|
PE_FLAGS_INTERRUPTIBLE_AMS = 7,
|
||||||
/** Flag to trigger sending a Data Role Swap */
|
/** Flag to trigger sending a Data Role Swap */
|
||||||
PE_FLAGS_DR_SWAP_TO_DFP = 8,
|
PE_FLAGS_DR_SWAP_TO_DFP = 8,
|
||||||
/** Flag is set when an AMS is initiated by the Device Policy Manager */
|
/** Flag is set when an AMS is initiated by the Device Policy Manager */
|
||||||
PE_FLAGS_DPM_INITIATED_AMS = 9,
|
PE_FLAGS_DPM_INITIATED_AMS = 9,
|
||||||
/** Flag to note message was discarded due to incoming message */
|
/** Flag to note message was discarded due to incoming message */
|
||||||
PE_FLAGS_MSG_DISCARDED = 10,
|
PE_FLAGS_MSG_DISCARDED = 10,
|
||||||
/** Flag to trigger sending a soft reset */
|
/** Flag to trigger sending a soft reset */
|
||||||
PE_FLAGS_SEND_SOFT_RESET = 11,
|
PE_FLAGS_SEND_SOFT_RESET = 11,
|
||||||
/**
|
/**
|
||||||
* This flag is set when a Wait message is received in response to a
|
* This flag is set when a Wait message is received in response to a
|
||||||
* Sink REQUEST
|
* Sink REQUEST
|
||||||
*/
|
*/
|
||||||
PE_FLAGS_WAIT_SINK_REQUEST = 12,
|
PE_FLAGS_WAIT_SINK_REQUEST = 12,
|
||||||
/**
|
/**
|
||||||
* This flag is set when a Wait message is received in response to a
|
* This flag is set when a Wait message is received in response to a
|
||||||
* Data Role Swap
|
* Data Role Swap
|
||||||
*/
|
*/
|
||||||
PE_FLAGS_WAIT_DATA_ROLE_SWAP = 13
|
PE_FLAGS_WAIT_DATA_ROLE_SWAP = 13
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,8 +159,7 @@ struct policy_engine {
|
||||||
* @param dev Pointer to the device structure for the driver instance
|
* @param dev Pointer to the device structure for the driver instance
|
||||||
* @param state next PE State to enter
|
* @param state next PE State to enter
|
||||||
*/
|
*/
|
||||||
void pe_set_state(const struct device *dev,
|
void pe_set_state(const struct device *dev, const enum usbc_pe_state state);
|
||||||
const enum usbc_pe_state state);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Policy Engine's current state
|
* @brief Get the Policy Engine's current state
|
||||||
|
@ -184,8 +183,7 @@ enum usbc_pe_state pe_get_last_state(const struct device *dev);
|
||||||
* @param dev Pointer to the device structure for the driver instance
|
* @param dev Pointer to the device structure for the driver instance
|
||||||
* @param type SOP* to send soft reset message
|
* @param type SOP* to send soft reset message
|
||||||
*/
|
*/
|
||||||
void pe_send_soft_reset(const struct device *dev,
|
void pe_send_soft_reset(const struct device *dev, const enum pd_packet_type type);
|
||||||
const enum pd_packet_type type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send a Power Delivery Data Message
|
* @brief Send a Power Delivery Data Message
|
||||||
|
@ -215,8 +213,7 @@ void pe_send_ctrl_msg(const struct device *dev,
|
||||||
* @param dev Pointer to the device structure for the driver instance
|
* @param dev Pointer to the device structure for the driver instance
|
||||||
* @param rdo Request Data Object to send
|
* @param rdo Request Data Object to send
|
||||||
*/
|
*/
|
||||||
void pe_send_request_msg(const struct device *dev,
|
void pe_send_request_msg(const struct device *dev, const uint32_t rdo);
|
||||||
const uint32_t rdo);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Transitions state after receiving an extended message.
|
* @brief Transitions state after receiving an extended message.
|
||||||
|
@ -233,8 +230,7 @@ void extended_message_not_supported(const struct device *dev);
|
||||||
* @param mt message type to check
|
* @param mt message type to check
|
||||||
* @retval true if the header contains the message type, else false
|
* @retval true if the header contains the message type, else false
|
||||||
*/
|
*/
|
||||||
bool received_control_message(const struct device *dev,
|
bool received_control_message(const struct device *dev, const union pd_header header,
|
||||||
const union pd_header header,
|
|
||||||
const enum pd_ctrl_msg_type mt);
|
const enum pd_ctrl_msg_type mt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -245,8 +241,7 @@ bool received_control_message(const struct device *dev,
|
||||||
* @param mt message type to check
|
* @param mt message type to check
|
||||||
* @param true if the header contains the message type, else false
|
* @param true if the header contains the message type, else false
|
||||||
*/
|
*/
|
||||||
bool received_data_message(const struct device *dev,
|
bool received_data_message(const struct device *dev, const union pd_header header,
|
||||||
const union pd_header header,
|
|
||||||
const enum pd_data_msg_type mt);
|
const enum pd_data_msg_type mt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -256,8 +251,7 @@ bool received_data_message(const struct device *dev,
|
||||||
* @param pc The DPM policy to check
|
* @param pc The DPM policy to check
|
||||||
* @retval true if the DPM approves the check, else false
|
* @retval true if the DPM approves the check, else false
|
||||||
*/
|
*/
|
||||||
bool policy_check(const struct device *dev,
|
bool policy_check(const struct device *dev, const enum usbc_policy_check_t pc);
|
||||||
const enum usbc_policy_check_t pc);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Notify the DPM of a policy change
|
* @brief Notify the DPM of a policy change
|
||||||
|
@ -265,8 +259,7 @@ bool policy_check(const struct device *dev,
|
||||||
* @param dev Pointer to the device structure for the driver instance
|
* @param dev Pointer to the device structure for the driver instance
|
||||||
* @param notify The notification to send the the DPM
|
* @param notify The notification to send the the DPM
|
||||||
*/
|
*/
|
||||||
void policy_notify(const struct device *dev,
|
void policy_notify(const struct device *dev, const enum usbc_policy_notify_t notify);
|
||||||
const enum usbc_policy_notify_t notify);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Notify the DPM of a WAIT message reception
|
* @brief Notify the DPM of a WAIT message reception
|
||||||
|
@ -275,9 +268,7 @@ void policy_notify(const struct device *dev,
|
||||||
* @param notify Wait message to send to DPM
|
* @param notify Wait message to send to DPM
|
||||||
* @retval true if the Policy Engine should wait and try the action again
|
* @retval true if the Policy Engine should wait and try the action again
|
||||||
*/
|
*/
|
||||||
bool policy_wait_notify(const struct device *dev,
|
bool policy_wait_notify(const struct device *dev, const enum usbc_policy_wait_t notify);
|
||||||
const enum usbc_policy_wait_t notify);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send the received source caps to the DPM
|
* @brief Send the received source caps to the DPM
|
||||||
|
@ -286,9 +277,7 @@ bool policy_wait_notify(const struct device *dev,
|
||||||
* @param pdos pointer to pdos to send
|
* @param pdos pointer to pdos to send
|
||||||
* @param num_pdos number of pdos to send
|
* @param num_pdos number of pdos to send
|
||||||
*/
|
*/
|
||||||
void policy_set_src_cap(const struct device *dev,
|
void policy_set_src_cap(const struct device *dev, const uint32_t *pdos, const int num_pdos);
|
||||||
const uint32_t *pdos,
|
|
||||||
const int num_pdos);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get a Request Data Object from the DPM
|
* @brief Get a Request Data Object from the DPM
|
||||||
|
@ -313,8 +302,6 @@ bool policy_is_snk_at_default(const struct device *dev);
|
||||||
* @param pdos pointer to pdo sink caps
|
* @param pdos pointer to pdo sink caps
|
||||||
* @param num_pdos number of pdo sink caps
|
* @param num_pdos number of pdo sink caps
|
||||||
*/
|
*/
|
||||||
void policy_get_snk_cap(const struct device *dev,
|
void policy_get_snk_cap(const struct device *dev, uint32_t **pdos, int *num_pdos);
|
||||||
uint32_t **pdos,
|
|
||||||
int *num_pdos);
|
|
||||||
|
|
||||||
#endif /* ZEPHYR_SUBSYS_USBC_PE_COMMON_INTERNAL_H_ */
|
#endif /* ZEPHYR_SUBSYS_USBC_PE_COMMON_INTERNAL_H_ */
|
||||||
|
|
|
@ -205,7 +205,6 @@ void pe_snk_select_capability_entry(void *obj)
|
||||||
policy_notify(dev, PD_CONNECTED);
|
policy_notify(dev, PD_CONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PE_SNK_Select_Capability Run State
|
* @brief PE_SNK_Select_Capability Run State
|
||||||
*/
|
*/
|
||||||
|
@ -274,7 +273,7 @@ void pe_snk_select_capability_run(void *obj)
|
||||||
*/
|
*/
|
||||||
if (policy_wait_notify(dev, WAIT_SINK_REQUEST)) {
|
if (policy_wait_notify(dev, WAIT_SINK_REQUEST)) {
|
||||||
atomic_set_bit(&pe->flags,
|
atomic_set_bit(&pe->flags,
|
||||||
PE_FLAGS_WAIT_SINK_REQUEST);
|
PE_FLAGS_WAIT_SINK_REQUEST);
|
||||||
usbc_timer_start(&pe->pd_t_wait_to_resend);
|
usbc_timer_start(&pe->pd_t_wait_to_resend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -721,7 +720,7 @@ void pe_soft_reset_entry(void *obj)
|
||||||
/**
|
/**
|
||||||
* @brief PE_SNK_Soft_Reset Run State
|
* @brief PE_SNK_Soft_Reset Run State
|
||||||
*/
|
*/
|
||||||
void pe_soft_reset_run(void *obj)
|
void pe_soft_reset_run(void *obj)
|
||||||
{
|
{
|
||||||
struct policy_engine *pe = (struct policy_engine *)obj;
|
struct policy_engine *pe = (struct policy_engine *)obj;
|
||||||
const struct device *dev = pe->dev;
|
const struct device *dev = pe->dev;
|
||||||
|
@ -770,7 +769,7 @@ void pe_send_not_supported_run(void *obj)
|
||||||
const struct device *dev = pe->dev;
|
const struct device *dev = pe->dev;
|
||||||
|
|
||||||
if (atomic_test_bit(&pe->flags, PE_FLAGS_TX_COMPLETE) ||
|
if (atomic_test_bit(&pe->flags, PE_FLAGS_TX_COMPLETE) ||
|
||||||
atomic_test_bit(&pe->flags, PE_FLAGS_MSG_DISCARDED)) {
|
atomic_test_bit(&pe->flags, PE_FLAGS_MSG_DISCARDED)) {
|
||||||
atomic_clear_bit(&pe->flags, PE_FLAGS_TX_COMPLETE);
|
atomic_clear_bit(&pe->flags, PE_FLAGS_TX_COMPLETE);
|
||||||
atomic_clear_bit(&pe->flags, PE_FLAGS_MSG_DISCARDED);
|
atomic_clear_bit(&pe->flags, PE_FLAGS_MSG_DISCARDED);
|
||||||
pe_set_state(dev, PE_SNK_READY);
|
pe_set_state(dev, PE_SNK_READY);
|
||||||
|
|
|
@ -29,24 +29,24 @@ LOG_MODULE_DECLARE(usbc_stack, CONFIG_USBC_STACK_LOG_LEVEL);
|
||||||
*/
|
*/
|
||||||
enum prl_flags {
|
enum prl_flags {
|
||||||
/** Flag to note message transmission completed */
|
/** Flag to note message transmission completed */
|
||||||
PRL_FLAGS_TX_COMPLETE = 0,
|
PRL_FLAGS_TX_COMPLETE = 0,
|
||||||
/** Flag to note message was discarded */
|
/** Flag to note message was discarded */
|
||||||
PRL_FLAGS_TX_DISCARDED = 1,
|
PRL_FLAGS_TX_DISCARDED = 1,
|
||||||
/** Flag to note PRL waited for SINK_OK CC state before transmitting */
|
/** Flag to note PRL waited for SINK_OK CC state before transmitting */
|
||||||
PRL_FLAGS_WAIT_SINK_OK = 2,
|
PRL_FLAGS_WAIT_SINK_OK = 2,
|
||||||
/** Flag to note transmission error occurred */
|
/** Flag to note transmission error occurred */
|
||||||
PRL_FLAGS_TX_ERROR = 3,
|
PRL_FLAGS_TX_ERROR = 3,
|
||||||
/** Flag to note PE triggered a hard reset */
|
/** Flag to note PE triggered a hard reset */
|
||||||
PRL_FLAGS_PE_HARD_RESET = 4,
|
PRL_FLAGS_PE_HARD_RESET = 4,
|
||||||
/** Flag to note hard reset has completed */
|
/** Flag to note hard reset has completed */
|
||||||
PRL_FLAGS_HARD_RESET_COMPLETE = 5,
|
PRL_FLAGS_HARD_RESET_COMPLETE = 5,
|
||||||
/** Flag to note port partner sent a hard reset */
|
/** Flag to note port partner sent a hard reset */
|
||||||
PRL_FLAGS_PORT_PARTNER_HARD_RESET = 6,
|
PRL_FLAGS_PORT_PARTNER_HARD_RESET = 6,
|
||||||
/**
|
/**
|
||||||
* Flag to note a message transmission has been requested. It is only
|
* Flag to note a message transmission has been requested. It is only
|
||||||
* cleared when the message is sent to the TCPC layer.
|
* cleared when the message is sent to the TCPC layer.
|
||||||
*/
|
*/
|
||||||
PRL_FLAGS_MSG_XMIT = 7,
|
PRL_FLAGS_MSG_XMIT = 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,10 +94,8 @@ static const struct smf_state prl_hr_states[];
|
||||||
|
|
||||||
static void prl_tx_construct_message(const struct device *dev);
|
static void prl_tx_construct_message(const struct device *dev);
|
||||||
static void prl_rx_wait_for_phy_message(const struct device *dev);
|
static void prl_rx_wait_for_phy_message(const struct device *dev);
|
||||||
static void prl_hr_set_state(const struct device *dev,
|
static void prl_hr_set_state(const struct device *dev, const enum usbc_prl_hr_state_t state);
|
||||||
const enum usbc_prl_hr_state_t state);
|
static void prl_tx_set_state(const struct device *dev, const enum usbc_prl_tx_state_t state);
|
||||||
static void prl_tx_set_state(const struct device *dev,
|
|
||||||
const enum usbc_prl_tx_state_t state);
|
|
||||||
static void prl_init(const struct device *dev);
|
static void prl_init(const struct device *dev);
|
||||||
static enum usbc_prl_hr_state_t prl_hr_get_state(const struct device *dev);
|
static enum usbc_prl_hr_state_t prl_hr_get_state(const struct device *dev);
|
||||||
|
|
||||||
|
@ -167,8 +165,7 @@ void prl_hard_reset_complete(const struct device *dev)
|
||||||
* @brief Directs the Protocol Layer to construct and transmit a Power Delivery
|
* @brief Directs the Protocol Layer to construct and transmit a Power Delivery
|
||||||
* Control message.
|
* Control message.
|
||||||
*/
|
*/
|
||||||
void prl_send_ctrl_msg(const struct device *dev,
|
void prl_send_ctrl_msg(const struct device *dev, const enum pd_packet_type type,
|
||||||
const enum pd_packet_type type,
|
|
||||||
const enum pd_ctrl_msg_type msg)
|
const enum pd_ctrl_msg_type msg)
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
@ -191,8 +188,7 @@ void prl_send_ctrl_msg(const struct device *dev,
|
||||||
* @note: Before calling this function prl_tx->emsg.data and prl_tx->emsg.len
|
* @note: Before calling this function prl_tx->emsg.data and prl_tx->emsg.len
|
||||||
* must be set.
|
* must be set.
|
||||||
*/
|
*/
|
||||||
void prl_send_data_msg(const struct device *dev,
|
void prl_send_data_msg(const struct device *dev, const enum pd_packet_type type,
|
||||||
const enum pd_packet_type type,
|
|
||||||
const enum pd_data_msg_type msg)
|
const enum pd_data_msg_type msg)
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
@ -317,8 +313,7 @@ void prl_run(const struct device *dev)
|
||||||
* @brief Set revision for the give packet type. This function is called
|
* @brief Set revision for the give packet type. This function is called
|
||||||
* from the Policy Engine.
|
* from the Policy Engine.
|
||||||
*/
|
*/
|
||||||
void prl_set_rev(const struct device *dev,
|
void prl_set_rev(const struct device *dev, const enum pd_packet_type type,
|
||||||
const enum pd_packet_type type,
|
|
||||||
const enum pd_rev_type rev)
|
const enum pd_rev_type rev)
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
@ -330,8 +325,7 @@ void prl_set_rev(const struct device *dev,
|
||||||
* @brief Get the revision for the give packet type.
|
* @brief Get the revision for the give packet type.
|
||||||
* This function is called from the Policy Engine.
|
* This function is called from the Policy Engine.
|
||||||
*/
|
*/
|
||||||
enum pd_rev_type prl_get_rev(const struct device *dev,
|
enum pd_rev_type prl_get_rev(const struct device *dev, const enum pd_packet_type type)
|
||||||
const enum pd_packet_type type)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -343,9 +337,7 @@ enum pd_rev_type prl_get_rev(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Alert Handler called by the TCPC driver
|
* @brief Alert Handler called by the TCPC driver
|
||||||
*/
|
*/
|
||||||
static void alert_handler(const struct device *tcpc,
|
static void alert_handler(const struct device *tcpc, void *port_dev, enum tcpc_alert alert)
|
||||||
void *port_dev,
|
|
||||||
enum tcpc_alert alert)
|
|
||||||
{
|
{
|
||||||
const struct device *dev = (const struct device *)port_dev;
|
const struct device *dev = (const struct device *)port_dev;
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
@ -354,8 +346,7 @@ static void alert_handler(const struct device *tcpc,
|
||||||
|
|
||||||
switch (alert) {
|
switch (alert) {
|
||||||
case TCPC_ALERT_HARD_RESET_RECEIVED:
|
case TCPC_ALERT_HARD_RESET_RECEIVED:
|
||||||
atomic_set_bit(&prl_hr->flags,
|
atomic_set_bit(&prl_hr->flags, PRL_FLAGS_PORT_PARTNER_HARD_RESET);
|
||||||
PRL_FLAGS_PORT_PARTNER_HARD_RESET);
|
|
||||||
break;
|
break;
|
||||||
case TCPC_ALERT_TRANSMIT_MSG_FAILED:
|
case TCPC_ALERT_TRANSMIT_MSG_FAILED:
|
||||||
atomic_set_bit(&prl_tx->flags, PRL_FLAGS_TX_ERROR);
|
atomic_set_bit(&prl_tx->flags, PRL_FLAGS_TX_ERROR);
|
||||||
|
@ -378,8 +369,7 @@ static void alert_handler(const struct device *tcpc,
|
||||||
/**
|
/**
|
||||||
* @brief Set the Protocol Layer Message Transmission state
|
* @brief Set the Protocol Layer Message Transmission state
|
||||||
*/
|
*/
|
||||||
static void prl_tx_set_state(const struct device *dev,
|
static void prl_tx_set_state(const struct device *dev, const enum usbc_prl_tx_state_t state)
|
||||||
const enum usbc_prl_tx_state_t state)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
struct protocol_layer_tx_t *prl_tx = data->prl_tx;
|
struct protocol_layer_tx_t *prl_tx = data->prl_tx;
|
||||||
|
@ -390,8 +380,7 @@ static void prl_tx_set_state(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Set the Protocol Layer Hard Reset state
|
* @brief Set the Protocol Layer Hard Reset state
|
||||||
*/
|
*/
|
||||||
static void prl_hr_set_state(const struct device *dev,
|
static void prl_hr_set_state(const struct device *dev, const enum usbc_prl_hr_state_t state)
|
||||||
const enum usbc_prl_hr_state_t state)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
struct protocol_hard_reset_t *prl_hr = data->prl_hr;
|
struct protocol_hard_reset_t *prl_hr = data->prl_hr;
|
||||||
|
@ -424,8 +413,7 @@ static void increment_msgid_counter(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
prl_tx->msg_id_counter[prl_tx->last_xmit_type] =
|
prl_tx->msg_id_counter[prl_tx->last_xmit_type] =
|
||||||
(prl_tx->msg_id_counter[prl_tx->last_xmit_type] + 1) &
|
(prl_tx->msg_id_counter[prl_tx->last_xmit_type] + 1) & PD_MESSAGE_ID_COUNT;
|
||||||
PD_MESSAGE_ID_COUNT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -442,11 +430,9 @@ static uint32_t get_sop_star_header(const struct device *dev)
|
||||||
header.message_type = prl_tx->msg_type;
|
header.message_type = prl_tx->msg_type;
|
||||||
header.port_data_role = is_sop_packet ? pe_get_data_role(dev) : 0;
|
header.port_data_role = is_sop_packet ? pe_get_data_role(dev) : 0;
|
||||||
header.specification_revision = data->rev[prl_tx->emsg.type];
|
header.specification_revision = data->rev[prl_tx->emsg.type];
|
||||||
header.port_power_role = is_sop_packet ?
|
header.port_power_role = is_sop_packet ? pe_get_power_role(dev) : pe_get_cable_plug(dev);
|
||||||
pe_get_power_role(dev) : pe_get_cable_plug(dev);
|
|
||||||
header.message_id = prl_tx->msg_id_counter[prl_tx->emsg.type];
|
header.message_id = prl_tx->msg_id_counter[prl_tx->emsg.type];
|
||||||
header.number_of_data_objects =
|
header.number_of_data_objects = PD_CONVERT_BYTES_TO_PD_HEADER_COUNT(prl_tx->emsg.len);
|
||||||
PD_CONVERT_BYTES_TO_PD_HEADER_COUNT(prl_tx->emsg.len);
|
|
||||||
header.extended = false;
|
header.extended = false;
|
||||||
|
|
||||||
return header.raw_value;
|
return header.raw_value;
|
||||||
|
@ -462,9 +448,8 @@ static void prl_tx_construct_message(const struct device *dev)
|
||||||
const struct device *tcpc = data->tcpc;
|
const struct device *tcpc = data->tcpc;
|
||||||
|
|
||||||
/* The header is unused for hard reset, etc. */
|
/* The header is unused for hard reset, etc. */
|
||||||
prl_tx->emsg.header.raw_value = prl_tx->emsg.type < NUM_SOP_STAR_TYPES ?
|
prl_tx->emsg.header.raw_value =
|
||||||
get_sop_star_header(dev) : 0;
|
prl_tx->emsg.type < NUM_SOP_STAR_TYPES ? get_sop_star_header(dev) : 0;
|
||||||
|
|
||||||
|
|
||||||
/* Save SOP* so the correct msg_id_counter can be incremented */
|
/* Save SOP* so the correct msg_id_counter can be incremented */
|
||||||
prl_tx->last_xmit_type = prl_tx->emsg.type;
|
prl_tx->last_xmit_type = prl_tx->emsg.type;
|
||||||
|
@ -534,8 +519,7 @@ static void prl_init(const struct device *dev)
|
||||||
|
|
||||||
/* Initialize the PRL_HR state machine */
|
/* Initialize the PRL_HR state machine */
|
||||||
prl_hr->flags = ATOMIC_INIT(0);
|
prl_hr->flags = ATOMIC_INIT(0);
|
||||||
usbc_timer_init(&prl_hr->pd_t_hard_reset_complete,
|
usbc_timer_init(&prl_hr->pd_t_hard_reset_complete, PD_T_HARD_RESET_COMPLETE_MAX_MS);
|
||||||
PD_T_HARD_RESET_COMPLETE_MAX_MS);
|
|
||||||
prl_hr_set_state(dev, PRL_HR_WAIT_FOR_REQUEST);
|
prl_hr_set_state(dev, PRL_HR_WAIT_FOR_REQUEST);
|
||||||
|
|
||||||
/* Initialize the PRL_TX state machine */
|
/* Initialize the PRL_TX state machine */
|
||||||
|
@ -626,8 +610,7 @@ static void prl_tx_wait_for_message_request_run(void *obj)
|
||||||
/*
|
/*
|
||||||
* Soft Reset Message pending
|
* Soft Reset Message pending
|
||||||
*/
|
*/
|
||||||
if ((prl_tx->msg_type == PD_CTRL_SOFT_RESET) &&
|
if ((prl_tx->msg_type == PD_CTRL_SOFT_RESET) && (prl_tx->emsg.len == 0)) {
|
||||||
(prl_tx->emsg.len == 0)) {
|
|
||||||
prl_tx_set_state(dev, PRL_TX_LAYER_RESET_FOR_TRANSMIT);
|
prl_tx_set_state(dev, PRL_TX_LAYER_RESET_FOR_TRANSMIT);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -134,8 +134,7 @@ void prl_hard_reset_complete(const struct device *dev);
|
||||||
* @param type SOP* packet sent from port partner
|
* @param type SOP* packet sent from port partner
|
||||||
* @param rev Revision sent from the port partner
|
* @param rev Revision sent from the port partner
|
||||||
*/
|
*/
|
||||||
void prl_set_rev(const struct device *dev,
|
void prl_set_rev(const struct device *dev, const enum pd_packet_type type,
|
||||||
const enum pd_packet_type type,
|
|
||||||
const enum pd_rev_type rev);
|
const enum pd_rev_type rev);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,8 +145,7 @@ void prl_set_rev(const struct device *dev,
|
||||||
*
|
*
|
||||||
* @retval revsion associated with the packet type
|
* @retval revsion associated with the packet type
|
||||||
*/
|
*/
|
||||||
enum pd_rev_type prl_get_rev(const struct device *dev,
|
enum pd_rev_type prl_get_rev(const struct device *dev, const enum pd_packet_type type);
|
||||||
const enum pd_packet_type type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Instructs the Protocol Layer to send a Power Delivery control message
|
* @brief Instructs the Protocol Layer to send a Power Delivery control message
|
||||||
|
@ -156,8 +154,7 @@ enum pd_rev_type prl_get_rev(const struct device *dev,
|
||||||
* @param type The port partner to send this message to
|
* @param type The port partner to send this message to
|
||||||
* @param msg The control message to send
|
* @param msg The control message to send
|
||||||
*/
|
*/
|
||||||
void prl_send_ctrl_msg(const struct device *dev,
|
void prl_send_ctrl_msg(const struct device *dev, const enum pd_packet_type type,
|
||||||
const enum pd_packet_type type,
|
|
||||||
const enum pd_ctrl_msg_type msg);
|
const enum pd_ctrl_msg_type msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,8 +164,7 @@ void prl_send_ctrl_msg(const struct device *dev,
|
||||||
* @param type The port partner to send this message to
|
* @param type The port partner to send this message to
|
||||||
* @param msg The data message to send
|
* @param msg The data message to send
|
||||||
*/
|
*/
|
||||||
void prl_send_data_msg(const struct device *dev,
|
void prl_send_data_msg(const struct device *dev, const enum pd_packet_type type,
|
||||||
const enum pd_packet_type type,
|
|
||||||
const enum pd_data_msg_type msg);
|
const enum pd_data_msg_type msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,62 +40,50 @@ static ALWAYS_INLINE void usbc_handler(void *port_dev)
|
||||||
k_msleep(CONFIG_USBC_STATE_MACHINE_CYCLE_TIME);
|
k_msleep(CONFIG_USBC_STATE_MACHINE_CYCLE_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define USBC_SUBSYS_INIT(inst) \
|
#define USBC_SUBSYS_INIT(inst) \
|
||||||
K_THREAD_STACK_DEFINE(my_stack_area_##inst, \
|
K_THREAD_STACK_DEFINE(my_stack_area_##inst, CONFIG_USBC_STACK_SIZE); \
|
||||||
CONFIG_USBC_STACK_SIZE); \
|
\
|
||||||
\
|
static struct tc_sm_t tc_##inst; \
|
||||||
static struct tc_sm_t tc_##inst; \
|
static struct policy_engine pe_##inst; \
|
||||||
static struct policy_engine pe_##inst; \
|
static struct protocol_layer_rx_t prl_rx_##inst; \
|
||||||
static struct protocol_layer_rx_t prl_rx_##inst; \
|
static struct protocol_layer_tx_t prl_tx_##inst; \
|
||||||
static struct protocol_layer_tx_t prl_tx_##inst; \
|
static struct protocol_hard_reset_t prl_hr_##inst; \
|
||||||
static struct protocol_hard_reset_t prl_hr_##inst; \
|
\
|
||||||
\
|
static void run_usbc_##inst(void *port_dev, void *unused1, void *unused2) \
|
||||||
static void run_usbc_##inst(void *port_dev, \
|
{ \
|
||||||
void *unused1, \
|
while (1) { \
|
||||||
void *unused2) \
|
usbc_handler(port_dev); \
|
||||||
{ \
|
} \
|
||||||
while (1) { \
|
} \
|
||||||
usbc_handler(port_dev); \
|
\
|
||||||
} \
|
static void create_thread_##inst(const struct device *dev) \
|
||||||
} \
|
{ \
|
||||||
\
|
struct usbc_port_data *port = dev->data; \
|
||||||
static void create_thread_##inst(const struct device *dev) \
|
\
|
||||||
{ \
|
port->port_thread = k_thread_create( \
|
||||||
struct usbc_port_data *port = dev->data; \
|
&port->thread_data, my_stack_area_##inst, \
|
||||||
\
|
K_THREAD_STACK_SIZEOF(my_stack_area_##inst), run_usbc_##inst, (void *)dev, \
|
||||||
port->port_thread = k_thread_create(&port->thread_data, \
|
0, 0, CONFIG_USBC_THREAD_PRIORITY, K_ESSENTIAL, K_NO_WAIT); \
|
||||||
my_stack_area_##inst, \
|
k_thread_suspend(port->port_thread); \
|
||||||
K_THREAD_STACK_SIZEOF(my_stack_area_##inst), \
|
} \
|
||||||
run_usbc_##inst, \
|
\
|
||||||
(void *)dev, 0, 0, \
|
static struct usbc_port_data usbc_port_data_##inst = { \
|
||||||
CONFIG_USBC_THREAD_PRIORITY, \
|
.tc = &tc_##inst, \
|
||||||
K_ESSENTIAL, \
|
.pe = &pe_##inst, \
|
||||||
K_NO_WAIT); \
|
.prl_rx = &prl_rx_##inst, \
|
||||||
k_thread_suspend(port->port_thread); \
|
.prl_tx = &prl_tx_##inst, \
|
||||||
} \
|
.prl_hr = &prl_hr_##inst, \
|
||||||
\
|
.tcpc = DEVICE_DT_GET(DT_INST_PROP(inst, tcpc)), \
|
||||||
static struct usbc_port_data usbc_port_data_##inst = { \
|
.vbus = DEVICE_DT_GET(DT_INST_PROP(inst, vbus)), \
|
||||||
.tc = &tc_##inst, \
|
}; \
|
||||||
.pe = &pe_##inst, \
|
\
|
||||||
.prl_rx = &prl_rx_##inst, \
|
static const struct usbc_port_config usbc_port_config_##inst = { \
|
||||||
.prl_tx = &prl_tx_##inst, \
|
.create_thread = create_thread_##inst, \
|
||||||
.prl_hr = &prl_hr_##inst, \
|
}; \
|
||||||
.tcpc = DEVICE_DT_GET(DT_INST_PROP(inst, tcpc)), \
|
\
|
||||||
.vbus = DEVICE_DT_GET(DT_INST_PROP(inst, vbus)), \
|
DEVICE_DT_INST_DEFINE(inst, &usbc_subsys_init, NULL, &usbc_port_data_##inst, \
|
||||||
}; \
|
&usbc_port_config_##inst, APPLICATION, \
|
||||||
\
|
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
|
||||||
static const struct usbc_port_config usbc_port_config_##inst = { \
|
|
||||||
.create_thread = create_thread_##inst, \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
DEVICE_DT_INST_DEFINE(inst, \
|
|
||||||
&usbc_subsys_init, \
|
|
||||||
NULL, \
|
|
||||||
&usbc_port_data_##inst, \
|
|
||||||
&usbc_port_config_##inst, \
|
|
||||||
APPLICATION, \
|
|
||||||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(USBC_SUBSYS_INIT)
|
DT_INST_FOREACH_STATUS_OKAY(USBC_SUBSYS_INIT)
|
||||||
|
|
||||||
|
@ -134,8 +122,7 @@ int usbc_suspend(const struct device *dev)
|
||||||
* @brief Called by the Device Policy Manager to make a request of the
|
* @brief Called by the Device Policy Manager to make a request of the
|
||||||
* USB-C Subsystem
|
* USB-C Subsystem
|
||||||
*/
|
*/
|
||||||
int usbc_request(const struct device *dev,
|
int usbc_request(const struct device *dev, const enum usbc_policy_request_t req)
|
||||||
const enum usbc_policy_request_t req)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -149,8 +136,7 @@ int usbc_request(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Sets the Device Policy Manager's data
|
* @brief Sets the Device Policy Manager's data
|
||||||
*/
|
*/
|
||||||
void usbc_set_dpm_data(const struct device *dev,
|
void usbc_set_dpm_data(const struct device *dev, void *dpm_data)
|
||||||
void *dpm_data)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -194,8 +180,7 @@ void usbc_set_policy_cb_set_src_cap(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Set the callback for the Device Policy Manager policy check
|
* @brief Set the callback for the Device Policy Manager policy check
|
||||||
*/
|
*/
|
||||||
void usbc_set_policy_cb_check(const struct device *dev,
|
void usbc_set_policy_cb_check(const struct device *dev, const policy_cb_check_t policy_cb_check)
|
||||||
const policy_cb_check_t policy_cb_check)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -205,8 +190,7 @@ void usbc_set_policy_cb_check(const struct device *dev,
|
||||||
/**
|
/**
|
||||||
* @brief Set the callback for the Device Policy Manager policy change notify
|
* @brief Set the callback for the Device Policy Manager policy change notify
|
||||||
*/
|
*/
|
||||||
void usbc_set_policy_cb_notify(const struct device *dev,
|
void usbc_set_policy_cb_notify(const struct device *dev, const policy_cb_notify_t policy_cb_notify)
|
||||||
const policy_cb_notify_t policy_cb_notify)
|
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
@ -239,8 +223,8 @@ void usbc_set_policy_cb_get_rdo(const struct device *dev,
|
||||||
* @brief Set the callback for checking if Sink Power Supply is at
|
* @brief Set the callback for checking if Sink Power Supply is at
|
||||||
* default level
|
* default level
|
||||||
*/
|
*/
|
||||||
void usbc_set_policy_cb_is_snk_at_default(const struct device *dev,
|
void usbc_set_policy_cb_is_snk_at_default(
|
||||||
const policy_cb_is_snk_at_default_t policy_cb_is_snk_at_default)
|
const struct device *dev, const policy_cb_is_snk_at_default_t policy_cb_is_snk_at_default)
|
||||||
{
|
{
|
||||||
struct usbc_port_data *data = dev->data;
|
struct usbc_port_data *data = dev->data;
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
#include "usbc_pe.h"
|
#include "usbc_pe.h"
|
||||||
#include "usbc_prl.h"
|
#include "usbc_prl.h"
|
||||||
|
|
||||||
#define PRIV_PORT_REQUEST_SUSPEND -1
|
#define PRIV_PORT_REQUEST_SUSPEND -1
|
||||||
#define PRIV_PORT_REQUEST_START -2
|
#define PRIV_PORT_REQUEST_START -2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Each layer of the stack is composed of state machines that can be
|
* @brief Each layer of the stack is composed of state machines that can be
|
||||||
|
@ -131,16 +131,13 @@ struct usbc_port_data {
|
||||||
* Callback used by the Policy Engine to get the Sink Capabilities
|
* Callback used by the Policy Engine to get the Sink Capabilities
|
||||||
* from the Device Policy Manager
|
* from the Device Policy Manager
|
||||||
*/
|
*/
|
||||||
int (*policy_cb_get_snk_cap)(const struct device *dev,
|
int (*policy_cb_get_snk_cap)(const struct device *dev, uint32_t **pdos, int *num_pdos);
|
||||||
uint32_t **pdos,
|
|
||||||
int *num_pdos);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback used by the Policy Engine to send the received Source
|
* Callback used by the Policy Engine to send the received Source
|
||||||
* Capabilities to the Device Policy Manager
|
* Capabilities to the Device Policy Manager
|
||||||
*/
|
*/
|
||||||
void (*policy_cb_set_src_cap)(const struct device *dev,
|
void (*policy_cb_set_src_cap)(const struct device *dev, const uint32_t *pdos,
|
||||||
const uint32_t *pdos,
|
|
||||||
const int num_pdos);
|
const int num_pdos);
|
||||||
/**
|
/**
|
||||||
* Callback used by the Policy Engine to get the Request Data Object
|
* Callback used by the Policy Engine to get the Request Data Object
|
||||||
|
|
|
@ -68,8 +68,7 @@ void tc_run(const struct device *dev, const int32_t dpm_request)
|
||||||
tcpc_get_cc(tcpc, &tc->cc1, &tc->cc2);
|
tcpc_get_cc(tcpc, &tc->cc1, &tc->cc2);
|
||||||
|
|
||||||
/* Detect polarity */
|
/* Detect polarity */
|
||||||
tc->cc_polarity = (tc->cc1 > tc->cc2) ?
|
tc->cc_polarity = (tc->cc1 > tc->cc2) ? TC_POLARITY_CC1 : TC_POLARITY_CC2;
|
||||||
TC_POLARITY_CC1 : TC_POLARITY_CC2;
|
|
||||||
|
|
||||||
/* Execute any asyncronous Device Policy Manager Requests */
|
/* Execute any asyncronous Device Policy Manager Requests */
|
||||||
if (dpm_request == REQUEST_TC_ERROR_RECOVERY) {
|
if (dpm_request == REQUEST_TC_ERROR_RECOVERY) {
|
||||||
|
@ -144,8 +143,7 @@ enum tc_state_t tc_get_state(const struct device *dev)
|
||||||
/**
|
/**
|
||||||
* @brief Enable Power Delivery
|
* @brief Enable Power Delivery
|
||||||
*/
|
*/
|
||||||
void tc_pd_enable(const struct device *dev,
|
void tc_pd_enable(const struct device *dev, const bool enable)
|
||||||
const bool enable)
|
|
||||||
{
|
{
|
||||||
if (enable) {
|
if (enable) {
|
||||||
prl_start(dev);
|
prl_start(dev);
|
||||||
|
|
|
@ -67,8 +67,7 @@ static void sink_power_sub_states(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Notify DPM of sink sub-state power change */
|
/* Notify DPM of sink sub-state power change */
|
||||||
if (atomic_test_and_clear_bit(&tc->flags,
|
if (atomic_test_and_clear_bit(&tc->flags, TC_FLAGS_RP_SUBSTATE_CHANGE)) {
|
||||||
TC_FLAGS_RP_SUBSTATE_CHANGE)) {
|
|
||||||
if (data->policy_cb_notify) {
|
if (data->policy_cb_notify) {
|
||||||
data->policy_cb_notify(dev, dpm_pwr_change_notify);
|
data->policy_cb_notify(dev, dpm_pwr_change_notify);
|
||||||
}
|
}
|
||||||
|
@ -138,7 +137,7 @@ void tc_attach_wait_snk_run(void *obj)
|
||||||
|
|
||||||
/* Wait for CC debounce */
|
/* Wait for CC debounce */
|
||||||
if (usbc_timer_running(&tc->tc_t_cc_debounce) &&
|
if (usbc_timer_running(&tc->tc_t_cc_debounce) &&
|
||||||
usbc_timer_expired(&tc->tc_t_cc_debounce) == false) {
|
usbc_timer_expired(&tc->tc_t_cc_debounce) == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
#include "usbc_timer.h"
|
#include "usbc_timer.h"
|
||||||
|
|
||||||
/** Timer flag to track if timer was started */
|
/** Timer flag to track if timer was started */
|
||||||
#define TIMER_STARTED 0
|
#define TIMER_STARTED 0
|
||||||
/** Timer flag to track if timer has expired */
|
/** Timer flag to track if timer has expired */
|
||||||
#define TIMER_EXPIRED 1
|
#define TIMER_EXPIRED 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The timer function that's executed when the timer expires
|
* @brief The timer function that's executed when the timer expires
|
||||||
|
@ -21,8 +21,7 @@ static void usbc_timer_handler(struct k_timer *timer)
|
||||||
atomic_set_bit(&usbc_timer->flags, TIMER_EXPIRED);
|
atomic_set_bit(&usbc_timer->flags, TIMER_EXPIRED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbc_timer_init(struct usbc_timer_t *usbc_timer,
|
void usbc_timer_init(struct usbc_timer_t *usbc_timer, uint32_t timeout_ms)
|
||||||
uint32_t timeout_ms)
|
|
||||||
{
|
{
|
||||||
k_timer_init(&usbc_timer->timer, usbc_timer_handler, NULL);
|
k_timer_init(&usbc_timer->timer, usbc_timer_handler, NULL);
|
||||||
k_timer_user_data_set(&usbc_timer->timer, usbc_timer);
|
k_timer_user_data_set(&usbc_timer->timer, usbc_timer);
|
||||||
|
|
|
@ -27,8 +27,7 @@ struct usbc_timer_t {
|
||||||
* @param usbc_timer timer object
|
* @param usbc_timer timer object
|
||||||
* @param timeout_ms timer timeout in ms
|
* @param timeout_ms timer timeout in ms
|
||||||
*/
|
*/
|
||||||
void usbc_timer_init(struct usbc_timer_t *usbc_timer,
|
void usbc_timer_init(struct usbc_timer_t *usbc_timer, uint32_t timeout_ms);
|
||||||
uint32_t timeout_ms);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start a timer
|
* @brief Start a timer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue