Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/server.hpp> |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 5 | #include "device.hpp" |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 6 | #include "event.hpp" |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 7 | #include "device_monitor.hpp" |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 8 | #include "timer.hpp" |
| 9 | |
| 10 | namespace witherspoon |
| 11 | { |
| 12 | namespace power |
| 13 | { |
| 14 | |
| 15 | /** |
| 16 | * @class PGOODMonitor |
| 17 | * |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 18 | * Monitors PGOOD and checks for errors on the power sequencer |
| 19 | * if it doesn't come on in time. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 20 | * |
| 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 Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 27 | class PGOODMonitor : public DeviceMonitor |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 28 | { |
| 29 | public: |
| 30 | |
| 31 | PGOODMonitor() = delete; |
| 32 | ~PGOODMonitor() = default; |
| 33 | PGOODMonitor(const PGOODMonitor&) = delete; |
| 34 | PGOODMonitor& operator=(const PGOODMonitor&) = delete; |
| 35 | PGOODMonitor(PGOODMonitor&&) = delete; |
| 36 | PGOODMonitor& operator=(PGOODMonitor&&) = delete; |
| 37 | |
| 38 | /** |
| 39 | * Constructor |
| 40 | * |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 41 | * @param[in] d - the device to monitor |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 42 | * @param[in] b - D-Bus bus object |
| 43 | * @param[in] e - event object |
| 44 | * @param[in] t - time to allow PGOOD to come up |
| 45 | */ |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 46 | PGOODMonitor(std::unique_ptr<witherspoon::power::Device>&& d, |
| 47 | sdbusplus::bus::bus& b, |
| 48 | witherspoon::power::event::Event& e, |
Matt Spinler | 78c5c2b | 2017-12-14 10:42:07 -0600 | [diff] [blame] | 49 | std::chrono::milliseconds& t) : |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 50 | DeviceMonitor(std::move(d), e, t), |
| 51 | bus(b) |
| 52 | { |
| 53 | } |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 54 | |
| 55 | /** |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 56 | * Analyzes the power sequencer for fails and then |
| 57 | * notifies the event loop that it can exit. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 58 | * |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 59 | * The timer callback. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 60 | */ |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 61 | void analyze() override; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Waits a specified amount of time for PGOOD to |
| 65 | * come on, and if it fails to come on in that time |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 66 | * it will analyze the power sequencer for faults. |
| 67 | * |
| 68 | * It will exit after either PGOOD is asserted or |
| 69 | * the device is analyzed for faults. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 70 | * |
| 71 | * @return - the return value from sd_event_loop() |
| 72 | */ |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 73 | int run() override; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 74 | |
| 75 | private: |
| 76 | |
| 77 | /** |
| 78 | * Enables the properties changed signal callback |
| 79 | * on the power object so we can tell when PGOOD |
| 80 | * comes on. |
| 81 | */ |
| 82 | void startListening(); |
| 83 | |
| 84 | /** |
| 85 | * The callback function for the properties changed |
| 86 | * signal. |
| 87 | */ |
| 88 | void propertyChanged(); |
| 89 | |
| 90 | /** |
| 91 | * Returns true if the system has been turned on |
| 92 | * but PGOOD isn't up yet. |
| 93 | */ |
| 94 | bool pgoodPending(); |
| 95 | |
| 96 | /** |
| 97 | * Used to break out of the event loop in run() |
| 98 | */ |
| 99 | void exitEventLoop(); |
| 100 | |
| 101 | /** |
| 102 | * The D-Bus object |
| 103 | */ |
| 104 | sdbusplus::bus::bus& bus; |
| 105 | |
| 106 | /** |
| 107 | * The match object for the properties changed signal |
| 108 | */ |
| 109 | std::unique_ptr<sdbusplus::bus::match_t> match; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } |
| 113 | } |