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" |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame^] | 4 | #include "power_sequencer_monitor.hpp" |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 5 | #include "utility.hpp" |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 6 | |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 7 | #include <gpiod.hpp> |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 9 | #include <sdbusplus/bus/match.hpp> |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 10 | #include <sdbusplus/message.hpp> |
| 11 | #include <sdbusplus/server/object.hpp> |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 12 | #include <sdeventplus/clock.hpp> |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 13 | #include <sdeventplus/event.hpp> |
| 14 | #include <sdeventplus/utility/timer.hpp> |
| 15 | |
| 16 | #include <chrono> |
| 17 | |
| 18 | namespace phosphor::power::sequencer |
| 19 | { |
| 20 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 21 | using PowerObject = sdbusplus::server::object::object<PowerInterface>; |
| 22 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 23 | /** |
| 24 | * @class PowerControl |
| 25 | * This class implements GPIO control of power on / off, and monitoring of the |
| 26 | * chassis power good. |
| 27 | */ |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 28 | class PowerControl : public PowerObject |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 29 | { |
| 30 | public: |
| 31 | PowerControl() = delete; |
| 32 | PowerControl(const PowerControl&) = delete; |
| 33 | PowerControl& operator=(const PowerControl&) = delete; |
| 34 | PowerControl(PowerControl&&) = delete; |
| 35 | PowerControl& operator=(PowerControl&&) = delete; |
| 36 | ~PowerControl() = default; |
| 37 | |
| 38 | /** |
| 39 | * Creates a controller object for power on and off. |
| 40 | * @param[in] bus D-Bus bus object |
| 41 | * @param[in] event event object |
| 42 | */ |
| 43 | PowerControl(sdbusplus::bus::bus& bus, const sdeventplus::Event& event); |
| 44 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 45 | /** @copydoc PowerInterface::getPgood() */ |
| 46 | int getPgood() const override; |
| 47 | |
| 48 | /** @copydoc PowerInterface::getPgoodTimeout() */ |
| 49 | int getPgoodTimeout() const override; |
| 50 | |
| 51 | /** @copydoc PowerInterface::getState() */ |
| 52 | int getState() const override; |
| 53 | |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 54 | /** |
| 55 | * Callback function to handle interfacesAdded D-Bus signals |
| 56 | * @param msg Expanded sdbusplus message data |
| 57 | */ |
| 58 | void interfacesAddedHandler(sdbusplus::message::message& msg); |
| 59 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 60 | /** @copydoc PowerInterface::setPgoodTimeout() */ |
| 61 | void setPgoodTimeout(int timeout) override; |
| 62 | |
| 63 | /** @copydoc PowerInterface::setState() */ |
| 64 | void setState(int state) override; |
| 65 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 66 | private: |
| 67 | /** |
| 68 | * The D-Bus bus object |
| 69 | */ |
| 70 | sdbusplus::bus::bus& bus; |
| 71 | |
| 72 | /** |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame^] | 73 | * The power sequencer device to monitor. |
| 74 | */ |
| 75 | std::unique_ptr<PowerSequencerMonitor> device; |
| 76 | |
| 77 | /** |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 78 | * Indicates if a state transistion is taking place |
| 79 | */ |
| 80 | bool inStateTransition{false}; |
| 81 | |
| 82 | /** |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 83 | * The match to Entity Manager interfaces added. |
| 84 | */ |
| 85 | std::unique_ptr<sdbusplus::bus::match_t> match; |
| 86 | |
| 87 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 88 | * Power good |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 89 | */ |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 90 | int pgood{0}; |
| 91 | |
| 92 | /** |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 93 | * GPIO line object for chassis power good |
| 94 | */ |
| 95 | gpiod::line pgoodLine; |
| 96 | |
| 97 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 98 | * Power good timeout constant |
| 99 | */ |
| 100 | static constexpr std::chrono::seconds pgoodTimeout{ |
| 101 | std::chrono::seconds(10)}; |
| 102 | |
| 103 | /** |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 104 | * Point in time at which power good timeout will take place |
| 105 | */ |
| 106 | std::chrono::time_point<std::chrono::steady_clock> pgoodTimeoutTime; |
| 107 | |
| 108 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 109 | * Poll interval constant |
| 110 | */ |
| 111 | static constexpr std::chrono::milliseconds pollInterval{ |
| 112 | std::chrono::milliseconds(3000)}; |
| 113 | |
| 114 | /** |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 115 | * GPIO line object for power-on / power-off control |
| 116 | */ |
| 117 | gpiod::line powerControlLine; |
| 118 | |
| 119 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 120 | * Power state |
| 121 | */ |
| 122 | int state{0}; |
| 123 | |
| 124 | /** |
| 125 | * Power good timeout |
| 126 | */ |
| 127 | std::chrono::seconds timeout{pgoodTimeout}; |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * Timer to poll the pgood |
| 131 | */ |
| 132 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer; |
| 133 | |
| 134 | /** |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 135 | * Get the device properties |
| 136 | * @param[in] properties A map of property names and values |
| 137 | */ |
| 138 | void getDeviceProperties(util::DbusPropertyMap& properties); |
| 139 | |
| 140 | /** |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 141 | * Polling method for monitoring the system power good |
| 142 | */ |
| 143 | void pollPgood(); |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 144 | |
| 145 | /** |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 146 | * Set up power sequencer device |
| 147 | */ |
| 148 | void setUpDevice(); |
| 149 | |
| 150 | /** |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 151 | * Set up GPIOs |
| 152 | */ |
| 153 | void setUpGpio(); |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | } // namespace phosphor::power::sequencer |