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; |
| 18 | |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 19 | struct fwnode_handle { |
Rafael J. Wysocki | 97badf8 | 2015-04-03 23:23:37 +0200 | [diff] [blame] | 20 | struct fwnode_handle *secondary; |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 21 | const struct fwnode_operations *ops; |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 22 | }; |
| 23 | |
Sakari Ailus | 2bd5452 | 2017-03-28 10:52:25 +0300 | [diff] [blame] | 24 | /** |
| 25 | * struct fwnode_endpoint - Fwnode graph endpoint |
| 26 | * @port: Port number |
| 27 | * @id: Endpoint id |
| 28 | * @local_fwnode: reference to the related fwnode |
| 29 | */ |
| 30 | struct fwnode_endpoint { |
| 31 | unsigned int port; |
| 32 | unsigned int id; |
| 33 | const struct fwnode_handle *local_fwnode; |
| 34 | }; |
| 35 | |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 36 | /** |
| 37 | * struct fwnode_operations - Operations for fwnode interface |
| 38 | * @get: Get a reference to an fwnode. |
| 39 | * @put: Put a reference to an fwnode. |
| 40 | * @property_present: Return true if a property is present. |
| 41 | * @property_read_integer_array: Read an array of integer properties. Return |
| 42 | * zero on success, a negative error code |
| 43 | * otherwise. |
| 44 | * @property_read_string_array: Read an array of string properties. Return zero |
| 45 | * on success, a negative error code otherwise. |
| 46 | * @get_parent: Return the parent of an fwnode. |
| 47 | * @get_next_child_node: Return the next child node in an iteration. |
| 48 | * @get_named_child_node: Return a child node with a given name. |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 49 | * @graph_get_next_endpoint: Return an endpoint node in an iteration. |
| 50 | * @graph_get_remote_endpoint: Return the remote endpoint node of a local |
| 51 | * endpoint node. |
| 52 | * @graph_get_port_parent: Return the parent node of a port node. |
| 53 | * @graph_parse_endpoint: Parse endpoint for port and endpoint id. |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 54 | */ |
| 55 | struct fwnode_operations { |
| 56 | void (*get)(struct fwnode_handle *fwnode); |
| 57 | void (*put)(struct fwnode_handle *fwnode); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame^] | 58 | bool (*device_is_available)(const struct fwnode_handle *fwnode); |
| 59 | bool (*property_present)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 60 | const char *propname); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame^] | 61 | int (*property_read_int_array)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 62 | const char *propname, |
| 63 | unsigned int elem_size, void *val, |
| 64 | size_t nval); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame^] | 65 | int |
| 66 | (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, |
| 67 | const char *propname, const char **val, |
| 68 | size_t nval); |
| 69 | struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 70 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame^] | 71 | (*get_next_child_node)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 72 | struct fwnode_handle *child); |
| 73 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame^] | 74 | (*get_named_child_node)(const struct fwnode_handle *fwnode, |
| 75 | const char *name); |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 76 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame^] | 77 | (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 78 | struct fwnode_handle *prev); |
| 79 | struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame^] | 80 | (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode); |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 81 | struct fwnode_handle * |
| 82 | (*graph_get_port_parent)(struct fwnode_handle *fwnode); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame^] | 83 | int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 84 | struct fwnode_endpoint *endpoint); |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | #define fwnode_has_op(fwnode, op) \ |
| 88 | ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) |
| 89 | #define fwnode_call_int_op(fwnode, op, ...) \ |
| 90 | (fwnode ? (fwnode_has_op(fwnode, op) ? \ |
| 91 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ |
| 92 | -EINVAL) |
Sakari Ailus | e8158b48 | 2017-07-11 18:20:20 +0300 | [diff] [blame] | 93 | #define fwnode_call_bool_op(fwnode, op, ...) \ |
| 94 | (fwnode ? (fwnode_has_op(fwnode, op) ? \ |
| 95 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \ |
| 96 | false) |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 97 | #define fwnode_call_ptr_op(fwnode, op, ...) \ |
| 98 | (fwnode_has_op(fwnode, op) ? \ |
| 99 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL) |
| 100 | #define fwnode_call_void_op(fwnode, op, ...) \ |
| 101 | do { \ |
| 102 | if (fwnode_has_op(fwnode, op)) \ |
| 103 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ |
| 104 | } while (false) |
| 105 | |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 106 | #endif |