Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 1 | /* |
| 2 | * fwnode.h - Firmware device node object handle type definition. |
| 3 | * |
| 4 | * Copyright (C) 2015, Intel Corporation |
| 5 | * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #ifndef _LINUX_FWNODE_H_ |
| 13 | #define _LINUX_FWNODE_H_ |
| 14 | |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 15 | #include <linux/types.h> |
| 16 | |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 17 | struct fwnode_operations; |
Sinan Kaya | b283f15 | 2017-12-13 02:20:49 -0500 | [diff] [blame] | 18 | struct device; |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 19 | |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 20 | struct fwnode_handle { |
Rafael J. Wysocki | 97badf8 | 2015-04-03 23:23:37 +0200 | [diff] [blame] | 21 | struct fwnode_handle *secondary; |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 22 | const struct fwnode_operations *ops; |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
Sakari Ailus | 2bd5452 | 2017-03-28 10:52:25 +0300 | [diff] [blame] | 25 | /** |
| 26 | * struct fwnode_endpoint - Fwnode graph endpoint |
| 27 | * @port: Port number |
| 28 | * @id: Endpoint id |
| 29 | * @local_fwnode: reference to the related fwnode |
| 30 | */ |
| 31 | struct fwnode_endpoint { |
| 32 | unsigned int port; |
| 33 | unsigned int id; |
| 34 | const struct fwnode_handle *local_fwnode; |
| 35 | }; |
| 36 | |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 37 | #define NR_FWNODE_REFERENCE_ARGS 8 |
| 38 | |
| 39 | /** |
| 40 | * struct fwnode_reference_args - Fwnode reference with additional arguments |
| 41 | * @fwnode:- A reference to the base fwnode |
| 42 | * @nargs: Number of elements in @args array |
| 43 | * @args: Integer arguments on the fwnode |
| 44 | */ |
| 45 | struct fwnode_reference_args { |
| 46 | struct fwnode_handle *fwnode; |
| 47 | unsigned int nargs; |
| 48 | unsigned int args[NR_FWNODE_REFERENCE_ARGS]; |
| 49 | }; |
| 50 | |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 51 | /** |
| 52 | * struct fwnode_operations - Operations for fwnode interface |
| 53 | * @get: Get a reference to an fwnode. |
| 54 | * @put: Put a reference to an fwnode. |
Sinan Kaya | b283f15 | 2017-12-13 02:20:49 -0500 | [diff] [blame] | 55 | * @device_get_match_data: Return the device driver match data. |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 56 | * @property_present: Return true if a property is present. |
| 57 | * @property_read_integer_array: Read an array of integer properties. Return |
| 58 | * zero on success, a negative error code |
| 59 | * otherwise. |
| 60 | * @property_read_string_array: Read an array of string properties. Return zero |
| 61 | * on success, a negative error code otherwise. |
| 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. |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 71 | */ |
| 72 | struct fwnode_operations { |
Sakari Ailus | cf89a31 | 2017-09-19 12:39:11 +0300 | [diff] [blame] | 73 | struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 74 | void (*put)(struct fwnode_handle *fwnode); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 75 | bool (*device_is_available)(const struct fwnode_handle *fwnode); |
Andy Shevchenko | 67dcc26 | 2018-02-09 17:38:36 +0200 | [diff] [blame] | 76 | const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, |
| 77 | const struct device *dev); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 78 | bool (*property_present)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 79 | const char *propname); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 80 | int (*property_read_int_array)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 81 | const char *propname, |
| 82 | unsigned int elem_size, void *val, |
| 83 | size_t nval); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 84 | int |
| 85 | (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, |
| 86 | const char *propname, const char **val, |
| 87 | size_t nval); |
| 88 | struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 89 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 90 | (*get_next_child_node)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 91 | struct fwnode_handle *child); |
| 92 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 93 | (*get_named_child_node)(const struct fwnode_handle *fwnode, |
| 94 | const char *name); |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 95 | int (*get_reference_args)(const struct fwnode_handle *fwnode, |
| 96 | const char *prop, const char *nargs_prop, |
| 97 | unsigned int nargs, unsigned int index, |
| 98 | struct fwnode_reference_args *args); |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 99 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 100 | (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 101 | struct fwnode_handle *prev); |
| 102 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 103 | (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode); |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 104 | struct fwnode_handle * |
| 105 | (*graph_get_port_parent)(struct fwnode_handle *fwnode); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 106 | int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 107 | struct fwnode_endpoint *endpoint); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | #define fwnode_has_op(fwnode, op) \ |
| 111 | ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) |
| 112 | #define fwnode_call_int_op(fwnode, op, ...) \ |
| 113 | (fwnode ? (fwnode_has_op(fwnode, op) ? \ |
| 114 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ |
| 115 | -EINVAL) |
Sakari Ailus | e8158b4 | 2017-07-11 18:20:20 +0300 | [diff] [blame] | 116 | #define fwnode_call_bool_op(fwnode, op, ...) \ |
| 117 | (fwnode ? (fwnode_has_op(fwnode, op) ? \ |
| 118 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \ |
| 119 | false) |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 120 | #define fwnode_call_ptr_op(fwnode, op, ...) \ |
| 121 | (fwnode_has_op(fwnode, op) ? \ |
| 122 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL) |
| 123 | #define fwnode_call_void_op(fwnode, op, ...) \ |
| 124 | do { \ |
| 125 | if (fwnode_has_op(fwnode, op)) \ |
| 126 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ |
| 127 | } while (false) |
| 128 | |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 129 | #endif |