1 /**
2  * Copyright © 2024 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 #pragma once
17 
18 #include "pmbus_driver_device.hpp"
19 #include "rail.hpp"
20 #include "services.hpp"
21 
22 #include <cstdint>
23 #include <map>
24 #include <memory>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 namespace phosphor::power::sequencer
30 {
31 
32 /**
33  * @class UCD90xDevice
34  *
35  * PMBusDriverDevice sub-class for the UCD90X family of power sequencer devices.
36  *
37  * These devices share a common device driver.
38  */
39 class UCD90xDevice : public PMBusDriverDevice
40 {
41   public:
42     // Specify which compiler-generated methods we want
43     UCD90xDevice() = delete;
44     UCD90xDevice(const UCD90xDevice&) = delete;
45     UCD90xDevice(UCD90xDevice&&) = delete;
46     UCD90xDevice& operator=(const UCD90xDevice&) = delete;
47     UCD90xDevice& operator=(UCD90xDevice&&) = delete;
48     virtual ~UCD90xDevice() = default;
49 
50     /**
51      * Constructor.
52      *
53      * @param name Device name
54      * @param rails Voltage rails that are enabled and monitored by this device
55      * @param services System services like hardware presence and the journal
56      * @param bus I2C bus for the device
57      * @param address I2C address for the device
58      */
UCD90xDevice(const std::string & name,std::vector<std::unique_ptr<Rail>> rails,Services & services,uint8_t bus,uint16_t address)59     explicit UCD90xDevice(const std::string& name,
60                           std::vector<std::unique_ptr<Rail>> rails,
61                           Services& services, uint8_t bus, uint16_t address) :
62         PMBusDriverDevice(name, std::move(rails), services, bus, address,
63                           driverName)
64     {}
65 
66     /**
67      * Returns the value of the PMBus MFR_STATUS command.
68      *
69      * This is a manufacturer-specific command that replaces the standard
70      * STATUS_MFR_SPECIFIC command on UCD90x devices.
71      *
72      * The returned value is in host-endian order.
73      *
74      * Note that the UCD90x documentation states that this is a paged command.
75      * This means that the PMBus PAGE should be set, and some of the bits in the
76      * command value are page-specific.  However, the current device driver only
77      * provides a single file in sysfs, and the driver always sets the PAGE to
78      * 0.  Thus, the bits that are page-specific in the returned value are
79      * always for PAGE 0.
80      *
81      * Throws an exception if the value could not be obtained.
82      *
83      * @return MFR_STATUS value
84      */
85     virtual uint64_t getMfrStatus();
86 
87     constexpr static std::string driverName{"ucd9000"};
88 
89   protected:
90     /** @copydoc PMBusDriverDevice::storePgoodFaultDebugData() */
91     virtual void storePgoodFaultDebugData(
92         Services& services, const std::vector<int>& gpioValues,
93         std::map<std::string, std::string>& additionalData) override;
94 };
95 
96 } // namespace phosphor::power::sequencer
97