Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 1 | #include "power_supply.hpp" |
| 2 | |
| 3 | #include "types.hpp" |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 4 | #include "util.hpp" |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 5 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 6 | #include <xyz/openbmc_project/Common/Device/error.hpp> |
| 7 | |
| 8 | namespace phosphor::power::psu |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 9 | { |
| 10 | |
| 11 | using namespace phosphor::logging; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 12 | using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error; |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 13 | |
| 14 | void PowerSupply::updatePresence() |
| 15 | { |
| 16 | try |
| 17 | { |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 18 | present = getPresence(bus, inventoryPath); |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 19 | } |
| 20 | catch (const sdbusplus::exception::SdBusError& e) |
| 21 | { |
| 22 | // Relying on property change or interface added to retry. |
| 23 | // Log an informational trace to the journal. |
| 24 | log<level::INFO>("D-Bus property access failure exception"); |
| 25 | } |
| 26 | } |
| 27 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 28 | void PowerSupply::analyze() |
| 29 | { |
| 30 | using namespace phosphor::pmbus; |
| 31 | |
| 32 | if (present) |
| 33 | { |
| 34 | try |
| 35 | { |
| 36 | auto statusWord{pmbusIntf->read(STATUS_WORD, Type::Debug)}; |
| 37 | |
| 38 | if (statusWord) |
| 39 | { |
| 40 | if (statusWord & status_word::INPUT_FAULT_WARN) |
| 41 | { |
| 42 | if (!inputFault) |
| 43 | { |
| 44 | log<level::INFO>( |
| 45 | "INPUT fault", |
| 46 | entry("STATUS_WORD=0x%04X", |
| 47 | static_cast<uint16_t>(statusWord))); |
| 48 | } |
| 49 | |
| 50 | faultFound = true; |
| 51 | inputFault = true; |
| 52 | } |
| 53 | |
| 54 | if (statusWord & status_word::MFR_SPECIFIC_FAULT) |
| 55 | { |
| 56 | if (!mfrFault) |
| 57 | { |
| 58 | log<level::INFO>( |
| 59 | "MFRSPECIFIC fault", |
| 60 | entry("STATUS_WORD=0x%04X", |
| 61 | static_cast<uint16_t>(statusWord))); |
| 62 | } |
| 63 | faultFound = true; |
| 64 | mfrFault = true; |
| 65 | } |
| 66 | |
| 67 | if (statusWord & status_word::VIN_UV_FAULT) |
| 68 | { |
| 69 | if (!vinUVFault) |
| 70 | { |
| 71 | log<level::INFO>( |
| 72 | "VIN_UV fault", |
| 73 | entry("STATUS_WORD=0x%04X", |
| 74 | static_cast<uint16_t>(statusWord))); |
| 75 | } |
| 76 | |
| 77 | faultFound = true; |
| 78 | vinUVFault = true; |
| 79 | } |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | faultFound = false; |
| 84 | inputFault = false; |
| 85 | mfrFault = false; |
| 86 | vinUVFault = false; |
| 87 | } |
| 88 | } |
| 89 | catch (ReadFailure& e) |
| 90 | { |
| 91 | phosphor::logging::commit<ReadFailure>(); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
Brandon Wyman | aed1f75 | 2019-11-25 18:10:52 -0600 | [diff] [blame] | 96 | void PowerSupply::inventoryChanged(sdbusplus::message::message& msg) |
| 97 | { |
| 98 | std::string msgSensor; |
| 99 | std::map<std::string, sdbusplus::message::variant<uint32_t, bool>> msgData; |
| 100 | msg.read(msgSensor, msgData); |
| 101 | |
| 102 | // Check if it was the Present property that changed. |
| 103 | auto valPropMap = msgData.find(PRESENT_PROP); |
| 104 | if (valPropMap != msgData.end()) |
| 105 | { |
| 106 | if (std::get<bool>(valPropMap->second)) |
| 107 | { |
| 108 | present = true; |
| 109 | clearFaults(); |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | present = false; |
| 114 | |
| 115 | // Clear out the now outdated inventory properties |
| 116 | updateInventory(); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 121 | } // namespace phosphor::power::psu |