Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 3 | #include "device.hpp" |
| 4 | #include "device_monitor.hpp" |
| 5 | |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <sdbusplus/server.hpp> |
William A. Kennington III | e5a8b47 | 2018-10-18 00:40:04 -0700 | [diff] [blame] | 8 | #include <sdeventplus/event.hpp> |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 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 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 29 | 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 Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 36 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 37 | /** |
| 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) |
Patrick Williams | 2c4fbc4 | 2020-06-26 15:33:11 -0500 | [diff] [blame^] | 50 | {} |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 51 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 52 | /** |
| 53 | * Analyzes the power sequencer for fails and then |
| 54 | * notifies the event loop that it can exit. |
| 55 | * |
| 56 | * The timer callback. |
| 57 | */ |
| 58 | void analyze() override; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 59 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 60 | /** |
| 61 | * Waits a specified amount of time for PGOOD to |
| 62 | * come on, and if it fails to come on in that time |
| 63 | * it will analyze the power sequencer for faults. |
| 64 | * |
| 65 | * It will exit after either PGOOD is asserted or |
| 66 | * the device is analyzed for faults. |
| 67 | * |
| 68 | * @return - the return value from sd_event_loop() |
| 69 | */ |
| 70 | int run() override; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 71 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 72 | private: |
| 73 | /** |
| 74 | * Enables the properties changed signal callback |
| 75 | * on the power object so we can tell when PGOOD |
| 76 | * comes on. |
| 77 | */ |
| 78 | void startListening(); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 79 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 80 | /** |
| 81 | * The callback function for the properties changed |
| 82 | * signal. |
| 83 | */ |
| 84 | void propertyChanged(); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 85 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 86 | /** |
| 87 | * Returns true if the system has been turned on |
| 88 | * but PGOOD isn't up yet. |
| 89 | */ |
| 90 | bool pgoodPending(); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 91 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 92 | /** |
| 93 | * Used to break out of the event loop in run() |
| 94 | */ |
| 95 | void exitEventLoop(); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 96 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 97 | /** |
| 98 | * The D-Bus object |
| 99 | */ |
| 100 | sdbusplus::bus::bus& bus; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 101 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 102 | /** |
| 103 | * The match object for the properties changed signal |
| 104 | */ |
| 105 | std::unique_ptr<sdbusplus::bus::match_t> match; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 106 | }; |
| 107 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 108 | } // namespace power |
| 109 | } // namespace witherspoon |