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; |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 20 | }; |
| 21 | |
Sakari Ailus | 2bd5452 | 2017-03-28 10:52:25 +0300 | [diff] [blame] | 22 | /** |
| 23 | * struct fwnode_endpoint - Fwnode graph endpoint |
| 24 | * @port: Port number |
| 25 | * @id: Endpoint id |
| 26 | * @local_fwnode: reference to the related fwnode |
| 27 | */ |
| 28 | struct fwnode_endpoint { |
| 29 | unsigned int port; |
| 30 | unsigned int id; |
| 31 | const struct fwnode_handle *local_fwnode; |
| 32 | }; |
| 33 | |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 34 | #define NR_FWNODE_REFERENCE_ARGS 8 |
| 35 | |
| 36 | /** |
| 37 | * struct fwnode_reference_args - Fwnode reference with additional arguments |
| 38 | * @fwnode:- A reference to the base fwnode |
| 39 | * @nargs: Number of elements in @args array |
| 40 | * @args: Integer arguments on the fwnode |
| 41 | */ |
| 42 | struct fwnode_reference_args { |
| 43 | struct fwnode_handle *fwnode; |
| 44 | unsigned int nargs; |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 45 | u64 args[NR_FWNODE_REFERENCE_ARGS]; |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 46 | }; |
| 47 | |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 48 | /** |
| 49 | * struct fwnode_operations - Operations for fwnode interface |
| 50 | * @get: Get a reference to an fwnode. |
| 51 | * @put: Put a reference to an fwnode. |
Sinan Kaya | b283f15 | 2017-12-13 02:20:49 -0500 | [diff] [blame] | 52 | * @device_get_match_data: Return the device driver match data. |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 53 | * @property_present: Return true if a property is present. |
| 54 | * @property_read_integer_array: Read an array of integer properties. Return |
| 55 | * zero on success, a negative error code |
| 56 | * otherwise. |
| 57 | * @property_read_string_array: Read an array of string properties. Return zero |
| 58 | * on success, a negative error code otherwise. |
| 59 | * @get_parent: Return the parent of an fwnode. |
| 60 | * @get_next_child_node: Return the next child node in an iteration. |
| 61 | * @get_named_child_node: Return a child node with a given name. |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 62 | * @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] | 63 | * @graph_get_next_endpoint: Return an endpoint node in an iteration. |
| 64 | * @graph_get_remote_endpoint: Return the remote endpoint node of a local |
| 65 | * endpoint node. |
| 66 | * @graph_get_port_parent: Return the parent node of a port node. |
| 67 | * @graph_parse_endpoint: Parse endpoint for port and endpoint id. |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 68 | */ |
| 69 | struct fwnode_operations { |
Sakari Ailus | cf89a31 | 2017-09-19 12:39:11 +0300 | [diff] [blame] | 70 | struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 71 | void (*put)(struct fwnode_handle *fwnode); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 72 | bool (*device_is_available)(const struct fwnode_handle *fwnode); |
Andy Shevchenko | 67dcc26 | 2018-02-09 17:38:36 +0200 | [diff] [blame] | 73 | const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, |
| 74 | const struct device *dev); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 75 | bool (*property_present)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 76 | const char *propname); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 77 | int (*property_read_int_array)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 78 | const char *propname, |
| 79 | unsigned int elem_size, void *val, |
| 80 | size_t nval); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 81 | int |
| 82 | (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, |
| 83 | const char *propname, const char **val, |
| 84 | size_t nval); |
| 85 | struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 86 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 87 | (*get_next_child_node)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 88 | struct fwnode_handle *child); |
| 89 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 90 | (*get_named_child_node)(const struct fwnode_handle *fwnode, |
| 91 | const char *name); |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 92 | int (*get_reference_args)(const struct fwnode_handle *fwnode, |
| 93 | const char *prop, const char *nargs_prop, |
| 94 | unsigned int nargs, unsigned int index, |
| 95 | struct fwnode_reference_args *args); |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 96 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 97 | (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 98 | struct fwnode_handle *prev); |
| 99 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 100 | (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode); |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 101 | struct fwnode_handle * |
| 102 | (*graph_get_port_parent)(struct fwnode_handle *fwnode); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 103 | int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 104 | struct fwnode_endpoint *endpoint); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | #define fwnode_has_op(fwnode, op) \ |
| 108 | ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) |
| 109 | #define fwnode_call_int_op(fwnode, op, ...) \ |
| 110 | (fwnode ? (fwnode_has_op(fwnode, op) ? \ |
| 111 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ |
| 112 | -EINVAL) |
Sakari Ailus | e8158b48 | 2017-07-11 18:20:20 +0300 | [diff] [blame] | 113 | #define fwnode_call_bool_op(fwnode, op, ...) \ |
| 114 | (fwnode ? (fwnode_has_op(fwnode, op) ? \ |
| 115 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \ |
| 116 | false) |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 117 | #define fwnode_call_ptr_op(fwnode, op, ...) \ |
| 118 | (fwnode_has_op(fwnode, op) ? \ |
| 119 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL) |
| 120 | #define fwnode_call_void_op(fwnode, op, ...) \ |
| 121 | do { \ |
| 122 | if (fwnode_has_op(fwnode, op)) \ |
| 123 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ |
| 124 | } while (false) |
| 125 | |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 126 | #endif |