| 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 | * @br_ops_owner: module containing the br_ops |
| 49 | * @info: fpga image specific information |
| 50 | * @node: FPGA bridge list node |
| 51 | * @priv: low level driver private date |
| 52 | */ |
| 53 | struct fpga_bridge { |
| 54 | const char *name; |
| 55 | struct device dev; |
| 56 | struct mutex mutex; /* for exclusive reference to bridge */ |
| 57 | const struct fpga_bridge_ops *br_ops; |
| 58 | struct module *br_ops_owner; |
| 59 | struct fpga_image_info *info; |
| 60 | struct list_head node; |
| 61 | void *priv; |
| 62 | }; |
| 63 | |
| 64 | #define to_fpga_bridge(d) container_of(d, struct fpga_bridge, dev) |
| 65 | |
| 66 | struct fpga_bridge *of_fpga_bridge_get(struct device_node *node, |
| 67 | struct fpga_image_info *info); |
| 68 | struct fpga_bridge *fpga_bridge_get(struct device *dev, |
| 69 | struct fpga_image_info *info); |
| 70 | void fpga_bridge_put(struct fpga_bridge *bridge); |
| 71 | int fpga_bridge_enable(struct fpga_bridge *bridge); |
| 72 | int fpga_bridge_disable(struct fpga_bridge *bridge); |
| 73 | |
| 74 | int fpga_bridges_enable(struct list_head *bridge_list); |
| 75 | int fpga_bridges_disable(struct list_head *bridge_list); |
| 76 | void fpga_bridges_put(struct list_head *bridge_list); |
| 77 | int fpga_bridge_get_to_list(struct device *dev, |
| 78 | struct fpga_image_info *info, |
| 79 | struct list_head *bridge_list); |
| 80 | int of_fpga_bridge_get_to_list(struct device_node *np, |
| 81 | struct fpga_image_info *info, |
| 82 | struct list_head *bridge_list); |
| 83 | |
| 84 | #define fpga_bridge_register(parent, name, br_ops, priv) \ |
| 85 | __fpga_bridge_register(parent, name, br_ops, priv, THIS_MODULE) |
| 86 | struct fpga_bridge * |
| 87 | __fpga_bridge_register(struct device *parent, const char *name, |
| 88 | const struct fpga_bridge_ops *br_ops, void *priv, |
| 89 | struct module *owner); |
| 90 | void fpga_bridge_unregister(struct fpga_bridge *br); |
| 91 | |
| 92 | #endif /* _LINUX_FPGA_BRIDGE_H */ |
| 93 | |