xref: /openbmc/linux/drivers/usb/typec/ucsi/trace.c (revision 9e3bd0f6)
1 // SPDX-License-Identifier: GPL-2.0
2 #define CREATE_TRACE_POINTS
3 #include "ucsi.h"
4 #include "trace.h"
5 
6 static const char * const ucsi_cmd_strs[] = {
7 	[0]				= "Unknown command",
8 	[UCSI_PPM_RESET]		= "PPM_RESET",
9 	[UCSI_CANCEL]			= "CANCEL",
10 	[UCSI_CONNECTOR_RESET]		= "CONNECTOR_RESET",
11 	[UCSI_ACK_CC_CI]		= "ACK_CC_CI",
12 	[UCSI_SET_NOTIFICATION_ENABLE]	= "SET_NOTIFICATION_ENABLE",
13 	[UCSI_GET_CAPABILITY]		= "GET_CAPABILITY",
14 	[UCSI_GET_CONNECTOR_CAPABILITY]	= "GET_CONNECTOR_CAPABILITY",
15 	[UCSI_SET_UOM]			= "SET_UOM",
16 	[UCSI_SET_UOR]			= "SET_UOR",
17 	[UCSI_SET_PDM]			= "SET_PDM",
18 	[UCSI_SET_PDR]			= "SET_PDR",
19 	[UCSI_GET_ALTERNATE_MODES]	= "GET_ALTERNATE_MODES",
20 	[UCSI_GET_CAM_SUPPORTED]	= "GET_CAM_SUPPORTED",
21 	[UCSI_GET_CURRENT_CAM]		= "GET_CURRENT_CAM",
22 	[UCSI_SET_NEW_CAM]		= "SET_NEW_CAM",
23 	[UCSI_GET_PDOS]			= "GET_PDOS",
24 	[UCSI_GET_CABLE_PROPERTY]	= "GET_CABLE_PROPERTY",
25 	[UCSI_GET_CONNECTOR_STATUS]	= "GET_CONNECTOR_STATUS",
26 	[UCSI_GET_ERROR_STATUS]		= "GET_ERROR_STATUS",
27 };
28 
29 const char *ucsi_cmd_str(u64 raw_cmd)
30 {
31 	u8 cmd = raw_cmd & GENMASK(7, 0);
32 
33 	return ucsi_cmd_strs[(cmd >= ARRAY_SIZE(ucsi_cmd_strs)) ? 0 : cmd];
34 }
35 
36 static const char * const ucsi_ack_strs[] = {
37 	[0]				= "",
38 	[UCSI_ACK_EVENT]		= "event",
39 	[UCSI_ACK_CMD]			= "command",
40 };
41 
42 const char *ucsi_ack_str(u8 ack)
43 {
44 	return ucsi_ack_strs[(ack >= ARRAY_SIZE(ucsi_ack_strs)) ? 0 : ack];
45 }
46 
47 const char *ucsi_cci_str(u32 cci)
48 {
49 	if (cci & GENMASK(7, 0)) {
50 		if (cci & BIT(29))
51 			return "Event pending (ACK completed)";
52 		if (cci & BIT(31))
53 			return "Event pending (command completed)";
54 		return "Connector Change";
55 	}
56 	if (cci & BIT(29))
57 		return "ACK completed";
58 	if (cci & BIT(31))
59 		return "Command completed";
60 
61 	return "";
62 }
63 
64 static const char * const ucsi_recipient_strs[] = {
65 	[UCSI_RECIPIENT_CON]		= "port",
66 	[UCSI_RECIPIENT_SOP]		= "partner",
67 	[UCSI_RECIPIENT_SOP_P]		= "plug (prime)",
68 	[UCSI_RECIPIENT_SOP_PP]		= "plug (double prime)",
69 };
70 
71 const char *ucsi_recipient_str(u8 recipient)
72 {
73 	return ucsi_recipient_strs[recipient];
74 }
75