usbc: add support for TCPC control of vbus sourcing
Adds calls to the set_src_ctrl of TCPC driver to enable and disable the VBUS sourcing. If the TCPC doesn't support these functions, no errors should be printed. Signed-off-by: Michał Barnaś <mb@semihalf.com>
This commit is contained in:
parent
44e4270a28
commit
0b4365ef29
3 changed files with 38 additions and 6 deletions
|
|
@ -216,4 +216,37 @@ struct usbc_port_data {
|
|||
void *dpm_data;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_USBC_CSM_SOURCE_ONLY
|
||||
/**
|
||||
* @brief Function that enables the source path either using callback or by the TCPC.
|
||||
* If source and sink paths are controlled by the TCPC, this callback doesn't have to be set.
|
||||
*
|
||||
* @param dev USB-C connector device
|
||||
* @param tcpc Type-C Port Controller device
|
||||
* @param en True to enable the sourcing, false to disable
|
||||
* @return int 0 if success, -ENOSYS if both callback and TCPC function are not implemented.
|
||||
* In case of error, value from any of the functions is returned
|
||||
*/
|
||||
static inline int usbc_policy_src_en(const struct device *dev, const struct device *tcpc, bool en)
|
||||
{
|
||||
struct usbc_port_data *data = dev->data;
|
||||
int ret_cb = -ENOSYS;
|
||||
int ret_tcpc;
|
||||
|
||||
if (data->policy_cb_src_en != NULL) {
|
||||
ret_cb = data->policy_cb_src_en(dev, en);
|
||||
if (ret_cb != 0 && ret_cb != -ENOSYS) {
|
||||
return ret_cb;
|
||||
}
|
||||
}
|
||||
|
||||
ret_tcpc = tcpc_set_src_ctrl(tcpc, en);
|
||||
if (ret_tcpc == -ENOSYS) {
|
||||
return ret_cb;
|
||||
}
|
||||
|
||||
return ret_tcpc;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_SUBSYS_USBC_STACK_PRIV_H_ */
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ static int tc_init(const struct device *dev)
|
|||
|
||||
#ifdef CONFIG_USBC_CSM_SOURCE_ONLY
|
||||
/* Stop sourcing VBUS by policy callback and/or TCPC */
|
||||
ret = data->policy_cb_src_en(dev, false);
|
||||
ret = usbc_policy_src_en(dev, tcpc, false);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Couldn't disable vbus sourcing: %d", ret);
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ void tc_attached_src_entry(void *obj)
|
|||
}
|
||||
|
||||
/* Start sourcing VBUS */
|
||||
if (data->policy_cb_src_en(dev, true) == 0) {
|
||||
if (usbc_policy_src_en(dev, tcpc, true) == 0) {
|
||||
/* Start sourcing VCONN */
|
||||
if (policy_check(dev, CHECK_VCONN_CONTROL)) {
|
||||
if (tcpc_set_vconn(tcpc, true) == 0) {
|
||||
|
|
@ -304,14 +304,13 @@ void tc_attached_src_exit(void *obj)
|
|||
const struct device *tcpc = data->tcpc;
|
||||
int ret;
|
||||
|
||||
__ASSERT(data->policy_cb_src_en != NULL,
|
||||
"policy_cb_src_en must not be NULL");
|
||||
|
||||
/* Disable PD */
|
||||
tc_pd_enable(dev, false);
|
||||
|
||||
/* Stop sourcing VBUS */
|
||||
data->policy_cb_src_en(dev, false);
|
||||
if (usbc_policy_src_en(dev, tcpc, false) != 0) {
|
||||
LOG_ERR("Couldn't disable VBUS source");
|
||||
}
|
||||
|
||||
/* Disable the VBUS sourcing by the PPC */
|
||||
if (data->ppc != NULL) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue