| Shawn McCarney | 7b7a563 | 2025-11-19 13:08:58 -0600 | [diff] [blame^] | 1 | /** |
| 2 | * Copyright © 2025 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 "power_sequencer_device.hpp" |
| 19 | #include "rail.hpp" |
| 20 | #include "services.hpp" |
| 21 | |
| 22 | #include <cstdint> |
| 23 | #include <map> |
| 24 | #include <memory> |
| 25 | #include <stdexcept> |
| 26 | #include <string> |
| 27 | #include <vector> |
| 28 | |
| 29 | namespace phosphor::power::sequencer |
| 30 | { |
| 31 | |
| 32 | /** |
| 33 | * @class GPIOsOnlyDevice |
| 34 | * |
| 35 | * PowerSequencerDevice sub-class that only uses the named GPIOs. |
| 36 | * |
| 37 | * This class uses named GPIOs to power the device on/off and read the power |
| 38 | * good signal from the device. |
| 39 | * |
| 40 | * No other communication is performed to the device over I2C or through a |
| 41 | * device driver. If a pgood fault occurs, no attempt will be made to determine |
| 42 | * which voltage rail caused the fault. |
| 43 | * |
| 44 | * This device type is useful for simple systems that do not require pgood fault |
| 45 | * isolation. It is also useful as a temporary solution when performing early |
| 46 | * bring-up work on a new system. |
| 47 | */ |
| 48 | class GPIOsOnlyDevice : public PowerSequencerDevice |
| 49 | { |
| 50 | public: |
| 51 | GPIOsOnlyDevice() = delete; |
| 52 | GPIOsOnlyDevice(const GPIOsOnlyDevice&) = delete; |
| 53 | GPIOsOnlyDevice(GPIOsOnlyDevice&&) = delete; |
| 54 | GPIOsOnlyDevice& operator=(const GPIOsOnlyDevice&) = delete; |
| 55 | GPIOsOnlyDevice& operator=(GPIOsOnlyDevice&&) = delete; |
| 56 | virtual ~GPIOsOnlyDevice() = default; |
| 57 | |
| 58 | /** |
| 59 | * Constructor. |
| 60 | * |
| 61 | * @param powerControlGPIOName name of the GPIO that turns this device on |
| 62 | * and off |
| 63 | * @param powerGoodGPIOName name of the GPIO that reads the power good |
| 64 | * signal from this device |
| 65 | */ |
| 66 | explicit GPIOsOnlyDevice(const std::string& powerControlGPIOName, |
| 67 | const std::string& powerGoodGPIOName) : |
| 68 | powerControlGPIOName{powerControlGPIOName}, |
| 69 | powerGoodGPIOName{powerGoodGPIOName} |
| 70 | {} |
| 71 | |
| 72 | /** @copydoc PowerSequencerDevice::getName() */ |
| 73 | virtual const std::string& getName() const override |
| 74 | { |
| 75 | return deviceName; |
| 76 | } |
| 77 | |
| 78 | /** @copydoc PowerSequencerDevice::getBus() */ |
| 79 | virtual uint8_t getBus() const override |
| 80 | { |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | /** @copydoc PowerSequencerDevice::getAddress() */ |
| 85 | virtual uint16_t getAddress() const override |
| 86 | { |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /** @copydoc PowerSequencerDevice::getPowerControlGPIOName() */ |
| 91 | virtual const std::string& getPowerControlGPIOName() const override |
| 92 | { |
| 93 | return powerControlGPIOName; |
| 94 | } |
| 95 | |
| 96 | /** @copydoc PowerSequencerDevice::getPowerGoodGPIOName() */ |
| 97 | virtual const std::string& getPowerGoodGPIOName() const override |
| 98 | { |
| 99 | return powerGoodGPIOName; |
| 100 | } |
| 101 | |
| 102 | /** @copydoc PowerSequencerDevice::getRails() */ |
| 103 | virtual const std::vector<std::unique_ptr<Rail>>& getRails() const override |
| 104 | { |
| 105 | return rails; |
| 106 | } |
| 107 | |
| 108 | /** @copydoc PowerSequencerDevice::getGPIOValues() */ |
| 109 | virtual std::vector<int> getGPIOValues( |
| 110 | [[maybe_unused]] Services& services) override |
| 111 | { |
| 112 | throw std::logic_error{"getGPIOValues() is not supported"}; |
| 113 | } |
| 114 | |
| 115 | /** @copydoc PowerSequencerDevice::getStatusWord() */ |
| 116 | virtual uint16_t getStatusWord([[maybe_unused]] uint8_t page) override |
| 117 | { |
| 118 | throw std::logic_error{"getStatusWord() is not supported"}; |
| 119 | } |
| 120 | |
| 121 | /** @copydoc PowerSequencerDevice::getStatusVout() */ |
| 122 | virtual uint8_t getStatusVout([[maybe_unused]] uint8_t page) override |
| 123 | { |
| 124 | throw std::logic_error{"getStatusVout() is not supported"}; |
| 125 | } |
| 126 | |
| 127 | /** @copydoc PowerSequencerDevice::getReadVout() */ |
| 128 | virtual double getReadVout([[maybe_unused]] uint8_t page) override |
| 129 | { |
| 130 | throw std::logic_error{"getReadVout() is not supported"}; |
| 131 | } |
| 132 | |
| 133 | /** @copydoc PowerSequencerDevice::getVoutUVFaultLimit() */ |
| 134 | virtual double getVoutUVFaultLimit([[maybe_unused]] uint8_t page) override |
| 135 | { |
| 136 | throw std::logic_error{"getVoutUVFaultLimit() is not supported"}; |
| 137 | } |
| 138 | |
| 139 | /** @copydoc PowerSequencerDevice::findPgoodFault() */ |
| 140 | virtual std::string findPgoodFault( |
| 141 | [[maybe_unused]] Services& services, |
| 142 | [[maybe_unused]] const std::string& powerSupplyError, |
| 143 | [[maybe_unused]] std::map<std::string, std::string>& additionalData) |
| 144 | override |
| 145 | { |
| 146 | return std::string{}; |
| 147 | } |
| 148 | |
| 149 | inline static const std::string deviceName{"gpios_only_device"}; |
| 150 | |
| 151 | protected: |
| 152 | /** |
| 153 | * Name of the GPIO that turns this device on and off. |
| 154 | */ |
| 155 | std::string powerControlGPIOName{}; |
| 156 | |
| 157 | /** |
| 158 | * Name of the GPIO that reads the power good signal from this device. |
| 159 | */ |
| 160 | std::string powerGoodGPIOName{}; |
| 161 | |
| 162 | /** |
| 163 | * Empty list of voltage rails to return from getRails(). |
| 164 | */ |
| 165 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 166 | }; |
| 167 | |
| 168 | } // namespace phosphor::power::sequencer |