Lines Matching +full:vbus +full:- +full:detect
4 * SPDX-License-Identifier: Apache-2.0
24 struct usbc_port_data *data = dev->data; in tc_subsys_init()
25 struct tc_sm_t *tc = data->tc; in tc_subsys_init()
28 tc->dev = dev; in tc_subsys_init()
35 * @brief Runs the Type-C layer
39 struct usbc_port_data *data = dev->data; in tc_run()
40 const struct device *tcpc = data->tcpc; in tc_run()
41 struct tc_sm_t *tc = data->tc; in tc_run()
46 data->tc_enabled = true; in tc_run()
48 data->tc_enabled = false; in tc_run()
52 switch (data->tc_sm_state) { in tc_run()
54 if (data->tc_enabled == false) { in tc_run()
59 /* Initialize the Type-C layer */ in tc_run()
61 if (ret != 0 && ret != -EAGAIN) { in tc_run()
63 LOG_ERR("Disabling the Type-C Layer"); in tc_run()
64 data->tc_enabled = false; in tc_run()
72 data->tc_sm_state = SM_RUN; in tc_run()
75 if (data->tc_enabled == false) { in tc_run()
77 data->tc_sm_state = SM_PAUSED; in tc_run()
82 if (tcpc_get_cc(tcpc, &tc->cc1, &tc->cc2) != 0) { in tc_run()
87 tc->cc1 = TC_CC_VOLT_OPEN; in tc_run()
88 tc->cc2 = TC_CC_VOLT_OPEN; in tc_run()
91 /* Detect polarity */ in tc_run()
92 tc->cc_polarity = (tc->cc1 > tc->cc2) ? TC_POLARITY_CC1 : TC_POLARITY_CC2; in tc_run()
121 * @brief Initializes the Type-C layer
125 struct usbc_port_data *data = dev->data; in tc_init()
126 struct tc_sm_t *tc = data->tc; in tc_init()
127 const struct device *tcpc = data->tcpc; in tc_init()
131 usbc_timer_init(&tc->tc_t_error_recovery, TC_T_ERROR_RECOVERY_SOURCE_MIN_MS); in tc_init()
132 usbc_timer_init(&tc->tc_t_cc_debounce, TC_T_CC_DEBOUNCE_MAX_MS); in tc_init()
133 usbc_timer_init(&tc->tc_t_rp_value_change, TC_T_RP_VALUE_CHANGE_MAX_MS); in tc_init()
135 usbc_timer_init(&tc->tc_t_vconn_off, TC_T_VCONN_OFF_MAX_MS); in tc_init()
139 tc->flags = ATOMIC_INIT(0); in tc_init()
149 /* Stop sourcing VBUS by policy callback and/or TCPC */ in tc_init()
152 LOG_ERR("Couldn't disable vbus sourcing: %d", ret); in tc_init()
156 /* Disable VBUS sourcing by the PPC */ in tc_init()
157 if (data->ppc != NULL) { in tc_init()
158 ppc_set_src_ctrl(data->ppc, false); in tc_init()
163 if (ret != 0 && ret != -ENOTSUP) { in tc_init()
180 * @brief Sets a Type-C state
184 struct usbc_port_data *data = dev->data; in tc_set_state()
185 struct tc_sm_t *tc = data->tc; in tc_set_state()
192 * @brief Get the Type-C current state
196 struct usbc_port_data *data = dev->data; in tc_get_state()
198 return data->tc->ctx.current - &tc_states[0]; in tc_get_state()
220 struct usbc_port_data *data = dev->data; in tc_select_src_collision_rp()
221 const struct device *tcpc = data->tcpc; in tc_select_src_collision_rp()
226 if (ret != 0 && ret != -ENOTSUP) { in tc_select_src_collision_rp()
246 const struct device *dev = tc->dev; in tc_cc_open_entry()
247 struct usbc_port_data *data = dev->data; in tc_cc_open_entry()
248 const struct device *tcpc = data->tcpc; in tc_cc_open_entry()
251 tc->cc_voltage = TC_CC_VOLT_OPEN; in tc_cc_open_entry()
255 if (ret != 0 && ret != -ENOSYS) { in tc_cc_open_entry()
295 usbc_timer_start(&tc->tc_t_error_recovery); in tc_error_recovery_entry()
304 const struct device *dev = tc->dev; in tc_error_recovery_run()
307 if (usbc_timer_expired(&tc->tc_t_error_recovery) == false) { in tc_error_recovery_run()
321 * @brief Type-C State Table