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> |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 17 | #include <string> |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 18 | |
| 19 | namespace phosphor::power::sequencer |
| 20 | { |
| 21 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 22 | using PowerObject = sdbusplus::server::object_t<PowerInterface>; |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 23 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 24 | /** |
| 25 | * @class PowerControl |
| 26 | * This class implements GPIO control of power on / off, and monitoring of the |
| 27 | * chassis power good. |
| 28 | */ |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 29 | class PowerControl : public PowerObject |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 30 | { |
| 31 | public: |
| 32 | PowerControl() = delete; |
| 33 | PowerControl(const PowerControl&) = delete; |
| 34 | PowerControl& operator=(const PowerControl&) = delete; |
| 35 | PowerControl(PowerControl&&) = delete; |
| 36 | PowerControl& operator=(PowerControl&&) = delete; |
| 37 | ~PowerControl() = default; |
| 38 | |
| 39 | /** |
| 40 | * Creates a controller object for power on and off. |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 41 | * @param bus D-Bus bus object |
| 42 | * @param event event object |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 43 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 44 | PowerControl(sdbusplus::bus_t& bus, const sdeventplus::Event& event); |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 45 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 46 | /** @copydoc PowerInterface::getPgood() */ |
| 47 | int getPgood() const override; |
| 48 | |
| 49 | /** @copydoc PowerInterface::getPgoodTimeout() */ |
| 50 | int getPgoodTimeout() const override; |
| 51 | |
| 52 | /** @copydoc PowerInterface::getState() */ |
| 53 | int getState() const override; |
| 54 | |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 55 | /** |
| 56 | * Callback function to handle interfacesAdded D-Bus signals |
| 57 | * @param msg Expanded sdbusplus message data |
| 58 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 59 | void interfacesAddedHandler(sdbusplus::message_t& msg); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 60 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 61 | /** @copydoc PowerInterface::setPgoodTimeout() */ |
| 62 | void setPgoodTimeout(int timeout) override; |
| 63 | |
| 64 | /** @copydoc PowerInterface::setState() */ |
| 65 | void setState(int state) override; |
| 66 | |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 67 | /** @copydoc PowerInterface::setPowerSupplyError() */ |
| 68 | void setPowerSupplyError(const std::string& error) override; |
| 69 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 70 | private: |
| 71 | /** |
| 72 | * The D-Bus bus object |
| 73 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 74 | sdbusplus::bus_t& bus; |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 75 | |
| 76 | /** |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 77 | * The power sequencer device to monitor. |
| 78 | */ |
Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 79 | std::unique_ptr<PowerSequencerMonitor> device; |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * Indicates if a specific power sequencer device has already been found. |
| 83 | */ |
| 84 | bool deviceFound{false}; |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 85 | |
| 86 | /** |
Jim Wright | 4875262 | 2022-02-28 20:37:53 -0600 | [diff] [blame] | 87 | * Indicates if a failure has already been found. Cleared at power on. |
| 88 | */ |
| 89 | bool failureFound{false}; |
| 90 | |
| 91 | /** |
| 92 | * Indicates if a state transition is taking place |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 93 | */ |
| 94 | bool inStateTransition{false}; |
| 95 | |
| 96 | /** |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 97 | * The match to Entity Manager interfaces added. |
| 98 | */ |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 99 | sdbusplus::bus::match_t match; |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 100 | |
| 101 | /** |
Jim Wright | b4ad95d | 2022-03-08 17:24:01 -0600 | [diff] [blame] | 102 | * Minimum time from cold start to power on constant |
| 103 | */ |
| 104 | static constexpr std::chrono::seconds minimumColdStartTime{15}; |
| 105 | |
| 106 | /** |
| 107 | * Minimum time from power off to power on constant |
| 108 | */ |
| 109 | static constexpr std::chrono::seconds minimumPowerOffTime{25}; |
| 110 | |
| 111 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 112 | * Power good |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 113 | */ |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 114 | int pgood{0}; |
| 115 | |
| 116 | /** |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 117 | * GPIO line object for chassis power good |
| 118 | */ |
| 119 | gpiod::line pgoodLine; |
| 120 | |
| 121 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 122 | * Power good timeout constant |
| 123 | */ |
Jim Wright | b4ad95d | 2022-03-08 17:24:01 -0600 | [diff] [blame] | 124 | static constexpr std::chrono::seconds pgoodTimeout{10}; |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 125 | |
| 126 | /** |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 127 | * Point in time at which power good timeout will take place |
| 128 | */ |
| 129 | std::chrono::time_point<std::chrono::steady_clock> pgoodTimeoutTime; |
| 130 | |
| 131 | /** |
Jim Wright | 1b63953 | 2022-11-19 17:41:33 -0600 | [diff] [blame] | 132 | * Timer to wait after pgood failure. This is to allow the power supplies |
| 133 | * and other hardware time to complete failure processing. |
| 134 | */ |
| 135 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> pgoodWaitTimer; |
| 136 | |
| 137 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 138 | * Poll interval constant |
| 139 | */ |
Jim Wright | b4ad95d | 2022-03-08 17:24:01 -0600 | [diff] [blame] | 140 | static constexpr std::chrono::milliseconds pollInterval{3000}; |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 141 | |
| 142 | /** |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 143 | * GPIO line object for power on / power off control |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 144 | */ |
| 145 | gpiod::line powerControlLine; |
| 146 | |
| 147 | /** |
Jim Wright | b4ad95d | 2022-03-08 17:24:01 -0600 | [diff] [blame] | 148 | * Point in time at which minumum power off time will have passed |
| 149 | */ |
| 150 | std::chrono::time_point<std::chrono::steady_clock> powerOnAllowedTime; |
| 151 | |
| 152 | /** |
Jim Wright | 4875262 | 2022-02-28 20:37:53 -0600 | [diff] [blame] | 153 | * Power supply error. Cleared at power on. |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 154 | */ |
| 155 | std::string powerSupplyError; |
| 156 | |
| 157 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 158 | * Power state |
| 159 | */ |
| 160 | int state{0}; |
| 161 | |
| 162 | /** |
| 163 | * Power good timeout |
| 164 | */ |
| 165 | std::chrono::seconds timeout{pgoodTimeout}; |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * Timer to poll the pgood |
| 169 | */ |
| 170 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer; |
| 171 | |
| 172 | /** |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 173 | * Get the device properties |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 174 | * @param properties A map of property names and values |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 175 | */ |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 176 | void getDeviceProperties(const util::DbusPropertyMap& properties); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 177 | |
| 178 | /** |
Jim Wright | 1b63953 | 2022-11-19 17:41:33 -0600 | [diff] [blame] | 179 | * Callback to begin failure processing after observing pgood failure wait |
| 180 | */ |
| 181 | void onFailureCallback(); |
| 182 | |
| 183 | /** |
| 184 | * Begin pgood failute processing |
| 185 | * @param timeout if the failure state was determined by timing out |
| 186 | */ |
| 187 | void onFailure(bool timeout); |
| 188 | |
| 189 | /** |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 190 | * Polling method for monitoring the system power good |
| 191 | */ |
| 192 | void pollPgood(); |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 193 | |
| 194 | /** |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 195 | * Set up power sequencer device |
| 196 | */ |
| 197 | void setUpDevice(); |
| 198 | |
| 199 | /** |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 200 | * Set up GPIOs |
| 201 | */ |
| 202 | void setUpGpio(); |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | } // namespace phosphor::power::sequencer |