dts:arm:rk3288-box: ddr frequency set to 533 when playing 4K video.
[firefly-linux-kernel-4.4.55.git] / include / linux / of.h
1 #ifndef _LINUX_OF_H
2 #define _LINUX_OF_H
3 /*
4  * Definitions for talking to the Open Firmware PROM on
5  * Power Macintosh and other computers.
6  *
7  * Copyright (C) 1996-2005 Paul Mackerras.
8  *
9  * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
10  * Updates for SPARC64 by David S. Miller
11  * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version
16  * 2 of the License, or (at your option) any later version.
17  */
18 #include <linux/types.h>
19 #include <linux/bitops.h>
20 #include <linux/errno.h>
21 #include <linux/kobject.h>
22 #include <linux/mod_devicetable.h>
23 #include <linux/spinlock.h>
24 #include <linux/topology.h>
25 #include <linux/notifier.h>
26 #include <linux/list.h>
27
28 #include <asm/byteorder.h>
29 #include <asm/errno.h>
30
31 typedef u32 phandle;
32 typedef u32 ihandle;
33
34 struct property {
35         char    *name;
36         int     length;
37         void    *value;
38         struct property *next;
39         unsigned long _flags;
40         unsigned int unique_id;
41         struct bin_attribute attr;
42 };
43
44 #if defined(CONFIG_SPARC)
45 struct of_irq_controller;
46 #endif
47
48 struct device_node {
49         const char *name;
50         const char *type;
51         phandle phandle;
52         const char *full_name;
53
54         struct  property *properties;
55         struct  property *deadprops;    /* removed properties */
56         struct  device_node *parent;
57         struct  device_node *child;
58         struct  device_node *sibling;
59         struct  device_node *next;      /* next device of same type */
60         struct  device_node *allnext;   /* next in list of all nodes */
61         struct  kobject kobj;
62         unsigned long _flags;
63         void    *data;
64 #if defined(CONFIG_SPARC)
65         const char *path_component_name;
66         unsigned int unique_id;
67         struct of_irq_controller *irq_trans;
68 #endif
69 };
70
71 #define MAX_PHANDLE_ARGS 8
72 struct of_phandle_args {
73         struct device_node *np;
74         int args_count;
75         uint32_t args[MAX_PHANDLE_ARGS];
76 };
77
78 struct of_reconfig_data {
79         struct device_node      *dn;
80         struct property         *prop;
81         struct property         *old_prop;
82 };
83
84 /* initialize a node */
85 extern struct kobj_type of_node_ktype;
86 static inline void of_node_init(struct device_node *node)
87 {
88         kobject_init(&node->kobj, &of_node_ktype);
89 }
90
91 /* true when node is initialized */
92 static inline int of_node_is_initialized(struct device_node *node)
93 {
94         return node && node->kobj.state_initialized;
95 }
96
97 /* true when node is attached (i.e. present on sysfs) */
98 static inline int of_node_is_attached(struct device_node *node)
99 {
100         return node && node->kobj.state_in_sysfs;
101 }
102
103 #ifdef CONFIG_OF_DYNAMIC
104 extern struct device_node *of_node_get(struct device_node *node);
105 extern void of_node_put(struct device_node *node);
106 #else /* CONFIG_OF_DYNAMIC */
107 /* Dummy ref counting routines - to be implemented later */
108 static inline struct device_node *of_node_get(struct device_node *node)
109 {
110         return node;
111 }
112 static inline void of_node_put(struct device_node *node) { }
113 #endif /* !CONFIG_OF_DYNAMIC */
114
115 #ifdef CONFIG_OF
116
117 /* Pointer for first entry in chain of all nodes. */
118 extern struct device_node *of_allnodes;
119 extern struct device_node *of_chosen;
120 extern struct device_node *of_aliases;
121 extern raw_spinlock_t devtree_lock;
122
123 static inline bool of_have_populated_dt(void)
124 {
125         return of_allnodes != NULL;
126 }
127
128 static inline bool of_node_is_root(const struct device_node *node)
129 {
130         return node && (node->parent == NULL);
131 }
132
133 static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
134 {
135         return test_bit(flag, &n->_flags);
136 }
137
138 static inline int of_node_test_and_set_flag(struct device_node *n,
139                                             unsigned long flag)
140 {
141         return test_and_set_bit(flag, &n->_flags);
142 }
143
144 static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
145 {
146         set_bit(flag, &n->_flags);
147 }
148
149 static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
150 {
151         clear_bit(flag, &n->_flags);
152 }
153
154 static inline int of_property_check_flag(struct property *p, unsigned long flag)
155 {
156         return test_bit(flag, &p->_flags);
157 }
158
159 static inline void of_property_set_flag(struct property *p, unsigned long flag)
160 {
161         set_bit(flag, &p->_flags);
162 }
163
164 static inline void of_property_clear_flag(struct property *p, unsigned long flag)
165 {
166         clear_bit(flag, &p->_flags);
167 }
168
169 extern struct device_node *of_find_all_nodes(struct device_node *prev);
170
171 /*
172  * OF address retrieval & translation
173  */
174
175 /* Helper to read a big number; size is in cells (not bytes) */
176 static inline u64 of_read_number(const __be32 *cell, int size)
177 {
178         u64 r = 0;
179         while (size--)
180                 r = (r << 32) | be32_to_cpu(*(cell++));
181         return r;
182 }
183
184 /* Like of_read_number, but we want an unsigned long result */
185 static inline unsigned long of_read_ulong(const __be32 *cell, int size)
186 {
187         /* toss away upper bits if unsigned long is smaller than u64 */
188         return of_read_number(cell, size);
189 }
190
191 #include <asm/prom.h>
192
193 /* Default #address and #size cells.  Allow arch asm/prom.h to override */
194 #if !defined(OF_ROOT_NODE_ADDR_CELLS_DEFAULT)
195 #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
196 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
197 #endif
198
199 /* Default string compare functions, Allow arch asm/prom.h to override */
200 #if !defined(of_compat_cmp)
201 #define of_compat_cmp(s1, s2, l)        strcasecmp((s1), (s2))
202 #define of_prop_cmp(s1, s2)             strcmp((s1), (s2))
203 #define of_node_cmp(s1, s2)             strcasecmp((s1), (s2))
204 #endif
205
206 /* flag descriptions */
207 #define OF_DYNAMIC      1 /* node and properties were allocated via kmalloc */
208 #define OF_DETACHED     2 /* node has been detached from the device tree */
209 #define OF_POPULATED    3 /* device already created for the node */
210 #define OF_POPULATED_BUS        4 /* of_platform_populate recursed to children of this node */
211
212 #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
213 #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
214
215 #define OF_BAD_ADDR     ((u64)-1)
216
217 static inline const char *of_node_full_name(const struct device_node *np)
218 {
219         return np ? np->full_name : "<no-node>";
220 }
221
222 #define for_each_of_allnodes(dn) \
223         for (dn = of_allnodes; dn; dn = dn->allnext)
224 extern struct device_node *of_find_node_by_name(struct device_node *from,
225         const char *name);
226 #define for_each_node_by_name(dn, name) \
227         for (dn = of_find_node_by_name(NULL, name); dn; \
228              dn = of_find_node_by_name(dn, name))
229 extern struct device_node *of_find_node_by_type(struct device_node *from,
230         const char *type);
231 #define for_each_node_by_type(dn, type) \
232         for (dn = of_find_node_by_type(NULL, type); dn; \
233              dn = of_find_node_by_type(dn, type))
234 extern struct device_node *of_find_compatible_node(struct device_node *from,
235         const char *type, const char *compat);
236 #define for_each_compatible_node(dn, type, compatible) \
237         for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
238              dn = of_find_compatible_node(dn, type, compatible))
239 extern struct device_node *of_find_matching_node_and_match(
240         struct device_node *from,
241         const struct of_device_id *matches,
242         const struct of_device_id **match);
243 static inline struct device_node *of_find_matching_node(
244         struct device_node *from,
245         const struct of_device_id *matches)
246 {
247         return of_find_matching_node_and_match(from, matches, NULL);
248 }
249 #define for_each_matching_node(dn, matches) \
250         for (dn = of_find_matching_node(NULL, matches); dn; \
251              dn = of_find_matching_node(dn, matches))
252 #define for_each_matching_node_and_match(dn, matches, match) \
253         for (dn = of_find_matching_node_and_match(NULL, matches, match); \
254              dn; dn = of_find_matching_node_and_match(dn, matches, match))
255 extern struct device_node *of_find_node_by_path(const char *path);
256 extern struct device_node *of_find_node_by_phandle(phandle handle);
257 extern struct device_node *of_get_parent(const struct device_node *node);
258 extern struct device_node *of_get_next_parent(struct device_node *node);
259 extern struct device_node *of_get_next_child(const struct device_node *node,
260                                              struct device_node *prev);
261 extern struct device_node *of_get_next_available_child(
262         const struct device_node *node, struct device_node *prev);
263
264 extern struct device_node *of_get_child_by_name(const struct device_node *node,
265                                         const char *name);
266 #define for_each_child_of_node(parent, child) \
267         for (child = of_get_next_child(parent, NULL); child != NULL; \
268              child = of_get_next_child(parent, child))
269
270 #define for_each_available_child_of_node(parent, child) \
271         for (child = of_get_next_available_child(parent, NULL); child != NULL; \
272              child = of_get_next_available_child(parent, child))
273
274 static inline int of_get_child_count(const struct device_node *np)
275 {
276         struct device_node *child;
277         int num = 0;
278
279         for_each_child_of_node(np, child)
280                 num++;
281
282         return num;
283 }
284
285 extern struct device_node *of_find_node_with_property(
286         struct device_node *from, const char *prop_name);
287 #define for_each_node_with_property(dn, prop_name) \
288         for (dn = of_find_node_with_property(NULL, prop_name); dn; \
289              dn = of_find_node_with_property(dn, prop_name))
290
291 extern struct property *of_find_property(const struct device_node *np,
292                                          const char *name,
293                                          int *lenp);
294 extern int of_property_count_elems_of_size(const struct device_node *np,
295                                 const char *propname, int elem_size);
296 extern int of_property_read_u32_index(const struct device_node *np,
297                                        const char *propname,
298                                        u32 index, u32 *out_value);
299
300 extern int of_property_read_u8_array_tp(const struct device_node *np,
301                         const char *propname, u8 *out_values, size_t sz);
302
303 extern int of_property_read_u8_array(const struct device_node *np,
304                         const char *propname, u8 *out_values, size_t sz);
305 extern int of_property_read_u16_array(const struct device_node *np,
306                         const char *propname, u16 *out_values, size_t sz);
307 extern int of_property_read_u32_array(const struct device_node *np,
308                                       const char *propname,
309                                       u32 *out_values,
310                                       size_t sz);
311 extern int of_property_read_u64(const struct device_node *np,
312                                 const char *propname, u64 *out_value);
313
314 extern int of_property_read_string(struct device_node *np,
315                                    const char *propname,
316                                    const char **out_string);
317 extern int of_property_match_string(struct device_node *np,
318                                     const char *propname,
319                                     const char *string);
320 extern int of_property_read_string_helper(struct device_node *np,
321                                               const char *propname,
322                                               const char **out_strs, size_t sz, int index);
323 extern int of_device_is_compatible(const struct device_node *device,
324                                    const char *);
325 extern int of_device_is_available(const struct device_node *device);
326 extern const void *of_get_property(const struct device_node *node,
327                                 const char *name,
328                                 int *lenp);
329 extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
330 #define for_each_property_of_node(dn, pp) \
331         for (pp = dn->properties; pp != NULL; pp = pp->next)
332
333 extern int of_n_addr_cells(struct device_node *np);
334 extern int of_n_size_cells(struct device_node *np);
335 extern const struct of_device_id *of_match_node(
336         const struct of_device_id *matches, const struct device_node *node);
337 extern int of_modalias_node(struct device_node *node, char *modalias, int len);
338 extern struct device_node *of_parse_phandle(const struct device_node *np,
339                                             const char *phandle_name,
340                                             int index);
341 extern int of_parse_phandle_with_args(const struct device_node *np,
342         const char *list_name, const char *cells_name, int index,
343         struct of_phandle_args *out_args);
344 extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
345         const char *list_name, int cells_count, int index,
346         struct of_phandle_args *out_args);
347 extern int of_count_phandle_with_args(const struct device_node *np,
348         const char *list_name, const char *cells_name);
349
350 extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
351 extern int of_alias_get_id(struct device_node *np, const char *stem);
352
353 extern int of_machine_is_compatible(const char *compat);
354
355 extern int of_add_property(struct device_node *np, struct property *prop);
356 extern int of_remove_property(struct device_node *np, struct property *prop);
357 extern int of_update_property(struct device_node *np, struct property *newprop);
358
359 /* For updating the device tree at runtime */
360 #define OF_RECONFIG_ATTACH_NODE         0x0001
361 #define OF_RECONFIG_DETACH_NODE         0x0002
362 #define OF_RECONFIG_ADD_PROPERTY        0x0003
363 #define OF_RECONFIG_REMOVE_PROPERTY     0x0004
364 #define OF_RECONFIG_UPDATE_PROPERTY     0x0005
365
366 extern int of_attach_node(struct device_node *);
367 extern int of_detach_node(struct device_node *);
368
369 #define of_match_ptr(_ptr)      (_ptr)
370
371 /*
372  * struct property *prop;
373  * const __be32 *p;
374  * u32 u;
375  *
376  * of_property_for_each_u32(np, "propname", prop, p, u)
377  *         printk("U32 value: %x\n", u);
378  */
379 const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
380                                u32 *pu);
381 #define of_property_for_each_u32(np, propname, prop, p, u)      \
382         for (prop = of_find_property(np, propname, NULL),       \
383                 p = of_prop_next_u32(prop, NULL, &u);           \
384                 p;                                              \
385                 p = of_prop_next_u32(prop, p, &u))
386
387 /*
388  * struct property *prop;
389  * const char *s;
390  *
391  * of_property_for_each_string(np, "propname", prop, s)
392  *         printk("String value: %s\n", s);
393  */
394 const char *of_prop_next_string(struct property *prop, const char *cur);
395 #define of_property_for_each_string(np, propname, prop, s)      \
396         for (prop = of_find_property(np, propname, NULL),       \
397                 s = of_prop_next_string(prop, NULL);            \
398                 s;                                              \
399                 s = of_prop_next_string(prop, s))
400
401 int of_device_is_stdout_path(struct device_node *dn);
402
403 #else /* CONFIG_OF */
404
405 static inline const char* of_node_full_name(struct device_node *np)
406 {
407         return "<no-node>";
408 }
409
410 static inline struct device_node *of_find_node_by_name(struct device_node *from,
411         const char *name)
412 {
413         return NULL;
414 }
415
416 static inline struct device_node *of_get_parent(const struct device_node *node)
417 {
418         return NULL;
419 }
420
421 static inline bool of_have_populated_dt(void)
422 {
423         return false;
424 }
425
426 #define for_each_child_of_node(parent, child) \
427         while (0)
428
429 static inline struct device_node *of_get_child_by_name(
430                                         const struct device_node *node,
431                                         const char *name)
432 {
433         return NULL;
434 }
435
436 static inline int of_get_child_count(const struct device_node *np)
437 {
438         return 0;
439 }
440
441 static inline int of_device_is_compatible(const struct device_node *device,
442                                           const char *name)
443 {
444         return 0;
445 }
446
447 static inline int of_device_is_available(const struct device_node *device)
448 {
449         return 0;
450 }
451
452 static inline struct property *of_find_property(const struct device_node *np,
453                                                 const char *name,
454                                                 int *lenp)
455 {
456         return NULL;
457 }
458
459 static inline struct device_node *of_find_compatible_node(
460                                                 struct device_node *from,
461                                                 const char *type,
462                                                 const char *compat)
463 {
464         return NULL;
465 }
466
467 static inline int of_property_count_elems_of_size(const struct device_node *np,
468                         const char *propname, int elem_size)
469 {
470         return -ENOSYS;
471 }
472
473 static inline int of_property_read_u32_index(const struct device_node *np,
474                         const char *propname, u32 index, u32 *out_value)
475 {
476         return -ENOSYS;
477 }
478
479 static inline int of_property_read_u8_array_tp(const struct device_node *np,
480                         const char *propname, u8 *out_values, size_t sz)
481 {
482         return -ENOSYS;
483 }
484
485
486
487 static inline int of_property_read_u8_array(const struct device_node *np,
488                         const char *propname, u8 *out_values, size_t sz)
489 {
490         return -ENOSYS;
491 }
492
493 static inline int of_property_read_u16_array(const struct device_node *np,
494                         const char *propname, u16 *out_values, size_t sz)
495 {
496         return -ENOSYS;
497 }
498
499 static inline int of_property_read_u32_array(const struct device_node *np,
500                                              const char *propname,
501                                              u32 *out_values, size_t sz)
502 {
503         return -ENOSYS;
504 }
505
506 static inline int of_property_read_string(struct device_node *np,
507                                           const char *propname,
508                                           const char **out_string)
509 {
510         return -ENOSYS;
511 }
512
513 static inline int of_property_read_string_helper(struct device_node *np,
514                                                  const char *propname,
515                                                  const char **out_strs, size_t sz, int index)
516 {
517         return -ENOSYS;
518 }
519
520 static inline const void *of_get_property(const struct device_node *node,
521                                 const char *name,
522                                 int *lenp)
523 {
524         return NULL;
525 }
526
527 static inline struct device_node *of_get_cpu_node(int cpu,
528                                         unsigned int *thread)
529 {
530         return NULL;
531 }
532
533 static inline int of_property_read_u64(const struct device_node *np,
534                                        const char *propname, u64 *out_value)
535 {
536         return -ENOSYS;
537 }
538
539 static inline int of_property_match_string(struct device_node *np,
540                                            const char *propname,
541                                            const char *string)
542 {
543         return -ENOSYS;
544 }
545
546 static inline struct device_node *of_parse_phandle(const struct device_node *np,
547                                                    const char *phandle_name,
548                                                    int index)
549 {
550         return NULL;
551 }
552
553 static inline int of_parse_phandle_with_args(struct device_node *np,
554                                              const char *list_name,
555                                              const char *cells_name,
556                                              int index,
557                                              struct of_phandle_args *out_args)
558 {
559         return -ENOSYS;
560 }
561
562 static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
563         const char *list_name, int cells_count, int index,
564         struct of_phandle_args *out_args)
565 {
566         return -ENOSYS;
567 }
568
569 static inline int of_count_phandle_with_args(struct device_node *np,
570                                              const char *list_name,
571                                              const char *cells_name)
572 {
573         return -ENOSYS;
574 }
575
576 static inline int of_alias_get_id(struct device_node *np, const char *stem)
577 {
578         return -ENOSYS;
579 }
580
581 static inline int of_machine_is_compatible(const char *compat)
582 {
583         return 0;
584 }
585
586 static inline int of_device_is_stdout_path(struct device_node *dn)
587 {
588         return 0;
589 }
590
591 #define of_match_ptr(_ptr)      NULL
592 #define of_match_node(_matches, _node)  NULL
593 #define of_property_for_each_u32(np, propname, prop, p, u) \
594         while (0)
595 #define of_property_for_each_string(np, propname, prop, s) \
596         while (0)
597 #endif /* CONFIG_OF */
598
599 #ifndef of_node_to_nid
600 static inline int of_node_to_nid(struct device_node *np)
601 {
602         return numa_node_id();
603 }
604
605 #define of_node_to_nid of_node_to_nid
606 #endif
607
608 /**
609  * of_property_read_string_array() - Read an array of strings from a multiple
610  * strings property.
611  * @np:         device node from which the property value is to be read.
612  * @propname:   name of the property to be searched.
613  * @out_strs:   output array of string pointers.
614  * @sz:         number of array elements to read.
615  *
616  * Search for a property in a device tree node and retrieve a list of
617  * terminated string values (pointer to data, not a copy) in that property.
618  *
619  * If @out_strs is NULL, the number of strings in the property is returned.
620  */
621 static inline int of_property_read_string_array(struct device_node *np,
622                                                 const char *propname, const char **out_strs,
623                                                 size_t sz)
624 {
625         return of_property_read_string_helper(np, propname, out_strs, sz, 0);
626 }
627
628 /**
629  * of_property_count_strings() - Find and return the number of strings from a
630  * multiple strings property.
631  * @np:         device node from which the property value is to be read.
632  * @propname:   name of the property to be searched.
633  *
634  * Search for a property in a device tree node and retrieve the number of null
635  * terminated string contain in it. Returns the number of strings on
636  * success, -EINVAL if the property does not exist, -ENODATA if property
637  * does not have a value, and -EILSEQ if the string is not null-terminated
638  * within the length of the property data.
639  */
640 static inline int of_property_count_strings(struct device_node *np,
641                                             const char *propname)
642 {
643         return of_property_read_string_helper(np, propname, NULL, 0, 0);
644 }
645
646 /**
647  * of_property_read_string_index() - Find and read a string from a multiple
648  * strings property.
649  * @np:         device node from which the property value is to be read.
650  * @propname:   name of the property to be searched.
651  * @index:      index of the string in the list of strings
652  * @out_string: pointer to null terminated return string, modified only if
653  *              return value is 0.
654  *
655  * Search for a property in a device tree node and retrieve a null
656  * terminated string value (pointer to data, not a copy) in the list of strings
657  * contained in that property.
658  * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
659  * property does not have a value, and -EILSEQ if the string is not
660  * null-terminated within the length of the property data.
661  *
662  * The out_string pointer is modified only if a valid string can be decoded.
663  */
664 static inline int of_property_read_string_index(struct device_node *np,
665                                                 const char *propname,
666                                                 int index, const char **output)
667 {
668         int rc = of_property_read_string_helper(np, propname, output, 1, index);
669         return rc < 0 ? rc : 0;
670 }
671
672 /*
673  * of_property_count_u8_elems - Count the number of u8 elements in a property
674  *
675  * @np:         device node from which the property value is to be read.
676  * @propname:   name of the property to be searched.
677  *
678  * Search for a property in a device node and count the number of u8 elements
679  * in it. Returns number of elements on sucess, -EINVAL if the property does
680  * not exist or its length does not match a multiple of u8 and -ENODATA if the
681  * property does not have a value.
682  */
683 static inline int of_property_count_u8_elems(const struct device_node *np,
684                                 const char *propname)
685 {
686         return of_property_count_elems_of_size(np, propname, sizeof(u8));
687 }
688
689 /**
690  * of_property_count_u16_elems - Count the number of u16 elements in a property
691  *
692  * @np:         device node from which the property value is to be read.
693  * @propname:   name of the property to be searched.
694  *
695  * Search for a property in a device node and count the number of u16 elements
696  * in it. Returns number of elements on sucess, -EINVAL if the property does
697  * not exist or its length does not match a multiple of u16 and -ENODATA if the
698  * property does not have a value.
699  */
700 static inline int of_property_count_u16_elems(const struct device_node *np,
701                                 const char *propname)
702 {
703         return of_property_count_elems_of_size(np, propname, sizeof(u16));
704 }
705
706 /**
707  * of_property_count_u32_elems - Count the number of u32 elements in a property
708  *
709  * @np:         device node from which the property value is to be read.
710  * @propname:   name of the property to be searched.
711  *
712  * Search for a property in a device node and count the number of u32 elements
713  * in it. Returns number of elements on sucess, -EINVAL if the property does
714  * not exist or its length does not match a multiple of u32 and -ENODATA if the
715  * property does not have a value.
716  */
717 static inline int of_property_count_u32_elems(const struct device_node *np,
718                                 const char *propname)
719 {
720         return of_property_count_elems_of_size(np, propname, sizeof(u32));
721 }
722
723 /**
724  * of_property_count_u64_elems - Count the number of u64 elements in a property
725  *
726  * @np:         device node from which the property value is to be read.
727  * @propname:   name of the property to be searched.
728  *
729  * Search for a property in a device node and count the number of u64 elements
730  * in it. Returns number of elements on sucess, -EINVAL if the property does
731  * not exist or its length does not match a multiple of u64 and -ENODATA if the
732  * property does not have a value.
733  */
734 static inline int of_property_count_u64_elems(const struct device_node *np,
735                                 const char *propname)
736 {
737         return of_property_count_elems_of_size(np, propname, sizeof(u64));
738 }
739
740 /**
741  * of_property_read_bool - Findfrom a property
742  * @np:         device node from which the property value is to be read.
743  * @propname:   name of the property to be searched.
744  *
745  * Search for a property in a device node.
746  * Returns true if the property exist false otherwise.
747  */
748 static inline bool of_property_read_bool(const struct device_node *np,
749                                          const char *propname)
750 {
751         struct property *prop = of_find_property(np, propname, NULL);
752
753         return prop ? true : false;
754 }
755
756 static inline int of_property_read_u8(const struct device_node *np,
757                                        const char *propname,
758                                        u8 *out_value)
759 {
760         return of_property_read_u8_array(np, propname, out_value, 1);
761 }
762
763 static inline int of_property_read_u16(const struct device_node *np,
764                                        const char *propname,
765                                        u16 *out_value)
766 {
767         return of_property_read_u16_array(np, propname, out_value, 1);
768 }
769
770 static inline int of_property_read_u32(const struct device_node *np,
771                                        const char *propname,
772                                        u32 *out_value)
773 {
774         return of_property_read_u32_array(np, propname, out_value, 1);
775 }
776
777 /**
778  * struct of_changeset_entry    - Holds a changeset entry
779  *
780  * @node:       list_head for the log list
781  * @action:     notifier action
782  * @np:         pointer to the device node affected
783  * @prop:       pointer to the property affected
784  * @old_prop:   hold a pointer to the original property
785  *
786  * Every modification of the device tree during a changeset
787  * is held in a list of of_changeset_entry structures.
788  * That way we can recover from a partial application, or we can
789  * revert the changeset
790  */
791 struct of_changeset_entry {
792         struct list_head node;
793         unsigned long action;
794         struct device_node *np;
795         struct property *prop;
796         struct property *old_prop;
797 };
798
799 /**
800  * struct of_changeset - changeset tracker structure
801  *
802  * @entries:    list_head for the changeset entries
803  *
804  * changesets are a convenient way to apply bulk changes to the
805  * live tree. In case of an error, changes are rolled-back.
806  * changesets live on after initial application, and if not
807  * destroyed after use, they can be reverted in one single call.
808  */
809 struct of_changeset {
810         struct list_head entries;
811 };
812
813 enum of_reconfig_change {
814         OF_RECONFIG_NO_CHANGE = 0,
815         OF_RECONFIG_CHANGE_ADD,
816         OF_RECONFIG_CHANGE_REMOVE,
817 };
818
819 #ifdef CONFIG_OF_DYNAMIC
820 extern int of_reconfig_notifier_register(struct notifier_block *);
821 extern int of_reconfig_notifier_unregister(struct notifier_block *);
822 extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
823 extern int of_reconfig_get_state_change(unsigned long action,
824                                         struct of_reconfig_data *arg);
825
826 extern void of_changeset_init(struct of_changeset *ocs);
827 extern void of_changeset_destroy(struct of_changeset *ocs);
828 extern int of_changeset_apply(struct of_changeset *ocs);
829 extern int of_changeset_revert(struct of_changeset *ocs);
830 extern int of_changeset_action(struct of_changeset *ocs,
831                 unsigned long action, struct device_node *np,
832                 struct property *prop);
833
834 static inline int of_changeset_attach_node(struct of_changeset *ocs,
835                 struct device_node *np)
836 {
837         return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
838 }
839
840 static inline int of_changeset_detach_node(struct of_changeset *ocs,
841                 struct device_node *np)
842 {
843         return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
844 }
845
846 static inline int of_changeset_add_property(struct of_changeset *ocs,
847                 struct device_node *np, struct property *prop)
848 {
849         return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
850 }
851
852 static inline int of_changeset_remove_property(struct of_changeset *ocs,
853                 struct device_node *np, struct property *prop)
854 {
855         return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
856 }
857
858 static inline int of_changeset_update_property(struct of_changeset *ocs,
859                 struct device_node *np, struct property *prop)
860 {
861         return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
862 }
863 #else /* CONFIG_OF_DYNAMIC */
864 static inline int of_reconfig_notifier_register(struct notifier_block *nb)
865 {
866         return -EINVAL;
867 }
868 static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
869 {
870         return -EINVAL;
871 }
872 static inline int of_reconfig_notify(unsigned long action,
873                                      struct of_reconfig_data *arg)
874 {
875         return -EINVAL;
876 }
877 static inline int of_reconfig_get_state_change(unsigned long action,
878                                                 struct of_reconfig_data *arg)
879 {
880         return -EINVAL;
881 }
882 #endif /* CONFIG_OF_DYNAMIC */
883
884 /* CONFIG_OF_RESOLVE api */
885 extern int of_resolve_phandles(struct device_node *tree);
886
887 /**
888  * Overlay support
889  */
890
891 #ifdef CONFIG_OF_OVERLAY
892
893 /* ID based overlays; the API for external users */
894 int of_overlay_create(struct device_node *tree);
895 int of_overlay_destroy(int id);
896 int of_overlay_destroy_all(void);
897
898 #else
899
900 static inline int of_overlay_create(struct device_node *tree)
901 {
902         return -ENOTSUPP;
903 }
904
905 static inline int of_overlay_destroy(int id)
906 {
907         return -ENOTSUPP;
908 }
909
910 static inline int of_overlay_destroy_all(void)
911 {
912         return -ENOTSUPP;
913 }
914
915 #endif
916
917 #endif /* _LINUX_OF_H */