Merge tag 'sparc-for-6.10-tag1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / include / linux / fwnode.h
CommitLineData
d2912cb1 1/* SPDX-License-Identifier: GPL-2.0-only */
ce793486
RW
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>
ce793486
RW
7 */
8
9#ifndef _LINUX_FWNODE_H_
10#define _LINUX_FWNODE_H_
11
f0ada6da 12#include <linux/bits.h>
74c782cf 13#include <linux/err.h>
4dc3d612
AS
14#include <linux/list.h>
15#include <linux/types.h>
3708184a 16
420b104d
AS
17enum dev_dma_attr {
18 DEV_DMA_NOT_SUPPORTED,
19 DEV_DMA_NON_COHERENT,
20 DEV_DMA_COHERENT,
21};
22
3708184a 23struct fwnode_operations;
b283f157 24struct device;
3708184a 25
c2c724c8 26/*
6a6dfdf8 27 * fwnode flags
c2c724c8 28 *
74c782cf
SK
29 * LINKS_ADDED: The fwnode has already be parsed to add fwnode links.
30 * NOT_DEVICE: The fwnode will never be populated as a struct device.
31 * INITIALIZED: The hardware corresponding to fwnode has been initialized.
5501765a
SK
32 * NEEDS_CHILD_BOUND_ON_ADD: For this fwnode/device to probe successfully, its
33 * driver needs its child devices to be bound with
34 * their respective drivers as soon as they are
35 * added.
8f486cab
SK
36 * BEST_EFFORT: The fwnode/device needs to probe early and might be missing some
37 * suppliers. Only enforce ordering with suppliers that have
38 * drivers.
c2c724c8 39 */
5501765a
SK
40#define FWNODE_FLAG_LINKS_ADDED BIT(0)
41#define FWNODE_FLAG_NOT_DEVICE BIT(1)
42#define FWNODE_FLAG_INITIALIZED BIT(2)
43#define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD BIT(3)
8f486cab 44#define FWNODE_FLAG_BEST_EFFORT BIT(4)
6a6dfdf8 45#define FWNODE_FLAG_VISITED BIT(5)
c2c724c8 46
ce793486 47struct fwnode_handle {
97badf87 48 struct fwnode_handle *secondary;
3708184a 49 const struct fwnode_operations *ops;
7523d330
AS
50
51 /* The below is used solely by device links, don't use otherwise */
372a67c0 52 struct device *dev;
7b337cb3
SK
53 struct list_head suppliers;
54 struct list_head consumers;
c2c724c8 55 u8 flags;
7b337cb3
SK
56};
57
6a6dfdf8
SK
58/*
59 * fwnode link flags
60 *
61 * CYCLE: The fwnode link is part of a cycle. Don't defer probe.
b7e1241d 62 * IGNORE: Completely ignore this link, even during cycle detection.
6a6dfdf8
SK
63 */
64#define FWLINK_FLAG_CYCLE BIT(0)
b7e1241d 65#define FWLINK_FLAG_IGNORE BIT(1)
6a6dfdf8 66
7b337cb3
SK
67struct fwnode_link {
68 struct fwnode_handle *supplier;
69 struct list_head s_hook;
70 struct fwnode_handle *consumer;
71 struct list_head c_hook;
6a6dfdf8 72 u8 flags;
ce793486
RW
73};
74
2bd5452d
SA
75/**
76 * struct fwnode_endpoint - Fwnode graph endpoint
77 * @port: Port number
78 * @id: Endpoint id
79 * @local_fwnode: reference to the related fwnode
80 */
81struct fwnode_endpoint {
82 unsigned int port;
83 unsigned int id;
84 const struct fwnode_handle *local_fwnode;
85};
86
529b56a8
DS
87/*
88 * ports and endpoints defined as software_nodes should all follow a common
89 * naming scheme; use these macros to ensure commonality.
90 */
91#define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"
92#define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u"
93
3e3119d3
SA
94#define NR_FWNODE_REFERENCE_ARGS 8
95
96/**
97 * struct fwnode_reference_args - Fwnode reference with additional arguments
98 * @fwnode:- A reference to the base fwnode
99 * @nargs: Number of elements in @args array
100 * @args: Integer arguments on the fwnode
101 */
102struct fwnode_reference_args {
103 struct fwnode_handle *fwnode;
104 unsigned int nargs;
977d5ad3 105 u64 args[NR_FWNODE_REFERENCE_ARGS];
3e3119d3
SA
106};
107
3708184a
SA
108/**
109 * struct fwnode_operations - Operations for fwnode interface
110 * @get: Get a reference to an fwnode.
111 * @put: Put a reference to an fwnode.
8ed61d36 112 * @device_is_available: Return true if the device is available.
b283f157 113 * @device_get_match_data: Return the device driver match data.
3708184a 114 * @property_present: Return true if a property is present.
8ed61d36
HK
115 * @property_read_int_array: Read an array of integer properties. Return zero on
116 * success, a negative error code otherwise.
3708184a
SA
117 * @property_read_string_array: Read an array of string properties. Return zero
118 * on success, a negative error code otherwise.
bc0500c1 119 * @get_name: Return the name of an fwnode.
e7e242bc 120 * @get_name_prefix: Get a prefix for a node (for printing purposes).
3708184a
SA
121 * @get_parent: Return the parent of an fwnode.
122 * @get_next_child_node: Return the next child node in an iteration.
123 * @get_named_child_node: Return a child node with a given name.
3e3119d3 124 * @get_reference_args: Return a reference pointed to by a property, with args
3b27d00e
SA
125 * @graph_get_next_endpoint: Return an endpoint node in an iteration.
126 * @graph_get_remote_endpoint: Return the remote endpoint node of a local
127 * endpoint node.
128 * @graph_get_port_parent: Return the parent node of a port node.
129 * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
04f63c21
SK
130 * @add_links: Create fwnode links to all the suppliers of the fwnode. Return
131 * zero on success, a negative error code otherwise.
3708184a
SA
132 */
133struct fwnode_operations {
cf89a31c 134 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
3708184a 135 void (*put)(struct fwnode_handle *fwnode);
37ba983c 136 bool (*device_is_available)(const struct fwnode_handle *fwnode);
67dcc26d
AS
137 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
138 const struct device *dev);
8c756a0a
SA
139 bool (*device_dma_supported)(const struct fwnode_handle *fwnode);
140 enum dev_dma_attr
141 (*device_get_dma_attr)(const struct fwnode_handle *fwnode);
37ba983c 142 bool (*property_present)(const struct fwnode_handle *fwnode,
3708184a 143 const char *propname);
37ba983c 144 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
3708184a
SA
145 const char *propname,
146 unsigned int elem_size, void *val,
147 size_t nval);
37ba983c
SA
148 int
149 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
150 const char *propname, const char **val,
151 size_t nval);
bc0500c1 152 const char *(*get_name)(const struct fwnode_handle *fwnode);
e7e242bc 153 const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
37ba983c 154 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
3708184a 155 struct fwnode_handle *
37ba983c 156 (*get_next_child_node)(const struct fwnode_handle *fwnode,
3708184a
SA
157 struct fwnode_handle *child);
158 struct fwnode_handle *
37ba983c
SA
159 (*get_named_child_node)(const struct fwnode_handle *fwnode,
160 const char *name);
3e3119d3
SA
161 int (*get_reference_args)(const struct fwnode_handle *fwnode,
162 const char *prop, const char *nargs_prop,
163 unsigned int nargs, unsigned int index,
164 struct fwnode_reference_args *args);
3b27d00e 165 struct fwnode_handle *
37ba983c 166 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
3b27d00e
SA
167 struct fwnode_handle *prev);
168 struct fwnode_handle *
37ba983c 169 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
3b27d00e
SA
170 struct fwnode_handle *
171 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
37ba983c 172 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
3b27d00e 173 struct fwnode_endpoint *endpoint);
68b979d0 174 void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index);
99c63707 175 int (*irq_get)(const struct fwnode_handle *fwnode, unsigned int index);
2d09e6eb 176 int (*add_links)(struct fwnode_handle *fwnode);
3708184a
SA
177};
178
002752af
AS
179#define fwnode_has_op(fwnode, op) \
180 (!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op)
181
3708184a 182#define fwnode_call_int_op(fwnode, op, ...) \
002752af
AS
183 (fwnode_has_op(fwnode, op) ? \
184 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO))
149f3b87
AS
185
186#define fwnode_call_bool_op(fwnode, op, ...) \
187 (fwnode_has_op(fwnode, op) ? \
188 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
189
3708184a
SA
190#define fwnode_call_ptr_op(fwnode, op, ...) \
191 (fwnode_has_op(fwnode, op) ? \
192 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
193#define fwnode_call_void_op(fwnode, op, ...) \
194 do { \
195 if (fwnode_has_op(fwnode, op)) \
196 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
197 } while (false)
198
01bb86b3
SK
199static inline void fwnode_init(struct fwnode_handle *fwnode,
200 const struct fwnode_operations *ops)
201{
202 fwnode->ops = ops;
7b337cb3
SK
203 INIT_LIST_HEAD(&fwnode->consumers);
204 INIT_LIST_HEAD(&fwnode->suppliers);
01bb86b3
SK
205}
206
74c782cf
SK
207static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
208 bool initialized)
209{
210 if (IS_ERR_OR_NULL(fwnode))
211 return;
212
213 if (initialized)
214 fwnode->flags |= FWNODE_FLAG_INITIALIZED;
215 else
216 fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
217}
218
75cde56a
SK
219int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup,
220 u8 flags);
7b337cb3 221void fwnode_links_purge(struct fwnode_handle *fwnode);
28ec344b 222void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
bbf6cfba 223bool fw_devlink_is_strict(void);
8375e74f 224
ce793486 225#endif