blob: ec8e05ed3f13c66ea5762e159be54b1589eed8bc [file] [log] [blame]
Matt Spinlerf02daec2017-08-14 14:00:46 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/server.hpp>
William A. Kennington IIIe5a8b472018-10-18 00:40:04 -07005#include <sdeventplus/event.hpp>
Matt Spinlerb2d72512017-08-22 09:07:01 -05006#include "device.hpp"
Matt Spinlerb2d72512017-08-22 09:07:01 -05007#include "device_monitor.hpp"
Matt Spinlerf02daec2017-08-14 14:00:46 -05008
9namespace witherspoon
10{
11namespace power
12{
13
14/**
15 * @class PGOODMonitor
16 *
Matt Spinlerb2d72512017-08-22 09:07:01 -050017 * Monitors PGOOD and checks for errors on the power sequencer
18 * if it doesn't come on in time.
Matt Spinlerf02daec2017-08-14 14:00:46 -050019 *
20 * The run() function is designed to be called right after the
21 * power sequencer device is told to kick off a power on.
22 *
23 * Future commits will analyze the power sequencer chip for errors
24 * on a PGOOD fail.
25 */
Matt Spinlerb2d72512017-08-22 09:07:01 -050026class PGOODMonitor : public DeviceMonitor
Matt Spinlerf02daec2017-08-14 14:00:46 -050027{
28 public:
29
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;
36
37 /**
38 * Constructor
39 *
Matt Spinlerb2d72512017-08-22 09:07:01 -050040 * @param[in] d - the device to monitor
Matt Spinlerf02daec2017-08-14 14:00:46 -050041 * @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 */
Matt Spinlerb2d72512017-08-22 09:07:01 -050045 PGOODMonitor(std::unique_ptr<witherspoon::power::Device>&& d,
46 sdbusplus::bus::bus& b,
William A. Kennington IIIe5a8b472018-10-18 00:40:04 -070047 const sdeventplus::Event& e,
Matt Spinler78c5c2b2017-12-14 10:42:07 -060048 std::chrono::milliseconds& t) :
Matt Spinlerb2d72512017-08-22 09:07:01 -050049 DeviceMonitor(std::move(d), e, t),
50 bus(b)
51 {
52 }
Matt Spinlerf02daec2017-08-14 14:00:46 -050053
54 /**
Matt Spinlerb2d72512017-08-22 09:07:01 -050055 * Analyzes the power sequencer for fails and then
56 * notifies the event loop that it can exit.
Matt Spinlerf02daec2017-08-14 14:00:46 -050057 *
Matt Spinlerb2d72512017-08-22 09:07:01 -050058 * The timer callback.
Matt Spinlerf02daec2017-08-14 14:00:46 -050059 */
Matt Spinlerb2d72512017-08-22 09:07:01 -050060 void analyze() override;
Matt Spinlerf02daec2017-08-14 14:00:46 -050061
62 /**
63 * Waits a specified amount of time for PGOOD to
64 * come on, and if it fails to come on in that time
Matt Spinlerb2d72512017-08-22 09:07:01 -050065 * it will analyze the power sequencer for faults.
66 *
67 * It will exit after either PGOOD is asserted or
68 * the device is analyzed for faults.
Matt Spinlerf02daec2017-08-14 14:00:46 -050069 *
70 * @return - the return value from sd_event_loop()
71 */
Matt Spinlerb2d72512017-08-22 09:07:01 -050072 int run() override;
Matt Spinlerf02daec2017-08-14 14:00:46 -050073
74 private:
75
76 /**
77 * Enables the properties changed signal callback
78 * on the power object so we can tell when PGOOD
79 * comes on.
80 */
81 void startListening();
82
83 /**
84 * The callback function for the properties changed
85 * signal.
86 */
87 void propertyChanged();
88
89 /**
90 * Returns true if the system has been turned on
91 * but PGOOD isn't up yet.
92 */
93 bool pgoodPending();
94
95 /**
96 * Used to break out of the event loop in run()
97 */
98 void exitEventLoop();
99
100 /**
101 * The D-Bus object
102 */
103 sdbusplus::bus::bus& bus;
104
105 /**
106 * The match object for the properties changed signal
107 */
108 std::unique_ptr<sdbusplus::bus::match_t> match;
Matt Spinlerf02daec2017-08-14 14:00:46 -0500109};
110
111}
112}