1 /** 2 * Copyright © 2017 IBM Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include <phosphor-logging/log.hpp> 17 #include <phosphor-logging/elog.hpp> 18 #include <xyz/openbmc_project/Sensor/Device/error.hpp> 19 #include <xyz/openbmc_project/Control/Device/error.hpp> 20 #include <xyz/openbmc_project/Power/Fault/error.hpp> 21 #include "elog-errors.hpp" 22 #include "power_supply.hpp" 23 #include "pmbus.hpp" 24 #include "utility.hpp" 25 26 using namespace phosphor::logging; 27 using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error; 28 using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error; 29 using namespace sdbusplus::xyz::openbmc_project::Power::Fault::Error; 30 31 namespace witherspoon 32 { 33 namespace power 34 { 35 namespace psu 36 { 37 38 39 void PowerSupply::analyze() 40 { 41 using namespace witherspoon::pmbus; 42 43 try 44 { 45 auto curUVFault = pmbusIntf.readBit(VIN_UV_FAULT, Type::Hwmon); 46 //TODO: 3 consecutive reads should be performed. 47 // If 3 consecutive reads are seen, log the fault. 48 // Driver gives cached value, read once a second. 49 // increment for fault on, decrement for fault off, to deglitch. 50 // If count reaches 3, we have fault. If count reaches 0, fault is 51 // cleared. 52 53 //TODO: INPUT FAULT or WARNING bit to check from STATUS_WORD 54 // pmbus-core update to read high byte of STATUS_WORD? 55 56 if ((curUVFault != vinUVFault) || inputFault) 57 { 58 if (curUVFault) 59 { 60 //FIXME - metadata 61 report<PowerSupplyUnderVoltageFault>(); 62 vinUVFault = true; 63 } 64 else 65 { 66 log<level::INFO>("VIN_UV_FAULT cleared"); 67 vinUVFault = false; 68 } 69 } 70 } 71 catch (ReadFailure& e) 72 { 73 if (!readFailLogged) 74 { 75 commit<ReadFailure>(); 76 readFailLogged = true; 77 // TODO - Need to reset that to false at start of power on, or 78 // presence change. 79 } 80 } 81 82 return; 83 } 84 85 void PowerSupply::clearFaults() 86 { 87 //TODO - Clear faults at pre-poweron. 88 return; 89 } 90 91 } 92 } 93 } 94