ARM: rockchip: rk3228: add grf definition
[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_find_node_by_path(const char *path)
417 {
418         return NULL;
419 }
420
421 static inline struct device_node *of_get_parent(const struct device_node *node)
422 {
423         return NULL;
424 }
425
426 static inline bool of_have_populated_dt(void)
427 {
428         return false;
429 }
430
431 #define for_each_child_of_node(parent, child) \
432         while (0)
433
434 static inline struct device_node *of_get_child_by_name(
435                                         const struct device_node *node,
436                                         const char *name)
437 {
438         return NULL;
439 }
440
441 static inline int of_get_child_count(const struct device_node *np)
442 {
443         return 0;
444 }
445
446 static inline int of_device_is_compatible(const struct device_node *device,
447                                           const char *name)
448 {
449         return 0;
450 }
451
452 static inline int of_device_is_available(const struct device_node *device)
453 {
454         return 0;
455 }
456
457 static inline struct property *of_find_property(const struct device_node *np,
458                                                 const char *name,
459                                                 int *lenp)
460 {
461         return NULL;
462 }
463
464 static inline struct device_node *of_find_compatible_node(
465                                                 struct device_node *from,
466                                                 const char *type,
467                                                 const char *compat)
468 {
469         return NULL;
470 }
471
472 static inline int of_property_count_elems_of_size(const struct device_node *np,
473                         const char *propname, int elem_size)
474 {
475         return -ENOSYS;
476 }
477
478 static inline int of_property_read_u32_index(const struct device_node *np,
479                         const char *propname, u32 index, u32 *out_value)
480 {
481         return -ENOSYS;
482 }
483
484 static inline int of_property_read_u8_array_tp(const struct device_node *np,
485                         const char *propname, u8 *out_values, size_t sz)
486 {
487         return -ENOSYS;
488 }
489
490
491
492 static inline int of_property_read_u8_array(const struct device_node *np,
493                         const char *propname, u8 *out_values, size_t sz)
494 {
495         return -ENOSYS;
496 }
497
498 static inline int of_property_read_u16_array(const struct device_node *np,
499                         const char *propname, u16 *out_values, size_t sz)
500 {
501         return -ENOSYS;
502 }
503
504 static inline int of_property_read_u32_array(const struct device_node *np,
505                                              const char *propname,
506                                              u32 *out_values, size_t sz)
507 {
508         return -ENOSYS;
509 }
510
511 static inline int of_property_read_string(struct device_node *np,
512                                           const char *propname,
513                                           const char **out_string)
514 {
515         return -ENOSYS;
516 }
517
518 static inline int of_property_read_string_helper(struct device_node *np,
519                                                  const char *propname,
520                                                  const char **out_strs, size_t sz, int index)
521 {
522         return -ENOSYS;
523 }
524
525 static inline const void *of_get_property(const struct device_node *node,
526                                 const char *name,
527                                 int *lenp)
528 {
529         return NULL;
530 }
531
532 static inline struct device_node *of_get_cpu_node(int cpu,
533                                         unsigned int *thread)
534 {
535         return NULL;
536 }
537
538 static inline int of_property_read_u64(const struct device_node *np,
539                                        const char *propname, u64 *out_value)
540 {
541         return -ENOSYS;
542 }
543
544 static inline int of_property_match_string(struct device_node *np,
545                                            const char *propname,
546                                            const char *string)
547 {
548         return -ENOSYS;
549 }
550
551 static inline struct device_node *of_parse_phandle(const struct device_node *np,
552                                                    const char *phandle_name,
553                                                    int index)
554 {
555         return NULL;
556 }
557
558 static inline int of_parse_phandle_with_args(struct device_node *np,
559                                              const char *list_name,
560                                              const char *cells_name,
561                                              int index,
562                                              struct of_phandle_args *out_args)
563 {
564         return -ENOSYS;
565 }
566
567 static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
568         const char *list_name, int cells_count, int index,
569         struct of_phandle_args *out_args)
570 {
571         return -ENOSYS;
572 }
573
574 static inline int of_count_phandle_with_args(struct device_node *np,
575                                              const char *list_name,
576                                              const char *cells_name)
577 {
578         return -ENOSYS;
579 }
580
581 static inline int of_alias_get_id(struct device_node *np, const char *stem)
582 {
583         return -ENOSYS;
584 }
585
586 static inline int of_machine_is_compatible(const char *compat)
587 {
588         return 0;
589 }
590
591 static inline int of_device_is_stdout_path(struct device_node *dn)
592 {
593         return 0;
594 }
595
596 #define of_match_ptr(_ptr)      NULL
597 #define of_match_node(_matches, _node)  NULL
598 #define of_property_for_each_u32(np, propname, prop, p, u) \
599         while (0)
600 #define of_property_for_each_string(np, propname, prop, s) \
601         while (0)
602 #endif /* CONFIG_OF */
603
604 #ifndef of_node_to_nid
605 static inline int of_node_to_nid(struct device_node *np)
606 {
607         return numa_node_id();
608 }
609
610 #define of_node_to_nid of_node_to_nid
611 #endif
612
613 /**
614  * of_property_read_string_array() - Read an array of strings from a multiple
615  * strings property.
616  * @np:         device node from which the property value is to be read.
617  * @propname:   name of the property to be searched.
618  * @out_strs:   output array of string pointers.
619  * @sz:         number of array elements to read.
620  *
621  * Search for a property in a device tree node and retrieve a list of
622  * terminated string values (pointer to data, not a copy) in that property.
623  *
624  * If @out_strs is NULL, the number of strings in the property is returned.
625  */
626 static inline int of_property_read_string_array(struct device_node *np,
627                                                 const char *propname, const char **out_strs,
628                                                 size_t sz)
629 {
630         return of_property_read_string_helper(np, propname, out_strs, sz, 0);
631 }
632
633 /**
634  * of_property_count_strings() - Find and return the number of strings from a
635  * multiple strings property.
636  * @np:         device node from which the property value is to be read.
637  * @propname:   name of the property to be searched.
638  *
639  * Search for a property in a device tree node and retrieve the number of null
640  * terminated string contain in it. Returns the number of strings on
641  * success, -EINVAL if the property does not exist, -ENODATA if property
642  * does not have a value, and -EILSEQ if the string is not null-terminated
643  * within the length of the property data.
644  */
645 static inline int of_property_count_strings(struct device_node *np,
646                                             const char *propname)
647 {
648         return of_property_read_string_helper(np, propname, NULL, 0, 0);
649 }
650
651 /**
652  * of_property_read_string_index() - Find and read a string from a multiple
653  * strings property.
654  * @np:         device node from which the property value is to be read.
655  * @propname:   name of the property to be searched.
656  * @index:      index of the string in the list of strings
657  * @out_string: pointer to null terminated return string, modified only if
658  *              return value is 0.
659  *
660  * Search for a property in a device tree node and retrieve a null
661  * terminated string value (pointer to data, not a copy) in the list of strings
662  * contained in that property.
663  * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
664  * property does not have a value, and -EILSEQ if the string is not
665  * null-terminated within the length of the property data.
666  *
667  * The out_string pointer is modified only if a valid string can be decoded.
668  */
669 static inline int of_property_read_string_index(struct device_node *np,
670                                                 const char *propname,
671                                                 int index, const char **output)
672 {
673         int rc = of_property_read_string_helper(np, propname, output, 1, index);
674         return rc < 0 ? rc : 0;
675 }
676
677 /*
678  * of_property_count_u8_elems - Count the number of u8 elements in a property
679  *
680  * @np:         device node from which the property value is to be read.
681  * @propname:   name of the property to be searched.
682  *
683  * Search for a property in a device node and count the number of u8 elements
684  * in it. Returns number of elements on sucess, -EINVAL if the property does
685  * not exist or its length does not match a multiple of u8 and -ENODATA if the
686  * property does not have a value.
687  */
688 static inline int of_property_count_u8_elems(const struct device_node *np,
689                                 const char *propname)
690 {
691         return of_property_count_elems_of_size(np, propname, sizeof(u8));
692 }
693
694 /**
695  * of_property_count_u16_elems - Count the number of u16 elements in a property
696  *
697  * @np:         device node from which the property value is to be read.
698  * @propname:   name of the property to be searched.
699  *
700  * Search for a property in a device node and count the number of u16 elements
701  * in it. Returns number of elements on sucess, -EINVAL if the property does
702  * not exist or its length does not match a multiple of u16 and -ENODATA if the
703  * property does not have a value.
704  */
705 static inline int of_property_count_u16_elems(const struct device_node *np,
706                                 const char *propname)
707 {
708         return of_property_count_elems_of_size(np, propname, sizeof(u16));
709 }
710
711 /**
712  * of_property_count_u32_elems - Count the number of u32 elements in a property
713  *
714  * @np:         device node from which the property value is to be read.
715  * @propname:   name of the property to be searched.
716  *
717  * Search for a property in a device node and count the number of u32 elements
718  * in it. Returns number of elements on sucess, -EINVAL if the property does
719  * not exist or its length does not match a multiple of u32 and -ENODATA if the
720  * property does not have a value.
721  */
722 static inline int of_property_count_u32_elems(const struct device_node *np,
723                                 const char *propname)
724 {
725         return of_property_count_elems_of_size(np, propname, sizeof(u32));
726 }
727
728 /**
729  * of_property_count_u64_elems - Count the number of u64 elements in a property
730  *
731  * @np:         device node from which the property value is to be read.
732  * @propname:   name of the property to be searched.
733  *
734  * Search for a property in a device node and count the number of u64 elements
735  * in it. Returns number of elements on sucess, -EINVAL if the property does
736  * not exist or its length does not match a multiple of u64 and -ENODATA if the
737  * property does not have a value.
738  */
739 static inline int of_property_count_u64_elems(const struct device_node *np,
740                                 const char *propname)
741 {
742         return of_property_count_elems_of_size(np, propname, sizeof(u64));
743 }
744
745 /**
746  * of_property_read_bool - Findfrom a property
747  * @np:         device node from which the property value is to be read.
748  * @propname:   name of the property to be searched.
749  *
750  * Search for a property in a device node.
751  * Returns true if the property exist false otherwise.
752  */
753 static inline bool of_property_read_bool(const struct device_node *np,
754                                          const char *propname)
755 {
756         struct property *prop = of_find_property(np, propname, NULL);
757
758         return prop ? true : false;
759 }
760
761 static inline int of_property_read_u8(const struct device_node *np,
762                                        const char *propname,
763                                        u8 *out_value)
764 {
765         return of_property_read_u8_array(np, propname, out_value, 1);
766 }
767
768 static inline int of_property_read_u16(const struct device_node *np,
769                                        const char *propname,
770                                        u16 *out_value)
771 {
772         return of_property_read_u16_array(np, propname, out_value, 1);
773 }
774
775 static inline int of_property_read_u32(const struct device_node *np,
776                                        const char *propname,
777                                        u32 *out_value)
778 {
779         return of_property_read_u32_array(np, propname, out_value, 1);
780 }
781
782 /**
783  * struct of_changeset_entry    - Holds a changeset entry
784  *
785  * @node:       list_head for the log list
786  * @action:     notifier action
787  * @np:         pointer to the device node affected
788  * @prop:       pointer to the property affected
789  * @old_prop:   hold a pointer to the original property
790  *
791  * Every modification of the device tree during a changeset
792  * is held in a list of of_changeset_entry structures.
793  * That way we can recover from a partial application, or we can
794  * revert the changeset
795  */
796 struct of_changeset_entry {
797         struct list_head node;
798         unsigned long action;
799         struct device_node *np;
800         struct property *prop;
801         struct property *old_prop;
802 };
803
804 /**
805  * struct of_changeset - changeset tracker structure
806  *
807  * @entries:    list_head for the changeset entries
808  *
809  * changesets are a convenient way to apply bulk changes to the
810  * live tree. In case of an error, changes are rolled-back.
811  * changesets live on after initial application, and if not
812  * destroyed after use, they can be reverted in one single call.
813  */
814 struct of_changeset {
815         struct list_head entries;
816 };
817
818 enum of_reconfig_change {
819         OF_RECONFIG_NO_CHANGE = 0,
820         OF_RECONFIG_CHANGE_ADD,
821         OF_RECONFIG_CHANGE_REMOVE,
822 };
823
824 #ifdef CONFIG_OF_DYNAMIC
825 extern int of_reconfig_notifier_register(struct notifier_block *);
826 extern int of_reconfig_notifier_unregister(struct notifier_block *);
827 extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
828 extern int of_reconfig_get_state_change(unsigned long action,
829                                         struct of_reconfig_data *arg);
830
831 extern void of_changeset_init(struct of_changeset *ocs);
832 extern void of_changeset_destroy(struct of_changeset *ocs);
833 extern int of_changeset_apply(struct of_changeset *ocs);
834 extern int of_changeset_revert(struct of_changeset *ocs);
835 extern int of_changeset_action(struct of_changeset *ocs,
836                 unsigned long action, struct device_node *np,
837                 struct property *prop);
838
839 static inline int of_changeset_attach_node(struct of_changeset *ocs,
840                 struct device_node *np)
841 {
842         return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
843 }
844
845 static inline int of_changeset_detach_node(struct of_changeset *ocs,
846                 struct device_node *np)
847 {
848         return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
849 }
850
851 static inline int of_changeset_add_property(struct of_changeset *ocs,
852                 struct device_node *np, struct property *prop)
853 {
854         return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
855 }
856
857 static inline int of_changeset_remove_property(struct of_changeset *ocs,
858                 struct device_node *np, struct property *prop)
859 {
860         return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
861 }
862
863 static inline int of_changeset_update_property(struct of_changeset *ocs,
864                 struct device_node *np, struct property *prop)
865 {
866         return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
867 }
868 #else /* CONFIG_OF_DYNAMIC */
869 static inline int of_reconfig_notifier_register(struct notifier_block *nb)
870 {
871         return -EINVAL;
872 }
873 static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
874 {
875         return -EINVAL;
876 }
877 static inline int of_reconfig_notify(unsigned long action,
878                                      struct of_reconfig_data *arg)
879 {
880         return -EINVAL;
881 }
882 static inline int of_reconfig_get_state_change(unsigned long action,
883                                                 struct of_reconfig_data *arg)
884 {
885         return -EINVAL;
886 }
887 #endif /* CONFIG_OF_DYNAMIC */
888
889 /* CONFIG_OF_RESOLVE api */
890 extern int of_resolve_phandles(struct device_node *tree);
891
892 /**
893  * Overlay support
894  */
895
896 #ifdef CONFIG_OF_OVERLAY
897
898 /* ID based overlays; the API for external users */
899 int of_overlay_create(struct device_node *tree);
900 int of_overlay_destroy(int id);
901 int of_overlay_destroy_all(void);
902
903 #else
904
905 static inline int of_overlay_create(struct device_node *tree)
906 {
907         return -ENOTSUPP;
908 }
909
910 static inline int of_overlay_destroy(int id)
911 {
912         return -ENOTSUPP;
913 }
914
915 static inline int of_overlay_destroy_all(void)
916 {
917         return -ENOTSUPP;
918 }
919
920 #endif
921
922 #endif /* _LINUX_OF_H */