ucsi.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #include <linux/types.h>
  2. /* -------------------------------------------------------------------------- */
  3. /* Command Status and Connector Change Indication (CCI) data structure */
  4. struct ucsi_cci {
  5. unsigned int RESERVED1:1;
  6. unsigned int connector_change:7;
  7. u8 data_length;
  8. unsigned int RESERVED9:9;
  9. unsigned int not_supported:1;
  10. unsigned int cancel_complete:1;
  11. unsigned int reset_complete:1;
  12. unsigned int busy:1;
  13. unsigned int ack_complete:1;
  14. unsigned int error:1;
  15. unsigned int cmd_complete:1;
  16. } __packed;
  17. /* Default fields in CONTROL data structure */
  18. struct ucsi_command {
  19. u8 cmd;
  20. u8 length;
  21. u64 data:48;
  22. } __packed;
  23. /* Set USB Operation Mode Command structure */
  24. struct ucsi_uor_cmd {
  25. u8 cmd;
  26. u8 length;
  27. u64 con_num:7;
  28. u64 role:3;
  29. #define UCSI_UOR_ROLE_DFP BIT(0)
  30. #define UCSI_UOR_ROLE_UFP BIT(1)
  31. #define UCSI_UOR_ROLE_DRP BIT(2)
  32. u64 data:38;
  33. } __packed;
  34. struct ucsi_control {
  35. union {
  36. u64 raw_cmd;
  37. struct ucsi_command cmd;
  38. struct ucsi_uor_cmd uor;
  39. };
  40. };
  41. struct ucsi_data {
  42. u16 version;
  43. u16 RESERVED;
  44. union {
  45. u32 raw_cci;
  46. struct ucsi_cci cci;
  47. };
  48. struct ucsi_control ctrl;
  49. u32 message_in[4];
  50. u32 message_out[4];
  51. } __packed;
  52. /* Commands */
  53. #define UCSI_PPM_RESET 0x01
  54. #define UCSI_CANCEL 0x02
  55. #define UCSI_CONNECTOR_RESET 0x03
  56. #define UCSI_ACK_CC_CI 0x04
  57. #define UCSI_SET_NOTIFICATION_ENABLE 0x05
  58. #define UCSI_GET_CAPABILITY 0x06
  59. #define UCSI_GET_CONNECTOR_CAPABILITY 0x07
  60. #define UCSI_SET_UOM 0x08
  61. #define UCSI_SET_UOR 0x09
  62. #define UCSI_SET_PDM 0x0A
  63. #define UCSI_SET_PDR 0x0B
  64. #define UCSI_GET_ALTERNATE_MODES 0x0C
  65. #define UCSI_GET_CAM_SUPPORTED 0x0D
  66. #define UCSI_GET_CURRENT_CAM 0x0E
  67. #define UCSI_SET_NEW_CAM 0x0F
  68. #define UCSI_GET_PDOS 0x10
  69. #define UCSI_GET_CABLE_PROPERTY 0x11
  70. #define UCSI_GET_CONNECTOR_STATUS 0x12
  71. #define UCSI_GET_ERROR_STATUS 0x13
  72. /* ACK_CC_CI commands */
  73. #define UCSI_ACK_EVENT 1
  74. #define UCSI_ACK_CMD 2
  75. /* Bits for SET_NOTIFICATION_ENABLE command */
  76. #define UCSI_ENABLE_NTFY_CMD_COMPLETE BIT(0)
  77. #define UCSI_ENABLE_NTFY_EXT_PWR_SRC_CHANGE BIT(1)
  78. #define UCSI_ENABLE_NTFY_PWR_OPMODE_CHANGE BIT(2)
  79. #define UCSI_ENABLE_NTFY_CAP_CHANGE BIT(5)
  80. #define UCSI_ENABLE_NTFY_PWR_LEVEL_CHANGE BIT(6)
  81. #define UCSI_ENABLE_NTFY_PD_RESET_COMPLETE BIT(7)
  82. #define UCSI_ENABLE_NTFY_CAM_CHANGE BIT(8)
  83. #define UCSI_ENABLE_NTFY_BAT_STATUS_CHANGE BIT(9)
  84. #define UCSI_ENABLE_NTFY_PARTNER_CHANGE BIT(11)
  85. #define UCSI_ENABLE_NTFY_PWR_DIR_CHANGE BIT(12)
  86. #define UCSI_ENABLE_NTFY_CONNECTOR_CHANGE BIT(14)
  87. #define UCSI_ENABLE_NTFY_ERROR BIT(15)
  88. #define UCSI_ENABLE_NTFY_ALL 0xdbe7
  89. /* Error information returned by PPM in response to GET_ERROR_STATUS command. */
  90. #define UCSI_ERROR_UNREGONIZED_CMD BIT(0)
  91. #define UCSI_ERROR_INVALID_CON_NUM BIT(1)
  92. #define UCSI_ERROR_INVALID_CMD_ARGUMENT BIT(2)
  93. #define UCSI_ERROR_INCOMPATIBLE_PARTNER BIT(3)
  94. #define UCSI_ERROR_CC_COMMUNICATION_ERR BIT(4)
  95. #define UCSI_ERROR_DEAD_BATTERY BIT(5)
  96. #define UCSI_ERROR_CONTRACT_NEGOTIATION_FAIL BIT(6)
  97. /* Data structure filled by PPM in response to GET_CAPABILITY command. */
  98. struct ucsi_capability {
  99. u32 attributes;
  100. #define UCSI_CAP_ATTR_DISABLE_STATE BIT(0)
  101. #define UCSI_CAP_ATTR_BATTERY_CHARGING BIT(1)
  102. #define UCSI_CAP_ATTR_USB_PD BIT(2)
  103. #define UCSI_CAP_ATTR_TYPEC_CURRENT BIT(6)
  104. #define UCSI_CAP_ATTR_POWER_AC_SUPPLY BIT(8)
  105. #define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
  106. #define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
  107. u8 num_connectors;
  108. u32 features:24;
  109. #define UCSI_CAP_SET_UOM BIT(0)
  110. #define UCSI_CAP_SET_PDM BIT(1)
  111. #define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
  112. #define UCSI_CAP_ALT_MODE_OVERRIDE BIT(3)
  113. #define UCSI_CAP_PDO_DETAILS BIT(4)
  114. #define UCSI_CAP_CABLE_DETAILS BIT(5)
  115. #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
  116. #define UCSI_CAP_PD_RESET BIT(7)
  117. u8 num_alt_modes;
  118. u8 RESERVED;
  119. u16 bc_version;
  120. u16 pd_version;
  121. u16 typec_version;
  122. } __packed;
  123. /* Data structure filled by PPM in response to GET_CONNECTOR_CAPABILITY cmd. */
  124. struct ucsi_connector_capability {
  125. u8 op_mode;
  126. #define UCSI_CONCAP_OPMODE_DFP BIT(0)
  127. #define UCSI_CONCAP_OPMODE_UFP BIT(1)
  128. #define UCSI_CONCAP_OPMODE_DRP BIT(2)
  129. #define UCSI_CONCAP_OPMODE_AUDIO_ACCESSORY BIT(3)
  130. #define UCSI_CONCAP_OPMODE_DEBUG_ACCESSORY BIT(4)
  131. #define UCSI_CONCAP_OPMODE_USB2 BIT(5)
  132. #define UCSI_CONCAP_OPMODE_USB3 BIT(6)
  133. #define UCSI_CONCAP_OPMODE_ALT_MODE BIT(7)
  134. u8 provider:1;
  135. u8 consumer:1;
  136. } __packed;
  137. /* Data structure filled by PPM in response to GET_CABLE_PROPERTY command. */
  138. struct ucsi_cable_property {
  139. u16 speed_supported;
  140. u8 current_capability;
  141. u8 vbus_in_cable:1;
  142. u8 active_cable:1;
  143. u8 directionality:1;
  144. u8 plug_type:2;
  145. #define UCSI_CABLE_PROPERTY_PLUG_TYPE_A 0
  146. #define UCSI_CABLE_PROPERTY_PLUG_TYPE_B 1
  147. #define UCSI_CABLE_PROPERTY_PLUG_TYPE_C 2
  148. #define UCSI_CABLE_PROPERTY_PLUG_OTHER 3
  149. u8 mode_support:1;
  150. u8 RESERVED_2:2;
  151. u8 latency:4;
  152. u8 RESERVED_4:4;
  153. } __packed;
  154. /* Data structure filled by PPM in response to GET_CONNECTOR_STATUS command. */
  155. struct ucsi_connector_status {
  156. u16 change;
  157. #define UCSI_CONSTAT_EXT_SUPPLY_CHANGE BIT(1)
  158. #define UCSI_CONSTAT_POWER_OPMODE_CHANGE BIT(2)
  159. #define UCSI_CONSTAT_PDOS_CHANGE BIT(5)
  160. #define UCSI_CONSTAT_POWER_LEVEL_CHANGE BIT(6)
  161. #define UCSI_CONSTAT_PD_RESET_COMPLETE BIT(7)
  162. #define UCSI_CONSTAT_CAM_CHANGE BIT(8)
  163. #define UCSI_CONSTAT_BC_CHANGE BIT(9)
  164. #define UCSI_CONSTAT_PARTNER_CHANGE BIT(11)
  165. #define UCSI_CONSTAT_POWER_DIR_CHANGE BIT(12)
  166. #define UCSI_CONSTAT_CONNECT_CHANGE BIT(14)
  167. #define UCSI_CONSTAT_ERROR BIT(15)
  168. u16 pwr_op_mode:3;
  169. #define UCSI_CONSTAT_PWR_OPMODE_NONE 0
  170. #define UCSI_CONSTAT_PWR_OPMODE_DEFAULT 1
  171. #define UCSI_CONSTAT_PWR_OPMODE_BC 2
  172. #define UCSI_CONSTAT_PWR_OPMODE_PD 3
  173. #define UCSI_CONSTAT_PWR_OPMODE_TYPEC1_3 4
  174. #define UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0 5
  175. u16 connected:1;
  176. u16 pwr_dir:1;
  177. u16 partner_flags:8;
  178. #define UCSI_CONSTAT_PARTNER_FLAG_USB BIT(0)
  179. #define UCSI_CONSTAT_PARTNER_FLAG_ALT_MODE BIT(1)
  180. u16 partner_type:3;
  181. #define UCSI_CONSTAT_PARTNER_TYPE_DFP 1
  182. #define UCSI_CONSTAT_PARTNER_TYPE_UFP 2
  183. #define UCSI_CONSTAT_PARTNER_TYPE_CABLE_NO_UFP 3 /* Powered Cable */
  184. #define UCSI_CONSTAT_PARTNER_TYPE_CABLE_AND_UFP 4 /* Powered Cable */
  185. #define UCSI_CONSTAT_PARTNER_TYPE_DEBUG 5
  186. #define UCSI_CONSTAT_PARTNER_TYPE_AUDIO 6
  187. u32 request_data_obj;
  188. u8 bc_status:2;
  189. #define UCSI_CONSTAT_BC_NOT_CHARGING 0
  190. #define UCSI_CONSTAT_BC_NOMINAL_CHARGING 1
  191. #define UCSI_CONSTAT_BC_SLOW_CHARGING 2
  192. #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3
  193. u8 provider_cap_limit_reason:4;
  194. #define UCSI_CONSTAT_CAP_PWR_LOWERED 0
  195. #define UCSI_CONSTAT_CAP_PWR_BUDGET_LIMIT 1
  196. u8 RESERVED:2;
  197. } __packed;
  198. /* -------------------------------------------------------------------------- */