1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Driver for TI TPS6598x USB Power Delivery controller family 4 * 5 * Copyright (C) 2020 Purism SPC 6 * Author: Guido Günther <agx@sigxcpu.org> 7 */ 8 9 #undef TRACE_SYSTEM 10 #define TRACE_SYSTEM tps6598x 11 12 #if !defined(_TPS6598X_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ) 13 #define _TPS6598X_TRACE_H_ 14 15 #include "tps6598x.h" 16 17 #include <linux/stringify.h> 18 #include <linux/types.h> 19 #include <linux/tracepoint.h> 20 21 #define show_irq_flags(flags) \ 22 __print_flags_u64(flags, "|", \ 23 { TPS_REG_INT_PD_SOFT_RESET, "PD_SOFT_RESET" }, \ 24 { TPS_REG_INT_HARD_RESET, "HARD_RESET" }, \ 25 { TPS_REG_INT_PLUG_EVENT, "PLUG_EVENT" }, \ 26 { TPS_REG_INT_PR_SWAP_COMPLETE, "PR_SWAP_COMPLETE" }, \ 27 { TPS_REG_INT_DR_SWAP_COMPLETE, "DR_SWAP_COMPLETE" }, \ 28 { TPS_REG_INT_RDO_RECEIVED_FROM_SINK, "RDO_RECEIVED_FROM_SINK" }, \ 29 { TPS_REG_INT_BIST, "BIST" }, \ 30 { TPS_REG_INT_OVERCURRENT, "OVERCURRENT" }, \ 31 { TPS_REG_INT_ATTENTION_RECEIVED, "ATTENTION_RECEIVED" }, \ 32 { TPS_REG_INT_VDM_RECEIVED, "VDM_RECEIVED" }, \ 33 { TPS_REG_INT_NEW_CONTRACT_AS_CONSUMER, "NEW_CONTRACT_AS_CONSUMER" }, \ 34 { TPS_REG_INT_NEW_CONTRACT_AS_PROVIDER, "NEW_CONTRACT_AS_PROVIDER" }, \ 35 { TPS_REG_INT_SOURCE_CAP_MESSAGE_READY, "SOURCE_CAP_MESSAGE_READY" }, \ 36 { TPS_REG_INT_SINK_CAP_MESSAGE_READY, "SINK_CAP_MESSAGE_READY" }, \ 37 { TPS_REG_INT_PR_SWAP_REQUESTED, "PR_SWAP_REQUESTED" }, \ 38 { TPS_REG_INT_GOTO_MIN_RECEIVED, "GOTO_MIN_RECEIVED" }, \ 39 { TPS_REG_INT_USB_HOST_PRESENT, "USB_HOST_PRESENT" }, \ 40 { TPS_REG_INT_USB_HOST_PRESENT_NO_LONGER, "USB_HOST_PRESENT_NO_LONGER" }, \ 41 { TPS_REG_INT_HIGH_VOLTAGE_WARNING, "HIGH_VOLTAGE_WARNING" }, \ 42 { TPS_REG_INT_PP_SWITCH_CHANGED, "PP_SWITCH_CHANGED" }, \ 43 { TPS_REG_INT_POWER_STATUS_UPDATE, "POWER_STATUS_UPDATE" }, \ 44 { TPS_REG_INT_DATA_STATUS_UPDATE, "DATA_STATUS_UPDATE" }, \ 45 { TPS_REG_INT_STATUS_UPDATE, "STATUS_UPDATE" }, \ 46 { TPS_REG_INT_PD_STATUS_UPDATE, "PD_STATUS_UPDATE" }, \ 47 { TPS_REG_INT_ADC_LOW_THRESHOLD, "ADC_LOW_THRESHOLD" }, \ 48 { TPS_REG_INT_ADC_HIGH_THRESHOLD, "ADC_HIGH_THRESHOLD" }, \ 49 { TPS_REG_INT_CMD1_COMPLETE, "CMD1_COMPLETE" }, \ 50 { TPS_REG_INT_CMD2_COMPLETE, "CMD2_COMPLETE" }, \ 51 { TPS_REG_INT_ERROR_DEVICE_INCOMPATIBLE, "ERROR_DEVICE_INCOMPATIBLE" }, \ 52 { TPS_REG_INT_ERROR_CANNOT_PROVIDE_PWR, "ERROR_CANNOT_PROVIDE_PWR" }, \ 53 { TPS_REG_INT_ERROR_CAN_PROVIDE_PWR_LATER, "ERROR_CAN_PROVIDE_PWR_LATER" }, \ 54 { TPS_REG_INT_ERROR_POWER_EVENT_OCCURRED, "ERROR_POWER_EVENT_OCCURRED" }, \ 55 { TPS_REG_INT_ERROR_MISSING_GET_CAP_MESSAGE, "ERROR_MISSING_GET_CAP_MESSAGE" }, \ 56 { TPS_REG_INT_ERROR_PROTOCOL_ERROR, "ERROR_PROTOCOL_ERROR" }, \ 57 { TPS_REG_INT_ERROR_MESSAGE_DATA, "ERROR_MESSAGE_DATA" }, \ 58 { TPS_REG_INT_ERROR_DISCHARGE_FAILED, "ERROR_DISCHARGE_FAILED" }, \ 59 { TPS_REG_INT_SRC_TRANSITION, "SRC_TRANSITION" }, \ 60 { TPS_REG_INT_ERROR_UNABLE_TO_SOURCE, "ERROR_UNABLE_TO_SOURCE" }, \ 61 { TPS_REG_INT_VDM_ENTERED_MODE, "VDM_ENTERED_MODE" }, \ 62 { TPS_REG_INT_VDM_MSG_SENT, "VDM_MSG_SENT" }, \ 63 { TPS_REG_INT_DISCOVER_MODES_COMPLETE, "DISCOVER_MODES_COMPLETE" }, \ 64 { TPS_REG_INT_EXIT_MODES_COMPLETE, "EXIT_MODES_COMPLETE" }, \ 65 { TPS_REG_INT_USER_VID_ALT_MODE_ENTERED, "USER_VID_ALT_MODE_ENTERED" }, \ 66 { TPS_REG_INT_USER_VID_ALT_MODE_EXIT, "USER_VID_ALT_MODE_EXIT" }, \ 67 { TPS_REG_INT_USER_VID_ALT_MODE_ATTN_VDM, "USER_VID_ALT_MODE_ATTN_VDM" }, \ 68 { TPS_REG_INT_USER_VID_ALT_MODE_OTHER_VDM, "USER_VID_ALT_MODE_OTHER_VDM" }) 69 70 #define TPS6598X_STATUS_FLAGS_MASK (GENMASK(31, 0) ^ (TPS_STATUS_CONN_STATE_MASK | \ 71 TPS_STATUS_PP_5V0_SWITCH_MASK | \ 72 TPS_STATUS_PP_HV_SWITCH_MASK | \ 73 TPS_STATUS_PP_EXT_SWITCH_MASK | \ 74 TPS_STATUS_PP_CABLE_SWITCH_MASK | \ 75 TPS_STATUS_POWER_SOURCE_MASK | \ 76 TPS_STATUS_VBUS_STATUS_MASK | \ 77 TPS_STATUS_USB_HOST_PRESENT_MASK | \ 78 TPS_STATUS_LEGACY_MASK)) 79 80 #define show_status_conn_state(status) \ 81 __print_symbolic(TPS_STATUS_CONN_STATE((status)), \ 82 { TPS_STATUS_CONN_STATE_CONN_WITH_R_A, "conn-Ra" }, \ 83 { TPS_STATUS_CONN_STATE_CONN_NO_R_A, "conn-no-Ra" }, \ 84 { TPS_STATUS_CONN_STATE_NO_CONN_R_A, "no-conn-Ra" }, \ 85 { TPS_STATUS_CONN_STATE_DEBUG_CONN, "debug" }, \ 86 { TPS_STATUS_CONN_STATE_AUDIO_CONN, "audio" }, \ 87 { TPS_STATUS_CONN_STATE_DISABLED, "disabled" }, \ 88 { TPS_STATUS_CONN_STATE_NO_CONN, "no-conn" }) 89 90 #define show_status_pp_switch_state(status) \ 91 __print_symbolic(status, \ 92 { TPS_STATUS_PP_SWITCH_STATE_IN, "in" }, \ 93 { TPS_STATUS_PP_SWITCH_STATE_OUT, "out" }, \ 94 { TPS_STATUS_PP_SWITCH_STATE_FAULT, "fault" }, \ 95 { TPS_STATUS_PP_SWITCH_STATE_DISABLED, "off" }) 96 97 #define show_status_power_sources(status) \ 98 __print_symbolic(TPS_STATUS_POWER_SOURCE(status), \ 99 { TPS_STATUS_POWER_SOURCE_VBUS, "vbus" }, \ 100 { TPS_STATUS_POWER_SOURCE_VIN_3P3, "vin-3p3" }, \ 101 { TPS_STATUS_POWER_SOURCE_DEAD_BAT, "dead-battery" }, \ 102 { TPS_STATUS_POWER_SOURCE_UNKNOWN, "unknown" }) 103 104 #define show_status_vbus_status(status) \ 105 __print_symbolic(TPS_STATUS_VBUS_STATUS(status), \ 106 { TPS_STATUS_VBUS_STATUS_VSAFE0V, "vSafe0V" }, \ 107 { TPS_STATUS_VBUS_STATUS_VSAFE5V, "vSafe5V" }, \ 108 { TPS_STATUS_VBUS_STATUS_PD, "pd" }, \ 109 { TPS_STATUS_VBUS_STATUS_FAULT, "fault" }) 110 111 #define show_status_usb_host_present(status) \ 112 __print_symbolic(TPS_STATUS_USB_HOST_PRESENT(status), \ 113 { TPS_STATUS_USB_HOST_PRESENT_PD_USB, "pd-usb" }, \ 114 { TPS_STATUS_USB_HOST_PRESENT_NO_PD, "no-pd" }, \ 115 { TPS_STATUS_USB_HOST_PRESENT_PD_NO_USB, "pd-no-usb" }, \ 116 { TPS_STATUS_USB_HOST_PRESENT_NO, "no" }) 117 118 #define show_status_legacy(status) \ 119 __print_symbolic(TPS_STATUS_LEGACY(status), \ 120 { TPS_STATUS_LEGACY_SOURCE, "source" }, \ 121 { TPS_STATUS_LEGACY_SINK, "sink" }, \ 122 { TPS_STATUS_LEGACY_NO, "no" }) 123 124 #define show_status_flags(flags) \ 125 __print_flags((flags & TPS6598X_STATUS_FLAGS_MASK), "|", \ 126 { TPS_STATUS_PLUG_PRESENT, "PLUG_PRESENT" }, \ 127 { TPS_STATUS_PLUG_UPSIDE_DOWN, "UPSIDE_DOWN" }, \ 128 { TPS_STATUS_PORTROLE, "PORTROLE" }, \ 129 { TPS_STATUS_DATAROLE, "DATAROLE" }, \ 130 { TPS_STATUS_VCONN, "VCONN" }, \ 131 { TPS_STATUS_OVERCURRENT, "OVERCURRENT" }, \ 132 { TPS_STATUS_GOTO_MIN_ACTIVE, "GOTO_MIN_ACTIVE" }, \ 133 { TPS_STATUS_BIST, "BIST" }, \ 134 { TPS_STATUS_HIGH_VOLAGE_WARNING, "HIGH_VOLAGE_WARNING" }, \ 135 { TPS_STATUS_HIGH_LOW_VOLTAGE_WARNING, "HIGH_LOW_VOLTAGE_WARNING" }) 136 137 #define show_power_status_source_sink(power_status) \ 138 __print_symbolic(TPS_POWER_STATUS_SOURCESINK(power_status), \ 139 { 1, "sink" }, \ 140 { 0, "source" }) 141 142 #define show_power_status_typec_status(power_status) \ 143 __print_symbolic(TPS_POWER_STATUS_PWROPMODE(power_status), \ 144 { TPS_POWER_STATUS_TYPEC_CURRENT_PD, "pd" }, \ 145 { TPS_POWER_STATUS_TYPEC_CURRENT_3A0, "3.0A" }, \ 146 { TPS_POWER_STATUS_TYPEC_CURRENT_1A5, "1.5A" }, \ 147 { TPS_POWER_STATUS_TYPEC_CURRENT_USB, "usb" }) 148 149 #define show_power_status_bc12_status(power_status) \ 150 __print_symbolic(TPS_POWER_STATUS_BC12_STATUS(power_status), \ 151 { TPS_POWER_STATUS_BC12_STATUS_DCP, "dcp" }, \ 152 { TPS_POWER_STATUS_BC12_STATUS_CDP, "cdp" }, \ 153 { TPS_POWER_STATUS_BC12_STATUS_SDP, "sdp" }) 154 155 #define TPS_DATA_STATUS_FLAGS_MASK (GENMASK(31, 0) ^ (TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK | \ 156 TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK | \ 157 TPS_DATA_STATUS_TBT_CABLE_GEN_MASK)) 158 159 #define show_data_status_flags(data_status) \ 160 __print_flags(data_status & TPS_DATA_STATUS_FLAGS_MASK, "|", \ 161 { TPS_DATA_STATUS_DATA_CONNECTION, "DATA_CONNECTION" }, \ 162 { TPS_DATA_STATUS_UPSIDE_DOWN, "DATA_UPSIDE_DOWN" }, \ 163 { TPS_DATA_STATUS_ACTIVE_CABLE, "ACTIVE_CABLE" }, \ 164 { TPS_DATA_STATUS_USB2_CONNECTION, "USB2_CONNECTION" }, \ 165 { TPS_DATA_STATUS_USB3_CONNECTION, "USB3_CONNECTION" }, \ 166 { TPS_DATA_STATUS_USB3_GEN2, "USB3_GEN2" }, \ 167 { TPS_DATA_STATUS_USB_DATA_ROLE, "USB_DATA_ROLE" }, \ 168 { TPS_DATA_STATUS_DP_CONNECTION, "DP_CONNECTION" }, \ 169 { TPS_DATA_STATUS_DP_SINK, "DP_SINK" }, \ 170 { TPS_DATA_STATUS_TBT_CONNECTION, "TBT_CONNECTION" }, \ 171 { TPS_DATA_STATUS_TBT_TYPE, "TBT_TYPE" }, \ 172 { TPS_DATA_STATUS_OPTICAL_CABLE, "OPTICAL_CABLE" }, \ 173 { TPS_DATA_STATUS_ACTIVE_LINK_TRAIN, "ACTIVE_LINK_TRAIN" }, \ 174 { TPS_DATA_STATUS_FORCE_LSX, "FORCE_LSX" }, \ 175 { TPS_DATA_STATUS_POWER_MISMATCH, "POWER_MISMATCH" }) 176 177 #define show_data_status_dp_pin_assignment(data_status) \ 178 __print_symbolic(TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT(data_status), \ 179 { TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_E, "E" }, \ 180 { TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_F, "F" }, \ 181 { TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_C, "C" }, \ 182 { TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_D, "D" }, \ 183 { TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_A, "A" }, \ 184 { TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B, "B" }) 185 186 #define maybe_show_data_status_dp_pin_assignment(data_status) \ 187 (data_status & TPS_DATA_STATUS_DP_CONNECTION ? \ 188 show_data_status_dp_pin_assignment(data_status) : "") 189 190 TRACE_EVENT(tps6598x_irq, 191 TP_PROTO(u64 event1, 192 u64 event2), 193 TP_ARGS(event1, event2), 194 195 TP_STRUCT__entry( 196 __field(u64, event1) 197 __field(u64, event2) 198 ), 199 200 TP_fast_assign( 201 __entry->event1 = event1; 202 __entry->event2 = event2; 203 ), 204 205 TP_printk("event1=%s, event2=%s", 206 show_irq_flags(__entry->event1), 207 show_irq_flags(__entry->event2)) 208 ); 209 210 TRACE_EVENT(tps6598x_status, 211 TP_PROTO(u32 status), 212 TP_ARGS(status), 213 214 TP_STRUCT__entry( 215 __field(u32, status) 216 ), 217 218 TP_fast_assign( 219 __entry->status = status; 220 ), 221 222 TP_printk("conn: %s, pp_5v0: %s, pp_hv: %s, pp_ext: %s, pp_cable: %s, " 223 "pwr-src: %s, vbus: %s, usb-host: %s, legacy: %s, flags: %s", 224 show_status_conn_state(__entry->status), 225 show_status_pp_switch_state(TPS_STATUS_PP_5V0_SWITCH(__entry->status)), 226 show_status_pp_switch_state(TPS_STATUS_PP_HV_SWITCH(__entry->status)), 227 show_status_pp_switch_state(TPS_STATUS_PP_EXT_SWITCH(__entry->status)), 228 show_status_pp_switch_state(TPS_STATUS_PP_CABLE_SWITCH(__entry->status)), 229 show_status_power_sources(__entry->status), 230 show_status_vbus_status(__entry->status), 231 show_status_usb_host_present(__entry->status), 232 show_status_legacy(__entry->status), 233 show_status_flags(__entry->status) 234 ) 235 ); 236 237 TRACE_EVENT(tps6598x_power_status, 238 TP_PROTO(u16 power_status), 239 TP_ARGS(power_status), 240 241 TP_STRUCT__entry( 242 __field(u16, power_status) 243 ), 244 245 TP_fast_assign( 246 __entry->power_status = power_status; 247 ), 248 249 TP_printk("conn: %d, pwr-role: %s, typec: %s, bc: %s", 250 !!TPS_POWER_STATUS_CONNECTION(__entry->power_status), 251 show_power_status_source_sink(__entry->power_status), 252 show_power_status_typec_status(__entry->power_status), 253 show_power_status_bc12_status(__entry->power_status) 254 ) 255 ); 256 257 TRACE_EVENT(tps6598x_data_status, 258 TP_PROTO(u32 data_status), 259 TP_ARGS(data_status), 260 261 TP_STRUCT__entry( 262 __field(u32, data_status) 263 ), 264 265 TP_fast_assign( 266 __entry->data_status = data_status; 267 ), 268 269 TP_printk("%s%s%s", 270 show_data_status_flags(__entry->data_status), 271 __entry->data_status & TPS_DATA_STATUS_DP_CONNECTION ? ", DP pinout " : "", 272 maybe_show_data_status_dp_pin_assignment(__entry->data_status) 273 ) 274 ); 275 276 #endif /* _TPS6598X_TRACE_H_ */ 277 278 /* This part must be outside protection */ 279 #undef TRACE_INCLUDE_FILE 280 #define TRACE_INCLUDE_FILE trace 281 #undef TRACE_INCLUDE_PATH 282 #define TRACE_INCLUDE_PATH . 283 #include <trace/define_trace.h> 284