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 | 75b57ec | 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> |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 26 | #include <linux/property.h> |
Pantelis Antoniou | 7518b589 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 27 | #include <linux/list.h> |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 28 | |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 29 | #include <asm/byteorder.h> |
Paul Gortmaker | d0a9940 | 2011-10-29 10:17:06 -0400 | [diff] [blame] | 30 | #include <asm/errno.h> |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 31 | |
Grant Likely | 731581e | 2009-10-15 10:57:46 -0600 | [diff] [blame] | 32 | typedef u32 phandle; |
| 33 | typedef u32 ihandle; |
| 34 | |
| 35 | struct property { |
| 36 | char *name; |
| 37 | int length; |
| 38 | void *value; |
| 39 | struct property *next; |
Rob Herring | 16bba30 | 2017-10-04 14:30:02 -0500 | [diff] [blame] | 40 | #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC) |
Grant Likely | 731581e | 2009-10-15 10:57:46 -0600 | [diff] [blame] | 41 | unsigned long _flags; |
Rob Herring | 16bba30 | 2017-10-04 14:30:02 -0500 | [diff] [blame] | 42 | #endif |
Rob Herring | 36689ec | 2017-09-29 20:08:28 -0500 | [diff] [blame] | 43 | #if defined(CONFIG_OF_PROMTREE) |
Grant Likely | 731581e | 2009-10-15 10:57:46 -0600 | [diff] [blame] | 44 | unsigned int unique_id; |
Rob Herring | 36689ec | 2017-09-29 20:08:28 -0500 | [diff] [blame] | 45 | #endif |
Rob Herring | b56b552 | 2017-10-04 14:09:40 -0500 | [diff] [blame] | 46 | #if defined(CONFIG_OF_KOBJ) |
Grant Likely | 75b57ec | 2014-02-20 18:02:11 +0000 | [diff] [blame] | 47 | struct bin_attribute attr; |
Rob Herring | b56b552 | 2017-10-04 14:09:40 -0500 | [diff] [blame] | 48 | #endif |
Grant Likely | 731581e | 2009-10-15 10:57:46 -0600 | [diff] [blame] | 49 | }; |
| 50 | |
Grant Likely | 6f19249 | 2009-10-15 10:57:49 -0600 | [diff] [blame] | 51 | #if defined(CONFIG_SPARC) |
| 52 | struct of_irq_controller; |
| 53 | #endif |
| 54 | |
| 55 | struct device_node { |
| 56 | const char *name; |
| 57 | const char *type; |
Grant Likely | 6016a36 | 2010-01-28 14:06:53 -0700 | [diff] [blame] | 58 | phandle phandle; |
Grant Likely | c22618a | 2012-11-14 22:37:12 +0000 | [diff] [blame] | 59 | const char *full_name; |
Rafael J. Wysocki | 8a0662d | 2014-11-04 14:03:59 +0100 | [diff] [blame] | 60 | struct fwnode_handle fwnode; |
Grant Likely | 6f19249 | 2009-10-15 10:57:49 -0600 | [diff] [blame] | 61 | |
| 62 | struct property *properties; |
| 63 | struct property *deadprops; /* removed properties */ |
| 64 | struct device_node *parent; |
| 65 | struct device_node *child; |
| 66 | struct device_node *sibling; |
Rob Herring | b56b552 | 2017-10-04 14:09:40 -0500 | [diff] [blame] | 67 | #if defined(CONFIG_OF_KOBJ) |
Grant Likely | 75b57ec | 2014-02-20 18:02:11 +0000 | [diff] [blame] | 68 | struct kobject kobj; |
Rob Herring | b56b552 | 2017-10-04 14:09:40 -0500 | [diff] [blame] | 69 | #endif |
Grant Likely | 6f19249 | 2009-10-15 10:57:49 -0600 | [diff] [blame] | 70 | unsigned long _flags; |
| 71 | void *data; |
| 72 | #if defined(CONFIG_SPARC) |
Grant Likely | c22618a | 2012-11-14 22:37:12 +0000 | [diff] [blame] | 73 | const char *path_component_name; |
Grant Likely | 6f19249 | 2009-10-15 10:57:49 -0600 | [diff] [blame] | 74 | unsigned int unique_id; |
| 75 | struct of_irq_controller *irq_trans; |
| 76 | #endif |
| 77 | }; |
| 78 | |
Andreas Herrmann | b66548e2 | 2014-01-17 12:08:30 +0100 | [diff] [blame] | 79 | #define MAX_PHANDLE_ARGS 16 |
Grant Likely | 15c9a0a | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 80 | struct of_phandle_args { |
| 81 | struct device_node *np; |
| 82 | int args_count; |
| 83 | uint32_t args[MAX_PHANDLE_ARGS]; |
| 84 | }; |
| 85 | |
Joerg Roedel | 74e1fbb | 2016-04-04 17:49:17 +0200 | [diff] [blame] | 86 | struct of_phandle_iterator { |
| 87 | /* Common iterator information */ |
| 88 | const char *cells_name; |
| 89 | int cell_count; |
| 90 | const struct device_node *parent; |
| 91 | |
| 92 | /* List size information */ |
| 93 | const __be32 *list_end; |
| 94 | const __be32 *phandle_end; |
| 95 | |
| 96 | /* Current position state */ |
| 97 | const __be32 *cur; |
| 98 | uint32_t cur_count; |
| 99 | phandle phandle; |
| 100 | struct device_node *node; |
| 101 | }; |
| 102 | |
Grant Likely | f5242e5 | 2014-11-24 17:58:01 +0000 | [diff] [blame] | 103 | struct of_reconfig_data { |
| 104 | struct device_node *dn; |
| 105 | struct property *prop; |
| 106 | struct property *old_prop; |
| 107 | }; |
| 108 | |
Pantelis Antoniou | 0829f6d | 2013-12-13 20:08:59 +0200 | [diff] [blame] | 109 | /* initialize a node */ |
| 110 | extern struct kobj_type of_node_ktype; |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 111 | extern const struct fwnode_operations of_fwnode_ops; |
Pantelis Antoniou | 0829f6d | 2013-12-13 20:08:59 +0200 | [diff] [blame] | 112 | static inline void of_node_init(struct device_node *node) |
| 113 | { |
Rob Herring | b56b552 | 2017-10-04 14:09:40 -0500 | [diff] [blame] | 114 | #if defined(CONFIG_OF_KOBJ) |
Pantelis Antoniou | 0829f6d | 2013-12-13 20:08:59 +0200 | [diff] [blame] | 115 | kobject_init(&node->kobj, &of_node_ktype); |
Rob Herring | b56b552 | 2017-10-04 14:09:40 -0500 | [diff] [blame] | 116 | #endif |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 117 | node->fwnode.ops = &of_fwnode_ops; |
Pantelis Antoniou | 0829f6d | 2013-12-13 20:08:59 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Rob Herring | b56b552 | 2017-10-04 14:09:40 -0500 | [diff] [blame] | 120 | #if defined(CONFIG_OF_KOBJ) |
Rob Herring | 0c3c234 | 2017-10-04 14:04:01 -0500 | [diff] [blame] | 121 | #define of_node_kobj(n) (&(n)->kobj) |
Rob Herring | b56b552 | 2017-10-04 14:09:40 -0500 | [diff] [blame] | 122 | #else |
| 123 | #define of_node_kobj(n) NULL |
| 124 | #endif |
Pantelis Antoniou | 0829f6d | 2013-12-13 20:08:59 +0200 | [diff] [blame] | 125 | |
Grant Likely | 0f22dd3 | 2012-02-15 20:38:40 -0700 | [diff] [blame] | 126 | #ifdef CONFIG_OF_DYNAMIC |
| 127 | extern struct device_node *of_node_get(struct device_node *node); |
| 128 | extern void of_node_put(struct device_node *node); |
| 129 | #else /* CONFIG_OF_DYNAMIC */ |
Rob Herring | 3ecdd05 | 2011-12-13 09:13:54 -0600 | [diff] [blame] | 130 | /* Dummy ref counting routines - to be implemented later */ |
| 131 | static inline struct device_node *of_node_get(struct device_node *node) |
| 132 | { |
| 133 | return node; |
| 134 | } |
Grant Likely | 0f22dd3 | 2012-02-15 20:38:40 -0700 | [diff] [blame] | 135 | static inline void of_node_put(struct device_node *node) { } |
| 136 | #endif /* !CONFIG_OF_DYNAMIC */ |
Rob Herring | 3ecdd05 | 2011-12-13 09:13:54 -0600 | [diff] [blame] | 137 | |
Grant Likely | 41f8800 | 2009-11-23 20:07:01 -0700 | [diff] [blame] | 138 | /* Pointer for first entry in chain of all nodes. */ |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 139 | extern struct device_node *of_root; |
Grant Likely | fc0bdae | 2010-02-14 07:13:55 -0700 | [diff] [blame] | 140 | extern struct device_node *of_chosen; |
Shawn Guo | 611cad7 | 2011-08-15 15:28:14 +0800 | [diff] [blame] | 141 | extern struct device_node *of_aliases; |
Grant Likely | a752ee5 | 2014-03-28 08:12:18 -0700 | [diff] [blame] | 142 | extern struct device_node *of_stdout; |
Thomas Gleixner | d6d3c4e | 2013-02-06 15:30:56 -0500 | [diff] [blame] | 143 | extern raw_spinlock_t devtree_lock; |
Grant Likely | 41f8800 | 2009-11-23 20:07:01 -0700 | [diff] [blame] | 144 | |
Pantelis Antoniou | 391b459 | 2015-04-24 12:41:56 +0300 | [diff] [blame] | 145 | /* flag descriptions (need to be visible even when !CONFIG_OF) */ |
| 146 | #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ |
| 147 | #define OF_DETACHED 2 /* node has been detached from the device tree */ |
| 148 | #define OF_POPULATED 3 /* device already created for the node */ |
| 149 | #define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */ |
| 150 | |
Guenter Roeck | b1d06b6 | 2015-11-06 19:28:22 -0800 | [diff] [blame] | 151 | #define OF_BAD_ADDR ((u64)-1) |
| 152 | |
Hans de Goede | 6d09dc6 | 2014-11-14 13:26:52 +0100 | [diff] [blame] | 153 | #ifdef CONFIG_OF |
Sudeep Holla | 194ec93 | 2015-05-14 15:28:24 +0100 | [diff] [blame] | 154 | void of_core_init(void); |
| 155 | |
Sakari Ailus | d20dc14 | 2017-05-24 17:53:55 +0300 | [diff] [blame] | 156 | static inline bool is_of_node(const struct fwnode_handle *fwnode) |
Rafael J. Wysocki | 8a0662d | 2014-11-04 14:03:59 +0100 | [diff] [blame] | 157 | { |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 158 | return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops; |
Rafael J. Wysocki | 8a0662d | 2014-11-04 14:03:59 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Sakari Ailus | d20dc14 | 2017-05-24 17:53:55 +0300 | [diff] [blame] | 161 | #define to_of_node(__fwnode) \ |
| 162 | ({ \ |
| 163 | typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \ |
| 164 | \ |
| 165 | is_of_node(__to_of_node_fwnode) ? \ |
| 166 | container_of(__to_of_node_fwnode, \ |
| 167 | struct device_node, fwnode) : \ |
| 168 | NULL; \ |
| 169 | }) |
Rafael J. Wysocki | 8a0662d | 2014-11-04 14:03:59 +0100 | [diff] [blame] | 170 | |
Sakari Ailus | debd3a3 | 2017-05-24 17:53:54 +0300 | [diff] [blame] | 171 | #define of_fwnode_handle(node) \ |
| 172 | ({ \ |
| 173 | typeof(node) __of_fwnode_handle_node = (node); \ |
| 174 | \ |
| 175 | __of_fwnode_handle_node ? \ |
| 176 | &__of_fwnode_handle_node->fwnode : NULL; \ |
| 177 | }) |
Sakari Ailus | 6783183 | 2017-03-28 10:52:23 +0300 | [diff] [blame] | 178 | |
Sebastian Andrzej Siewior | 3bcbaf6 | 2011-02-22 21:07:46 +0100 | [diff] [blame] | 179 | static inline bool of_have_populated_dt(void) |
| 180 | { |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 181 | return of_root != NULL; |
Sebastian Andrzej Siewior | 3bcbaf6 | 2011-02-22 21:07:46 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Andres Salomon | 035ebef | 2010-07-13 09:42:26 +0000 | [diff] [blame] | 184 | static inline bool of_node_is_root(const struct device_node *node) |
| 185 | { |
| 186 | return node && (node->parent == NULL); |
| 187 | } |
| 188 | |
Grant Likely | 5043631 | 2009-10-15 10:57:58 -0600 | [diff] [blame] | 189 | static inline int of_node_check_flag(struct device_node *n, unsigned long flag) |
| 190 | { |
| 191 | return test_bit(flag, &n->_flags); |
| 192 | } |
| 193 | |
Pawel Moll | c6e126d | 2014-05-15 16:55:24 +0100 | [diff] [blame] | 194 | static inline int of_node_test_and_set_flag(struct device_node *n, |
| 195 | unsigned long flag) |
| 196 | { |
| 197 | return test_and_set_bit(flag, &n->_flags); |
| 198 | } |
| 199 | |
Grant Likely | 5043631 | 2009-10-15 10:57:58 -0600 | [diff] [blame] | 200 | static inline void of_node_set_flag(struct device_node *n, unsigned long flag) |
| 201 | { |
| 202 | set_bit(flag, &n->_flags); |
| 203 | } |
| 204 | |
Pantelis Antoniou | 588453c | 2013-11-08 17:03:56 +0200 | [diff] [blame] | 205 | static inline void of_node_clear_flag(struct device_node *n, unsigned long flag) |
| 206 | { |
| 207 | clear_bit(flag, &n->_flags); |
| 208 | } |
| 209 | |
Rob Herring | 16bba30 | 2017-10-04 14:30:02 -0500 | [diff] [blame] | 210 | #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC) |
Pantelis Antoniou | 588453c | 2013-11-08 17:03:56 +0200 | [diff] [blame] | 211 | static inline int of_property_check_flag(struct property *p, unsigned long flag) |
| 212 | { |
| 213 | return test_bit(flag, &p->_flags); |
| 214 | } |
| 215 | |
| 216 | static inline void of_property_set_flag(struct property *p, unsigned long flag) |
| 217 | { |
| 218 | set_bit(flag, &p->_flags); |
| 219 | } |
| 220 | |
| 221 | static inline void of_property_clear_flag(struct property *p, unsigned long flag) |
| 222 | { |
| 223 | clear_bit(flag, &p->_flags); |
| 224 | } |
Rob Herring | 16bba30 | 2017-10-04 14:30:02 -0500 | [diff] [blame] | 225 | #endif |
Pantelis Antoniou | 588453c | 2013-11-08 17:03:56 +0200 | [diff] [blame] | 226 | |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 227 | extern struct device_node *__of_find_all_nodes(struct device_node *prev); |
Grant Likely | e91edcf | 2009-10-15 10:58:09 -0600 | [diff] [blame] | 228 | extern struct device_node *of_find_all_nodes(struct device_node *prev); |
| 229 | |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 230 | /* |
Lennert Buytenhek | 3d6b882 | 2011-02-22 18:18:51 +0100 | [diff] [blame] | 231 | * OF address retrieval & translation |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 232 | */ |
| 233 | |
| 234 | /* Helper to read a big number; size is in cells (not bytes) */ |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 235 | static inline u64 of_read_number(const __be32 *cell, int size) |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 236 | { |
| 237 | u64 r = 0; |
| 238 | while (size--) |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 239 | r = (r << 32) | be32_to_cpu(*(cell++)); |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 240 | return r; |
| 241 | } |
| 242 | |
| 243 | /* Like of_read_number, but we want an unsigned long result */ |
Jeremy Kerr | 2e89e68 | 2010-01-30 01:41:49 -0700 | [diff] [blame] | 244 | static inline unsigned long of_read_ulong(const __be32 *cell, int size) |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 245 | { |
Grant Likely | 2be09cb | 2009-11-23 20:16:46 -0700 | [diff] [blame] | 246 | /* toss away upper bits if unsigned long is smaller than u64 */ |
| 247 | return of_read_number(cell, size); |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 248 | } |
Grant Likely | b6caf2a | 2009-10-15 10:58:00 -0600 | [diff] [blame] | 249 | |
Rob Herring | b5b4bb3 | 2013-09-07 14:08:20 -0500 | [diff] [blame] | 250 | #if defined(CONFIG_SPARC) |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 251 | #include <asm/prom.h> |
Rob Herring | b5b4bb3 | 2013-09-07 14:08:20 -0500 | [diff] [blame] | 252 | #endif |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 253 | |
Grant Likely | 7c7b60c | 2010-02-14 07:13:50 -0700 | [diff] [blame] | 254 | /* Default #address and #size cells. Allow arch asm/prom.h to override */ |
| 255 | #if !defined(OF_ROOT_NODE_ADDR_CELLS_DEFAULT) |
| 256 | #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1 |
| 257 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 |
| 258 | #endif |
| 259 | |
Grant Likely | 61e955d | 2009-10-15 10:57:51 -0600 | [diff] [blame] | 260 | #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) |
| 261 | #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) |
| 262 | |
Steffen Trumtrar | c0a05bf | 2012-12-18 11:32:03 +0100 | [diff] [blame] | 263 | 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] | 264 | { |
| 265 | return np ? np->full_name : "<no-node>"; |
| 266 | } |
| 267 | |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 268 | #define for_each_of_allnodes_from(from, dn) \ |
| 269 | for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn)) |
| 270 | #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn) |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 271 | extern struct device_node *of_find_node_by_name(struct device_node *from, |
| 272 | const char *name); |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 273 | extern struct device_node *of_find_node_by_type(struct device_node *from, |
| 274 | const char *type); |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 275 | extern struct device_node *of_find_compatible_node(struct device_node *from, |
| 276 | const char *type, const char *compat); |
Stephen Warren | 50c8af4 | 2012-11-20 16:12:20 -0700 | [diff] [blame] | 277 | extern struct device_node *of_find_matching_node_and_match( |
| 278 | struct device_node *from, |
| 279 | const struct of_device_id *matches, |
| 280 | const struct of_device_id **match); |
Rob Herring | 662372e | 2014-02-03 08:53:44 -0600 | [diff] [blame] | 281 | |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 282 | extern struct device_node *of_find_node_opts_by_path(const char *path, |
| 283 | const char **opts); |
| 284 | static inline struct device_node *of_find_node_by_path(const char *path) |
| 285 | { |
| 286 | return of_find_node_opts_by_path(path, NULL); |
| 287 | } |
| 288 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 289 | extern struct device_node *of_find_node_by_phandle(phandle handle); |
| 290 | extern struct device_node *of_get_parent(const struct device_node *node); |
Michael Ellerman | f4eb010 | 2007-10-26 16:54:31 +1000 | [diff] [blame] | 291 | extern struct device_node *of_get_next_parent(struct device_node *node); |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 292 | extern struct device_node *of_get_next_child(const struct device_node *node, |
| 293 | struct device_node *prev); |
Timur Tabi | 3296193 | 2012-08-14 13:20:23 +0000 | [diff] [blame] | 294 | extern struct device_node *of_get_next_available_child( |
| 295 | const struct device_node *node, struct device_node *prev); |
| 296 | |
Srinivas Kandagatla | 9c19761 | 2012-09-18 08:10:28 +0100 | [diff] [blame] | 297 | extern struct device_node *of_get_child_by_name(const struct device_node *node, |
| 298 | const char *name); |
Bryan Wu | 954e04b | 2013-09-24 10:38:26 -0700 | [diff] [blame] | 299 | |
Sudeep KarkadaNagesha | a3e31b4 | 2013-09-18 11:53:05 +0100 | [diff] [blame] | 300 | /* cache lookup */ |
| 301 | extern struct device_node *of_find_next_cache_node(const struct device_node *); |
Sudeep Holla | 5fa2353 | 2017-01-16 10:40:43 +0000 | [diff] [blame] | 302 | extern int of_find_last_cache_level(unsigned int cpu); |
Michael Ellerman | 1e291b14 | 2008-11-12 18:54:42 +0000 | [diff] [blame] | 303 | extern struct device_node *of_find_node_with_property( |
| 304 | struct device_node *from, const char *prop_name); |
Michael Ellerman | 1e291b14 | 2008-11-12 18:54:42 +0000 | [diff] [blame] | 305 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 306 | extern struct property *of_find_property(const struct device_node *np, |
| 307 | const char *name, |
| 308 | int *lenp); |
Heiko Stuebner | ad54a0c | 2014-02-12 01:00:34 +0100 | [diff] [blame] | 309 | extern int of_property_count_elems_of_size(const struct device_node *np, |
| 310 | const char *propname, int elem_size); |
Tony Prisk | 3daf372 | 2013-03-23 17:02:15 +1300 | [diff] [blame] | 311 | extern int of_property_read_u32_index(const struct device_node *np, |
| 312 | const char *propname, |
| 313 | u32 index, u32 *out_value); |
Alistair Popple | 2475a2b | 2017-04-03 19:51:42 +1000 | [diff] [blame] | 314 | extern int of_property_read_u64_index(const struct device_node *np, |
| 315 | const char *propname, |
| 316 | u32 index, u64 *out_value); |
Richard Fitzgerald | a67e947 | 2016-09-12 14:01:29 +0100 | [diff] [blame] | 317 | extern int of_property_read_variable_u8_array(const struct device_node *np, |
| 318 | const char *propname, u8 *out_values, |
| 319 | size_t sz_min, size_t sz_max); |
| 320 | extern int of_property_read_variable_u16_array(const struct device_node *np, |
| 321 | const char *propname, u16 *out_values, |
| 322 | size_t sz_min, size_t sz_max); |
| 323 | extern int of_property_read_variable_u32_array(const struct device_node *np, |
| 324 | const char *propname, |
| 325 | u32 *out_values, |
| 326 | size_t sz_min, |
| 327 | size_t sz_max); |
Jamie Iles | 4cd7f7a | 2011-09-14 20:49:59 +0100 | [diff] [blame] | 328 | extern int of_property_read_u64(const struct device_node *np, |
| 329 | const char *propname, u64 *out_value); |
Richard Fitzgerald | a67e947 | 2016-09-12 14:01:29 +0100 | [diff] [blame] | 330 | extern int of_property_read_variable_u64_array(const struct device_node *np, |
| 331 | const char *propname, |
| 332 | u64 *out_values, |
| 333 | size_t sz_min, |
| 334 | size_t sz_max); |
Rob Herring | 0e37363 | 2011-07-06 15:42:58 -0500 | [diff] [blame] | 335 | |
David Rivshin | fe99c70 | 2016-03-02 16:35:51 -0500 | [diff] [blame] | 336 | extern int of_property_read_string(const struct device_node *np, |
Jamie Iles | aac285c | 2011-08-02 15:45:07 +0100 | [diff] [blame] | 337 | const char *propname, |
| 338 | const char **out_string); |
David Rivshin | fe99c70 | 2016-03-02 16:35:51 -0500 | [diff] [blame] | 339 | extern int of_property_match_string(const struct device_node *np, |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 340 | const char *propname, |
| 341 | const char *string); |
David Rivshin | fe99c70 | 2016-03-02 16:35:51 -0500 | [diff] [blame] | 342 | extern int of_property_read_string_helper(const struct device_node *np, |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 343 | const char *propname, |
| 344 | const char **out_strs, size_t sz, int index); |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 345 | extern int of_device_is_compatible(const struct device_node *device, |
| 346 | const char *); |
Benjamin Herrenschmidt | b9c13fe | 2016-07-08 08:35:59 +1000 | [diff] [blame] | 347 | extern int of_device_compatible_match(struct device_node *device, |
| 348 | const char *const *compat); |
Kevin Cernekee | 53a4ab9 | 2014-11-12 12:54:01 -0800 | [diff] [blame] | 349 | extern bool of_device_is_available(const struct device_node *device); |
Kevin Cernekee | 37786c7 | 2015-04-09 13:05:14 -0700 | [diff] [blame] | 350 | extern bool of_device_is_big_endian(const struct device_node *device); |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 351 | extern const void *of_get_property(const struct device_node *node, |
| 352 | const char *name, |
| 353 | int *lenp); |
Sudeep KarkadaNagesha | 183912d | 2013-08-15 14:01:40 +0100 | [diff] [blame] | 354 | 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] | 355 | #define for_each_property_of_node(dn, pp) \ |
| 356 | for (pp = dn->properties; pp != NULL; pp = pp->next) |
Shawn Guo | 611cad7 | 2011-08-15 15:28:14 +0800 | [diff] [blame] | 357 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 358 | extern int of_n_addr_cells(struct device_node *np); |
| 359 | extern int of_n_size_cells(struct device_node *np); |
Grant Likely | 283029d | 2008-01-09 06:20:40 +1100 | [diff] [blame] | 360 | extern const struct of_device_id *of_match_node( |
| 361 | const struct of_device_id *matches, const struct device_node *node); |
Grant Likely | 3f07af4 | 2008-07-25 22:25:13 -0400 | [diff] [blame] | 362 | extern int of_modalias_node(struct device_node *node, char *modalias, int len); |
Grant Likely | 624cfca | 2013-10-11 22:05:10 +0100 | [diff] [blame] | 363 | extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args); |
Steffen Trumtrar | b8fbdc4 | 2012-11-22 12:16:43 +0100 | [diff] [blame] | 364 | extern struct device_node *of_parse_phandle(const struct device_node *np, |
Grant Likely | 739649c | 2009-04-25 12:52:40 +0000 | [diff] [blame] | 365 | const char *phandle_name, |
| 366 | int index); |
Guennadi Liakhovetski | 93c667c | 2012-12-10 20:41:30 +0100 | [diff] [blame] | 367 | extern int of_parse_phandle_with_args(const struct device_node *np, |
Anton Vorontsov | 64b60e0 | 2008-10-10 04:43:17 +0000 | [diff] [blame] | 368 | const char *list_name, const char *cells_name, int index, |
Grant Likely | 15c9a0a | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 369 | struct of_phandle_args *out_args); |
Stephen Warren | 035fd94 | 2013-08-14 15:27:10 -0600 | [diff] [blame] | 370 | extern int of_parse_phandle_with_fixed_args(const struct device_node *np, |
| 371 | const char *list_name, int cells_count, int index, |
| 372 | struct of_phandle_args *out_args); |
Grant Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 373 | extern int of_count_phandle_with_args(const struct device_node *np, |
| 374 | const char *list_name, const char *cells_name); |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 375 | |
Joerg Roedel | 74e1fbb | 2016-04-04 17:49:17 +0200 | [diff] [blame] | 376 | /* phandle iterator functions */ |
| 377 | extern int of_phandle_iterator_init(struct of_phandle_iterator *it, |
| 378 | const struct device_node *np, |
| 379 | const char *list_name, |
| 380 | const char *cells_name, |
| 381 | int cell_count); |
| 382 | |
Joerg Roedel | cd209b4 | 2016-04-04 17:49:18 +0200 | [diff] [blame] | 383 | extern int of_phandle_iterator_next(struct of_phandle_iterator *it); |
Joerg Roedel | abdaa77 | 2016-04-04 17:49:21 +0200 | [diff] [blame] | 384 | extern int of_phandle_iterator_args(struct of_phandle_iterator *it, |
| 385 | uint32_t *args, |
| 386 | int size); |
Joerg Roedel | cd209b4 | 2016-04-04 17:49:18 +0200 | [diff] [blame] | 387 | |
Shawn Guo | 611cad7 | 2011-08-15 15:28:14 +0800 | [diff] [blame] | 388 | extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); |
| 389 | extern int of_alias_get_id(struct device_node *np, const char *stem); |
Wolfram Sang | 351d224 | 2015-03-12 17:17:58 +0100 | [diff] [blame] | 390 | extern int of_alias_get_highest_id(const char *stem); |
Shawn Guo | 611cad7 | 2011-08-15 15:28:14 +0800 | [diff] [blame] | 391 | |
Grant Likely | 21b082e | 2010-02-14 07:13:38 -0700 | [diff] [blame] | 392 | extern int of_machine_is_compatible(const char *compat); |
| 393 | |
Nathan Fontenot | 79d1c71 | 2012-10-02 16:58:46 +0000 | [diff] [blame] | 394 | extern int of_add_property(struct device_node *np, struct property *prop); |
| 395 | extern int of_remove_property(struct device_node *np, struct property *prop); |
| 396 | extern int of_update_property(struct device_node *np, struct property *newprop); |
Grant Likely | 21b082e | 2010-02-14 07:13:38 -0700 | [diff] [blame] | 397 | |
Grant Likely | fcdeb7f | 2010-01-29 05:04:33 -0700 | [diff] [blame] | 398 | /* For updating the device tree at runtime */ |
Nathan Fontenot | 1cf3d8b | 2012-10-02 16:57:57 +0000 | [diff] [blame] | 399 | #define OF_RECONFIG_ATTACH_NODE 0x0001 |
| 400 | #define OF_RECONFIG_DETACH_NODE 0x0002 |
| 401 | #define OF_RECONFIG_ADD_PROPERTY 0x0003 |
| 402 | #define OF_RECONFIG_REMOVE_PROPERTY 0x0004 |
| 403 | #define OF_RECONFIG_UPDATE_PROPERTY 0x0005 |
| 404 | |
Nathan Fontenot | 1cf3d8b | 2012-10-02 16:57:57 +0000 | [diff] [blame] | 405 | extern int of_attach_node(struct device_node *); |
| 406 | extern int of_detach_node(struct device_node *); |
Grant Likely | fcdeb7f | 2010-01-29 05:04:33 -0700 | [diff] [blame] | 407 | |
Ben Dooks | 3a1e362 | 2011-08-03 10:11:42 +0100 | [diff] [blame] | 408 | #define of_match_ptr(_ptr) (_ptr) |
Stephen Warren | c541adc | 2012-04-04 09:27:46 -0600 | [diff] [blame] | 409 | |
Richard Fitzgerald | a67e947 | 2016-09-12 14:01:29 +0100 | [diff] [blame] | 410 | /** |
| 411 | * of_property_read_u8_array - Find and read an array of u8 from a property. |
| 412 | * |
| 413 | * @np: device node from which the property value is to be read. |
| 414 | * @propname: name of the property to be searched. |
| 415 | * @out_values: pointer to return value, modified only if return value is 0. |
| 416 | * @sz: number of array elements to read |
| 417 | * |
| 418 | * Search for a property in a device node and read 8-bit value(s) from |
| 419 | * it. Returns 0 on success, -EINVAL if the property does not exist, |
| 420 | * -ENODATA if property does not have a value, and -EOVERFLOW if the |
| 421 | * property data isn't large enough. |
| 422 | * |
| 423 | * dts entry of array should be like: |
| 424 | * property = /bits/ 8 <0x50 0x60 0x70>; |
| 425 | * |
| 426 | * The out_values is modified only if a valid u8 value can be decoded. |
| 427 | */ |
| 428 | static inline int of_property_read_u8_array(const struct device_node *np, |
| 429 | const char *propname, |
| 430 | u8 *out_values, size_t sz) |
| 431 | { |
| 432 | int ret = of_property_read_variable_u8_array(np, propname, out_values, |
| 433 | sz, 0); |
| 434 | if (ret >= 0) |
| 435 | return 0; |
| 436 | else |
| 437 | return ret; |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * of_property_read_u16_array - Find and read an array of u16 from a property. |
| 442 | * |
| 443 | * @np: device node from which the property value is to be read. |
| 444 | * @propname: name of the property to be searched. |
| 445 | * @out_values: pointer to return value, modified only if return value is 0. |
| 446 | * @sz: number of array elements to read |
| 447 | * |
| 448 | * Search for a property in a device node and read 16-bit value(s) from |
| 449 | * it. Returns 0 on success, -EINVAL if the property does not exist, |
| 450 | * -ENODATA if property does not have a value, and -EOVERFLOW if the |
| 451 | * property data isn't large enough. |
| 452 | * |
| 453 | * dts entry of array should be like: |
| 454 | * property = /bits/ 16 <0x5000 0x6000 0x7000>; |
| 455 | * |
| 456 | * The out_values is modified only if a valid u16 value can be decoded. |
| 457 | */ |
| 458 | static inline int of_property_read_u16_array(const struct device_node *np, |
| 459 | const char *propname, |
| 460 | u16 *out_values, size_t sz) |
| 461 | { |
| 462 | int ret = of_property_read_variable_u16_array(np, propname, out_values, |
| 463 | sz, 0); |
| 464 | if (ret >= 0) |
| 465 | return 0; |
| 466 | else |
| 467 | return ret; |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * of_property_read_u32_array - Find and read an array of 32 bit integers |
| 472 | * from a property. |
| 473 | * |
| 474 | * @np: device node from which the property value is to be read. |
| 475 | * @propname: name of the property to be searched. |
| 476 | * @out_values: pointer to return value, modified only if return value is 0. |
| 477 | * @sz: number of array elements to read |
| 478 | * |
| 479 | * Search for a property in a device node and read 32-bit value(s) from |
| 480 | * it. Returns 0 on success, -EINVAL if the property does not exist, |
| 481 | * -ENODATA if property does not have a value, and -EOVERFLOW if the |
| 482 | * property data isn't large enough. |
| 483 | * |
| 484 | * The out_values is modified only if a valid u32 value can be decoded. |
| 485 | */ |
| 486 | static inline int of_property_read_u32_array(const struct device_node *np, |
| 487 | const char *propname, |
| 488 | u32 *out_values, size_t sz) |
| 489 | { |
| 490 | int ret = of_property_read_variable_u32_array(np, propname, out_values, |
| 491 | sz, 0); |
| 492 | if (ret >= 0) |
| 493 | return 0; |
| 494 | else |
| 495 | return ret; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * of_property_read_u64_array - Find and read an array of 64 bit integers |
| 500 | * from a property. |
| 501 | * |
| 502 | * @np: device node from which the property value is to be read. |
| 503 | * @propname: name of the property to be searched. |
| 504 | * @out_values: pointer to return value, modified only if return value is 0. |
| 505 | * @sz: number of array elements to read |
| 506 | * |
| 507 | * Search for a property in a device node and read 64-bit value(s) from |
| 508 | * it. Returns 0 on success, -EINVAL if the property does not exist, |
| 509 | * -ENODATA if property does not have a value, and -EOVERFLOW if the |
| 510 | * property data isn't large enough. |
| 511 | * |
| 512 | * The out_values is modified only if a valid u64 value can be decoded. |
| 513 | */ |
| 514 | static inline int of_property_read_u64_array(const struct device_node *np, |
| 515 | const char *propname, |
| 516 | u64 *out_values, size_t sz) |
| 517 | { |
| 518 | int ret = of_property_read_variable_u64_array(np, propname, out_values, |
| 519 | sz, 0); |
| 520 | if (ret >= 0) |
| 521 | return 0; |
| 522 | else |
| 523 | return ret; |
| 524 | } |
| 525 | |
Stephen Warren | c541adc | 2012-04-04 09:27:46 -0600 | [diff] [blame] | 526 | /* |
| 527 | * struct property *prop; |
| 528 | * const __be32 *p; |
| 529 | * u32 u; |
| 530 | * |
| 531 | * of_property_for_each_u32(np, "propname", prop, p, u) |
| 532 | * printk("U32 value: %x\n", u); |
| 533 | */ |
| 534 | const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur, |
| 535 | u32 *pu); |
Stephen Warren | c541adc | 2012-04-04 09:27:46 -0600 | [diff] [blame] | 536 | /* |
| 537 | * struct property *prop; |
| 538 | * const char *s; |
| 539 | * |
| 540 | * of_property_for_each_string(np, "propname", prop, s) |
| 541 | * printk("String value: %s\n", s); |
| 542 | */ |
| 543 | const char *of_prop_next_string(struct property *prop, const char *cur); |
Stephen Warren | c541adc | 2012-04-04 09:27:46 -0600 | [diff] [blame] | 544 | |
Grant Likely | 3482f2c | 2014-03-27 17:18:55 -0700 | [diff] [blame] | 545 | bool of_console_check(struct device_node *dn, char *name, int index); |
Sascha Hauer | 5c19e95 | 2013-08-05 14:40:44 +0200 | [diff] [blame] | 546 | |
Suzuki K Poulose | a0e71cd | 2018-01-02 11:25:27 +0000 | [diff] [blame] | 547 | extern int of_cpu_node_to_id(struct device_node *np); |
| 548 | |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 549 | #else /* CONFIG_OF */ |
Sebastian Andrzej Siewior | 3bcbaf6 | 2011-02-22 21:07:46 +0100 | [diff] [blame] | 550 | |
Sudeep Holla | 194ec93 | 2015-05-14 15:28:24 +0100 | [diff] [blame] | 551 | static inline void of_core_init(void) |
| 552 | { |
| 553 | } |
| 554 | |
Sakari Ailus | d20dc14 | 2017-05-24 17:53:55 +0300 | [diff] [blame] | 555 | static inline bool is_of_node(const struct fwnode_handle *fwnode) |
Rafael J. Wysocki | 8a0662d | 2014-11-04 14:03:59 +0100 | [diff] [blame] | 556 | { |
| 557 | return false; |
| 558 | } |
| 559 | |
Sakari Ailus | d20dc14 | 2017-05-24 17:53:55 +0300 | [diff] [blame] | 560 | static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode) |
Rafael J. Wysocki | 8a0662d | 2014-11-04 14:03:59 +0100 | [diff] [blame] | 561 | { |
| 562 | return NULL; |
| 563 | } |
| 564 | |
Stephen Rothwell | 4c358e1 | 2014-05-15 14:44:30 +1000 | [diff] [blame] | 565 | 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] | 566 | { |
| 567 | return "<no-node>"; |
| 568 | } |
| 569 | |
Peter Ujfalusi | 1cc44f4 | 2012-09-10 13:46:24 +0300 | [diff] [blame] | 570 | static inline struct device_node *of_find_node_by_name(struct device_node *from, |
| 571 | const char *name) |
| 572 | { |
| 573 | return NULL; |
| 574 | } |
| 575 | |
Rob Herring | 662372e | 2014-02-03 08:53:44 -0600 | [diff] [blame] | 576 | static inline struct device_node *of_find_node_by_type(struct device_node *from, |
| 577 | const char *type) |
| 578 | { |
| 579 | return NULL; |
| 580 | } |
| 581 | |
| 582 | static inline struct device_node *of_find_matching_node_and_match( |
| 583 | struct device_node *from, |
| 584 | const struct of_device_id *matches, |
| 585 | const struct of_device_id **match) |
| 586 | { |
| 587 | return NULL; |
| 588 | } |
| 589 | |
Alexander Shiyan | 20cd477 | 2014-04-16 10:49:20 +0400 | [diff] [blame] | 590 | static inline struct device_node *of_find_node_by_path(const char *path) |
| 591 | { |
| 592 | return NULL; |
| 593 | } |
| 594 | |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 595 | static inline struct device_node *of_find_node_opts_by_path(const char *path, |
| 596 | const char **opts) |
| 597 | { |
| 598 | return NULL; |
| 599 | } |
| 600 | |
Suman Anna | ce16b9d | 2015-06-17 11:53:53 -0500 | [diff] [blame] | 601 | static inline struct device_node *of_find_node_by_phandle(phandle handle) |
| 602 | { |
| 603 | return NULL; |
| 604 | } |
| 605 | |
Alexander Shiyan | 066ec1d | 2013-04-09 19:47:40 +0400 | [diff] [blame] | 606 | static inline struct device_node *of_get_parent(const struct device_node *node) |
| 607 | { |
| 608 | return NULL; |
| 609 | } |
| 610 | |
Rob Herring | 662372e | 2014-02-03 08:53:44 -0600 | [diff] [blame] | 611 | static inline struct device_node *of_get_next_child( |
| 612 | const struct device_node *node, struct device_node *prev) |
| 613 | { |
| 614 | return NULL; |
| 615 | } |
| 616 | |
| 617 | static inline struct device_node *of_get_next_available_child( |
| 618 | const struct device_node *node, struct device_node *prev) |
| 619 | { |
| 620 | return NULL; |
| 621 | } |
| 622 | |
| 623 | static inline struct device_node *of_find_node_with_property( |
| 624 | struct device_node *from, const char *prop_name) |
| 625 | { |
| 626 | return NULL; |
| 627 | } |
| 628 | |
Sakari Ailus | 6783183 | 2017-03-28 10:52:23 +0300 | [diff] [blame] | 629 | #define of_fwnode_handle(node) NULL |
| 630 | |
Sebastian Andrzej Siewior | 3bcbaf6 | 2011-02-22 21:07:46 +0100 | [diff] [blame] | 631 | static inline bool of_have_populated_dt(void) |
| 632 | { |
| 633 | return false; |
| 634 | } |
| 635 | |
Olof Johansson | 25c040c | 2012-10-07 10:40:54 -0700 | [diff] [blame] | 636 | static inline struct device_node *of_get_child_by_name( |
| 637 | const struct device_node *node, |
| 638 | const char *name) |
| 639 | { |
| 640 | return NULL; |
| 641 | } |
| 642 | |
Rajendra Nayak | 36a0904 | 2011-10-10 21:49:35 +0530 | [diff] [blame] | 643 | static inline int of_device_is_compatible(const struct device_node *device, |
| 644 | const char *name) |
| 645 | { |
| 646 | return 0; |
| 647 | } |
| 648 | |
Geert Uytterhoeven | 3bc1630 | 2017-04-25 19:38:48 +0200 | [diff] [blame] | 649 | static inline int of_device_compatible_match(struct device_node *device, |
| 650 | const char *const *compat) |
| 651 | { |
| 652 | return 0; |
| 653 | } |
| 654 | |
Kevin Cernekee | 53a4ab9 | 2014-11-12 12:54:01 -0800 | [diff] [blame] | 655 | static inline bool of_device_is_available(const struct device_node *device) |
Rob Herring | d719569 | 2013-03-20 16:56:18 -0500 | [diff] [blame] | 656 | { |
Kevin Cernekee | 53a4ab9 | 2014-11-12 12:54:01 -0800 | [diff] [blame] | 657 | return false; |
Rob Herring | d719569 | 2013-03-20 16:56:18 -0500 | [diff] [blame] | 658 | } |
| 659 | |
Kevin Cernekee | 37786c7 | 2015-04-09 13:05:14 -0700 | [diff] [blame] | 660 | static inline bool of_device_is_big_endian(const struct device_node *device) |
| 661 | { |
| 662 | return false; |
| 663 | } |
| 664 | |
Stephen Warren | aba3dff | 2011-09-21 13:23:10 -0600 | [diff] [blame] | 665 | static inline struct property *of_find_property(const struct device_node *np, |
| 666 | const char *name, |
| 667 | int *lenp) |
| 668 | { |
| 669 | return NULL; |
| 670 | } |
| 671 | |
Shawn Guo | 2261cc6 | 2012-02-15 10:47:42 -0800 | [diff] [blame] | 672 | static inline struct device_node *of_find_compatible_node( |
| 673 | struct device_node *from, |
| 674 | const char *type, |
| 675 | const char *compat) |
| 676 | { |
| 677 | return NULL; |
| 678 | } |
| 679 | |
Heiko Stuebner | ad54a0c | 2014-02-12 01:00:34 +0100 | [diff] [blame] | 680 | static inline int of_property_count_elems_of_size(const struct device_node *np, |
| 681 | const char *propname, int elem_size) |
| 682 | { |
| 683 | return -ENOSYS; |
| 684 | } |
| 685 | |
Viresh Kumar | be19324 | 2012-11-20 10:15:19 +0530 | [diff] [blame] | 686 | static inline int of_property_read_u8_array(const struct device_node *np, |
| 687 | const char *propname, u8 *out_values, size_t sz) |
| 688 | { |
| 689 | return -ENOSYS; |
| 690 | } |
| 691 | |
| 692 | static inline int of_property_read_u16_array(const struct device_node *np, |
| 693 | const char *propname, u16 *out_values, size_t sz) |
| 694 | { |
| 695 | return -ENOSYS; |
| 696 | } |
| 697 | |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 698 | 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] | 699 | const char *propname, |
| 700 | u32 *out_values, size_t sz) |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 701 | { |
| 702 | return -ENOSYS; |
| 703 | } |
| 704 | |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 705 | static inline int of_property_read_u64_array(const struct device_node *np, |
| 706 | const char *propname, |
| 707 | u64 *out_values, size_t sz) |
| 708 | { |
| 709 | return -ENOSYS; |
| 710 | } |
| 711 | |
Arnd Bergmann | 96c623e | 2017-11-06 14:26:10 +0100 | [diff] [blame] | 712 | static inline int of_property_read_u32_index(const struct device_node *np, |
| 713 | const char *propname, u32 index, u32 *out_value) |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 714 | { |
| 715 | return -ENOSYS; |
| 716 | } |
| 717 | |
Arnd Bergmann | 96c623e | 2017-11-06 14:26:10 +0100 | [diff] [blame] | 718 | static inline int of_property_read_u64_index(const struct device_node *np, |
| 719 | const char *propname, u32 index, u64 *out_value) |
Benoit Cousson | 4fcd15a | 2011-09-27 17:45:43 +0200 | [diff] [blame] | 720 | { |
| 721 | return -ENOSYS; |
| 722 | } |
| 723 | |
Stephen Warren | 89272b8 | 2011-08-05 16:50:30 -0600 | [diff] [blame] | 724 | static inline const void *of_get_property(const struct device_node *node, |
| 725 | const char *name, |
| 726 | int *lenp) |
| 727 | { |
| 728 | return NULL; |
| 729 | } |
| 730 | |
Sudeep KarkadaNagesha | 183912d | 2013-08-15 14:01:40 +0100 | [diff] [blame] | 731 | static inline struct device_node *of_get_cpu_node(int cpu, |
| 732 | unsigned int *thread) |
| 733 | { |
| 734 | return NULL; |
| 735 | } |
| 736 | |
Arnd Bergmann | 8a1ac5d | 2017-10-13 15:57:40 -0700 | [diff] [blame] | 737 | static inline int of_n_addr_cells(struct device_node *np) |
| 738 | { |
| 739 | return 0; |
| 740 | |
| 741 | } |
| 742 | static inline int of_n_size_cells(struct device_node *np) |
| 743 | { |
| 744 | return 0; |
| 745 | } |
| 746 | |
Arnd Bergmann | 96c623e | 2017-11-06 14:26:10 +0100 | [diff] [blame] | 747 | static inline int of_property_read_variable_u8_array(const struct device_node *np, |
| 748 | const char *propname, u8 *out_values, |
| 749 | size_t sz_min, size_t sz_max) |
| 750 | { |
| 751 | return -ENOSYS; |
| 752 | } |
| 753 | |
| 754 | static inline int of_property_read_variable_u16_array(const struct device_node *np, |
| 755 | const char *propname, u16 *out_values, |
| 756 | size_t sz_min, size_t sz_max) |
| 757 | { |
| 758 | return -ENOSYS; |
| 759 | } |
| 760 | |
| 761 | static inline int of_property_read_variable_u32_array(const struct device_node *np, |
| 762 | const char *propname, |
| 763 | u32 *out_values, |
| 764 | size_t sz_min, |
| 765 | size_t sz_max) |
| 766 | { |
| 767 | return -ENOSYS; |
| 768 | } |
| 769 | |
Jamie Iles | 4cd7f7a | 2011-09-14 20:49:59 +0100 | [diff] [blame] | 770 | static inline int of_property_read_u64(const struct device_node *np, |
| 771 | const char *propname, u64 *out_value) |
| 772 | { |
| 773 | return -ENOSYS; |
| 774 | } |
| 775 | |
Arnd Bergmann | 96c623e | 2017-11-06 14:26:10 +0100 | [diff] [blame] | 776 | static inline int of_property_read_variable_u64_array(const struct device_node *np, |
| 777 | const char *propname, |
| 778 | u64 *out_values, |
| 779 | size_t sz_min, |
| 780 | size_t sz_max) |
| 781 | { |
| 782 | return -ENOSYS; |
| 783 | } |
| 784 | |
| 785 | static inline int of_property_read_string(const struct device_node *np, |
| 786 | const char *propname, |
| 787 | const char **out_string) |
| 788 | { |
| 789 | return -ENOSYS; |
| 790 | } |
| 791 | |
David Rivshin | fe99c70 | 2016-03-02 16:35:51 -0500 | [diff] [blame] | 792 | static inline int of_property_match_string(const struct device_node *np, |
Thierry Reding | bd3d550 | 2012-04-13 16:18:34 +0200 | [diff] [blame] | 793 | const char *propname, |
| 794 | const char *string) |
| 795 | { |
| 796 | return -ENOSYS; |
| 797 | } |
| 798 | |
Arnd Bergmann | 96c623e | 2017-11-06 14:26:10 +0100 | [diff] [blame] | 799 | static inline int of_property_read_string_helper(const struct device_node *np, |
| 800 | const char *propname, |
| 801 | const char **out_strs, size_t sz, int index) |
| 802 | { |
| 803 | return -ENOSYS; |
| 804 | } |
| 805 | |
Steffen Trumtrar | b8fbdc4 | 2012-11-22 12:16:43 +0100 | [diff] [blame] | 806 | 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] | 807 | const char *phandle_name, |
| 808 | int index) |
| 809 | { |
| 810 | return NULL; |
| 811 | } |
| 812 | |
Kuninori Morimoto | e93aeea | 2016-05-25 01:15:04 +0000 | [diff] [blame] | 813 | static inline int of_parse_phandle_with_args(const struct device_node *np, |
Thierry Reding | e05e507 | 2012-04-13 16:19:21 +0200 | [diff] [blame] | 814 | const char *list_name, |
| 815 | const char *cells_name, |
| 816 | int index, |
| 817 | struct of_phandle_args *out_args) |
| 818 | { |
| 819 | return -ENOSYS; |
| 820 | } |
| 821 | |
Stephen Warren | 035fd94 | 2013-08-14 15:27:10 -0600 | [diff] [blame] | 822 | static inline int of_parse_phandle_with_fixed_args(const struct device_node *np, |
| 823 | const char *list_name, int cells_count, int index, |
| 824 | struct of_phandle_args *out_args) |
| 825 | { |
| 826 | return -ENOSYS; |
| 827 | } |
| 828 | |
Grant Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 829 | static inline int of_count_phandle_with_args(struct device_node *np, |
| 830 | const char *list_name, |
| 831 | const char *cells_name) |
| 832 | { |
| 833 | return -ENOSYS; |
| 834 | } |
| 835 | |
Joerg Roedel | 74e1fbb | 2016-04-04 17:49:17 +0200 | [diff] [blame] | 836 | static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, |
| 837 | const struct device_node *np, |
| 838 | const char *list_name, |
| 839 | const char *cells_name, |
| 840 | int cell_count) |
| 841 | { |
| 842 | return -ENOSYS; |
| 843 | } |
| 844 | |
Joerg Roedel | cd209b4 | 2016-04-04 17:49:18 +0200 | [diff] [blame] | 845 | static inline int of_phandle_iterator_next(struct of_phandle_iterator *it) |
| 846 | { |
| 847 | return -ENOSYS; |
| 848 | } |
| 849 | |
Joerg Roedel | abdaa77 | 2016-04-04 17:49:21 +0200 | [diff] [blame] | 850 | static inline int of_phandle_iterator_args(struct of_phandle_iterator *it, |
| 851 | uint32_t *args, |
| 852 | int size) |
| 853 | { |
| 854 | return 0; |
| 855 | } |
| 856 | |
Nicolas Ferre | ed5f886 | 2011-10-27 11:07:28 +0200 | [diff] [blame] | 857 | static inline int of_alias_get_id(struct device_node *np, const char *stem) |
| 858 | { |
| 859 | return -ENOSYS; |
| 860 | } |
| 861 | |
Wolfram Sang | 351d224 | 2015-03-12 17:17:58 +0100 | [diff] [blame] | 862 | static inline int of_alias_get_highest_id(const char *stem) |
| 863 | { |
| 864 | return -ENOSYS; |
| 865 | } |
| 866 | |
Stephen Warren | 50e07f8 | 2011-10-25 14:01:26 +0200 | [diff] [blame] | 867 | static inline int of_machine_is_compatible(const char *compat) |
| 868 | { |
| 869 | return 0; |
| 870 | } |
| 871 | |
Grant Likely | 3482f2c | 2014-03-27 17:18:55 -0700 | [diff] [blame] | 872 | static inline bool of_console_check(const struct device_node *dn, const char *name, int index) |
Sascha Hauer | 5c19e95 | 2013-08-05 14:40:44 +0200 | [diff] [blame] | 873 | { |
Grant Likely | 3482f2c | 2014-03-27 17:18:55 -0700 | [diff] [blame] | 874 | return false; |
Sascha Hauer | 5c19e95 | 2013-08-05 14:40:44 +0200 | [diff] [blame] | 875 | } |
| 876 | |
Sebastian Andrzej Siewior | 2adfffa | 2013-06-17 16:48:13 +0200 | [diff] [blame] | 877 | static inline const __be32 *of_prop_next_u32(struct property *prop, |
| 878 | const __be32 *cur, u32 *pu) |
| 879 | { |
| 880 | return NULL; |
| 881 | } |
| 882 | |
| 883 | static inline const char *of_prop_next_string(struct property *prop, |
| 884 | const char *cur) |
| 885 | { |
| 886 | return NULL; |
| 887 | } |
| 888 | |
Pantelis Antoniou | 0384e8c | 2015-01-21 19:05:57 +0200 | [diff] [blame] | 889 | static inline int of_node_check_flag(struct device_node *n, unsigned long flag) |
| 890 | { |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | static inline int of_node_test_and_set_flag(struct device_node *n, |
| 895 | unsigned long flag) |
| 896 | { |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | static inline void of_node_set_flag(struct device_node *n, unsigned long flag) |
| 901 | { |
| 902 | } |
| 903 | |
| 904 | static inline void of_node_clear_flag(struct device_node *n, unsigned long flag) |
| 905 | { |
| 906 | } |
| 907 | |
| 908 | static inline int of_property_check_flag(struct property *p, unsigned long flag) |
| 909 | { |
| 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | static inline void of_property_set_flag(struct property *p, unsigned long flag) |
| 914 | { |
| 915 | } |
| 916 | |
| 917 | static inline void of_property_clear_flag(struct property *p, unsigned long flag) |
| 918 | { |
| 919 | } |
| 920 | |
Suzuki K Poulose | a0e71cd | 2018-01-02 11:25:27 +0000 | [diff] [blame] | 921 | static inline int of_cpu_node_to_id(struct device_node *np) |
| 922 | { |
| 923 | return -ENODEV; |
| 924 | } |
| 925 | |
Ben Dooks | 3a1e362 | 2011-08-03 10:11:42 +0100 | [diff] [blame] | 926 | #define of_match_ptr(_ptr) NULL |
Nicolas Ferre | 5762c20 | 2011-10-24 11:53:32 +0200 | [diff] [blame] | 927 | #define of_match_node(_matches, _node) NULL |
Jeremy Kerr | 9dfbf20 | 2010-02-14 07:13:43 -0700 | [diff] [blame] | 928 | #endif /* CONFIG_OF */ |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 929 | |
Adam Thomson | 613e972 | 2016-06-21 18:50:20 +0100 | [diff] [blame] | 930 | /* Default string compare functions, Allow arch asm/prom.h to override */ |
| 931 | #if !defined(of_compat_cmp) |
| 932 | #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2)) |
| 933 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) |
| 934 | #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) |
| 935 | #endif |
| 936 | |
Rob Herring | 0c3f061 | 2013-09-17 10:42:50 -0500 | [diff] [blame] | 937 | #if defined(CONFIG_OF) && defined(CONFIG_NUMA) |
| 938 | extern int of_node_to_nid(struct device_node *np); |
| 939 | #else |
Konstantin Khlebnikov | c8fff7b | 2015-04-08 19:59:20 +0300 | [diff] [blame] | 940 | static inline int of_node_to_nid(struct device_node *device) |
| 941 | { |
| 942 | return NUMA_NO_NODE; |
| 943 | } |
Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 944 | #endif |
| 945 | |
David Daney | 298535c | 2016-04-08 15:50:25 -0700 | [diff] [blame] | 946 | #ifdef CONFIG_OF_NUMA |
| 947 | extern int of_numa_init(void); |
| 948 | #else |
| 949 | static inline int of_numa_init(void) |
| 950 | { |
| 951 | return -ENOSYS; |
| 952 | } |
| 953 | #endif |
| 954 | |
Rob Herring | 662372e | 2014-02-03 08:53:44 -0600 | [diff] [blame] | 955 | static inline struct device_node *of_find_matching_node( |
| 956 | struct device_node *from, |
| 957 | const struct of_device_id *matches) |
| 958 | { |
| 959 | return of_find_matching_node_and_match(from, matches, NULL); |
| 960 | } |
| 961 | |
Jean-Christophe PLAGNIOL-VILLARD | fa4d34c | 2012-02-07 12:12:51 +0800 | [diff] [blame] | 962 | /** |
Heiko Stuebner | ad54a0c | 2014-02-12 01:00:34 +0100 | [diff] [blame] | 963 | * of_property_count_u8_elems - Count the number of u8 elements in a property |
| 964 | * |
| 965 | * @np: device node from which the property value is to be read. |
| 966 | * @propname: name of the property to be searched. |
| 967 | * |
| 968 | * Search for a property in a device node and count the number of u8 elements |
| 969 | * in it. Returns number of elements on sucess, -EINVAL if the property does |
| 970 | * not exist or its length does not match a multiple of u8 and -ENODATA if the |
| 971 | * property does not have a value. |
| 972 | */ |
| 973 | static inline int of_property_count_u8_elems(const struct device_node *np, |
| 974 | const char *propname) |
| 975 | { |
| 976 | return of_property_count_elems_of_size(np, propname, sizeof(u8)); |
| 977 | } |
| 978 | |
| 979 | /** |
| 980 | * of_property_count_u16_elems - Count the number of u16 elements in a property |
| 981 | * |
| 982 | * @np: device node from which the property value is to be read. |
| 983 | * @propname: name of the property to be searched. |
| 984 | * |
| 985 | * Search for a property in a device node and count the number of u16 elements |
| 986 | * in it. Returns number of elements on sucess, -EINVAL if the property does |
| 987 | * not exist or its length does not match a multiple of u16 and -ENODATA if the |
| 988 | * property does not have a value. |
| 989 | */ |
| 990 | static inline int of_property_count_u16_elems(const struct device_node *np, |
| 991 | const char *propname) |
| 992 | { |
| 993 | return of_property_count_elems_of_size(np, propname, sizeof(u16)); |
| 994 | } |
| 995 | |
| 996 | /** |
| 997 | * of_property_count_u32_elems - Count the number of u32 elements in a property |
| 998 | * |
| 999 | * @np: device node from which the property value is to be read. |
| 1000 | * @propname: name of the property to be searched. |
| 1001 | * |
| 1002 | * Search for a property in a device node and count the number of u32 elements |
| 1003 | * in it. Returns number of elements on sucess, -EINVAL if the property does |
| 1004 | * not exist or its length does not match a multiple of u32 and -ENODATA if the |
| 1005 | * property does not have a value. |
| 1006 | */ |
| 1007 | static inline int of_property_count_u32_elems(const struct device_node *np, |
| 1008 | const char *propname) |
| 1009 | { |
| 1010 | return of_property_count_elems_of_size(np, propname, sizeof(u32)); |
| 1011 | } |
| 1012 | |
| 1013 | /** |
| 1014 | * of_property_count_u64_elems - Count the number of u64 elements in a property |
| 1015 | * |
| 1016 | * @np: device node from which the property value is to be read. |
| 1017 | * @propname: name of the property to be searched. |
| 1018 | * |
| 1019 | * Search for a property in a device node and count the number of u64 elements |
| 1020 | * in it. Returns number of elements on sucess, -EINVAL if the property does |
| 1021 | * not exist or its length does not match a multiple of u64 and -ENODATA if the |
| 1022 | * property does not have a value. |
| 1023 | */ |
| 1024 | static inline int of_property_count_u64_elems(const struct device_node *np, |
| 1025 | const char *propname) |
| 1026 | { |
| 1027 | return of_property_count_elems_of_size(np, propname, sizeof(u64)); |
| 1028 | } |
| 1029 | |
Jean-Christophe PLAGNIOL-VILLARD | fa4d34c | 2012-02-07 12:12:51 +0800 | [diff] [blame] | 1030 | /** |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 1031 | * of_property_read_string_array() - Read an array of strings from a multiple |
| 1032 | * strings property. |
| 1033 | * @np: device node from which the property value is to be read. |
| 1034 | * @propname: name of the property to be searched. |
| 1035 | * @out_strs: output array of string pointers. |
| 1036 | * @sz: number of array elements to read. |
| 1037 | * |
| 1038 | * Search for a property in a device tree node and retrieve a list of |
| 1039 | * terminated string values (pointer to data, not a copy) in that property. |
| 1040 | * |
| 1041 | * If @out_strs is NULL, the number of strings in the property is returned. |
| 1042 | */ |
David Rivshin | fe99c70 | 2016-03-02 16:35:51 -0500 | [diff] [blame] | 1043 | static inline int of_property_read_string_array(const struct device_node *np, |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 1044 | const char *propname, const char **out_strs, |
| 1045 | size_t sz) |
| 1046 | { |
| 1047 | return of_property_read_string_helper(np, propname, out_strs, sz, 0); |
| 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * of_property_count_strings() - Find and return the number of strings from a |
| 1052 | * multiple strings property. |
| 1053 | * @np: device node from which the property value is to be read. |
| 1054 | * @propname: name of the property to be searched. |
| 1055 | * |
| 1056 | * Search for a property in a device tree node and retrieve the number of null |
| 1057 | * terminated string contain in it. Returns the number of strings on |
| 1058 | * success, -EINVAL if the property does not exist, -ENODATA if property |
| 1059 | * does not have a value, and -EILSEQ if the string is not null-terminated |
| 1060 | * within the length of the property data. |
| 1061 | */ |
David Rivshin | fe99c70 | 2016-03-02 16:35:51 -0500 | [diff] [blame] | 1062 | static inline int of_property_count_strings(const struct device_node *np, |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 1063 | const char *propname) |
| 1064 | { |
| 1065 | return of_property_read_string_helper(np, propname, NULL, 0, 0); |
| 1066 | } |
| 1067 | |
| 1068 | /** |
| 1069 | * of_property_read_string_index() - Find and read a string from a multiple |
| 1070 | * strings property. |
| 1071 | * @np: device node from which the property value is to be read. |
| 1072 | * @propname: name of the property to be searched. |
| 1073 | * @index: index of the string in the list of strings |
| 1074 | * @out_string: pointer to null terminated return string, modified only if |
| 1075 | * return value is 0. |
| 1076 | * |
| 1077 | * Search for a property in a device tree node and retrieve a null |
| 1078 | * terminated string value (pointer to data, not a copy) in the list of strings |
| 1079 | * contained in that property. |
| 1080 | * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if |
| 1081 | * property does not have a value, and -EILSEQ if the string is not |
| 1082 | * null-terminated within the length of the property data. |
| 1083 | * |
| 1084 | * The out_string pointer is modified only if a valid string can be decoded. |
| 1085 | */ |
David Rivshin | fe99c70 | 2016-03-02 16:35:51 -0500 | [diff] [blame] | 1086 | static inline int of_property_read_string_index(const struct device_node *np, |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 1087 | const char *propname, |
| 1088 | int index, const char **output) |
| 1089 | { |
| 1090 | int rc = of_property_read_string_helper(np, propname, output, 1, index); |
| 1091 | return rc < 0 ? rc : 0; |
| 1092 | } |
| 1093 | |
| 1094 | /** |
Jean-Christophe PLAGNIOL-VILLARD | fa4d34c | 2012-02-07 12:12:51 +0800 | [diff] [blame] | 1095 | * of_property_read_bool - Findfrom a property |
| 1096 | * @np: device node from which the property value is to be read. |
| 1097 | * @propname: name of the property to be searched. |
| 1098 | * |
| 1099 | * Search for a property in a device node. |
Geert Uytterhoeven | 31712c9 | 2015-05-04 19:42:19 +0200 | [diff] [blame] | 1100 | * Returns true if the property exists false otherwise. |
Jean-Christophe PLAGNIOL-VILLARD | fa4d34c | 2012-02-07 12:12:51 +0800 | [diff] [blame] | 1101 | */ |
| 1102 | static inline bool of_property_read_bool(const struct device_node *np, |
| 1103 | const char *propname) |
| 1104 | { |
| 1105 | struct property *prop = of_find_property(np, propname, NULL); |
| 1106 | |
| 1107 | return prop ? true : false; |
| 1108 | } |
| 1109 | |
Viresh Kumar | be19324 | 2012-11-20 10:15:19 +0530 | [diff] [blame] | 1110 | static inline int of_property_read_u8(const struct device_node *np, |
| 1111 | const char *propname, |
| 1112 | u8 *out_value) |
| 1113 | { |
| 1114 | return of_property_read_u8_array(np, propname, out_value, 1); |
| 1115 | } |
| 1116 | |
| 1117 | static inline int of_property_read_u16(const struct device_node *np, |
| 1118 | const char *propname, |
| 1119 | u16 *out_value) |
| 1120 | { |
| 1121 | return of_property_read_u16_array(np, propname, out_value, 1); |
| 1122 | } |
| 1123 | |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 1124 | static inline int of_property_read_u32(const struct device_node *np, |
Jamie Iles | aac285c | 2011-08-02 15:45:07 +0100 | [diff] [blame] | 1125 | const char *propname, |
Shawn Guo | b98c023 | 2011-07-08 16:27:33 +0800 | [diff] [blame] | 1126 | u32 *out_value) |
| 1127 | { |
| 1128 | return of_property_read_u32_array(np, propname, out_value, 1); |
| 1129 | } |
| 1130 | |
Sebastian Reichel | e7a00e4 | 2014-04-06 12:52:11 +0200 | [diff] [blame] | 1131 | static inline int of_property_read_s32(const struct device_node *np, |
| 1132 | const char *propname, |
| 1133 | s32 *out_value) |
| 1134 | { |
| 1135 | return of_property_read_u32(np, propname, (u32*) out_value); |
| 1136 | } |
| 1137 | |
Joerg Roedel | f623ce9 | 2016-04-04 17:49:20 +0200 | [diff] [blame] | 1138 | #define of_for_each_phandle(it, err, np, ln, cn, cc) \ |
| 1139 | for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \ |
| 1140 | err = of_phandle_iterator_next(it); \ |
| 1141 | err == 0; \ |
| 1142 | err = of_phandle_iterator_next(it)) |
| 1143 | |
Sebastian Andrzej Siewior | 2adfffa | 2013-06-17 16:48:13 +0200 | [diff] [blame] | 1144 | #define of_property_for_each_u32(np, propname, prop, p, u) \ |
| 1145 | for (prop = of_find_property(np, propname, NULL), \ |
| 1146 | p = of_prop_next_u32(prop, NULL, &u); \ |
| 1147 | p; \ |
| 1148 | p = of_prop_next_u32(prop, p, &u)) |
| 1149 | |
| 1150 | #define of_property_for_each_string(np, propname, prop, s) \ |
| 1151 | for (prop = of_find_property(np, propname, NULL), \ |
| 1152 | s = of_prop_next_string(prop, NULL); \ |
| 1153 | s; \ |
| 1154 | s = of_prop_next_string(prop, s)) |
| 1155 | |
Rob Herring | 662372e | 2014-02-03 08:53:44 -0600 | [diff] [blame] | 1156 | #define for_each_node_by_name(dn, name) \ |
| 1157 | for (dn = of_find_node_by_name(NULL, name); dn; \ |
| 1158 | dn = of_find_node_by_name(dn, name)) |
| 1159 | #define for_each_node_by_type(dn, type) \ |
| 1160 | for (dn = of_find_node_by_type(NULL, type); dn; \ |
| 1161 | dn = of_find_node_by_type(dn, type)) |
| 1162 | #define for_each_compatible_node(dn, type, compatible) \ |
| 1163 | for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ |
| 1164 | dn = of_find_compatible_node(dn, type, compatible)) |
| 1165 | #define for_each_matching_node(dn, matches) \ |
| 1166 | for (dn = of_find_matching_node(NULL, matches); dn; \ |
| 1167 | dn = of_find_matching_node(dn, matches)) |
| 1168 | #define for_each_matching_node_and_match(dn, matches, match) \ |
| 1169 | for (dn = of_find_matching_node_and_match(NULL, matches, match); \ |
| 1170 | dn; dn = of_find_matching_node_and_match(dn, matches, match)) |
| 1171 | |
| 1172 | #define for_each_child_of_node(parent, child) \ |
| 1173 | for (child = of_get_next_child(parent, NULL); child != NULL; \ |
| 1174 | child = of_get_next_child(parent, child)) |
| 1175 | #define for_each_available_child_of_node(parent, child) \ |
| 1176 | for (child = of_get_next_available_child(parent, NULL); child != NULL; \ |
| 1177 | child = of_get_next_available_child(parent, child)) |
| 1178 | |
| 1179 | #define for_each_node_with_property(dn, prop_name) \ |
| 1180 | for (dn = of_find_node_with_property(NULL, prop_name); dn; \ |
| 1181 | dn = of_find_node_with_property(dn, prop_name)) |
| 1182 | |
| 1183 | static inline int of_get_child_count(const struct device_node *np) |
| 1184 | { |
| 1185 | struct device_node *child; |
| 1186 | int num = 0; |
| 1187 | |
| 1188 | for_each_child_of_node(np, child) |
| 1189 | num++; |
| 1190 | |
| 1191 | return num; |
| 1192 | } |
| 1193 | |
| 1194 | static inline int of_get_available_child_count(const struct device_node *np) |
| 1195 | { |
| 1196 | struct device_node *child; |
| 1197 | int num = 0; |
| 1198 | |
| 1199 | for_each_available_child_of_node(np, child) |
| 1200 | num++; |
| 1201 | |
| 1202 | return num; |
| 1203 | } |
| 1204 | |
Masahiro Yamada | 71f50c6 | 2016-01-22 01:33:51 +0900 | [diff] [blame] | 1205 | #if defined(CONFIG_OF) && !defined(MODULE) |
Rob Herring | 54196cc | 2014-05-08 16:09:24 -0500 | [diff] [blame] | 1206 | #define _OF_DECLARE(table, name, compat, fn, fn_type) \ |
| 1207 | static const struct of_device_id __of_table_##name \ |
| 1208 | __used __section(__##table##_of_table) \ |
| 1209 | = { .compatible = compat, \ |
| 1210 | .data = (fn == (fn_type)NULL) ? fn : fn } |
| 1211 | #else |
Thierry Reding | 5f56358 | 2014-10-02 16:01:10 +0200 | [diff] [blame] | 1212 | #define _OF_DECLARE(table, name, compat, fn, fn_type) \ |
Rob Herring | 54196cc | 2014-05-08 16:09:24 -0500 | [diff] [blame] | 1213 | static const struct of_device_id __of_table_##name \ |
| 1214 | __attribute__((unused)) \ |
| 1215 | = { .compatible = compat, \ |
| 1216 | .data = (fn == (fn_type)NULL) ? fn : fn } |
| 1217 | #endif |
| 1218 | |
| 1219 | typedef int (*of_init_fn_2)(struct device_node *, struct device_node *); |
Daniel Lezcano | c35d929 | 2016-04-18 23:06:48 +0200 | [diff] [blame] | 1220 | typedef int (*of_init_fn_1_ret)(struct device_node *); |
Rob Herring | 54196cc | 2014-05-08 16:09:24 -0500 | [diff] [blame] | 1221 | typedef void (*of_init_fn_1)(struct device_node *); |
| 1222 | |
| 1223 | #define OF_DECLARE_1(table, name, compat, fn) \ |
| 1224 | _OF_DECLARE(table, name, compat, fn, of_init_fn_1) |
Daniel Lezcano | c35d929 | 2016-04-18 23:06:48 +0200 | [diff] [blame] | 1225 | #define OF_DECLARE_1_RET(table, name, compat, fn) \ |
| 1226 | _OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret) |
Rob Herring | 54196cc | 2014-05-08 16:09:24 -0500 | [diff] [blame] | 1227 | #define OF_DECLARE_2(table, name, compat, fn) \ |
| 1228 | _OF_DECLARE(table, name, compat, fn, of_init_fn_2) |
| 1229 | |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 1230 | /** |
| 1231 | * struct of_changeset_entry - Holds a changeset entry |
| 1232 | * |
| 1233 | * @node: list_head for the log list |
| 1234 | * @action: notifier action |
| 1235 | * @np: pointer to the device node affected |
| 1236 | * @prop: pointer to the property affected |
| 1237 | * @old_prop: hold a pointer to the original property |
| 1238 | * |
| 1239 | * Every modification of the device tree during a changeset |
| 1240 | * is held in a list of of_changeset_entry structures. |
| 1241 | * That way we can recover from a partial application, or we can |
| 1242 | * revert the changeset |
| 1243 | */ |
| 1244 | struct of_changeset_entry { |
| 1245 | struct list_head node; |
| 1246 | unsigned long action; |
| 1247 | struct device_node *np; |
| 1248 | struct property *prop; |
| 1249 | struct property *old_prop; |
| 1250 | }; |
| 1251 | |
| 1252 | /** |
| 1253 | * struct of_changeset - changeset tracker structure |
| 1254 | * |
| 1255 | * @entries: list_head for the changeset entries |
| 1256 | * |
| 1257 | * changesets are a convenient way to apply bulk changes to the |
| 1258 | * live tree. In case of an error, changes are rolled-back. |
| 1259 | * changesets live on after initial application, and if not |
| 1260 | * destroyed after use, they can be reverted in one single call. |
| 1261 | */ |
| 1262 | struct of_changeset { |
| 1263 | struct list_head entries; |
| 1264 | }; |
| 1265 | |
Pantelis Antoniou | b53a234 | 2014-10-28 22:33:53 +0200 | [diff] [blame] | 1266 | enum of_reconfig_change { |
| 1267 | OF_RECONFIG_NO_CHANGE = 0, |
| 1268 | OF_RECONFIG_CHANGE_ADD, |
| 1269 | OF_RECONFIG_CHANGE_REMOVE, |
| 1270 | }; |
| 1271 | |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 1272 | #ifdef CONFIG_OF_DYNAMIC |
Grant Likely | f6892d1 | 2014-11-21 15:14:58 +0000 | [diff] [blame] | 1273 | extern int of_reconfig_notifier_register(struct notifier_block *); |
| 1274 | extern int of_reconfig_notifier_unregister(struct notifier_block *); |
Grant Likely | f5242e5 | 2014-11-24 17:58:01 +0000 | [diff] [blame] | 1275 | extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd); |
| 1276 | extern int of_reconfig_get_state_change(unsigned long action, |
| 1277 | struct of_reconfig_data *arg); |
Grant Likely | f6892d1 | 2014-11-21 15:14:58 +0000 | [diff] [blame] | 1278 | |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 1279 | extern void of_changeset_init(struct of_changeset *ocs); |
| 1280 | extern void of_changeset_destroy(struct of_changeset *ocs); |
| 1281 | extern int of_changeset_apply(struct of_changeset *ocs); |
| 1282 | extern int of_changeset_revert(struct of_changeset *ocs); |
| 1283 | extern int of_changeset_action(struct of_changeset *ocs, |
| 1284 | unsigned long action, struct device_node *np, |
| 1285 | struct property *prop); |
| 1286 | |
| 1287 | static inline int of_changeset_attach_node(struct of_changeset *ocs, |
| 1288 | struct device_node *np) |
| 1289 | { |
| 1290 | return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL); |
| 1291 | } |
| 1292 | |
| 1293 | static inline int of_changeset_detach_node(struct of_changeset *ocs, |
| 1294 | struct device_node *np) |
| 1295 | { |
| 1296 | return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL); |
| 1297 | } |
| 1298 | |
| 1299 | static inline int of_changeset_add_property(struct of_changeset *ocs, |
| 1300 | struct device_node *np, struct property *prop) |
| 1301 | { |
| 1302 | return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop); |
| 1303 | } |
| 1304 | |
| 1305 | static inline int of_changeset_remove_property(struct of_changeset *ocs, |
| 1306 | struct device_node *np, struct property *prop) |
| 1307 | { |
| 1308 | return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop); |
| 1309 | } |
| 1310 | |
| 1311 | static inline int of_changeset_update_property(struct of_changeset *ocs, |
| 1312 | struct device_node *np, struct property *prop) |
| 1313 | { |
| 1314 | return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop); |
| 1315 | } |
Grant Likely | f6892d1 | 2014-11-21 15:14:58 +0000 | [diff] [blame] | 1316 | #else /* CONFIG_OF_DYNAMIC */ |
| 1317 | static inline int of_reconfig_notifier_register(struct notifier_block *nb) |
| 1318 | { |
| 1319 | return -EINVAL; |
| 1320 | } |
| 1321 | static inline int of_reconfig_notifier_unregister(struct notifier_block *nb) |
| 1322 | { |
| 1323 | return -EINVAL; |
| 1324 | } |
Grant Likely | f5242e5 | 2014-11-24 17:58:01 +0000 | [diff] [blame] | 1325 | static inline int of_reconfig_notify(unsigned long action, |
| 1326 | struct of_reconfig_data *arg) |
Grant Likely | f6892d1 | 2014-11-21 15:14:58 +0000 | [diff] [blame] | 1327 | { |
| 1328 | return -EINVAL; |
| 1329 | } |
Grant Likely | f5242e5 | 2014-11-24 17:58:01 +0000 | [diff] [blame] | 1330 | static inline int of_reconfig_get_state_change(unsigned long action, |
| 1331 | struct of_reconfig_data *arg) |
Grant Likely | f6892d1 | 2014-11-21 15:14:58 +0000 | [diff] [blame] | 1332 | { |
| 1333 | return -EINVAL; |
| 1334 | } |
| 1335 | #endif /* CONFIG_OF_DYNAMIC */ |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 1336 | |
Romain Perier | a4b4e04 | 2014-10-14 06:31:09 +0000 | [diff] [blame] | 1337 | /** |
Romain Perier | 8f73110 | 2014-11-25 12:28:25 +0000 | [diff] [blame] | 1338 | * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node |
Romain Perier | a4b4e04 | 2014-10-14 06:31:09 +0000 | [diff] [blame] | 1339 | * @np: Pointer to the given device_node |
| 1340 | * |
| 1341 | * return true if present false otherwise |
| 1342 | */ |
Romain Perier | 8f73110 | 2014-11-25 12:28:25 +0000 | [diff] [blame] | 1343 | static inline bool of_device_is_system_power_controller(const struct device_node *np) |
Romain Perier | a4b4e04 | 2014-10-14 06:31:09 +0000 | [diff] [blame] | 1344 | { |
Romain Perier | 8f73110 | 2014-11-25 12:28:25 +0000 | [diff] [blame] | 1345 | return of_property_read_bool(np, "system-power-controller"); |
Romain Perier | a4b4e04 | 2014-10-14 06:31:09 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Linus Torvalds | 7ef58b3 | 2014-12-11 13:06:58 -0800 | [diff] [blame] | 1348 | /** |
Pantelis Antoniou | 7518b589 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 1349 | * Overlay support |
| 1350 | */ |
| 1351 | |
Alan Tull | 39a842e | 2016-11-01 14:14:22 -0500 | [diff] [blame] | 1352 | enum of_overlay_notify_action { |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1353 | OF_OVERLAY_PRE_APPLY = 0, |
Alan Tull | 39a842e | 2016-11-01 14:14:22 -0500 | [diff] [blame] | 1354 | OF_OVERLAY_POST_APPLY, |
| 1355 | OF_OVERLAY_PRE_REMOVE, |
| 1356 | OF_OVERLAY_POST_REMOVE, |
| 1357 | }; |
| 1358 | |
| 1359 | struct of_overlay_notify_data { |
| 1360 | struct device_node *overlay; |
| 1361 | struct device_node *target; |
| 1362 | }; |
| 1363 | |
Pantelis Antoniou | 7518b589 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 1364 | #ifdef CONFIG_OF_OVERLAY |
| 1365 | |
| 1366 | /* ID based overlays; the API for external users */ |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1367 | int of_overlay_apply(struct device_node *tree, int *ovcs_id); |
| 1368 | int of_overlay_remove(int *ovcs_id); |
Frank Rowand | 0290c4c | 2017-10-17 16:36:23 -0700 | [diff] [blame] | 1369 | int of_overlay_remove_all(void); |
Pantelis Antoniou | 7518b589 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 1370 | |
Alan Tull | 39a842e | 2016-11-01 14:14:22 -0500 | [diff] [blame] | 1371 | int of_overlay_notifier_register(struct notifier_block *nb); |
| 1372 | int of_overlay_notifier_unregister(struct notifier_block *nb); |
| 1373 | |
Pantelis Antoniou | 7518b589 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 1374 | #else |
| 1375 | |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1376 | static inline int of_overlay_apply(struct device_node *tree, int *ovcs_id) |
Pantelis Antoniou | 7518b589 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 1377 | { |
| 1378 | return -ENOTSUPP; |
| 1379 | } |
| 1380 | |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1381 | static inline int of_overlay_remove(int *ovcs_id) |
Pantelis Antoniou | 7518b589 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 1382 | { |
| 1383 | return -ENOTSUPP; |
| 1384 | } |
| 1385 | |
Frank Rowand | 0290c4c | 2017-10-17 16:36:23 -0700 | [diff] [blame] | 1386 | static inline int of_overlay_remove_all(void) |
Pantelis Antoniou | 7518b589 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 1387 | { |
| 1388 | return -ENOTSUPP; |
| 1389 | } |
| 1390 | |
Alan Tull | 39a842e | 2016-11-01 14:14:22 -0500 | [diff] [blame] | 1391 | static inline int of_overlay_notifier_register(struct notifier_block *nb) |
| 1392 | { |
| 1393 | return 0; |
| 1394 | } |
| 1395 | |
| 1396 | static inline int of_overlay_notifier_unregister(struct notifier_block *nb) |
| 1397 | { |
| 1398 | return 0; |
| 1399 | } |
| 1400 | |
Pantelis Antoniou | 7518b589 | 2014-10-28 22:35:58 +0200 | [diff] [blame] | 1401 | #endif |
| 1402 | |
Stephen Rothwell | 76c1ce7 | 2007-05-01 16:19:07 +1000 | [diff] [blame] | 1403 | #endif /* _LINUX_OF_H */ |