cfam-reset: utilize new sysfs interface if avaialble
The kernel introduced support on some systems for a sysfs based
mechanism to issue cfam resets. See the following commit for more
information:
https://github.com/openbmc/linux/commit/0298c9857e284aae7841a31c2a6cd3954afec6c9
Userspace software should first look to utilize the new sysfs based
mechanism and if not available, fall back to the libgpiod mechanism.
Currently only witherspoon-tacoma and rainier support this new sysfs
based cfam reset mechanism.
Tested:
- Built a witherspoon image and verified libgpiod path was used
- Built a witherspoon-tacoma and verified new sysfs path was used
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I3a99899cb7d46a878a62c93954c59b7853c2b759
diff --git a/procedures/common/cfam_reset.cpp b/procedures/common/cfam_reset.cpp
index 5558374..acf3d3d 100644
--- a/procedures/common/cfam_reset.cpp
+++ b/procedures/common/cfam_reset.cpp
@@ -1,6 +1,7 @@
#include <unistd.h>
#include <chrono>
+#include <fstream>
#include <gpiod.hpp>
#include <phosphor-logging/log.hpp>
#include <registration.hpp>
@@ -12,6 +13,8 @@
namespace misc
{
+constexpr auto cfamResetPath = "/sys/class/fsi-master/fsi0/device/cfam_reset";
+
using namespace phosphor::logging;
/**
@@ -20,6 +23,26 @@
*/
void cfamReset()
{
+
+ // First look if system supports kernel sysfs based cfam reset
+ // If it does then write a 1 and let the kernel handle the reset
+ std::ofstream file;
+ file.open(cfamResetPath);
+ if (!file)
+ {
+ log<level::DEBUG>("system does not support kernel cfam reset, default "
+ "to using libgpiod");
+ }
+ else
+ {
+ // Write a 1 to have kernel toggle the reset
+ file << "1";
+ file.close();
+ log<level::DEBUG>("cfam reset via sysfs complete");
+ return;
+ }
+
+ // No kernel support so toggle gpio from userspace
const std::string cfamReset = {"cfam-reset"};
auto line = gpiod::find_line(cfamReset);
if (!line)