Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 3 | #include "power_interface.hpp" |
| 4 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <sdbusplus/message.hpp> |
| 7 | #include <sdbusplus/server/object.hpp> |
| 8 | #include <sdeventplus/event.hpp> |
| 9 | #include <sdeventplus/utility/timer.hpp> |
| 10 | |
| 11 | #include <chrono> |
| 12 | |
| 13 | namespace phosphor::power::sequencer |
| 14 | { |
| 15 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 16 | using PowerObject = sdbusplus::server::object::object<PowerInterface>; |
| 17 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 18 | /** |
| 19 | * @class PowerControl |
| 20 | * This class implements GPIO control of power on / off, and monitoring of the |
| 21 | * chassis power good. |
| 22 | */ |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 23 | class PowerControl : public PowerObject |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 24 | { |
| 25 | public: |
| 26 | PowerControl() = delete; |
| 27 | PowerControl(const PowerControl&) = delete; |
| 28 | PowerControl& operator=(const PowerControl&) = delete; |
| 29 | PowerControl(PowerControl&&) = delete; |
| 30 | PowerControl& operator=(PowerControl&&) = delete; |
| 31 | ~PowerControl() = default; |
| 32 | |
| 33 | /** |
| 34 | * Creates a controller object for power on and off. |
| 35 | * @param[in] bus D-Bus bus object |
| 36 | * @param[in] event event object |
| 37 | */ |
| 38 | PowerControl(sdbusplus::bus::bus& bus, const sdeventplus::Event& event); |
| 39 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 40 | /** @copydoc PowerInterface::getPgood() */ |
| 41 | int getPgood() const override; |
| 42 | |
| 43 | /** @copydoc PowerInterface::getPgoodTimeout() */ |
| 44 | int getPgoodTimeout() const override; |
| 45 | |
| 46 | /** @copydoc PowerInterface::getState() */ |
| 47 | int getState() const override; |
| 48 | |
| 49 | /** @copydoc PowerInterface::setPgoodTimeout() */ |
| 50 | void setPgoodTimeout(int timeout) override; |
| 51 | |
| 52 | /** @copydoc PowerInterface::setState() */ |
| 53 | void setState(int state) override; |
| 54 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 55 | private: |
| 56 | /** |
| 57 | * The D-Bus bus object |
| 58 | */ |
| 59 | sdbusplus::bus::bus& bus; |
| 60 | |
| 61 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 62 | * Power good |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 63 | */ |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 64 | int pgood{0}; |
| 65 | |
| 66 | /** |
| 67 | * Power good timeout constant |
| 68 | */ |
| 69 | static constexpr std::chrono::seconds pgoodTimeout{ |
| 70 | std::chrono::seconds(10)}; |
| 71 | |
| 72 | /** |
| 73 | * Poll interval constant |
| 74 | */ |
| 75 | static constexpr std::chrono::milliseconds pollInterval{ |
| 76 | std::chrono::milliseconds(3000)}; |
| 77 | |
| 78 | /** |
| 79 | * Power state |
| 80 | */ |
| 81 | int state{0}; |
| 82 | |
| 83 | /** |
| 84 | * Power good timeout |
| 85 | */ |
| 86 | std::chrono::seconds timeout{pgoodTimeout}; |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * Timer to poll the pgood |
| 90 | */ |
| 91 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer; |
| 92 | |
| 93 | /** |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 94 | * Polling method for monitoring the system power good |
| 95 | */ |
| 96 | void pollPgood(); |
| 97 | }; |
| 98 | |
| 99 | } // namespace phosphor::power::sequencer |