Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 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 <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 | |
| 26 | namespace witherspoon |
| 27 | { |
| 28 | namespace power |
| 29 | { |
| 30 | |
| 31 | using namespace std::string_literals; |
| 32 | |
Matt Spinler | 1e36569 | 2017-08-21 14:43:55 -0500 | [diff] [blame] | 33 | const auto CLEAR_LOGGED_FAULTS = "clear_logged_faults"s; |
| 34 | |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 35 | const auto DEVICE_NAME = "UCD90160"s; |
| 36 | const auto DRIVER_NAME = "ucd9000"s; |
| 37 | |
| 38 | using namespace pmbus; |
| 39 | using namespace phosphor::logging; |
| 40 | using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error; |
| 41 | using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error; |
| 42 | using namespace sdbusplus::xyz::openbmc_project::Power::Fault::Error; |
| 43 | |
| 44 | UCD90160::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 | |
| 53 | void 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 | |
| 78 | void 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 | |
| 97 | void UCD90160::clearFaults() |
| 98 | { |
Matt Spinler | 1e36569 | 2017-08-21 14:43:55 -0500 | [diff] [blame] | 99 | 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 Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | bool UCD90160::checkVOUTFaults() |
| 115 | { |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | bool UCD90160::checkPGOODFaults(bool polling) |
| 120 | { |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | void UCD90160::createPowerFaultLog() |
| 125 | { |
| 126 | |
| 127 | } |
| 128 | |
| 129 | } |
| 130 | } |