blob: 8dd4c3eafd1243d42b67e143e65b8d073bd1d984 [file] [log] [blame]
Brandon Wyman24e422f2017-07-25 19:40:14 -05001/**
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 */
Brandon Wyman442035f2017-08-08 15:58:45 -050016#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"
Brandon Wyman24e422f2017-07-25 19:40:14 -050022#include "power_supply.hpp"
Brandon Wyman442035f2017-08-08 15:58:45 -050023#include "pmbus.hpp"
24#include "utility.hpp"
25
26using namespace phosphor::logging;
27using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
28using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error;
29using namespace sdbusplus::xyz::openbmc_project::Power::Fault::Error;
Brandon Wyman24e422f2017-07-25 19:40:14 -050030
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050031namespace witherspoon
Brandon Wyman24e422f2017-07-25 19:40:14 -050032{
33namespace power
34{
35namespace psu
36{
37
Brandon Wyman442035f2017-08-08 15:58:45 -050038
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050039void PowerSupply::analyze()
40{
Brandon Wyman442035f2017-08-08 15:58:45 -050041 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
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050082 return;
83}
84
85void PowerSupply::clearFaults()
86{
Brandon Wyman442035f2017-08-08 15:58:45 -050087 //TODO - Clear faults at pre-poweron.
Brandon Wyman1db9a9e2017-07-26 18:50:22 -050088 return;
89}
90
Brandon Wyman24e422f2017-07-25 19:40:14 -050091}
92}
93}