aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/acpi.h4
-rw-r--r--include/linux/fwnode.h54
-rw-r--r--include/linux/of.h2
3 files changed, 60 insertions, 0 deletions
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 137e4a3d89c5..b8f23c521b67 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -56,6 +56,9 @@ static inline acpi_handle acpi_device_handle(struct acpi_device *adev)
56 acpi_fwnode_handle(adev) : NULL) 56 acpi_fwnode_handle(adev) : NULL)
57#define ACPI_HANDLE(dev) acpi_device_handle(ACPI_COMPANION(dev)) 57#define ACPI_HANDLE(dev) acpi_device_handle(ACPI_COMPANION(dev))
58 58
59
60extern const struct fwnode_operations acpi_fwnode_ops;
61
59static inline struct fwnode_handle *acpi_alloc_fwnode_static(void) 62static inline struct fwnode_handle *acpi_alloc_fwnode_static(void)
60{ 63{
61 struct fwnode_handle *fwnode; 64 struct fwnode_handle *fwnode;
@@ -65,6 +68,7 @@ static inline struct fwnode_handle *acpi_alloc_fwnode_static(void)
65 return NULL; 68 return NULL;
66 69
67 fwnode->type = FWNODE_ACPI_STATIC; 70 fwnode->type = FWNODE_ACPI_STATIC;
71 fwnode->ops = &acpi_fwnode_ops;
68 72
69 return fwnode; 73 return fwnode;
70} 74}
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index 3dff2398a5f0..8f64b3ae9c57 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -12,6 +12,8 @@
12#ifndef _LINUX_FWNODE_H_ 12#ifndef _LINUX_FWNODE_H_
13#define _LINUX_FWNODE_H_ 13#define _LINUX_FWNODE_H_
14 14
15#include <linux/types.h>
16
15enum fwnode_type { 17enum fwnode_type {
16 FWNODE_INVALID = 0, 18 FWNODE_INVALID = 0,
17 FWNODE_OF, 19 FWNODE_OF,
@@ -22,9 +24,12 @@ enum fwnode_type {
22 FWNODE_IRQCHIP 24 FWNODE_IRQCHIP
23}; 25};
24 26
27struct fwnode_operations;
28
25struct fwnode_handle { 29struct fwnode_handle {
26 enum fwnode_type type; 30 enum fwnode_type type;
27 struct fwnode_handle *secondary; 31 struct fwnode_handle *secondary;
32 const struct fwnode_operations *ops;
28}; 33};
29 34
30/** 35/**
@@ -39,4 +44,53 @@ struct fwnode_endpoint {
39 const struct fwnode_handle *local_fwnode; 44 const struct fwnode_handle *local_fwnode;
40}; 45};
41 46
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.
60 */
61struct fwnode_operations {
62 void (*get)(struct fwnode_handle *fwnode);
63 void (*put)(struct fwnode_handle *fwnode);
64 bool (*property_present)(struct fwnode_handle *fwnode,
65 const char *propname);
66 int (*property_read_int_array)(struct fwnode_handle *fwnode,
67 const char *propname,
68 unsigned int elem_size, void *val,
69 size_t nval);
70 int (*property_read_string_array)(struct fwnode_handle *fwnode_handle,
71 const char *propname,
72 const char **val, size_t nval);
73 struct fwnode_handle *(*get_parent)(struct fwnode_handle *fwnode);
74 struct fwnode_handle *
75 (*get_next_child_node)(struct fwnode_handle *fwnode,
76 struct fwnode_handle *child);
77 struct fwnode_handle *
78 (*get_named_child_node)(struct fwnode_handle *fwnode, const char *name);
79};
80
81#define fwnode_has_op(fwnode, op) \
82 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
83#define fwnode_call_int_op(fwnode, op, ...) \
84 (fwnode ? (fwnode_has_op(fwnode, op) ? \
85 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
86 -EINVAL)
87#define fwnode_call_ptr_op(fwnode, op, ...) \
88 (fwnode_has_op(fwnode, op) ? \
89 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
90#define fwnode_call_void_op(fwnode, op, ...) \
91 do { \
92 if (fwnode_has_op(fwnode, op)) \
93 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
94 } while (false)
95
42#endif 96#endif
diff --git a/include/linux/of.h b/include/linux/of.h
index 29b7b738b509..cdbfa88c32cf 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -100,10 +100,12 @@ struct of_reconfig_data {
100 100
101/* initialize a node */ 101/* initialize a node */
102extern struct kobj_type of_node_ktype; 102extern struct kobj_type of_node_ktype;
103extern const struct fwnode_operations of_fwnode_ops;
103static inline void of_node_init(struct device_node *node) 104static inline void of_node_init(struct device_node *node)
104{ 105{
105 kobject_init(&node->kobj, &of_node_ktype); 106 kobject_init(&node->kobj, &of_node_ktype);
106 node->fwnode.type = FWNODE_OF; 107 node->fwnode.type = FWNODE_OF;
108 node->fwnode.ops = &of_fwnode_ops;
107} 109}
108 110
109/* true when node is initialized */ 111/* true when node is initialized */