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