Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 2 | /* |
| 3 | * fwnode.h - Firmware device node object handle type definition. |
| 4 | * |
| 5 | * Copyright (C) 2015, Intel Corporation |
| 6 | * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _LINUX_FWNODE_H_ |
| 10 | #define _LINUX_FWNODE_H_ |
| 11 | |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 12 | #include <linux/types.h> |
| 13 | |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 14 | struct fwnode_operations; |
Sinan Kaya | b283f15 | 2017-12-13 02:20:49 -0500 | [diff] [blame] | 15 | struct device; |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 16 | |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 17 | struct fwnode_handle { |
Rafael J. Wysocki | 97badf8 | 2015-04-03 23:23:37 +0200 | [diff] [blame] | 18 | struct fwnode_handle *secondary; |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 19 | const struct fwnode_operations *ops; |
Saravana Kannan | 372a67c | 2019-09-04 14:11:20 -0700 | [diff] [blame] | 20 | struct device *dev; |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 21 | }; |
| 22 | |
Sakari Ailus | 2bd5452 | 2017-03-28 10:52:25 +0300 | [diff] [blame] | 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 | |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 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; |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 46 | u64 args[NR_FWNODE_REFERENCE_ARGS]; |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 47 | }; |
| 48 | |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 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. |
Heikki Krogerus | 8ed61d3 | 2019-10-08 16:26:06 +0300 | [diff] [blame] | 53 | * @device_is_available: Return true if the device is available. |
Sinan Kaya | b283f15 | 2017-12-13 02:20:49 -0500 | [diff] [blame] | 54 | * @device_get_match_data: Return the device driver match data. |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 55 | * @property_present: Return true if a property is present. |
Heikki Krogerus | 8ed61d3 | 2019-10-08 16:26:06 +0300 | [diff] [blame] | 56 | * @property_read_int_array: Read an array of integer properties. Return zero on |
| 57 | * success, a negative error code otherwise. |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 58 | * @property_read_string_array: Read an array of string properties. Return zero |
| 59 | * on success, a negative error code otherwise. |
Sakari Ailus | bc0500c | 2019-10-03 15:32:12 +0300 | [diff] [blame] | 60 | * @get_name: Return the name of an fwnode. |
Sakari Ailus | e7e242b | 2019-10-03 15:32:13 +0300 | [diff] [blame] | 61 | * @get_name_prefix: Get a prefix for a node (for printing purposes). |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 62 | * @get_parent: Return the parent of an fwnode. |
| 63 | * @get_next_child_node: Return the next child node in an iteration. |
| 64 | * @get_named_child_node: Return a child node with a given name. |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 65 | * @get_reference_args: Return a reference pointed to by a property, with args |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 66 | * @graph_get_next_endpoint: Return an endpoint node in an iteration. |
| 67 | * @graph_get_remote_endpoint: Return the remote endpoint node of a local |
| 68 | * endpoint node. |
| 69 | * @graph_get_port_parent: Return the parent node of a port node. |
| 70 | * @graph_parse_endpoint: Parse endpoint for port and endpoint id. |
Saravana Kannan | e2ae9bc | 2019-09-04 14:11:21 -0700 | [diff] [blame] | 71 | * @add_links: Called after the device corresponding to the fwnode is added |
| 72 | * using device_add(). The function is expected to create device |
| 73 | * links to all the suppliers of the device that are available at |
| 74 | * the time this function is called. The function must NOT stop |
| 75 | * at the first failed device link if other unlinked supplier |
Saravana Kannan | 92df01e | 2019-10-11 12:15:20 -0700 | [diff] [blame] | 76 | * devices are present in the system. This is necessary for the |
| 77 | * driver/bus sync_state() callbacks to work correctly. |
| 78 | * |
| 79 | * For example, say Device-C depends on suppliers Device-S1 and |
| 80 | * Device-S2 and the dependency is listed in that order in the |
| 81 | * firmware. Say, S1 gets populated from the firmware after |
| 82 | * late_initcall_sync(). Say S2 is populated and probed way |
| 83 | * before that in device_initcall(). When C is populated, if this |
| 84 | * add_links() function doesn't continue past a "failed linking to |
| 85 | * S1" and continue linking C to S2, then S2 will get a |
| 86 | * sync_state() callback before C is probed. This is because from |
| 87 | * the perspective of S2, C was never a consumer when its |
| 88 | * sync_state() evaluation is done. To avoid this, the add_links() |
| 89 | * function has to go through all available suppliers of the |
| 90 | * device (that corresponds to this fwnode) and link to them |
| 91 | * before returning. |
| 92 | * |
| 93 | * If some suppliers are not yet available (indicated by an error |
| 94 | * return value), this function will be called again when other |
Saravana Kannan | e2ae9bc | 2019-09-04 14:11:21 -0700 | [diff] [blame] | 95 | * devices are added to allow creating device links to any newly |
| 96 | * available suppliers. |
| 97 | * |
| 98 | * Return 0 if device links have been successfully created to all |
Saravana Kannan | bee3bbe6 | 2019-11-12 18:35:59 -0800 | [diff] [blame] | 99 | * the known suppliers of this device or if the supplier |
| 100 | * information is not known. |
Saravana Kannan | 0332450 | 2019-10-28 15:00:24 -0700 | [diff] [blame] | 101 | * |
Saravana Kannan | bee3bbe6 | 2019-11-12 18:35:59 -0800 | [diff] [blame] | 102 | * Return -ENODEV if the suppliers needed for probing this device |
| 103 | * have not been registered yet (because device links can only be |
| 104 | * created to devices registered with the driver core). |
Saravana Kannan | 0332450 | 2019-10-28 15:00:24 -0700 | [diff] [blame] | 105 | * |
Saravana Kannan | bee3bbe6 | 2019-11-12 18:35:59 -0800 | [diff] [blame] | 106 | * Return -EAGAIN if some of the suppliers of this device have not |
| 107 | * been registered yet, but none of those suppliers are necessary |
| 108 | * for probing the device. |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 109 | */ |
| 110 | struct fwnode_operations { |
Sakari Ailus | cf89a31 | 2017-09-19 12:39:11 +0300 | [diff] [blame] | 111 | struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 112 | void (*put)(struct fwnode_handle *fwnode); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 113 | bool (*device_is_available)(const struct fwnode_handle *fwnode); |
Andy Shevchenko | 67dcc26 | 2018-02-09 17:38:36 +0200 | [diff] [blame] | 114 | const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, |
| 115 | const struct device *dev); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 116 | bool (*property_present)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 117 | const char *propname); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 118 | int (*property_read_int_array)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 119 | const char *propname, |
| 120 | unsigned int elem_size, void *val, |
| 121 | size_t nval); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 122 | int |
| 123 | (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, |
| 124 | const char *propname, const char **val, |
| 125 | size_t nval); |
Sakari Ailus | bc0500c | 2019-10-03 15:32:12 +0300 | [diff] [blame] | 126 | const char *(*get_name)(const struct fwnode_handle *fwnode); |
Sakari Ailus | e7e242b | 2019-10-03 15:32:13 +0300 | [diff] [blame] | 127 | const char *(*get_name_prefix)(const struct fwnode_handle *fwnode); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 128 | struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 129 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 130 | (*get_next_child_node)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 131 | struct fwnode_handle *child); |
| 132 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 133 | (*get_named_child_node)(const struct fwnode_handle *fwnode, |
| 134 | const char *name); |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 135 | int (*get_reference_args)(const struct fwnode_handle *fwnode, |
| 136 | const char *prop, const char *nargs_prop, |
| 137 | unsigned int nargs, unsigned int index, |
| 138 | struct fwnode_reference_args *args); |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 139 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 140 | (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 141 | struct fwnode_handle *prev); |
| 142 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 143 | (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode); |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 144 | struct fwnode_handle * |
| 145 | (*graph_get_port_parent)(struct fwnode_handle *fwnode); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 146 | int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 147 | struct fwnode_endpoint *endpoint); |
Saravana Kannan | e2ae9bc | 2019-09-04 14:11:21 -0700 | [diff] [blame] | 148 | int (*add_links)(const struct fwnode_handle *fwnode, |
| 149 | struct device *dev); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | #define fwnode_has_op(fwnode, op) \ |
| 153 | ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) |
| 154 | #define fwnode_call_int_op(fwnode, op, ...) \ |
| 155 | (fwnode ? (fwnode_has_op(fwnode, op) ? \ |
| 156 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ |
| 157 | -EINVAL) |
Andy Shevchenko | 149f3b8 | 2019-08-23 23:32:27 +0300 | [diff] [blame] | 158 | |
| 159 | #define fwnode_call_bool_op(fwnode, op, ...) \ |
| 160 | (fwnode_has_op(fwnode, op) ? \ |
| 161 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) |
| 162 | |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 163 | #define fwnode_call_ptr_op(fwnode, op, ...) \ |
| 164 | (fwnode_has_op(fwnode, op) ? \ |
| 165 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL) |
| 166 | #define fwnode_call_void_op(fwnode, op, ...) \ |
| 167 | do { \ |
| 168 | if (fwnode_has_op(fwnode, op)) \ |
| 169 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ |
| 170 | } while (false) |
Saravana Kannan | 372a67c | 2019-09-04 14:11:20 -0700 | [diff] [blame] | 171 | #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 172 | |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 173 | #endif |