blob: 248431a608cf096b1b51bb0094b720deee46c78c [file] [log] [blame]
Jim Wright539b6082021-08-02 14:50:23 -05001#pragma once
2
Jim Wright22318a32021-08-27 15:56:09 -05003#include "power_interface.hpp"
4
Jim Wright539b6082021-08-02 14:50:23 -05005#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
13namespace phosphor::power::sequencer
14{
15
Jim Wright22318a32021-08-27 15:56:09 -050016using PowerObject = sdbusplus::server::object::object<PowerInterface>;
17
Jim Wright539b6082021-08-02 14:50:23 -050018/**
19 * @class PowerControl
20 * This class implements GPIO control of power on / off, and monitoring of the
21 * chassis power good.
22 */
Jim Wright22318a32021-08-27 15:56:09 -050023class PowerControl : public PowerObject
Jim Wright539b6082021-08-02 14:50:23 -050024{
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 Wright22318a32021-08-27 15:56:09 -050040 /** @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 Wright539b6082021-08-02 14:50:23 -050055 private:
56 /**
57 * The D-Bus bus object
58 */
59 sdbusplus::bus::bus& bus;
60
61 /**
Jim Wright22318a32021-08-27 15:56:09 -050062 * Power good
Jim Wright539b6082021-08-02 14:50:23 -050063 */
Jim Wright22318a32021-08-27 15:56:09 -050064 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 Wright539b6082021-08-02 14:50:23 -050087
88 /**
89 * Timer to poll the pgood
90 */
91 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer;
92
93 /**
Jim Wright539b6082021-08-02 14:50:23 -050094 * Polling method for monitoring the system power good
95 */
96 void pollPgood();
97};
98
99} // namespace phosphor::power::sequencer