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 2.9KB

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