Lines Matching +full:pd +full:- +full:revision
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2015-2017 Google, Inc
12 #include <irq-generic.h>
187 VDM_STATE_ERR_BUSY = -3,
188 VDM_STATE_ERR_SEND = -2,
189 VDM_STATE_ERR_TMOUT = -1,
217 * Based on "Table 6-14 Fixed Supply PDO - Sink" of "USB Power Delivery Specification Revision 3.0,
279 POWER_SUPPLY_USB_TYPE_PD_DRP, /* PD Dual Role Port */
280 POWER_SUPPLY_USB_TYPE_PD_PPS, /* PD Programmable Power Supply */
372 * whether to wait for the Type-C device to send the DR_SWAP Message flag
373 * For Type-C device with Dual-Role Power and Dual-Role Data, the port side
374 * is used as sink + ufp, then the tcpm framework needs to wait for Type-C
403 /* PD state for Vendor Defined Messages */
443 * the actual currrent limit after RX of PD_CTRL_PSRDY for PD link,
444 * SNK_READY for non-pd link.
472 ((tcpm_cc_is_sink((port)->cc1) && !tcpm_cc_is_sink((port)->cc2)) || \
473 (tcpm_cc_is_sink((port)->cc2) && !tcpm_cc_is_sink((port)->cc1)))
480 ((tcpm_cc_is_source((port)->cc1) && \
481 !tcpm_cc_is_source((port)->cc2)) || \
482 (tcpm_cc_is_source((port)->cc2) && \
483 !tcpm_cc_is_source((port)->cc1)))
486 (tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2))
489 (tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_audio((port)->cc2))
492 ((tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_open((port)->cc2)) || \
493 (tcpm_cc_is_audio((port)->cc2) && tcpm_cc_is_open((port)->cc1)))
496 ((port)->try_snk_count == 0 && (port)->try_role == TYPEC_SINK && \
497 (port)->port_type == TYPEC_PORT_DRP)
500 ((port)->try_src_count == 0 && (port)->try_role == TYPEC_SOURCE && \
501 (port)->port_type == TYPEC_PORT_DRP)
504 ((port)->typec_caps.data == TYPEC_PORT_UFP ? \
508 ((port)->typec_caps.data == TYPEC_PORT_DFP ? \
513 if (port->port_type == TYPEC_PORT_DRP) { in tcpm_default_state()
514 if (port->try_role == TYPEC_SINK) in tcpm_default_state()
516 else if (port->try_role == TYPEC_SOURCE) in tcpm_default_state()
519 } else if (port->port_type == TYPEC_PORT_SNK) { in tcpm_default_state()
527 return (!port->attached && port->cc1 == TYPEC_CC_OPEN && in tcpm_port_is_disconnected()
528 port->cc2 == TYPEC_CC_OPEN) || in tcpm_port_is_disconnected()
529 (port->attached && ((port->polarity == TYPEC_POLARITY_CC1 && in tcpm_port_is_disconnected()
530 port->cc1 == TYPEC_CC_OPEN) || in tcpm_port_is_disconnected()
531 (port->polarity == TYPEC_POLARITY_CC2 && in tcpm_port_is_disconnected()
532 port->cc2 == TYPEC_CC_OPEN))); in tcpm_port_is_disconnected()
538 port->cc_req = cc; in tcpm_set_cc()
539 port->tcpc->set_cc(port->tcpc, cc); in tcpm_set_cc()
549 const u32 *src_pdo = port->src_pdo; in tcpm_rp_cc()
550 int nr_pdo = port->nr_src_pdo; in tcpm_rp_cc()
583 debug("PD TX, header: %#x\n", le16_to_cpu(msg->header)); in tcpm_pd_transmit()
585 debug("PD TX, type: %#x\n", type); in tcpm_pd_transmit()
587 port->tx_complete = false; in tcpm_pd_transmit()
588 ret = port->tcpc->pd_transmit(port->tcpc, type, msg, port->negotiated_rev); in tcpm_pd_transmit()
592 while ((timeout > 0) && (!port->tx_complete)) { in tcpm_pd_transmit()
593 port->tcpc->poll_event(port->tcpc); in tcpm_pd_transmit()
595 timeout--; in tcpm_pd_transmit()
599 printf("%s: pd transmit data timeout\n", __func__); in tcpm_pd_transmit()
600 return -ETIMEDOUT; in tcpm_pd_transmit()
603 switch (port->tx_status) { in tcpm_pd_transmit()
605 port->message_id = (port->message_id + 1) & PD_HEADER_ID_MASK; in tcpm_pd_transmit()
608 ret = -EAGAIN; in tcpm_pd_transmit()
612 ret = -EIO; in tcpm_pd_transmit()
622 debug("%s: PD TX complete, status: %u\n", __func__, status); in tcpm_pd_transmit_complete()
623 port->poll_event_cnt = 0; in tcpm_pd_transmit_complete()
624 port->tx_status = status; in tcpm_pd_transmit_complete()
625 port->tx_complete = true; in tcpm_pd_transmit_complete()
636 ret = port->tcpc->set_polarity(port->tcpc, polarity); in tcpm_set_polarity()
640 port->polarity = polarity; in tcpm_set_polarity()
651 ret = port->tcpc->set_vconn(port->tcpc, enable); in tcpm_set_vconn()
653 port->vconn_role = enable ? TYPEC_SOURCE : TYPEC_SINK; in tcpm_set_vconn()
663 cc = port->polarity ? port->cc2 : port->cc1; in tcpm_get_current_limit()
673 if (port->tcpc->get_current_limit) in tcpm_get_current_limit()
674 limit = port->tcpc->get_current_limit(port->tcpc); in tcpm_get_current_limit()
685 int ret = -EOPNOTSUPP; in tcpm_set_current_limit()
689 port->supply_voltage = mv; in tcpm_set_current_limit()
690 port->current_limit = max_ma; in tcpm_set_current_limit()
692 if (port->tcpc->set_current_limit) in tcpm_set_current_limit()
693 ret = port->tcpc->set_current_limit(port->tcpc, max_ma, mv); in tcpm_set_current_limit()
700 return port->tcpc->set_roles(port->tcpc, attached, port->pwr_role, in tcpm_set_attached_state()
701 port->data_role); in tcpm_set_attached_state()
714 if (port->polarity == TYPEC_POLARITY_CC1) in tcpm_set_roles()
729 ret = port->tcpc->set_roles(port->tcpc, attached, role, data); in tcpm_set_roles()
733 port->pwr_role = role; in tcpm_set_roles()
734 port->data_role = data; in tcpm_set_roles()
736 typec_set_data_role(port->typec_port, data); in tcpm_set_roles()
737 typec_set_pwr_role(port->typec_port, role); in tcpm_set_roles()
750 if (!port->nr_src_pdo) { in tcpm_pd_send_source_caps()
753 port->pwr_role, in tcpm_pd_send_source_caps()
754 port->data_role, in tcpm_pd_send_source_caps()
755 port->negotiated_rev, in tcpm_pd_send_source_caps()
756 port->message_id, 0); in tcpm_pd_send_source_caps()
759 port->pwr_role, in tcpm_pd_send_source_caps()
760 port->data_role, in tcpm_pd_send_source_caps()
761 port->negotiated_rev, in tcpm_pd_send_source_caps()
762 port->message_id, in tcpm_pd_send_source_caps()
763 port->nr_src_pdo); in tcpm_pd_send_source_caps()
766 for (i = 0; i < port->nr_src_pdo; i++) in tcpm_pd_send_source_caps()
767 msg.payload[i] = cpu_to_le32(port->src_pdo[i]); in tcpm_pd_send_source_caps()
779 if (!port->nr_snk_pdo) { in tcpm_pd_send_sink_caps()
782 port->pwr_role, in tcpm_pd_send_sink_caps()
783 port->data_role, in tcpm_pd_send_sink_caps()
784 port->negotiated_rev, in tcpm_pd_send_sink_caps()
785 port->message_id, 0); in tcpm_pd_send_sink_caps()
788 port->pwr_role, in tcpm_pd_send_sink_caps()
789 port->data_role, in tcpm_pd_send_sink_caps()
790 port->negotiated_rev, in tcpm_pd_send_sink_caps()
791 port->message_id, in tcpm_pd_send_sink_caps()
792 port->nr_snk_pdo); in tcpm_pd_send_sink_caps()
795 for (i = 0; i < port->nr_snk_pdo; i++) in tcpm_pd_send_sink_caps()
796 msg.payload[i] = cpu_to_le32(port->snk_pdo[i]); in tcpm_pd_send_sink_caps()
856 debug("pending state change %s -> %s @ %u ms [%s]\n", in tcpm_set_state()
857 tcpm_states[port->state], tcpm_states[state], delay_ms, in tcpm_set_state()
858 pd_rev[port->negotiated_rev]); in tcpm_set_state()
859 port->delayed_state = state; in tcpm_set_state()
861 port->delay_ms = delay_ms; in tcpm_set_state()
863 debug("state change %s -> %s\n", in tcpm_set_state()
864 tcpm_states[port->state], tcpm_states[state]); in tcpm_set_state()
865 port->delayed_state = INVALID_STATE; in tcpm_set_state()
866 port->prev_state = port->state; in tcpm_set_state()
867 port->state = state; in tcpm_set_state()
869 * Don't re-queue the state machine work item if we're currently in tcpm_set_state()
874 if (!port->state_machine_running) in tcpm_set_state()
882 if (port->enter_state == port->state) in tcpm_set_state_cond()
885 debug("skipped %sstate change %s -> %s [%u ms], context state %s [%s %s]\n", in tcpm_set_state_cond()
887 tcpm_states[port->state], tcpm_states[state], in tcpm_set_state_cond()
888 delay_ms, tcpm_states[port->enter_state], in tcpm_set_state_cond()
889 pd_rev[port->negotiated_rev], tcpm_ams_str[port->ams]); in tcpm_set_state_cond()
895 port->queued_message = message; in tcpm_queue_message()
951 if (pdo_type(pdo[i]) < pdo_type(pdo[i - 1])) { in tcpm_caps_err()
953 } else if (pdo_type(pdo[i]) == pdo_type(pdo[i - 1])) { in tcpm_caps_err()
964 pdo_fixed_voltage(pdo[i - 1])) in tcpm_caps_err()
975 pdo_min_voltage(pdo[i - 1])) in tcpm_caps_err()
978 pdo_min_voltage(pdo[i - 1])) && in tcpm_caps_err()
980 pdo_max_voltage(pdo[i - 1]))) in tcpm_caps_err()
993 pdo_pps_apdo_max_voltage(pdo[i - 1])) in tcpm_caps_err()
996 pdo_pps_apdo_min_voltage(pdo[i - 1]) && in tcpm_caps_err()
998 pdo_pps_apdo_max_voltage(pdo[i - 1]) && in tcpm_caps_err()
1000 pdo_pps_apdo_max_current(pdo[i - 1])) in tcpm_caps_err()
1019 return -EINVAL; in tcpm_validate_caps()
1026 * PD (data, control) command handling functions
1030 if (port->pwr_role == TYPEC_SOURCE) in ready_state()
1044 switch (port->state) {
1047 port->ams = ams;
1050 /* PD 3.0 Spec 8.3.3.4.1.1 and 6.8.1 */
1058 tcpm_set_state(port, port->pwr_role == TYPEC_SOURCE ?
1063 port->next_ams = ams;
1076 enum pd_data_msg_type type = pd_header_type_le(msg->header); in tcpm_pd_data_request()
1077 unsigned int cnt = pd_header_cnt_le(msg->header); in tcpm_pd_data_request()
1078 unsigned int rev = pd_header_rev_le(msg->header); in tcpm_pd_data_request()
1084 port->source_caps[i] = le32_to_cpu(msg->payload[i]); in tcpm_pd_data_request()
1086 port->nr_source_caps = cnt; in tcpm_pd_data_request()
1088 tcpm_validate_caps(port, port->source_caps, in tcpm_pd_data_request()
1089 port->nr_source_caps); in tcpm_pd_data_request()
1092 * Adjust revision in subsequent message headers, as required, in tcpm_pd_data_request()
1093 * to comply with 6.2.1.1.5 of the USB PD 3.0 spec. We don't in tcpm_pd_data_request()
1101 port->negotiated_rev = rev; in tcpm_pd_data_request()
1103 if ((pdo_type(port->source_caps[0]) == PDO_TYPE_FIXED) && in tcpm_pd_data_request()
1104 (port->source_caps[0] & PDO_FIXED_DUAL_ROLE) && in tcpm_pd_data_request()
1105 (port->source_caps[0] & PDO_FIXED_DATA_SWAP)) { in tcpm_pd_data_request()
1106 /* Dual role power and data, eg: self-powered Type-C */ in tcpm_pd_data_request()
1107 port->wait_dr_swap_Message = true; in tcpm_pd_data_request()
1109 /* Non-Dual role power, eg: adapter */ in tcpm_pd_data_request()
1110 port->wait_dr_swap_Message = false; in tcpm_pd_data_request()
1115 * present. This is quite unexpected; see USB PD in tcpm_pd_data_request()
1120 * if VBUS is available or not (USB PD specification, in tcpm_pd_data_request()
1130 * Adjust revision in subsequent message headers, as required, in tcpm_pd_data_request()
1131 * to comply with 6.2.1.1.5 of the USB PD 3.0 spec. We don't in tcpm_pd_data_request()
1140 port->negotiated_rev = rev; in tcpm_pd_data_request()
1142 port->sink_request = le32_to_cpu(msg->payload[0]); in tcpm_pd_data_request()
1149 port->sink_caps[i] = le32_to_cpu(msg->payload[i]); in tcpm_pd_data_request()
1151 port->nr_sink_caps = cnt; in tcpm_pd_data_request()
1161 enum pd_ctrl_msg_type type = pd_header_type_le(msg->header); in tcpm_pd_ctrl_request()
1169 switch (port->state) { in tcpm_pd_ctrl_request()
1180 switch (port->state) { in tcpm_pd_ctrl_request()
1193 switch (port->state) { in tcpm_pd_ctrl_request()
1195 if (port->vbus_present) { in tcpm_pd_ctrl_request()
1197 port->req_current_limit, in tcpm_pd_ctrl_request()
1198 port->req_supply_voltage); in tcpm_pd_ctrl_request()
1199 port->explicit_contract = true; in tcpm_pd_ctrl_request()
1217 switch (port->state) { in tcpm_pd_ctrl_request()
1219 /* USB PD specification, Figure 8-43 */ in tcpm_pd_ctrl_request()
1220 if (port->explicit_contract) in tcpm_pd_ctrl_request()
1229 port->pps_data.req_out_volt = port->supply_voltage; in tcpm_pd_ctrl_request()
1230 port->pps_data.req_op_curr = port->current_limit; in tcpm_pd_ctrl_request()
1231 port->pps_status = (type == PD_CTRL_WAIT ? in tcpm_pd_ctrl_request()
1232 -EAGAIN : -EOPNOTSUPP); in tcpm_pd_ctrl_request()
1240 switch (port->state) { in tcpm_pd_ctrl_request()
1242 port->pps_data.active = false; in tcpm_pd_ctrl_request()
1246 port->pps_data.active = true; in tcpm_pd_ctrl_request()
1248 port->pps_data.min_volt = port->pps_data.req_min_volt; in tcpm_pd_ctrl_request()
1249 port->pps_data.max_volt = port->pps_data.req_max_volt; in tcpm_pd_ctrl_request()
1250 port->pps_data.max_curr = port->pps_data.req_max_curr; in tcpm_pd_ctrl_request()
1251 port->req_supply_voltage = port->pps_data.req_out_volt; in tcpm_pd_ctrl_request()
1252 port->req_current_limit = port->pps_data.req_op_curr; in tcpm_pd_ctrl_request()
1256 port->message_id = 0; in tcpm_pd_ctrl_request()
1257 port->rx_msgid = -1; in tcpm_pd_ctrl_request()
1258 if (port->pwr_role == TYPEC_SOURCE) in tcpm_pd_ctrl_request()
1272 if (port->port_type != TYPEC_PORT_DRP) { in tcpm_pd_ctrl_request()
1281 switch (port->state) { in tcpm_pd_ctrl_request()
1285 if (port->vdm_sm_running) { in tcpm_pd_ctrl_request()
1318 enum pd_ext_msg_type type = pd_header_type_le(msg->header);
1319 unsigned int data_size = pd_ext_header_data_size_le(msg->ext_msg.header);
1321 if (!(le16_to_cpu(msg->ext_msg.header) & PD_EXT_HDR_CHUNKED)) {
1364 const struct pd_message *msg = &event->msg; in tcpm_pd_rx_handler()
1365 unsigned int cnt = pd_header_cnt_le(msg->header); in tcpm_pd_rx_handler()
1367 debug("PD RX, header: %#x [%d]\n", le16_to_cpu(msg->header), in tcpm_pd_rx_handler()
1368 port->attached); in tcpm_pd_rx_handler()
1370 if (port->attached) { in tcpm_pd_rx_handler()
1371 enum pd_ctrl_msg_type type = pd_header_type_le(msg->header); in tcpm_pd_rx_handler()
1372 unsigned int msgid = pd_header_msgid_le(msg->header); in tcpm_pd_rx_handler()
1375 * USB PD standard, 6.6.1.2: in tcpm_pd_rx_handler()
1383 if (msgid == port->rx_msgid && type != PD_CTRL_SOFT_RESET) in tcpm_pd_rx_handler()
1385 port->rx_msgid = msgid; in tcpm_pd_rx_handler()
1391 if (!!(le16_to_cpu(msg->header) & PD_HEADER_DATA_ROLE) == in tcpm_pd_rx_handler()
1392 (port->data_role == TYPEC_HOST)) { in tcpm_pd_rx_handler()
1411 port->poll_event_cnt = 0; in tcpm_pd_receive()
1416 event->port = port; in tcpm_pd_receive()
1417 memcpy(&event->msg, msg, sizeof(*msg)); in tcpm_pd_receive()
1428 msg.header = PD_HEADER_LE(type, port->pwr_role, in tcpm_pd_send_control()
1429 port->data_role, in tcpm_pd_send_control()
1430 port->negotiated_rev, in tcpm_pd_send_control()
1431 port->message_id, 0); in tcpm_pd_send_control()
1446 queued_message = port->queued_message; in tcpm_send_queued_message()
1447 port->queued_message = PD_MSG_NONE; in tcpm_send_queued_message()
1468 } while (port->queued_message != PD_MSG_NONE); in tcpm_send_queued_message()
1472 if (port->delayed_state != INVALID_STATE) { in tcpm_send_queued_message()
1473 if (ktime_after(port->delayed_runtime, ktime_get())) { in tcpm_send_queued_message()
1474 mod_tcpm_delayed_work(port, ktime_to_ms(ktime_sub(port->delayed_runtime, in tcpm_send_queued_message()
1478 port->delayed_state = INVALID_STATE; in tcpm_send_queued_message()
1486 u32 pdo, rdo = port->sink_request; in tcpm_pd_check_request()
1491 if (!index || index > port->nr_src_pdo) in tcpm_pd_check_request()
1492 return -EINVAL; in tcpm_pd_check_request()
1494 pdo = port->src_pdo[index - 1]; in tcpm_pd_check_request()
1504 return -EINVAL; in tcpm_pd_check_request()
1506 return -EINVAL; in tcpm_pd_check_request()
1512 debug("Requested %u -> %u mV, %u mA for %u / %u mA\n", in tcpm_pd_check_request()
1522 return -EINVAL; in tcpm_pd_check_request()
1524 return -EINVAL; in tcpm_pd_check_request()
1525 printf("Requested %u -> %u mV, %u mW for %u / %u mW\n", in tcpm_pd_check_request()
1530 return -EINVAL; in tcpm_pd_check_request()
1533 port->op_vsafe5v = index == 1; in tcpm_pd_check_request()
1547 int ret = -EINVAL; in tcpm_pd_select_pdo()
1549 port->pps_data.supported = false; in tcpm_pd_select_pdo()
1550 port->usb_type = POWER_SUPPLY_USB_TYPE_PD; in tcpm_pd_select_pdo()
1556 for (i = 0; i < port->nr_source_caps; i++) { in tcpm_pd_select_pdo()
1557 u32 pdo = port->source_caps[i]; in tcpm_pd_select_pdo()
1572 port->pps_data.supported = true; in tcpm_pd_select_pdo()
1573 port->usb_type = in tcpm_pd_select_pdo()
1598 for (j = 0; j < port->nr_snk_pdo; j++) { in tcpm_pd_select_pdo()
1599 pdo = port->snk_pdo[j]; in tcpm_pd_select_pdo()
1653 for (i = 1; i < port->nr_source_caps; ++i) { in tcpm_pd_select_pps_apdo()
1654 pdo = port->source_caps[i]; in tcpm_pd_select_pps_apdo()
1673 for (j = 1; j < port->nr_snk_pdo; j++) { in tcpm_pd_select_pps_apdo()
1674 pdo = port->snk_pdo[j]; in tcpm_pd_select_pps_apdo()
1717 src = port->source_caps[src_pdo]; in tcpm_pd_select_pps_apdo()
1718 snk = port->snk_pdo[snk_pdo]; in tcpm_pd_select_pps_apdo()
1720 port->pps_data.req_min_volt = max(pdo_pps_apdo_min_voltage(src), in tcpm_pd_select_pps_apdo()
1722 port->pps_data.req_max_volt = min(pdo_pps_apdo_max_voltage(src), in tcpm_pd_select_pps_apdo()
1724 port->pps_data.req_max_curr = min_pps_apdo_current(src, snk); in tcpm_pd_select_pps_apdo()
1725 port->pps_data.req_out_volt = min(port->pps_data.req_max_volt, in tcpm_pd_select_pps_apdo()
1726 max(port->pps_data.req_min_volt, in tcpm_pd_select_pps_apdo()
1727 port->pps_data.req_out_volt)); in tcpm_pd_select_pps_apdo()
1728 port->pps_data.req_op_curr = min(port->pps_data.req_max_curr, in tcpm_pd_select_pps_apdo()
1729 port->pps_data.req_op_curr); in tcpm_pd_select_pps_apdo()
1749 pdo = port->source_caps[src_pdo_index]; in tcpm_pd_build_request()
1750 matching_snk_pdo = port->snk_pdo[snk_pdo_index]; in tcpm_pd_build_request()
1763 return -EINVAL; in tcpm_pd_build_request()
1780 if (mw < port->operating_snk_mw) { in tcpm_pd_build_request()
1791 port->cc_req, port->cc1, port->cc2, port->vbus_source, in tcpm_pd_build_request()
1792 port->vconn_role == TYPEC_SOURCE ? "source" : "sink", in tcpm_pd_build_request()
1793 port->polarity); in tcpm_pd_build_request()
1809 port->req_current_limit = ma; in tcpm_pd_build_request()
1810 port->req_supply_voltage = mv; in tcpm_pd_build_request()
1827 port->pwr_role, in tcpm_pd_send_request()
1828 port->data_role, in tcpm_pd_send_request()
1829 port->negotiated_rev, in tcpm_pd_send_request()
1830 port->message_id, 1); in tcpm_pd_send_request()
1845 return -EOPNOTSUPP; in tcpm_pd_build_pps_request()
1847 pdo = port->source_caps[src_pdo_index]; in tcpm_pd_build_pps_request()
1854 return -EINVAL; in tcpm_pd_build_pps_request()
1856 max_mv = port->pps_data.req_max_volt; in tcpm_pd_build_pps_request()
1857 max_ma = port->pps_data.req_max_curr; in tcpm_pd_build_pps_request()
1858 out_mv = port->pps_data.req_out_volt; in tcpm_pd_build_pps_request()
1859 op_ma = port->pps_data.req_op_curr; in tcpm_pd_build_pps_request()
1863 return -EINVAL; in tcpm_pd_build_pps_request()
1869 if (op_mw < port->operating_snk_mw) { in tcpm_pd_build_pps_request()
1876 op_ma = (port->operating_snk_mw * 1000) / out_mv; in tcpm_pd_build_pps_request()
1877 if ((port->operating_snk_mw * 1000) % out_mv) in tcpm_pd_build_pps_request()
1879 op_ma += RDO_PROG_CURR_MA_STEP - (op_ma % RDO_PROG_CURR_MA_STEP); in tcpm_pd_build_pps_request()
1883 out_mv = (port->operating_snk_mw * 1000) / op_ma; in tcpm_pd_build_pps_request()
1884 if ((port->operating_snk_mw * 1000) % op_ma) in tcpm_pd_build_pps_request()
1886 out_mv += RDO_PROG_VOLT_MV_STEP - in tcpm_pd_build_pps_request()
1891 return -EINVAL; in tcpm_pd_build_pps_request()
1897 port->cc_req, port->cc1, port->cc2, port->vbus_source, in tcpm_pd_build_pps_request()
1898 port->vconn_role == TYPEC_SOURCE ? "source" : "sink", in tcpm_pd_build_pps_request()
1899 port->polarity); in tcpm_pd_build_pps_request()
1906 port->pps_data.req_op_curr = op_ma; in tcpm_pd_build_pps_request()
1907 port->pps_data.req_out_volt = out_mv; in tcpm_pd_build_pps_request()
1924 port->pwr_role, in tcpm_pd_send_pps_request()
1925 port->data_role, in tcpm_pd_send_pps_request()
1926 port->negotiated_rev, in tcpm_pd_send_pps_request()
1927 port->message_id, 1); in tcpm_pd_send_pps_request()
1937 if (enable && port->vbus_charge) in tcpm_set_vbus()
1938 return -EINVAL; in tcpm_set_vbus()
1940 debug("vbus = %d charge = %d\n", enable, port->vbus_charge); in tcpm_set_vbus()
1942 ret = port->tcpc->set_vbus(port->tcpc, enable, port->vbus_charge); in tcpm_set_vbus()
1946 port->vbus_source = enable; in tcpm_set_vbus()
1954 if (charge && port->vbus_source) in tcpm_set_charge()
1955 return -EINVAL; in tcpm_set_charge()
1957 if (charge != port->vbus_charge) { in tcpm_set_charge()
1958 debug("vbus = %d charge = %d\n", port->vbus_source, charge); in tcpm_set_charge()
1959 ret = port->tcpc->set_vbus(port->tcpc, port->vbus_source, in tcpm_set_charge()
1964 port->vbus_charge = charge; in tcpm_set_charge()
1972 if (!port->tcpc->start_toggling) in tcpm_start_toggling()
1976 ret = port->tcpc->start_toggling(port->tcpc, port->port_type, cc); in tcpm_start_toggling()
1984 ret = port->tcpc->set_vbus(port->tcpc, false, false); in tcpm_init_vbus()
1985 port->vbus_source = false; in tcpm_init_vbus()
1986 port->vbus_charge = false; in tcpm_init_vbus()
1994 ret = port->tcpc->set_vconn(port->tcpc, false); in tcpm_init_vconn()
1995 port->vconn_role = TYPEC_SINK; in tcpm_init_vconn()
2001 if (!port->connected) { in tcpm_typec_connect()
2002 port->connected = true; in tcpm_typec_connect()
2009 port->cc2 == TYPEC_CC_RD ? TYPEC_POLARITY_CC2 in tcpm_src_attach()
2013 if (port->attached) in tcpm_src_attach()
2024 ret = port->tcpc->set_pd_rx(port->tcpc, true); in tcpm_src_attach()
2029 * USB Type-C specification, version 1.2, in tcpm_src_attach()
2031 * Enable VCONN only if the non-RD port is set to RA. in tcpm_src_attach()
2033 if ((polarity == TYPEC_POLARITY_CC1 && port->cc2 == TYPEC_CC_RA) || in tcpm_src_attach()
2034 (polarity == TYPEC_POLARITY_CC2 && port->cc1 == TYPEC_CC_RA)) { in tcpm_src_attach()
2044 port->pd_capable = false; in tcpm_src_attach()
2046 port->partner = NULL; in tcpm_src_attach()
2048 port->attached = true; in tcpm_src_attach()
2049 port->debouncing = false; in tcpm_src_attach()
2050 //port->send_discover = true; in tcpm_src_attach()
2057 port->tcpc->set_pd_rx(port->tcpc, false); in tcpm_src_attach()
2066 if (port->connected) { in tcpm_typec_disconnect()
2067 port->partner = NULL; in tcpm_typec_disconnect()
2068 port->connected = false; in tcpm_typec_disconnect()
2076 port->poll_event_cnt = 0; in tcpm_reset_port()
2077 port->wait_dr_swap_Message = false; in tcpm_reset_port()
2078 port->attached = false; in tcpm_reset_port()
2079 port->pd_capable = false; in tcpm_reset_port()
2080 port->pps_data.supported = false; in tcpm_reset_port()
2083 * First Rx ID should be 0; set this to a sentinel of -1 so that in tcpm_reset_port()
2086 port->rx_msgid = -1; in tcpm_reset_port()
2088 port->tcpc->set_pd_rx(port->tcpc, false); in tcpm_reset_port()
2094 port->usb_type = POWER_SUPPLY_USB_TYPE_C; in tcpm_reset_port()
2095 port->nr_sink_caps = 0; in tcpm_reset_port()
2096 port->sink_cap_done = false; in tcpm_reset_port()
2102 port->hard_reset_count = 0; in tcpm_detach()
2104 if (!port->attached) in tcpm_detach()
2119 if (port->attached) in tcpm_snk_attach()
2122 ret = tcpm_set_polarity(port, port->cc2 != TYPEC_CC_OPEN ? in tcpm_snk_attach()
2131 port->pd_capable = false; in tcpm_snk_attach()
2133 port->partner = NULL; in tcpm_snk_attach()
2135 port->attached = true; in tcpm_snk_attach()
2136 port->debouncing = false; in tcpm_snk_attach()
2138 port->cc1 != TYPEC_CC_OPEN ? "CC1" : "CC2"); in tcpm_snk_attach()
2152 if (port->attached) in tcpm_acc_attach()
2159 port->partner = NULL; in tcpm_acc_attach()
2163 port->attached = true; in tcpm_acc_attach()
2165 dev_info(port->dev, "CC connected as Audio Accessory\n"); in tcpm_acc_attach()
2177 if (port->hard_reset_count < PD_N_HARD_RESET_COUNT) in hard_reset_state()
2179 if (port->pd_capable) in hard_reset_state()
2181 if (port->pwr_role == TYPEC_SOURCE) in hard_reset_state()
2183 if (port->state == SNK_WAIT_CAPABILITIES) in hard_reset_state()
2190 if (port->port_type == TYPEC_PORT_DRP) { in unattached_state()
2191 if (port->pwr_role == TYPEC_SOURCE) in unattached_state()
2195 } else if (port->port_type == TYPEC_PORT_SRC) { in unattached_state()
2204 if (port->port_type == TYPEC_PORT_DRP) in tcpm_is_toggling()
2205 return port->state == SRC_UNATTACHED || port->state == SNK_UNATTACHED || in tcpm_is_toggling()
2206 port->state == TOGGLING; in tcpm_is_toggling()
2216 port->enter_state = port->state; in run_state_machine()
2217 switch (port->state) { in run_state_machine()
2228 if (port->port_type == TYPEC_PORT_DRP) in run_state_machine()
2255 port->caps_count = 0; in run_state_machine()
2256 port->negotiated_rev = PD_MAX_REV; in run_state_machine()
2257 port->message_id = 0; in run_state_machine()
2258 port->rx_msgid = -1; in run_state_machine()
2259 port->explicit_contract = false; in run_state_machine()
2263 port->caps_count++; in run_state_machine()
2264 if (port->caps_count > PD_N_CAPS_COUNT) { in run_state_machine()
2275 * However, that can result in state machine hang-ups. in run_state_machine()
2278 /* port->hard_reset_count = 0; */ in run_state_machine()
2279 port->caps_count = 0; in run_state_machine()
2280 port->pd_capable = true; in run_state_machine()
2289 * PD 2.0 sinks are supposed to accept src-capabilities with a in run_state_machine()
2295 * After PD_N_HARD_RESET_COUNT hard-reset attempts, we try in run_state_machine()
2296 * sending src-capabilities with a lower PD revision to in run_state_machine()
2299 if (port->hard_reset_count < PD_N_HARD_RESET_COUNT) { in run_state_machine()
2301 } else if (port->negotiated_rev > PD_REV20) { in run_state_machine()
2302 port->negotiated_rev--; in run_state_machine()
2303 port->hard_reset_count = 0; in run_state_machine()
2313 if (!port->explicit_contract) { in run_state_machine()
2328 port->explicit_contract = true; in run_state_machine()
2333 port->hard_reset_count = 0; in run_state_machine()
2335 port->try_src_count = 0; in run_state_machine()
2351 if (port->port_type == TYPEC_PORT_DRP) in run_state_machine()
2355 if ((port->cc1 == TYPEC_CC_OPEN && in run_state_machine()
2356 port->cc2 != TYPEC_CC_OPEN) || in run_state_machine()
2357 (port->cc1 != TYPEC_CC_OPEN && in run_state_machine()
2358 port->cc2 == TYPEC_CC_OPEN)) in run_state_machine()
2369 } else if (port->vbus_present) in run_state_machine()
2384 port->negotiated_rev = PD_MAX_REV; in run_state_machine()
2385 port->message_id = 0; in run_state_machine()
2386 port->rx_msgid = -1; in run_state_machine()
2387 port->explicit_contract = false; in run_state_machine()
2391 if (port->vbus_present) { in run_state_machine()
2405 port->port_type == TYPEC_PORT_DRP ? in run_state_machine()
2416 ktime_after(port->delayed_runtime, ktime_get())) { in run_state_machine()
2418 ktime_to_ms(ktime_sub(port->delayed_runtime, ktime_get()))); in run_state_machine()
2425 ret = port->tcpc->set_pd_rx(port->tcpc, true); in run_state_machine()
2436 if (port->vbus_never_low) { in run_state_machine()
2437 port->vbus_never_low = false; in run_state_machine()
2446 port->pd_capable = true; in run_state_machine()
2447 port->hard_reset_count = 0; in run_state_machine()
2460 port->pps_status = ret; in run_state_machine()
2466 if (port->update_sink_caps) in run_state_machine()
2481 port->try_snk_count = 0; in run_state_machine()
2482 port->update_sink_caps = false; in run_state_machine()
2485 * Here poll_event_cnt is cleared, waiting for self-powered Type-C devices in run_state_machine()
2488 if (port->wait_dr_swap_Message) in run_state_machine()
2489 port->poll_event_cnt = 0; in run_state_machine()
2512 port->wait_dr_swap_Message = false; in run_state_machine()
2515 port->hard_reset_count++; in run_state_machine()
2516 port->tcpc->set_pd_rx(port->tcpc, false); in run_state_machine()
2517 port->nr_sink_caps = 0; in run_state_machine()
2518 port->send_discover = true; in run_state_machine()
2519 if (port->pwr_role == TYPEC_SOURCE) in run_state_machine()
2528 tcpm_set_roles(port, port->self_powered, TYPEC_SOURCE, in run_state_machine()
2535 port->tcpc->set_pd_rx(port->tcpc, true); in run_state_machine()
2540 memset(&port->pps_data, 0, sizeof(port->pps_data)); in run_state_machine()
2542 if (port->pd_capable) in run_state_machine()
2544 tcpm_set_roles(port, port->self_powered, TYPEC_SINK, in run_state_machine()
2566 * - turn off VCONN, reset power supply in run_state_machine()
2567 * - request hardware reset in run_state_machine()
2568 * - turn on VCONN in run_state_machine()
2569 * - Transition to state PE_Src_Startup in run_state_machine()
2572 * Similar, dual-mode ports in source mode should transition in run_state_machine()
2575 if (port->pd_capable) { in run_state_machine()
2587 port->message_id = 0; in run_state_machine()
2588 port->rx_msgid = -1; in run_state_machine()
2590 if (port->pwr_role == TYPEC_SOURCE) { in run_state_machine()
2597 port->message_id = 0; in run_state_machine()
2598 port->rx_msgid = -1; in run_state_machine()
2616 if (port->data_role == TYPEC_DEVICE && port->send_discover) in run_state_machine()
2617 port->vdm_sm_running = true; in run_state_machine()
2622 //tcpm_swap_complete(port, -ETIMEDOUT); in run_state_machine()
2626 if (port->data_role == TYPEC_HOST) { in run_state_machine()
2628 tcpm_set_roles(port, true, port->pwr_role, in run_state_machine()
2631 tcpm_set_roles(port, true, port->pwr_role, in run_state_machine()
2633 //port->send_discover = true; in run_state_machine()
2636 port->wait_dr_swap_Message = false; in run_state_machine()
2657 if (port->pwr_role == TYPEC_SOURCE) in run_state_machine()
2669 port->explicit_contract = false; in run_state_machine()
2685 * USB-PD standard, 6.2.1.4, Port Power Role: in run_state_machine()
2713 port->pps_data.active, 0); in run_state_machine()
2722 * allow time VBUS ramp-up, must be < tNewSrc in run_state_machine()
2731 * USB PD standard, 6.2.1.4: in run_state_machine()
2777 port->vbus_present ? PD_T_PS_SOURCE_OFF : 0); in run_state_machine()
2780 printf("Unexpected port state %d\n", port->state); in run_state_machine()
2789 mutex_lock(&port->lock); in tcpm_state_machine()
2790 port->state_machine_running = true; in tcpm_state_machine()
2792 if (port->queued_message && tcpm_send_queued_message(port)) in tcpm_state_machine()
2796 if (port->delayed_state) { in tcpm_state_machine()
2797 debug("state change %s -> %s [delayed %ld ms]\n", in tcpm_state_machine()
2798 tcpm_states[port->state], in tcpm_state_machine()
2799 tcpm_states[port->delayed_state], port->delay_ms); in tcpm_state_machine()
2800 port->prev_state = port->state; in tcpm_state_machine()
2801 port->state = port->delayed_state; in tcpm_state_machine()
2802 port->delayed_state = INVALID_STATE; in tcpm_state_machine()
2806 * Continue running as long as we have (non-delayed) state changes in tcpm_state_machine()
2810 prev_state = port->state; in tcpm_state_machine()
2812 if (port->queued_message) in tcpm_state_machine()
2814 } while (port->state != prev_state && !port->delayed_state); in tcpm_state_machine()
2817 port->state_machine_running = false; in tcpm_state_machine()
2818 mutex_unlock(&port->lock); in tcpm_state_machine()
2827 old_cc1 = port->cc1; in _tcpm_cc_change()
2828 old_cc2 = port->cc2; in _tcpm_cc_change()
2829 port->cc1 = cc1; in _tcpm_cc_change()
2830 port->cc2 = cc2; in _tcpm_cc_change()
2832 debug("CC1: %u -> %u, CC2: %u -> %u [state %s, polarity %d, %s]\n", in _tcpm_cc_change()
2833 old_cc1, cc1, old_cc2, cc2, tcpm_states[port->state], in _tcpm_cc_change()
2834 port->polarity, in _tcpm_cc_change()
2837 switch (port->state) { in _tcpm_cc_change()
2870 if ((port->cc1 == TYPEC_CC_OPEN && in _tcpm_cc_change()
2871 port->cc2 != TYPEC_CC_OPEN) || in _tcpm_cc_change()
2872 (port->cc1 != TYPEC_CC_OPEN && in _tcpm_cc_change()
2873 port->cc2 == TYPEC_CC_OPEN)) in _tcpm_cc_change()
2879 if (new_state != port->delayed_state) in _tcpm_cc_change()
2885 else if (port->vbus_present) in _tcpm_cc_change()
2889 if (new_state != port->delayed_state) in _tcpm_cc_change()
2895 else if (!port->pd_capable && in _tcpm_cc_change()
2930 if (!port->vbus_present && tcpm_port_is_source(port)) in _tcpm_cc_change()
2934 if (port->vbus_present || !tcpm_port_is_source(port)) in _tcpm_cc_change()
2939 port->max_wait = 0; in _tcpm_cc_change()
2993 port->vbus_present = true; in _tcpm_pd_vbus_on()
2998 port->vbus_vsafe0v = false; in _tcpm_pd_vbus_on()
3000 switch (port->state) { in _tcpm_pd_vbus_on()
3002 port->explicit_contract = true; in _tcpm_pd_vbus_on()
3064 port->vbus_present = false; in _tcpm_pd_vbus_off()
3065 port->vbus_never_low = false; in _tcpm_pd_vbus_off()
3066 switch (port->state) { in _tcpm_pd_vbus_off()
3088 port->debouncing = false; in _tcpm_pd_vbus_off()
3128 if (port->pwr_role == TYPEC_SINK && port->attached) in _tcpm_pd_vbus_off()
3137 port->poll_event_cnt = 0; in _tcpm_pd_hard_reset()
3140 * we should ignore it, that is, do not set port->state to HARD_RESET_START. in _tcpm_pd_hard_reset()
3142 if (port->state == PORT_RESET || port->state == PORT_RESET_WAIT_OFF) in _tcpm_pd_hard_reset()
3150 port->hard_reset_count < PD_N_HARD_RESET_COUNT ? in _tcpm_pd_hard_reset()
3160 while (port->pd_events) {
3161 events = port->pd_events;
3162 port->pd_events = 0;
3168 vbus = port->tcpc->get_vbus(port->tcpc);
3178 if (!port->tcpc->is_vbus_vsafe0v ||
3179 port->tcpc->is_vbus_vsafe0v(port->tcpc))
3186 if (port->tcpc->get_cc(port->tcpc, &cc1, &cc2) == 0)
3190 if (port->state == SNK_READY) {
3193 port->upcoming_state = FR_SWAP_SEND;
3195 if (ret == -EAGAIN)
3196 port->upcoming_state = INVALID_STATE;
3210 port->vbus_source = true;
3221 port->poll_event_cnt = 0; in tcpm_cc_change()
3222 if (port->tcpc->get_cc(port->tcpc, &cc1, &cc2) == 0) in tcpm_cc_change()
3231 port->poll_event_cnt = 0; in tcpm_vbus_change()
3232 vbus = port->tcpc->get_vbus(port->tcpc); in tcpm_vbus_change()
3242 port->poll_event_cnt = 0; in tcpm_pd_hard_reset()
3251 port->tcpc->init(port->tcpc); in tcpm_init()
3260 port->vbus_present = port->tcpc->get_vbus(port->tcpc); in tcpm_init()
3261 if (port->vbus_present) in tcpm_init()
3262 port->vbus_never_low = true; in tcpm_init()
3275 if (port->vbus_present) in tcpm_init()
3276 port->vbus_vsafe0v = false; in tcpm_init()
3277 else if (!port->tcpc->is_vbus_vsafe0v) in tcpm_init()
3278 port->vbus_vsafe0v = true; in tcpm_init()
3280 port->vbus_vsafe0v = port->tcpc->is_vbus_vsafe0v(port->tcpc); in tcpm_init()
3284 if (port->tcpc->get_cc(port->tcpc, &cc1, &cc2) == 0) in tcpm_init()
3290 mutex_lock(&port->lock); in tcpm_tcpc_reset()
3291 /* XXX: Maintain PD connection if possible? */ in tcpm_tcpc_reset()
3293 mutex_unlock(&port->lock); in tcpm_tcpc_reset()
3300 ofnode node = port->tcpc->connector_node; in tcpm_fw_get_caps()
3306 cap_str = ofnode_read_string(node, "data-role"); in tcpm_fw_get_caps()
3311 port->typec_caps.data = ret; in tcpm_fw_get_caps()
3315 cap_str = ofnode_read_string(node, "power-role"); in tcpm_fw_get_caps()
3317 return -EINVAL; in tcpm_fw_get_caps()
3320 port->typec_caps.type = TYPEC_PORT_DRP; in tcpm_fw_get_caps()
3322 port->typec_caps.type = TYPEC_PORT_SRC; in tcpm_fw_get_caps()
3324 port->typec_caps.type = TYPEC_PORT_SNK; in tcpm_fw_get_caps()
3329 port->port_type = port->typec_caps.type; in tcpm_fw_get_caps()
3331 port->slow_charger_loop = ofnode_read_bool(node, "slow-charger-loop"); in tcpm_fw_get_caps()
3332 if (port->port_type == TYPEC_PORT_SNK) in tcpm_fw_get_caps()
3336 ret = ofnode_read_size(node, "source-pdos") / sizeof(u32); in tcpm_fw_get_caps()
3338 return -EINVAL; in tcpm_fw_get_caps()
3340 port->nr_src_pdo = min(ret, PDO_MAX_OBJECTS); in tcpm_fw_get_caps()
3341 ret = ofnode_read_u32_array(node, "source-pdos", in tcpm_fw_get_caps()
3342 port->src_pdo, port->nr_src_pdo); in tcpm_fw_get_caps()
3343 if (ret || tcpm_validate_caps(port, port->src_pdo, in tcpm_fw_get_caps()
3344 port->nr_src_pdo)) in tcpm_fw_get_caps()
3345 return -EINVAL; in tcpm_fw_get_caps()
3347 if (port->port_type == TYPEC_PORT_SRC) in tcpm_fw_get_caps()
3351 cap_str = ofnode_read_string(node, "try-power-role"); in tcpm_fw_get_caps()
3353 return -EINVAL; in tcpm_fw_get_caps()
3356 port->typec_caps.prefer_role = TYPEC_SINK; in tcpm_fw_get_caps()
3358 port->typec_caps.prefer_role = TYPEC_SOURCE; in tcpm_fw_get_caps()
3360 return -EINVAL; in tcpm_fw_get_caps()
3362 if (port->typec_caps.prefer_role < 0) in tcpm_fw_get_caps()
3363 return -EINVAL; in tcpm_fw_get_caps()
3366 ret = ofnode_read_size(node, "sink-pdos") / sizeof(u32); in tcpm_fw_get_caps()
3368 return -EINVAL; in tcpm_fw_get_caps()
3370 port->nr_snk_pdo = min(ret, PDO_MAX_OBJECTS); in tcpm_fw_get_caps()
3371 ret = ofnode_read_u32_array(node, "sink-pdos", in tcpm_fw_get_caps()
3372 port->snk_pdo, port->nr_snk_pdo); in tcpm_fw_get_caps()
3373 if (ret || tcpm_validate_caps(port, port->snk_pdo, in tcpm_fw_get_caps()
3374 port->nr_snk_pdo)) in tcpm_fw_get_caps()
3375 return -EINVAL; in tcpm_fw_get_caps()
3377 if (ofnode_read_u32_array(node, "op-sink-microwatt", &mw, 1)) in tcpm_fw_get_caps()
3378 return -EINVAL; in tcpm_fw_get_caps()
3379 port->operating_snk_mw = mw / 1000; in tcpm_fw_get_caps()
3381 port->self_powered = ofnode_read_bool(node, "self-powered"); in tcpm_fw_get_caps()
3384 if (port->port_type == TYPEC_PORT_DRP) { in tcpm_fw_get_caps()
3385 ret = ofnode_read_u32_array(node, "new-source-frs-typec-current", in tcpm_fw_get_caps()
3388 port->new_source_frs_current = frs_current; in tcpm_fw_get_caps()
3391 /* sink-vdos is optional */ in tcpm_fw_get_caps()
3392 ret = ofnode_read_size(node, "sink-vdos") / sizeof(u32); in tcpm_fw_get_caps()
3396 port->nr_snk_vdo = min(ret, VDO_MAX_OBJECTS); in tcpm_fw_get_caps()
3397 if (port->nr_snk_vdo) { in tcpm_fw_get_caps()
3398 ret = ofnode_read_u32_array(node, "sink-vdos", in tcpm_fw_get_caps()
3399 port->snk_vdo, port->nr_snk_vdo); in tcpm_fw_get_caps()
3404 /* If sink-vdos is found, sink-vdos-v1 is expected for backward compatibility. */ in tcpm_fw_get_caps()
3405 if (port->nr_snk_vdo) { in tcpm_fw_get_caps()
3406 ret = ofnode_read_size(node, "sink-vdos-v1") / sizeof(u32); in tcpm_fw_get_caps()
3410 return -ENODATA; in tcpm_fw_get_caps()
3412 port->nr_snk_vdo_v1 = min(ret, VDO_MAX_OBJECTS); in tcpm_fw_get_caps()
3413 ret = ofnode_read_u32_array(node, "sink-vdos-v1", in tcpm_fw_get_caps()
3414 port->snk_vdo_v1, in tcpm_fw_get_caps()
3415 port->nr_snk_vdo_v1); in tcpm_fw_get_caps()
3429 !tcpc->get_vbus || !tcpc->set_cc || !tcpc->get_cc || in tcpm_port_init()
3430 !tcpc->set_polarity || !tcpc->set_vconn || !tcpc->set_vbus || in tcpm_port_init()
3431 !tcpc->set_pd_rx || !tcpc->set_roles || !tcpc->pd_transmit) in tcpm_port_init()
3432 return ERR_PTR(-EINVAL); in tcpm_port_init()
3436 return ERR_PTR(-ENOMEM); in tcpm_port_init()
3438 port->dev = dev; in tcpm_port_init()
3439 port->tcpc = tcpc; in tcpm_port_init()
3448 port->try_role = port->typec_caps.prefer_role; in tcpm_port_init()
3450 port->typec_caps.revision = 0x0120; /* Type-C spec release 1.2 */ in tcpm_port_init()
3451 port->typec_caps.pd_revision = 0x0300; /* USB-PD spec release 3.0 */ in tcpm_port_init()
3452 port->typec_caps.svdm_version = SVDM_VER_2_0; in tcpm_port_init()
3453 port->typec_caps.driver_data = port; in tcpm_port_init()
3454 port->typec_caps.orientation_aware = 1; in tcpm_port_init()
3456 port->port_type = port->typec_caps.type; in tcpm_port_init()
3468 if (!port->tcpc->get_vbus(port->tcpc)) in tcpm_poll_event()
3471 while (port->poll_event_cnt < TCPM_POLL_EVENT_TIME_OUT) { in tcpm_poll_event()
3472 if (!port->wait_dr_swap_Message && in tcpm_poll_event()
3473 ((port->state == SNK_READY) || in tcpm_poll_event()
3474 (port->state == SRC_READY) || in tcpm_poll_event()
3475 (port->state == DEBUG_ACC_ATTACHED) || in tcpm_poll_event()
3476 (port->state == AUDIO_ACC_ATTACHED))) in tcpm_poll_event()
3479 port->tcpc->poll_event(port->tcpc); in tcpm_poll_event()
3480 port->poll_event_cnt++; in tcpm_poll_event()
3485 * At this time, call the callback function of the respective pd chip in tcpm_poll_event()
3486 * to enter the low-power mode. In order to reduce the time spent on in tcpm_poll_event()
3487 * the PD chip driver as much as possible, the tcpm framework does not in tcpm_poll_event()
3491 * self-powered Type-C device will initiate a Message(eg: self-powered in tcpm_poll_event()
3492 * Type-C hub initiates a SINK capability request(PD_CTRL_GET_SINK_CAP)) in tcpm_poll_event()
3493 * and the pd chip cannot reply to GoodCRC, causing the self-powered Type-C in tcpm_poll_event()
3496 if (port->tcpc->enter_low_power_mode) { in tcpm_poll_event()
3497 if (port->tcpc->enter_low_power_mode(port->tcpc, in tcpm_poll_event()
3498 port->attached, in tcpm_poll_event()
3499 port->pd_capable)) in tcpm_poll_event()
3502 printf("PD chip enter low power mode\n"); in tcpm_poll_event()
3509 return port->supply_voltage * 1000; in tcpm_get_voltage()
3515 return port->current_limit * 1000; in tcpm_get_current()
3521 if (port->state == SNK_READY) in tcpm_get_online()