Jim Wright | 10eb00f | 2021-07-21 12:10:38 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2021 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 17 | #include "power_control.hpp" |
| 18 | |
| 19 | #include "types.hpp" |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 20 | #include "ucd90160_monitor.hpp" |
Jim Wright | 7945dd2 | 2021-04-06 16:55:15 -0500 | [diff] [blame] | 21 | #include "ucd90320_monitor.hpp" |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 22 | |
Jim Wright | b4ad95d | 2022-03-08 17:24:01 -0600 | [diff] [blame] | 23 | #include <fmt/chrono.h> |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 24 | #include <fmt/format.h> |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 25 | #include <fmt/ranges.h> |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 26 | |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 27 | #include <phosphor-logging/elog-errors.hpp> |
| 28 | #include <phosphor-logging/elog.hpp> |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 29 | #include <phosphor-logging/log.hpp> |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 30 | #include <xyz/openbmc_project/Common/error.hpp> |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 31 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 32 | #include <exception> |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 33 | #include <vector> |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 34 | |
| 35 | using namespace phosphor::logging; |
| 36 | |
| 37 | namespace phosphor::power::sequencer |
Jim Wright | 10eb00f | 2021-07-21 12:10:38 -0500 | [diff] [blame] | 38 | { |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 39 | |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 40 | const std::vector<std::string> |
| 41 | interfaceNames({"xyz.openbmc_project.Configuration.UCD90160", |
| 42 | "xyz.openbmc_project.Configuration.UCD90320"}); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 43 | const std::string addressPropertyName = "Address"; |
| 44 | const std::string busPropertyName = "Bus"; |
| 45 | const std::string namePropertyName = "Name"; |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 46 | const std::string typePropertyName = "Type"; |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 47 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 48 | PowerControl::PowerControl(sdbusplus::bus_t& bus, |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 49 | const sdeventplus::Event& event) : |
Patrick Williams | 3fa31a7 | 2022-04-05 21:22:58 -0500 | [diff] [blame] | 50 | PowerObject{bus, POWER_OBJ_PATH, PowerObject::action::defer_emit}, |
Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 51 | bus{bus}, device{std::make_unique<PowerSequencerMonitor>(bus)}, |
| 52 | match{bus, |
| 53 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 54 | sdbusplus::bus::match::rules::sender( |
| 55 | "xyz.openbmc_project.EntityManager"), |
| 56 | std::bind(&PowerControl::interfacesAddedHandler, this, |
| 57 | std::placeholders::_1)}, |
Jim Wright | 1b63953 | 2022-11-19 17:41:33 -0600 | [diff] [blame] | 58 | pgoodWaitTimer{event, std::bind(&PowerControl::onFailureCallback, this)}, |
Jim Wright | b4ad95d | 2022-03-08 17:24:01 -0600 | [diff] [blame] | 59 | powerOnAllowedTime{std::chrono::steady_clock::now() + minimumColdStartTime}, |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 60 | timer{event, std::bind(&PowerControl::pollPgood, this), pollInterval} |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 61 | { |
| 62 | // Obtain dbus service name |
| 63 | bus.request_name(POWER_IFACE); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 64 | |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 65 | setUpDevice(); |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 66 | setUpGpio(); |
Jim Wright | 10eb00f | 2021-07-21 12:10:38 -0500 | [diff] [blame] | 67 | } |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 68 | |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 69 | void PowerControl::getDeviceProperties(const util::DbusPropertyMap& properties) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 70 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 71 | uint64_t i2cBus{0}; |
| 72 | uint64_t i2cAddress{0}; |
| 73 | std::string name; |
| 74 | std::string type; |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 75 | |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 76 | for (const auto& [property, value] : properties) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 77 | { |
| 78 | try |
| 79 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 80 | if (property == busPropertyName) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 81 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 82 | i2cBus = std::get<uint64_t>(value); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 83 | } |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 84 | else if (property == addressPropertyName) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 85 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 86 | i2cAddress = std::get<uint64_t>(value); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 87 | } |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 88 | else if (property == namePropertyName) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 89 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 90 | name = std::get<std::string>(value); |
| 91 | } |
| 92 | else if (property == typePropertyName) |
| 93 | { |
| 94 | type = std::get<std::string>(value); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 95 | } |
| 96 | } |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 97 | catch (const std::exception& e) |
| 98 | { |
| 99 | log<level::INFO>( |
| 100 | fmt::format("Error getting device properties, error: {}", |
| 101 | e.what()) |
| 102 | .c_str()); |
| 103 | } |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 104 | } |
| 105 | |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 106 | log<level::INFO>( |
| 107 | fmt::format( |
| 108 | "Found power sequencer device properties, name: {}, type: {}, bus: {} addr: {:#02x} ", |
| 109 | name, type, i2cBus, i2cAddress) |
| 110 | .c_str()); |
| 111 | |
| 112 | // Create device object |
| 113 | if (type == "UCD90320") |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 114 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 115 | device = std::make_unique<UCD90320Monitor>(bus, i2cBus, i2cAddress); |
| 116 | deviceFound = true; |
| 117 | } |
| 118 | else if (type == "UCD90160") |
| 119 | { |
| 120 | device = std::make_unique<UCD90160Monitor>(bus, i2cBus, i2cAddress); |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 121 | deviceFound = true; |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 125 | int PowerControl::getPgood() const |
| 126 | { |
| 127 | return pgood; |
| 128 | } |
| 129 | |
| 130 | int PowerControl::getPgoodTimeout() const |
| 131 | { |
| 132 | return timeout.count(); |
| 133 | } |
| 134 | |
| 135 | int PowerControl::getState() const |
| 136 | { |
| 137 | return state; |
| 138 | } |
| 139 | |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 140 | void PowerControl::interfacesAddedHandler(sdbusplus::message_t& message) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 141 | { |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 142 | // Only continue if message is valid and device has not already been found |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 143 | if (!message || deviceFound) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 144 | { |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | try |
| 149 | { |
| 150 | // Read the dbus message |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 151 | sdbusplus::message::object_path path; |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 152 | std::map<std::string, std::map<std::string, util::DbusVariant>> |
| 153 | interfaces; |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 154 | message.read(path, interfaces); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 155 | |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 156 | for (const auto& [interface, properties] : interfaces) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 157 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 158 | log<level::DEBUG>( |
| 159 | fmt::format( |
| 160 | "Interfaces added handler found path: {}, interface: {}", |
| 161 | path.str, interface) |
| 162 | .c_str()); |
| 163 | |
| 164 | // Find the device interface, if present |
| 165 | for (const auto& interfaceName : interfaceNames) |
| 166 | { |
| 167 | if (interface == interfaceName) |
| 168 | { |
| 169 | log<level::INFO>( |
| 170 | fmt::format( |
| 171 | "Interfaces added handler matched interface name: {}", |
| 172 | interfaceName) |
| 173 | .c_str()); |
| 174 | getDeviceProperties(properties); |
| 175 | } |
| 176 | } |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 177 | } |
| 178 | } |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 179 | catch (const std::exception& e) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 180 | { |
| 181 | // Error trying to read interfacesAdded message. |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 182 | log<level::INFO>( |
| 183 | fmt::format( |
| 184 | "Error trying to read interfacesAdded message, error: {}", |
| 185 | e.what()) |
| 186 | .c_str()); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
Jim Wright | 1b63953 | 2022-11-19 17:41:33 -0600 | [diff] [blame] | 190 | void PowerControl::onFailureCallback() |
| 191 | { |
| 192 | log<level::INFO>("After onFailure wait"); |
| 193 | |
| 194 | onFailure(false); |
| 195 | |
| 196 | // Power good has failed, call for chassis hard power off |
| 197 | auto method = bus.new_method_call(util::SYSTEMD_SERVICE, util::SYSTEMD_ROOT, |
| 198 | util::SYSTEMD_INTERFACE, "StartUnit"); |
| 199 | method.append(util::POWEROFF_TARGET); |
| 200 | method.append("replace"); |
| 201 | bus.call_noreply(method); |
| 202 | } |
| 203 | |
| 204 | void PowerControl::onFailure(bool timeout) |
| 205 | { |
| 206 | // Call device on failure |
| 207 | device->onFailure(timeout, powerSupplyError); |
| 208 | } |
| 209 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 210 | void PowerControl::pollPgood() |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 211 | { |
| 212 | if (inStateTransition) |
| 213 | { |
Jim Wright | 9d7d95c | 2021-11-16 11:32:23 -0600 | [diff] [blame] | 214 | // In transition between power on and off, check for timeout |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 215 | const auto now = std::chrono::steady_clock::now(); |
| 216 | if (now > pgoodTimeoutTime) |
| 217 | { |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 218 | log<level::ERR>( |
| 219 | fmt::format("Power state transition timeout, state: {}", state) |
| 220 | .c_str()); |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 221 | inStateTransition = false; |
Jim Wright | 4e25df5 | 2021-11-17 09:38:00 -0600 | [diff] [blame] | 222 | |
Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 223 | if (state) |
Jim Wright | 4e25df5 | 2021-11-17 09:38:00 -0600 | [diff] [blame] | 224 | { |
Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 225 | // Time out powering on |
Jim Wright | 1b63953 | 2022-11-19 17:41:33 -0600 | [diff] [blame] | 226 | onFailure(true); |
Jim Wright | 4e25df5 | 2021-11-17 09:38:00 -0600 | [diff] [blame] | 227 | } |
Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 228 | else |
Jim Wright | 4e25df5 | 2021-11-17 09:38:00 -0600 | [diff] [blame] | 229 | { |
Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 230 | // Time out powering off |
| 231 | std::map<std::string, std::string> additionalData{}; |
| 232 | device->logError( |
| 233 | "xyz.openbmc_project.Power.Error.PowerOffTimeout", |
| 234 | additionalData); |
Jim Wright | 4e25df5 | 2021-11-17 09:38:00 -0600 | [diff] [blame] | 235 | } |
| 236 | |
Jim Wright | 4875262 | 2022-02-28 20:37:53 -0600 | [diff] [blame] | 237 | failureFound = true; |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 238 | return; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | int pgoodState = pgoodLine.get_value(); |
| 243 | if (pgoodState != pgood) |
| 244 | { |
Jim Wright | 9d7d95c | 2021-11-16 11:32:23 -0600 | [diff] [blame] | 245 | // Power good has changed since last read |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 246 | pgood = pgoodState; |
| 247 | if (pgoodState == 0) |
| 248 | { |
| 249 | emitPowerLostSignal(); |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | emitPowerGoodSignal(); |
Jim Wright | 4875262 | 2022-02-28 20:37:53 -0600 | [diff] [blame] | 254 | // Clear any errors on the transition to power on |
Jim Wright | abd64b9 | 2022-02-11 09:56:56 -0600 | [diff] [blame] | 255 | powerSupplyError.clear(); |
Jim Wright | 4875262 | 2022-02-28 20:37:53 -0600 | [diff] [blame] | 256 | failureFound = false; |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 257 | } |
| 258 | emitPropertyChangedSignal("pgood"); |
| 259 | } |
| 260 | if (pgoodState == state) |
| 261 | { |
Jim Wright | 9d7d95c | 2021-11-16 11:32:23 -0600 | [diff] [blame] | 262 | // Power good matches requested state |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 263 | inStateTransition = false; |
| 264 | } |
Jim Wright | 4875262 | 2022-02-28 20:37:53 -0600 | [diff] [blame] | 265 | else if (!inStateTransition && (pgoodState == 0) && !failureFound) |
Jim Wright | 9d7d95c | 2021-11-16 11:32:23 -0600 | [diff] [blame] | 266 | { |
| 267 | // Not in power off state, not changing state, and power good is off |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 268 | log<level::ERR>("Chassis pgood failure"); |
Jim Wright | 1b63953 | 2022-11-19 17:41:33 -0600 | [diff] [blame] | 269 | pgoodWaitTimer.restartOnce(std::chrono::seconds(7)); |
Jim Wright | 4875262 | 2022-02-28 20:37:53 -0600 | [diff] [blame] | 270 | failureFound = true; |
Jim Wright | 9d7d95c | 2021-11-16 11:32:23 -0600 | [diff] [blame] | 271 | } |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 272 | } |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 273 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 274 | void PowerControl::setPgoodTimeout(int t) |
| 275 | { |
| 276 | if (timeout.count() != t) |
| 277 | { |
| 278 | timeout = std::chrono::seconds(t); |
| 279 | emitPropertyChangedSignal("pgood_timeout"); |
| 280 | } |
| 281 | } |
| 282 | |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 283 | void PowerControl::setPowerSupplyError(const std::string& error) |
| 284 | { |
| 285 | powerSupplyError = error; |
| 286 | } |
| 287 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 288 | void PowerControl::setState(int s) |
| 289 | { |
| 290 | if (state == s) |
| 291 | { |
| 292 | log<level::INFO>( |
| 293 | fmt::format("Power already at requested state: {}", state).c_str()); |
| 294 | return; |
| 295 | } |
Jim Wright | 209690b | 2021-11-11 14:46:42 -0600 | [diff] [blame] | 296 | if (s == 0) |
| 297 | { |
| 298 | // Wait for two seconds when powering down. This is to allow host and |
| 299 | // other BMC applications time to complete power off processing |
| 300 | std::this_thread::sleep_for(std::chrono::seconds(2)); |
| 301 | } |
Jim Wright | b4ad95d | 2022-03-08 17:24:01 -0600 | [diff] [blame] | 302 | else |
| 303 | { |
| 304 | // If minimum power off time has not passed, wait |
| 305 | if (powerOnAllowedTime > std::chrono::steady_clock::now()) |
| 306 | { |
| 307 | log<level::INFO>( |
| 308 | fmt::format( |
| 309 | "Waiting {} seconds until power on allowed", |
| 310 | std::chrono::duration_cast<std::chrono::seconds>( |
| 311 | powerOnAllowedTime - std::chrono::steady_clock::now()) |
| 312 | .count()) |
| 313 | .c_str()); |
| 314 | } |
| 315 | std::this_thread::sleep_until(powerOnAllowedTime); |
| 316 | } |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 317 | |
| 318 | log<level::INFO>(fmt::format("setState: {}", s).c_str()); |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 319 | powerControlLine.request( |
| 320 | {"phosphor-power-control", gpiod::line_request::DIRECTION_OUTPUT, 0}); |
| 321 | powerControlLine.set_value(s); |
| 322 | powerControlLine.release(); |
| 323 | |
Jim Wright | b4ad95d | 2022-03-08 17:24:01 -0600 | [diff] [blame] | 324 | if (s == 0) |
| 325 | { |
| 326 | // Set a minimum amount of time to wait before next power on |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 327 | powerOnAllowedTime = std::chrono::steady_clock::now() + |
| 328 | minimumPowerOffTime; |
Jim Wright | b4ad95d | 2022-03-08 17:24:01 -0600 | [diff] [blame] | 329 | } |
| 330 | |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 331 | pgoodTimeoutTime = std::chrono::steady_clock::now() + timeout; |
| 332 | inStateTransition = true; |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 333 | state = s; |
| 334 | emitPropertyChangedSignal("state"); |
| 335 | } |
| 336 | |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 337 | void PowerControl::setUpDevice() |
| 338 | { |
| 339 | try |
| 340 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 341 | // Check if device information is already available |
| 342 | auto objects = util::getSubTree(bus, "/", interfaceNames, 0); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 343 | |
| 344 | // Search for matching interface in returned objects |
| 345 | for (const auto& [path, services] : objects) |
| 346 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 347 | log<level::DEBUG>( |
| 348 | fmt::format("Found path: {}, services: {}", path, services) |
| 349 | .c_str()); |
| 350 | for (const auto& [service, interfaces] : services) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 351 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 352 | log<level::DEBUG>( |
| 353 | fmt::format("Found service: {}, interfaces: {}", service, |
| 354 | interfaces) |
| 355 | .c_str()); |
| 356 | for (const auto& interface : interfaces) |
| 357 | { |
| 358 | log<level::DEBUG>( |
| 359 | fmt::format("Found interface: {}", interface).c_str()); |
| 360 | // Get the properties for the device interface |
| 361 | auto properties = |
| 362 | util::getAllProperties(bus, path, interface, service); |
| 363 | |
| 364 | getDeviceProperties(properties); |
| 365 | } |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 366 | } |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 367 | } |
| 368 | } |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 369 | catch (const std::exception& e) |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 370 | { |
Jim Wright | eae2d61 | 2022-12-23 13:14:17 -0600 | [diff] [blame] | 371 | // Interface or property not found. Let the Interfaces Added |
| 372 | // callback process the information once the interfaces are added to |
| 373 | // D-Bus. |
| 374 | log<level::DEBUG>( |
| 375 | fmt::format("Error setting up device, error: {}", e.what()) |
| 376 | .c_str()); |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 380 | void PowerControl::setUpGpio() |
| 381 | { |
Jim Wright | 2d99bf7 | 2021-11-19 11:18:12 -0600 | [diff] [blame] | 382 | const std::string powerControlLineName = "power-chassis-control"; |
| 383 | const std::string pgoodLineName = "power-chassis-good"; |
| 384 | |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 385 | pgoodLine = gpiod::find_line(pgoodLineName); |
| 386 | if (!pgoodLine) |
| 387 | { |
Jim Wright | 209690b | 2021-11-11 14:46:42 -0600 | [diff] [blame] | 388 | std::string errorString{"GPIO line name not found: " + pgoodLineName}; |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 389 | log<level::ERR>(errorString.c_str()); |
| 390 | report< |
| 391 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure>(); |
| 392 | throw std::runtime_error(errorString); |
| 393 | } |
| 394 | powerControlLine = gpiod::find_line(powerControlLineName); |
| 395 | if (!powerControlLine) |
| 396 | { |
Jim Wright | 209690b | 2021-11-11 14:46:42 -0600 | [diff] [blame] | 397 | std::string errorString{"GPIO line name not found: " + |
| 398 | powerControlLineName}; |
Jim Wright | 7a5dd99 | 2021-08-31 16:56:52 -0500 | [diff] [blame] | 399 | log<level::ERR>(errorString.c_str()); |
| 400 | report< |
| 401 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure>(); |
| 402 | throw std::runtime_error(errorString); |
| 403 | } |
| 404 | |
| 405 | pgoodLine.request( |
| 406 | {"phosphor-power-control", gpiod::line_request::DIRECTION_INPUT, 0}); |
| 407 | int pgoodState = pgoodLine.get_value(); |
| 408 | pgood = pgoodState; |
| 409 | state = pgoodState; |
| 410 | log<level::INFO>(fmt::format("Pgood state: {}", pgoodState).c_str()); |
| 411 | } |
| 412 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 413 | } // namespace phosphor::power::sequencer |