xref: /openbmc/phosphor-power/phosphor-power-sequencer/src/gpios_only_device.hpp (revision 7b7a5632c594d60f4620ca14379a766a56faf846)
1*7b7a5632SShawn McCarney /**
2*7b7a5632SShawn McCarney  * Copyright © 2025 IBM Corporation
3*7b7a5632SShawn McCarney  *
4*7b7a5632SShawn McCarney  * Licensed under the Apache License, Version 2.0 (the "License");
5*7b7a5632SShawn McCarney  * you may not use this file except in compliance with the License.
6*7b7a5632SShawn McCarney  * You may obtain a copy of the License at
7*7b7a5632SShawn McCarney  *
8*7b7a5632SShawn McCarney  *     http://www.apache.org/licenses/LICENSE-2.0
9*7b7a5632SShawn McCarney  *
10*7b7a5632SShawn McCarney  * Unless required by applicable law or agreed to in writing, software
11*7b7a5632SShawn McCarney  * distributed under the License is distributed on an "AS IS" BASIS,
12*7b7a5632SShawn McCarney  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*7b7a5632SShawn McCarney  * See the License for the specific language governing permissions and
14*7b7a5632SShawn McCarney  * limitations under the License.
15*7b7a5632SShawn McCarney  */
16*7b7a5632SShawn McCarney #pragma once
17*7b7a5632SShawn McCarney 
18*7b7a5632SShawn McCarney #include "power_sequencer_device.hpp"
19*7b7a5632SShawn McCarney #include "rail.hpp"
20*7b7a5632SShawn McCarney #include "services.hpp"
21*7b7a5632SShawn McCarney 
22*7b7a5632SShawn McCarney #include <cstdint>
23*7b7a5632SShawn McCarney #include <map>
24*7b7a5632SShawn McCarney #include <memory>
25*7b7a5632SShawn McCarney #include <stdexcept>
26*7b7a5632SShawn McCarney #include <string>
27*7b7a5632SShawn McCarney #include <vector>
28*7b7a5632SShawn McCarney 
29*7b7a5632SShawn McCarney namespace phosphor::power::sequencer
30*7b7a5632SShawn McCarney {
31*7b7a5632SShawn McCarney 
32*7b7a5632SShawn McCarney /**
33*7b7a5632SShawn McCarney  * @class GPIOsOnlyDevice
34*7b7a5632SShawn McCarney  *
35*7b7a5632SShawn McCarney  * PowerSequencerDevice sub-class that only uses the named GPIOs.
36*7b7a5632SShawn McCarney  *
37*7b7a5632SShawn McCarney  * This class uses named GPIOs to power the device on/off and read the power
38*7b7a5632SShawn McCarney  * good signal from the device.
39*7b7a5632SShawn McCarney  *
40*7b7a5632SShawn McCarney  * No other communication is performed to the device over I2C or through a
41*7b7a5632SShawn McCarney  * device driver. If a pgood fault occurs, no attempt will be made to determine
42*7b7a5632SShawn McCarney  * which voltage rail caused the fault.
43*7b7a5632SShawn McCarney  *
44*7b7a5632SShawn McCarney  * This device type is useful for simple systems that do not require pgood fault
45*7b7a5632SShawn McCarney  * isolation. It is also useful as a temporary solution when performing early
46*7b7a5632SShawn McCarney  * bring-up work on a new system.
47*7b7a5632SShawn McCarney  */
48*7b7a5632SShawn McCarney class GPIOsOnlyDevice : public PowerSequencerDevice
49*7b7a5632SShawn McCarney {
50*7b7a5632SShawn McCarney   public:
51*7b7a5632SShawn McCarney     GPIOsOnlyDevice() = delete;
52*7b7a5632SShawn McCarney     GPIOsOnlyDevice(const GPIOsOnlyDevice&) = delete;
53*7b7a5632SShawn McCarney     GPIOsOnlyDevice(GPIOsOnlyDevice&&) = delete;
54*7b7a5632SShawn McCarney     GPIOsOnlyDevice& operator=(const GPIOsOnlyDevice&) = delete;
55*7b7a5632SShawn McCarney     GPIOsOnlyDevice& operator=(GPIOsOnlyDevice&&) = delete;
56*7b7a5632SShawn McCarney     virtual ~GPIOsOnlyDevice() = default;
57*7b7a5632SShawn McCarney 
58*7b7a5632SShawn McCarney     /**
59*7b7a5632SShawn McCarney      * Constructor.
60*7b7a5632SShawn McCarney      *
61*7b7a5632SShawn McCarney      * @param powerControlGPIOName name of the GPIO that turns this device on
62*7b7a5632SShawn McCarney      *                             and off
63*7b7a5632SShawn McCarney      * @param powerGoodGPIOName name of the GPIO that reads the power good
64*7b7a5632SShawn McCarney      *                          signal from this device
65*7b7a5632SShawn McCarney      */
GPIOsOnlyDevice(const std::string & powerControlGPIOName,const std::string & powerGoodGPIOName)66*7b7a5632SShawn McCarney     explicit GPIOsOnlyDevice(const std::string& powerControlGPIOName,
67*7b7a5632SShawn McCarney                              const std::string& powerGoodGPIOName) :
68*7b7a5632SShawn McCarney         powerControlGPIOName{powerControlGPIOName},
69*7b7a5632SShawn McCarney         powerGoodGPIOName{powerGoodGPIOName}
70*7b7a5632SShawn McCarney     {}
71*7b7a5632SShawn McCarney 
72*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getName() */
getName() const73*7b7a5632SShawn McCarney     virtual const std::string& getName() const override
74*7b7a5632SShawn McCarney     {
75*7b7a5632SShawn McCarney         return deviceName;
76*7b7a5632SShawn McCarney     }
77*7b7a5632SShawn McCarney 
78*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getBus() */
getBus() const79*7b7a5632SShawn McCarney     virtual uint8_t getBus() const override
80*7b7a5632SShawn McCarney     {
81*7b7a5632SShawn McCarney         return 0;
82*7b7a5632SShawn McCarney     }
83*7b7a5632SShawn McCarney 
84*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getAddress() */
getAddress() const85*7b7a5632SShawn McCarney     virtual uint16_t getAddress() const override
86*7b7a5632SShawn McCarney     {
87*7b7a5632SShawn McCarney         return 0;
88*7b7a5632SShawn McCarney     }
89*7b7a5632SShawn McCarney 
90*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getPowerControlGPIOName() */
getPowerControlGPIOName() const91*7b7a5632SShawn McCarney     virtual const std::string& getPowerControlGPIOName() const override
92*7b7a5632SShawn McCarney     {
93*7b7a5632SShawn McCarney         return powerControlGPIOName;
94*7b7a5632SShawn McCarney     }
95*7b7a5632SShawn McCarney 
96*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getPowerGoodGPIOName() */
getPowerGoodGPIOName() const97*7b7a5632SShawn McCarney     virtual const std::string& getPowerGoodGPIOName() const override
98*7b7a5632SShawn McCarney     {
99*7b7a5632SShawn McCarney         return powerGoodGPIOName;
100*7b7a5632SShawn McCarney     }
101*7b7a5632SShawn McCarney 
102*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getRails() */
getRails() const103*7b7a5632SShawn McCarney     virtual const std::vector<std::unique_ptr<Rail>>& getRails() const override
104*7b7a5632SShawn McCarney     {
105*7b7a5632SShawn McCarney         return rails;
106*7b7a5632SShawn McCarney     }
107*7b7a5632SShawn McCarney 
108*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getGPIOValues() */
getGPIOValues(Services & services)109*7b7a5632SShawn McCarney     virtual std::vector<int> getGPIOValues(
110*7b7a5632SShawn McCarney         [[maybe_unused]] Services& services) override
111*7b7a5632SShawn McCarney     {
112*7b7a5632SShawn McCarney         throw std::logic_error{"getGPIOValues() is not supported"};
113*7b7a5632SShawn McCarney     }
114*7b7a5632SShawn McCarney 
115*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getStatusWord() */
getStatusWord(uint8_t page)116*7b7a5632SShawn McCarney     virtual uint16_t getStatusWord([[maybe_unused]] uint8_t page) override
117*7b7a5632SShawn McCarney     {
118*7b7a5632SShawn McCarney         throw std::logic_error{"getStatusWord() is not supported"};
119*7b7a5632SShawn McCarney     }
120*7b7a5632SShawn McCarney 
121*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getStatusVout() */
getStatusVout(uint8_t page)122*7b7a5632SShawn McCarney     virtual uint8_t getStatusVout([[maybe_unused]] uint8_t page) override
123*7b7a5632SShawn McCarney     {
124*7b7a5632SShawn McCarney         throw std::logic_error{"getStatusVout() is not supported"};
125*7b7a5632SShawn McCarney     }
126*7b7a5632SShawn McCarney 
127*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getReadVout() */
getReadVout(uint8_t page)128*7b7a5632SShawn McCarney     virtual double getReadVout([[maybe_unused]] uint8_t page) override
129*7b7a5632SShawn McCarney     {
130*7b7a5632SShawn McCarney         throw std::logic_error{"getReadVout() is not supported"};
131*7b7a5632SShawn McCarney     }
132*7b7a5632SShawn McCarney 
133*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::getVoutUVFaultLimit() */
getVoutUVFaultLimit(uint8_t page)134*7b7a5632SShawn McCarney     virtual double getVoutUVFaultLimit([[maybe_unused]] uint8_t page) override
135*7b7a5632SShawn McCarney     {
136*7b7a5632SShawn McCarney         throw std::logic_error{"getVoutUVFaultLimit() is not supported"};
137*7b7a5632SShawn McCarney     }
138*7b7a5632SShawn McCarney 
139*7b7a5632SShawn McCarney     /** @copydoc PowerSequencerDevice::findPgoodFault() */
findPgoodFault(Services & services,const std::string & powerSupplyError,std::map<std::string,std::string> & additionalData)140*7b7a5632SShawn McCarney     virtual std::string findPgoodFault(
141*7b7a5632SShawn McCarney         [[maybe_unused]] Services& services,
142*7b7a5632SShawn McCarney         [[maybe_unused]] const std::string& powerSupplyError,
143*7b7a5632SShawn McCarney         [[maybe_unused]] std::map<std::string, std::string>& additionalData)
144*7b7a5632SShawn McCarney         override
145*7b7a5632SShawn McCarney     {
146*7b7a5632SShawn McCarney         return std::string{};
147*7b7a5632SShawn McCarney     }
148*7b7a5632SShawn McCarney 
149*7b7a5632SShawn McCarney     inline static const std::string deviceName{"gpios_only_device"};
150*7b7a5632SShawn McCarney 
151*7b7a5632SShawn McCarney   protected:
152*7b7a5632SShawn McCarney     /**
153*7b7a5632SShawn McCarney      * Name of the GPIO that turns this device on and off.
154*7b7a5632SShawn McCarney      */
155*7b7a5632SShawn McCarney     std::string powerControlGPIOName{};
156*7b7a5632SShawn McCarney 
157*7b7a5632SShawn McCarney     /**
158*7b7a5632SShawn McCarney      * Name of the GPIO that reads the power good signal from this device.
159*7b7a5632SShawn McCarney      */
160*7b7a5632SShawn McCarney     std::string powerGoodGPIOName{};
161*7b7a5632SShawn McCarney 
162*7b7a5632SShawn McCarney     /**
163*7b7a5632SShawn McCarney      * Empty list of voltage rails to return from getRails().
164*7b7a5632SShawn McCarney      */
165*7b7a5632SShawn McCarney     std::vector<std::unique_ptr<Rail>> rails{};
166*7b7a5632SShawn McCarney };
167*7b7a5632SShawn McCarney 
168*7b7a5632SShawn McCarney } // namespace phosphor::power::sequencer
169