blob: 2d0935d389ca58a299ba62e1a8bc74e36625ca88 [file] [log] [blame]
Matt Spinlerf02daec2017-08-14 14:00:46 -05001#pragma once
2
Matt Spinlerf0f02b92018-10-25 16:12:43 -05003#include "device.hpp"
4#include "device_monitor.hpp"
5
Matt Spinlerf02daec2017-08-14 14:00:46 -05006#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server.hpp>
William A. Kennington IIIe5a8b472018-10-18 00:40:04 -07008#include <sdeventplus/event.hpp>
Matt Spinlerf02daec2017-08-14 14:00:46 -05009
Lei YUab093322019-10-09 16:43:22 +080010namespace phosphor
Matt Spinlerf02daec2017-08-14 14:00:46 -050011{
12namespace power
13{
14
15/**
16 * @class PGOODMonitor
17 *
Matt Spinlerb2d72512017-08-22 09:07:01 -050018 * Monitors PGOOD and checks for errors on the power sequencer
19 * if it doesn't come on in time.
Matt Spinlerf02daec2017-08-14 14:00:46 -050020 *
21 * The run() function is designed to be called right after the
22 * power sequencer device is told to kick off a power on.
23 *
24 * Future commits will analyze the power sequencer chip for errors
25 * on a PGOOD fail.
26 */
Matt Spinlerb2d72512017-08-22 09:07:01 -050027class PGOODMonitor : public DeviceMonitor
Matt Spinlerf02daec2017-08-14 14:00:46 -050028{
Matt Spinlerf0f02b92018-10-25 16:12:43 -050029 public:
30 PGOODMonitor() = delete;
31 ~PGOODMonitor() = default;
32 PGOODMonitor(const PGOODMonitor&) = delete;
33 PGOODMonitor& operator=(const PGOODMonitor&) = delete;
34 PGOODMonitor(PGOODMonitor&&) = delete;
35 PGOODMonitor& operator=(PGOODMonitor&&) = delete;
Matt Spinlerf02daec2017-08-14 14:00:46 -050036
Matt Spinlerf0f02b92018-10-25 16:12:43 -050037 /**
38 * Constructor
39 *
40 * @param[in] d - the device to monitor
41 * @param[in] b - D-Bus bus object
42 * @param[in] e - event object
43 * @param[in] t - time to allow PGOOD to come up
44 */
Lei YUab093322019-10-09 16:43:22 +080045 PGOODMonitor(std::unique_ptr<phosphor::power::Device>&& d,
Patrick Williams7354ce62022-07-22 19:26:56 -050046 sdbusplus::bus_t& b, const sdeventplus::Event& e,
Matt Spinlerf0f02b92018-10-25 16:12:43 -050047 std::chrono::milliseconds& t) :
Patrick Williamsf5402192024-08-16 15:20:53 -040048 DeviceMonitor(std::move(d), e, t), bus(b)
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000049 {}
Matt Spinlerf02daec2017-08-14 14:00:46 -050050
Matt Spinlerf0f02b92018-10-25 16:12:43 -050051 /**
52 * Analyzes the power sequencer for fails and then
53 * notifies the event loop that it can exit.
54 *
55 * The timer callback.
56 */
57 void analyze() override;
Matt Spinlerf02daec2017-08-14 14:00:46 -050058
Matt Spinlerf0f02b92018-10-25 16:12:43 -050059 /**
60 * Waits a specified amount of time for PGOOD to
61 * come on, and if it fails to come on in that time
62 * it will analyze the power sequencer for faults.
63 *
64 * It will exit after either PGOOD is asserted or
65 * the device is analyzed for faults.
66 *
67 * @return - the return value from sd_event_loop()
68 */
69 int run() override;
Matt Spinlerf02daec2017-08-14 14:00:46 -050070
Matt Spinlerf0f02b92018-10-25 16:12:43 -050071 private:
72 /**
73 * Enables the properties changed signal callback
74 * on the power object so we can tell when PGOOD
75 * comes on.
76 */
77 void startListening();
Matt Spinlerf02daec2017-08-14 14:00:46 -050078
Matt Spinlerf0f02b92018-10-25 16:12:43 -050079 /**
80 * The callback function for the properties changed
81 * signal.
82 */
83 void propertyChanged();
Matt Spinlerf02daec2017-08-14 14:00:46 -050084
Matt Spinlerf0f02b92018-10-25 16:12:43 -050085 /**
86 * Returns true if the system has been turned on
87 * but PGOOD isn't up yet.
88 */
89 bool pgoodPending();
Matt Spinlerf02daec2017-08-14 14:00:46 -050090
Matt Spinlerf0f02b92018-10-25 16:12:43 -050091 /**
92 * Used to break out of the event loop in run()
93 */
94 void exitEventLoop();
Matt Spinlerf02daec2017-08-14 14:00:46 -050095
Matt Spinlerf0f02b92018-10-25 16:12:43 -050096 /**
97 * The D-Bus object
98 */
Patrick Williams7354ce62022-07-22 19:26:56 -050099 sdbusplus::bus_t& bus;
Matt Spinlerf02daec2017-08-14 14:00:46 -0500100
Matt Spinlerf0f02b92018-10-25 16:12:43 -0500101 /**
102 * The match object for the properties changed signal
103 */
104 std::unique_ptr<sdbusplus::bus::match_t> match;
Matt Spinlerf02daec2017-08-14 14:00:46 -0500105};
106
Matt Spinlerf0f02b92018-10-25 16:12:43 -0500107} // namespace power
Lei YUab093322019-10-09 16:43:22 +0800108} // namespace phosphor