1
2
3
4
5
6
7
8
9
10#ifndef _LINUX_PROPERTY_H_
11#define _LINUX_PROPERTY_H_
12
13#include <linux/bits.h>
14#include <linux/fwnode.h>
15#include <linux/types.h>
16
17struct device;
18
19enum dev_prop_type {
20 DEV_PROP_U8,
21 DEV_PROP_U16,
22 DEV_PROP_U32,
23 DEV_PROP_U64,
24 DEV_PROP_STRING,
25 DEV_PROP_MAX,
26};
27
28enum dev_dma_attr {
29 DEV_DMA_NOT_SUPPORTED,
30 DEV_DMA_NON_COHERENT,
31 DEV_DMA_COHERENT,
32};
33
34struct fwnode_handle *dev_fwnode(struct device *dev);
35
36bool device_property_present(struct device *dev, const char *propname);
37int device_property_read_u8_array(struct device *dev, const char *propname,
38 u8 *val, size_t nval);
39int device_property_read_u16_array(struct device *dev, const char *propname,
40 u16 *val, size_t nval);
41int device_property_read_u32_array(struct device *dev, const char *propname,
42 u32 *val, size_t nval);
43int device_property_read_u64_array(struct device *dev, const char *propname,
44 u64 *val, size_t nval);
45int device_property_read_string_array(struct device *dev, const char *propname,
46 const char **val, size_t nval);
47int device_property_read_string(struct device *dev, const char *propname,
48 const char **val);
49int device_property_match_string(struct device *dev,
50 const char *propname, const char *string);
51
52bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
53bool fwnode_property_present(const struct fwnode_handle *fwnode,
54 const char *propname);
55int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
56 const char *propname, u8 *val,
57 size_t nval);
58int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode,
59 const char *propname, u16 *val,
60 size_t nval);
61int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode,
62 const char *propname, u32 *val,
63 size_t nval);
64int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode,
65 const char *propname, u64 *val,
66 size_t nval);
67int fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
68 const char *propname, const char **val,
69 size_t nval);
70int fwnode_property_read_string(const struct fwnode_handle *fwnode,
71 const char *propname, const char **val);
72int fwnode_property_match_string(const struct fwnode_handle *fwnode,
73 const char *propname, const char *string);
74int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
75 const char *prop, const char *nargs_prop,
76 unsigned int nargs, unsigned int index,
77 struct fwnode_reference_args *args);
78
79struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
80 const char *name,
81 unsigned int index);
82
83struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
84struct fwnode_handle *fwnode_get_next_parent(
85 struct fwnode_handle *fwnode);
86struct fwnode_handle *fwnode_get_next_child_node(
87 const struct fwnode_handle *fwnode, struct fwnode_handle *child);
88struct fwnode_handle *fwnode_get_next_available_child_node(
89 const struct fwnode_handle *fwnode, struct fwnode_handle *child);
90
91#define fwnode_for_each_child_node(fwnode, child) \
92 for (child = fwnode_get_next_child_node(fwnode, NULL); child; \
93 child = fwnode_get_next_child_node(fwnode, child))
94
95#define fwnode_for_each_available_child_node(fwnode, child) \
96 for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\
97 child = fwnode_get_next_available_child_node(fwnode, child))
98
99struct fwnode_handle *device_get_next_child_node(
100 struct device *dev, struct fwnode_handle *child);
101
102#define device_for_each_child_node(dev, child) \
103 for (child = device_get_next_child_node(dev, NULL); child; \
104 child = device_get_next_child_node(dev, child))
105
106struct fwnode_handle *fwnode_get_named_child_node(
107 const struct fwnode_handle *fwnode, const char *childname);
108struct fwnode_handle *device_get_named_child_node(struct device *dev,
109 const char *childname);
110
111struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
112void fwnode_handle_put(struct fwnode_handle *fwnode);
113
114int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
115
116unsigned int device_get_child_node_count(struct device *dev);
117
118static inline bool device_property_read_bool(struct device *dev,
119 const char *propname)
120{
121 return device_property_present(dev, propname);
122}
123
124static inline int device_property_read_u8(struct device *dev,
125 const char *propname, u8 *val)
126{
127 return device_property_read_u8_array(dev, propname, val, 1);
128}
129
130static inline int device_property_read_u16(struct device *dev,
131 const char *propname, u16 *val)
132{
133 return device_property_read_u16_array(dev, propname, val, 1);
134}
135
136static inline int device_property_read_u32(struct device *dev,
137 const char *propname, u32 *val)
138{
139 return device_property_read_u32_array(dev, propname, val, 1);
140}
141
142static inline int device_property_read_u64(struct device *dev,
143 const char *propname, u64 *val)
144{
145 return device_property_read_u64_array(dev, propname, val, 1);
146}
147
148static inline int device_property_count_u8(struct device *dev, const char *propname)
149{
150 return device_property_read_u8_array(dev, propname, NULL, 0);
151}
152
153static inline int device_property_count_u16(struct device *dev, const char *propname)
154{
155 return device_property_read_u16_array(dev, propname, NULL, 0);
156}
157
158static inline int device_property_count_u32(struct device *dev, const char *propname)
159{
160 return device_property_read_u32_array(dev, propname, NULL, 0);
161}
162
163static inline int device_property_count_u64(struct device *dev, const char *propname)
164{
165 return device_property_read_u64_array(dev, propname, NULL, 0);
166}
167
168static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
169 const char *propname)
170{
171 return fwnode_property_present(fwnode, propname);
172}
173
174static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode,
175 const char *propname, u8 *val)
176{
177 return fwnode_property_read_u8_array(fwnode, propname, val, 1);
178}
179
180static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode,
181 const char *propname, u16 *val)
182{
183 return fwnode_property_read_u16_array(fwnode, propname, val, 1);
184}
185
186static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode,
187 const char *propname, u32 *val)
188{
189 return fwnode_property_read_u32_array(fwnode, propname, val, 1);
190}
191
192static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode,
193 const char *propname, u64 *val)
194{
195 return fwnode_property_read_u64_array(fwnode, propname, val, 1);
196}
197
198static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode,
199 const char *propname)
200{
201 return fwnode_property_read_u8_array(fwnode, propname, NULL, 0);
202}
203
204static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode,
205 const char *propname)
206{
207 return fwnode_property_read_u16_array(fwnode, propname, NULL, 0);
208}
209
210static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode,
211 const char *propname)
212{
213 return fwnode_property_read_u32_array(fwnode, propname, NULL, 0);
214}
215
216static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode,
217 const char *propname)
218{
219 return fwnode_property_read_u64_array(fwnode, propname, NULL, 0);
220}
221
222
223
224
225
226
227
228
229
230
231struct property_entry {
232 const char *name;
233 size_t length;
234 bool is_array;
235 enum dev_prop_type type;
236 union {
237 union {
238 const u8 *u8_data;
239 const u16 *u16_data;
240 const u32 *u32_data;
241 const u64 *u64_data;
242 const char * const *str;
243 } pointer;
244 union {
245 u8 u8_data;
246 u16 u16_data;
247 u32 u32_data;
248 u64 u64_data;
249 const char *str;
250 } value;
251 };
252};
253
254
255
256
257
258
259
260#define PROPERTY_ENTRY_INTEGER_ARRAY(_name_, _type_, _Type_, _val_) \
261(struct property_entry) { \
262 .name = _name_, \
263 .length = ARRAY_SIZE(_val_) * sizeof(_type_), \
264 .is_array = true, \
265 .type = DEV_PROP_##_Type_, \
266 { .pointer = { ._type_##_data = _val_ } }, \
267}
268
269#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \
270 PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u8, U8, _val_)
271#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \
272 PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u16, U16, _val_)
273#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \
274 PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u32, U32, _val_)
275#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \
276 PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u64, U64, _val_)
277
278#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \
279(struct property_entry) { \
280 .name = _name_, \
281 .length = ARRAY_SIZE(_val_) * sizeof(const char *), \
282 .is_array = true, \
283 .type = DEV_PROP_STRING, \
284 { .pointer = { .str = _val_ } }, \
285}
286
287#define PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \
288(struct property_entry) { \
289 .name = _name_, \
290 .length = sizeof(_type_), \
291 .type = DEV_PROP_##_Type_, \
292 { .value = { ._type_##_data = _val_ } }, \
293}
294
295#define PROPERTY_ENTRY_U8(_name_, _val_) \
296 PROPERTY_ENTRY_INTEGER(_name_, u8, U8, _val_)
297#define PROPERTY_ENTRY_U16(_name_, _val_) \
298 PROPERTY_ENTRY_INTEGER(_name_, u16, U16, _val_)
299#define PROPERTY_ENTRY_U32(_name_, _val_) \
300 PROPERTY_ENTRY_INTEGER(_name_, u32, U32, _val_)
301#define PROPERTY_ENTRY_U64(_name_, _val_) \
302 PROPERTY_ENTRY_INTEGER(_name_, u64, U64, _val_)
303
304#define PROPERTY_ENTRY_STRING(_name_, _val_) \
305(struct property_entry) { \
306 .name = _name_, \
307 .length = sizeof(const char *), \
308 .type = DEV_PROP_STRING, \
309 { .value = { .str = _val_ } }, \
310}
311
312#define PROPERTY_ENTRY_BOOL(_name_) \
313(struct property_entry) { \
314 .name = _name_, \
315}
316
317struct property_entry *
318property_entries_dup(const struct property_entry *properties);
319
320void property_entries_free(const struct property_entry *properties);
321
322int device_add_properties(struct device *dev,
323 const struct property_entry *properties);
324void device_remove_properties(struct device *dev);
325
326bool device_dma_supported(struct device *dev);
327
328enum dev_dma_attr device_get_dma_attr(struct device *dev);
329
330const void *device_get_match_data(struct device *dev);
331
332int device_get_phy_mode(struct device *dev);
333
334void *device_get_mac_address(struct device *dev, char *addr, int alen);
335
336int fwnode_get_phy_mode(struct fwnode_handle *fwnode);
337void *fwnode_get_mac_address(struct fwnode_handle *fwnode,
338 char *addr, int alen);
339struct fwnode_handle *fwnode_graph_get_next_endpoint(
340 const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
341struct fwnode_handle *
342fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode);
343struct fwnode_handle *fwnode_graph_get_remote_port_parent(
344 const struct fwnode_handle *fwnode);
345struct fwnode_handle *fwnode_graph_get_remote_port(
346 const struct fwnode_handle *fwnode);
347struct fwnode_handle *fwnode_graph_get_remote_endpoint(
348 const struct fwnode_handle *fwnode);
349struct fwnode_handle *
350fwnode_graph_get_remote_node(const struct fwnode_handle *fwnode, u32 port,
351 u32 endpoint);
352
353
354
355
356
357
358
359
360
361
362
363#define FWNODE_GRAPH_ENDPOINT_NEXT BIT(0)
364#define FWNODE_GRAPH_DEVICE_DISABLED BIT(1)
365
366struct fwnode_handle *
367fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
368 u32 port, u32 endpoint, unsigned long flags);
369
370#define fwnode_graph_for_each_endpoint(fwnode, child) \
371 for (child = NULL; \
372 (child = fwnode_graph_get_next_endpoint(fwnode, child)); )
373
374int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
375 struct fwnode_endpoint *endpoint);
376
377
378
379
380struct software_node;
381
382
383
384
385
386
387
388struct software_node_ref_args {
389 const struct software_node *node;
390 unsigned int nargs;
391 u64 args[NR_FWNODE_REFERENCE_ARGS];
392};
393
394
395
396
397
398
399
400struct software_node_reference {
401 const char *name;
402 unsigned int nrefs;
403 const struct software_node_ref_args *refs;
404};
405
406
407
408
409
410
411
412
413struct software_node {
414 const char *name;
415 const struct software_node *parent;
416 const struct property_entry *properties;
417 const struct software_node_reference *references;
418};
419
420bool is_software_node(const struct fwnode_handle *fwnode);
421const struct software_node *to_software_node(struct fwnode_handle *fwnode);
422struct fwnode_handle *software_node_fwnode(const struct software_node *node);
423
424const struct software_node *
425software_node_find_by_name(const struct software_node *parent,
426 const char *name);
427
428int software_node_register_nodes(const struct software_node *nodes);
429void software_node_unregister_nodes(const struct software_node *nodes);
430
431int software_node_register(const struct software_node *node);
432
433int software_node_notify(struct device *dev, unsigned long action);
434
435struct fwnode_handle *
436fwnode_create_software_node(const struct property_entry *properties,
437 const struct fwnode_handle *parent);
438void fwnode_remove_software_node(struct fwnode_handle *fwnode);
439
440#endif
441