summaryrefslogtreecommitdiffstats
path: root/include/of.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/of.h')
-rw-r--r--include/of.h307
1 files changed, 265 insertions, 42 deletions
diff --git a/include/of.h b/include/of.h
index e5df4cab4a..f99cff5cf5 100644
--- a/include/of.h
+++ b/include/of.h
@@ -5,7 +5,9 @@
#include <fdt.h>
#include <errno.h>
#include <linux/types.h>
+#include <linux/limits.h>
#include <linux/list.h>
+#include <linux/err.h>
#include <asm/byteorder.h>
/* Default string compare functions */
@@ -35,11 +37,11 @@ struct device_node {
struct list_head parent_list;
struct list_head list;
phandle phandle;
- struct device_d *dev;
+ struct device *dev;
};
struct of_device_id {
- char *compatible;
+ const char *compatible;
const void *data;
};
@@ -58,23 +60,27 @@ struct of_reserve_map {
};
int of_add_reserve_entry(resource_size_t start, resource_size_t end);
-struct of_reserve_map *of_get_reserve_map(void);
void of_clean_reserve_map(void);
void fdt_add_reserve_map(void *fdt);
+void fdt_print_reserve_map(const void *fdt);
-struct device_d;
-struct driver_d;
+int fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, const char *compat);
-int of_fix_tree(struct device_node *);
-int of_match(struct device_d *dev, struct driver_d *drv);
+struct device;
+struct driver;
+struct resource;
+
+void of_fix_tree(struct device_node *);
+
+int of_match(struct device *dev, struct driver *drv);
int of_add_initrd(struct device_node *root, resource_size_t start,
resource_size_t end);
struct fdt_header *fdt_get_tree(void);
-struct fdt_header *of_get_fixed_tree(struct device_node *node);
+struct fdt_header *of_get_fixed_tree(const struct device_node *node);
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
@@ -101,25 +107,39 @@ static inline const void *of_property_get_value(const struct property *pp)
return pp->value ? pp->value : pp->value_const;
}
+static inline struct device_node *of_node_get(struct device_node *node)
+{
+ return node;
+}
+static inline void of_node_put(struct device_node *node) { }
void of_print_property(const void *data, int len);
void of_print_cmdline(struct device_node *root);
-void of_print_nodes(struct device_node *node, int indent);
-void of_print_properties(struct device_node *node);
-void of_diff(struct device_node *a, struct device_node *b, int indent);
+void of_print_nodes(struct device_node *node, int indent, unsigned maxpropsize);
+void of_print_properties(struct device_node *node, unsigned maxpropsize);
+int of_diff(struct device_node *a, struct device_node *b, int indent);
int of_probe(void);
int of_parse_dtb(struct fdt_header *fdt);
struct device_node *of_unflatten_dtb(const void *fdt, int size);
struct device_node *of_unflatten_dtb_const(const void *infdt, int size);
+int of_fixup_reserved_memory(struct device_node *node, void *data);
+
struct cdev;
+/* Maximum score returned by of_device_is_compatible() */
+#define OF_DEVICE_COMPATIBLE_MAX_SCORE (INT_MAX / 2)
+
#ifdef CONFIG_OFTREE
+extern struct device_node *of_read_file(const char *filename);
+extern struct of_reserve_map *of_get_reserve_map(void);
extern int of_bus_n_addr_cells(struct device_node *np);
extern int of_n_addr_cells(struct device_node *np);
extern int of_bus_n_size_cells(struct device_node *np);
extern int of_n_size_cells(struct device_node *np);
+extern bool of_node_name_eq(const struct device_node *np, const char *name);
+extern size_t of_node_has_prefix(const struct device_node *np, const char *prefix);
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
@@ -129,15 +149,28 @@ extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
extern int of_set_property(struct device_node *node, const char *p,
const void *val, int len, int create);
+extern int of_append_property(struct device_node *np, const char *p,
+ const void *val, int len);
+extern int of_prepend_property(struct device_node *np, const char *name,
+ const void *val, int len);
extern struct property *of_new_property(struct device_node *node,
const char *name, const void *data, int len);
extern struct property *of_new_property_const(struct device_node *node,
const char *name,
const void *data, int len);
+extern struct property *__of_new_property(struct device_node *node,
+ const char *name, void *data, int len);
extern void of_delete_property(struct property *pp);
+extern struct property *of_rename_property(struct device_node *np,
+ const char *old_name, const char *new_name);
+extern struct property *of_copy_property(const struct device_node *src,
+ const char *propname,
+ struct device_node *dst);
extern struct device_node *of_find_node_by_name(struct device_node *from,
const char *name);
+extern struct device_node *of_find_node_by_name_address(struct device_node *from,
+ const char *name);
extern struct device_node *of_find_node_by_path_from(struct device_node *from,
const char *path);
extern struct device_node *of_find_node_by_path(const char *path);
@@ -161,6 +194,7 @@ extern struct device_node *of_new_node(struct device_node *parent,
const char *name);
extern struct device_node *of_create_node(struct device_node *root,
const char *path);
+extern void of_merge_nodes(struct device_node *np, const struct device_node *other);
extern struct device_node *of_copy_node(struct device_node *parent,
const struct device_node *other);
extern struct device_node *of_dup(const struct device_node *root);
@@ -185,6 +219,9 @@ extern struct device_node *of_get_compatible_child(const struct device_node *par
extern struct device_node *of_get_child_by_name(const struct device_node *node,
const char *name);
extern char *of_get_reproducible_name(struct device_node *node);
+extern struct device_node *of_get_node_by_reproducible_name(struct device_node *dstroot,
+ struct device_node *srcnp);
+
extern struct device_node *of_find_node_by_reproducible_name(struct device_node
*from,
const char *name);
@@ -203,16 +240,27 @@ extern int of_property_read_u32_array(const struct device_node *np,
size_t sz);
extern int of_property_read_u64(const struct device_node *np,
const char *propname, u64 *out_value);
-
+extern int of_property_read_variable_u8_array(const struct device_node *np,
+ const char *propname, u8 *out_values,
+ size_t sz_min, size_t sz_max);
+extern int of_property_read_variable_u16_array(const struct device_node *np,
+ const char *propname, u16 *out_values,
+ size_t sz_min, size_t sz_max);
+extern int of_property_read_variable_u32_array(const struct device_node *np,
+ const char *propname,
+ u32 *out_values,
+ size_t sz_min,
+ size_t sz_max);
extern int of_property_read_variable_u64_array(const struct device_node *np,
const char *propname,
u64 *out_values,
- size_t sz);
+ size_t sz_min,
+ size_t sz_max);
extern int of_property_read_string(struct device_node *np,
const char *propname,
const char **out_string);
-extern int of_property_match_string(struct device_node *np,
+extern int of_property_match_string(const struct device_node *np,
const char *propname,
const char *string);
extern int of_property_read_string_helper(const struct device_node *np,
@@ -269,22 +317,22 @@ extern int of_set_root_node(struct device_node *node);
extern int barebox_register_of(struct device_node *root);
extern int barebox_register_fdt(const void *dtb);
-extern struct device_d *of_platform_device_create(struct device_node *np,
- struct device_d *parent);
-extern void of_platform_device_dummy_drv(struct device_d *dev);
+extern struct device *of_platform_device_create(struct device_node *np,
+ struct device *parent);
+extern void of_platform_device_dummy_drv(struct device *dev);
extern int of_platform_populate(struct device_node *root,
const struct of_device_id *matches,
- struct device_d *parent);
-extern struct device_d *of_find_device_by_node(struct device_node *np);
-extern struct device_d *of_device_enable_and_register(struct device_node *np);
-extern struct device_d *of_device_enable_and_register_by_name(const char *name);
-extern struct device_d *of_device_enable_and_register_by_alias(
+ struct device *parent);
+extern struct device *of_find_device_by_node(struct device_node *np);
+extern struct device *of_device_enable_and_register(struct device_node *np);
+extern struct device *of_device_enable_and_register_by_name(const char *name);
+extern struct device *of_device_enable_and_register_by_alias(
const char *alias);
-extern struct device_d *of_device_create_on_demand(struct device_node *np);
extern int of_device_ensure_probed(struct device_node *np);
extern int of_device_ensure_probed_by_alias(const char *alias);
extern int of_devices_ensure_probed_by_property(const char *property_name);
+extern int of_devices_ensure_probed_by_name(const char *name);
extern int of_devices_ensure_probed_by_dev_id(const struct of_device_id *ids);
extern int of_partition_ensure_probed(struct device_node *np);
@@ -292,20 +340,33 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node);
int of_parse_partitions(struct cdev *cdev, struct device_node *node);
int of_fixup_partitions(struct device_node *np, struct cdev *cdev);
int of_partitions_register_fixup(struct cdev *cdev);
+struct device_node *of_find_node_by_chosen(const char *propname,
+ const char **options);
struct device_node *of_get_stdoutpath(unsigned int *);
-int of_device_is_stdout_path(struct device_d *dev, unsigned int *baudrate);
+int of_device_is_stdout_path(struct device *dev, unsigned int *baudrate);
const char *of_get_model(void);
void *of_flatten_dtb(struct device_node *node);
int of_add_memory(struct device_node *node, bool dump);
int of_add_memory_bank(struct device_node *node, bool dump, int r,
u64 base, u64 size);
-struct device_d *of_find_device_by_node_path(const char *path);
+struct device *of_find_device_by_node_path(const char *path);
#define OF_FIND_PATH_FLAGS_BB 1 /* return .bb device if available */
int of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags);
+struct cdev *of_cdev_find(struct device_node *node);
int of_find_path_by_node(struct device_node *node, char **outpath, unsigned flags);
struct device_node *of_find_node_by_devpath(struct device_node *root, const char *path);
int of_register_fixup(int (*fixup)(struct device_node *, void *), void *context);
int of_unregister_fixup(int (*fixup)(struct device_node *, void *), void *context);
+
+struct of_fixup {
+ int (*fixup)(struct device_node *, void *);
+ void *context;
+ struct list_head list;
+ bool disabled;
+};
+
+extern struct list_head of_fixup_list;
+
int of_register_set_status_fixup(const char *node, bool status);
struct device_node *of_find_node_by_alias(struct device_node *root,
const char *alias);
@@ -313,7 +374,34 @@ struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
const char *str);
int of_autoenable_device_by_path(char *path);
int of_autoenable_i2c_by_component(char *path);
+int of_prepend_machine_compatible(struct device_node *root, const char *compat);
+
+static inline const char *of_node_full_name(const struct device_node *np)
+{
+ return np ? np->full_name : "<no-node>";
+}
+
#else
+static inline struct device_node *of_read_file(const char *filename)
+{
+ return ERR_PTR(-ENOSYS);
+}
+
+static inline struct of_reserve_map *of_get_reserve_map(void)
+{
+ return NULL;
+}
+
+static inline bool of_node_name_eq(const struct device_node *np, const char *name)
+{
+ return false;
+}
+
+static inline size_t of_node_has_prefix(const struct device_node *np, const char *prefix)
+{
+ return 0;
+}
+
static inline int of_parse_partitions(struct cdev *cdev,
struct device_node *node)
{
@@ -330,12 +418,19 @@ static inline int of_partitions_register_fixup(struct cdev *cdev)
return -ENOSYS;
}
+static inline struct device_node *of_find_node_by_chosen(const char *propname,
+ const char **options)
+{
+ return NULL;
+}
+
static inline struct device_node *of_get_stdoutpath(unsigned int *rate)
{
return NULL;
}
-static inline int of_device_is_stdout_path(struct device_d *dev, unsigned int *baudrate)
+static inline int of_device_is_stdout_path(struct device *dev,
+ unsigned int *baudrate)
{
return 0;
}
@@ -365,19 +460,19 @@ static inline int of_set_root_node(struct device_node *node)
return -ENOSYS;
}
-static inline struct device_d *of_platform_device_create(struct device_node *np,
- struct device_d *parent)
+static inline int barebox_register_of(struct device_node *root)
{
- return NULL;
+ return -ENOSYS;
}
-static inline void of_platform_device_dummy_drv(struct device_d *dev)
+static inline struct device *of_platform_device_create(struct device_node *np,
+ struct device *parent)
{
+ return NULL;
}
-static inline struct device_d *of_device_create_on_demand(struct device_node *np)
+static inline void of_platform_device_dummy_drv(struct device *dev)
{
- return NULL;
}
static inline int of_device_ensure_probed(struct device_node *np)
@@ -476,6 +571,13 @@ of_find_node_by_reproducible_name(struct device_node *from, const char *name)
return NULL;
}
+
+static inline struct device_node *of_get_node_by_reproducible_name(struct device_node *dstroot,
+ struct device_node *srcnp)
+{
+ return NULL;
+}
+
static inline struct property *of_find_property(const struct device_node *np,
const char *name,
int *lenp)
@@ -501,16 +603,47 @@ static inline int of_set_property(struct device_node *node, const char *p,
return -ENOSYS;
}
+static inline int of_append_property(struct device_node *np, const char *p,
+ const void *val, int len)
+{
+ return -ENOSYS;
+}
+
+static inline int of_prepend_property(struct device_node *np, const char *name,
+ const void *val, int len)
+{
+ return -ENOSYS;
+}
+
static inline struct property *of_new_property(struct device_node *node,
const char *name, const void *data, int len)
{
return NULL;
}
+static inline struct property *__of_new_property(struct device_node *node,
+ const char *name, void *data, int len)
+{
+ return NULL;
+}
+
+static inline struct property *of_copy_property(const struct device_node *src,
+ const char *propname,
+ struct device_node *dst)
+{
+ return NULL;
+}
+
static inline void of_delete_property(struct property *pp)
{
}
+static inline struct property *of_rename_property(struct device_node *np,
+ const char *old_name, const char *new_name)
+{
+ return NULL;
+}
+
static inline int of_property_read_u32_index(const struct device_node *np,
const char *propname, u32 index, u32 *out_value)
{
@@ -547,10 +680,34 @@ static inline int of_property_read_u64(const struct device_node *np,
return -ENOSYS;
}
+static inline int of_property_read_variable_u8_array(const struct device_node *np,
+ const char *propname, u8 *out_values,
+ size_t sz_min, size_t sz_max)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_variable_u16_array(const struct device_node *np,
+ const char *propname, u16 *out_values,
+ size_t sz_min, size_t sz_max)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_variable_u32_array(const struct device_node *np,
+ const char *propname,
+ u32 *out_values,
+ size_t sz_min,
+ size_t sz_max)
+{
+ return -ENOSYS;
+}
+
static inline int of_property_read_variable_u64_array(const struct device_node *np,
const char *propname,
u64 *out_values,
- size_t sz)
+ size_t sz_min,
+ size_t sz_max)
{
return -ENOSYS;
}
@@ -561,7 +718,7 @@ static inline int of_property_read_string(struct device_node *np,
return -ENOSYS;
}
-static inline int of_property_match_string(struct device_node *np,
+static inline int of_property_match_string(const struct device_node *np,
const char *propname, const char *string)
{
return -ENOSYS;
@@ -665,6 +822,12 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
return NULL;
}
+static inline struct device_node *of_find_node_by_name_address(struct device_node *from,
+ const char *name)
+{
+ return NULL;
+}
+
static inline struct device_node *of_find_node_by_phandle(phandle phandle)
{
return NULL;
@@ -716,6 +879,11 @@ static inline struct device_node *of_create_node(struct device_node *root,
return NULL;
}
+static inline struct device_node *of_dup(const struct device_node *root)
+{
+ return NULL;
+}
+
static inline void of_delete_node(struct device_node *node)
{
}
@@ -769,29 +937,29 @@ static inline int of_modalias_node(struct device_node *node, char *modalias,
static inline int of_platform_populate(struct device_node *root,
const struct of_device_id *matches,
- struct device_d *parent)
+ struct device *parent)
{
return -ENOSYS;
}
-static inline struct device_d *of_find_device_by_node(struct device_node *np)
+static inline struct device *of_find_device_by_node(struct device_node *np)
{
return NULL;
}
-static inline struct device_d *of_device_enable_and_register(
+static inline struct device *of_device_enable_and_register(
struct device_node *np)
{
return NULL;
}
-static inline struct device_d *of_device_enable_and_register_by_name(
+static inline struct device *of_device_enable_and_register_by_name(
const char *name)
{
return NULL;
}
-static inline struct device_d *of_device_enable_and_register_by_alias(
+static inline struct device *of_device_enable_and_register_by_alias(
const char *alias)
{
return NULL;
@@ -825,6 +993,16 @@ static inline int of_autoenable_i2c_by_component(char *path)
return -ENODEV;
}
+static inline int of_prepend_machine_compatible(struct device_node *root,
+ const char *compat)
+{
+ return -ENODEV;
+}
+
+static inline const char *of_node_full_name(const struct device_node *np)
+{
+ return "<no-node>";
+}
#endif
@@ -833,12 +1011,18 @@ static inline int of_autoenable_i2c_by_component(char *path)
#define for_each_node_by_name(dn, name) \
for (dn = of_find_node_by_name(NULL, name); dn; \
dn = of_find_node_by_name(dn, name))
+#define for_each_node_by_name_address(dn, name) \
+ for (dn = of_find_node_by_name_address(NULL, name); dn; \
+ dn = of_find_node_by_name_address(dn, name))
#define for_each_node_by_type(dn, type) \
for (dn = of_find_node_by_type(NULL, type); dn; \
dn = of_find_node_by_type(dn, type))
#define for_each_node_by_name_from(dn, root, name) \
for (dn = of_find_node_by_name(root, name); dn; \
dn = of_find_node_by_name(dn, name))
+#define for_each_node_by_name_address_from(dn, root, name) \
+ for (dn = of_find_node_by_name_address(root, name); dn; \
+ dn = of_find_node_by_name_address(dn, name))
/* Iterate over compatible nodes starting from given root */
#define for_each_compatible_node_from(dn, root, type, compatible) \
for (dn = of_find_compatible_node(root, type, compatible); dn; \
@@ -941,8 +1125,10 @@ static inline int of_property_read_string_index(const struct device_node *np,
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
*
- * Search for a property in a device node.
- * Returns true if the property exist false otherwise.
+ * Search for a boolean property in a device node. Usage on non-boolean
+ * property types is deprecated.
+
+ * Return: true if the property exist false otherwise.
*/
static inline bool of_property_read_bool(const struct device_node *np,
const char *propname)
@@ -952,6 +1138,20 @@ static inline bool of_property_read_bool(const struct device_node *np,
return prop ? true : false;
}
+/**
+ * of_property_present - Test if a property is present in a node
+ * @np: device node to search for the property.
+ * @propname: name of the property to be searched.
+ *
+ * Test for a property present in a device node.
+ *
+ * Return: true if the property exists false otherwise.
+ */
+static inline bool of_property_present(const struct device_node *np, const char *propname)
+{
+ return of_property_read_bool(np, propname);
+}
+
static inline int of_property_read_u8(const struct device_node *np,
const char *propname,
u8 *out_value)
@@ -973,6 +1173,13 @@ static inline int of_property_read_u32(const struct device_node *np,
return of_property_read_u32_array(np, propname, out_value, 1);
}
+static inline int of_property_read_s32(const struct device_node *np,
+ const char *propname,
+ s32 *out_value)
+{
+ return of_property_read_u32(np, propname, (u32*) out_value);
+}
+
/**
* of_property_read_u64_array - Find and read an array of 64 bit integers
* from a property.
@@ -994,7 +1201,7 @@ static inline int of_property_read_u64_array(const struct device_node *np,
u64 *out_values, size_t sz)
{
int ret = of_property_read_variable_u64_array(np, propname, out_values,
- sz);
+ sz, 0);
if (ret >= 0)
return 0;
else
@@ -1054,14 +1261,30 @@ static inline int of_property_write_u64(struct device_node *np,
return of_property_write_u64_array(np, propname, &value, 1);
}
+static inline void of_delete_property_by_name(struct device_node *np, const char *name)
+{
+ of_delete_property(of_find_property(np, name, NULL));
+}
+
extern const struct of_device_id of_default_bus_match_table[];
int of_device_enable(struct device_node *node);
int of_device_enable_path(const char *path);
+int of_device_enable_by_alias(const char *alias);
int of_device_disable(struct device_node *node);
int of_device_disable_path(const char *path);
int of_device_disable_by_alias(const char *alias);
+static inline int of_devices_ensure_probed_by_compatible(const char *compatible)
+{
+ struct of_device_id match_id[] = {
+ { .compatible = compatible, },
+ { /* sentinel */ },
+ };
+
+ return of_devices_ensure_probed_by_dev_id(match_id);
+}
+
phandle of_get_tree_max_phandle(struct device_node *root);
phandle of_node_create_phandle(struct device_node *node);
int of_set_property_to_child_phandle(struct device_node *node, char *prop_name);