Andrew Geissler | 5dc5c39 | 2020-02-05 12:48:01 -0600 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | |
| 3 | #include <chrono> |
| 4 | #include <gpiod.hpp> |
| 5 | #include <phosphor-logging/log.hpp> |
| 6 | #include <registration.hpp> |
| 7 | #include <system_error> |
| 8 | #include <thread> |
| 9 | |
| 10 | namespace openpower |
| 11 | { |
| 12 | namespace misc |
| 13 | { |
| 14 | |
| 15 | using namespace phosphor::logging; |
| 16 | |
| 17 | /** |
| 18 | * @brief Reset the CFAM using the appropriate GPIO |
| 19 | * @return void |
| 20 | */ |
| 21 | void cfamReset() |
| 22 | { |
| 23 | const std::string cfamReset = {"cfam-reset"}; |
| 24 | auto line = gpiod::find_line(cfamReset); |
| 25 | if (!line) |
| 26 | { |
| 27 | log<level::ERR>("failed to find cfam-reset line"); |
| 28 | throw std::system_error(ENODEV, std::system_category()); |
| 29 | } |
| 30 | |
| 31 | // Configure this app to own the gpio while doing the reset |
| 32 | gpiod::line_request conf; |
| 33 | conf.consumer = "cfamReset"; |
| 34 | conf.request_type = gpiod::line_request::DIRECTION_OUTPUT; |
| 35 | line.request(conf); |
| 36 | |
| 37 | // Put chips into reset |
| 38 | line.set_value(0); |
| 39 | |
| 40 | // Sleep one second to ensure reset processed |
| 41 | using namespace std::chrono_literals; |
| 42 | std::this_thread::sleep_for(1s); |
| 43 | |
| 44 | // Take chips out of reset |
| 45 | line.set_value(1); |
| 46 | } |
| 47 | |
| 48 | REGISTER_PROCEDURE("cfamReset", cfamReset); |
| 49 | |
| 50 | } // namespace misc |
| 51 | } // namespace openpower |