blob: 7dbabf98b39c0375fe4e8a0a09c2e180f8d6607b [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
10namespace witherspoon
11{
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 */
45 PGOODMonitor(std::unique_ptr<witherspoon::power::Device>&& d,
46 sdbusplus::bus::bus& b, const sdeventplus::Event& e,
47 std::chrono::milliseconds& t) :
48 DeviceMonitor(std::move(d), e, t),
49 bus(b)
50 {
51 }
Matt Spinlerf02daec2017-08-14 14:00:46 -050052
Matt Spinlerf0f02b92018-10-25 16:12:43 -050053 /**
54 * Analyzes the power sequencer for fails and then
55 * notifies the event loop that it can exit.
56 *
57 * The timer callback.
58 */
59 void analyze() override;
Matt Spinlerf02daec2017-08-14 14:00:46 -050060
Matt Spinlerf0f02b92018-10-25 16:12:43 -050061 /**
62 * Waits a specified amount of time for PGOOD to
63 * come on, and if it fails to come on in that time
64 * it will analyze the power sequencer for faults.
65 *
66 * It will exit after either PGOOD is asserted or
67 * the device is analyzed for faults.
68 *
69 * @return - the return value from sd_event_loop()
70 */
71 int run() override;
Matt Spinlerf02daec2017-08-14 14:00:46 -050072
Matt Spinlerf0f02b92018-10-25 16:12:43 -050073 private:
74 /**
75 * Enables the properties changed signal callback
76 * on the power object so we can tell when PGOOD
77 * comes on.
78 */
79 void startListening();
Matt Spinlerf02daec2017-08-14 14:00:46 -050080
Matt Spinlerf0f02b92018-10-25 16:12:43 -050081 /**
82 * The callback function for the properties changed
83 * signal.
84 */
85 void propertyChanged();
Matt Spinlerf02daec2017-08-14 14:00:46 -050086
Matt Spinlerf0f02b92018-10-25 16:12:43 -050087 /**
88 * Returns true if the system has been turned on
89 * but PGOOD isn't up yet.
90 */
91 bool pgoodPending();
Matt Spinlerf02daec2017-08-14 14:00:46 -050092
Matt Spinlerf0f02b92018-10-25 16:12:43 -050093 /**
94 * Used to break out of the event loop in run()
95 */
96 void exitEventLoop();
Matt Spinlerf02daec2017-08-14 14:00:46 -050097
Matt Spinlerf0f02b92018-10-25 16:12:43 -050098 /**
99 * The D-Bus object
100 */
101 sdbusplus::bus::bus& bus;
Matt Spinlerf02daec2017-08-14 14:00:46 -0500102
Matt Spinlerf0f02b92018-10-25 16:12:43 -0500103 /**
104 * The match object for the properties changed signal
105 */
106 std::unique_ptr<sdbusplus::bus::match_t> match;
Matt Spinlerf02daec2017-08-14 14:00:46 -0500107};
108
Matt Spinlerf0f02b92018-10-25 16:12:43 -0500109} // namespace power
110} // namespace witherspoon