1 /* 2 * Copyright 2022 The Chromium OS Authors 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6 /** 7 * @file 8 * @brief USB-C Power Delivery API used for USB-C drivers 9 * 10 * The information in this file was taken from the USB PD 11 * Specification Revision 3.0, Version 2.0 12 */ 13 14 #ifndef ZEPHYR_INCLUDE_DRIVERS_USBC_USBC_PD_H_ 15 #define ZEPHYR_INCLUDE_DRIVERS_USBC_USBC_PD_H_ 16 17 /** 18 * @brief USB Power Delivery 19 * @defgroup usb_power_delivery USB Power Delivery 20 * @ingroup io_interfaces 21 * @{ 22 */ 23 24 #include <zephyr/types.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /** 31 * @brief Maximum length of a non-Extended Message in bytes. 32 * See Table 6-75 Value Parameters 33 * Parameter Name: MaxExtendedMsgLegacyLen 34 */ 35 #define PD_MAX_EXTENDED_MSG_LEGACY_LEN 26 36 37 /** 38 * @brief Maximum length of an Extended Message in bytes. 39 * See Table 6-75 Value Parameters 40 * Parameter Name: MaxExtendedMsgLen 41 */ 42 #define PD_MAX_EXTENDED_MSG_LEN 260 43 44 /** 45 * @brief Maximum length of a Chunked Message in bytes. 46 * When one of both Port Partners do not support Extended 47 * Messages of Data Size greater than PD_MAX_EXTENDED_MSG_LEGACY_LEN 48 * then the Protocol Layer supports a Chunking mechanism to 49 * break larger Messages into smaller Chunks of size 50 * PD_MAX_EXTENDED_MSG_CHUNK_LEN. 51 * See Table 6-75 Value Parameters 52 * Parameter Name: MaxExtendedMsgChunkLen 53 */ 54 #define PD_MAX_EXTENDED_MSG_CHUNK_LEN 26 55 56 /** 57 * @name USB PD 3.1 Rev 1.6, Table 6-70 Counter Parameters 58 * @{ 59 */ 60 61 /** 62 * @brief The CapsCounter is used to count the number of Source_Capabilities 63 * Messages which have been sent by a Source at power up or after a 64 * Hard Reset. 65 * Parameter Name: nCapsCounter 66 */ 67 #define PD_N_CAPS_COUNT 50 68 69 /** 70 * @brief The HardResetCounter is used to retry the Hard Reset whenever there 71 * is no response from the remote device (see Section 6.6.6) 72 * Parameter Name: nHardResetCounter 73 */ 74 #define PD_N_HARD_RESET_COUNT 2 75 76 /** @} */ 77 78 /** 79 * @name USB PD 3.1 Rev 1.6, Table 6-68 Time Values 80 * @{ 81 */ 82 83 /** 84 * @brief The NoResponseTimer is used by the Policy Engine in a Source to 85 * determine that its Port Partner is not responding after a Hard Reset. 86 * Parameter Name: tNoResponseTimer 87 */ 88 #define PD_T_NO_RESPONSE_MIN_MS 4500 89 90 /** 91 * @brief The NoResponseTimer is used by the Policy Engine in a Source to 92 * determine that its Port Partner is not responding after a Hard Reset. 93 * Parameter Name: tNoResponseTimer 94 */ 95 #define PD_T_NO_RESPONSE_MAX_MS 5500 96 97 /** 98 * @brief Min time the Source waits to ensure that the Sink has had 99 * sufficient time to process Hard Reset Signaling before 100 * turning off its power supply to VBUS 101 * Parameter Name: tPSHardReset 102 */ 103 #define PD_T_PS_HARD_RESET_MIN_MS 25 104 105 /** 106 * @brief Max time the Source waits to ensure that the Sink has had 107 * sufficient time to process Hard Reset Signaling before 108 * turning off its power supply to VBUS 109 * Parameter Name: tPSHardReset 110 */ 111 #define PD_T_PS_HARD_RESET_MAX_MS 35 112 113 /** 114 * @brief Minimum time a Source waits after changing Rp from SinkTxOk to SinkTxNG 115 * before initiating an AMS by sending a Message. 116 * Parameter Name: tSinkTx 117 */ 118 #define PD_T_SINK_TX_MIN_MS 16 119 120 /** 121 * @brief Maximum time a Source waits after changing Rp from SinkTxOk to SinkTxNG 122 * before initiating an AMS by sending a Message. 123 * Parameter Name: tSinkTx 124 */ 125 #define PD_T_SINK_TX_MAX_MS 20 126 127 /** 128 * @brief Minimum time a source shall wait before sending a 129 * Source_Capabilities message while the following is true: 130 * 1) The Port is Attached. 131 * 2) The Source is not in an active connection with a PD Sink Port. 132 * Parameter Name: tTypeCSendSourceCap 133 */ 134 #define PD_T_TYPEC_SEND_SOURCE_CAP_MIN_MS 100 135 136 /** 137 * @brief Maxmimum time a source shall wait before sending a 138 * Source_Capabilities message while the following is true: 139 * 1) The Port is Attached. 140 * 2) The Source is not in an active connection with a PD Sink Port. 141 * Parameter Name: tTypeCSendSourceCap 142 */ 143 #define PD_T_TYPEC_SEND_SOURCE_CAP_MAX_MS 200 144 145 /** @} */ 146 147 /** 148 * @brief Minimum time a sink shall wait for a Source_Capabilities message 149 * before sending a Hard Reset 150 * See Table 6-61 Time Values 151 * Parameter Name: tTypeCSinkWaitCap 152 */ 153 #define PD_T_TYPEC_SINK_WAIT_CAP_MIN_MS 310 154 155 /** 156 * @brief Minimum time a sink shall wait for a Source_Capabilities message 157 * before sending a Hard Reset 158 * See Table 6-61 Time Values 159 * Parameter Name: tTypeCSinkWaitCap 160 */ 161 #define PD_T_TYPEC_SINK_WAIT_CAP_MAX_MS 620 162 163 /** 164 * @brief VBUS maximum safe operating voltage at "zero volts". 165 * See Table 7-24 Common Source/Sink Electrical Parameters 166 * Parameter Name: vSafe0V 167 */ 168 #define PD_V_SAFE_0V_MAX_MV 800 169 170 /** 171 * @brief VBUS minimum safe operating voltage at 5V. 172 * See Table 7-24 Common Source/Sink Electrical Parameters 173 * Parameter Name: vSafe5V 174 */ 175 #define PD_V_SAFE_5V_MIN_MV 4750 176 177 /** 178 * @brief Time to reach PD_V_SAFE_0V_MV max in milliseconds. 179 * See Table 7-24 Common Source/Sink Electrical Parameters 180 * Parameter Name: tSafe0V 181 */ 182 #define PD_T_SAFE_0V_MAX_MS 650 183 184 /** 185 * @brief Time to reach PD_V_SAFE_5V_MV max in milliseconds. 186 * See Table 7-24 Common Source/Sink Electrical Parameters 187 * Parameter Name: tSafe5V 188 */ 189 #define PD_T_SAFE_5V_MAX_MS 275 190 191 /** 192 * @brief Time to wait for TCPC to complete transmit 193 */ 194 #define PD_T_TX_TIMEOUT_MS 100 195 196 /** 197 * @brief Minimum time a Hard Reset must complete. 198 * See Table 6-68 Time Values 199 */ 200 #define PD_T_HARD_RESET_COMPLETE_MIN_MS 4 201 202 /** 203 * @brief Maximum time a Hard Reset must complete. 204 * See Table 6-68 Time Values 205 */ 206 #define PD_T_HARD_RESET_COMPLETE_MAX_MS 5 207 208 /** 209 * @brief Minimum time a response must be sent from a Port Partner 210 * See Table 6-68 Time Values 211 */ 212 #define PD_T_SENDER_RESPONSE_MIN_MS 24 213 214 /** 215 * @brief Nomiminal time a response must be sent from a Port Partner 216 * See Table 6-68 Time Values 217 */ 218 #define PD_T_SENDER_RESPONSE_NOM_MS 27 219 220 /** 221 * @brief Maximum time a response must be sent from a Port Partner 222 * See Table 6-68 Time Values 223 */ 224 #define PD_T_SENDER_RESPONSE_MAX_MS 30 225 226 /** 227 * @brief Minimum SPR Mode time for a power suppply to transition to a new level 228 * See Table 6-68 Time Values 229 */ 230 #define PD_T_SPR_PS_TRANSITION_MIN_MS 450 231 232 /** 233 * @brief Nominal SPR Mode time for a power suppply to transition to a new level 234 * See Table 6-68 Time Values 235 */ 236 #define PD_T_SPR_PS_TRANSITION_NOM_MS 500 237 238 /** 239 * @brief Maximum SPR Mode time for a power suppply to transition to a new level 240 * See Table 6-68 Time Values 241 */ 242 #define PD_T_SPR_PS_TRANSITION_MAX_MS 550 243 244 /** 245 * @brief Minimum EPR Mode time for a power suppply to transition to a new level 246 * See Table 6-68 Time Values 247 */ 248 #define PD_T_EPR_PS_TRANSITION_MIN_MS 830 249 250 /** 251 * @brief Nominal EPR Mode time for a power suppply to transition to a new level 252 * See Table 6-68 Time Values 253 */ 254 #define PD_T_EPR_PS_TRANSITION_NOM_MS 925 255 256 /** 257 * @brief Maximum EPR Mode time for a power suppply to transition to a new level 258 * See Table 6-68 Time Values 259 */ 260 #define PD_T_EPR_PS_TRANSITION_MAX_MS 1020 261 262 /** 263 * @brief Minimum time to wait before sending another request after receiving a Wait message 264 * See Table 6-68 Time Values 265 */ 266 #define PD_T_SINK_REQUEST_MIN_MS 100 267 268 /** 269 * @brief Minimum time to wait before sending a Not_Supported message after receiving a 270 * Chunked message 271 * See Table 6-68 Time Values 272 */ 273 #define PD_T_CHUNKING_NOT_SUPPORTED_MIN_MS 40 274 275 /** 276 * @brief Nominal time to wait before sending a Not_Supported message after receiving a 277 * Chunked message 278 * See Table 6-68 Time Values 279 */ 280 #define PD_T_CHUNKING_NOT_SUPPORTED_NOM_MS 45 281 282 /** 283 * @brief Maximum time to wait before sending a Not_Supported message after receiving a 284 * Chunked message 285 * See Table 6-68 Time Values 286 */ 287 #define PD_T_CHUNKING_NOT_SUPPORTED_MAX_MS 50 288 289 /** 290 * @brief Convert bytes to PD Header data object count, where a 291 * data object is 4-bytes. 292 * 293 * @param c number of bytes to convert 294 */ 295 #define PD_CONVERT_BYTES_TO_PD_HEADER_COUNT(c) ((c) >> 2) 296 297 /** 298 * @brief Convert PD Header data object count to bytes 299 * 300 * @param c number of PD Header data objects 301 */ 302 #define PD_CONVERT_PD_HEADER_COUNT_TO_BYTES(c) ((c) << 2) 303 304 /** 305 * @brief Collision avoidance Rp values in REV 3.0 306 * Sink Transmit "OK" 307 */ 308 #define SINK_TX_OK TC_RP_3A0 309 310 /** 311 * @brief Collision avoidance Rp values in REV 3.0 312 * Sink Transmit "NO GO" 313 */ 314 #define SINK_TX_NG TC_RP_1A5 315 316 /** 317 * @brief Build a PD message header 318 * See Table 6-1 Message Header 319 */ 320 union pd_header { 321 struct { 322 /** Type of message */ 323 uint16_t message_type : 5; 324 /** Port Data role */ 325 uint16_t port_data_role : 1; 326 /** Specification Revision */ 327 uint16_t specification_revision : 2; 328 /** Port Power Role */ 329 uint16_t port_power_role : 1; 330 /** Message ID */ 331 uint16_t message_id : 3; 332 /** Number of Data Objects */ 333 uint16_t number_of_data_objects : 3; 334 /** Extended Message */ 335 uint16_t extended : 1; 336 }; 337 uint16_t raw_value; 338 }; 339 340 /** 341 * @brief Used to get extended header from the first 32-bit word of the message 342 * 343 * @param c first 32-bit word of the message 344 */ 345 #define PD_GET_EXT_HEADER(c) ((c) & 0xffff) 346 347 /** 348 * @brief Build an extended message header 349 * See Table 6-3 Extended Message Header 350 */ 351 union pd_ext_header { 352 struct { 353 /** Number of total bytes in data block */ 354 uint16_t data_size : 9; 355 /** Reserved */ 356 uint16_t reserved0 : 1; 357 /** 1 for a chunked message, else 0 */ 358 uint16_t request_chunk : 1; 359 /** Chunk number when chkd = 1, else 0 */ 360 uint16_t chunk_number : 4; 361 /** 1 for chunked messages */ 362 uint16_t chunked : 1; 363 }; 364 /** Raw PD Ext Header value */ 365 uint16_t raw_value; 366 }; 367 368 /** 369 * PDO - Power Data Object 370 * RDO - Request Data Object 371 */ 372 373 /** 374 * @brief Maximum number of 32-bit data objects sent in a single request 375 */ 376 #define PDO_MAX_DATA_OBJECTS 7 377 378 /** 379 * @brief Power Data Object Type 380 * Table 6-7 Power Data Object 381 */ 382 enum pdo_type { 383 /** Fixed supply (Vmin = Vmax) */ 384 PDO_FIXED = 0, 385 /** Battery */ 386 PDO_BATTERY = 1, 387 /** Variable Supply (non-Battery) */ 388 PDO_VARIABLE = 2, 389 /** Augmented Power Data Object (APDO) */ 390 PDO_AUGMENTED = 3 391 }; 392 393 /** 394 * @brief Convert milliamps to Fixed PDO Current in 10mA units. 395 * 396 * @param c Current in milliamps 397 */ 398 #define PD_CONVERT_MA_TO_FIXED_PDO_CURRENT(c) ((c) / 10) 399 400 /** 401 * @brief Convert millivolts to Fixed PDO Voltage in 50mV units 402 * 403 * @param v Voltage in millivolts 404 */ 405 #define PD_CONVERT_MV_TO_FIXED_PDO_VOLTAGE(v) ((v) / 50) 406 407 /** 408 * @brief Convert a Fixed PDO Current from 10mA units to milliamps. 409 * 410 * @param c Fixed PDO current in 10mA units. 411 */ 412 #define PD_CONVERT_FIXED_PDO_CURRENT_TO_MA(c) ((c) * 10) 413 414 /** 415 * @brief Convert a Fixed PDO Voltage from 50mV units to millivolts. 416 * Used for converting pd_fixed_supply_pdo_source.voltage and 417 * pd_fixed_supply_pdo_sink.voltage 418 * 419 * @param v Fixed PDO voltage in 50mV units. 420 */ 421 #define PD_CONVERT_FIXED_PDO_VOLTAGE_TO_MV(v) ((v) * 50) 422 423 /** 424 * @brief Create a Fixed Supply PDO Source value 425 * See Table 6-9 Fixed Supply PDO - Source 426 */ 427 union pd_fixed_supply_pdo_source { 428 struct { 429 /** Maximum Current in 10mA units */ 430 uint32_t max_current : 10; 431 /** Voltage in 50mV units */ 432 uint32_t voltage : 10; 433 /** Peak Current */ 434 uint32_t peak_current : 2; 435 /** Reserved – Shall be set to zero. */ 436 uint32_t reserved0 : 2; 437 /** Unchunked Extended Messages Supported */ 438 uint32_t unchunked_ext_msg_supported : 1; 439 /** Dual-Role Data */ 440 uint32_t dual_role_data : 1; 441 /** USB Communications Capable */ 442 uint32_t usb_comms_capable : 1; 443 /** Unconstrained Power */ 444 uint32_t unconstrained_power : 1; 445 /** USB Suspend Supported */ 446 uint32_t usb_suspend_supported : 1; 447 /** Dual-Role Power */ 448 uint32_t dual_role_power : 1; 449 /** Fixed supply. SET TO PDO_FIXED */ 450 enum pdo_type type : 2; 451 }; 452 /** Raw PDO value */ 453 uint32_t raw_value; 454 }; 455 456 /** 457 * @brief Fast Role Swap Required for USB Type-C current 458 */ 459 enum pd_frs_type { 460 /** Fast Swap not supported */ 461 FRS_NOT_SUPPORTED, 462 /** Default USB Power */ 463 FRS_DEFAULT_USB_POWER, 464 /** 1.5A @ 5V */ 465 FRS_1P5A_5V, 466 /** 3.0A @ 5V */ 467 FRS_3P0A_5V 468 }; 469 470 /** 471 * @brief Create a Fixed Supply PDO Sink value 472 * See Table 6-14 Fixed Supply PDO - Sink 473 */ 474 union pd_fixed_supply_pdo_sink { 475 struct { 476 /** Operational Current in 10mA units */ 477 uint32_t operational_current : 10; 478 /** Voltage in 50mV units */ 479 uint32_t voltage : 10; 480 /** Reserved – Shall be set to zero. */ 481 uint32_t reserved0 : 3; 482 /** Fast Role Swap required USB Type-C Current */ 483 enum pd_frs_type frs_required : 2; 484 /** Dual-Role Data */ 485 uint32_t dual_role_data : 1; 486 /** USB Communications Capable */ 487 uint32_t usb_comms_capable : 1; 488 /** Unconstrained Power */ 489 uint32_t unconstrained_power : 1; 490 /** Higher Capability */ 491 uint32_t higher_capability : 1; 492 /** Dual-Role Power */ 493 uint32_t dual_role_power : 1; 494 /** Fixed supply. SET TO PDO_FIXED */ 495 enum pdo_type type : 2; 496 }; 497 /** Raw PDO value */ 498 uint32_t raw_value; 499 }; 500 501 /** 502 * @brief Convert milliamps to Variable PDO Current in 10ma units. 503 * 504 * @param c Current in milliamps 505 */ 506 #define PD_CONVERT_MA_TO_VARIABLE_PDO_CURRENT(c) ((c) / 10) 507 508 /** 509 * @brief Convert millivolts to Variable PDO Voltage in 50mV units 510 * 511 * @param v Voltage in millivolts 512 */ 513 #define PD_CONVERT_MV_TO_VARIABLE_PDO_VOLTAGE(v) ((v) / 50) 514 515 /** 516 * @brief Convert a Variable PDO Current from 10mA units to milliamps. 517 * 518 * @param c Variable PDO current in 10mA units. 519 */ 520 #define PD_CONVERT_VARIABLE_PDO_CURRENT_TO_MA(c) ((c) * 10) 521 522 /** 523 * @brief Convert a Variable PDO Voltage from 50mV units to millivolts. 524 * 525 * @param v Variable PDO voltage in 50mV units. 526 */ 527 #define PD_CONVERT_VARIABLE_PDO_VOLTAGE_TO_MV(v) ((v) * 50) 528 529 /** 530 * @brief Create a Variable Supply PDO Source value 531 * See Table 6-11 Variable Supply (non-Battery) PDO - Source 532 */ 533 union pd_variable_supply_pdo_source { 534 struct { 535 /** Maximum Current in 10mA units */ 536 uint32_t max_current : 10; 537 /** Minimum Voltage in 50mV units */ 538 uint32_t min_voltage : 10; 539 /** Maximum Voltage in 50mV units */ 540 uint32_t max_voltage : 10; 541 /** Variable supply. SET TO PDO_VARIABLE */ 542 enum pdo_type type : 2; 543 }; 544 /** Raw PDO value */ 545 uint32_t raw_value; 546 }; 547 548 /** 549 * @brief Create a Variable Supply PDO Sink value 550 * See Table 6-15 Variable Supply (non-Battery) PDO - Sink 551 */ 552 union pd_variable_supply_pdo_sink { 553 struct { 554 /** operational Current in 10mA units */ 555 uint32_t operational_current : 10; 556 /** Minimum Voltage in 50mV units */ 557 uint32_t min_voltage : 10; 558 /** Maximum Voltage in 50mV units */ 559 uint32_t max_voltage : 10; 560 /** Variable supply. SET TO PDO_VARIABLE */ 561 enum pdo_type type : 2; 562 }; 563 /** Raw PDO value */ 564 uint32_t raw_value; 565 }; 566 567 /** 568 * @brief Convert milliwatts to Battery PDO Power in 250mW units 569 * 570 * @param c Power in milliwatts 571 */ 572 #define PD_CONVERT_MW_TO_BATTERY_PDO_POWER(c) ((c) / 250) 573 574 /** 575 * @brief Convert milliwatts to Battery PDO Voltage in 50mV units 576 * 577 * @param v Voltage in millivolts 578 */ 579 #define PD_CONVERT_MV_TO_BATTERY_PDO_VOLTAGE(v) ((v) / 50) 580 581 /** 582 * @brief Convert a Battery PDO Power from 250mW units to milliwatts 583 * 584 * @param c Power in 250mW units. 585 */ 586 #define PD_CONVERT_BATTERY_PDO_POWER_TO_MW(c) ((c) * 250) 587 588 /** 589 * @brief Convert a Battery PDO Voltage from 50mV units to millivolts 590 * 591 * @param v Voltage in 50mV units. 592 */ 593 #define PD_CONVERT_BATTERY_PDO_VOLTAGE_TO_MV(v) ((v) * 50) 594 595 /** 596 * @brief Create a Battery Supply PDO Source value 597 * See Table 6-12 Battery Supply PDO - Source 598 */ 599 union pd_battery_supply_pdo_source { 600 struct { 601 /** Maximum Allowable Power in 250mW units */ 602 uint32_t max_power : 10; 603 /** Minimum Voltage in 50mV units */ 604 uint32_t min_voltage : 10; 605 /** Maximum Voltage in 50mV units */ 606 uint32_t max_voltage : 10; 607 /** Battery supply. SET TO PDO_BATTERY */ 608 enum pdo_type type : 2; 609 }; 610 /** Raw PDO value */ 611 uint32_t raw_value; 612 }; 613 614 /** 615 * @brief Create a Battery Supply PDO Sink value 616 * See Table 6-16 Battery Supply PDO - Sink 617 */ 618 union pd_battery_supply_pdo_sink { 619 struct { 620 /** Operational Power in 250mW units */ 621 uint32_t operational_power : 10; 622 /** Minimum Voltage in 50mV units */ 623 uint32_t min_voltage : 10; 624 /** Maximum Voltage in 50mV units */ 625 uint32_t max_voltage : 10; 626 /** Battery supply. SET TO PDO_BATTERY */ 627 enum pdo_type type : 2; 628 }; 629 /** Raw PDO value */ 630 uint32_t raw_value; 631 }; 632 633 /** 634 * @brief Convert milliamps to Augmented PDO Current in 50mA units 635 * 636 * @param c Current in milliamps 637 */ 638 #define PD_CONVERT_MA_TO_AUGMENTED_PDO_CURRENT(c) ((c) / 50) 639 640 /** 641 * @brief Convert millivolts to Augmented PDO Voltage in 100mV units 642 * 643 * @param v Voltage in millivolts 644 */ 645 #define PD_CONVERT_MV_TO_AUGMENTED_PDO_VOLTAGE(v) ((v) / 100) 646 647 /** 648 * @brief Convert an Augmented PDO Current from 50mA units to milliamps 649 * 650 * @param c Augmented PDO current in 50mA units. 651 */ 652 #define PD_CONVERT_AUGMENTED_PDO_CURRENT_TO_MA(c) ((c) * 50) 653 654 /** 655 * @brief Convert an Augmented PDO Voltage from 100mV units to millivolts 656 * 657 * @param v Augmented PDO voltage in 100mV units. 658 */ 659 #define PD_CONVERT_AUGMENTED_PDO_VOLTAGE_TO_MV(v) ((v) * 100) 660 661 /** 662 * @brief Create Augmented Supply PDO Source value 663 * See Table 6-13 Programmable Power Supply APDO - Source 664 */ 665 union pd_augmented_supply_pdo_source { 666 struct { 667 /** Maximum Current in 50mA increments */ 668 uint32_t max_current : 7; 669 /** Reserved – Shall be set to zero */ 670 uint32_t reserved0 : 1; 671 /** Minimum Voltage in 100mV increments */ 672 uint32_t min_voltage : 8; 673 /** Reserved – Shall be set to zero */ 674 uint32_t reserved1 : 1; 675 /** Maximum Voltage in 100mV increments */ 676 uint32_t max_voltage : 8; 677 /** Reserved – Shall be set to zero */ 678 uint32_t reserved2 : 2; 679 /** PPS Power Limited */ 680 uint32_t pps_power_limited : 1; 681 /** 682 * 00b – Programmable Power Supply 683 * 01b…11b - Reserved, Shall Not be used 684 * Setting as reserved because it defaults to 0 when not set. 685 */ 686 uint32_t reserved3 : 2; 687 /** Augmented Power Data Object (APDO). SET TO PDO_AUGMENTED */ 688 enum pdo_type type : 2; 689 }; 690 /** Raw PDO value */ 691 uint32_t raw_value; 692 }; 693 694 /** 695 * @brief Create Augmented Supply PDO Sink value 696 * See Table 6-17 Programmable Power Supply APDO - Sink 697 */ 698 union pd_augmented_supply_pdo_sink { 699 struct { 700 /** Maximum Current in 50mA increments */ 701 uint32_t max_current : 7; 702 /** Reserved – Shall be set to zero */ 703 uint32_t reserved0 : 1; 704 /** Minimum Voltage in 100mV increments */ 705 uint32_t min_voltage : 8; 706 /** Reserved – Shall be set to zero */ 707 uint32_t reserved1 : 1; 708 /** Maximum Voltage in 100mV increments */ 709 uint32_t max_voltage : 8; 710 /** Reserved – Shall be set to zero */ 711 uint32_t reserved2 : 3; 712 /** 713 * 00b – Programmable Power Supply 714 * 01b…11b - Reserved, Shall Not be used 715 * Setting as reserved because it defaults to 0 when not set. 716 */ 717 uint32_t reserved3 : 2; 718 /** Augmented Power Data Object (APDO). SET TO PDO_AUGMENTED */ 719 enum pdo_type type : 2; 720 }; 721 /** Raw PDO value */ 722 uint32_t raw_value; 723 }; 724 725 /** 726 * @brief The Request Data Object (RDO) Shall be returned by the Sink making 727 * a request for power. 728 * See Section 6.4.2 Request Message 729 */ 730 union pd_rdo { 731 /** 732 * @brief Create a Fixed RDO value 733 * See Table 6-19 Fixed and Variable Request Data Object 734 */ 735 struct { 736 /** 737 * Operating Current 10mA units 738 * NOTE: If Give Back Flag is zero, this field is 739 * the Maximum Operating Current. 740 * If Give Back Flag is one, this field is 741 * the Minimum Operating Current. 742 */ 743 uint32_t min_or_max_operating_current : 10; 744 /** Operating current in 10mA units */ 745 uint32_t operating_current : 10; 746 /** Reserved - Shall be set to zero. */ 747 uint32_t reserved0 : 3; 748 /** Unchunked Extended Messages Supported */ 749 uint32_t unchunked_ext_msg_supported : 1; 750 /** No USB Suspend */ 751 uint32_t no_usb_suspend : 1; 752 /** USB Communications Capable */ 753 uint32_t usb_comm_capable : 1; 754 /** Capability Mismatch */ 755 uint32_t cap_mismatch : 1; 756 /** Give Back Flag */ 757 uint32_t giveback : 1; 758 /** Object Position (000b is Reserved and Shall Not be used) */ 759 uint32_t object_pos : 3; 760 /** Reserved - Shall be set to zero. */ 761 uint32_t reserved1 : 1; 762 } fixed; 763 764 /** 765 * @brief Create a Variable RDO value 766 * See Table 6-19 Fixed and Variable Request Data Object 767 */ 768 struct { 769 /** 770 * Operating Current 10mA units 771 * NOTE: If Give Back Flag is zero, this field is 772 * the Maximum Operating Current. 773 * If Give Back Flag is one, this field is 774 * the Minimum Operating Current. 775 */ 776 uint32_t min_or_max_operating_current : 10; 777 /** Operating current in 10mA units */ 778 uint32_t operating_current : 10; 779 /** Reserved - Shall be set to zero. */ 780 uint32_t reserved0 : 3; 781 /** Unchunked Extended Messages Supported */ 782 uint32_t unchunked_ext_msg_supported : 1; 783 /** No USB Suspend */ 784 uint32_t no_usb_suspend : 1; 785 /** USB Communications Capable */ 786 uint32_t usb_comm_capable : 1; 787 /** Capability Mismatch */ 788 uint32_t cap_mismatch : 1; 789 /** Give Back Flag */ 790 uint32_t giveback : 1; 791 /** Object Position (000b is Reserved and Shall Not be used) */ 792 uint32_t object_pos : 3; 793 /** Reserved - Shall be set to zero. */ 794 uint32_t reserved1 : 1; 795 } variable; 796 797 /** 798 * @brief Create a Battery RDO value 799 * See Table 6-20 Battery Request Data Object 800 */ 801 struct { 802 /** Minimum Operating Power in 250mW units */ 803 uint32_t min_operating_power : 10; 804 /** Operating power in 250mW units */ 805 uint32_t operating_power : 10; 806 /** Reserved - Shall be set to zero. */ 807 uint32_t reserved0 : 3; 808 /** Unchunked Extended Messages Supported */ 809 uint32_t unchunked_ext_msg_supported : 1; 810 /** No USB Suspend */ 811 uint32_t no_usb_suspend : 1; 812 /** USB Communications Capable */ 813 uint32_t usb_comm_capable : 1; 814 /** Capability Mismatch */ 815 uint32_t cap_mismatch : 1; 816 /** Give Back Flag */ 817 uint32_t giveback : 1; 818 /** Object Position (000b is Reserved and Shall Not be used) */ 819 uint32_t object_pos : 3; 820 /** Reserved - Shall be set to zero. */ 821 uint32_t reserved1 : 1; 822 } battery; 823 824 /** 825 * @brief Create an Augmented RDO value 826 * See Table 6-22 Programmable Request Data Object 827 */ 828 struct { 829 /** Operating Current 50mA units */ 830 uint32_t operating_current : 7; 831 /** Reserved - Shall be set to zero. */ 832 uint32_t reserved0 : 2; 833 /** Output Voltage in 20mV units */ 834 uint32_t output_voltage : 11; 835 /** Reserved - Shall be set to zero. */ 836 uint32_t reserved1 : 3; 837 /** Unchunked Extended Messages Supported */ 838 uint32_t unchunked_ext_msg_supported : 1; 839 /** No USB Suspend */ 840 uint32_t no_usb_suspend : 1; 841 /** USB Communications Capable */ 842 uint32_t usb_comm_capable : 1; 843 /** Capability Mismatch */ 844 uint32_t cap_mismatch : 1; 845 /** Reserved - Shall be set to zero */ 846 uint32_t reserved2 : 1; 847 /** Object Position (000b is Reserved and Shall Not be used) */ 848 uint32_t object_pos : 3; 849 /** Reserved - Shall be set to zero. */ 850 uint32_t reserved3 : 1; 851 } augmented; 852 /** Raw RDO value */ 853 uint32_t raw_value; 854 }; 855 856 /** 857 * @brief Protocol revision 858 */ 859 enum pd_rev_type { 860 /** PD revision 1.0 */ 861 PD_REV10 = 0, 862 /** PD revision 2.0 */ 863 PD_REV20 = 1, 864 /** PD revision 3.0 */ 865 PD_REV30 = 2, 866 }; 867 868 /** 869 * @brief Power Delivery packet type 870 * See USB Type-C Port Controller Interface Specification, 871 * Revision 2.0, Version 1.2, Table 4-38 TRANSMIT Register Definition 872 */ 873 enum pd_packet_type { 874 /** Port Partner message */ 875 PD_PACKET_SOP = 0, 876 /** Cable Plug message */ 877 PD_PACKET_SOP_PRIME = 1, 878 /** Cable Plug message far end*/ 879 PD_PACKET_PRIME_PRIME = 2, 880 /** Currently undefined in the PD specification */ 881 PD_PACKET_DEBUG_PRIME = 3, 882 /** Currently undefined in the PD specification */ 883 PD_PACKET_DEBUG_PRIME_PRIME = 4, 884 /** Hard Reset message to the Port Partner */ 885 PD_PACKET_TX_HARD_RESET = 5, 886 /** Cable Reset message to the Cable */ 887 PD_PACKET_CABLE_RESET = 6, 888 /** BIST_MODE_2 message to the Port Partner */ 889 PD_PACKET_TX_BIST_MODE_2 = 7, 890 891 /** USED ONLY FOR RECEPTION OF UNKNOWN MSG TYPES */ 892 PD_PACKET_MSG_INVALID = 0xf 893 }; 894 895 /** 896 * @brief Number of valid Transmit Types 897 */ 898 #define NUM_SOP_STAR_TYPES (PD_PACKET_DEBUG_PRIME_PRIME + 1) 899 900 /** 901 * @brief Control Message type 902 * See Table 6-5 Control Message Types 903 */ 904 enum pd_ctrl_msg_type { 905 /** 0 Reserved */ 906 907 /** GoodCRC Message */ 908 PD_CTRL_GOOD_CRC = 1, 909 /** GotoMin Message */ 910 PD_CTRL_GOTO_MIN = 2, 911 /** Accept Message */ 912 PD_CTRL_ACCEPT = 3, 913 /** Reject Message */ 914 PD_CTRL_REJECT = 4, 915 /** Ping Message */ 916 PD_CTRL_PING = 5, 917 /** PS_RDY Message */ 918 PD_CTRL_PS_RDY = 6, 919 /** Get_Source_Cap Message */ 920 PD_CTRL_GET_SOURCE_CAP = 7, 921 /** Get_Sink_Cap Message */ 922 PD_CTRL_GET_SINK_CAP = 8, 923 /** DR_Swap Message */ 924 PD_CTRL_DR_SWAP = 9, 925 /** PR_Swap Message */ 926 PD_CTRL_PR_SWAP = 10, 927 /** VCONN_Swap Message */ 928 PD_CTRL_VCONN_SWAP = 11, 929 /** Wait Message */ 930 PD_CTRL_WAIT = 12, 931 /** Soft Reset Message */ 932 PD_CTRL_SOFT_RESET = 13, 933 934 /** Used for REV 3.0 */ 935 936 /** Data_Reset Message */ 937 PD_CTRL_DATA_RESET = 14, 938 /** Data_Reset_Complete Message */ 939 PD_CTRL_DATA_RESET_COMPLETE = 15, 940 /** Not_Supported Message */ 941 PD_CTRL_NOT_SUPPORTED = 16, 942 /** Get_Source_Cap_Extended Message */ 943 PD_CTRL_GET_SOURCE_CAP_EXT = 17, 944 /** Get_Status Message */ 945 PD_CTRL_GET_STATUS = 18, 946 /** FR_Swap Message */ 947 PD_CTRL_FR_SWAP = 19, 948 /** Get_PPS_Status Message */ 949 PD_CTRL_GET_PPS_STATUS = 20, 950 /** Get_Country_Codes Message */ 951 PD_CTRL_GET_COUNTRY_CODES = 21, 952 /** Get_Sink_Cap_Extended Message */ 953 PD_CTRL_GET_SINK_CAP_EXT = 22 954 955 /** 23-31 Reserved */ 956 }; 957 958 /** 959 * @brief Data message type 960 * See Table 6-6 Data Message Types 961 */ 962 enum pd_data_msg_type { 963 /** 0 Reserved */ 964 965 /** Source_Capabilities Message */ 966 PD_DATA_SOURCE_CAP = 1, 967 /** Request Message */ 968 PD_DATA_REQUEST = 2, 969 /** BIST Message */ 970 PD_DATA_BIST = 3, 971 /** Sink Capabilities Message */ 972 PD_DATA_SINK_CAP = 4, 973 /** 5-14 Reserved for REV 2.0 */ 974 PD_DATA_BATTERY_STATUS = 5, 975 /** Alert Message */ 976 PD_DATA_ALERT = 6, 977 /** Get Country Info Message */ 978 PD_DATA_GET_COUNTRY_INFO = 7, 979 980 /** 8-14 Reserved for REV 3.0 */ 981 982 /** Enter USB message */ 983 PD_DATA_ENTER_USB = 8, 984 /** Vendor Defined Message */ 985 PD_DATA_VENDOR_DEF = 15, 986 }; 987 988 /** 989 * @brief Extended message type for REV 3.0 990 * See Table 6-48 Extended Message Types 991 */ 992 enum pd_ext_msg_type { 993 /** 0 Reserved */ 994 995 /** Source_Capabilities_Extended Message */ 996 PD_EXT_SOURCE_CAP = 1, 997 /** Status Message */ 998 PD_EXT_STATUS = 2, 999 /** Get_Battery_Cap Message */ 1000 PD_EXT_GET_BATTERY_CAP = 3, 1001 /** Get_Battery_Status Message */ 1002 PD_EXT_GET_BATTERY_STATUS = 4, 1003 /** Battery_Capabilities Message */ 1004 PD_EXT_BATTERY_CAP = 5, 1005 /** Get_Manufacturer_Info Message */ 1006 PD_EXT_GET_MANUFACTURER_INFO = 6, 1007 /** Manufacturer_Info Message */ 1008 PD_EXT_MANUFACTURER_INFO = 7, 1009 /** Security_Request Message */ 1010 PD_EXT_SECURITY_REQUEST = 8, 1011 /** Security_Response Message */ 1012 PD_EXT_SECURITY_RESPONSE = 9, 1013 /** Firmware_Update_Request Message */ 1014 PD_EXT_FIRMWARE_UPDATE_REQUEST = 10, 1015 /** Firmware_Update_Response Message */ 1016 PD_EXT_FIRMWARE_UPDATE_RESPONSE = 11, 1017 /** PPS_Status Message */ 1018 PD_EXT_PPS_STATUS = 12, 1019 /** Country_Codes Message */ 1020 PD_EXT_COUNTRY_INFO = 13, 1021 /** Country_Info Message */ 1022 PD_EXT_COUNTRY_CODES = 14, 1023 1024 /*8 15-31 Reserved */ 1025 }; 1026 1027 /** 1028 * @brief Active PD CC pin 1029 */ 1030 enum usbpd_cc_pin { 1031 /** PD is active on CC1 */ 1032 USBPD_CC_PIN_1 = 0, 1033 /** PD is active on CC2 */ 1034 USBPD_CC_PIN_2 = 1, 1035 }; 1036 1037 /** 1038 * @brief Power Delivery message 1039 */ 1040 struct pd_msg { 1041 /** Type of this packet */ 1042 enum pd_packet_type type; 1043 /** Header of this message */ 1044 union pd_header header; 1045 /** Length of bytes in data */ 1046 uint32_t len; 1047 /** Message data */ 1048 uint8_t data[PD_MAX_EXTENDED_MSG_LEN]; 1049 }; 1050 1051 /** 1052 * @} 1053 */ 1054 1055 #ifdef __cplusplus 1056 } 1057 #endif 1058 1059 #endif /* ZEPHYR_INCLUDE_DRIVERS_USBC_USBC_PD_H_ */ 1060