Skip to content

Commit

Permalink
usbc: Enable VBUS measurement before VBUS check level
Browse files Browse the repository at this point in the history
Enable VBUS measurement before checking the VBUS level and
disable it when unattached.

Signed-off-by: Jianxiong Gu <jianxiong.gu@outlook.com>
  • Loading branch information
recalci committed Mar 4, 2025
1 parent ebdfaeb commit f654639
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions subsys/usb/usb_c/usbc_pe_snk_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,14 @@ void pe_snk_startup_run(void *obj)
*/
void pe_snk_discovery_entry(void *obj)
{
struct policy_engine *pe = (struct policy_engine *)obj;
const struct device *dev = pe->dev;
struct usbc_port_data *data = dev->data;
const struct device *vbus = data->vbus;

LOG_INF("PE_SNK_Discovery");

usbc_vbus_enable(vbus, true);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions subsys/usb/usb_c/usbc_tc_snk_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ void tc_unattached_snk_run(void *obj)
{
struct tc_sm_t *tc = (struct tc_sm_t *)obj;
const struct device *dev = tc->dev;
struct usbc_port_data *data = dev->data;
const struct device *vbus = data->vbus;

/*
* Transition to AttachWait.SNK when the SNK.Rp state is present
* on at least one of its CC pins.
*/
if (tcpc_is_cc_rp(tc->cc1) || tcpc_is_cc_rp(tc->cc2)) {
usbc_vbus_enable(vbus, true);
tc_set_state(dev, TC_ATTACH_WAIT_SNK_STATE);
}
}
Expand Down Expand Up @@ -240,6 +243,7 @@ void tc_attached_snk_run(void *obj)

/* Detach detection */
if (usbc_vbus_check_level(vbus, TC_VBUS_PRESENT) == false) {
usbc_vbus_enable(vbus, false);
tc_set_state(dev, TC_UNATTACHED_SNK_STATE);
return;
}
Expand Down
5 changes: 5 additions & 0 deletions subsys/usb/usb_c/usbc_tc_src_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,16 @@ void tc_unattached_wait_src_exit(void *obj)
void tc_attach_wait_src_entry(void *obj)
{
struct tc_sm_t *tc = (struct tc_sm_t *)obj;
const struct device *dev = tc->dev;
struct usbc_port_data *data = dev->data;
const struct device *vbus = data->vbus;

LOG_INF("AttachWait.SRC");

/* Initialize the cc state to open */
tc->cc_state = TC_CC_NONE;

usbc_vbus_enable(vbus, true);
}

void tc_attach_wait_src_run(void *obj)
Expand Down

0 comments on commit f654639

Please sign in to comment.