1 #pragma once
2 
3 #include "pmbus.hpp"
4 #include "types.hpp"
5 #include "util.hpp"
6 #include "utility.hpp"
7 
8 #include <gpiod.hpp>
9 #include <sdbusplus/bus/match.hpp>
10 #include <xyz/openbmc_project/Association/Definitions/server.hpp>
11 #include <xyz/openbmc_project/Sensor/Value/server.hpp>
12 #include <xyz/openbmc_project/State/Decorator/Availability/server.hpp>
13 #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
14 
15 #include <filesystem>
16 #include <stdexcept>
17 
18 namespace phosphor::power::psu
19 {
20 
21 #if IBM_VPD
22 // PMBus device driver "file name" to read for CCIN value.
23 constexpr auto CCIN = "ccin";
24 constexpr auto PART_NUMBER = "mfr_revision";
25 constexpr auto FRU_NUMBER = "mfr_model";
26 constexpr auto SERIAL_HEADER = "mfr_location";
27 constexpr auto SERIAL_NUMBER = "mfr_serial";
28 constexpr auto FW_VERSION = "fw_version";
29 
30 // The D-Bus property name to update with the CCIN value.
31 constexpr auto MODEL_PROP = "Model";
32 constexpr auto PN_PROP = "PartNumber";
33 constexpr auto SPARE_PN_PROP = "SparePartNumber";
34 constexpr auto SN_PROP = "SerialNumber";
35 constexpr auto VERSION_PROP = "Version";
36 
37 // ipzVPD Keyword sizes
38 static constexpr auto FL_KW_SIZE = 20;
39 static constexpr auto FN_KW_SIZE = 7;
40 static constexpr auto PN_KW_SIZE = 7;
41 // For IBM power supplies, the SN is 6-byte header + 6-byte serial.
42 static constexpr auto SN_KW_SIZE = 12;
43 static constexpr auto CC_KW_SIZE = 4;
44 #endif
45 
46 constexpr auto LOG_LIMIT = 3;
47 constexpr auto DEGLITCH_LIMIT = 3;
48 constexpr auto PGOOD_DEGLITCH_LIMIT = 5;
49 // Number of polls to remember that an AC fault occured. Should remain greater
50 // than PGOOD_DEGLITCH_LIMIT.
51 constexpr auto AC_FAULT_LIMIT = 6;
52 
53 constexpr auto IBMCFFPS_DD_NAME = "ibm-cffps";
54 constexpr auto ACBEL_FSG032_DD_NAME = "acbel-fsg032";
55 
56 using AvailabilityInterface =
57     sdbusplus::xyz::openbmc_project::State::Decorator::server::Availability;
58 using OperationalStatusInterface = sdbusplus::xyz::openbmc_project::State::
59     Decorator::server::OperationalStatus;
60 using AssocDefInterface =
61     sdbusplus::xyz::openbmc_project::Association::server::Definitions;
62 using SensorInterface = sdbusplus::xyz::openbmc_project::Sensor::server::Value;
63 using SensorObject = sdbusplus::server::object_t<SensorInterface>;
64 using PowerSensorObject =
65     sdbusplus::server::object_t<SensorInterface, OperationalStatusInterface,
66                                 AvailabilityInterface, AssocDefInterface>;
67 
68 using AssociationTuple = std::tuple<std::string, std::string, std::string>;
69 
70 /**
71  * @class PowerSupply
72  * Represents a PMBus power supply device.
73  */
74 class PowerSupply
75 {
76   public:
77     PowerSupply() = delete;
78     PowerSupply(const PowerSupply&) = delete;
79     PowerSupply(PowerSupply&&) = delete;
80     PowerSupply& operator=(const PowerSupply&) = delete;
81     PowerSupply& operator=(PowerSupply&&) = delete;
82     ~PowerSupply() = default;
83 
84     /**
85      * @param[in] invpath - String for inventory path to use
86      * @param[in] i2cbus - The bus number this power supply is on
87      * @param[in] i2caddr - The 16-bit I2C address of the power supply
88      * @param[in] driver - i2c driver name for power supply
89      * @param[in] gpioLineName - The gpio-line-name to read for presence. See
90      * https://github.com/openbmc/docs/blob/master/designs/device-tree-gpio-naming.md
91      * @param[in] callback - Get the power on status of the psu manager class
92      */
93     PowerSupply(sdbusplus::bus_t& bus, const std::string& invpath,
94                 std::uint8_t i2cbus, const std::uint16_t i2caddr,
95                 const std::string& driver, const std::string& gpioLineName,
96                 std::function<bool()>&& callback);
97 
98     phosphor::pmbus::PMBusBase& getPMBus()
99     {
100         return *pmbusIntf;
101     }
102 
103     GPIOInterfaceBase* getPresenceGPIO()
104     {
105         return presenceGPIO.get();
106     }
107 
108     std::string getPresenceGPIOName() const
109     {
110         if (presenceGPIO != nullptr)
111         {
112             return presenceGPIO->getName();
113         }
114         else
115         {
116             return std::string();
117         }
118     }
119 
120     /**
121      * Power supply specific function to analyze for faults/errors.
122      *
123      * Various PMBus status bits will be checked for fault conditions.
124      * If a certain fault bits are on, the appropriate error will be
125      * committed.
126      */
127     void analyze();
128 
129     /**
130      * Write PMBus ON_OFF_CONFIG
131      *
132      * This function will be called to cause the PMBus device driver to send the
133      * ON_OFF_CONFIG command. Takes one byte of data.
134      *
135      * @param[in] data - The ON_OFF_CONFIG data byte mask.
136      */
137     void onOffConfig(uint8_t data);
138 
139     /**
140      * Clears all the member variables that indicate if a fault bit was seen as
141      * on in the STATUS_WORD or STATUS_MFR_SPECIFIC response.
142      */
143     void clearFaultFlags()
144     {
145         inputFault = 0;
146         mfrFault = 0;
147         statusMFR = 0;
148         vinUVFault = 0;
149         cmlFault = 0;
150         voutOVFault = 0;
151         ioutOCFault = 0;
152         voutUVFault = 0;
153         fanFault = 0;
154         tempFault = 0;
155         pgoodFault = 0;
156         psKillFault = 0;
157         ps12VcsFault = 0;
158         psCS12VFault = 0;
159         faultLogged = false;
160     }
161 
162     /**
163      * @brief Function to specifically clear VIN_UV/OFF fault(s).
164      *
165      * The PMBus HWMON device driver has various alarm "files" to read out of
166      * sysfs. Reading those files will indicate if various alarms are active or
167      * not, and then specifically clear those faults that go with that alarm.
168      *
169      * The VIN_UV fault, indicated in STATUS_INPUT, goes with in1_lcrit_alarm.
170      * When a VIN_UV fault occurs, the "Unit Off For Insufficient Input Voltage"
171      * may also be active. Reading in1_lcrit_alarm should clear both fault bits,
172      * resulting in the corresponding fault bits in STATUS_WORD also clearing.
173      *
174      * See: https://www.kernel.org/doc/html/latest/hwmon/pmbus.html
175      */
176     void clearVinUVFault();
177 
178     /**
179      * Write PMBus CLEAR_FAULTS
180      *
181      * This function will be called in various situations in order to clear
182      * any fault status bits that may have been set, in order to start over
183      * with a clean state. Presence changes and power state changes will
184      * want to clear any faults logged.
185      */
186     void clearFaults();
187 
188     /**
189      * @brief Adds properties to the inventory.
190      *
191      * Reads the values from the device and writes them to the
192      * associated power supply D-Bus inventory object.
193      *
194      * This needs to be done on startup, and each time the presence
195      * state changes.
196      *
197      * Properties added:
198      * - Serial Number
199      * - Part Number
200      * - CCIN (Customer Card Identification Number) - added as the Model
201      * - Firmware version
202      */
203     void updateInventory();
204 
205     /**
206      * @brief Accessor function to indicate present status
207      */
208     bool isPresent() const
209     {
210         return present;
211     }
212 
213     /**
214      * @brief Returns the last read value from STATUS_WORD.
215      */
216     uint64_t getStatusWord() const
217     {
218         return statusWord;
219     }
220 
221     /**
222      * @brief Returns the last read value from STATUS_INPUT.
223      */
224     uint64_t getStatusInput() const
225     {
226         return statusInput;
227     }
228 
229     /**
230      * @brief Returns the last read value from STATUS_MFR.
231      */
232     uint64_t getMFRFault() const
233     {
234         return statusMFR;
235     }
236 
237     /**
238      * @brief Returns the last read value from STATUS_CML.
239      */
240     uint64_t getStatusCML() const
241     {
242         return statusCML;
243     }
244 
245     /**
246      * @brief Returns the last read value from STATUS_VOUT.
247      */
248     uint64_t getStatusVout() const
249     {
250         return statusVout;
251     }
252 
253     /**
254      * @brief Returns the last value read from STATUS_IOUT.
255      */
256     uint64_t getStatusIout() const
257     {
258         return statusIout;
259     }
260 
261     /**
262      * @brief Returns the last value read from STATUS_FANS_1_2.
263      */
264     uint64_t getStatusFans12() const
265     {
266         return statusFans12;
267     }
268 
269     /**
270      * @brief Returns the last value read from STATUS_TEMPERATURE.
271      */
272     uint64_t getStatusTemperature() const
273     {
274         return statusTemperature;
275     }
276 
277     /**
278      * @brief Returns true if a fault was found.
279      */
280     bool isFaulted() const
281     {
282         return (hasCommFault() || (vinUVFault >= DEGLITCH_LIMIT) ||
283                 (inputFault >= DEGLITCH_LIMIT) ||
284                 (voutOVFault >= DEGLITCH_LIMIT) ||
285                 (ioutOCFault >= DEGLITCH_LIMIT) ||
286                 (voutUVFault >= DEGLITCH_LIMIT) ||
287                 (fanFault >= DEGLITCH_LIMIT) || (tempFault >= DEGLITCH_LIMIT) ||
288                 (pgoodFault >= PGOOD_DEGLITCH_LIMIT) ||
289                 (mfrFault >= DEGLITCH_LIMIT));
290     }
291 
292     /**
293      * @brief Return whether a fault has been logged for this power supply
294      */
295     bool isFaultLogged() const
296     {
297         return faultLogged;
298     }
299 
300     /**
301      * @brief Called when a fault for this power supply has been logged.
302      */
303     void setFaultLogged()
304     {
305         faultLogged = true;
306     }
307 
308     /**
309      * @brief Returns true if INPUT fault occurred.
310      */
311     bool hasInputFault() const
312     {
313         return (inputFault >= DEGLITCH_LIMIT);
314     }
315 
316     /**
317      * @brief Returns true if MFRSPECIFIC occurred.
318      */
319     bool hasMFRFault() const
320     {
321         return (mfrFault >= DEGLITCH_LIMIT);
322     }
323 
324     /**
325      * @brief Returns true if VIN_UV_FAULT occurred.
326      */
327     bool hasVINUVFault() const
328     {
329         return (vinUVFault >= DEGLITCH_LIMIT);
330     }
331 
332     /**
333      * @brief Returns true if VOUT_OV_FAULT occurred.
334      */
335     bool hasVoutOVFault() const
336     {
337         return (voutOVFault >= DEGLITCH_LIMIT);
338     }
339 
340     /**
341      * @brief Returns true if IOUT_OC fault occurred (bit 4 STATUS_BYTE).
342      */
343     bool hasIoutOCFault() const
344     {
345         return (ioutOCFault >= DEGLITCH_LIMIT);
346     }
347 
348     /**
349      * @brief Returns true if VOUT_UV_FAULT occurred.
350      */
351     bool hasVoutUVFault() const
352     {
353         return (voutUVFault >= DEGLITCH_LIMIT);
354     }
355 
356     /**
357      *@brief Returns true if fan fault occurred.
358      */
359     bool hasFanFault() const
360     {
361         return (fanFault >= DEGLITCH_LIMIT);
362     }
363 
364     /**
365      * @brief Returns true if TEMPERATURE fault occurred.
366      */
367     bool hasTempFault() const
368     {
369         return (tempFault >= DEGLITCH_LIMIT);
370     }
371 
372     /**
373      * @brief Returns true if there is a PGood fault (PGOOD# inactive, or OFF
374      * bit on).
375      */
376     bool hasPgoodFault() const
377     {
378         return (pgoodFault >= PGOOD_DEGLITCH_LIMIT);
379     }
380 
381     /**
382      * @brief Return true if there is a PS_Kill fault.
383      */
384     bool hasPSKillFault() const
385     {
386         return (psKillFault >= DEGLITCH_LIMIT);
387     }
388 
389     /**
390      * @brief Returns true if there is a 12Vcs (standy power) fault.
391      */
392     bool hasPS12VcsFault() const
393     {
394         return (ps12VcsFault >= DEGLITCH_LIMIT);
395     }
396 
397     /**
398      * @brief Returns true if there is a 12V current-share fault.
399      */
400     bool hasPSCS12VFault() const
401     {
402         return (psCS12VFault >= DEGLITCH_LIMIT);
403     }
404 
405     /**
406      * @brief Returns true if an AC fault has occurred in the window of
407      * interest.
408      */
409     bool hasACFault() const
410     {
411         return acFault != 0;
412     }
413 
414     /**
415      * @brief Returns the device path
416      *
417      * This can be used for error call outs.
418      * Example: /sys/bus/i2c/devices/3-0068
419      */
420     const std::string getDevicePath() const
421     {
422         return pmbusIntf->path();
423     }
424 
425     /**
426      * @brief Returns this power supply's inventory path.
427      *
428      * This can be used for error call outs.
429      * Example:
430      * /xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1
431      */
432     const std::string& getInventoryPath() const
433     {
434         return inventoryPath;
435     }
436 
437     /**
438      * @brief Returns the short name (last part of inventoryPath).
439      */
440     const std::string& getShortName() const
441     {
442         return shortName;
443     }
444 
445     /**
446      * @brief Returns the firmware revision version read from the power supply
447      */
448     const std::string& getFWVersion() const
449     {
450         return fwVersion;
451     }
452 
453     /**
454      * @brief Returns the model name of the power supply
455      */
456     const std::string& getModelName() const
457     {
458         return modelName;
459     }
460 
461     /**
462      * @brief Returns true if the number of failed reads exceeds limit
463      * TODO: or CML bit on.
464      */
465     bool hasCommFault() const
466     {
467         return ((readFail >= LOG_LIMIT) || (cmlFault >= DEGLITCH_LIMIT));
468     }
469 
470     /**
471      * @brief Reads the pmbus input voltage and returns that actual voltage
472      *        reading and the calculated input voltage based on thresholds.
473      * @param[out] actualInputVoltage - The actual voltage reading, in Volts.
474      * @param[out] inputVoltage - A rounded up/down value of the actual input
475      *             voltage based on thresholds, in Volts.
476      */
477     void getInputVoltage(double& actualInputVoltage, int& inputVoltage) const;
478 
479     /**
480      * @brief Check if the PS is considered to be available or not
481      *
482      * It is unavailable if any of:
483      * - not present
484      * - input fault active
485      * - Vin UV fault active
486      * - PS KILL fault active
487      * - Iout OC fault active
488      *
489      * Other faults will, through creating error logs with callouts, already
490      * be setting the Functional property to false.
491      *
492      * On changes, the Available property is updated in the inventory.
493      */
494     void checkAvailability();
495 
496     /**
497      * @brief Returns true when INPUT_HISTORY sync is required.
498      */
499     bool isSyncHistoryRequired() const
500     {
501         return syncHistoryRequired;
502     }
503 
504     /**
505      * @brief Clears the indicator that sync required for INPUT_HISTORY.
506      *
507      * Sets variable to false to indicate that the sync is no longer required.
508      * This can be used after the PSUManager has reacted to the need for the
509      * INPUT_HISTORY data to be synchronized.
510      */
511     void clearSyncHistoryRequired()
512     {
513         syncHistoryRequired = false;
514     }
515 
516     /**
517      * @brief Puts the input voltage rating on D-Bus.
518      *
519      * The rating is like 0, 110, 220.
520      */
521     void setInputVoltageRating();
522 
523     /**
524      * @brief Returns the peak input power value if there is one,
525      *        otherwise std::nullopt.
526      */
527     std::optional<double> getPeakInputPower() const
528     {
529         std::optional<double> value;
530         if (peakInputPowerSensor)
531         {
532             value = peakInputPowerSensor->value();
533         }
534         return value;
535     }
536 
537     /**
538      * @brief Converts a Linear Format power number to an integer
539      *
540      * The PMBus spec describes a 2 byte Linear Format
541      * number that is composed of an exponent and mantissa
542      * in two's complement notation.
543      *
544      * Value = Mantissa * 2**Exponent
545      *
546      * @return double - The converted value
547      */
548     static double linearToInteger(uint16_t data);
549 
550   private:
551     /**
552      * @brief Examine STATUS_WORD for CML (communication, memory, logic fault).
553      */
554     void analyzeCMLFault();
555 
556     /**
557      * @brief Examine STATUS_WORD for INPUT bit on.
558      *
559      * "An input voltage, input current, or input power fault or warning has
560      * occurred."
561      */
562     void analyzeInputFault();
563 
564     /**
565      * @brief Examine STATUS_WORD for VOUT being set.
566      *
567      * If VOUT is on, "An output voltage fault or warning has occurred.", and
568      * VOUT_OV_FAULT is on, there is an output over-voltage fault.
569      */
570     void analyzeVoutOVFault();
571 
572     /**
573      * @brief Examine STATUS_WORD value read for IOUT_OC_FAULT.
574      *
575      * "An output overcurrent fault has occurred." If it is on, and fault not
576      * set, trace STATUS_WORD, STATUS_MFR_SPECIFIC, and STATUS_IOUT values.
577      */
578     void analyzeIoutOCFault();
579 
580     /**
581      * @brief Examines STATUS_WORD value read to see if there is a UV fault.
582      *
583      * Checks if the VOUT bit is on, indicating "An output voltage fault or
584      * warning has occurred", if it is on, but VOUT_OV_FAULT is off, it is
585      * determined to be an indication of an output under-voltage fault.
586      */
587     void analyzeVoutUVFault();
588 
589     /**
590      * @brief Examine STATUS_WORD for the fan fault/warning bit.
591      *
592      * If fanFault is not on, trace that the bit now came on, include
593      * STATUS_WORD, STATUS_MFR_SPECIFIC, and STATUS_FANS_1_2 values as well, to
594      * help with understanding what may have caused it to be set.
595      */
596     void analyzeFanFault();
597 
598     /**
599      * @brief Examine STATUS_WORD for temperature fault.
600      */
601     void analyzeTemperatureFault();
602 
603     /**
604      * @brief Examine STATUS_WORD for pgood or unit off faults.
605      */
606     void analyzePgoodFault();
607 
608     /**
609      * @brief Determine possible manufacturer-specific faults from bits in
610      * STATUS_MFR.
611      *
612      * The bits in the STATUS_MFR_SPECIFIC command response have "Manufacturer
613      * Defined" meanings. Determine which faults, if any, are present based on
614      * the power supply (device driver) type.
615      */
616     void determineMFRFault();
617 
618     /**
619      * @brief Examine STATUS_WORD value read for MFRSPECIFIC bit on.
620      *
621      * "A manufacturer specific fault or warning has occurred."
622      *
623      * If it is on, call the determineMFRFault() helper function to examine the
624      * value read from STATUS_MFR_SPECIFIC.
625      */
626     void analyzeMFRFault();
627 
628     /**
629      * @brief Analyzes the STATUS_WORD for a VIN_UV_FAULT indicator.
630      */
631     void analyzeVinUVFault();
632 
633     /**
634      * @brief Given a full inventory path, returns the last node of the path as
635      * the "short name"
636      */
637     std::string findShortName(const std::string& invPath)
638     {
639         const auto lastSlashPos = invPath.find_last_of('/');
640 
641         if ((lastSlashPos == std::string::npos) ||
642             ((lastSlashPos + 1) == invPath.size()))
643         {
644             return invPath;
645         }
646         else
647         {
648             return invPath.substr(lastSlashPos + 1);
649         }
650     }
651 
652     /**
653      * @brief Binds or unbinds the power supply device driver
654      *
655      * Called when a presence change is detected to either bind the device
656      * driver for the power supply when it is installed, or unbind the device
657      * driver when the power supply is removed.
658      *
659      * Writes <device> to <path>/bind (or unbind)
660      *
661      * @param present - when true, will bind the device driver
662      *                  when false, will unbind the device driver
663      */
664     void bindOrUnbindDriver(bool present);
665 
666     /**
667      *  @brief Updates the presence status by querying D-Bus
668      *
669      * The D-Bus inventory properties for this power supply will be read to
670      * determine if the power supply is present or not and update this
671      * object's present member variable to reflect current status.
672      **/
673     void updatePresence();
674 
675     /**
676      * @brief Updates the power supply presence by reading the GPIO line.
677      */
678     void updatePresenceGPIO();
679 
680     /**
681      * @brief Callback for inventory property changes
682      *
683      * Process change of Present property for power supply.
684      *
685      * This is used if we are watching the D-Bus properties instead of reading
686      * the GPIO presence line ourselves.
687      *
688      * @param[in]  msg - Data associated with Present change signal
689      **/
690     void inventoryChanged(sdbusplus::message_t& msg);
691 
692     /**
693      * @brief Callback for inventory property added.
694      *
695      * Process add of the interface with the Present property for power supply.
696      *
697      * This is used if we are watching the D-Bus properties instead of reading
698      * the GPIO presence line ourselves.
699      *
700      * @param[in]  msg - Data associated with Present add signal
701      **/
702     void inventoryAdded(sdbusplus::message_t& msg);
703 
704     /**
705      * @brief Reads the pmbus MFR_POUT_MAX value.
706      *
707      * "The MFR_POUT_MAX command sets or retrieves the maximum rated output
708      * power, in watts, that the unit is rated to supply."
709      *
710      * @return max_power_out value converted from string.
711      */
712     auto getMaxPowerOut() const;
713 
714     /**
715      * @brief Reads a VPD value from PMBus, correct size, and contents.
716      *
717      * If the VPD data read is not the passed in size, resize and fill with
718      * spaces. If the data contains a non-alphanumeric value, replace any of
719      * those values with spaces.
720      *
721      * @param[in] vpdName - The name of the sysfs "file" to read data from.
722      * @param[in] type - The HWMON file type to read from.
723      * @param[in] vpdSize - The expacted size of the data for this VPD/property
724      *
725      * @return A string containing the VPD data read, resized if necessary
726      */
727     auto readVPDValue(const std::string& vpdName,
728                       const phosphor::pmbus::Type& type,
729                       const std::size_t& vpdSize);
730 
731     /**
732      * @brief Retrieve PSU VPD keyword from D-Bus
733      *
734      * It retrieves PSU VPD keyword from D-Bus and assign the associated
735      * string to vpdStr.
736      * @param[in] keyword - The VPD search keyword
737      * @param[out] vpdStr - The VPD string associated with the keyword.
738      */
739     void getPsuVpdFromDbus(const std::string& keyword, std::string& vpdStr);
740 
741     /**
742      * @brief Creates the appropriate sensor D-Bus objects.
743      */
744     void setupSensors();
745 
746     /**
747      * @brief Monitors sensor values and updates D-Bus.
748      *        Called from analyze().
749      */
750     void monitorSensors();
751 
752     /**
753      * @brief Creates the peak input power sensor D-Bus object
754      *        if the PS supports it.
755      */
756     void setupInputPowerPeakSensor();
757 
758     /**
759      * @brief Monitors the peak input power sensor
760      */
761     void monitorPeakInputPowerSensor();
762 
763     /**
764      * @brief Sets any sensor objects to Available = false on D-Bus.
765      */
766     void setSensorsNotAvailable();
767 
768     /**
769      * @brief Returns the associations to create for a sensor on this
770      *        power supply.
771      */
772     std::vector<AssociationTuple> getSensorAssociations();
773 
774     /**
775      * @brief systemd bus member
776      */
777     sdbusplus::bus_t& bus;
778 
779     /**
780      * @brief D-Bus path to use for this power supply's inventory status.
781      **/
782     std::string inventoryPath;
783 
784     /**
785      * @brief The file system path used for binding the device driver.
786      */
787     const std::filesystem::path bindPath;
788 
789     /**
790      * @brief Get the power on status of the psu manager class.
791      *
792      * This is a callback method used to get the power on status of the psu
793      * manager class.
794      */
795     std::function<bool()> isPowerOn;
796 
797     /**
798      * @brief Set to true when INPUT_HISTORY sync is required.
799      *
800      * A power supply will need to synchronize its INPUT_HISTORY data with the
801      * other power supplies installed in the system when it goes from missing to
802      * present.
803      */
804     bool syncHistoryRequired{false};
805 
806     /**
807      * @brief Store the short name to avoid string processing.
808      *
809      * The short name will be something like powersupply1, the last part of the
810      * inventoryPath.
811      */
812     std::string shortName;
813 
814     /**
815      * @brief The libgpiod object for monitoring PSU presence
816      */
817     std::unique_ptr<GPIOInterfaceBase> presenceGPIO = nullptr;
818 
819     /**
820      * @brief True if the power supply is present.
821      */
822     bool present = false;
823 
824     /**
825      * @brief Power supply model name.
826      */
827     std::string modelName;
828 
829     /**
830      * @brief D-Bus match variable used to subscribe to Present property
831      * changes.
832      **/
833     std::unique_ptr<sdbusplus::bus::match_t> presentMatch;
834 
835     /**
836      * @brief D-Bus match variable used to subscribe for Present property
837      * interface added.
838      */
839     std::unique_ptr<sdbusplus::bus::match_t> presentAddedMatch;
840 
841     /**
842      * @brief Pointer to the PMBus interface
843      *
844      * Used to read or write to/from PMBus power supply devices.
845      */
846     std::unique_ptr<phosphor::pmbus::PMBusBase> pmbusIntf = nullptr;
847 
848     /**
849      * @brief Stored copy of the firmware version/revision string
850      */
851     std::string fwVersion;
852 
853     /**
854      * @brief The string to pass in for binding the device driver.
855      */
856     std::string bindDevice;
857 
858     /**
859      * @brief The result of the most recent availability check
860      *
861      * Saved on the object so changes can be detected.
862      */
863     bool available = false;
864 
865     /**
866      * @brief Will be updated to the latest/lastvalue read from STATUS_WORD.
867      */
868     uint64_t statusWord = 0;
869 
870     /**
871      * @brief Will be set to the last read value of STATUS_WORD.
872      */
873     uint64_t statusWordOld = 0;
874 
875     /**
876      * @brief Will be updated to the latest/lastvalue read from STATUS_INPUT.
877      */
878     uint64_t statusInput = 0;
879 
880     /**
881      * @brief Will be updated to the latest/lastvalue read from STATUS_MFR.
882      */
883     uint64_t statusMFR = 0;
884 
885     /**
886      * @brief Will be updated to the latest/last value read from STATUS_CML.
887      */
888     uint64_t statusCML = 0;
889 
890     /**
891      * @brief Will be updated to the latest/last value read from STATUS_VOUT.
892      */
893     uint64_t statusVout = 0;
894 
895     /**
896      * @brief Will be updated to the latest/last value read from STATUS_IOUT.
897      */
898     uint64_t statusIout = 0;
899 
900     /**
901      * @brief Will be updated to the latest/last value read from
902      * STATUS_FANS_1_2.
903      */
904     uint64_t statusFans12 = 0;
905 
906     /**
907      * @brief Will be updated to the latest/last value read from
908      * STATUS_TEMPERATURE.
909      */
910     uint64_t statusTemperature = 0;
911 
912     /**
913      * @brief Will be updated with latest converted value read from READ_VIN
914      */
915     int inputVoltage = phosphor::pmbus::in_input::VIN_VOLTAGE_0;
916 
917     /**
918      * @brief Will be updated with the actual voltage last read from READ_VIN
919      */
920     double actualInputVoltage = 0;
921 
922     /**
923      * @brief True if an error for a fault has already been logged.
924      */
925     bool faultLogged = false;
926 
927     /**
928      * @brief Incremented if bit 1 of STATUS_WORD low byte is on.
929      *
930      * Considered faulted if reaches DEGLITCH_LIMIT.
931      */
932     size_t cmlFault = 0;
933 
934     /**
935      * @brief Incremented if bit 5 of STATUS_WORD high byte is on.
936      *
937      * Considered faulted if reaches DEGLITCH_LIMIT.
938      */
939     size_t inputFault = 0;
940 
941     /**
942      * @brief Incremented if bit 4 of STATUS_WORD high byte is on.
943      *
944      * Considered faulted if reaches DEGLITCH_LIMIT.
945      */
946     size_t mfrFault = 0;
947 
948     /**
949      * @brief Incremented if bit 3 of STATUS_WORD low byte is on.
950      *
951      * Considered faulted if reaches DEGLITCH_LIMIT.
952      */
953     size_t vinUVFault = 0;
954 
955     /**
956      * @brief Incremented if bit 5 of STATUS_WORD low byte is on.
957      *
958      * Considered faulted if reaches DEGLITCH_LIMIT.
959      */
960     size_t voutOVFault = 0;
961 
962     /**
963      * @brief Incremented if bit 4 of STATUS_WORD low byte is on.
964      *
965      * Considered faulted if reaches DEGLITCH_LIMIT.
966      */
967     size_t ioutOCFault = 0;
968 
969     /**
970      * @brief Incremented if bit 7 of STATUS_WORD high byte is on and bit 5
971      * (VOUT_OV) of low byte is off.
972      *
973      * Considered faulted if reaches DEGLITCH_LIMIT.
974      */
975     size_t voutUVFault = 0;
976 
977     /**
978      * @brief Incremented if FANS fault/warn bit on in STATUS_WORD.
979      *
980      * Considered faulted if reaches DEGLITCH_LIMIT.
981      */
982     size_t fanFault = 0;
983 
984     /**
985      * @brief Incremented if bit 2 of STATUS_WORD low byte is on.
986      *
987      * Considered faulted if reaches DEGLITCH_LIMIT.
988      */
989     size_t tempFault = 0;
990 
991     /**
992      * @brief Incremented if bit 11 or 6 of STATUS_WORD is on. PGOOD# is
993      * inactive, or the unit is off.
994      *
995      * Considered faulted if reaches DEGLITCH_LIMIT.
996      */
997     size_t pgoodFault = 0;
998 
999     /**
1000      * @brief Power Supply Kill fault.
1001      *
1002      * Incremented based on bits in STATUS_MFR_SPECIFIC. IBM power supplies use
1003      * bit 4 to indicate this fault. Considered faulted if it reaches
1004      * DEGLITCH_LIMIT.
1005      */
1006     size_t psKillFault = 0;
1007 
1008     /**
1009      * @brief Power Supply 12Vcs fault (standby power).
1010      *
1011      * Incremented based on bits in STATUS_MFR_SPECIFIC. IBM power supplies use
1012      * bit 6 to indicate this fault. Considered faulted if it reaches
1013      * DEGLITCH_LIMIT.
1014      */
1015     size_t ps12VcsFault = 0;
1016 
1017     /**
1018      * @brief Power Supply Current-Share fault in 12V domain.
1019      *
1020      * Incremented based on bits in STATUS_MFR_SPECIFIC. IBM power supplies use
1021      * bit 7 to indicate this fault. Considered faulted if it reaches
1022      * DEGLITCH_LIMIT.
1023      */
1024     size_t psCS12VFault = 0;
1025 
1026     /**
1027      * @brief Set to AC_FAULT_LIMIT when AC fault is detected, decremented when
1028      * AC fault has cleared. Effectively forms a timer since last AC failure.
1029      * Zero indicates being outside the window of concern.
1030      */
1031     size_t acFault = 0;
1032 
1033     /**
1034      * @brief Count of the number of read failures.
1035      */
1036     size_t readFail = 0;
1037 
1038     /**
1039      * @brief The D-Bus object for the input voltage rating
1040      *
1041      * It is updated at startup and power on.  If a power supply is
1042      * added or removed after that, it does not need to be updated
1043      * again (though that could be done as a future improvement).
1044      */
1045     std::unique_ptr<SensorObject> inputVoltageRatingIface;
1046 
1047     /**
1048      * @brief The D-Bus object for the peak input power sensor.
1049      */
1050     std::unique_ptr<PowerSensorObject> peakInputPowerSensor;
1051 
1052     /**
1053      * @brief The device driver name
1054      */
1055     std::string driverName;
1056 };
1057 
1058 } // namespace phosphor::power::psu
1059