PD Buddy Sink Firmware
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pdb_dpm.h 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * PD Buddy Firmware Library - USB Power Delivery for everyone
  3. * Copyright 2017-2018 Clayton G. Hobbs
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #ifndef PDB_DPM_H
  18. #define PDB_DPM_H
  19. #include <stdbool.h>
  20. #include <pdb_fusb.h>
  21. #include <pdb_msg.h>
  22. /* Forward declaration of struct pdb_config */
  23. struct pdb_config;
  24. /* DPM callback typedefs */
  25. typedef void (*pdb_dpm_func)(struct pdb_config *);
  26. typedef bool (*pdb_dpm_eval_cap_func)(struct pdb_config *,
  27. const union pd_msg *, union pd_msg *);
  28. typedef void (*pdb_dpm_get_sink_cap_func)(struct pdb_config *, union pd_msg *);
  29. typedef bool (*pdb_dpm_giveback_func)(struct pdb_config *);
  30. typedef bool (*pdb_dpm_tcc_func)(struct pdb_config *, enum fusb_typec_current);
  31. /*
  32. * PD Buddy firmware library Device Policy Manager callbacks
  33. *
  34. * All functions are passed a struct pdb_config * as their first parameter.
  35. * This points to the struct pdb_config that contains the calling thread.
  36. *
  37. * Optional functions may be set to NULL if the associated functionality is not
  38. * required.
  39. */
  40. struct pdb_dpm_callbacks {
  41. /*
  42. * Evaluate the Source_Capabilities, creating a Request in response.
  43. *
  44. * The second parameter is the Source_Capabilities message. This is NULL
  45. * when the function is called as a result of the PDB_EVT_PE_NEW_POWER
  46. * event.
  47. *
  48. * The third parameter is a union pd_msg * into which the Request must be
  49. * written.
  50. *
  51. * Returns true if sufficient power is available, false otherwise.
  52. */
  53. pdb_dpm_eval_cap_func evaluate_capability;
  54. /*
  55. * Create a Sink_Capabilities message for our current capabilities.
  56. *
  57. * The second parameter is a union pd_msg * into which the
  58. * Sink_Capabilities message must be written.
  59. */
  60. pdb_dpm_get_sink_cap_func get_sink_capability;
  61. /*
  62. * Return whether or not GiveBack support is enabled.
  63. *
  64. * Optional. If the implementation does not support GiveBack under any
  65. * circumstances, this may be omitted.
  66. */
  67. pdb_dpm_giveback_func giveback_enabled;
  68. /*
  69. * Evaluate whether or not the Type-C Current can fulfill our power needs.
  70. *
  71. * The second parameter is an enum fusb_typec_current holding the Type-C
  72. * Current level to evaluate.
  73. *
  74. * Returns true if sufficient power is available, false otherwise.
  75. *
  76. * Optional. If the implementation does not require Type-C Current support
  77. * (e.g. more than 5 V is required for the device to function), this may be
  78. * omitted.
  79. */
  80. pdb_dpm_tcc_func evaluate_typec_current;
  81. /*
  82. * Called at the start of Power Delivery negotiations.
  83. *
  84. * Optional. If nothing special needs to happen when PD negotiations
  85. * start, this may be omitted.
  86. */
  87. pdb_dpm_func pd_start;
  88. /*
  89. * Transition the sink to the default power level for USB.
  90. */
  91. pdb_dpm_func transition_default;
  92. /*
  93. * Transition to the requested minimum current.
  94. *
  95. * Optional. If and only if giveback_enabled is NULL, this may be omitted.
  96. */
  97. pdb_dpm_func transition_min;
  98. /*
  99. * Transition to Sink Standby if necessary.
  100. *
  101. * From section 7.2.3 of the USB PD spec, the sink shall reduce its
  102. * power draw to no more than 2.5 W before a positive or negative
  103. * transition of Vbus. This function must determine if a voltage
  104. * transition is occurring, and if it is, it must reduce the power
  105. * consumption to the required level.
  106. */
  107. pdb_dpm_func transition_standby;
  108. /*
  109. * Transition to the requested power level.
  110. */
  111. pdb_dpm_func transition_requested;
  112. /*
  113. * Transition to the appropriate power level for the most recent Type-C
  114. * Current evaluated.
  115. *
  116. * Optional. If and only if evaluate_typec_current is NULL, this may be
  117. * omitted.
  118. */
  119. pdb_dpm_func transition_typec;
  120. /*
  121. * Handle a received Not_Supported message.
  122. *
  123. * Optional. If no special handling is needed, this may be omitted.
  124. */
  125. pdb_dpm_func not_supported_received;
  126. };
  127. #endif /* PDB_DPM_H */