1*71d7fe43SShawn McCarney /**
2*71d7fe43SShawn McCarney  * Copyright © 2024 IBM Corporation
3*71d7fe43SShawn McCarney  *
4*71d7fe43SShawn McCarney  * Licensed under the Apache License, Version 2.0 (the "License");
5*71d7fe43SShawn McCarney  * you may not use this file except in compliance with the License.
6*71d7fe43SShawn McCarney  * You may obtain a copy of the License at
7*71d7fe43SShawn McCarney  *
8*71d7fe43SShawn McCarney  *     http://www.apache.org/licenses/LICENSE-2.0
9*71d7fe43SShawn McCarney  *
10*71d7fe43SShawn McCarney  * Unless required by applicable law or agreed to in writing, software
11*71d7fe43SShawn McCarney  * distributed under the License is distributed on an "AS IS" BASIS,
12*71d7fe43SShawn McCarney  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*71d7fe43SShawn McCarney  * See the License for the specific language governing permissions and
14*71d7fe43SShawn McCarney  * limitations under the License.
15*71d7fe43SShawn McCarney  */
16*71d7fe43SShawn McCarney 
17*71d7fe43SShawn McCarney #include "ucd90x_device.hpp"
18*71d7fe43SShawn McCarney 
19*71d7fe43SShawn McCarney #include "pmbus.hpp"
20*71d7fe43SShawn McCarney 
21*71d7fe43SShawn McCarney #include <exception>
22*71d7fe43SShawn McCarney #include <format>
23*71d7fe43SShawn McCarney #include <stdexcept>
24*71d7fe43SShawn McCarney 
25*71d7fe43SShawn McCarney namespace phosphor::power::sequencer
26*71d7fe43SShawn McCarney {
27*71d7fe43SShawn McCarney 
28*71d7fe43SShawn McCarney using namespace pmbus;
29*71d7fe43SShawn McCarney 
getMfrStatus()30*71d7fe43SShawn McCarney uint64_t UCD90xDevice::getMfrStatus()
31*71d7fe43SShawn McCarney {
32*71d7fe43SShawn McCarney     uint64_t value{0};
33*71d7fe43SShawn McCarney     try
34*71d7fe43SShawn McCarney     {
35*71d7fe43SShawn McCarney         std::string fileName{"mfr_status"};
36*71d7fe43SShawn McCarney         value = pmbusInterface->read(fileName, Type::HwmonDeviceDebug);
37*71d7fe43SShawn McCarney     }
38*71d7fe43SShawn McCarney     catch (const std::exception& e)
39*71d7fe43SShawn McCarney     {
40*71d7fe43SShawn McCarney         throw std::runtime_error{std::format(
41*71d7fe43SShawn McCarney             "Unable to read MFR_STATUS for device {}: {}", name, e.what())};
42*71d7fe43SShawn McCarney     }
43*71d7fe43SShawn McCarney     return value;
44*71d7fe43SShawn McCarney }
45*71d7fe43SShawn McCarney 
storePgoodFaultDebugData(Services & services,const std::vector<int> & gpioValues,std::map<std::string,std::string> & additionalData)46*71d7fe43SShawn McCarney void UCD90xDevice::storePgoodFaultDebugData(
47*71d7fe43SShawn McCarney     Services& services, const std::vector<int>& gpioValues,
48*71d7fe43SShawn McCarney     std::map<std::string, std::string>& additionalData)
49*71d7fe43SShawn McCarney {
50*71d7fe43SShawn McCarney     // Store manufacturer-specific MFR_STATUS command value
51*71d7fe43SShawn McCarney     try
52*71d7fe43SShawn McCarney     {
53*71d7fe43SShawn McCarney         uint64_t value = getMfrStatus();
54*71d7fe43SShawn McCarney         services.logInfoMsg(
55*71d7fe43SShawn McCarney             std::format("Device {} MFR_STATUS: {:#014x}", name, value));
56*71d7fe43SShawn McCarney         additionalData.emplace("MFR_STATUS", std::format("{:#014x}", value));
57*71d7fe43SShawn McCarney     }
58*71d7fe43SShawn McCarney     catch (...)
59*71d7fe43SShawn McCarney     {
60*71d7fe43SShawn McCarney         // Ignore error; don't interrupt pgood fault handling
61*71d7fe43SShawn McCarney     }
62*71d7fe43SShawn McCarney 
63*71d7fe43SShawn McCarney     // Call parent class method to store standard data
64*71d7fe43SShawn McCarney     PMBusDriverDevice::storePgoodFaultDebugData(services, gpioValues,
65*71d7fe43SShawn McCarney                                                 additionalData);
66*71d7fe43SShawn McCarney }
67*71d7fe43SShawn McCarney 
68*71d7fe43SShawn McCarney } // namespace phosphor::power::sequencer
69