Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | /* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright 2015-2017 Google, Inc * Copyright 2024 Collabora */ #ifndef __LINUX_USB_TCPM_INTERNAL_H #define __LINUX_USB_TCPM_INTERNAL_H #define FOREACH_TCPM_STATE(S) \ S(INVALID_STATE), \ S(TOGGLING), \ S(SRC_UNATTACHED), \ S(SRC_ATTACH_WAIT), \ S(SRC_ATTACHED), \ S(SRC_STARTUP), \ S(SRC_SEND_CAPABILITIES), \ S(SRC_SEND_CAPABILITIES_TIMEOUT), \ S(SRC_NEGOTIATE_CAPABILITIES), \ S(SRC_TRANSITION_SUPPLY), \ S(SRC_READY), \ S(SRC_WAIT_NEW_CAPABILITIES), \ \ S(SNK_UNATTACHED), \ S(SNK_ATTACH_WAIT), \ S(SNK_DEBOUNCED), \ S(SNK_ATTACHED), \ S(SNK_STARTUP), \ S(SNK_DISCOVERY), \ S(SNK_DISCOVERY_DEBOUNCE), \ S(SNK_DISCOVERY_DEBOUNCE_DONE), \ S(SNK_WAIT_CAPABILITIES), \ S(SNK_NEGOTIATE_CAPABILITIES), \ S(SNK_TRANSITION_SINK), \ S(SNK_TRANSITION_SINK_VBUS), \ S(SNK_READY), \ \ S(HARD_RESET_SEND), \ S(HARD_RESET_START), \ S(SRC_HARD_RESET_VBUS_OFF), \ S(SRC_HARD_RESET_VBUS_ON), \ S(SNK_HARD_RESET_SINK_OFF), \ S(SNK_HARD_RESET_WAIT_VBUS), \ S(SNK_HARD_RESET_SINK_ON), \ \ S(SOFT_RESET), \ S(SOFT_RESET_SEND), \ \ S(DR_SWAP_ACCEPT), \ S(DR_SWAP_CHANGE_DR), \ \ S(ERROR_RECOVERY), \ S(PORT_RESET), \ S(PORT_RESET_WAIT_OFF) #define GENERATE_TCPM_ENUM(e) e #define GENERATE_TCPM_STRING(s) #s #define TCPM_POLL_EVENT_TIME_OUT 2000 enum tcpm_state { FOREACH_TCPM_STATE(GENERATE_TCPM_ENUM) }; enum pd_msg_request { PD_MSG_NONE = 0, PD_MSG_CTRL_REJECT, PD_MSG_CTRL_WAIT, PD_MSG_CTRL_NOT_SUPP, PD_MSG_DATA_SINK_CAP, PD_MSG_DATA_SOURCE_CAP, }; struct tcpm_port { enum typec_port_type typec_type; int typec_prefer_role; enum typec_role vconn_role; enum typec_role pwr_role; enum typec_data_role data_role; struct typec_partner *partner; enum typec_cc_status cc_req; enum typec_cc_status cc1; enum typec_cc_status cc2; enum typec_cc_polarity polarity; bool attached; bool connected; int poll_event_cnt; enum typec_port_type port_type; /* * Set to true when vbus is greater than VSAFE5V min. * Set to false when vbus falls below vSinkDisconnect max threshold. */ bool vbus_present; /* * Set to true when vbus is less than VSAFE0V max. * Set to false when vbus is greater than VSAFE0V max. */ bool vbus_vsafe0v; bool vbus_never_low; bool vbus_source; bool vbus_charge; int try_role; enum pd_msg_request queued_message; enum tcpm_state enter_state; enum tcpm_state prev_state; enum tcpm_state state; enum tcpm_state delayed_state; unsigned long delay_ms; bool state_machine_running; bool tx_complete; enum tcpm_transmit_status tx_status; unsigned int negotiated_rev; unsigned int message_id; unsigned int caps_count; unsigned int hard_reset_count; bool pd_capable; bool explicit_contract; unsigned int rx_msgid; /* Partner capabilities/requests */ u32 sink_request; u32 source_caps[PDO_MAX_OBJECTS]; unsigned int nr_source_caps; u32 sink_caps[PDO_MAX_OBJECTS]; unsigned int nr_sink_caps; /* * whether to wait for the Type-C device to send the DR_SWAP Message flag * For Type-C device with Dual-Role Power and Dual-Role Data, the port side * is used as sink + ufp, then the tcpm framework needs to wait for Type-C * device to initiate DR_swap Message. */ bool wait_dr_swap_message; /* Local capabilities */ u32 src_pdo[PDO_MAX_OBJECTS]; unsigned int nr_src_pdo; u32 snk_pdo[PDO_MAX_OBJECTS]; unsigned int nr_snk_pdo; unsigned int operating_snk_mw; bool update_sink_caps; /* Requested current / voltage to the port partner */ u32 req_current_limit; u32 req_supply_voltage; /* Actual current / voltage limit of the local port */ u32 current_limit; u32 supply_voltage; /* port belongs to a self powered device */ bool self_powered; unsigned long delay_target; }; extern const char * const tcpm_states[]; int tcpm_post_probe(struct udevice *dev); #endif |