Lines Matching full:pe
9 * @brief USB-C Power Policy Engine (PE)
32 struct policy_engine *pe = data->pe; in pe_src_init() local
38 pe->snk_request_reply = SNK_REQUEST_REJECT; in pe_src_init()
41 usbc_timer_init(&pe->pd_t_typec_send_source_cap, PD_T_TYPEC_SEND_SOURCE_CAP_MIN_MS); in pe_src_init()
42 usbc_timer_init(&pe->pd_t_ps_hard_reset, PD_T_PS_HARD_RESET_MAX_MS); in pe_src_init()
54 struct policy_engine *pe = data->pe; in source_dpm_requests() local
56 if (pe->dpm_request == REQUEST_GET_SNK_CAPS) { in source_dpm_requests()
57 atomic_set_bit(pe->flags, PE_FLAGS_DPM_INITIATED_AMS); in source_dpm_requests()
60 } else if (pe->dpm_request == REQUEST_PE_GOTO_MIN) { in source_dpm_requests()
61 atomic_set_bit(pe->flags, PE_FLAGS_DPM_INITIATED_AMS); in source_dpm_requests()
72 static void send_src_caps(struct policy_engine *pe) in send_src_caps() argument
74 const struct device *dev = pe->dev; in send_src_caps()
97 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_startup_entry() local
98 const struct device *dev = pe->dev; in pe_src_startup_entry()
103 pe->caps_counter = 0; in pe_src_startup_entry()
109 pe->power_role = TC_ROLE_SOURCE; in pe_src_startup_entry()
112 atomic_clear_bit(pe->flags, PE_FLAGS_EXPLICIT_CONTRACT); in pe_src_startup_entry()
119 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_startup_run() local
120 const struct device *dev = pe->dev; in pe_src_startup_run()
136 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_discovery_entry() local
144 usbc_timer_start(&pe->pd_t_typec_send_source_cap); in pe_src_discovery_entry()
149 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_discovery_run() local
150 const struct device *dev = pe->dev; in pe_src_discovery_run()
157 if (usbc_timer_expired(&pe->pd_t_typec_send_source_cap)) { in pe_src_discovery_run()
158 if (pe->caps_counter <= PD_N_CAPS_COUNT) { in pe_src_discovery_run()
168 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_discovery_exit() local
170 usbc_timer_stop(&pe->pd_t_typec_send_source_cap); in pe_src_discovery_exit()
178 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_send_capabilities_entry() local
181 send_src_caps(pe); in pe_src_send_capabilities_entry()
183 pe->caps_counter++; in pe_src_send_capabilities_entry()
185 pe->submachine = SM_WAIT_FOR_TX; in pe_src_send_capabilities_entry()
192 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_send_capabilities_run() local
193 const struct device *dev = pe->dev; in pe_src_send_capabilities_run()
197 switch (pe->submachine) { in pe_src_send_capabilities_run()
205 if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_TX_COMPLETE)) { in pe_src_send_capabilities_run()
206 usbc_timer_stop(&pe->pd_t_no_response); in pe_src_send_capabilities_run()
207 pe->hard_reset_counter = 0; in pe_src_send_capabilities_run()
208 pe->caps_counter = 0; in pe_src_send_capabilities_run()
209 pe->submachine = SM_WAIT_FOR_RX; in pe_src_send_capabilities_run()
218 else if ((atomic_test_and_clear_bit(pe->flags, PE_FLAGS_MSG_XMIT_ERROR) || in pe_src_send_capabilities_run()
219 atomic_test_and_clear_bit(pe->flags, PE_FLAGS_MSG_DISCARDED)) in pe_src_send_capabilities_run()
220 && (atomic_test_bit(pe->flags, PE_FLAGS_PD_CONNECTED) == false)) { in pe_src_send_capabilities_run()
229 if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_MSG_RECEIVED)) { in pe_src_send_capabilities_run()
244 else if (usbc_timer_expired(&pe->pd_t_sender_response)) { in pe_src_send_capabilities_run()
256 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_negotiate_capability_entry() local
257 const struct device *dev = pe->dev; in pe_src_negotiate_capability_entry()
264 pe->snk_request = *(uint32_t *)prl_rx->emsg.data; in pe_src_negotiate_capability_entry()
270 pe->snk_request_reply = in pe_src_negotiate_capability_entry()
271 policy_check_sink_request(dev, pe->snk_request); in pe_src_negotiate_capability_entry()
278 if (pe->snk_request_reply == SNK_REQUEST_VALID) { in pe_src_negotiate_capability_entry()
297 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_transition_supply_entry() local
298 const struct device *dev = pe->dev; in pe_src_transition_supply_entry()
308 if (pe->snk_request_reply == SNK_REQUEST_VALID) { in pe_src_transition_supply_entry()
323 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_transition_supply_run() local
324 const struct device *dev = pe->dev; in pe_src_transition_supply_run()
331 if (atomic_test_bit(pe->flags, PE_FLAGS_TX_COMPLETE)) { in pe_src_transition_supply_run()
341 else if (atomic_test_bit(pe->flags, PE_FLAGS_PROTOCOL_ERROR)) { in pe_src_transition_supply_run()
348 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_transition_supply_exit() local
349 const struct device *dev = pe->dev; in pe_src_transition_supply_exit()
352 if (pe->snk_request_reply == SNK_REQUEST_VALID) { in pe_src_transition_supply_exit()
354 pe->snk_request_reply = SNK_REQUEST_REJECT; in pe_src_transition_supply_exit()
358 atomic_set_bit(pe->flags, PE_FLAGS_EXPLICIT_CONTRACT); in pe_src_transition_supply_exit()
360 pe->present_contract = pe->snk_request; in pe_src_transition_supply_exit()
369 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_ready_entry() local
370 const struct device *dev = pe->dev; in pe_src_ready_entry()
383 if (atomic_test_and_clear_bit(pe->flags, in pe_src_ready_entry()
391 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_ready_run() local
392 const struct device *dev = pe->dev; in pe_src_ready_run()
397 if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_MSG_RECEIVED)) { in pe_src_ready_run()
477 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_ready_exit() local
478 const struct device *dev = pe->dev; in pe_src_ready_exit()
507 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_transition_to_default_entry() local
508 const struct device *dev = pe->dev; in pe_src_transition_to_default_entry()
523 pe->data_role = TC_ROLE_DFP; in pe_src_transition_to_default_entry()
529 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_transition_to_default_run() local
530 const struct device *dev = pe->dev; in pe_src_transition_to_default_run()
545 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_transition_to_default_exit() local
546 const struct device *dev = pe->dev; in pe_src_transition_to_default_exit()
555 * PE that the Power Supply is at the default level. in pe_src_transition_to_default_exit()
565 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_capability_response_entry() local
566 const struct device *dev = pe->dev; in pe_src_capability_response_entry()
577 if (pe->snk_request_reply == SNK_REQUEST_REJECT) { in pe_src_capability_response_entry()
592 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_capability_response_run() local
593 const struct device *dev = pe->dev; in pe_src_capability_response_run()
596 if (!atomic_test_and_clear_bit(pe->flags, PE_FLAGS_TX_COMPLETE)) { in pe_src_capability_response_run()
607 if (atomic_test_bit(pe->flags, PE_FLAGS_EXPLICIT_CONTRACT) && in pe_src_capability_response_run()
608 ((pe->snk_request_reply == SNK_REQUEST_REJECT && in pe_src_capability_response_run()
609 policy_present_contract_is_valid(dev, pe->present_contract)) || in pe_src_capability_response_run()
610 (pe->snk_request_reply == SNK_REQUEST_WAIT))) { in pe_src_capability_response_run()
620 else if (atomic_test_bit(pe->flags, PE_FLAGS_EXPLICIT_CONTRACT) && in pe_src_capability_response_run()
621 policy_present_contract_is_valid(dev, pe->present_contract) == false) { in pe_src_capability_response_run()
658 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_hard_reset_parent_entry() local
660 pe->submachine = SM_HARD_RESET_START; in pe_src_hard_reset_parent_entry()
665 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_hard_reset_parent_run() local
666 const struct device *dev = pe->dev; in pe_src_hard_reset_parent_run()
668 switch (pe->submachine) { in pe_src_hard_reset_parent_run()
675 usbc_timer_start(&pe->pd_t_no_response); in pe_src_hard_reset_parent_run()
678 usbc_timer_start(&pe->pd_t_ps_hard_reset); in pe_src_hard_reset_parent_run()
680 pe->submachine = SM_HARD_RESET_WAIT; in pe_src_hard_reset_parent_run()
688 if (usbc_timer_expired(&pe->pd_t_ps_hard_reset)) { in pe_src_hard_reset_parent_run()
697 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_hard_reset_parent_exit() local
700 usbc_timer_stop(&pe->pd_t_ps_hard_reset); in pe_src_hard_reset_parent_exit()
708 struct policy_engine *pe = (struct policy_engine *)obj; in pe_src_hard_reset_entry() local
709 const struct device *dev = pe->dev; in pe_src_hard_reset_entry()