usbc: merge the is_rx and get_rx_pending_msg functions
These two functions are used together so there is no need for splitting them into two functions. This commit also makes this function required to be implemented by the TCPC driver. Signed-off-by: Michał Barnaś <mb@semihalf.com>
This commit is contained in:
parent
793d29d23f
commit
fe0b6af337
|
@ -1024,45 +1024,25 @@ static int ucpd_transmit_data(const struct device *dev,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests if a received Power Delivery message is pending
|
||||
*
|
||||
* @retval 0 if there is no pending message
|
||||
* @retval 1 if there is a pending message
|
||||
*/
|
||||
static int ucpd_is_rx_pending_msg(const struct device *dev, enum pd_packet_type *type)
|
||||
{
|
||||
struct tcpc_data *data = dev->data;
|
||||
bool pending;
|
||||
|
||||
pending = (*(uint32_t *)data->ucpd_rx_buffer > 0);
|
||||
|
||||
if (pending & (type != NULL)) {
|
||||
*type = *(uint16_t *)data->ucpd_rx_buffer;
|
||||
}
|
||||
|
||||
return (pending) ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieves the Power Delivery message from the TCPC
|
||||
*
|
||||
* @retval number of bytes received
|
||||
* @retval -EIO on no message to retrieve
|
||||
* @retval -EFAULT on buf being NULL
|
||||
* @retval number of bytes received if msg parameter is provided
|
||||
* @retval 0 if there is a message pending and the msg parameter is NULL
|
||||
* @retval -ENODATA if there is no pending message
|
||||
*/
|
||||
static int ucpd_receive_data(const struct device *dev, struct pd_msg *msg)
|
||||
static int ucpd_get_rx_pending_msg(const struct device *dev, struct pd_msg *msg)
|
||||
{
|
||||
struct tcpc_data *data = dev->data;
|
||||
int ret = 0;
|
||||
|
||||
if (msg == NULL) {
|
||||
return -EFAULT;
|
||||
/* Make sure we have a message to retrieve */
|
||||
if (*(uint32_t *)data->ucpd_rx_buffer == 0) {
|
||||
return -ENODATA;
|
||||
}
|
||||
|
||||
/* Make sure we have a message to retrieve */
|
||||
if (!ucpd_is_rx_pending_msg(dev, NULL)) {
|
||||
return -EIO;
|
||||
if (msg == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
msg->type = *(uint16_t *)data->ucpd_rx_buffer;
|
||||
|
@ -1443,8 +1423,7 @@ static const struct tcpc_driver_api driver_api = {
|
|||
.set_alert_handler_cb = ucpd_set_alert_handler_cb,
|
||||
.get_cc = ucpd_get_cc,
|
||||
.set_rx_enable = ucpd_set_rx_enable,
|
||||
.is_rx_pending_msg = ucpd_is_rx_pending_msg,
|
||||
.receive_data = ucpd_receive_data,
|
||||
.get_rx_pending_msg = ucpd_get_rx_pending_msg,
|
||||
.transmit_data = ucpd_transmit_data,
|
||||
.select_rp_value = ucpd_select_rp_value,
|
||||
.get_rp_value = ucpd_get_rp_value,
|
||||
|
|
|
@ -136,8 +136,7 @@ __subsystem struct tcpc_driver_api {
|
|||
int (*set_vconn)(const struct device *dev, bool enable);
|
||||
int (*set_roles)(const struct device *dev, enum tc_power_role power_role,
|
||||
enum tc_data_role data_role);
|
||||
int (*receive_data)(const struct device *dev, struct pd_msg *msg);
|
||||
int (*is_rx_pending_msg)(const struct device *dev, enum pd_packet_type *type);
|
||||
int (*get_rx_pending_msg)(const struct device *dev, struct pd_msg *msg);
|
||||
int (*set_rx_enable)(const struct device *dev, bool enable);
|
||||
int (*set_cc_polarity)(const struct device *dev, enum tc_cc_polarity polarity);
|
||||
int (*transmit_data)(const struct device *dev, struct pd_msg *msg);
|
||||
|
@ -455,50 +454,25 @@ static inline int tcpc_set_roles(const struct device *dev,
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Tests if a received Power Delivery message is pending
|
||||
* @brief Retrieves the Power Delivery message from the TCPC.
|
||||
* If buf is NULL, then only the status is returned, where 0 means there is a message pending and
|
||||
* -ENODATA means there is no pending message.
|
||||
*
|
||||
* @param dev Runtime device structure
|
||||
* @param type pointer to where message type is written. Can be NULL
|
||||
* @param dev Runtime device structure
|
||||
* @param buf pointer where the pd_buf pointer is written, NULL if only checking the status
|
||||
*
|
||||
* @retval 0 if there is no pending message
|
||||
* @retval 1 if there is a pending message
|
||||
* @retval Greater or equal to 0 is the number of bytes received if buf parameter is provided
|
||||
* @retval 0 if there is a message pending and buf parameter is NULL
|
||||
* @retval -EIO on failure
|
||||
* @retval -ENOSYS if not implemented
|
||||
* @retval -ENODATA if no message is pending
|
||||
*/
|
||||
static inline int tcpc_is_rx_pending_msg(const struct device *dev, enum pd_packet_type *type)
|
||||
static inline int tcpc_get_rx_pending_msg(const struct device *dev, struct pd_msg *buf)
|
||||
{
|
||||
const struct tcpc_driver_api *api =
|
||||
(const struct tcpc_driver_api *)dev->api;
|
||||
const struct tcpc_driver_api *api = (const struct tcpc_driver_api *)dev->api;
|
||||
|
||||
if (api->is_rx_pending_msg == NULL) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
__ASSERT(api->get_rx_pending_msg != NULL, "Callback pointer should not be NULL");
|
||||
|
||||
return api->is_rx_pending_msg(dev, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieves the Power Delivery message from the TCPC
|
||||
*
|
||||
* @param dev Runtime device structure
|
||||
* @param buf pointer where the pd_buf pointer is written
|
||||
*
|
||||
* @retval Greater or equal to 0 is the number of bytes received
|
||||
* @retval -EIO on failure
|
||||
* @retval -EFAULT on buf being NULL
|
||||
* @retval -ENOSYS if not implemented
|
||||
*/
|
||||
static inline int tcpc_receive_data(const struct device *dev,
|
||||
struct pd_msg *buf)
|
||||
{
|
||||
const struct tcpc_driver_api *api =
|
||||
(const struct tcpc_driver_api *)dev->api;
|
||||
|
||||
if (api->receive_data == NULL) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
return api->receive_data(dev, buf);
|
||||
return api->get_rx_pending_msg(dev, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1177,7 +1177,7 @@ static void prl_rx_wait_for_phy_message(const struct device *dev)
|
|||
uint8_t power_role;
|
||||
|
||||
/* Get the message */
|
||||
if (tcpc_is_rx_pending_msg(tcpc, NULL) == 0 || tcpc_receive_data(tcpc, rx_emsg) <= 0) {
|
||||
if (tcpc_get_rx_pending_msg(tcpc, rx_emsg) <= 0) {
|
||||
/* No pending message or problem getting the message */
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue