blob: 7a69a646de3b6eb9e80d7c2c7024b544f2bcb354 [file] [log] [blame]
Matt Spinlerb54357f2017-08-21 14:38:54 -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 */
16#include <map>
17#include <memory>
18#include <phosphor-logging/elog.hpp>
19#include <phosphor-logging/log.hpp>
20#include <elog-errors.hpp>
21#include <xyz/openbmc_project/Sensor/Device/error.hpp>
22#include <xyz/openbmc_project/Control/Device/error.hpp>
23#include <xyz/openbmc_project/Power/Fault/error.hpp>
24#include "ucd90160.hpp"
25
26namespace witherspoon
27{
28namespace power
29{
30
31using namespace std::string_literals;
32
Matt Spinler1e365692017-08-21 14:43:55 -050033const auto CLEAR_LOGGED_FAULTS = "clear_logged_faults"s;
34
Matt Spinlerb54357f2017-08-21 14:38:54 -050035const auto DEVICE_NAME = "UCD90160"s;
36const auto DRIVER_NAME = "ucd9000"s;
37
38using namespace pmbus;
39using namespace phosphor::logging;
40using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
41using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error;
42using namespace sdbusplus::xyz::openbmc_project::Power::Fault::Error;
43
44UCD90160::UCD90160(size_t instance) :
45 Device(DEVICE_NAME, instance),
46 interface(std::get<ucd90160::pathField>(
47 deviceMap.find(instance)->second),
48 DRIVER_NAME,
49 instance)
50{
51}
52
53void UCD90160::onFailure()
54{
55 try
56 {
57 auto voutError = checkVOUTFaults();
58
59 auto pgoodError = checkPGOODFaults(false);
60
61 //Not a voltage or PGOOD fault, but we know something
62 //failed so still create an error log.
63 if (!voutError && !pgoodError)
64 {
65 createPowerFaultLog();
66 }
67 }
68 catch (ReadFailure& e)
69 {
70 if (!accessError)
71 {
72 commit<ReadFailure>();
73 accessError = true;
74 }
75 }
76}
77
78void UCD90160::analyze()
79{
80 try
81 {
82 //Note: Voltage faults are always fatal, so they just
83 //need to be analyzed in onFailure().
84
85 checkPGOODFaults(true);
86 }
87 catch (ReadFailure& e)
88 {
89 if (!accessError)
90 {
91 commit<ReadFailure>();
92 accessError = true;
93 }
94 }
95}
96
97void UCD90160::clearFaults()
98{
Matt Spinler1e365692017-08-21 14:43:55 -050099 try
100 {
101 interface.write(CLEAR_LOGGED_FAULTS, 1, Type::Base);
102 }
103 catch (WriteFailure& e)
104 {
105 if (!accessError)
106 {
107 log<level::ERR>("UCD90160 clear logged faults command failed");
108 commit<WriteFailure>();
109 accessError = true;
110 }
111 }
Matt Spinlerb54357f2017-08-21 14:38:54 -0500112}
113
114bool UCD90160::checkVOUTFaults()
115{
116 return false;
117}
118
119bool UCD90160::checkPGOODFaults(bool polling)
120{
121 return false;
122}
123
124void UCD90160::createPowerFaultLog()
125{
126
127}
128
129}
130}