1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef _LINUX_FPGA_BRIDGE_H 4 #define _LINUX_FPGA_BRIDGE_H 5 6 #include <linux/device.h> 7 #include <linux/fpga/fpga-mgr.h> 8 9 struct fpga_bridge; 10 11 /** 12 * struct fpga_bridge_ops - ops for low level FPGA bridge drivers 13 * @enable_show: returns the FPGA bridge's status 14 * @enable_set: set an FPGA bridge as enabled or disabled 15 * @fpga_bridge_remove: set FPGA into a specific state during driver remove 16 * @groups: optional attribute groups. 17 */ 18 struct fpga_bridge_ops { 19 int (*enable_show)(struct fpga_bridge *bridge); 20 int (*enable_set)(struct fpga_bridge *bridge, bool enable); 21 void (*fpga_bridge_remove)(struct fpga_bridge *bridge); 22 const struct attribute_group **groups; 23 }; 24 25 /** 26 * struct fpga_bridge_info - collection of parameters an FPGA Bridge 27 * @name: fpga bridge name 28 * @br_ops: pointer to structure of fpga bridge ops 29 * @priv: fpga bridge private data 30 * 31 * fpga_bridge_info contains parameters for the register function. These 32 * are separated into an info structure because they some are optional 33 * others could be added to in the future. The info structure facilitates 34 * maintaining a stable API. 35 */ 36 struct fpga_bridge_info { 37 const char *name; 38 const struct fpga_bridge_ops *br_ops; 39 void *priv; 40 }; 41 42 /** 43 * struct fpga_bridge - FPGA bridge structure 44 * @name: name of low level FPGA bridge 45 * @dev: FPGA bridge device 46 * @mutex: enforces exclusive reference to bridge 47 * @br_ops: pointer to struct of FPGA bridge ops 48 * @info: fpga image specific information 49 * @node: FPGA bridge list node 50 * @priv: low level driver private date 51 */ 52 struct fpga_bridge { 53 const char *name; 54 struct device dev; 55 struct mutex mutex; /* for exclusive reference to bridge */ 56 const struct fpga_bridge_ops *br_ops; 57 struct fpga_image_info *info; 58 struct list_head node; 59 void *priv; 60 }; 61 62 #define to_fpga_bridge(d) container_of(d, struct fpga_bridge, dev) 63 64 struct fpga_bridge *of_fpga_bridge_get(struct device_node *node, 65 struct fpga_image_info *info); 66 struct fpga_bridge *fpga_bridge_get(struct device *dev, 67 struct fpga_image_info *info); 68 void fpga_bridge_put(struct fpga_bridge *bridge); 69 int fpga_bridge_enable(struct fpga_bridge *bridge); 70 int fpga_bridge_disable(struct fpga_bridge *bridge); 71 72 int fpga_bridges_enable(struct list_head *bridge_list); 73 int fpga_bridges_disable(struct list_head *bridge_list); 74 void fpga_bridges_put(struct list_head *bridge_list); 75 int fpga_bridge_get_to_list(struct device *dev, 76 struct fpga_image_info *info, 77 struct list_head *bridge_list); 78 int of_fpga_bridge_get_to_list(struct device_node *np, 79 struct fpga_image_info *info, 80 struct list_head *bridge_list); 81 82 struct fpga_bridge * 83 fpga_bridge_register(struct device *parent, const char *name, 84 const struct fpga_bridge_ops *br_ops, 85 void *priv); 86 void fpga_bridge_unregister(struct fpga_bridge *br); 87 88 #endif /* _LINUX_FPGA_BRIDGE_H */ 89