blob: c00415ccec4bcaa3b8bec6b569f8302aa59f88a5 [file] [log] [blame]
Stephen Rothwell76c1ce72007-05-01 16:19:07 +10001#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>
Jiri Slaby1977f032007-10-18 23:40:25 -070019#include <linux/bitops.h>
Kalle Valoe51130c2011-10-06 15:40:44 +030020#include <linux/errno.h>
Grant Likelyf57a8e22014-02-20 18:02:11 +000021#include <linux/kobject.h>
Grant Likely283029d2008-01-09 06:20:40 +110022#include <linux/mod_devicetable.h>
Grant Likely0d351c32010-02-14 14:13:57 -070023#include <linux/spinlock.h>
Paul Mundt5ca4db62012-06-03 22:04:34 -070024#include <linux/topology.h>
Nathan Fontenot1cf3d8b2012-10-02 16:57:57 +000025#include <linux/notifier.h>
Pantelis Antoniou0327df42014-10-28 22:35:58 +020026#include <linux/list.h>
Stephen Rothwell76c1ce72007-05-01 16:19:07 +100027
Jeremy Kerr2e89e682010-01-30 01:41:49 -070028#include <asm/byteorder.h>
Paul Gortmakerd0a99402011-10-29 10:17:06 -040029#include <asm/errno.h>
Jeremy Kerr2e89e682010-01-30 01:41:49 -070030
Grant Likely731581e2009-10-15 10:57:46 -060031typedef u32 phandle;
32typedef u32 ihandle;
33
34struct property {
35 char *name;
36 int length;
37 void *value;
38 struct property *next;
39 unsigned long _flags;
40 unsigned int unique_id;
Grant Likelyf57a8e22014-02-20 18:02:11 +000041 struct bin_attribute attr;
Grant Likely731581e2009-10-15 10:57:46 -060042};
43
Grant Likely6f192492009-10-15 10:57:49 -060044#if defined(CONFIG_SPARC)
45struct of_irq_controller;
46#endif
47
48struct device_node {
49 const char *name;
50 const char *type;
Grant Likely6016a362010-01-28 14:06:53 -070051 phandle phandle;
Grant Likelyc22618a2012-11-14 22:37:12 +000052 const char *full_name;
Grant Likely6f192492009-10-15 10:57:49 -060053
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 */
Grant Likelyf57a8e22014-02-20 18:02:11 +000061 struct kobject kobj;
Grant Likely6f192492009-10-15 10:57:49 -060062 unsigned long _flags;
63 void *data;
64#if defined(CONFIG_SPARC)
Grant Likelyc22618a2012-11-14 22:37:12 +000065 const char *path_component_name;
Grant Likely6f192492009-10-15 10:57:49 -060066 unsigned int unique_id;
67 struct of_irq_controller *irq_trans;
68#endif
69};
70
Grant Likely15c9a0a2011-12-12 09:25:57 -070071#define MAX_PHANDLE_ARGS 8
72struct of_phandle_args {
73 struct device_node *np;
74 int args_count;
75 uint32_t args[MAX_PHANDLE_ARGS];
76};
77
Grant Likelye60dc702014-11-24 17:58:01 +000078struct of_reconfig_data {
79 struct device_node *dn;
80 struct property *prop;
81 struct property *old_prop;
82};
83
Pantelis Antonioub74e9e12013-12-13 20:08:59 +020084/* initialize a node */
85extern struct kobj_type of_node_ktype;
86static 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 */
92static 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) */
98static inline int of_node_is_attached(struct device_node *node)
99{
100 return node && node->kobj.state_in_sysfs;
101}
102
Grant Likely0f22dd32012-02-15 20:38:40 -0700103#ifdef CONFIG_OF_DYNAMIC
104extern struct device_node *of_node_get(struct device_node *node);
105extern void of_node_put(struct device_node *node);
106#else /* CONFIG_OF_DYNAMIC */
Rob Herring3ecdd052011-12-13 09:13:54 -0600107/* Dummy ref counting routines - to be implemented later */
108static inline struct device_node *of_node_get(struct device_node *node)
109{
110 return node;
111}
Grant Likely0f22dd32012-02-15 20:38:40 -0700112static inline void of_node_put(struct device_node *node) { }
113#endif /* !CONFIG_OF_DYNAMIC */
Rob Herring3ecdd052011-12-13 09:13:54 -0600114
Grant Likelyc9e358d2011-01-21 09:24:48 -0700115#ifdef CONFIG_OF
116
Grant Likely41f88002009-11-23 20:07:01 -0700117/* Pointer for first entry in chain of all nodes. */
Randy Dunlap465aac62012-11-30 10:01:51 +0000118extern struct device_node *of_allnodes;
Grant Likelyfc0bdae2010-02-14 07:13:55 -0700119extern struct device_node *of_chosen;
Shawn Guo611cad72011-08-15 15:28:14 +0800120extern struct device_node *of_aliases;
Thomas Gleixnerd6d3c4e2013-02-06 15:30:56 -0500121extern raw_spinlock_t devtree_lock;
Grant Likely41f88002009-11-23 20:07:01 -0700122
Sebastian Andrzej Siewior3bcbaf62011-02-22 21:07:46 +0100123static inline bool of_have_populated_dt(void)
124{
Randy Dunlap465aac62012-11-30 10:01:51 +0000125 return of_allnodes != NULL;
Sebastian Andrzej Siewior3bcbaf62011-02-22 21:07:46 +0100126}
127
Andres Salomon035ebef2010-07-13 09:42:26 +0000128static inline bool of_node_is_root(const struct device_node *node)
129{
130 return node && (node->parent == NULL);
131}
132
Grant Likely50436312009-10-15 10:57:58 -0600133static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
134{
135 return test_bit(flag, &n->_flags);
136}
137
Pawel Molle0bc89c2014-05-15 16:55:24 +0100138static 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
Grant Likely50436312009-10-15 10:57:58 -0600144static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
145{
146 set_bit(flag, &n->_flags);
147}
148
Pantelis Antonioub49b1622013-11-08 17:03:56 +0200149static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
150{
151 clear_bit(flag, &n->_flags);
152}
153
154static inline int of_property_check_flag(struct property *p, unsigned long flag)
155{
156 return test_bit(flag, &p->_flags);
157}
158
159static inline void of_property_set_flag(struct property *p, unsigned long flag)
160{
161 set_bit(flag, &p->_flags);
162}
163
164static inline void of_property_clear_flag(struct property *p, unsigned long flag)
165{
166 clear_bit(flag, &p->_flags);
167}
168
Grant Likelye91edcf2009-10-15 10:58:09 -0600169extern struct device_node *of_find_all_nodes(struct device_node *prev);
170
Grant Likelyb6caf2a2009-10-15 10:58:00 -0600171/*
Lennert Buytenhek3d6b8822011-02-22 18:18:51 +0100172 * OF address retrieval & translation
Grant Likelyb6caf2a2009-10-15 10:58:00 -0600173 */
174
175/* Helper to read a big number; size is in cells (not bytes) */
Jeremy Kerr2e89e682010-01-30 01:41:49 -0700176static inline u64 of_read_number(const __be32 *cell, int size)
Grant Likelyb6caf2a2009-10-15 10:58:00 -0600177{
178 u64 r = 0;
179 while (size--)
Jeremy Kerr2e89e682010-01-30 01:41:49 -0700180 r = (r << 32) | be32_to_cpu(*(cell++));
Grant Likelyb6caf2a2009-10-15 10:58:00 -0600181 return r;
182}
183
184/* Like of_read_number, but we want an unsigned long result */
Jeremy Kerr2e89e682010-01-30 01:41:49 -0700185static inline unsigned long of_read_ulong(const __be32 *cell, int size)
Grant Likelyb6caf2a2009-10-15 10:58:00 -0600186{
Grant Likely2be09cb2009-11-23 20:16:46 -0700187 /* toss away upper bits if unsigned long is smaller than u64 */
188 return of_read_number(cell, size);
Grant Likelyb6caf2a2009-10-15 10:58:00 -0600189}
Grant Likelyb6caf2a2009-10-15 10:58:00 -0600190
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000191#include <asm/prom.h>
192
Grant Likely7c7b60c2010-02-14 07:13:50 -0700193/* 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)
Grant Likely19761522010-03-18 07:30:31 -0600201#define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
Grant Likely7c7b60c2010-02-14 07:13:50 -0700202#define of_prop_cmp(s1, s2) strcmp((s1), (s2))
203#define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
204#endif
205
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000206/* 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 */
Pawel Molle0bc89c2014-05-15 16:55:24 +0100209#define OF_POPULATED 3 /* device already created for the node */
Grant Likelyf2d2cdb2014-06-24 16:13:47 +0100210#define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000211
Grant Likely61e955d2009-10-15 10:57:51 -0600212#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
213#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
214
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000215#define OF_BAD_ADDR ((u64)-1)
216
Steffen Trumtrarc0a05bf2012-12-18 11:32:03 +0100217static inline const char *of_node_full_name(const struct device_node *np)
Grant Likely74a7f082012-06-15 11:50:25 -0600218{
219 return np ? np->full_name : "<no-node>";
220}
221
Grant Likelyf57a8e22014-02-20 18:02:11 +0000222#define for_each_of_allnodes(dn) \
223 for (dn = of_allnodes; dn; dn = dn->allnext)
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000224extern 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))
229extern 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))
234extern 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))
Stephen Warren50c8af42012-11-20 16:12:20 -0700239extern 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);
243static 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}
Grant Likely283029d2008-01-09 06:20:40 +1100249#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))
Stephen Warren50c8af42012-11-20 16:12:20 -0700252#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))
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000255extern struct device_node *of_find_node_by_path(const char *path);
256extern struct device_node *of_find_node_by_phandle(phandle handle);
257extern struct device_node *of_get_parent(const struct device_node *node);
Michael Ellermanf4eb0102007-10-26 16:54:31 +1000258extern struct device_node *of_get_next_parent(struct device_node *node);
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000259extern struct device_node *of_get_next_child(const struct device_node *node,
260 struct device_node *prev);
Timur Tabi32961932012-08-14 13:20:23 +0000261extern struct device_node *of_get_next_available_child(
262 const struct device_node *node, struct device_node *prev);
263
Srinivas Kandagatla9c197612012-09-18 08:10:28 +0100264extern struct device_node *of_get_child_by_name(const struct device_node *node,
265 const char *name);
Michael Ellermanaabc08d2007-11-26 19:03:45 +1100266#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
Timur Tabi32961932012-08-14 13:20:23 +0000270#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
Dong Aisheng183f1d02012-04-27 11:36:20 +0800274static 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
Michael Ellerman1e291b12008-11-12 18:54:42 +0000285extern 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
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000291extern struct property *of_find_property(const struct device_node *np,
292 const char *name,
293 int *lenp);
Heiko Stuebner10408542014-02-12 01:00:34 +0100294extern int of_property_count_elems_of_size(const struct device_node *np,
295 const char *propname, int elem_size);
Tony Prisk3daf3722013-03-23 17:02:15 +1300296extern int of_property_read_u32_index(const struct device_node *np,
297 const char *propname,
298 u32 index, u32 *out_value);
Viresh Kumarbe193242012-11-20 10:15:19 +0530299extern int of_property_read_u8_array(const struct device_node *np,
300 const char *propname, u8 *out_values, size_t sz);
301extern int of_property_read_u16_array(const struct device_node *np,
302 const char *propname, u16 *out_values, size_t sz);
Rob Herring0e373632011-07-06 15:42:58 -0500303extern int of_property_read_u32_array(const struct device_node *np,
Jamie Ilesaac285c2011-08-02 15:45:07 +0100304 const char *propname,
Rob Herring0e373632011-07-06 15:42:58 -0500305 u32 *out_values,
306 size_t sz);
Jamie Iles4cd7f7a2011-09-14 20:49:59 +0100307extern int of_property_read_u64(const struct device_node *np,
308 const char *propname, u64 *out_value);
Rob Herring0e373632011-07-06 15:42:58 -0500309
Jamie Ilesaac285c2011-08-02 15:45:07 +0100310extern int of_property_read_string(struct device_node *np,
311 const char *propname,
312 const char **out_string);
Grant Likely7aff0fe2011-12-12 09:25:58 -0700313extern int of_property_match_string(struct device_node *np,
314 const char *propname,
315 const char *string);
Grant Likely96db9732014-11-03 15:15:35 +0000316extern int of_property_read_string_helper(struct device_node *np,
317 const char *propname,
318 const char **out_strs, size_t sz, int index);
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000319extern int of_device_is_compatible(const struct device_node *device,
320 const char *);
Josh Boyer834d97d2008-03-27 00:33:14 +1100321extern int of_device_is_available(const struct device_node *device);
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000322extern const void *of_get_property(const struct device_node *node,
323 const char *name,
324 int *lenp);
Sudeep KarkadaNagesha6e2bb912013-08-15 14:01:40 +0100325extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
Dong Aisheng8af0da92011-12-22 20:19:24 +0800326#define for_each_property_of_node(dn, pp) \
327 for (pp = dn->properties; pp != NULL; pp = pp->next)
Shawn Guo611cad72011-08-15 15:28:14 +0800328
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000329extern int of_n_addr_cells(struct device_node *np);
330extern int of_n_size_cells(struct device_node *np);
Grant Likely283029d2008-01-09 06:20:40 +1100331extern const struct of_device_id *of_match_node(
332 const struct of_device_id *matches, const struct device_node *node);
Grant Likely3f07af42008-07-25 22:25:13 -0400333extern int of_modalias_node(struct device_node *node, char *modalias, int len);
Steffen Trumtrarb8fbdc42012-11-22 12:16:43 +0100334extern struct device_node *of_parse_phandle(const struct device_node *np,
Grant Likely739649c2009-04-25 12:52:40 +0000335 const char *phandle_name,
336 int index);
Guennadi Liakhovetski93c667c2012-12-10 20:41:30 +0100337extern int of_parse_phandle_with_args(const struct device_node *np,
Anton Vorontsov64b60e02008-10-10 04:43:17 +0000338 const char *list_name, const char *cells_name, int index,
Grant Likely15c9a0a2011-12-12 09:25:57 -0700339 struct of_phandle_args *out_args);
Stephen Warrenf35c0932013-08-14 15:27:10 -0600340extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
341 const char *list_name, int cells_count, int index,
342 struct of_phandle_args *out_args);
Grant Likelybd69f732013-02-10 22:57:21 +0000343extern int of_count_phandle_with_args(const struct device_node *np,
344 const char *list_name, const char *cells_name);
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000345
Shawn Guo611cad72011-08-15 15:28:14 +0800346extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
347extern int of_alias_get_id(struct device_node *np, const char *stem);
348
Grant Likely21b082e2010-02-14 07:13:38 -0700349extern int of_machine_is_compatible(const char *compat);
350
Nathan Fontenot79d1c712012-10-02 16:58:46 +0000351extern int of_add_property(struct device_node *np, struct property *prop);
352extern int of_remove_property(struct device_node *np, struct property *prop);
353extern int of_update_property(struct device_node *np, struct property *newprop);
Grant Likely21b082e2010-02-14 07:13:38 -0700354
Grant Likelyfcdeb7f2010-01-29 05:04:33 -0700355/* For updating the device tree at runtime */
Nathan Fontenot1cf3d8b2012-10-02 16:57:57 +0000356#define OF_RECONFIG_ATTACH_NODE 0x0001
357#define OF_RECONFIG_DETACH_NODE 0x0002
358#define OF_RECONFIG_ADD_PROPERTY 0x0003
359#define OF_RECONFIG_REMOVE_PROPERTY 0x0004
360#define OF_RECONFIG_UPDATE_PROPERTY 0x0005
361
Nathan Fontenot1cf3d8b2012-10-02 16:57:57 +0000362extern int of_attach_node(struct device_node *);
363extern int of_detach_node(struct device_node *);
Grant Likelyfcdeb7f2010-01-29 05:04:33 -0700364
Ben Dooks3a1e3622011-08-03 10:11:42 +0100365#define of_match_ptr(_ptr) (_ptr)
Stephen Warrenc541adc2012-04-04 09:27:46 -0600366
367/*
368 * struct property *prop;
369 * const __be32 *p;
370 * u32 u;
371 *
372 * of_property_for_each_u32(np, "propname", prop, p, u)
373 * printk("U32 value: %x\n", u);
374 */
375const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
376 u32 *pu);
377#define of_property_for_each_u32(np, propname, prop, p, u) \
378 for (prop = of_find_property(np, propname, NULL), \
379 p = of_prop_next_u32(prop, NULL, &u); \
380 p; \
381 p = of_prop_next_u32(prop, p, &u))
382
383/*
384 * struct property *prop;
385 * const char *s;
386 *
387 * of_property_for_each_string(np, "propname", prop, s)
388 * printk("String value: %s\n", s);
389 */
390const char *of_prop_next_string(struct property *prop, const char *cur);
391#define of_property_for_each_string(np, propname, prop, s) \
392 for (prop = of_find_property(np, propname, NULL), \
393 s = of_prop_next_string(prop, NULL); \
394 s; \
395 s = of_prop_next_string(prop, s))
396
Sascha Hauer88a81042013-08-05 14:40:44 +0200397int of_device_is_stdout_path(struct device_node *dn);
398
Shawn Guob98c0232011-07-08 16:27:33 +0800399#else /* CONFIG_OF */
Sebastian Andrzej Siewior3bcbaf62011-02-22 21:07:46 +0100400
Grant Likely74a7f082012-06-15 11:50:25 -0600401static inline const char* of_node_full_name(struct device_node *np)
402{
403 return "<no-node>";
404}
405
Peter Ujfalusi1cc44f42012-09-10 13:46:24 +0300406static inline struct device_node *of_find_node_by_name(struct device_node *from,
407 const char *name)
408{
409 return NULL;
410}
411
Alexander Shiyan066ec1d2013-04-09 19:47:40 +0400412static inline struct device_node *of_get_parent(const struct device_node *node)
413{
414 return NULL;
415}
416
Sebastian Andrzej Siewior3bcbaf62011-02-22 21:07:46 +0100417static inline bool of_have_populated_dt(void)
418{
419 return false;
420}
421
Stephen Warrenaba3dff2011-09-21 13:23:10 -0600422#define for_each_child_of_node(parent, child) \
423 while (0)
424
Olof Johansson25c040c2012-10-07 10:40:54 -0700425static inline struct device_node *of_get_child_by_name(
426 const struct device_node *node,
427 const char *name)
428{
429 return NULL;
430}
431
Dong Aisheng183f1d02012-04-27 11:36:20 +0800432static inline int of_get_child_count(const struct device_node *np)
433{
434 return 0;
435}
436
Rajendra Nayak36a09042011-10-10 21:49:35 +0530437static inline int of_device_is_compatible(const struct device_node *device,
438 const char *name)
439{
440 return 0;
441}
442
Rob Herringd7195692013-03-20 16:56:18 -0500443static inline int of_device_is_available(const struct device_node *device)
444{
445 return 0;
446}
447
Stephen Warrenaba3dff2011-09-21 13:23:10 -0600448static inline struct property *of_find_property(const struct device_node *np,
449 const char *name,
450 int *lenp)
451{
452 return NULL;
453}
454
Shawn Guo2261cc62012-02-15 10:47:42 -0800455static inline struct device_node *of_find_compatible_node(
456 struct device_node *from,
457 const char *type,
458 const char *compat)
459{
460 return NULL;
461}
462
Heiko Stuebner10408542014-02-12 01:00:34 +0100463static inline int of_property_count_elems_of_size(const struct device_node *np,
464 const char *propname, int elem_size)
465{
466 return -ENOSYS;
467}
468
Tony Prisk3daf3722013-03-23 17:02:15 +1300469static inline int of_property_read_u32_index(const struct device_node *np,
470 const char *propname, u32 index, u32 *out_value)
471{
472 return -ENOSYS;
473}
474
Viresh Kumarbe193242012-11-20 10:15:19 +0530475static inline int of_property_read_u8_array(const struct device_node *np,
476 const char *propname, u8 *out_values, size_t sz)
477{
478 return -ENOSYS;
479}
480
481static inline int of_property_read_u16_array(const struct device_node *np,
482 const char *propname, u16 *out_values, size_t sz)
483{
484 return -ENOSYS;
485}
486
Shawn Guob98c0232011-07-08 16:27:33 +0800487static inline int of_property_read_u32_array(const struct device_node *np,
Jamie Ilesaac285c2011-08-02 15:45:07 +0100488 const char *propname,
489 u32 *out_values, size_t sz)
Shawn Guob98c0232011-07-08 16:27:33 +0800490{
491 return -ENOSYS;
492}
493
494static inline int of_property_read_string(struct device_node *np,
Jamie Ilesaac285c2011-08-02 15:45:07 +0100495 const char *propname,
496 const char **out_string)
Shawn Guob98c0232011-07-08 16:27:33 +0800497{
498 return -ENOSYS;
499}
500
Grant Likely96db9732014-11-03 15:15:35 +0000501static inline int of_property_read_string_helper(struct device_node *np,
502 const char *propname,
503 const char **out_strs, size_t sz, int index)
Benoit Cousson4fcd15a2011-09-27 17:45:43 +0200504{
505 return -ENOSYS;
506}
507
Stephen Warren89272b82011-08-05 16:50:30 -0600508static inline const void *of_get_property(const struct device_node *node,
509 const char *name,
510 int *lenp)
511{
512 return NULL;
513}
514
Sudeep KarkadaNagesha6e2bb912013-08-15 14:01:40 +0100515static inline struct device_node *of_get_cpu_node(int cpu,
516 unsigned int *thread)
517{
518 return NULL;
519}
520
Jamie Iles4cd7f7a2011-09-14 20:49:59 +0100521static inline int of_property_read_u64(const struct device_node *np,
522 const char *propname, u64 *out_value)
523{
524 return -ENOSYS;
525}
526
Thierry Redingbd3d5502012-04-13 16:18:34 +0200527static inline int of_property_match_string(struct device_node *np,
528 const char *propname,
529 const char *string)
530{
531 return -ENOSYS;
532}
533
Steffen Trumtrarb8fbdc42012-11-22 12:16:43 +0100534static inline struct device_node *of_parse_phandle(const struct device_node *np,
Rajendra Nayak36a09042011-10-10 21:49:35 +0530535 const char *phandle_name,
536 int index)
537{
538 return NULL;
539}
540
Thierry Redinge05e5072012-04-13 16:19:21 +0200541static inline int of_parse_phandle_with_args(struct device_node *np,
542 const char *list_name,
543 const char *cells_name,
544 int index,
545 struct of_phandle_args *out_args)
546{
547 return -ENOSYS;
548}
549
Stephen Warrenf35c0932013-08-14 15:27:10 -0600550static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
551 const char *list_name, int cells_count, int index,
552 struct of_phandle_args *out_args)
553{
554 return -ENOSYS;
555}
556
Grant Likelybd69f732013-02-10 22:57:21 +0000557static inline int of_count_phandle_with_args(struct device_node *np,
558 const char *list_name,
559 const char *cells_name)
560{
561 return -ENOSYS;
562}
563
Nicolas Ferreed5f8862011-10-27 11:07:28 +0200564static inline int of_alias_get_id(struct device_node *np, const char *stem)
565{
566 return -ENOSYS;
567}
568
Stephen Warren50e07f82011-10-25 14:01:26 +0200569static inline int of_machine_is_compatible(const char *compat)
570{
571 return 0;
572}
573
Sascha Hauer88a81042013-08-05 14:40:44 +0200574static inline int of_device_is_stdout_path(struct device_node *dn)
575{
576 return 0;
577}
578
Ben Dooks3a1e3622011-08-03 10:11:42 +0100579#define of_match_ptr(_ptr) NULL
Nicolas Ferre5762c202011-10-24 11:53:32 +0200580#define of_match_node(_matches, _node) NULL
Stephen Warrenc541adc2012-04-04 09:27:46 -0600581#define of_property_for_each_u32(np, propname, prop, p, u) \
582 while (0)
583#define of_property_for_each_string(np, propname, prop, s) \
584 while (0)
Jeremy Kerr9dfbf202010-02-14 07:13:43 -0700585#endif /* CONFIG_OF */
Shawn Guob98c0232011-07-08 16:27:33 +0800586
Paul Mundt5ca4db62012-06-03 22:04:34 -0700587#ifndef of_node_to_nid
588static inline int of_node_to_nid(struct device_node *np)
589{
590 return numa_node_id();
591}
592
593#define of_node_to_nid of_node_to_nid
594#endif
595
Jean-Christophe PLAGNIOL-VILLARDfa4d34c2012-02-07 12:12:51 +0800596/**
Grant Likely96db9732014-11-03 15:15:35 +0000597 * of_property_read_string_array() - Read an array of strings from a multiple
598 * strings property.
599 * @np: device node from which the property value is to be read.
600 * @propname: name of the property to be searched.
601 * @out_strs: output array of string pointers.
602 * @sz: number of array elements to read.
603 *
604 * Search for a property in a device tree node and retrieve a list of
605 * terminated string values (pointer to data, not a copy) in that property.
606 *
607 * If @out_strs is NULL, the number of strings in the property is returned.
608 */
609static inline int of_property_read_string_array(struct device_node *np,
610 const char *propname, const char **out_strs,
611 size_t sz)
612{
613 return of_property_read_string_helper(np, propname, out_strs, sz, 0);
614}
615
616/**
617 * of_property_count_strings() - Find and return the number of strings from a
618 * multiple strings property.
619 * @np: device node from which the property value is to be read.
620 * @propname: name of the property to be searched.
621 *
622 * Search for a property in a device tree node and retrieve the number of null
623 * terminated string contain in it. Returns the number of strings on
624 * success, -EINVAL if the property does not exist, -ENODATA if property
625 * does not have a value, and -EILSEQ if the string is not null-terminated
626 * within the length of the property data.
627 */
628static inline int of_property_count_strings(struct device_node *np,
629 const char *propname)
630{
631 return of_property_read_string_helper(np, propname, NULL, 0, 0);
632}
633
634/**
635 * of_property_read_string_index() - Find and read a string from a multiple
636 * strings property.
637 * @np: device node from which the property value is to be read.
638 * @propname: name of the property to be searched.
639 * @index: index of the string in the list of strings
640 * @out_string: pointer to null terminated return string, modified only if
641 * return value is 0.
642 *
643 * Search for a property in a device tree node and retrieve a null
644 * terminated string value (pointer to data, not a copy) in the list of strings
645 * contained in that property.
646 * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
647 * property does not have a value, and -EILSEQ if the string is not
648 * null-terminated within the length of the property data.
649 *
650 * The out_string pointer is modified only if a valid string can be decoded.
651 */
652static inline int of_property_read_string_index(struct device_node *np,
653 const char *propname,
654 int index, const char **output)
655{
656 int rc = of_property_read_string_helper(np, propname, output, 1, index);
657 return rc < 0 ? rc : 0;
658}
659
Mark Brown77106012015-02-16 16:57:48 +0900660/*
Heiko Stuebner10408542014-02-12 01:00:34 +0100661 * of_property_count_u8_elems - Count the number of u8 elements in a property
662 *
663 * @np: device node from which the property value is to be read.
664 * @propname: name of the property to be searched.
665 *
666 * Search for a property in a device node and count the number of u8 elements
667 * in it. Returns number of elements on sucess, -EINVAL if the property does
668 * not exist or its length does not match a multiple of u8 and -ENODATA if the
669 * property does not have a value.
670 */
671static inline int of_property_count_u8_elems(const struct device_node *np,
672 const char *propname)
673{
674 return of_property_count_elems_of_size(np, propname, sizeof(u8));
675}
676
677/**
678 * of_property_count_u16_elems - Count the number of u16 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 u16 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 u16 and -ENODATA if the
686 * property does not have a value.
687 */
688static inline int of_property_count_u16_elems(const struct device_node *np,
689 const char *propname)
690{
691 return of_property_count_elems_of_size(np, propname, sizeof(u16));
692}
693
694/**
695 * of_property_count_u32_elems - Count the number of u32 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 u32 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 u32 and -ENODATA if the
703 * property does not have a value.
704 */
705static inline int of_property_count_u32_elems(const struct device_node *np,
706 const char *propname)
707{
708 return of_property_count_elems_of_size(np, propname, sizeof(u32));
709}
710
711/**
712 * of_property_count_u64_elems - Count the number of u64 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 u64 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 u64 and -ENODATA if the
720 * property does not have a value.
721 */
722static inline int of_property_count_u64_elems(const struct device_node *np,
723 const char *propname)
724{
725 return of_property_count_elems_of_size(np, propname, sizeof(u64));
726}
727
Grant Likely96db9732014-11-03 15:15:35 +0000728/**
Jean-Christophe PLAGNIOL-VILLARDfa4d34c2012-02-07 12:12:51 +0800729 * of_property_read_bool - Findfrom a property
730 * @np: device node from which the property value is to be read.
731 * @propname: name of the property to be searched.
732 *
733 * Search for a property in a device node.
734 * Returns true if the property exist false otherwise.
735 */
736static inline bool of_property_read_bool(const struct device_node *np,
737 const char *propname)
738{
739 struct property *prop = of_find_property(np, propname, NULL);
740
741 return prop ? true : false;
742}
743
Viresh Kumarbe193242012-11-20 10:15:19 +0530744static inline int of_property_read_u8(const struct device_node *np,
745 const char *propname,
746 u8 *out_value)
747{
748 return of_property_read_u8_array(np, propname, out_value, 1);
749}
750
751static inline int of_property_read_u16(const struct device_node *np,
752 const char *propname,
753 u16 *out_value)
754{
755 return of_property_read_u16_array(np, propname, out_value, 1);
756}
757
Shawn Guob98c0232011-07-08 16:27:33 +0800758static inline int of_property_read_u32(const struct device_node *np,
Jamie Ilesaac285c2011-08-02 15:45:07 +0100759 const char *propname,
Shawn Guob98c0232011-07-08 16:27:33 +0800760 u32 *out_value)
761{
762 return of_property_read_u32_array(np, propname, out_value, 1);
763}
764
Pantelis Antoniou67cf7732014-07-04 19:58:49 +0300765/**
766 * struct of_changeset_entry - Holds a changeset entry
767 *
768 * @node: list_head for the log list
769 * @action: notifier action
770 * @np: pointer to the device node affected
771 * @prop: pointer to the property affected
772 * @old_prop: hold a pointer to the original property
773 *
774 * Every modification of the device tree during a changeset
775 * is held in a list of of_changeset_entry structures.
776 * That way we can recover from a partial application, or we can
777 * revert the changeset
778 */
779struct of_changeset_entry {
780 struct list_head node;
781 unsigned long action;
782 struct device_node *np;
783 struct property *prop;
784 struct property *old_prop;
785};
786
787/**
788 * struct of_changeset - changeset tracker structure
789 *
790 * @entries: list_head for the changeset entries
791 *
792 * changesets are a convenient way to apply bulk changes to the
793 * live tree. In case of an error, changes are rolled-back.
794 * changesets live on after initial application, and if not
795 * destroyed after use, they can be reverted in one single call.
796 */
797struct of_changeset {
798 struct list_head entries;
799};
800
Pantelis Antoniou8f2b7272014-10-28 22:33:53 +0200801enum of_reconfig_change {
802 OF_RECONFIG_NO_CHANGE = 0,
803 OF_RECONFIG_CHANGE_ADD,
804 OF_RECONFIG_CHANGE_REMOVE,
805};
806
Pantelis Antoniou67cf7732014-07-04 19:58:49 +0300807#ifdef CONFIG_OF_DYNAMIC
Grant Likelye60dc702014-11-24 17:58:01 +0000808extern int of_reconfig_notifier_register(struct notifier_block *);
809extern int of_reconfig_notifier_unregister(struct notifier_block *);
810extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
811extern int of_reconfig_get_state_change(unsigned long action,
812 struct of_reconfig_data *arg);
813
Pantelis Antoniou67cf7732014-07-04 19:58:49 +0300814extern void of_changeset_init(struct of_changeset *ocs);
815extern void of_changeset_destroy(struct of_changeset *ocs);
816extern int of_changeset_apply(struct of_changeset *ocs);
817extern int of_changeset_revert(struct of_changeset *ocs);
818extern int of_changeset_action(struct of_changeset *ocs,
819 unsigned long action, struct device_node *np,
820 struct property *prop);
821
822static inline int of_changeset_attach_node(struct of_changeset *ocs,
823 struct device_node *np)
824{
825 return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
826}
827
828static inline int of_changeset_detach_node(struct of_changeset *ocs,
829 struct device_node *np)
830{
831 return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
832}
833
834static inline int of_changeset_add_property(struct of_changeset *ocs,
835 struct device_node *np, struct property *prop)
836{
837 return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
838}
839
840static inline int of_changeset_remove_property(struct of_changeset *ocs,
841 struct device_node *np, struct property *prop)
842{
843 return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
844}
845
846static inline int of_changeset_update_property(struct of_changeset *ocs,
847 struct device_node *np, struct property *prop)
848{
849 return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
850}
Grant Likelye60dc702014-11-24 17:58:01 +0000851#else /* CONFIG_OF_DYNAMIC */
852static inline int of_reconfig_notifier_register(struct notifier_block *nb)
853{
854 return -EINVAL;
855}
856static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
857{
858 return -EINVAL;
859}
860static inline int of_reconfig_notify(unsigned long action,
861 struct of_reconfig_data *arg)
862{
863 return -EINVAL;
864}
865static inline int of_reconfig_get_state_change(unsigned long action,
866 struct of_reconfig_data *arg)
867{
868 return -EINVAL;
869}
870#endif /* CONFIG_OF_DYNAMIC */
Pantelis Antoniou67cf7732014-07-04 19:58:49 +0300871
Pantelis Antoniou614005d2014-07-04 19:59:20 +0300872/* CONFIG_OF_RESOLVE api */
873extern int of_resolve_phandles(struct device_node *tree);
David Howells34db8aa2013-04-12 02:29:19 +0100874
Pantelis Antoniou0327df42014-10-28 22:35:58 +0200875/**
876 * Overlay support
877 */
878
879#ifdef CONFIG_OF_OVERLAY
880
881/* ID based overlays; the API for external users */
882int of_overlay_create(struct device_node *tree);
883int of_overlay_destroy(int id);
884int of_overlay_destroy_all(void);
885
886#else
887
888static inline int of_overlay_create(struct device_node *tree)
889{
890 return -ENOTSUPP;
891}
892
893static inline int of_overlay_destroy(int id)
894{
895 return -ENOTSUPP;
896}
897
898static inline int of_overlay_destroy_all(void)
899{
900 return -ENOTSUPP;
901}
902
903#endif
904
Stephen Rothwell76c1ce72007-05-01 16:19:07 +1000905#endif /* _LINUX_OF_H */