| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ | 
|---|
| 2 | /* | 
|---|
| 3 | * property.h - Unified device property interface. | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright (C) 2014, Intel Corporation | 
|---|
| 6 | * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 
|---|
| 7 | *          Mika Westerberg <mika.westerberg@linux.intel.com> | 
|---|
| 8 | */ | 
|---|
| 9 |  | 
|---|
| 10 | #ifndef _LINUX_PROPERTY_H_ | 
|---|
| 11 | #define _LINUX_PROPERTY_H_ | 
|---|
| 12 |  | 
|---|
| 13 | #include <linux/args.h> | 
|---|
| 14 | #include <linux/array_size.h> | 
|---|
| 15 | #include <linux/bits.h> | 
|---|
| 16 | #include <linux/cleanup.h> | 
|---|
| 17 | #include <linux/fwnode.h> | 
|---|
| 18 | #include <linux/stddef.h> | 
|---|
| 19 | #include <linux/types.h> | 
|---|
| 20 | #include <linux/util_macros.h> | 
|---|
| 21 |  | 
|---|
| 22 | struct device; | 
|---|
| 23 |  | 
|---|
| 24 | enum dev_prop_type { | 
|---|
| 25 | DEV_PROP_U8, | 
|---|
| 26 | DEV_PROP_U16, | 
|---|
| 27 | DEV_PROP_U32, | 
|---|
| 28 | DEV_PROP_U64, | 
|---|
| 29 | DEV_PROP_STRING, | 
|---|
| 30 | DEV_PROP_REF, | 
|---|
| 31 | }; | 
|---|
| 32 |  | 
|---|
| 33 | const struct fwnode_handle *__dev_fwnode_const(const struct device *dev); | 
|---|
| 34 | struct fwnode_handle *__dev_fwnode(struct device *dev); | 
|---|
| 35 | #define dev_fwnode(dev)							\ | 
|---|
| 36 | _Generic((dev),							\ | 
|---|
| 37 | const struct device *: __dev_fwnode_const,	\ | 
|---|
| 38 | struct device *: __dev_fwnode)(dev) | 
|---|
| 39 |  | 
|---|
| 40 | bool device_property_present(const struct device *dev, const char *propname); | 
|---|
| 41 | bool device_property_read_bool(const struct device *dev, const char *propname); | 
|---|
| 42 | int device_property_read_u8_array(const struct device *dev, const char *propname, | 
|---|
| 43 | u8 *val, size_t nval); | 
|---|
| 44 | int device_property_read_u16_array(const struct device *dev, const char *propname, | 
|---|
| 45 | u16 *val, size_t nval); | 
|---|
| 46 | int device_property_read_u32_array(const struct device *dev, const char *propname, | 
|---|
| 47 | u32 *val, size_t nval); | 
|---|
| 48 | int device_property_read_u64_array(const struct device *dev, const char *propname, | 
|---|
| 49 | u64 *val, size_t nval); | 
|---|
| 50 | int device_property_read_string_array(const struct device *dev, const char *propname, | 
|---|
| 51 | const char **val, size_t nval); | 
|---|
| 52 | int device_property_read_string(const struct device *dev, const char *propname, | 
|---|
| 53 | const char **val); | 
|---|
| 54 | int device_property_match_string(const struct device *dev, | 
|---|
| 55 | const char *propname, const char *string); | 
|---|
| 56 |  | 
|---|
| 57 | bool fwnode_property_present(const struct fwnode_handle *fwnode, | 
|---|
| 58 | const char *propname); | 
|---|
| 59 | bool fwnode_property_read_bool(const struct fwnode_handle *fwnode, | 
|---|
| 60 | const char *propname); | 
|---|
| 61 | int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode, | 
|---|
| 62 | const char *propname, u8 *val, | 
|---|
| 63 | size_t nval); | 
|---|
| 64 | int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode, | 
|---|
| 65 | const char *propname, u16 *val, | 
|---|
| 66 | size_t nval); | 
|---|
| 67 | int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode, | 
|---|
| 68 | const char *propname, u32 *val, | 
|---|
| 69 | size_t nval); | 
|---|
| 70 | int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode, | 
|---|
| 71 | const char *propname, u64 *val, | 
|---|
| 72 | size_t nval); | 
|---|
| 73 | int fwnode_property_read_string_array(const struct fwnode_handle *fwnode, | 
|---|
| 74 | const char *propname, const char **val, | 
|---|
| 75 | size_t nval); | 
|---|
| 76 | int fwnode_property_read_string(const struct fwnode_handle *fwnode, | 
|---|
| 77 | const char *propname, const char **val); | 
|---|
| 78 | int fwnode_property_match_string(const struct fwnode_handle *fwnode, | 
|---|
| 79 | const char *propname, const char *string); | 
|---|
| 80 |  | 
|---|
| 81 | bool fwnode_device_is_available(const struct fwnode_handle *fwnode); | 
|---|
| 82 |  | 
|---|
| 83 | static inline bool fwnode_device_is_big_endian(const struct fwnode_handle *fwnode) | 
|---|
| 84 | { | 
|---|
| 85 | if (fwnode_property_present(fwnode, propname: "big-endian")) | 
|---|
| 86 | return true; | 
|---|
| 87 | if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) && | 
|---|
| 88 | fwnode_property_present(fwnode, propname: "native-endian")) | 
|---|
| 89 | return true; | 
|---|
| 90 | return false; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | static inline | 
|---|
| 94 | bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat) | 
|---|
| 95 | { | 
|---|
| 96 | return fwnode_property_match_string(fwnode, propname: "compatible", string: compat) >= 0; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | /** | 
|---|
| 100 | * device_is_big_endian - check if a device has BE registers | 
|---|
| 101 | * @dev: Pointer to the struct device | 
|---|
| 102 | * | 
|---|
| 103 | * Returns: true if the device has a "big-endian" property, or if the kernel | 
|---|
| 104 | * was compiled for BE *and* the device has a "native-endian" property. | 
|---|
| 105 | * Returns false otherwise. | 
|---|
| 106 | * | 
|---|
| 107 | * Callers would nominally use ioread32be/iowrite32be if | 
|---|
| 108 | * device_is_big_endian() == true, or readl/writel otherwise. | 
|---|
| 109 | */ | 
|---|
| 110 | static inline bool device_is_big_endian(const struct device *dev) | 
|---|
| 111 | { | 
|---|
| 112 | return fwnode_device_is_big_endian(dev_fwnode(dev)); | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | /** | 
|---|
| 116 | * device_is_compatible - match 'compatible' property of the device with a given string | 
|---|
| 117 | * @dev: Pointer to the struct device | 
|---|
| 118 | * @compat: The string to match 'compatible' property with | 
|---|
| 119 | * | 
|---|
| 120 | * Returns: true if matches, otherwise false. | 
|---|
| 121 | */ | 
|---|
| 122 | static inline bool device_is_compatible(const struct device *dev, const char *compat) | 
|---|
| 123 | { | 
|---|
| 124 | return fwnode_device_is_compatible(dev_fwnode(dev), compat); | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 | int fwnode_property_match_property_string(const struct fwnode_handle *fwnode, | 
|---|
| 128 | const char *propname, | 
|---|
| 129 | const char * const *array, size_t n); | 
|---|
| 130 |  | 
|---|
| 131 | static inline | 
|---|
| 132 | int device_property_match_property_string(const struct device *dev, | 
|---|
| 133 | const char *propname, | 
|---|
| 134 | const char * const *array, size_t n) | 
|---|
| 135 | { | 
|---|
| 136 | return fwnode_property_match_property_string(dev_fwnode(dev), propname, array, n); | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, | 
|---|
| 140 | const char *prop, const char *nargs_prop, | 
|---|
| 141 | unsigned int nargs, unsigned int index, | 
|---|
| 142 | struct fwnode_reference_args *args); | 
|---|
| 143 |  | 
|---|
| 144 | struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode, | 
|---|
| 145 | const char *name, | 
|---|
| 146 | unsigned int index); | 
|---|
| 147 |  | 
|---|
| 148 | const char *fwnode_get_name(const struct fwnode_handle *fwnode); | 
|---|
| 149 | const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode); | 
|---|
| 150 | bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name); | 
|---|
| 151 |  | 
|---|
| 152 | struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode); | 
|---|
| 153 | struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode); | 
|---|
| 154 |  | 
|---|
| 155 | #define fwnode_for_each_parent_node(fwnode, parent)		\ | 
|---|
| 156 | for (parent = fwnode_get_parent(fwnode); parent;	\ | 
|---|
| 157 | parent = fwnode_get_next_parent(parent)) | 
|---|
| 158 |  | 
|---|
| 159 | unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); | 
|---|
| 160 | struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, | 
|---|
| 161 | unsigned int depth); | 
|---|
| 162 | struct fwnode_handle *fwnode_get_next_child_node( | 
|---|
| 163 | const struct fwnode_handle *fwnode, struct fwnode_handle *child); | 
|---|
| 164 | struct fwnode_handle *fwnode_get_next_available_child_node( | 
|---|
| 165 | const struct fwnode_handle *fwnode, struct fwnode_handle *child); | 
|---|
| 166 |  | 
|---|
| 167 | #define fwnode_for_each_child_node(fwnode, child)			\ | 
|---|
| 168 | for (child = fwnode_get_next_child_node(fwnode, NULL); child;	\ | 
|---|
| 169 | child = fwnode_get_next_child_node(fwnode, child)) | 
|---|
| 170 |  | 
|---|
| 171 | #define fwnode_for_each_named_child_node(fwnode, child, name)		\ | 
|---|
| 172 | fwnode_for_each_child_node(fwnode, child)			\ | 
|---|
| 173 | for_each_if(fwnode_name_eq(child, name)) | 
|---|
| 174 |  | 
|---|
| 175 | #define fwnode_for_each_available_child_node(fwnode, child)		       \ | 
|---|
| 176 | for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\ | 
|---|
| 177 | child = fwnode_get_next_available_child_node(fwnode, child)) | 
|---|
| 178 |  | 
|---|
| 179 | #define fwnode_for_each_child_node_scoped(fwnode, child)		\ | 
|---|
| 180 | for (struct fwnode_handle *child __free(fwnode_handle) =	\ | 
|---|
| 181 | fwnode_get_next_child_node(fwnode, NULL);		\ | 
|---|
| 182 | child; child = fwnode_get_next_child_node(fwnode, child)) | 
|---|
| 183 |  | 
|---|
| 184 | #define fwnode_for_each_available_child_node_scoped(fwnode, child)	\ | 
|---|
| 185 | for (struct fwnode_handle *child __free(fwnode_handle) =	\ | 
|---|
| 186 | fwnode_get_next_available_child_node(fwnode, NULL);	\ | 
|---|
| 187 | child; child = fwnode_get_next_available_child_node(fwnode, child)) | 
|---|
| 188 |  | 
|---|
| 189 | struct fwnode_handle *device_get_next_child_node(const struct device *dev, | 
|---|
| 190 | struct fwnode_handle *child); | 
|---|
| 191 |  | 
|---|
| 192 | #define device_for_each_child_node(dev, child)				\ | 
|---|
| 193 | for (child = device_get_next_child_node(dev, NULL); child;	\ | 
|---|
| 194 | child = device_get_next_child_node(dev, child)) | 
|---|
| 195 |  | 
|---|
| 196 | #define device_for_each_named_child_node(dev, child, name)		\ | 
|---|
| 197 | device_for_each_child_node(dev, child)				\ | 
|---|
| 198 | for_each_if(fwnode_name_eq(child, name)) | 
|---|
| 199 |  | 
|---|
| 200 | #define device_for_each_child_node_scoped(dev, child)			\ | 
|---|
| 201 | for (struct fwnode_handle *child __free(fwnode_handle) =	\ | 
|---|
| 202 | device_get_next_child_node(dev, NULL);			\ | 
|---|
| 203 | child; child = device_get_next_child_node(dev, child)) | 
|---|
| 204 |  | 
|---|
| 205 | #define device_for_each_named_child_node_scoped(dev, child, name)	\ | 
|---|
| 206 | device_for_each_child_node_scoped(dev, child)			\ | 
|---|
| 207 | for_each_if(fwnode_name_eq(child, name)) | 
|---|
| 208 |  | 
|---|
| 209 | struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode, | 
|---|
| 210 | const char *childname); | 
|---|
| 211 | struct fwnode_handle *device_get_named_child_node(const struct device *dev, | 
|---|
| 212 | const char *childname); | 
|---|
| 213 |  | 
|---|
| 214 | struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode); | 
|---|
| 215 |  | 
|---|
| 216 | /** | 
|---|
| 217 | * fwnode_handle_put - Drop reference to a device node | 
|---|
| 218 | * @fwnode: Pointer to the device node to drop the reference to. | 
|---|
| 219 | * | 
|---|
| 220 | * This has to be used when terminating device_for_each_child_node() iteration | 
|---|
| 221 | * with break or return to prevent stale device node references from being left | 
|---|
| 222 | * behind. | 
|---|
| 223 | */ | 
|---|
| 224 | static inline void fwnode_handle_put(struct fwnode_handle *fwnode) | 
|---|
| 225 | { | 
|---|
| 226 | fwnode_call_void_op(fwnode, put); | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | DEFINE_FREE(fwnode_handle, struct fwnode_handle *, fwnode_handle_put(_T)) | 
|---|
| 230 |  | 
|---|
| 231 | int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index); | 
|---|
| 232 | int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name); | 
|---|
| 233 |  | 
|---|
| 234 | unsigned int fwnode_get_child_node_count(const struct fwnode_handle *fwnode); | 
|---|
| 235 |  | 
|---|
| 236 | static inline unsigned int device_get_child_node_count(const struct device *dev) | 
|---|
| 237 | { | 
|---|
| 238 | return fwnode_get_child_node_count(dev_fwnode(dev)); | 
|---|
| 239 | } | 
|---|
| 240 |  | 
|---|
| 241 | unsigned int fwnode_get_named_child_node_count(const struct fwnode_handle *fwnode, | 
|---|
| 242 | const char *name); | 
|---|
| 243 | static inline unsigned int device_get_named_child_node_count(const struct device *dev, | 
|---|
| 244 | const char *name) | 
|---|
| 245 | { | 
|---|
| 246 | return fwnode_get_named_child_node_count(dev_fwnode(dev), name); | 
|---|
| 247 | } | 
|---|
| 248 |  | 
|---|
| 249 | static inline int device_property_read_u8(const struct device *dev, | 
|---|
| 250 | const char *propname, u8 *val) | 
|---|
| 251 | { | 
|---|
| 252 | return device_property_read_u8_array(dev, propname, val, nval: 1); | 
|---|
| 253 | } | 
|---|
| 254 |  | 
|---|
| 255 | static inline int device_property_read_u16(const struct device *dev, | 
|---|
| 256 | const char *propname, u16 *val) | 
|---|
| 257 | { | 
|---|
| 258 | return device_property_read_u16_array(dev, propname, val, nval: 1); | 
|---|
| 259 | } | 
|---|
| 260 |  | 
|---|
| 261 | static inline int device_property_read_u32(const struct device *dev, | 
|---|
| 262 | const char *propname, u32 *val) | 
|---|
| 263 | { | 
|---|
| 264 | return device_property_read_u32_array(dev, propname, val, nval: 1); | 
|---|
| 265 | } | 
|---|
| 266 |  | 
|---|
| 267 | static inline int device_property_read_u64(const struct device *dev, | 
|---|
| 268 | const char *propname, u64 *val) | 
|---|
| 269 | { | 
|---|
| 270 | return device_property_read_u64_array(dev, propname, val, nval: 1); | 
|---|
| 271 | } | 
|---|
| 272 |  | 
|---|
| 273 | static inline int device_property_count_u8(const struct device *dev, const char *propname) | 
|---|
| 274 | { | 
|---|
| 275 | return device_property_read_u8_array(dev, propname, NULL, nval: 0); | 
|---|
| 276 | } | 
|---|
| 277 |  | 
|---|
| 278 | static inline int device_property_count_u16(const struct device *dev, const char *propname) | 
|---|
| 279 | { | 
|---|
| 280 | return device_property_read_u16_array(dev, propname, NULL, nval: 0); | 
|---|
| 281 | } | 
|---|
| 282 |  | 
|---|
| 283 | static inline int device_property_count_u32(const struct device *dev, const char *propname) | 
|---|
| 284 | { | 
|---|
| 285 | return device_property_read_u32_array(dev, propname, NULL, nval: 0); | 
|---|
| 286 | } | 
|---|
| 287 |  | 
|---|
| 288 | static inline int device_property_count_u64(const struct device *dev, const char *propname) | 
|---|
| 289 | { | 
|---|
| 290 | return device_property_read_u64_array(dev, propname, NULL, nval: 0); | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 | static inline int device_property_string_array_count(const struct device *dev, | 
|---|
| 294 | const char *propname) | 
|---|
| 295 | { | 
|---|
| 296 | return device_property_read_string_array(dev, propname, NULL, nval: 0); | 
|---|
| 297 | } | 
|---|
| 298 |  | 
|---|
| 299 | static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode, | 
|---|
| 300 | const char *propname, u8 *val) | 
|---|
| 301 | { | 
|---|
| 302 | return fwnode_property_read_u8_array(fwnode, propname, val, nval: 1); | 
|---|
| 303 | } | 
|---|
| 304 |  | 
|---|
| 305 | static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode, | 
|---|
| 306 | const char *propname, u16 *val) | 
|---|
| 307 | { | 
|---|
| 308 | return fwnode_property_read_u16_array(fwnode, propname, val, nval: 1); | 
|---|
| 309 | } | 
|---|
| 310 |  | 
|---|
| 311 | static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode, | 
|---|
| 312 | const char *propname, u32 *val) | 
|---|
| 313 | { | 
|---|
| 314 | return fwnode_property_read_u32_array(fwnode, propname, val, nval: 1); | 
|---|
| 315 | } | 
|---|
| 316 |  | 
|---|
| 317 | static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode, | 
|---|
| 318 | const char *propname, u64 *val) | 
|---|
| 319 | { | 
|---|
| 320 | return fwnode_property_read_u64_array(fwnode, propname, val, nval: 1); | 
|---|
| 321 | } | 
|---|
| 322 |  | 
|---|
| 323 | static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode, | 
|---|
| 324 | const char *propname) | 
|---|
| 325 | { | 
|---|
| 326 | return fwnode_property_read_u8_array(fwnode, propname, NULL, nval: 0); | 
|---|
| 327 | } | 
|---|
| 328 |  | 
|---|
| 329 | static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode, | 
|---|
| 330 | const char *propname) | 
|---|
| 331 | { | 
|---|
| 332 | return fwnode_property_read_u16_array(fwnode, propname, NULL, nval: 0); | 
|---|
| 333 | } | 
|---|
| 334 |  | 
|---|
| 335 | static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode, | 
|---|
| 336 | const char *propname) | 
|---|
| 337 | { | 
|---|
| 338 | return fwnode_property_read_u32_array(fwnode, propname, NULL, nval: 0); | 
|---|
| 339 | } | 
|---|
| 340 |  | 
|---|
| 341 | static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, | 
|---|
| 342 | const char *propname) | 
|---|
| 343 | { | 
|---|
| 344 | return fwnode_property_read_u64_array(fwnode, propname, NULL, nval: 0); | 
|---|
| 345 | } | 
|---|
| 346 |  | 
|---|
| 347 | static inline int | 
|---|
| 348 | fwnode_property_string_array_count(const struct fwnode_handle *fwnode, | 
|---|
| 349 | const char *propname) | 
|---|
| 350 | { | 
|---|
| 351 | return fwnode_property_read_string_array(fwnode, propname, NULL, nval: 0); | 
|---|
| 352 | } | 
|---|
| 353 |  | 
|---|
| 354 | struct software_node; | 
|---|
| 355 |  | 
|---|
| 356 | /** | 
|---|
| 357 | * struct software_node_ref_args - Reference property with additional arguments | 
|---|
| 358 | * @node: Reference to a software node | 
|---|
| 359 | * @nargs: Number of elements in @args array | 
|---|
| 360 | * @args: Integer arguments | 
|---|
| 361 | */ | 
|---|
| 362 | struct software_node_ref_args { | 
|---|
| 363 | const struct software_node *node; | 
|---|
| 364 | unsigned int nargs; | 
|---|
| 365 | u64 args[NR_FWNODE_REFERENCE_ARGS]; | 
|---|
| 366 | }; | 
|---|
| 367 |  | 
|---|
| 368 | #define SOFTWARE_NODE_REFERENCE(_ref_, ...)			\ | 
|---|
| 369 | (const struct software_node_ref_args) {				\ | 
|---|
| 370 | .node = _ref_,						\ | 
|---|
| 371 | .nargs = COUNT_ARGS(__VA_ARGS__),			\ | 
|---|
| 372 | .args = { __VA_ARGS__ },				\ | 
|---|
| 373 | } | 
|---|
| 374 |  | 
|---|
| 375 | /** | 
|---|
| 376 | * struct property_entry - "Built-in" device property representation. | 
|---|
| 377 | * @name: Name of the property. | 
|---|
| 378 | * @length: Length of data making up the value. | 
|---|
| 379 | * @is_inline: True when the property value is stored inline. | 
|---|
| 380 | * @type: Type of the data in unions. | 
|---|
| 381 | * @pointer: Pointer to the property when it is not stored inline. | 
|---|
| 382 | * @value: Value of the property when it is stored inline. | 
|---|
| 383 | */ | 
|---|
| 384 | struct property_entry { | 
|---|
| 385 | const char *name; | 
|---|
| 386 | size_t length; | 
|---|
| 387 | bool is_inline; | 
|---|
| 388 | enum dev_prop_type type; | 
|---|
| 389 | union { | 
|---|
| 390 | const void *pointer; | 
|---|
| 391 | union { | 
|---|
| 392 | u8 u8_data[sizeof(u64) / sizeof(u8)]; | 
|---|
| 393 | u16 u16_data[sizeof(u64) / sizeof(u16)]; | 
|---|
| 394 | u32 u32_data[sizeof(u64) / sizeof(u32)]; | 
|---|
| 395 | u64 u64_data[sizeof(u64) / sizeof(u64)]; | 
|---|
| 396 | const char *str[sizeof(u64) / sizeof(char *)]; | 
|---|
| 397 | } value; | 
|---|
| 398 | }; | 
|---|
| 399 | }; | 
|---|
| 400 |  | 
|---|
| 401 | /* | 
|---|
| 402 | * Note: the below initializers for the anonymous union are carefully | 
|---|
| 403 | * crafted to avoid gcc-4.4.4's problems with initialization of anon unions | 
|---|
| 404 | * and structs. | 
|---|
| 405 | */ | 
|---|
| 406 | #define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)		\ | 
|---|
| 407 | (struct property_entry) {								\ | 
|---|
| 408 | .name = _name_,									\ | 
|---|
| 409 | .length = (_len_) * sizeof_field(struct property_entry, value._elem_[0]),	\ | 
|---|
| 410 | .type = DEV_PROP_##_Type_,							\ | 
|---|
| 411 | { .pointer = _val_ },								\ | 
|---|
| 412 | } | 
|---|
| 413 |  | 
|---|
| 414 | #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_)		\ | 
|---|
| 415 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_) | 
|---|
| 416 | #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_)		\ | 
|---|
| 417 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16_data, U16, _val_, _len_) | 
|---|
| 418 | #define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_)		\ | 
|---|
| 419 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32_data, U32, _val_, _len_) | 
|---|
| 420 | #define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_)		\ | 
|---|
| 421 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_) | 
|---|
| 422 | #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_)		\ | 
|---|
| 423 | __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_) | 
|---|
| 424 |  | 
|---|
| 425 | #define PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, _len_)		\ | 
|---|
| 426 | (struct property_entry) {						\ | 
|---|
| 427 | .name = _name_,							\ | 
|---|
| 428 | .length = (_len_) * sizeof(struct software_node_ref_args),	\ | 
|---|
| 429 | .type = DEV_PROP_REF,						\ | 
|---|
| 430 | { .pointer = _val_ },						\ | 
|---|
| 431 | } | 
|---|
| 432 |  | 
|---|
| 433 | #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_)				\ | 
|---|
| 434 | PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | 
|---|
| 435 | #define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_)				\ | 
|---|
| 436 | PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | 
|---|
| 437 | #define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_)				\ | 
|---|
| 438 | PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | 
|---|
| 439 | #define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_)				\ | 
|---|
| 440 | PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | 
|---|
| 441 | #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_)			\ | 
|---|
| 442 | PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | 
|---|
| 443 | #define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_)				\ | 
|---|
| 444 | PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_)) | 
|---|
| 445 |  | 
|---|
| 446 | #define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_)		\ | 
|---|
| 447 | (struct property_entry) {						\ | 
|---|
| 448 | .name = _name_,							\ | 
|---|
| 449 | .length = sizeof_field(struct property_entry, value._elem_[0]),	\ | 
|---|
| 450 | .is_inline = true,						\ | 
|---|
| 451 | .type = DEV_PROP_##_Type_,					\ | 
|---|
| 452 | { .value = { ._elem_[0] = _val_ } },				\ | 
|---|
| 453 | } | 
|---|
| 454 |  | 
|---|
| 455 | #define PROPERTY_ENTRY_U8(_name_, _val_)				\ | 
|---|
| 456 | __PROPERTY_ENTRY_ELEMENT(_name_, u8_data, U8, _val_) | 
|---|
| 457 | #define PROPERTY_ENTRY_U16(_name_, _val_)				\ | 
|---|
| 458 | __PROPERTY_ENTRY_ELEMENT(_name_, u16_data, U16, _val_) | 
|---|
| 459 | #define PROPERTY_ENTRY_U32(_name_, _val_)				\ | 
|---|
| 460 | __PROPERTY_ENTRY_ELEMENT(_name_, u32_data, U32, _val_) | 
|---|
| 461 | #define PROPERTY_ENTRY_U64(_name_, _val_)				\ | 
|---|
| 462 | __PROPERTY_ENTRY_ELEMENT(_name_, u64_data, U64, _val_) | 
|---|
| 463 | #define PROPERTY_ENTRY_STRING(_name_, _val_)				\ | 
|---|
| 464 | __PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_) | 
|---|
| 465 |  | 
|---|
| 466 | #define PROPERTY_ENTRY_REF(_name_, _ref_, ...)				\ | 
|---|
| 467 | (struct property_entry) {						\ | 
|---|
| 468 | .name = _name_,							\ | 
|---|
| 469 | .length = sizeof(struct software_node_ref_args),		\ | 
|---|
| 470 | .type = DEV_PROP_REF,						\ | 
|---|
| 471 | { .pointer = &SOFTWARE_NODE_REFERENCE(_ref_, ##__VA_ARGS__), },	\ | 
|---|
| 472 | } | 
|---|
| 473 |  | 
|---|
| 474 | #define PROPERTY_ENTRY_BOOL(_name_)		\ | 
|---|
| 475 | (struct property_entry) {			\ | 
|---|
| 476 | .name = _name_,				\ | 
|---|
| 477 | .is_inline = true,			\ | 
|---|
| 478 | } | 
|---|
| 479 |  | 
|---|
| 480 | struct property_entry * | 
|---|
| 481 | property_entries_dup(const struct property_entry *properties); | 
|---|
| 482 | void property_entries_free(const struct property_entry *properties); | 
|---|
| 483 |  | 
|---|
| 484 | bool device_dma_supported(const struct device *dev); | 
|---|
| 485 | enum dev_dma_attr device_get_dma_attr(const struct device *dev); | 
|---|
| 486 |  | 
|---|
| 487 | const void *device_get_match_data(const struct device *dev); | 
|---|
| 488 |  | 
|---|
| 489 | int device_get_phy_mode(struct device *dev); | 
|---|
| 490 | int fwnode_get_phy_mode(const struct fwnode_handle *fwnode); | 
|---|
| 491 |  | 
|---|
| 492 | void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index); | 
|---|
| 493 |  | 
|---|
| 494 | struct fwnode_handle *fwnode_graph_get_next_endpoint( | 
|---|
| 495 | const struct fwnode_handle *fwnode, struct fwnode_handle *prev); | 
|---|
| 496 | struct fwnode_handle * | 
|---|
| 497 | fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode); | 
|---|
| 498 | struct fwnode_handle *fwnode_graph_get_remote_port_parent( | 
|---|
| 499 | const struct fwnode_handle *fwnode); | 
|---|
| 500 | struct fwnode_handle *fwnode_graph_get_remote_port( | 
|---|
| 501 | const struct fwnode_handle *fwnode); | 
|---|
| 502 | struct fwnode_handle *fwnode_graph_get_remote_endpoint( | 
|---|
| 503 | const struct fwnode_handle *fwnode); | 
|---|
| 504 |  | 
|---|
| 505 | static inline bool fwnode_graph_is_endpoint(const struct fwnode_handle *fwnode) | 
|---|
| 506 | { | 
|---|
| 507 | return fwnode_property_present(fwnode, propname: "remote-endpoint"); | 
|---|
| 508 | } | 
|---|
| 509 |  | 
|---|
| 510 | /* | 
|---|
| 511 | * Fwnode lookup flags | 
|---|
| 512 | * | 
|---|
| 513 | * @FWNODE_GRAPH_ENDPOINT_NEXT: In the case of no exact match, look for the | 
|---|
| 514 | *				closest endpoint ID greater than the specified | 
|---|
| 515 | *				one. | 
|---|
| 516 | * @FWNODE_GRAPH_DEVICE_DISABLED: That the device to which the remote | 
|---|
| 517 | *				  endpoint of the given endpoint belongs to, | 
|---|
| 518 | *				  may be disabled, or that the endpoint is not | 
|---|
| 519 | *				  connected. | 
|---|
| 520 | */ | 
|---|
| 521 | #define FWNODE_GRAPH_ENDPOINT_NEXT	BIT(0) | 
|---|
| 522 | #define FWNODE_GRAPH_DEVICE_DISABLED	BIT(1) | 
|---|
| 523 |  | 
|---|
| 524 | struct fwnode_handle * | 
|---|
| 525 | fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode, | 
|---|
| 526 | u32 port, u32 endpoint, unsigned long flags); | 
|---|
| 527 | unsigned int fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode, | 
|---|
| 528 | unsigned long flags); | 
|---|
| 529 |  | 
|---|
| 530 | #define fwnode_graph_for_each_endpoint(fwnode, child)				\ | 
|---|
| 531 | for (child = fwnode_graph_get_next_endpoint(fwnode, NULL); child;	\ | 
|---|
| 532 | child = fwnode_graph_get_next_endpoint(fwnode, child)) | 
|---|
| 533 |  | 
|---|
| 534 | int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, | 
|---|
| 535 | struct fwnode_endpoint *endpoint); | 
|---|
| 536 |  | 
|---|
| 537 | typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, const char *id, | 
|---|
| 538 | void *data); | 
|---|
| 539 |  | 
|---|
| 540 | void *fwnode_connection_find_match(const struct fwnode_handle *fwnode, | 
|---|
| 541 | const char *con_id, void *data, | 
|---|
| 542 | devcon_match_fn_t match); | 
|---|
| 543 |  | 
|---|
| 544 | static inline void *device_connection_find_match(const struct device *dev, | 
|---|
| 545 | const char *con_id, void *data, | 
|---|
| 546 | devcon_match_fn_t match) | 
|---|
| 547 | { | 
|---|
| 548 | return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match); | 
|---|
| 549 | } | 
|---|
| 550 |  | 
|---|
| 551 | int fwnode_connection_find_matches(const struct fwnode_handle *fwnode, | 
|---|
| 552 | const char *con_id, void *data, | 
|---|
| 553 | devcon_match_fn_t match, | 
|---|
| 554 | void **matches, unsigned int matches_len); | 
|---|
| 555 |  | 
|---|
| 556 | /* -------------------------------------------------------------------------- */ | 
|---|
| 557 | /* Software fwnode support - when HW description is incomplete or missing */ | 
|---|
| 558 |  | 
|---|
| 559 | /** | 
|---|
| 560 | * struct software_node - Software node description | 
|---|
| 561 | * @name: Name of the software node | 
|---|
| 562 | * @parent: Parent of the software node | 
|---|
| 563 | * @properties: Array of device properties | 
|---|
| 564 | */ | 
|---|
| 565 | struct software_node { | 
|---|
| 566 | const char *name; | 
|---|
| 567 | const struct software_node *parent; | 
|---|
| 568 | const struct property_entry *properties; | 
|---|
| 569 | }; | 
|---|
| 570 |  | 
|---|
| 571 | #define SOFTWARE_NODE(_name_, _properties_, _parent_)	\ | 
|---|
| 572 | (struct software_node) {			\ | 
|---|
| 573 | .name = _name_,				\ | 
|---|
| 574 | .properties = _properties_,		\ | 
|---|
| 575 | .parent = _parent_,			\ | 
|---|
| 576 | } | 
|---|
| 577 |  | 
|---|
| 578 | bool is_software_node(const struct fwnode_handle *fwnode); | 
|---|
| 579 | const struct software_node * | 
|---|
| 580 | to_software_node(const struct fwnode_handle *fwnode); | 
|---|
| 581 | struct fwnode_handle *software_node_fwnode(const struct software_node *node); | 
|---|
| 582 |  | 
|---|
| 583 | const struct software_node * | 
|---|
| 584 | software_node_find_by_name(const struct software_node *parent, | 
|---|
| 585 | const char *name); | 
|---|
| 586 |  | 
|---|
| 587 | int software_node_register_node_group(const struct software_node * const *node_group); | 
|---|
| 588 | void software_node_unregister_node_group(const struct software_node * const *node_group); | 
|---|
| 589 |  | 
|---|
| 590 | int software_node_register(const struct software_node *node); | 
|---|
| 591 | void software_node_unregister(const struct software_node *node); | 
|---|
| 592 |  | 
|---|
| 593 | struct fwnode_handle * | 
|---|
| 594 | fwnode_create_software_node(const struct property_entry *properties, | 
|---|
| 595 | const struct fwnode_handle *parent); | 
|---|
| 596 | void fwnode_remove_software_node(struct fwnode_handle *fwnode); | 
|---|
| 597 |  | 
|---|
| 598 | int device_add_software_node(struct device *dev, const struct software_node *node); | 
|---|
| 599 | void device_remove_software_node(struct device *dev); | 
|---|
| 600 |  | 
|---|
| 601 | int device_create_managed_software_node(struct device *dev, | 
|---|
| 602 | const struct property_entry *properties, | 
|---|
| 603 | const struct software_node *parent); | 
|---|
| 604 |  | 
|---|
| 605 | #endif /* _LINUX_PROPERTY_H_ */ | 
|---|
| 606 |  | 
|---|