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.

device_policy_manager.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * PD Buddy Sink Firmware - Smart power jack for USB Power Delivery
  3. * Copyright (C) 2017-2018 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 PDBS_DEVICE_POLICY_MANAGER_H
  19. #define PDBS_DEVICE_POLICY_MANAGER_H
  20. #include <stdbool.h>
  21. #include <pdb.h>
  22. struct pdbs_dpm_data {
  23. /* The most recently received Source_Capabilities message */
  24. const union pd_msg *capabilities;
  25. /* The most recently received Type-C Current advertisement */
  26. enum fusb_typec_current typec_current;
  27. /* Whether the DPM is able to turn on the output */
  28. bool output_enabled;
  29. /* Whether the DPM sets the LED to indicate the PD status */
  30. bool led_pd_status;
  31. /* Whether the device is capable of USB communications */
  32. bool usb_comms;
  33. /* Whether or not the power supply is unconstrained */
  34. bool _unconstrained_power;
  35. /* Whether our capabilities matched or not */
  36. bool _capability_match;
  37. /* The last explicitly or implicitly negotiated voltage, in millivolts */
  38. int _present_voltage;
  39. /* The requested voltage, in millivolts */
  40. int _requested_voltage;
  41. };
  42. /*
  43. * Create a Request message based on the given Source_Capabilities message. If
  44. * capabilities is NULL, the last non-null Source_Capabilities message passes
  45. * is used. If none has been provided, the behavior is undefined.
  46. *
  47. * Returns true if sufficient power is available, false otherwise.
  48. */
  49. bool pdbs_dpm_evaluate_capability(struct pdb_config *cfg,
  50. const union pd_msg *capabilities, union pd_msg *request);
  51. /*
  52. * Create a Sink_Capabilities message for our current capabilities.
  53. */
  54. void pdbs_dpm_get_sink_capability(struct pdb_config *cfg, union pd_msg *cap);
  55. /*
  56. * Return whether or not GiveBack support is enabled.
  57. */
  58. bool pdbs_dpm_giveback_enabled(struct pdb_config *cfg);
  59. /*
  60. * Evaluate whether or not the currently offered Type-C Current can fulfill our
  61. * power needs.
  62. *
  63. * Returns true if sufficient power is available, false otherwise.
  64. */
  65. bool pdbs_dpm_evaluate_typec_current(struct pdb_config *cfg, enum fusb_typec_current tcc);
  66. /*
  67. * Indicate that power negotiations are starting.
  68. */
  69. void pdbs_dpm_pd_start(struct pdb_config *cfg);
  70. /*
  71. * Transition the sink to default power.
  72. */
  73. void pdbs_dpm_transition_default(struct pdb_config *cfg);
  74. /*
  75. * Transition to the requested minimum current.
  76. */
  77. void pdbs_dpm_transition_min(struct pdb_config *cfg);
  78. /*
  79. * Transition to Sink Standby if necessary.
  80. */
  81. void pdbs_dpm_transition_standby(struct pdb_config *cfg);
  82. /*
  83. * Transition to the requested power level
  84. */
  85. void pdbs_dpm_transition_requested(struct pdb_config *cfg);
  86. #endif /* PDBS_DEVICE_POLICY_MANAGER_H */