1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * fwnode.h - Firmware device node object handle type definition.
5 * Copyright (C) 2015, Intel Corporation
6 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
9 #ifndef _LINUX_FWNODE_H_
10 #define _LINUX_FWNODE_H_
12 #include <linux/types.h>
13 #include <linux/list.h>
15 struct fwnode_operations;
18 struct fwnode_handle {
19 struct fwnode_handle *secondary;
20 const struct fwnode_operations *ops;
22 struct list_head suppliers;
23 struct list_head consumers;
27 struct fwnode_handle *supplier;
28 struct list_head s_hook;
29 struct fwnode_handle *consumer;
30 struct list_head c_hook;
34 * struct fwnode_endpoint - Fwnode graph endpoint
37 * @local_fwnode: reference to the related fwnode
39 struct fwnode_endpoint {
42 const struct fwnode_handle *local_fwnode;
45 #define NR_FWNODE_REFERENCE_ARGS 8
48 * struct fwnode_reference_args - Fwnode reference with additional arguments
49 * @fwnode:- A reference to the base fwnode
50 * @nargs: Number of elements in @args array
51 * @args: Integer arguments on the fwnode
53 struct fwnode_reference_args {
54 struct fwnode_handle *fwnode;
56 u64 args[NR_FWNODE_REFERENCE_ARGS];
60 * struct fwnode_operations - Operations for fwnode interface
61 * @get: Get a reference to an fwnode.
62 * @put: Put a reference to an fwnode.
63 * @device_is_available: Return true if the device is available.
64 * @device_get_match_data: Return the device driver match data.
65 * @property_present: Return true if a property is present.
66 * @property_read_int_array: Read an array of integer properties. Return zero on
67 * success, a negative error code otherwise.
68 * @property_read_string_array: Read an array of string properties. Return zero
69 * on success, a negative error code otherwise.
70 * @get_name: Return the name of an fwnode.
71 * @get_name_prefix: Get a prefix for a node (for printing purposes).
72 * @get_parent: Return the parent of an fwnode.
73 * @get_next_child_node: Return the next child node in an iteration.
74 * @get_named_child_node: Return a child node with a given name.
75 * @get_reference_args: Return a reference pointed to by a property, with args
76 * @graph_get_next_endpoint: Return an endpoint node in an iteration.
77 * @graph_get_remote_endpoint: Return the remote endpoint node of a local
79 * @graph_get_port_parent: Return the parent node of a port node.
80 * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
81 * @add_links: Create fwnode links to all the suppliers of the fwnode. Return
82 * zero on success, a negative error code otherwise.
84 struct fwnode_operations {
85 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
86 void (*put)(struct fwnode_handle *fwnode);
87 bool (*device_is_available)(const struct fwnode_handle *fwnode);
88 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
89 const struct device *dev);
90 bool (*property_present)(const struct fwnode_handle *fwnode,
91 const char *propname);
92 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
94 unsigned int elem_size, void *val,
97 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
98 const char *propname, const char **val,
100 const char *(*get_name)(const struct fwnode_handle *fwnode);
101 const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
102 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
103 struct fwnode_handle *
104 (*get_next_child_node)(const struct fwnode_handle *fwnode,
105 struct fwnode_handle *child);
106 struct fwnode_handle *
107 (*get_named_child_node)(const struct fwnode_handle *fwnode,
109 int (*get_reference_args)(const struct fwnode_handle *fwnode,
110 const char *prop, const char *nargs_prop,
111 unsigned int nargs, unsigned int index,
112 struct fwnode_reference_args *args);
113 struct fwnode_handle *
114 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
115 struct fwnode_handle *prev);
116 struct fwnode_handle *
117 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
118 struct fwnode_handle *
119 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
120 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
121 struct fwnode_endpoint *endpoint);
122 int (*add_links)(struct fwnode_handle *fwnode,
126 #define fwnode_has_op(fwnode, op) \
127 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
128 #define fwnode_call_int_op(fwnode, op, ...) \
129 (fwnode ? (fwnode_has_op(fwnode, op) ? \
130 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
133 #define fwnode_call_bool_op(fwnode, op, ...) \
134 (fwnode_has_op(fwnode, op) ? \
135 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
137 #define fwnode_call_ptr_op(fwnode, op, ...) \
138 (fwnode_has_op(fwnode, op) ? \
139 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
140 #define fwnode_call_void_op(fwnode, op, ...) \
142 if (fwnode_has_op(fwnode, op)) \
143 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
145 #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
147 static inline void fwnode_init(struct fwnode_handle *fwnode,
148 const struct fwnode_operations *ops)
151 INIT_LIST_HEAD(&fwnode->consumers);
152 INIT_LIST_HEAD(&fwnode->suppliers);
155 extern u32 fw_devlink_get_flags(void);
156 int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
157 void fwnode_links_purge(struct fwnode_handle *fwnode);