[RFC PATCH] fpga: fpga-bridge: Add manual set option via sysfs

From: Nava kishore Manne
Date: Thu May 25 2023 - 05:54:58 EST


This patch is intended for manual testing only.
It is provide an option to manually test bridges.

Enabling bridge (!0 values are handled)
br1# echo 1 > /sys/class/fpga_bridge/<bridge>/set

Disable bridge
br1# echo 0 > /sys/class/fpga_bridge/<bridge>/set

Signed-off-by: Nava kishore Manne <nava.kishore.manne@xxxxxxx>
---
.../ABI/testing/sysfs-class-fpga-bridge | 9 ++++++
drivers/fpga/fpga-bridge.c | 30 +++++++++++++++++++
2 files changed, 39 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-fpga-bridge b/Documentation/ABI/testing/sysfs-class-fpga-bridge
index 312ae2c579d8..e157eb737bfb 100644
--- a/Documentation/ABI/testing/sysfs-class-fpga-bridge
+++ b/Documentation/ABI/testing/sysfs-class-fpga-bridge
@@ -9,3 +9,12 @@ Date: January 2016
KernelVersion: 4.5
Contact: Alan Tull <atull@xxxxxxxxxxxxxxxxxxxxx>
Description: Show bridge state as "enabled" or "disabled"
+
+What: /sys/class/fpga_bridge/<bridge>/set
+Date: May 2023
+KernelVersion: 6.4
+Contact: Nava kishore Manne <nava.kishore.manne@xxxxxxx>
+Description: Manual set bridge state (0-disable, !0 enable).
+ Enabling this option requires that the module is
+ compiled with #define DEBUG which is enabled by default
+ when CONFIG_DEBUG_KERNEL is setup.
diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
index a6c25dee9cc1..54d15b709b10 100644
--- a/drivers/fpga/fpga-bridge.c
+++ b/drivers/fpga/fpga-bridge.c
@@ -13,6 +13,12 @@
#include <linux/slab.h>
#include <linux/spinlock.h>

+/* For enabling manual bridge set(enable/disable) function */
+#ifdef CONFIG_DEBUG_KERNEL
+#undef DEBUG
+#define DEBUG
+#endif
+
static DEFINE_IDA(fpga_bridge_ida);
static struct class *fpga_bridge_class;

@@ -307,9 +313,33 @@ static ssize_t state_show(struct device *dev,
static DEVICE_ATTR_RO(name);
static DEVICE_ATTR_RO(state);

+#ifdef DEBUG
+static ssize_t set_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct fpga_bridge *bridge = to_fpga_bridge(dev);
+ long enable;
+ int ret;
+
+ ret = kstrtol(buf, 16, &enable);
+ if (ret)
+ return ret;
+
+ if (bridge->br_ops && bridge->br_ops->enable_set)
+ enable = bridge->br_ops->enable_set(bridge, !!enable);
+
+ return count;
+}
+static DEVICE_ATTR_WO(set);
+#endif
+
static struct attribute *fpga_bridge_attrs[] = {
&dev_attr_name.attr,
&dev_attr_state.attr,
+#ifdef DEBUG
+ &dev_attr_set.attr,
+#endif
NULL,
};
ATTRIBUTE_GROUPS(fpga_bridge);
--
2.25.1