2011-08-24 19:03:05 +00:00
|
|
|
#ifndef __OF_H
|
|
|
|
#define __OF_H
|
|
|
|
|
|
|
|
#include <fdt.h>
|
2011-08-09 17:12:34 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <asm/byteorder.h>
|
2011-08-24 19:03:05 +00:00
|
|
|
|
2013-06-18 09:19:52 +00:00
|
|
|
/* Default string compare functions */
|
|
|
|
#define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
|
|
|
|
#define of_prop_cmp(s1, s2) strcmp((s1), (s2))
|
|
|
|
#define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
|
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
#define OF_BAD_ADDR ((u64)-1)
|
|
|
|
|
|
|
|
typedef u32 phandle;
|
|
|
|
|
|
|
|
struct property {
|
|
|
|
char *name;
|
|
|
|
int length;
|
|
|
|
void *value;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct device_node {
|
|
|
|
char *name;
|
|
|
|
char *full_name;
|
|
|
|
|
|
|
|
struct list_head properties;
|
|
|
|
struct device_node *parent;
|
|
|
|
struct list_head children;
|
|
|
|
struct list_head parent_list;
|
|
|
|
struct list_head list;
|
|
|
|
struct resource *resource;
|
2013-04-22 06:58:37 +00:00
|
|
|
int num_resource;
|
2011-08-09 17:12:34 +00:00
|
|
|
struct device_d *device;
|
|
|
|
struct list_head phandles;
|
|
|
|
phandle phandle;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct of_device_id {
|
|
|
|
char *compatible;
|
|
|
|
unsigned long data;
|
|
|
|
};
|
|
|
|
|
2013-02-17 13:47:01 +00:00
|
|
|
#define OF_MAX_RESERVE_MAP 16
|
2013-03-03 12:22:55 +00:00
|
|
|
struct of_reserve_map {
|
|
|
|
uint64_t start[OF_MAX_RESERVE_MAP];
|
|
|
|
uint64_t end[OF_MAX_RESERVE_MAP];
|
|
|
|
int num_entries;
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2013-02-17 13:47:01 +00:00
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
struct driver_d;
|
|
|
|
|
2013-02-20 23:21:29 +00:00
|
|
|
int of_fix_tree(struct device_node *);
|
|
|
|
int of_register_fixup(int (*fixup)(struct device_node *));
|
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
int of_match(struct device_d *dev, struct driver_d *drv);
|
|
|
|
|
2013-03-03 11:52:21 +00:00
|
|
|
int of_add_initrd(struct device_node *root, resource_size_t start,
|
|
|
|
resource_size_t end);
|
|
|
|
|
2013-02-20 23:20:33 +00:00
|
|
|
int of_n_addr_cells(struct device_node *np);
|
|
|
|
int of_n_size_cells(struct device_node *np);
|
|
|
|
|
2013-02-17 17:43:47 +00:00
|
|
|
struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
|
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
struct fdt_header *fdt_get_tree(void);
|
|
|
|
|
2013-02-19 23:10:44 +00:00
|
|
|
struct fdt_header *of_get_fixed_tree(struct device_node *node);
|
|
|
|
|
2013-05-31 13:47:14 +00:00
|
|
|
int of_modalias_node(struct device_node *node, char *modalias, int len);
|
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
#define device_node_for_nach_child(node, child) \
|
|
|
|
list_for_each_entry(child, &node->children, parent_list)
|
|
|
|
|
2013-02-25 08:32:38 +00:00
|
|
|
/*
|
|
|
|
* Iterate over all nodes of a tree. As a devicetree does not
|
|
|
|
* have a dedicated list head, the start node (usually the root
|
|
|
|
* node) will not be iterated over.
|
|
|
|
*/
|
|
|
|
#define of_tree_for_each_node(node, root) \
|
|
|
|
list_for_each_entry(node, &root->list, list)
|
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
/* Helper to read a big number; size is in cells (not bytes) */
|
|
|
|
static inline u64 of_read_number(const __be32 *cell, int size)
|
|
|
|
{
|
|
|
|
u64 r = 0;
|
|
|
|
while (size--)
|
|
|
|
r = (r << 32) | be32_to_cpu(*(cell++));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-03-03 10:46:57 +00:00
|
|
|
/* Helper to write a big number; size is in cells (not bytes) */
|
|
|
|
static inline void of_write_number(void *__cell, u64 val, int size)
|
|
|
|
{
|
|
|
|
__be32 *cell = __cell;
|
|
|
|
|
|
|
|
while (size--) {
|
|
|
|
cell[size] = cpu_to_be32(val);
|
|
|
|
val >>= 32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
int of_property_read_u32_array(const struct device_node *np,
|
|
|
|
const char *propname, u32 *out_values,
|
|
|
|
size_t sz);
|
|
|
|
|
|
|
|
static inline int of_property_read_u32(const struct device_node *np,
|
|
|
|
const char *propname,
|
|
|
|
u32 *out_value)
|
|
|
|
{
|
|
|
|
return of_property_read_u32_array(np, propname, out_value, 1);
|
|
|
|
}
|
|
|
|
|
2013-02-20 23:18:38 +00:00
|
|
|
int of_property_write_u32_array(struct device_node *np,
|
|
|
|
const char *propname, const u32 *values,
|
|
|
|
size_t sz);
|
|
|
|
|
|
|
|
static inline int of_property_write_u32(struct device_node *np,
|
|
|
|
const char *propname,
|
|
|
|
u32 value)
|
|
|
|
{
|
|
|
|
return of_property_write_u32_array(np, propname, &value, 1);
|
|
|
|
}
|
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
const void *of_get_property(const struct device_node *np, const char *name,
|
|
|
|
int *lenp);
|
|
|
|
|
|
|
|
int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
|
|
|
|
const char *cells_name, int index,
|
|
|
|
struct device_node **out_node,
|
|
|
|
const void **out_args);
|
|
|
|
|
|
|
|
int of_get_named_gpio(struct device_node *np,
|
|
|
|
const char *propname, int index);
|
|
|
|
|
|
|
|
struct device_node *of_find_node_by_phandle(phandle phandle);
|
|
|
|
void of_print_property(const void *data, int len);
|
2013-05-28 12:57:29 +00:00
|
|
|
void of_print_cmdline(struct device_node *root);
|
2011-08-09 17:12:34 +00:00
|
|
|
|
2013-02-25 08:58:58 +00:00
|
|
|
int of_device_is_compatible(const struct device_node *device,
|
|
|
|
const char *compat);
|
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
int of_machine_is_compatible(const char *compat);
|
|
|
|
|
2013-03-03 15:54:45 +00:00
|
|
|
u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
|
|
|
|
|
2011-08-09 17:12:34 +00:00
|
|
|
#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
|
|
|
|
#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
|
|
|
|
|
|
|
|
void of_print_nodes(struct device_node *node, int indent);
|
|
|
|
int of_probe(void);
|
|
|
|
int of_parse_dtb(struct fdt_header *fdt);
|
2013-01-09 13:55:30 +00:00
|
|
|
void of_free(struct device_node *node);
|
2013-02-17 12:36:41 +00:00
|
|
|
struct device_node *of_unflatten_dtb(struct device_node *root, void *fdt);
|
2013-01-09 22:19:59 +00:00
|
|
|
struct device_node *of_new_node(struct device_node *parent, const char *name);
|
2013-01-09 15:47:16 +00:00
|
|
|
struct property *of_new_property(struct device_node *node, const char *name,
|
|
|
|
const void *data, int len);
|
|
|
|
void of_delete_property(struct property *pp);
|
2011-08-09 17:12:34 +00:00
|
|
|
|
2012-10-07 09:37:37 +00:00
|
|
|
int of_property_read_string(struct device_node *np, const char *propname,
|
|
|
|
const char **out_string);
|
2013-04-21 14:28:54 +00:00
|
|
|
int of_property_read_string_index(struct device_node *np, const char *propname,
|
|
|
|
int index, const char **output);
|
2013-02-17 16:13:38 +00:00
|
|
|
int of_set_property(struct device_node *node, const char *p, const void *val, int len,
|
|
|
|
int create);
|
|
|
|
struct device_node *of_create_node(struct device_node *root, const char *path);
|
2012-10-07 09:37:37 +00:00
|
|
|
|
2013-02-26 10:55:23 +00:00
|
|
|
int of_set_root_node(struct device_node *);
|
|
|
|
|
2013-05-19 06:53:47 +00:00
|
|
|
const struct of_device_id *of_match_node(const struct of_device_id *matches,
|
|
|
|
const struct device_node *node);
|
|
|
|
|
2013-04-22 07:07:34 +00:00
|
|
|
struct cdev;
|
|
|
|
|
2013-02-26 10:55:23 +00:00
|
|
|
#ifdef CONFIG_OFTREE
|
2013-06-18 09:21:19 +00:00
|
|
|
extern struct property *of_find_property(const struct device_node *np,
|
|
|
|
const char *name, int *lenp);
|
|
|
|
|
2013-06-13 17:39:14 +00:00
|
|
|
extern struct device_node *of_find_node_by_name(struct device_node *from,
|
|
|
|
const char *name);
|
2013-06-13 16:06:44 +00:00
|
|
|
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);
|
2013-06-13 16:25:54 +00:00
|
|
|
extern int of_device_is_available(const struct device_node *device);
|
2013-06-13 16:06:44 +00:00
|
|
|
|
2013-06-14 15:28:58 +00:00
|
|
|
extern void of_alias_scan(void);
|
|
|
|
extern int of_alias_get_id(struct device_node *np, const char *stem);
|
|
|
|
extern const char *of_alias_get(struct device_node *np);
|
2012-09-09 21:07:28 +00:00
|
|
|
|
2013-06-14 15:28:58 +00:00
|
|
|
int of_parse_partitions(struct cdev *cdev, struct device_node *node);
|
2012-10-06 22:15:17 +00:00
|
|
|
int of_device_is_stdout_path(struct device_d *dev);
|
2012-10-07 09:37:37 +00:00
|
|
|
const char *of_get_model(void);
|
2013-02-17 13:47:01 +00:00
|
|
|
void *of_flatten_dtb(struct device_node *node);
|
2013-02-13 10:06:40 +00:00
|
|
|
int of_add_memory(struct device_node *node, bool dump);
|
2013-05-12 19:54:03 +00:00
|
|
|
void of_add_memory_bank(struct device_node *node, bool dump, int r,
|
|
|
|
u64 base, u64 size);
|
2013-05-23 13:10:07 +00:00
|
|
|
struct device_node *of_get_root_node(void);
|
2011-08-09 17:12:34 +00:00
|
|
|
#else
|
2013-04-22 07:07:34 +00:00
|
|
|
static inline int of_parse_partitions(struct cdev *cdev,
|
2012-09-09 21:07:28 +00:00
|
|
|
struct device_node *node)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-10-06 22:15:17 +00:00
|
|
|
static inline int of_device_is_stdout_path(struct device_d *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-16 13:02:44 +00:00
|
|
|
|
2012-10-07 09:37:37 +00:00
|
|
|
static inline const char *of_get_model(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-01-09 08:39:06 +00:00
|
|
|
|
2013-02-17 13:47:01 +00:00
|
|
|
static inline void *of_flatten_dtb(struct device_node *node)
|
2013-01-09 08:39:06 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-02-13 10:06:40 +00:00
|
|
|
|
|
|
|
static inline int of_add_memory(struct device_node *node, bool dump)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-05-23 13:10:07 +00:00
|
|
|
|
|
|
|
static inline struct device_node *of_get_root_node(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-06-14 15:28:58 +00:00
|
|
|
|
2013-06-18 09:21:19 +00:00
|
|
|
static inline struct property *of_find_property(const struct device_node *np,
|
|
|
|
const char *name,
|
|
|
|
int *lenp)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-13 16:06:44 +00:00
|
|
|
static inline struct device_node *of_find_node_by_path_from(
|
|
|
|
struct device_node *from, const char *path)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct device_node *of_find_node_by_path(const char *path)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-13 17:39:14 +00:00
|
|
|
static inline struct device_node *of_find_node_by_name(struct device_node *from,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-13 16:25:54 +00:00
|
|
|
static inline int of_device_is_available(const struct device_node *device)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-14 15:28:58 +00:00
|
|
|
static inline void of_alias_scan(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int of_alias_get_id(struct device_node *np, const char *stem)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char *of_alias_get(struct device_node *np)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-09 17:12:34 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-13 17:39:14 +00:00
|
|
|
#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))
|
|
|
|
|
2011-08-24 19:03:05 +00:00
|
|
|
#endif /* __OF_H */
|