PD Buddy Sink Firmware
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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