1 #include "host_condition.hpp"
2 
3 #include <gpiod.hpp>
4 #include <phosphor-logging/elog-errors.hpp>
5 #include <phosphor-logging/lg2.hpp>
6 
7 namespace phosphor
8 {
9 namespace condition
10 {
11 
12 PHOSPHOR_LOG2_USING;
13 
14 using namespace phosphor::logging;
15 
scanGpioPin()16 void Host::scanGpioPin()
17 {
18     /*
19      * Check the hostX-ready/-n pin is defined or not
20      */
21     if (gpiod::find_line(lineName + "-ready"))
22     {
23         lineName += "-ready";
24         isActHigh = true;
25     }
26     else if (gpiod::find_line(lineName + "-ready-n"))
27     {
28         lineName += "-ready-n";
29         isActHigh = false;
30     }
31     else
32     {
33         lineName = "";
34     }
35 }
36 
currentFirmwareCondition() const37 Host::FirmwareCondition Host::currentFirmwareCondition() const
38 {
39     auto retVal = Host::FirmwareCondition::Unknown;
40 
41     /*
42      * Check host is ready or not
43      */
44     if (!lineName.empty())
45     {
46         auto line = gpiod::find_line(lineName);
47 
48         try
49         {
50             int32_t gpioVal = 0;
51 
52             line.request(
53                 {lineName, gpiod::line_request::DIRECTION_INPUT,
54                  (isActHigh) ? 0 : gpiod::line_request::FLAG_ACTIVE_LOW});
55 
56             gpioVal = line.get_value();
57             line.release();
58 
59             retVal = (0 == gpioVal) ? Host::FirmwareCondition::Off
60                                     : Host::FirmwareCondition::Running;
61         }
62         catch (std::system_error&)
63         {
64             error("Error when read gpio value");
65         }
66     }
67 
68     return retVal;
69 }
70 } // namespace condition
71 } // namespace phosphor
72