Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 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> |
Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 19 | #include <linux/bitops.h> |
Kalle Valo | e51130c | 2011-10-06 15:40:44 +0300 | [diff] [blame] | 20 | #include <linux/errno.h> |
Grant Likely | f57a8e2 | 2014-02-20 18:02:11 +0000 | [diff] [blame] | 21 | #include <linux/kobject.h> |
Grant Likely | 283029d | 2008-01-09 06:20:40 +1100 | [diff] [blame] | 22 | #include <linux/mod_devicetable.h> |
Grant Likely | 0d351c3 | 2010-02-14 14:13:57 -0700 | [diff] [blame] | 23 | #include <linux/spinlock.h> |
Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 24 | #include <linux/topology.h> |
Nathan Fontenot | 1cf3d8b | 2012-10-02 16:57:57 +0000 | [diff] [blame] | 25 | #include <linux/notifier.h> |
Pantelis Antoniou | 0327df4 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 26 | #include <linux/list.h> |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 27 | |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 28 | #include <asm/byteorder.h> |
Paul Gortmaker | d0a9940 | 2011-10-29 10:17:06 -0400 | [diff] [blame] | 29 | #include <asm/errno.h> |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 30 | |
Grant Likely | 731581e | 2009-10-15 10:57:46 -0600 | [diff] [blame] | 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; |
Grant Likely | f57a8e2 | 2014-02-20 18:02:11 +0000 | [diff] [blame] | 41 | struct bin_attribute attr; |
Grant Likely | 731581e | 2009-10-15 10:57:46 -0600 | [diff] [blame] | 42 | }; |
| 43 | |
Grant Likely | 6f19249 | 2009-10-15 10:57:49 -0600 | [diff] [blame] | 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; |
Grant Likely | 6016a36 | 2010-01-28 14:06:53 -0700 | [diff] [blame] | 51 | phandle phandle; |
Grant Likely | c22618a | 2012-11-14 22:37:12 +0000 | [diff] [blame] | 52 | const char *full_name; |
Grant Likely | 6f19249 | 2009-10-15 10:57:49 -0600 | [diff] [blame] | 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 */ |
Grant Likely | f57a8e2 | 2014-02-20 18:02:11 +0000 | [diff] [blame] | 61 | struct kobject kobj; |
Grant Likely | 6f19249 | 2009-10-15 10:57:49 -0600 | [diff] [blame] | 62 | unsigned long _flags; |
| 63 | void *data; |
| 64 | #if defined(CONFIG_SPARC) |
Grant Likely | c22618a | 2012-11-14 22:37:12 +0000 | [diff] [blame] | 65 | const char *path_component_name; |
Grant Likely | 6f19249 | 2009-10-15 10:57:49 -0600 | [diff] [blame] | 66 | unsigned int unique_id; |
| 67 | struct of_irq_controller *irq_trans; |
| 68 | #endif |
| 69 | }; |
| 70 | |
Grant Likely | 15c9a0a | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 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 | |
Grant Likely | e60dc70 | 2014-11-24 17:58:01 +0000 | [diff] [blame] | 78 | struct of_reconfig_data { |
| 79 | struct device_node *dn; |
| 80 | struct property *prop; |
| 81 | struct property *old_prop; |
| 82 | }; |
| 83 | |
Pantelis Antoniou | b74e9e1 | 2013-12-13 20:08:59 +0200 | [diff] [blame] | 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 | |
Grant Likely | 0f22dd3 | 2012-02-15 20:38:40 -0700 | [diff] [blame] | 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 */ |
Rob Herring | 3ecdd05 | 2011-12-13 09:13:54 -0600 | [diff] [blame] | 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 | } |
Grant Likely | 0f22dd3 | 2012-02-15 20:38:40 -0700 | [diff] [blame] | 112 | static inline void of_node_put(struct device_node *node) { } |
| 113 | #endif /* !CONFIG_OF_DYNAMIC */ |
Rob Herring | 3ecdd05 | 2011-12-13 09:13:54 -0600 | [diff] [blame] | 114 | |
Grant Likely | c9e358d | 2011-01-21 09:24:48 -0700 | [diff] [blame] | 115 | #ifdef CONFIG_OF |
| 116 | |
Grant Likely | 41f8800 | 2009-11-23 20:07:01 -0700 | [diff] [blame] | 117 | /* Pointer for first entry in chain of all nodes. */ |
Randy Dunlap | 465aac6 | 2012-11-30 10:01:51 +0000 | [diff] [blame] | 118 | extern struct device_node *of_allnodes; |
Grant Likely | fc0bdae | 2010-02-14 07:13:55 -0700 | [diff] [blame] | 119 | extern struct device_node *of_chosen; |
Shawn Guo | 611cad7 | 2011-08-15 15:28:14 +0800 | [diff] [blame] | 120 | extern struct device_node *of_aliases; |
Thomas Gleixner | d6d3c4e | 2013-02-06 15:30:56 -0500 | [diff] [blame] | 121 | extern raw_spinlock_t devtree_lock; |
Grant Likely | 41f8800 | 2009-11-23 20:07:01 -0700 | [diff] [blame] | 122 | |
Sebastian Andrzej Siewior | 3bcbaf6 | 2011-02-22 21:07:46 +0100 | [diff] [blame] | 123 | static inline bool of_have_populated_dt(void) |
| 124 | { |
Randy Dunlap | 465aac6 | 2012-11-30 10:01:51 +0000 | [diff] [blame] | 125 | return of_allnodes != NULL; |
Sebastian Andrzej Siewior | 3bcbaf6 | 2011-02-22 21:07:46 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Andres Salomon | 035ebef | 2010-07-13 09:42:26 +0000 | [diff] [blame] | 128 | static inline bool of_node_is_root(const struct device_node *node) |
| 129 | { |
| 130 | return node && (node->parent == NULL); |
| 131 | } |
| 132 | |
Grant Likely | 5043631 | 2009-10-15 10:57:58 -0600 | [diff] [blame] | 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 | |
Pawel Moll | e0bc89c | 2014-05-15 16:55:24 +0100 | [diff] [blame] | 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 | |
Grant Likely | 5043631 | 2009-10-15 10:57:58 -0600 | [diff] [blame] | 144 | static inline void of_node_set_flag(struct device_node *n, unsigned long flag) |
| 145 | { |
| 146 | set_bit(flag, &n->_flags); |
| 147 | } |
| 148 | |
Pantelis Antoniou | b49b162 | 2013-11-08 17:03:56 +0200 | [diff] [blame] | 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 | |
Grant Likely | e91edcf | 2009-10-15 10:58:09 -0600 | [diff] [blame] | 169 | extern struct device_node *of_find_all_nodes(struct device_node *prev); |
| 170 | |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 171 | /* |
Lennert Buytenhek | 3d6b882 | 2011-02-22 18:18:51 +0100 | [diff] [blame] | 172 | * OF address retrieval & translation |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 173 | */ |
| 174 | |
| 175 | /* Helper to read a big number; size is in cells (not bytes) */ |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 176 | static inline u64 of_read_number(const __be32 *cell, int size) |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 177 | { |
| 178 | u64 r = 0; |
| 179 | while (size--) |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 180 | r = (r << 32) | be32_to_cpu(*(cell++)); |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 181 | return r; |
| 182 | } |
| 183 | |
| 184 | /* Like of_read_number, but we want an unsigned long result */ |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 185 | static inline unsigned long of_read_ulong(const __be32 *cell, int size) |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 186 | { |
Grant Likely | 2be09cb | 2009-11-23 20:16:46 -0700 | [diff] [blame] | 187 | /* toss away upper bits if unsigned long is smaller than u64 */ |
| 188 | return of_read_number(cell, size); |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 189 | } |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 190 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 191 | #include <asm/prom.h> |
| 192 | |
Grant Likely | 7c7b60c | 2010-02-14 07:13:50 -0700 | [diff] [blame] | 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) |
Grant Likely | 1976152 | 2010-03-18 07:30:31 -0600 | [diff] [blame] | 201 | #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2)) |
Grant Likely | 7c7b60c | 2010-02-14 07:13:50 -0700 | [diff] [blame] | 202 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) |
| 203 | #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) |
| 204 | #endif |
| 205 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 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 */ |
Pawel Moll | e0bc89c | 2014-05-15 16:55:24 +0100 | [diff] [blame] | 209 | #define OF_POPULATED 3 /* device already created for the node */ |
Grant Likely | f2d2cdb | 2014-06-24 16:13:47 +0100 | [diff] [blame] | 210 | #define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */ |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 211 | |
Grant Likely | 61e955d | 2009-10-15 10:57:51 -0600 | [diff] [blame] | 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 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 215 | #define OF_BAD_ADDR ((u64)-1) |
| 216 | |
Steffen Trumtrar | c0a05bf | 2012-12-18 11:32:03 +0100 | [diff] [blame] | 217 | static inline const char *of_node_full_name(const struct device_node *np) |
Grant Likely | 74a7f08 | 2012-06-15 11:50:25 -0600 | [diff] [blame] | 218 | { |
| 219 | return np ? np->full_name : "<no-node>"; |
| 220 | } |
| 221 | |
Grant Likely | f57a8e2 | 2014-02-20 18:02:11 +0000 | [diff] [blame] | 222 | #define for_each_of_allnodes(dn) \ |
| 223 | for (dn = of_allnodes; dn; dn = dn->allnext) |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 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)) |
Stephen Warren | 50c8af4 | 2012-11-20 16:12:20 -0700 | [diff] [blame] | 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 | } |
Grant Likely | 283029d | 2008-01-09 06:20:40 +1100 | [diff] [blame] | 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)) |
Stephen Warren | 50c8af4 | 2012-11-20 16:12:20 -0700 | [diff] [blame] | 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)) |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 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); |
Michael Ellerman | f4eb010 | 2007-10-26 16:54:31 +1000 | [diff] [blame] | 258 | extern struct device_node *of_get_next_parent(struct device_node *node); |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 259 | extern struct device_node *of_get_next_child(const struct device_node *node, |
| 260 | struct device_node *prev); |
Timur Tabi | 3296193 | 2012-08-14 13:20:23 +0000 | [diff] [blame] | 261 | extern struct device_node *of_get_next_available_child( |
| 262 | const struct device_node *node, struct device_node *prev); |
| 263 | |
Srinivas Kandagatla | 9c19761 | 2012-09-18 08:10:28 +0100 | [diff] [blame] | 264 | extern struct device_node *of_get_child_by_name(const struct device_node *node, |
| 265 | const char *name); |
Michael Ellerman | aabc08d | 2007-11-26 19:03:45 +1100 | [diff] [blame] | 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 | |
Timur Tabi | 3296193 | 2012-08-14 13:20:23 +0000 | [diff] [blame] | 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 | |
Dong Aisheng | 183f1d0 | 2012-04-27 11:36:20 +0800 | [diff] [blame] | 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 | |
Michael Ellerman | 1e291b1 | 2008-11-12 18:54:42 +0000 | [diff] [blame] | 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 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 291 | extern struct property *of_find_property(const struct device_node *np, |
| 292 | const char *name, |
| 293 | int *lenp); |
Heiko Stuebner | 1040854 | 2014-02-12 01:00:34 +0100 | [diff] [blame] | 294 | extern int of_property_count_elems_of_size(const struct device_node *np, |
| 295 | const char *propname, int elem_size); |
Tony Prisk | 3daf372 | 2013-03-23 17:02:15 +1300 | [diff] [blame] | 296 | extern int of_property_read_u32_index(const struct device_node *np, |
| 297 | const char *propname, |
| 298 | u32 index, u32 *out_value); |
Viresh Kumar | be19324 | 2012-11-20 10:15:19 +0530 | [diff] [blame] | 299 | extern int of_property_read_u8_array(const struct device_node *np, |
| 300 | const char *propname, u8 *out_values, size_t sz); |
| 301 | extern int of_property_read_u16_array(const struct device_node *np, |
| 302 | const char *propname, u16 *out_values, size_t sz); |
Rob Herring | 0e37363 | 2011-07-06 15:42:58 -0500 | [diff] [blame] | 303 | extern int of_property_read_u32_array(const struct device_node *np, |
Jamie Iles | aac285c | 2011-08-02 15:45:07 +0100 | [diff] [blame] | 304 | const char *propname, |
Rob Herring | 0e37363 | 2011-07-06 15:42:58 -0500 | [diff] [blame] | 305 | u32 *out_values, |
| 306 | size_t sz); |
Jamie Iles | 4cd7f7a | 2011-09-14 20:49:59 +0100 | [diff] [blame] | 307 | extern int of_property_read_u64(const struct device_node *np, |
| 308 | const char *propname, u64 *out_value); |
Rob Herring | 0e37363 | 2011-07-06 15:42:58 -0500 | [diff] [blame] | 309 | |
Jamie Iles | aac285c | 2011-08-02 15:45:07 +0100 | [diff] [blame] | 310 | extern int of_property_read_string(struct device_node *np, |
| 311 | const char *propname, |
| 312 | const char **out_string); |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 313 | extern int of_property_match_string(struct device_node *np, |
| 314 | const char *propname, |
| 315 | const char *string); |
Grant Likely | 96db973 | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 316 | extern 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 Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 319 | extern int of_device_is_compatible(const struct device_node *device, |
| 320 | const char *); |
Josh Boyer | 834d97d | 2008-03-27 00:33:14 +1100 | [diff] [blame] | 321 | extern int of_device_is_available(const struct device_node *device); |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 322 | extern const void *of_get_property(const struct device_node *node, |
| 323 | const char *name, |
| 324 | int *lenp); |
Sudeep KarkadaNagesha | 6e2bb91 | 2013-08-15 14:01:40 +0100 | [diff] [blame] | 325 | extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); |
Dong Aisheng | 8af0da9 | 2011-12-22 20:19:24 +0800 | [diff] [blame] | 326 | #define for_each_property_of_node(dn, pp) \ |
| 327 | for (pp = dn->properties; pp != NULL; pp = pp->next) |
Shawn Guo | 611cad7 | 2011-08-15 15:28:14 +0800 | [diff] [blame] | 328 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 329 | extern int of_n_addr_cells(struct device_node *np); |
| 330 | extern int of_n_size_cells(struct device_node *np); |
Grant Likely | 283029d | 2008-01-09 06:20:40 +1100 | [diff] [blame] | 331 | extern const struct of_device_id *of_match_node( |
| 332 | const struct of_device_id *matches, const struct device_node *node); |
Grant Likely | 3f07af4 | 2008-07-25 22:25:13 -0400 | [diff] [blame] | 333 | extern int of_modalias_node(struct device_node *node, char *modalias, int len); |
Steffen Trumtrar | b8fbdc4 | 2012-11-22 12:16:43 +0100 | [diff] [blame] | 334 | extern struct device_node *of_parse_phandle(const struct device_node *np, |
Grant Likely | 739649c | 2009-04-25 12:52:40 +0000 | [diff] [blame] | 335 | const char *phandle_name, |
| 336 | int index); |
Guennadi Liakhovetski | 93c667c | 2012-12-10 20:41:30 +0100 | [diff] [blame] | 337 | extern int of_parse_phandle_with_args(const struct device_node *np, |
Anton Vorontsov | 64b60e0 | 2008-10-10 04:43:17 +0000 | [diff] [blame] | 338 | const char *list_name, const char *cells_name, int index, |
Grant Likely | 15c9a0a | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 339 | struct of_phandle_args *out_args); |
Stephen Warren | f35c093 | 2013-08-14 15:27:10 -0600 | [diff] [blame] | 340 | extern 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 Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 343 | extern int of_count_phandle_with_args(const struct device_node *np, |
| 344 | const char *list_name, const char *cells_name); |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 345 | |
Shawn Guo | 611cad7 | 2011-08-15 15:28:14 +0800 | [diff] [blame] | 346 | extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); |
| 347 | extern int of_alias_get_id(struct device_node *np, const char *stem); |
| 348 | |
Grant Likely | 21b082e | 2010-02-14 07:13:38 -0700 | [diff] [blame] | 349 | extern int of_machine_is_compatible(const char *compat); |
| 350 | |
Nathan Fontenot | 79d1c71 | 2012-10-02 16:58:46 +0000 | [diff] [blame] | 351 | extern int of_add_property(struct device_node *np, struct property *prop); |
| 352 | extern int of_remove_property(struct device_node *np, struct property *prop); |
| 353 | extern int of_update_property(struct device_node *np, struct property *newprop); |
Grant Likely | 21b082e | 2010-02-14 07:13:38 -0700 | [diff] [blame] | 354 | |
Grant Likely | fcdeb7f | 2010-01-29 05:04:33 -0700 | [diff] [blame] | 355 | /* For updating the device tree at runtime */ |
Nathan Fontenot | 1cf3d8b | 2012-10-02 16:57:57 +0000 | [diff] [blame] | 356 | #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 Fontenot | 1cf3d8b | 2012-10-02 16:57:57 +0000 | [diff] [blame] | 362 | extern int of_attach_node(struct device_node *); |
| 363 | extern int of_detach_node(struct device_node *); |
Grant Likely | fcdeb7f | 2010-01-29 05:04:33 -0700 | [diff] [blame] | 364 | |
Ben Dooks | 3a1e362 | 2011-08-03 10:11:42 +0100 | [diff] [blame] | 365 | #define of_match_ptr(_ptr) (_ptr) |
Stephen Warren | c541adc | 2012-04-04 09:27:46 -0600 | [diff] [blame] | 366 | |
| 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 | */ |
| 375 | const __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 | */ |
| 390 | const 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 Hauer | 88a8104 | 2013-08-05 14:40:44 +0200 | [diff] [blame] | 397 | int of_device_is_stdout_path(struct device_node *dn); |
| 398 | |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 399 | #else /* CONFIG_OF */ |
Sebastian Andrzej Siewior | 3bcbaf6 | 2011-02-22 21:07:46 +0100 | [diff] [blame] | 400 | |
Grant Likely | 74a7f08 | 2012-06-15 11:50:25 -0600 | [diff] [blame] | 401 | static inline const char* of_node_full_name(struct device_node *np) |
| 402 | { |
| 403 | return "<no-node>"; |
| 404 | } |
| 405 | |
Peter Ujfalusi | 1cc44f4 | 2012-09-10 13:46:24 +0300 | [diff] [blame] | 406 | static inline struct device_node *of_find_node_by_name(struct device_node *from, |
| 407 | const char *name) |
| 408 | { |
| 409 | return NULL; |
| 410 | } |
| 411 | |
Alexander Shiyan | 066ec1d | 2013-04-09 19:47:40 +0400 | [diff] [blame] | 412 | static inline struct device_node *of_get_parent(const struct device_node *node) |
| 413 | { |
| 414 | return NULL; |
| 415 | } |
| 416 | |
Sebastian Andrzej Siewior | 3bcbaf6 | 2011-02-22 21:07:46 +0100 | [diff] [blame] | 417 | static inline bool of_have_populated_dt(void) |
| 418 | { |
| 419 | return false; |
| 420 | } |
| 421 | |
Stephen Warren | aba3dff | 2011-09-21 13:23:10 -0600 | [diff] [blame] | 422 | #define for_each_child_of_node(parent, child) \ |
| 423 | while (0) |
| 424 | |
Olof Johansson | 25c040c | 2012-10-07 10:40:54 -0700 | [diff] [blame] | 425 | static 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 Aisheng | 183f1d0 | 2012-04-27 11:36:20 +0800 | [diff] [blame] | 432 | static inline int of_get_child_count(const struct device_node *np) |
| 433 | { |
| 434 | return 0; |
| 435 | } |
| 436 | |
Rajendra Nayak | 36a0904 | 2011-10-10 21:49:35 +0530 | [diff] [blame] | 437 | static inline int of_device_is_compatible(const struct device_node *device, |
| 438 | const char *name) |
| 439 | { |
| 440 | return 0; |
| 441 | } |
| 442 | |
Rob Herring | d719569 | 2013-03-20 16:56:18 -0500 | [diff] [blame] | 443 | static inline int of_device_is_available(const struct device_node *device) |
| 444 | { |
| 445 | return 0; |
| 446 | } |
| 447 | |
Stephen Warren | aba3dff | 2011-09-21 13:23:10 -0600 | [diff] [blame] | 448 | static 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 Guo | 2261cc6 | 2012-02-15 10:47:42 -0800 | [diff] [blame] | 455 | static 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 Stuebner | 1040854 | 2014-02-12 01:00:34 +0100 | [diff] [blame] | 463 | static 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 Prisk | 3daf372 | 2013-03-23 17:02:15 +1300 | [diff] [blame] | 469 | static 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 Kumar | be19324 | 2012-11-20 10:15:19 +0530 | [diff] [blame] | 475 | static 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 | |
| 481 | static 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 Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 487 | static inline int of_property_read_u32_array(const struct device_node *np, |
Jamie Iles | aac285c | 2011-08-02 15:45:07 +0100 | [diff] [blame] | 488 | const char *propname, |
| 489 | u32 *out_values, size_t sz) |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 490 | { |
| 491 | return -ENOSYS; |
| 492 | } |
| 493 | |
| 494 | static inline int of_property_read_string(struct device_node *np, |
Jamie Iles | aac285c | 2011-08-02 15:45:07 +0100 | [diff] [blame] | 495 | const char *propname, |
| 496 | const char **out_string) |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 497 | { |
| 498 | return -ENOSYS; |
| 499 | } |
| 500 | |
Grant Likely | 96db973 | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 501 | static 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 Cousson | 4fcd15a | 2011-09-27 17:45:43 +0200 | [diff] [blame] | 504 | { |
| 505 | return -ENOSYS; |
| 506 | } |
| 507 | |
Stephen Warren | 89272b8 | 2011-08-05 16:50:30 -0600 | [diff] [blame] | 508 | static 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 KarkadaNagesha | 6e2bb91 | 2013-08-15 14:01:40 +0100 | [diff] [blame] | 515 | static inline struct device_node *of_get_cpu_node(int cpu, |
| 516 | unsigned int *thread) |
| 517 | { |
| 518 | return NULL; |
| 519 | } |
| 520 | |
Jamie Iles | 4cd7f7a | 2011-09-14 20:49:59 +0100 | [diff] [blame] | 521 | static 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 Reding | bd3d550 | 2012-04-13 16:18:34 +0200 | [diff] [blame] | 527 | static 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 Trumtrar | b8fbdc4 | 2012-11-22 12:16:43 +0100 | [diff] [blame] | 534 | static inline struct device_node *of_parse_phandle(const struct device_node *np, |
Rajendra Nayak | 36a0904 | 2011-10-10 21:49:35 +0530 | [diff] [blame] | 535 | const char *phandle_name, |
| 536 | int index) |
| 537 | { |
| 538 | return NULL; |
| 539 | } |
| 540 | |
Thierry Reding | e05e507 | 2012-04-13 16:19:21 +0200 | [diff] [blame] | 541 | static 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 Warren | f35c093 | 2013-08-14 15:27:10 -0600 | [diff] [blame] | 550 | static 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 Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 557 | static 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 Ferre | ed5f886 | 2011-10-27 11:07:28 +0200 | [diff] [blame] | 564 | static inline int of_alias_get_id(struct device_node *np, const char *stem) |
| 565 | { |
| 566 | return -ENOSYS; |
| 567 | } |
| 568 | |
Stephen Warren | 50e07f8 | 2011-10-25 14:01:26 +0200 | [diff] [blame] | 569 | static inline int of_machine_is_compatible(const char *compat) |
| 570 | { |
| 571 | return 0; |
| 572 | } |
| 573 | |
Sascha Hauer | 88a8104 | 2013-08-05 14:40:44 +0200 | [diff] [blame] | 574 | static inline int of_device_is_stdout_path(struct device_node *dn) |
| 575 | { |
| 576 | return 0; |
| 577 | } |
| 578 | |
Ben Dooks | 3a1e362 | 2011-08-03 10:11:42 +0100 | [diff] [blame] | 579 | #define of_match_ptr(_ptr) NULL |
Nicolas Ferre | 5762c20 | 2011-10-24 11:53:32 +0200 | [diff] [blame] | 580 | #define of_match_node(_matches, _node) NULL |
Stephen Warren | c541adc | 2012-04-04 09:27:46 -0600 | [diff] [blame] | 581 | #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 Kerr | 9dfbf20 | 2010-02-14 07:13:43 -0700 | [diff] [blame] | 585 | #endif /* CONFIG_OF */ |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 586 | |
Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 587 | #ifndef of_node_to_nid |
| 588 | static 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-VILLARD | fa4d34c | 2012-02-07 12:12:51 +0800 | [diff] [blame] | 596 | /** |
Grant Likely | 96db973 | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 597 | * 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 | */ |
| 609 | static 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 | */ |
| 628 | static 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 | */ |
| 652 | static 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 Brown | 7710601 | 2015-02-16 16:57:48 +0900 | [diff] [blame] | 660 | /* |
Heiko Stuebner | 1040854 | 2014-02-12 01:00:34 +0100 | [diff] [blame] | 661 | * 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 | */ |
| 671 | static 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 | */ |
| 688 | static 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 | */ |
| 705 | static 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 | */ |
| 722 | static 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 Likely | 96db973 | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 728 | /** |
Jean-Christophe PLAGNIOL-VILLARD | fa4d34c | 2012-02-07 12:12:51 +0800 | [diff] [blame] | 729 | * 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 | */ |
| 736 | static 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 Kumar | be19324 | 2012-11-20 10:15:19 +0530 | [diff] [blame] | 744 | static 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 | |
| 751 | static 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 Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 758 | static inline int of_property_read_u32(const struct device_node *np, |
Jamie Iles | aac285c | 2011-08-02 15:45:07 +0100 | [diff] [blame] | 759 | const char *propname, |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 760 | u32 *out_value) |
| 761 | { |
| 762 | return of_property_read_u32_array(np, propname, out_value, 1); |
| 763 | } |
| 764 | |
Pantelis Antoniou | 67cf773 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 765 | /** |
| 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 | */ |
| 779 | struct 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 | */ |
| 797 | struct of_changeset { |
| 798 | struct list_head entries; |
| 799 | }; |
| 800 | |
Pantelis Antoniou | 8f2b727 | 2014-10-28 22:33:53 +0200 | [diff] [blame] | 801 | enum of_reconfig_change { |
| 802 | OF_RECONFIG_NO_CHANGE = 0, |
| 803 | OF_RECONFIG_CHANGE_ADD, |
| 804 | OF_RECONFIG_CHANGE_REMOVE, |
| 805 | }; |
| 806 | |
Pantelis Antoniou | 67cf773 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 807 | #ifdef CONFIG_OF_DYNAMIC |
Grant Likely | e60dc70 | 2014-11-24 17:58:01 +0000 | [diff] [blame] | 808 | extern int of_reconfig_notifier_register(struct notifier_block *); |
| 809 | extern int of_reconfig_notifier_unregister(struct notifier_block *); |
| 810 | extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd); |
| 811 | extern int of_reconfig_get_state_change(unsigned long action, |
| 812 | struct of_reconfig_data *arg); |
| 813 | |
Pantelis Antoniou | 67cf773 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 814 | extern void of_changeset_init(struct of_changeset *ocs); |
| 815 | extern void of_changeset_destroy(struct of_changeset *ocs); |
| 816 | extern int of_changeset_apply(struct of_changeset *ocs); |
| 817 | extern int of_changeset_revert(struct of_changeset *ocs); |
| 818 | extern int of_changeset_action(struct of_changeset *ocs, |
| 819 | unsigned long action, struct device_node *np, |
| 820 | struct property *prop); |
| 821 | |
| 822 | static 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 | |
| 828 | static 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 | |
| 834 | static 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 | |
| 840 | static 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 | |
| 846 | static 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 Likely | e60dc70 | 2014-11-24 17:58:01 +0000 | [diff] [blame] | 851 | #else /* CONFIG_OF_DYNAMIC */ |
| 852 | static inline int of_reconfig_notifier_register(struct notifier_block *nb) |
| 853 | { |
| 854 | return -EINVAL; |
| 855 | } |
| 856 | static inline int of_reconfig_notifier_unregister(struct notifier_block *nb) |
| 857 | { |
| 858 | return -EINVAL; |
| 859 | } |
| 860 | static inline int of_reconfig_notify(unsigned long action, |
| 861 | struct of_reconfig_data *arg) |
| 862 | { |
| 863 | return -EINVAL; |
| 864 | } |
| 865 | static 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 Antoniou | 67cf773 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 871 | |
Pantelis Antoniou | 614005d | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 872 | /* CONFIG_OF_RESOLVE api */ |
| 873 | extern int of_resolve_phandles(struct device_node *tree); |
David Howells | 34db8aa | 2013-04-12 02:29:19 +0100 | [diff] [blame] | 874 | |
Pantelis Antoniou | 0327df4 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 875 | /** |
| 876 | * Overlay support |
| 877 | */ |
| 878 | |
| 879 | #ifdef CONFIG_OF_OVERLAY |
| 880 | |
| 881 | /* ID based overlays; the API for external users */ |
| 882 | int of_overlay_create(struct device_node *tree); |
| 883 | int of_overlay_destroy(int id); |
| 884 | int of_overlay_destroy_all(void); |
| 885 | |
| 886 | #else |
| 887 | |
| 888 | static inline int of_overlay_create(struct device_node *tree) |
| 889 | { |
| 890 | return -ENOTSUPP; |
| 891 | } |
| 892 | |
| 893 | static inline int of_overlay_destroy(int id) |
| 894 | { |
| 895 | return -ENOTSUPP; |
| 896 | } |
| 897 | |
| 898 | static inline int of_overlay_destroy_all(void) |
| 899 | { |
| 900 | return -ENOTSUPP; |
| 901 | } |
| 902 | |
| 903 | #endif |
| 904 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 905 | #endif /* _LINUX_OF_H */ |