blob: 4359074d0820efe8724b052d0e4fd57a778bd698 [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 Wright7a5dd992021-08-31 16:56:52 -05005#include <gpiod.hpp>
Jim Wright539b6082021-08-02 14:50:23 -05006#include <sdbusplus/bus.hpp>
7#include <sdbusplus/message.hpp>
8#include <sdbusplus/server/object.hpp>
Jim Wright7a5dd992021-08-31 16:56:52 -05009#include <sdeventplus/clock.hpp>
Jim Wright539b6082021-08-02 14:50:23 -050010#include <sdeventplus/event.hpp>
11#include <sdeventplus/utility/timer.hpp>
12
13#include <chrono>
14
15namespace phosphor::power::sequencer
16{
17
Jim Wright22318a32021-08-27 15:56:09 -050018using PowerObject = sdbusplus::server::object::object<PowerInterface>;
19
Jim Wright539b6082021-08-02 14:50:23 -050020/**
21 * @class PowerControl
22 * This class implements GPIO control of power on / off, and monitoring of the
23 * chassis power good.
24 */
Jim Wright22318a32021-08-27 15:56:09 -050025class PowerControl : public PowerObject
Jim Wright539b6082021-08-02 14:50:23 -050026{
27 public:
28 PowerControl() = delete;
29 PowerControl(const PowerControl&) = delete;
30 PowerControl& operator=(const PowerControl&) = delete;
31 PowerControl(PowerControl&&) = delete;
32 PowerControl& operator=(PowerControl&&) = delete;
33 ~PowerControl() = default;
34
35 /**
36 * Creates a controller object for power on and off.
37 * @param[in] bus D-Bus bus object
38 * @param[in] event event object
39 */
40 PowerControl(sdbusplus::bus::bus& bus, const sdeventplus::Event& event);
41
Jim Wright22318a32021-08-27 15:56:09 -050042 /** @copydoc PowerInterface::getPgood() */
43 int getPgood() const override;
44
45 /** @copydoc PowerInterface::getPgoodTimeout() */
46 int getPgoodTimeout() const override;
47
48 /** @copydoc PowerInterface::getState() */
49 int getState() const override;
50
51 /** @copydoc PowerInterface::setPgoodTimeout() */
52 void setPgoodTimeout(int timeout) override;
53
54 /** @copydoc PowerInterface::setState() */
55 void setState(int state) override;
56
Jim Wright539b6082021-08-02 14:50:23 -050057 private:
58 /**
59 * The D-Bus bus object
60 */
61 sdbusplus::bus::bus& bus;
62
63 /**
Jim Wright7a5dd992021-08-31 16:56:52 -050064 * Indicates if a state transistion is taking place
65 */
66 bool inStateTransition{false};
67
68 /**
Jim Wright22318a32021-08-27 15:56:09 -050069 * Power good
Jim Wright539b6082021-08-02 14:50:23 -050070 */
Jim Wright22318a32021-08-27 15:56:09 -050071 int pgood{0};
72
73 /**
Jim Wright7a5dd992021-08-31 16:56:52 -050074 * GPIO line object for chassis power good
75 */
76 gpiod::line pgoodLine;
77
78 /**
Jim Wright22318a32021-08-27 15:56:09 -050079 * Power good timeout constant
80 */
81 static constexpr std::chrono::seconds pgoodTimeout{
82 std::chrono::seconds(10)};
83
84 /**
Jim Wright7a5dd992021-08-31 16:56:52 -050085 * Point in time at which power good timeout will take place
86 */
87 std::chrono::time_point<std::chrono::steady_clock> pgoodTimeoutTime;
88
89 /**
Jim Wright22318a32021-08-27 15:56:09 -050090 * Poll interval constant
91 */
92 static constexpr std::chrono::milliseconds pollInterval{
93 std::chrono::milliseconds(3000)};
94
95 /**
Jim Wright7a5dd992021-08-31 16:56:52 -050096 * GPIO line object for power-on / power-off control
97 */
98 gpiod::line powerControlLine;
99
100 /**
Jim Wright22318a32021-08-27 15:56:09 -0500101 * Power state
102 */
103 int state{0};
104
105 /**
106 * Power good timeout
107 */
108 std::chrono::seconds timeout{pgoodTimeout};
Jim Wright539b6082021-08-02 14:50:23 -0500109
110 /**
111 * Timer to poll the pgood
112 */
113 sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer;
114
115 /**
Jim Wright539b6082021-08-02 14:50:23 -0500116 * Polling method for monitoring the system power good
117 */
118 void pollPgood();
Jim Wright7a5dd992021-08-31 16:56:52 -0500119
120 /**
121 * Set up GPIOs
122 */
123 void setUpGpio();
Jim Wright539b6082021-08-02 14:50:23 -0500124};
125
126} // namespace phosphor::power::sequencer