[PATCH v2 2/4] fpga: region: introduce compat_id_show op

From: trix
Date: Fri Jul 09 2021 - 09:42:56 EST


From: Tom Rix <trix@xxxxxxxxxx>

The sysfs reported value for compat_id is implementation
dependent. So add an optional op to fpga_region_ops to allow
an implementation to override the default.

Signed-off-by: Tom Rix <trix@xxxxxxxxxx>
---
drivers/fpga/fpga-region.c | 3 +++
include/linux/fpga/fpga-region.h | 2 ++
2 files changed, 5 insertions(+)

diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
index dfa35c2dc2720..864dd4f290e3b 100644
--- a/drivers/fpga/fpga-region.c
+++ b/drivers/fpga/fpga-region.c
@@ -169,6 +169,9 @@ static ssize_t compat_id_show(struct device *dev,
{
struct fpga_region *region = to_fpga_region(dev);

+ if (region->rops && region->rops->compat_id_show)
+ return region->rops->compat_id_show(region, buf);
+
if (!region->compat_id)
return -ENOENT;

diff --git a/include/linux/fpga/fpga-region.h b/include/linux/fpga/fpga-region.h
index d712344fd00a7..236d3819f1c13 100644
--- a/include/linux/fpga/fpga-region.h
+++ b/include/linux/fpga/fpga-region.h
@@ -12,6 +12,7 @@ struct fpga_region;
/**
* struct fpga_region_ops - ops for low level fpga region drivers
* @get_bridges: optional function to get bridges to a list
+ * @compat_id_show: optional function emit to sysfs a compatible id
*
* fpga_region_ops are the low level functions implemented by a specific
* fpga region driver. The optional ones are tested for NULL before being
@@ -19,6 +20,7 @@ struct fpga_region;
*/
struct fpga_region_ops {
int (*get_bridges)(struct fpga_region *region);
+ ssize_t (*compat_id_show)(struct fpga_region *region, char *buf);
};

/**
--
2.26.3