| Shawn McCarney | 71d7fe4 | 2024-05-02 16:06:10 -0500 | [diff] [blame] | 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 |
| Shawn McCarney | 71d7fe4 | 2024-05-02 16:06:10 -0500 | [diff] [blame] | 54 | * @param bus I2C bus for the device |
| 55 | * @param address I2C address for the device |
| Shawn McCarney | fe53667 | 2025-10-29 12:44:08 -0500 | [diff] [blame] | 56 | * @param powerControlGPIOName Name of the GPIO that turns this device on |
| 57 | * and off |
| 58 | * @param powerGoodGPIOName Name of the GPIO that reads the power good |
| 59 | * signal from this device |
| Shawn McCarney | 3123445 | 2025-10-28 12:32:05 -0500 | [diff] [blame] | 60 | * @param rails Voltage rails that are enabled and monitored by this device |
| 61 | * @param services System services like hardware presence and the journal |
| Shawn McCarney | 71d7fe4 | 2024-05-02 16:06:10 -0500 | [diff] [blame] | 62 | */ |
| Shawn McCarney | fe53667 | 2025-10-29 12:44:08 -0500 | [diff] [blame] | 63 | explicit UCD90xDevice( |
| 64 | const std::string& name, uint8_t bus, uint16_t address, |
| 65 | const std::string& powerControlGPIOName, |
| 66 | const std::string& powerGoodGPIOName, |
| 67 | std::vector<std::unique_ptr<Rail>> rails, Services& services) : |
| 68 | PMBusDriverDevice(name, bus, address, powerControlGPIOName, |
| 69 | powerGoodGPIOName, std::move(rails), services, |
| Shawn McCarney | 71d7fe4 | 2024-05-02 16:06:10 -0500 | [diff] [blame] | 70 | driverName) |
| 71 | {} |
| 72 | |
| 73 | /** |
| 74 | * Returns the value of the PMBus MFR_STATUS command. |
| 75 | * |
| 76 | * This is a manufacturer-specific command that replaces the standard |
| 77 | * STATUS_MFR_SPECIFIC command on UCD90x devices. |
| 78 | * |
| 79 | * The returned value is in host-endian order. |
| 80 | * |
| 81 | * Note that the UCD90x documentation states that this is a paged command. |
| 82 | * This means that the PMBus PAGE should be set, and some of the bits in the |
| 83 | * command value are page-specific. However, the current device driver only |
| 84 | * provides a single file in sysfs, and the driver always sets the PAGE to |
| 85 | * 0. Thus, the bits that are page-specific in the returned value are |
| 86 | * always for PAGE 0. |
| 87 | * |
| 88 | * Throws an exception if the value could not be obtained. |
| 89 | * |
| 90 | * @return MFR_STATUS value |
| 91 | */ |
| 92 | virtual uint64_t getMfrStatus(); |
| 93 | |
| 94 | constexpr static std::string driverName{"ucd9000"}; |
| 95 | |
| 96 | protected: |
| 97 | /** @copydoc PMBusDriverDevice::storePgoodFaultDebugData() */ |
| 98 | virtual void storePgoodFaultDebugData( |
| 99 | Services& services, const std::vector<int>& gpioValues, |
| 100 | std::map<std::string, std::string>& additionalData) override; |
| 101 | }; |
| 102 | |
| 103 | } // namespace phosphor::power::sequencer |