Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
b31384fa RW |
2 | /* |
3 | * property.h - Unified device property interface. | |
4 | * | |
5 | * Copyright (C) 2014, Intel Corporation | |
6 | * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | |
7 | * Mika Westerberg <mika.westerberg@linux.intel.com> | |
b31384fa RW |
8 | */ |
9 | ||
10 | #ifndef _LINUX_PROPERTY_H_ | |
11 | #define _LINUX_PROPERTY_H_ | |
12 | ||
1dc05a27 | 13 | #include <linux/args.h> |
4dc3d612 | 14 | #include <linux/array_size.h> |
0fcc2bdc | 15 | #include <linux/bits.h> |
59ed5e2d | 16 | #include <linux/cleanup.h> |
ce793486 | 17 | #include <linux/fwnode.h> |
40eb28dc | 18 | #include <linux/stddef.h> |
b31384fa RW |
19 | #include <linux/types.h> |
20 | ||
21 | struct device; | |
22 | ||
23 | enum dev_prop_type { | |
24 | DEV_PROP_U8, | |
25 | DEV_PROP_U16, | |
26 | DEV_PROP_U32, | |
27 | DEV_PROP_U64, | |
28 | DEV_PROP_STRING, | |
e64b674b | 29 | DEV_PROP_REF, |
b31384fa RW |
30 | }; |
31 | ||
b295d484 AS |
32 | const struct fwnode_handle *__dev_fwnode_const(const struct device *dev); |
33 | struct fwnode_handle *__dev_fwnode(struct device *dev); | |
34 | #define dev_fwnode(dev) \ | |
35 | _Generic((dev), \ | |
36 | const struct device *: __dev_fwnode_const, \ | |
37 | struct device *: __dev_fwnode)(dev) | |
e44bb0cb | 38 | |
046b6a17 | 39 | bool device_property_present(const struct device *dev, const char *propname); |
bb391410 | 40 | bool device_property_read_bool(const struct device *dev, const char *propname); |
046b6a17 | 41 | int device_property_read_u8_array(const struct device *dev, const char *propname, |
b31384fa | 42 | u8 *val, size_t nval); |
046b6a17 | 43 | int device_property_read_u16_array(const struct device *dev, const char *propname, |
b31384fa | 44 | u16 *val, size_t nval); |
046b6a17 | 45 | int device_property_read_u32_array(const struct device *dev, const char *propname, |
b31384fa | 46 | u32 *val, size_t nval); |
046b6a17 | 47 | int device_property_read_u64_array(const struct device *dev, const char *propname, |
b31384fa | 48 | u64 *val, size_t nval); |
046b6a17 | 49 | int device_property_read_string_array(const struct device *dev, const char *propname, |
b31384fa | 50 | const char **val, size_t nval); |
046b6a17 | 51 | int device_property_read_string(const struct device *dev, const char *propname, |
b31384fa | 52 | const char **val); |
046b6a17 | 53 | int device_property_match_string(const struct device *dev, |
3f5c8d31 | 54 | const char *propname, const char *string); |
b31384fa | 55 | |
37ba983c SA |
56 | bool fwnode_property_present(const struct fwnode_handle *fwnode, |
57 | const char *propname); | |
bb391410 RHA |
58 | bool fwnode_property_read_bool(const struct fwnode_handle *fwnode, |
59 | const char *propname); | |
37ba983c | 60 | int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
61 | const char *propname, u8 *val, |
62 | size_t nval); | |
37ba983c | 63 | int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
64 | const char *propname, u16 *val, |
65 | size_t nval); | |
37ba983c | 66 | int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
67 | const char *propname, u32 *val, |
68 | size_t nval); | |
37ba983c | 69 | int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
70 | const char *propname, u64 *val, |
71 | size_t nval); | |
37ba983c | 72 | int fwnode_property_read_string_array(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
73 | const char *propname, const char **val, |
74 | size_t nval); | |
37ba983c | 75 | int fwnode_property_read_string(const struct fwnode_handle *fwnode, |
8a0662d9 | 76 | const char *propname, const char **val); |
37ba983c | 77 | int fwnode_property_match_string(const struct fwnode_handle *fwnode, |
3f5c8d31 | 78 | const char *propname, const char *string); |
a521075d AS |
79 | |
80 | bool fwnode_device_is_available(const struct fwnode_handle *fwnode); | |
81 | ||
826a5d8c AS |
82 | static inline bool fwnode_device_is_big_endian(const struct fwnode_handle *fwnode) |
83 | { | |
84 | if (fwnode_property_present(fwnode, "big-endian")) | |
85 | return true; | |
86 | if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) && | |
87 | fwnode_property_present(fwnode, "native-endian")) | |
88 | return true; | |
89 | return false; | |
90 | } | |
91 | ||
a521075d AS |
92 | static inline |
93 | bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat) | |
94 | { | |
95 | return fwnode_property_match_string(fwnode, "compatible", compat) >= 0; | |
96 | } | |
97 | ||
826a5d8c AS |
98 | /** |
99 | * device_is_big_endian - check if a device has BE registers | |
100 | * @dev: Pointer to the struct device | |
101 | * | |
102 | * Returns: true if the device has a "big-endian" property, or if the kernel | |
103 | * was compiled for BE *and* the device has a "native-endian" property. | |
104 | * Returns false otherwise. | |
105 | * | |
106 | * Callers would nominally use ioread32be/iowrite32be if | |
107 | * device_is_big_endian() == true, or readl/writel otherwise. | |
108 | */ | |
109 | static inline bool device_is_big_endian(const struct device *dev) | |
110 | { | |
111 | return fwnode_device_is_big_endian(dev_fwnode(dev)); | |
112 | } | |
113 | ||
2de5897b AS |
114 | /** |
115 | * device_is_compatible - match 'compatible' property of the device with a given string | |
116 | * @dev: Pointer to the struct device | |
117 | * @compat: The string to match 'compatible' property with | |
118 | * | |
119 | * Returns: true if matches, otherwise false. | |
120 | */ | |
121 | static inline bool device_is_compatible(const struct device *dev, const char *compat) | |
122 | { | |
123 | return fwnode_device_is_compatible(dev_fwnode(dev), compat); | |
124 | } | |
125 | ||
fac4a535 AS |
126 | int fwnode_property_match_property_string(const struct fwnode_handle *fwnode, |
127 | const char *propname, | |
128 | const char * const *array, size_t n); | |
129 | ||
130 | static inline | |
131 | int device_property_match_property_string(const struct device *dev, | |
132 | const char *propname, | |
133 | const char * const *array, size_t n) | |
134 | { | |
135 | return fwnode_property_match_property_string(dev_fwnode(dev), propname, array, n); | |
136 | } | |
137 | ||
3e3119d3 SA |
138 | int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, |
139 | const char *prop, const char *nargs_prop, | |
140 | unsigned int nargs, unsigned int index, | |
141 | struct fwnode_reference_args *args); | |
8a0662d9 | 142 | |
83b34afb HK |
143 | struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode, |
144 | const char *name, | |
145 | unsigned int index); | |
146 | ||
bc0500c1 | 147 | const char *fwnode_get_name(const struct fwnode_handle *fwnode); |
e7e242bc | 148 | const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode); |
a9c8c738 | 149 | bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name); |
87ffea09 | 150 | |
37ba983c | 151 | struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode); |
87ffea09 AS |
152 | struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode); |
153 | ||
154 | #define fwnode_for_each_parent_node(fwnode, parent) \ | |
155 | for (parent = fwnode_get_parent(fwnode); parent; \ | |
156 | parent = fwnode_get_next_parent(parent)) | |
157 | ||
87e5e95d SA |
158 | unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); |
159 | struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, | |
160 | unsigned int depth); | |
37ba983c SA |
161 | struct fwnode_handle *fwnode_get_next_child_node( |
162 | const struct fwnode_handle *fwnode, struct fwnode_handle *child); | |
3395de96 MW |
163 | struct fwnode_handle *fwnode_get_next_available_child_node( |
164 | const struct fwnode_handle *fwnode, struct fwnode_handle *child); | |
34055190 MW |
165 | |
166 | #define fwnode_for_each_child_node(fwnode, child) \ | |
167 | for (child = fwnode_get_next_child_node(fwnode, NULL); child; \ | |
168 | child = fwnode_get_next_child_node(fwnode, child)) | |
afaf26fd | 169 | |
f2430363 MV |
170 | #define fwnode_for_each_named_child_node(fwnode, child, name) \ |
171 | fwnode_for_each_child_node(fwnode, child) \ | |
172 | if (!fwnode_name_eq(child, name)) { } else | |
173 | ||
3395de96 MW |
174 | #define fwnode_for_each_available_child_node(fwnode, child) \ |
175 | for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\ | |
176 | child = fwnode_get_next_available_child_node(fwnode, child)) | |
177 | ||
7952cd2b AS |
178 | struct fwnode_handle *device_get_next_child_node(const struct device *dev, |
179 | struct fwnode_handle *child); | |
8a0662d9 | 180 | |
1d656fb7 AS |
181 | #define device_for_each_child_node(dev, child) \ |
182 | for (child = device_get_next_child_node(dev, NULL); child; \ | |
8a0662d9 RW |
183 | child = device_get_next_child_node(dev, child)) |
184 | ||
f2430363 MV |
185 | #define device_for_each_named_child_node(dev, child, name) \ |
186 | device_for_each_child_node(dev, child) \ | |
187 | if (!fwnode_name_eq(child, name)) { } else | |
188 | ||
365130fd JC |
189 | #define device_for_each_child_node_scoped(dev, child) \ |
190 | for (struct fwnode_handle *child __free(fwnode_handle) = \ | |
191 | device_get_next_child_node(dev, NULL); \ | |
192 | child; child = device_get_next_child_node(dev, child)) | |
193 | ||
f2430363 MV |
194 | #define device_for_each_named_child_node_scoped(dev, child, name) \ |
195 | device_for_each_child_node_scoped(dev, child) \ | |
196 | if (!fwnode_name_eq(child, name)) { } else | |
197 | ||
7952cd2b AS |
198 | struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode, |
199 | const char *childname); | |
200 | struct fwnode_handle *device_get_named_child_node(const struct device *dev, | |
613e9721 AT |
201 | const char *childname); |
202 | ||
cf89a31c | 203 | struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode); |
77fc5151 JC |
204 | |
205 | /** | |
206 | * fwnode_handle_put - Drop reference to a device node | |
207 | * @fwnode: Pointer to the device node to drop the reference to. | |
208 | * | |
209 | * This has to be used when terminating device_for_each_child_node() iteration | |
210 | * with break or return to prevent stale device node references from being left | |
211 | * behind. | |
212 | */ | |
213 | static inline void fwnode_handle_put(struct fwnode_handle *fwnode) | |
214 | { | |
215 | fwnode_call_void_op(fwnode, put); | |
216 | } | |
8a0662d9 | 217 | |
59ed5e2d JC |
218 | DEFINE_FREE(fwnode_handle, struct fwnode_handle *, fwnode_handle_put(_T)) |
219 | ||
fb38f314 | 220 | int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index); |
ca0acb51 | 221 | int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name); |
7c6c57f2 | 222 | |
1490cbb9 AS |
223 | unsigned int fwnode_get_child_node_count(const struct fwnode_handle *fwnode); |
224 | ||
225 | static inline unsigned int device_get_child_node_count(const struct device *dev) | |
226 | { | |
227 | return fwnode_get_child_node_count(dev_fwnode(dev)); | |
228 | } | |
8a0662d9 | 229 | |
f2430363 MV |
230 | unsigned int fwnode_get_named_child_node_count(const struct fwnode_handle *fwnode, |
231 | const char *name); | |
232 | static inline unsigned int device_get_named_child_node_count(const struct device *dev, | |
233 | const char *name) | |
234 | { | |
235 | return fwnode_get_named_child_node_count(dev_fwnode(dev), name); | |
236 | } | |
237 | ||
046b6a17 | 238 | static inline int device_property_read_u8(const struct device *dev, |
b31384fa RW |
239 | const char *propname, u8 *val) |
240 | { | |
241 | return device_property_read_u8_array(dev, propname, val, 1); | |
242 | } | |
243 | ||
046b6a17 | 244 | static inline int device_property_read_u16(const struct device *dev, |
b31384fa RW |
245 | const char *propname, u16 *val) |
246 | { | |
247 | return device_property_read_u16_array(dev, propname, val, 1); | |
248 | } | |
249 | ||
046b6a17 | 250 | static inline int device_property_read_u32(const struct device *dev, |
b31384fa RW |
251 | const char *propname, u32 *val) |
252 | { | |
253 | return device_property_read_u32_array(dev, propname, val, 1); | |
254 | } | |
255 | ||
046b6a17 | 256 | static inline int device_property_read_u64(const struct device *dev, |
b31384fa RW |
257 | const char *propname, u64 *val) |
258 | { | |
259 | return device_property_read_u64_array(dev, propname, val, 1); | |
260 | } | |
261 | ||
046b6a17 | 262 | static inline int device_property_count_u8(const struct device *dev, const char *propname) |
33ee09cd AS |
263 | { |
264 | return device_property_read_u8_array(dev, propname, NULL, 0); | |
265 | } | |
266 | ||
046b6a17 | 267 | static inline int device_property_count_u16(const struct device *dev, const char *propname) |
33ee09cd AS |
268 | { |
269 | return device_property_read_u16_array(dev, propname, NULL, 0); | |
270 | } | |
271 | ||
046b6a17 | 272 | static inline int device_property_count_u32(const struct device *dev, const char *propname) |
33ee09cd AS |
273 | { |
274 | return device_property_read_u32_array(dev, propname, NULL, 0); | |
275 | } | |
276 | ||
046b6a17 | 277 | static inline int device_property_count_u64(const struct device *dev, const char *propname) |
33ee09cd AS |
278 | { |
279 | return device_property_read_u64_array(dev, propname, NULL, 0); | |
280 | } | |
281 | ||
046b6a17 | 282 | static inline int device_property_string_array_count(const struct device *dev, |
6b6ff4ac BG |
283 | const char *propname) |
284 | { | |
285 | return device_property_read_string_array(dev, propname, NULL, 0); | |
286 | } | |
287 | ||
37ba983c | 288 | static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
289 | const char *propname, u8 *val) |
290 | { | |
291 | return fwnode_property_read_u8_array(fwnode, propname, val, 1); | |
292 | } | |
293 | ||
37ba983c | 294 | static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
295 | const char *propname, u16 *val) |
296 | { | |
297 | return fwnode_property_read_u16_array(fwnode, propname, val, 1); | |
298 | } | |
299 | ||
37ba983c | 300 | static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
301 | const char *propname, u32 *val) |
302 | { | |
303 | return fwnode_property_read_u32_array(fwnode, propname, val, 1); | |
304 | } | |
305 | ||
37ba983c | 306 | static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode, |
8a0662d9 RW |
307 | const char *propname, u64 *val) |
308 | { | |
309 | return fwnode_property_read_u64_array(fwnode, propname, val, 1); | |
310 | } | |
311 | ||
33ee09cd AS |
312 | static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode, |
313 | const char *propname) | |
314 | { | |
315 | return fwnode_property_read_u8_array(fwnode, propname, NULL, 0); | |
316 | } | |
317 | ||
318 | static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode, | |
319 | const char *propname) | |
320 | { | |
321 | return fwnode_property_read_u16_array(fwnode, propname, NULL, 0); | |
322 | } | |
323 | ||
324 | static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode, | |
325 | const char *propname) | |
326 | { | |
327 | return fwnode_property_read_u32_array(fwnode, propname, NULL, 0); | |
328 | } | |
329 | ||
330 | static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, | |
331 | const char *propname) | |
332 | { | |
333 | return fwnode_property_read_u64_array(fwnode, propname, NULL, 0); | |
334 | } | |
335 | ||
6b6ff4ac BG |
336 | static inline int |
337 | fwnode_property_string_array_count(const struct fwnode_handle *fwnode, | |
338 | const char *propname) | |
339 | { | |
340 | return fwnode_property_read_string_array(fwnode, propname, NULL, 0); | |
341 | } | |
342 | ||
e64b674b DT |
343 | struct software_node; |
344 | ||
345 | /** | |
346 | * struct software_node_ref_args - Reference property with additional arguments | |
347 | * @node: Reference to a software node | |
348 | * @nargs: Number of elements in @args array | |
349 | * @args: Integer arguments | |
350 | */ | |
351 | struct software_node_ref_args { | |
352 | const struct software_node *node; | |
353 | unsigned int nargs; | |
354 | u64 args[NR_FWNODE_REFERENCE_ARGS]; | |
355 | }; | |
356 | ||
e588fead AS |
357 | #define SOFTWARE_NODE_REFERENCE(_ref_, ...) \ |
358 | (const struct software_node_ref_args) { \ | |
359 | .node = _ref_, \ | |
1dc05a27 | 360 | .nargs = COUNT_ARGS(__VA_ARGS__), \ |
e588fead AS |
361 | .args = { __VA_ARGS__ }, \ |
362 | } | |
363 | ||
16ba08d5 RW |
364 | /** |
365 | * struct property_entry - "Built-in" device property representation. | |
366 | * @name: Name of the property. | |
318a1971 | 367 | * @length: Length of data making up the value. |
e6bff466 | 368 | * @is_inline: True when the property value is stored inline. |
63dcc709 | 369 | * @type: Type of the data in unions. |
e6bff466 DT |
370 | * @pointer: Pointer to the property when it is not stored inline. |
371 | * @value: Value of the property when it is stored inline. | |
16ba08d5 RW |
372 | */ |
373 | struct property_entry { | |
374 | const char *name; | |
318a1971 | 375 | size_t length; |
e6bff466 | 376 | bool is_inline; |
63dcc709 | 377 | enum dev_prop_type type; |
16ba08d5 | 378 | union { |
1f74d70f | 379 | const void *pointer; |
66586bab | 380 | union { |
996b0830 DT |
381 | u8 u8_data[sizeof(u64) / sizeof(u8)]; |
382 | u16 u16_data[sizeof(u64) / sizeof(u16)]; | |
383 | u32 u32_data[sizeof(u64) / sizeof(u32)]; | |
384 | u64 u64_data[sizeof(u64) / sizeof(u64)]; | |
385 | const char *str[sizeof(u64) / sizeof(char *)]; | |
66586bab AS |
386 | } value; |
387 | }; | |
16ba08d5 RW |
388 | }; |
389 | ||
d76eebfa | 390 | /* |
daeba9bf | 391 | * Note: the below initializers for the anonymous union are carefully |
d76eebfa AM |
392 | * crafted to avoid gcc-4.4.4's problems with initialization of anon unions |
393 | * and structs. | |
394 | */ | |
40eb28dc AS |
395 | #define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_) \ |
396 | (struct property_entry) { \ | |
397 | .name = _name_, \ | |
398 | .length = (_len_) * sizeof_field(struct property_entry, value._elem_[0]), \ | |
399 | .type = DEV_PROP_##_Type_, \ | |
400 | { .pointer = _val_ }, \ | |
a85f4204 HK |
401 | } |
402 | ||
1741cfac | 403 | #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 404 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_) |
1741cfac | 405 | #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 406 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16_data, U16, _val_, _len_) |
1741cfac | 407 | #define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 408 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32_data, U32, _val_, _len_) |
1741cfac | 409 | #define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 410 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_) |
1741cfac | 411 | #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \ |
daeba9bf | 412 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_) |
c6c76563 | 413 | |
e64b674b | 414 | #define PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, _len_) \ |
40eb28dc AS |
415 | (struct property_entry) { \ |
416 | .name = _name_, \ | |
417 | .length = (_len_) * sizeof(struct software_node_ref_args), \ | |
418 | .type = DEV_PROP_REF, \ | |
419 | { .pointer = _val_ }, \ | |
420 | } | |
a85f4204 | 421 | |
1741cfac DT |
422 | #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \ |
423 | PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
424 | #define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \ | |
425 | PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
426 | #define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \ | |
427 | PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
428 | #define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \ | |
429 | PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
430 | #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \ | |
431 | PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | |
c6c76563 | 432 | #define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_) \ |
e64b674b | 433 | PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) |
1741cfac | 434 | |
daeba9bf DT |
435 | #define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_) \ |
436 | (struct property_entry) { \ | |
437 | .name = _name_, \ | |
40eb28dc | 438 | .length = sizeof_field(struct property_entry, value._elem_[0]), \ |
e6bff466 | 439 | .is_inline = true, \ |
daeba9bf | 440 | .type = DEV_PROP_##_Type_, \ |
996b0830 | 441 | { .value = { ._elem_[0] = _val_ } }, \ |
a85f4204 HK |
442 | } |
443 | ||
daeba9bf DT |
444 | #define PROPERTY_ENTRY_U8(_name_, _val_) \ |
445 | __PROPERTY_ENTRY_ELEMENT(_name_, u8_data, U8, _val_) | |
446 | #define PROPERTY_ENTRY_U16(_name_, _val_) \ | |
447 | __PROPERTY_ENTRY_ELEMENT(_name_, u16_data, U16, _val_) | |
448 | #define PROPERTY_ENTRY_U32(_name_, _val_) \ | |
449 | __PROPERTY_ENTRY_ELEMENT(_name_, u32_data, U32, _val_) | |
450 | #define PROPERTY_ENTRY_U64(_name_, _val_) \ | |
451 | __PROPERTY_ENTRY_ELEMENT(_name_, u64_data, U64, _val_) | |
452 | #define PROPERTY_ENTRY_STRING(_name_, _val_) \ | |
453 | __PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_) | |
a85f4204 | 454 | |
e64b674b DT |
455 | #define PROPERTY_ENTRY_REF(_name_, _ref_, ...) \ |
456 | (struct property_entry) { \ | |
457 | .name = _name_, \ | |
458 | .length = sizeof(struct software_node_ref_args), \ | |
459 | .type = DEV_PROP_REF, \ | |
e588fead | 460 | { .pointer = &SOFTWARE_NODE_REFERENCE(_ref_, ##__VA_ARGS__), }, \ |
e64b674b DT |
461 | } |
462 | ||
c6c76563 AS |
463 | #define PROPERTY_ENTRY_BOOL(_name_) \ |
464 | (struct property_entry) { \ | |
465 | .name = _name_, \ | |
466 | .is_inline = true, \ | |
467 | } | |
468 | ||
2d479e1f DT |
469 | struct property_entry * |
470 | property_entries_dup(const struct property_entry *properties); | |
2d479e1f DT |
471 | void property_entries_free(const struct property_entry *properties); |
472 | ||
59789f34 AS |
473 | bool device_dma_supported(const struct device *dev); |
474 | enum dev_dma_attr device_get_dma_attr(const struct device *dev); | |
b283f157 | 475 | |
aade55c8 | 476 | const void *device_get_match_data(const struct device *dev); |
e5e55864 | 477 | |
4c96b7dc | 478 | int device_get_phy_mode(struct device *dev); |
0a392354 | 479 | int fwnode_get_phy_mode(const struct fwnode_handle *fwnode); |
b2638e56 AS |
480 | |
481 | void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index); | |
482 | ||
07bb80d4 | 483 | struct fwnode_handle *fwnode_graph_get_next_endpoint( |
37ba983c | 484 | const struct fwnode_handle *fwnode, struct fwnode_handle *prev); |
6a71d8d7 | 485 | struct fwnode_handle * |
37ba983c | 486 | fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode); |
07bb80d4 | 487 | struct fwnode_handle *fwnode_graph_get_remote_port_parent( |
37ba983c | 488 | const struct fwnode_handle *fwnode); |
07bb80d4 | 489 | struct fwnode_handle *fwnode_graph_get_remote_port( |
37ba983c | 490 | const struct fwnode_handle *fwnode); |
07bb80d4 | 491 | struct fwnode_handle *fwnode_graph_get_remote_endpoint( |
37ba983c | 492 | const struct fwnode_handle *fwnode); |
07bb80d4 | 493 | |
a1bfed60 | 494 | static inline bool fwnode_graph_is_endpoint(const struct fwnode_handle *fwnode) |
35694afc LP |
495 | { |
496 | return fwnode_property_present(fwnode, "remote-endpoint"); | |
497 | } | |
498 | ||
0fcc2bdc SA |
499 | /* |
500 | * Fwnode lookup flags | |
501 | * | |
502 | * @FWNODE_GRAPH_ENDPOINT_NEXT: In the case of no exact match, look for the | |
503 | * closest endpoint ID greater than the specified | |
504 | * one. | |
505 | * @FWNODE_GRAPH_DEVICE_DISABLED: That the device to which the remote | |
506 | * endpoint of the given endpoint belongs to, | |
49f39cb0 SA |
507 | * may be disabled, or that the endpoint is not |
508 | * connected. | |
0fcc2bdc SA |
509 | */ |
510 | #define FWNODE_GRAPH_ENDPOINT_NEXT BIT(0) | |
511 | #define FWNODE_GRAPH_DEVICE_DISABLED BIT(1) | |
512 | ||
513 | struct fwnode_handle * | |
514 | fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode, | |
515 | u32 port, u32 endpoint, unsigned long flags); | |
5b9ff0ba | 516 | unsigned int fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode, |
c87b8fc5 | 517 | unsigned long flags); |
0fcc2bdc | 518 | |
52af7863 AS |
519 | #define fwnode_graph_for_each_endpoint(fwnode, child) \ |
520 | for (child = fwnode_graph_get_next_endpoint(fwnode, NULL); child; \ | |
521 | child = fwnode_graph_get_next_endpoint(fwnode, child)) | |
5e4b1b70 | 522 | |
37ba983c | 523 | int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, |
2bd5452d SA |
524 | struct fwnode_endpoint *endpoint); |
525 | ||
23ead33b | 526 | typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, const char *id, |
d7cf5590 HK |
527 | void *data); |
528 | ||
23ead33b | 529 | void *fwnode_connection_find_match(const struct fwnode_handle *fwnode, |
d7cf5590 HK |
530 | const char *con_id, void *data, |
531 | devcon_match_fn_t match); | |
532 | ||
23ead33b | 533 | static inline void *device_connection_find_match(const struct device *dev, |
d7cf5590 HK |
534 | const char *con_id, void *data, |
535 | devcon_match_fn_t match) | |
536 | { | |
537 | return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match); | |
538 | } | |
539 | ||
23ead33b | 540 | int fwnode_connection_find_matches(const struct fwnode_handle *fwnode, |
7a20917d BA |
541 | const char *con_id, void *data, |
542 | devcon_match_fn_t match, | |
543 | void **matches, unsigned int matches_len); | |
544 | ||
59abd836 HK |
545 | /* -------------------------------------------------------------------------- */ |
546 | /* Software fwnode support - when HW description is incomplete or missing */ | |
547 | ||
80488a6b HK |
548 | /** |
549 | * struct software_node - Software node description | |
550 | * @name: Name of the software node | |
551 | * @parent: Parent of the software node | |
552 | * @properties: Array of device properties | |
553 | */ | |
554 | struct software_node { | |
555 | const char *name; | |
556 | const struct software_node *parent; | |
557 | const struct property_entry *properties; | |
558 | }; | |
559 | ||
48c9996f SA |
560 | #define SOFTWARE_NODE(_name_, _properties_, _parent_) \ |
561 | (struct software_node) { \ | |
562 | .name = _name_, \ | |
563 | .properties = _properties_, \ | |
564 | .parent = _parent_, \ | |
565 | } | |
566 | ||
59abd836 | 567 | bool is_software_node(const struct fwnode_handle *fwnode); |
56c9aa07 SA |
568 | const struct software_node * |
569 | to_software_node(const struct fwnode_handle *fwnode); | |
80488a6b HK |
570 | struct fwnode_handle *software_node_fwnode(const struct software_node *node); |
571 | ||
1666faed HK |
572 | const struct software_node * |
573 | software_node_find_by_name(const struct software_node *parent, | |
574 | const char *name); | |
575 | ||
02094d54 AS |
576 | int software_node_register_node_group(const struct software_node **node_group); |
577 | void software_node_unregister_node_group(const struct software_node **node_group); | |
578 | ||
80488a6b | 579 | int software_node_register(const struct software_node *node); |
46d26819 | 580 | void software_node_unregister(const struct software_node *node); |
59abd836 | 581 | |
59abd836 HK |
582 | struct fwnode_handle * |
583 | fwnode_create_software_node(const struct property_entry *properties, | |
584 | const struct fwnode_handle *parent); | |
585 | void fwnode_remove_software_node(struct fwnode_handle *fwnode); | |
586 | ||
2a92c90f | 587 | int device_add_software_node(struct device *dev, const struct software_node *node); |
e68d0119 HK |
588 | void device_remove_software_node(struct device *dev); |
589 | ||
151f6ff7 HK |
590 | int device_create_managed_software_node(struct device *dev, |
591 | const struct property_entry *properties, | |
592 | const struct software_node *parent); | |
593 | ||
b31384fa | 594 | #endif /* _LINUX_PROPERTY_H_ */ |