1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * fwnode.h - Firmware device node object handle type definition. 4 * 5 * Copyright (C) 2015, Intel Corporation 6 * Author: Rafael J. Wysocki <[email protected]> 7 */ 8 9 #ifndef _LINUX_FWNODE_H_ 10 #define _LINUX_FWNODE_H_ 11 12 #include <linux/types.h> 13 14 struct fwnode_operations; 15 struct device; 16 17 struct fwnode_handle { 18 struct fwnode_handle *secondary; 19 const struct fwnode_operations *ops; 20 struct device *dev; 21 }; 22 23 /** 24 * struct fwnode_endpoint - Fwnode graph endpoint 25 * @port: Port number 26 * @id: Endpoint id 27 * @local_fwnode: reference to the related fwnode 28 */ 29 struct fwnode_endpoint { 30 unsigned int port; 31 unsigned int id; 32 const struct fwnode_handle *local_fwnode; 33 }; 34 35 #define NR_FWNODE_REFERENCE_ARGS 8 36 37 /** 38 * struct fwnode_reference_args - Fwnode reference with additional arguments 39 * @fwnode:- A reference to the base fwnode 40 * @nargs: Number of elements in @args array 41 * @args: Integer arguments on the fwnode 42 */ 43 struct fwnode_reference_args { 44 struct fwnode_handle *fwnode; 45 unsigned int nargs; 46 u64 args[NR_FWNODE_REFERENCE_ARGS]; 47 }; 48 49 /** 50 * struct fwnode_operations - Operations for fwnode interface 51 * @get: Get a reference to an fwnode. 52 * @put: Put a reference to an fwnode. 53 * @device_get_match_data: Return the device driver match data. 54 * @property_present: Return true if a property is present. 55 * @property_read_integer_array: Read an array of integer properties. Return 56 * zero on success, a negative error code 57 * otherwise. 58 * @property_read_string_array: Read an array of string properties. Return zero 59 * on success, a negative error code otherwise. 60 * @get_parent: Return the parent of an fwnode. 61 * @get_next_child_node: Return the next child node in an iteration. 62 * @get_named_child_node: Return a child node with a given name. 63 * @get_reference_args: Return a reference pointed to by a property, with args 64 * @graph_get_next_endpoint: Return an endpoint node in an iteration. 65 * @graph_get_remote_endpoint: Return the remote endpoint node of a local 66 * endpoint node. 67 * @graph_get_port_parent: Return the parent node of a port node. 68 * @graph_parse_endpoint: Parse endpoint for port and endpoint id. 69 * @add_links: Called after the device corresponding to the fwnode is added 70 * using device_add(). The function is expected to create device 71 * links to all the suppliers of the device that are available at 72 * the time this function is called. The function must NOT stop 73 * at the first failed device link if other unlinked supplier 74 * devices are present in the system. If some suppliers are not 75 * yet available, this function will be called again when other 76 * devices are added to allow creating device links to any newly 77 * available suppliers. 78 * 79 * Return 0 if device links have been successfully created to all 80 * the suppliers of this device or if the supplier information is 81 * not known. Return an error if and only if the supplier 82 * information is known but some of the suppliers are not yet 83 * available to create device links to. 84 */ 85 struct fwnode_operations { 86 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); 87 void (*put)(struct fwnode_handle *fwnode); 88 bool (*device_is_available)(const struct fwnode_handle *fwnode); 89 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, 90 const struct device *dev); 91 bool (*property_present)(const struct fwnode_handle *fwnode, 92 const char *propname); 93 int (*property_read_int_array)(const struct fwnode_handle *fwnode, 94 const char *propname, 95 unsigned int elem_size, void *val, 96 size_t nval); 97 int 98 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, 99 const char *propname, const char **val, 100 size_t nval); 101 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); 102 struct fwnode_handle * 103 (*get_next_child_node)(const struct fwnode_handle *fwnode, 104 struct fwnode_handle *child); 105 struct fwnode_handle * 106 (*get_named_child_node)(const struct fwnode_handle *fwnode, 107 const char *name); 108 int (*get_reference_args)(const struct fwnode_handle *fwnode, 109 const char *prop, const char *nargs_prop, 110 unsigned int nargs, unsigned int index, 111 struct fwnode_reference_args *args); 112 struct fwnode_handle * 113 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode, 114 struct fwnode_handle *prev); 115 struct fwnode_handle * 116 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode); 117 struct fwnode_handle * 118 (*graph_get_port_parent)(struct fwnode_handle *fwnode); 119 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, 120 struct fwnode_endpoint *endpoint); 121 int (*add_links)(const struct fwnode_handle *fwnode, 122 struct device *dev); 123 }; 124 125 #define fwnode_has_op(fwnode, op) \ 126 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) 127 #define fwnode_call_int_op(fwnode, op, ...) \ 128 (fwnode ? (fwnode_has_op(fwnode, op) ? \ 129 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ 130 -EINVAL) 131 132 #define fwnode_call_bool_op(fwnode, op, ...) \ 133 (fwnode_has_op(fwnode, op) ? \ 134 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) 135 136 #define fwnode_call_ptr_op(fwnode, op, ...) \ 137 (fwnode_has_op(fwnode, op) ? \ 138 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL) 139 #define fwnode_call_void_op(fwnode, op, ...) \ 140 do { \ 141 if (fwnode_has_op(fwnode, op)) \ 142 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ 143 } while (false) 144 #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) 145 146 #endif 147