blob: dc1b7bc21d5b6bcfc5623b5526d63d2867124858 [file] [log] [blame]
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -05001From 1a4aee6e48594cecf7e9083358d3d278f3060650 Mon Sep 17 00:00:00 2001
Brad Bishopc7d1cd92020-09-09 09:57:07 -04002From: Supreeth Venkatesh <supreeth.venkatesh@amd.com>
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -05003Date: Mon, 26 Oct 2020 19:04:15 -0500
Brad Bishopc7d1cd92020-09-09 09:57:07 -04004Subject: [PATCH 1/1] Amd power control modifications for EthanolX
5Content-Type: text/plain; charset="us-ascii"
6Content-Transfer-Encoding: 7bit
7
8This patch modifies recipes-x86 chassis manager code to support AMD
9EthanolX customer reference board.
10The configuration Json file is updated with the GPIO signals present on
11AMD EthanolX file.
12The Service file is updated to indicate this is modified version of x86
13power control suitable for AMD platforms.
14The source file is modified to remove Intel specific SIO signals and
15functions, modify it to support AMD specific GPIO signals.
16
17Further, Beep() is replaced by lighting up Fault LED, as AMD CRBs does
18not have a beeper.
19
20Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@amd.com>
21---
22 .../config/power-config-host0.json | 23 +-
23 ...nbmc_project.Chassis.Control.Power.service | 2 +-
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -050024 power-control-x86/src/power_control.cpp | 430 +++---------------
25 3 files changed, 81 insertions(+), 374 deletions(-)
Brad Bishopc7d1cd92020-09-09 09:57:07 -040026
27diff --git a/power-control-x86/config/power-config-host0.json b/power-control-x86/config/power-config-host0.json
28index 567f419..9e1a54a 100644
29--- a/power-control-x86/config/power-config-host0.json
30+++ b/power-control-x86/config/power-config-host0.json
31@@ -1,15 +1,14 @@
32 {
33- "IdButton": "ID_BUTTON",
34- "NMIButton": "NMI_BUTTON",
35- "NMIOut": "NMI_OUT",
36- "PostComplete": "POST_COMPLETE",
37- "PwrButton": "POWER_BUTTON",
38- "PwrOK": "PS_PWROK",
39- "PwrOut": "POWER_OUT",
40- "RstButton": "RESET_BUTTON",
41- "RstOut": "RESET_OUT",
42- "SIOOnCtl": "SIO_ONCONTROL",
43- "SIOPwrGd": "SIO_POWER_GOOD",
44- "SIOS5": "SIO_S5"
45+ "IdButton": "CHASSIS_ID_BTN",
46+ "NMIButton": "MON_P0_NMI_BTN",
47+ "NMIOut": "ASSERT_NMI_BTN",
48+ "PostComplete": "MON_PWROK",
49+ "PwrButton": "MON_P0_PWR_BTN",
50+ "PwrOK": "MON_P0_PWR_GOOD",
51+ "PwrOut": "ASSERT_PWR_BTN",
52+ "RstButton": "MON_P0_RST_BTN",
53+ "RstOut": "ASSERT_RST_BTN",
54+ "BmcReady": "ASSERT_BMC_READY",
55+ "FaultLed": "FAULT_LED"
56 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -050057
Brad Bishopc7d1cd92020-09-09 09:57:07 -040058diff --git a/power-control-x86/service_files/xyz.openbmc_project.Chassis.Control.Power.service b/power-control-x86/service_files/xyz.openbmc_project.Chassis.Control.Power.service
59index a80235e..43cf1a7 100644
60--- a/power-control-x86/service_files/xyz.openbmc_project.Chassis.Control.Power.service
61+++ b/power-control-x86/service_files/xyz.openbmc_project.Chassis.Control.Power.service
62@@ -1,5 +1,5 @@
63 [Unit]
64-Description=Intel Power Control
65+Description=Amd Power Control
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -050066
Brad Bishopc7d1cd92020-09-09 09:57:07 -040067 [Service]
68 Restart=always
69diff --git a/power-control-x86/src/power_control.cpp b/power-control-x86/src/power_control.cpp
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -050070index ab704d8..da81531 100644
Brad Bishopc7d1cd92020-09-09 09:57:07 -040071--- a/power-control-x86/src/power_control.cpp
72+++ b/power-control-x86/src/power_control.cpp
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -050073@@ -44,9 +44,8 @@ static std::string powerOutName;
Brad Bishopc7d1cd92020-09-09 09:57:07 -040074 static std::string powerOkName;
75 static std::string resetOutName;
76 static std::string nmiOutName;
77-static std::string sioPwrGoodName;
78-static std::string sioOnControlName;
79-static std::string sioS5Name;
80+static std::string bmcReadyName;
81+static std::string faultLedName;
82 static std::string postCompleteName;
83 static std::string powerButtonName;
84 static std::string resetButtonName;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -050085@@ -55,9 +54,7 @@ static std::string nmiButtonName;
86
87 static std::shared_ptr<sdbusplus::asio::dbus_interface> hostIface;
88 static std::shared_ptr<sdbusplus::asio::dbus_interface> chassisIface;
89-#ifdef CHASSIS_SYSTEM_RESET
90 static std::shared_ptr<sdbusplus::asio::dbus_interface> chassisSysIface;
91-#endif
92 static std::shared_ptr<sdbusplus::asio::dbus_interface> powerButtonIface;
93 static std::shared_ptr<sdbusplus::asio::dbus_interface> resetButtonIface;
94 static std::shared_ptr<sdbusplus::asio::dbus_interface> nmiButtonIface;
95@@ -74,18 +71,15 @@ const static constexpr int powerPulseTimeMs = 200;
Brad Bishopc7d1cd92020-09-09 09:57:07 -040096 const static constexpr int forceOffPulseTimeMs = 15000;
97 const static constexpr int resetPulseTimeMs = 500;
98 const static constexpr int powerCycleTimeMs = 5000;
99-const static constexpr int sioPowerGoodWatchdogTimeMs = 1000;
100 const static constexpr int psPowerOKWatchdogTimeMs = 8000;
101 const static constexpr int gracefulPowerOffTimeMs = 60000;
102 const static constexpr int warmResetCheckTimeMs = 500;
103-const static constexpr int buttonMaskTimeMs = 60000;
104 const static constexpr int powerOffSaveTimeMs = 7000;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500105
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400106 const static std::filesystem::path powerControlDir = "/var/lib/power-control";
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500107 const static constexpr std::string_view powerStateFile = "power-state";
108
109 static bool nmiEnabled = true;
110-static bool sioEnabled = true;
111
112 // Timers
113 // Time holding GPIOs asserted
114@@ -98,24 +92,14 @@ static boost::asio::steady_timer gracefulPowerOffTimer(io);
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400115 static boost::asio::steady_timer warmResetCheckTimer(io);
116 // Time power supply power OK assertion on power-on
117 static boost::asio::steady_timer psPowerOKWatchdogTimer(io);
118-// Time SIO power good assertion on power-on
119-static boost::asio::steady_timer sioPowerGoodWatchdogTimer(io);
120 // Time power-off state save for power loss tracking
121 static boost::asio::steady_timer powerStateSaveTimer(io);
122 // POH timer
123 static boost::asio::steady_timer pohCounterTimer(io);
124-// Time when to allow restart cause updates
125-static boost::asio::steady_timer restartCauseTimer(io);
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500126
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400127 // GPIO Lines and Event Descriptors
128 static gpiod::line psPowerOKLine;
129 static boost::asio::posix::stream_descriptor psPowerOKEvent(io);
130-static gpiod::line sioPowerGoodLine;
131-static boost::asio::posix::stream_descriptor sioPowerGoodEvent(io);
132-static gpiod::line sioOnControlLine;
133-static boost::asio::posix::stream_descriptor sioOnControlEvent(io);
134-static gpiod::line sioS5Line;
135-static boost::asio::posix::stream_descriptor sioS5Event(io);
136 static gpiod::line powerButtonLine;
137 static boost::asio::posix::stream_descriptor powerButtonEvent(io);
138 static gpiod::line resetButtonLine;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500139@@ -128,31 +112,10 @@ static gpiod::line postCompleteLine;
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400140 static boost::asio::posix::stream_descriptor postCompleteEvent(io);
141 static gpiod::line nmiOutLine;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500142
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400143-static constexpr uint8_t beepPowerFail = 8;
144-
145-static void beep(const uint8_t& beepPriority)
146-{
147- std::cerr << "Beep with priority: " << (unsigned)beepPriority << "\n";
148-
149- conn->async_method_call(
150- [](boost::system::error_code ec) {
151- if (ec)
152- {
153- std::cerr << "beep returned error with "
154- "async_method_call (ec = "
155- << ec << ")\n";
156- return;
157- }
158- },
159- "xyz.openbmc_project.BeepCode", "/xyz/openbmc_project/BeepCode",
160- "xyz.openbmc_project.BeepCode", "Beep", uint8_t(beepPriority));
161-}
162-
163 enum class PowerState
164 {
165 on,
166 waitForPSPowerOK,
167- waitForSIOPowerGood,
168 off,
169 transitionToOff,
170 gracefulTransitionToOff,
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500171@@ -172,9 +135,6 @@ static std::string getPowerStateName(PowerState state)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400172 case PowerState::waitForPSPowerOK:
173 return "Wait for Power Supply Power OK";
174 break;
175- case PowerState::waitForSIOPowerGood:
176- return "Wait for SIO Power Good";
177- break;
178 case PowerState::off:
179 return "Off";
180 break;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500181@@ -215,17 +175,12 @@ enum class Event
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400182 {
183 psPowerOKAssert,
184 psPowerOKDeAssert,
185- sioPowerGoodAssert,
186- sioPowerGoodDeAssert,
187- sioS5Assert,
188- sioS5DeAssert,
189 postCompleteAssert,
190 postCompleteDeAssert,
191 powerButtonPressed,
192 resetButtonPressed,
193 powerCycleTimerExpired,
194 psPowerOKWatchdogTimerExpired,
195- sioPowerGoodWatchdogTimerExpired,
196 gracefulPowerOffTimerExpired,
197 powerOnRequest,
198 powerOffRequest,
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500199@@ -245,18 +200,6 @@ static std::string getEventName(Event event)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400200 case Event::psPowerOKDeAssert:
201 return "power supply power OK de-assert";
202 break;
203- case Event::sioPowerGoodAssert:
204- return "SIO power good assert";
205- break;
206- case Event::sioPowerGoodDeAssert:
207- return "SIO power good de-assert";
208- break;
209- case Event::sioS5Assert:
210- return "SIO S5 assert";
211- break;
212- case Event::sioS5DeAssert:
213- return "SIO S5 de-assert";
214- break;
215 case Event::postCompleteAssert:
216 return "POST Complete assert";
217 break;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500218@@ -275,9 +218,6 @@ static std::string getEventName(Event event)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400219 case Event::psPowerOKWatchdogTimerExpired:
220 return "power supply power OK watchdog timer expired";
221 break;
222- case Event::sioPowerGoodWatchdogTimerExpired:
223- return "SIO power good watchdog timer expired";
224- break;
225 case Event::gracefulPowerOffTimerExpired:
226 return "graceful power-off timer expired";
227 break;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500228@@ -319,7 +259,6 @@ static void logEvent(const std::string_view stateHandler, const Event event)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400229 // Power state handlers
230 static void powerStateOn(const Event event);
231 static void powerStateWaitForPSPowerOK(const Event event);
232-static void powerStateWaitForSIOPowerGood(const Event event);
233 static void powerStateOff(const Event event);
234 static void powerStateTransitionToOff(const Event event);
235 static void powerStateGracefulTransitionToOff(const Event event);
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500236@@ -338,9 +277,6 @@ static std::function<void(const Event)> getPowerStateHandler(PowerState state)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400237 case PowerState::waitForPSPowerOK:
238 return powerStateWaitForPSPowerOK;
239 break;
240- case PowerState::waitForSIOPowerGood:
241- return powerStateWaitForSIOPowerGood;
242- break;
243 case PowerState::off:
244 return powerStateOff;
245 break;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500246@@ -404,7 +340,6 @@ static constexpr std::string_view getHostState(const PowerState state)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400247 return "xyz.openbmc_project.State.Host.HostState.Running";
248 break;
249 case PowerState::waitForPSPowerOK:
250- case PowerState::waitForSIOPowerGood:
251 case PowerState::off:
252 case PowerState::transitionToOff:
253 case PowerState::transitionToCycleOff:
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500254@@ -430,7 +365,6 @@ static constexpr std::string_view getChassisState(const PowerState state)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400255 return "xyz.openbmc_project.State.Chassis.PowerState.On";
256 break;
257 case PowerState::waitForPSPowerOK:
258- case PowerState::waitForSIOPowerGood:
259 case PowerState::off:
260 case PowerState::cycleOff:
261 return "xyz.openbmc_project.State.Chassis.PowerState.Off";
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500262@@ -598,7 +532,7 @@ static void systemPowerGoodFailedLog()
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400263 "MESSAGE=PowerControl: system power good failed to assert (VR failure)",
264 "PRIORITY=%i", LOG_INFO, "REDFISH_MESSAGE_ID=%s",
265 "OpenBMC.0.1.SystemPowerGoodFailed", "REDFISH_MESSAGE_ARGS=%d",
266- sioPowerGoodWatchdogTimeMs, NULL);
267+ psPowerOKWatchdogTimeMs, NULL);
268 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500269
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400270 static void psPowerOKFailedLog()
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500271@@ -1086,54 +1020,24 @@ static int setGPIOOutputForMs(const std::string& name, const int value,
272
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400273 static void powerOn()
274 {
275- setGPIOOutputForMs(power_control::powerOutName, 0, powerPulseTimeMs);
276+ setGPIOOutputForMs(power_control::powerOutName, 1, powerPulseTimeMs);
277 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500278
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400279 static void gracefulPowerOff()
280 {
281- setGPIOOutputForMs(power_control::powerOutName, 0, powerPulseTimeMs);
282+ setGPIOOutputForMs(power_control::powerOutName, 1, powerPulseTimeMs);
283 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500284
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400285 static void forcePowerOff()
286 {
287- if (setGPIOOutputForMs(power_control::powerOutName, 0,
288- forceOffPulseTimeMs) < 0)
289- {
290- return;
291- }
292+ setGPIOOutputForMs(power_control::powerOutName, 1, forceOffPulseTimeMs);
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500293
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400294- // If the force off timer expires, then the PCH power-button override
295- // failed, so attempt the Unconditional Powerdown SMBus command.
296- gpioAssertTimer.async_wait([](const boost::system::error_code ec) {
297- if (ec)
298- {
299- // operation_aborted is expected if timer is canceled before
300- // completion.
301- if (ec != boost::asio::error::operation_aborted)
302- {
303- std::cerr << "Force power off async_wait failed: "
304- << ec.message() << "\n";
305- }
306- return;
307- }
308- std::cerr << "PCH Power-button override failed. Issuing Unconditional "
309- "Powerdown SMBus command.\n";
310- const static constexpr size_t pchDevBusAddress = 3;
311- const static constexpr size_t pchDevSlaveAddress = 0x44;
312- const static constexpr size_t pchCmdReg = 0;
313- const static constexpr size_t pchPowerDownCmd = 0x02;
314- if (i2cSet(pchDevBusAddress, pchDevSlaveAddress, pchCmdReg,
315- pchPowerDownCmd) < 0)
316- {
317- std::cerr << "Unconditional Powerdown command failed! Not sure "
318- "what to do now.\n";
319- }
320- });
321+ return;
322 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500323
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400324 static void reset()
325 {
326- setGPIOOutputForMs(power_control::resetOutName, 0, resetPulseTimeMs);
327+ setGPIOOutputForMs(power_control::resetOutName, 1, resetPulseTimeMs);
328 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500329
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400330 static void gracefulPowerOffTimerStart()
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500331@@ -1378,43 +1282,16 @@ static void currentHostStateMonitor()
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400332 });
333 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500334
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400335-static void sioPowerGoodWatchdogTimerStart()
336-{
337- std::cerr << "SIO power good watchdog timer started\n";
338- sioPowerGoodWatchdogTimer.expires_after(
339- std::chrono::milliseconds(sioPowerGoodWatchdogTimeMs));
340- sioPowerGoodWatchdogTimer.async_wait(
341- [](const boost::system::error_code ec) {
342- if (ec)
343- {
344- // operation_aborted is expected if timer is canceled before
345- // completion.
346- if (ec != boost::asio::error::operation_aborted)
347- {
348- std::cerr << "SIO power good watchdog async_wait failed: "
349- << ec.message() << "\n";
350- }
351- std::cerr << "SIO power good watchdog timer canceled\n";
352- return;
353- }
354- std::cerr << "SIO power good watchdog timer completed\n";
355- sendPowerControlEvent(Event::sioPowerGoodWatchdogTimerExpired);
356- });
357-}
358-
359 static void powerStateOn(const Event event)
360 {
361+ gpiod::line line;
362 logEvent(__FUNCTION__, event);
363 switch (event)
364 {
365 case Event::psPowerOKDeAssert:
366 setPowerState(PowerState::off);
367- // DC power is unexpectedly lost, beep
368- beep(beepPowerFail);
369- break;
370- case Event::sioS5Assert:
371- setPowerState(PowerState::transitionToOff);
372- addRestartCause(RestartCause::softReset);
373+ // DC power is unexpectedly lost, Light Up fault LED
374+ power_control::setGPIOOutput(power_control::faultLedName, 1, line);
375 break;
376 case Event::postCompleteDeAssert:
377 setPowerState(PowerState::checkForWarmReset);
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500378@@ -1463,49 +1340,15 @@ static void powerStateWaitForPSPowerOK(const Event event)
379 switch (event)
380 {
381 case Event::psPowerOKAssert:
382- {
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400383 // Cancel any GPIO assertions held during the transition
384 gpioAssertTimer.cancel();
385 psPowerOKWatchdogTimer.cancel();
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500386- if (sioEnabled == true)
387- {
388- sioPowerGoodWatchdogTimerStart();
389- setPowerState(PowerState::waitForSIOPowerGood);
390- }
391- else
392- {
393- setPowerState(PowerState::on);
394- }
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400395+ setPowerState(PowerState::on);
396 break;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500397- }
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400398 case Event::psPowerOKWatchdogTimerExpired:
399 setPowerState(PowerState::off);
400 psPowerOKFailedLog();
401 break;
402- case Event::sioPowerGoodAssert:
403- psPowerOKWatchdogTimer.cancel();
404- setPowerState(PowerState::on);
405- break;
406- default:
407- phosphor::logging::log<phosphor::logging::level::INFO>(
408- "No action taken.");
409- break;
410- }
411-}
412-
413-static void powerStateWaitForSIOPowerGood(const Event event)
414-{
415- logEvent(__FUNCTION__, event);
416- switch (event)
417- {
418- case Event::sioPowerGoodAssert:
419- sioPowerGoodWatchdogTimer.cancel();
420- setPowerState(PowerState::on);
421- break;
422- case Event::sioPowerGoodWatchdogTimerExpired:
423- setPowerState(PowerState::off);
424- systemPowerGoodFailedLog();
425- break;
426 default:
427 phosphor::logging::log<phosphor::logging::level::INFO>(
428 "No action taken.");
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500429@@ -1519,21 +1362,6 @@ static void powerStateOff(const Event event)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400430 switch (event)
431 {
432 case Event::psPowerOKAssert:
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500433- {
434- if (sioEnabled == true)
435- {
436- setPowerState(PowerState::waitForSIOPowerGood);
437- }
438- else
439- {
440- setPowerState(PowerState::on);
441- }
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400442- break;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500443- }
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400444- case Event::sioS5DeAssert:
445- setPowerState(PowerState::waitForPSPowerOK);
446- break;
447- case Event::sioPowerGoodAssert:
448 setPowerState(PowerState::on);
449 break;
450 case Event::powerButtonPressed:
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500451@@ -1594,21 +1422,12 @@ static void powerStateCycleOff(const Event event)
452 switch (event)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400453 {
454 case Event::psPowerOKAssert:
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500455- {
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400456 powerCycleTimer.cancel();
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500457- if (sioEnabled == true)
458- {
459- setPowerState(PowerState::waitForSIOPowerGood);
460- }
461- else
462- {
463- setPowerState(PowerState::on);
464- }
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400465+ setPowerState(PowerState::on);
466 break;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500467- }
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400468- case Event::sioS5DeAssert:
469+ case Event::psPowerOKDeAssert:
470 powerCycleTimer.cancel();
471- setPowerState(PowerState::waitForPSPowerOK);
472+ setPowerState(PowerState::off);
473 break;
474 case Event::powerButtonPressed:
475 powerCycleTimer.cancel();
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500476@@ -1667,21 +1486,18 @@ static void powerStateGracefulTransitionToCycleOff(const Event event)
477
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400478 static void powerStateCheckForWarmReset(const Event event)
479 {
480+ gpiod::line line;
481 logEvent(__FUNCTION__, event);
482 switch (event)
483 {
484- case Event::sioS5Assert:
485- warmResetCheckTimer.cancel();
486- setPowerState(PowerState::transitionToOff);
487- break;
488 case Event::warmResetDetected:
489 setPowerState(PowerState::on);
490 break;
491 case Event::psPowerOKDeAssert:
492 warmResetCheckTimer.cancel();
493 setPowerState(PowerState::off);
494- // DC power is unexpectedly lost, beep
495- beep(beepPowerFail);
496+ // DC power is unexpectedly lost, Light up Fault LED
497+ power_control::setGPIOOutput(power_control::faultLedName, 1, line);
498 break;
499 default:
500 phosphor::logging::log<phosphor::logging::level::INFO>(
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500501@@ -1713,71 +1529,6 @@ static void psPowerOKHandler()
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400502 });
503 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500504
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400505-static void sioPowerGoodHandler()
506-{
507- gpiod::line_event gpioLineEvent = sioPowerGoodLine.event_read();
508-
509- Event powerControlEvent =
510- gpioLineEvent.event_type == gpiod::line_event::RISING_EDGE
511- ? Event::sioPowerGoodAssert
512- : Event::sioPowerGoodDeAssert;
513-
514- sendPowerControlEvent(powerControlEvent);
515- sioPowerGoodEvent.async_wait(
516- boost::asio::posix::stream_descriptor::wait_read,
517- [](const boost::system::error_code ec) {
518- if (ec)
519- {
520- std::cerr << "SIO power good handler error: " << ec.message()
521- << "\n";
522- return;
523- }
524- sioPowerGoodHandler();
525- });
526-}
527-
528-static void sioOnControlHandler()
529-{
530- gpiod::line_event gpioLineEvent = sioOnControlLine.event_read();
531-
532- bool sioOnControl =
533- gpioLineEvent.event_type == gpiod::line_event::RISING_EDGE;
534- std::cerr << "SIO_ONCONTROL value changed: " << sioOnControl << "\n";
535- sioOnControlEvent.async_wait(
536- boost::asio::posix::stream_descriptor::wait_read,
537- [](const boost::system::error_code ec) {
538- if (ec)
539- {
540- std::cerr << "SIO ONCONTROL handler error: " << ec.message()
541- << "\n";
542- return;
543- }
544- sioOnControlHandler();
545- });
546-}
547-
548-static void sioS5Handler()
549-{
550- gpiod::line_event gpioLineEvent = sioS5Line.event_read();
551-
552- Event powerControlEvent =
553- gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE
554- ? Event::sioS5Assert
555- : Event::sioS5DeAssert;
556-
557- sendPowerControlEvent(powerControlEvent);
558- sioS5Event.async_wait(boost::asio::posix::stream_descriptor::wait_read,
559- [](const boost::system::error_code ec) {
560- if (ec)
561- {
562- std::cerr << "SIO S5 handler error: "
563- << ec.message() << "\n";
564- return;
565- }
566- sioS5Handler();
567- });
568-}
569-
570 static void powerButtonHandler()
571 {
572 gpiod::line_event gpioLineEvent = powerButtonLine.event_read();
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500573@@ -1848,7 +1599,6 @@ static void resetButtonHandler()
574 });
575 }
576
577-#ifdef CHASSIS_SYSTEM_RESET
578 static constexpr auto systemdBusname = "org.freedesktop.systemd1";
579 static constexpr auto systemdPath = "/org/freedesktop/systemd1";
580 static constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager";
581@@ -1868,7 +1618,6 @@ void systemReset()
582 systemdBusname, systemdPath, systemdInterface, "StartUnit",
583 systemTargetName, "replace");
584 }
585-#endif
586
587 static void nmiSetEnablePorperty(bool value)
588 {
589@@ -2041,7 +1790,7 @@ static void postCompleteHandler()
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400590 gpiod::line_event gpioLineEvent = postCompleteLine.event_read();
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500591
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400592 bool postComplete =
593- gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE;
594+ gpioLineEvent.event_type == gpiod::line_event::RISING_EDGE;
595 if (postComplete)
596 {
597 sendPowerControlEvent(Event::postCompleteAssert);
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500598@@ -2129,19 +1878,14 @@ static int loadConfigValues()
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400599 resetOutName = data["RstOut"];
600 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500601
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400602- if (data.contains("SIOOnCtl"))
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400603+ if (data.contains("BmcReady"))
604 {
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500605- sioOnControlName = data["SIOOnCtl"];
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400606+ bmcReadyName = data["BmcReady"];
607 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500608
609- if (data.contains("SIOPwrGd"))
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400610+ if (data.contains("FaultLed"))
611 {
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500612- sioPwrGoodName = data["SIOPwrGd"];
613- }
614-
615- if (data.contains("SIOS5"))
616- {
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400617- sioS5Name = data["SIOS5"];
618+ faultLedName = data["FaultLed"];
619 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500620
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400621 return 0;
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500622@@ -2172,14 +1916,6 @@ int main(int argc, char* argv[])
623 power_control::conn->request_name(
624 "xyz.openbmc_project.Control.Host.RestartCause");
625
626- if (power_control::sioPwrGoodName.empty() ||
627- power_control::sioOnControlName.empty() ||
628- power_control::sioS5Name.empty())
629- {
630- power_control::sioEnabled = false;
631- std::cerr << "SIO control GPIOs not defined, disable SIO support.\n";
632- }
633-
634 // Request PS_PWROK GPIO events
635 if (!power_control::powerOkName.empty())
636 {
637@@ -2197,37 +1933,6 @@ int main(int argc, char* argv[])
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400638 return -1;
639 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500640
641- if (power_control::sioEnabled == true)
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400642- {
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500643- // Request SIO_POWER_GOOD GPIO events
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400644- if (!power_control::requestGPIOEvents(
645- power_control::sioPwrGoodName,
646- power_control::sioPowerGoodHandler,
647- power_control::sioPowerGoodLine,
648- power_control::sioPowerGoodEvent))
649- {
650- return -1;
651- }
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400652-
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500653- // Request SIO_ONCONTROL GPIO events
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400654- if (!power_control::requestGPIOEvents(
655- power_control::sioOnControlName,
656- power_control::sioOnControlHandler,
657- power_control::sioOnControlLine,
658- power_control::sioOnControlEvent))
659- {
660- return -1;
661- }
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400662-
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500663- // Request SIO_S5 GPIO events
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400664- if (!power_control::requestGPIOEvents(
665- power_control::sioS5Name, power_control::sioS5Handler,
666- power_control::sioS5Line, power_control::sioS5Event))
667- {
668- return -1;
669- }
670- }
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400671-
672 // Request POWER_BUTTON GPIO events
673 if (!power_control::powerButtonName.empty())
674 {
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500675@@ -2259,7 +1964,9 @@ int main(int argc, char* argv[])
676 }
677 else
678 {
679- std::cerr << "ResetButton not defined...\n";
680+ std::cerr
681+ << "resetButton name should be configured from json config file\n";
682+ return -1;
683 }
684
685 // Request NMI_BUTTON GPIO events
686@@ -2303,12 +2010,12 @@ int main(int argc, char* argv[])
687
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400688 // Initialize POWER_OUT and RESET_OUT GPIO.
689 gpiod::line line;
690- if (!power_control::setGPIOOutput(power_control::powerOutName, 1, line))
691+ if (!power_control::setGPIOOutput(power_control::powerOutName, 0, line))
692 {
693 return -1;
694 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500695
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400696- if (!power_control::setGPIOOutput(power_control::resetOutName, 1, line))
697+ if (!power_control::setGPIOOutput(power_control::resetOutName, 0, line))
698 {
699 return -1;
700 }
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500701@@ -2316,6 +2023,13 @@ int main(int argc, char* argv[])
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400702 // Release line
703 line.reset();
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500704
Brad Bishopc7d1cd92020-09-09 09:57:07 -0400705+ // DRIVE BMC_READY HIGH
706+ gpiod::line bmcReadyline;
707+ if (!power_control::setGPIOOutput(power_control::bmcReadyName, 1, bmcReadyline))
708+ {
709+ return -1;
710+ }
711+
712 // Initialize the power state
713 power_control::powerState = power_control::PowerState::off;
714 // Check power good
Supreeth Venkatesh72c03d72020-10-26 19:14:37 -0500715@@ -2444,7 +2158,6 @@ int main(int argc, char* argv[])
716
717 power_control::chassisIface->initialize();
718
719-#ifdef CHASSIS_SYSTEM_RESET
720 // Chassis System Service
721 sdbusplus::asio::object_server chassisSysServer =
722 sdbusplus::asio::object_server(power_control::conn);
723@@ -2481,7 +2194,6 @@ int main(int argc, char* argv[])
724 "LastStateChangeTime", power_control::getCurrentTimeMs());
725
726 power_control::chassisSysIface->initialize();
727-#endif
728
729 // Buttons Service
730 sdbusplus::asio::object_server buttonsServer =
731@@ -2531,51 +2243,47 @@ int main(int argc, char* argv[])
732 power_control::powerButtonIface->initialize();
733
734 // Reset Button Interface
735- if (!power_control::resetButtonName.empty())
736- {
737- power_control::resetButtonIface = buttonsServer.add_interface(
738- "/xyz/openbmc_project/chassis/buttons/reset",
739- "xyz.openbmc_project.Chassis.Buttons");
740+ power_control::resetButtonIface = buttonsServer.add_interface(
741+ "/xyz/openbmc_project/chassis/buttons/reset",
742+ "xyz.openbmc_project.Chassis.Buttons");
743
744- power_control::resetButtonIface->register_property(
745- "ButtonMasked", false, [](const bool requested, bool& current) {
746- if (requested)
747+ power_control::resetButtonIface->register_property(
748+ "ButtonMasked", false, [](const bool requested, bool& current) {
749+ if (requested)
750+ {
751+ if (power_control::resetButtonMask)
752 {
753- if (power_control::resetButtonMask)
754- {
755- return 1;
756- }
757- if (!power_control::setGPIOOutput(
758- power_control::resetOutName, 1,
759- power_control::resetButtonMask))
760- {
761- throw std::runtime_error("Failed to request GPIO");
762- return 0;
763- }
764- std::cerr << "Reset Button Masked.\n";
765+ return 1;
766 }
767- else
768+ if (!power_control::setGPIOOutput(
769+ power_control::resetOutName, 1,
770+ power_control::resetButtonMask))
771 {
772- if (!power_control::resetButtonMask)
773- {
774- return 1;
775- }
776- std::cerr << "Reset Button Un-masked\n";
777- power_control::resetButtonMask.reset();
778+ throw std::runtime_error("Failed to request GPIO");
779+ return 0;
780 }
781- // Update the mask setting
782- current = requested;
783- return 1;
784- });
785+ std::cerr << "Reset Button Masked.\n";
786+ }
787+ else
788+ {
789+ if (!power_control::resetButtonMask)
790+ {
791+ return 1;
792+ }
793+ std::cerr << "Reset Button Un-masked\n";
794+ power_control::resetButtonMask.reset();
795+ }
796+ // Update the mask setting
797+ current = requested;
798+ return 1;
799+ });
800
801- // Check reset button state
802- bool resetButtonPressed =
803- power_control::resetButtonLine.get_value() == 0;
804- power_control::resetButtonIface->register_property("ButtonPressed",
805- resetButtonPressed);
806+ // Check reset button state
807+ bool resetButtonPressed = power_control::resetButtonLine.get_value() == 0;
808+ power_control::resetButtonIface->register_property("ButtonPressed",
809+ resetButtonPressed);
810
811- power_control::resetButtonIface->initialize();
812- }
813+ power_control::resetButtonIface->initialize();
814
815 if (power_control::nmiButtonLine)
816 {
817--
Brad Bishopc7d1cd92020-09-09 09:57:07 -04008182.17.1
819