]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/linux/of.h
Merge tag 'drm-intel-next-fixes-2014-12-30' of git://anongit.freedesktop.org/drm...
[karo-tx-linux.git] / include / linux / of.h
index c55b50018ac4316c7874c2a5bf43f51a67296a4b..dfde07e77a632b3e7868f5aabebf7fe3870cbaeb 100644 (file)
@@ -23,6 +23,8 @@
 #include <linux/spinlock.h>
 #include <linux/topology.h>
 #include <linux/notifier.h>
+#include <linux/property.h>
+#include <linux/list.h>
 
 #include <asm/byteorder.h>
 #include <asm/errno.h>
@@ -49,14 +51,13 @@ struct device_node {
        const char *type;
        phandle phandle;
        const char *full_name;
+       struct fwnode_handle fwnode;
 
        struct  property *properties;
        struct  property *deadprops;    /* removed properties */
        struct  device_node *parent;
        struct  device_node *child;
        struct  device_node *sibling;
-       struct  device_node *next;      /* next device of same type */
-       struct  device_node *allnext;   /* next in list of all nodes */
        struct  kobject kobj;
        unsigned long _flags;
        void    *data;
@@ -74,11 +75,18 @@ struct of_phandle_args {
        uint32_t args[MAX_PHANDLE_ARGS];
 };
 
+struct of_reconfig_data {
+       struct device_node      *dn;
+       struct property         *prop;
+       struct property         *old_prop;
+};
+
 /* initialize a node */
 extern struct kobj_type of_node_ktype;
 static inline void of_node_init(struct device_node *node)
 {
        kobject_init(&node->kobj, &of_node_ktype);
+       node->fwnode.type = FWNODE_OF;
 }
 
 /* true when node is initialized */
@@ -105,18 +113,27 @@ static inline struct device_node *of_node_get(struct device_node *node)
 static inline void of_node_put(struct device_node *node) { }
 #endif /* !CONFIG_OF_DYNAMIC */
 
-#ifdef CONFIG_OF
-
 /* Pointer for first entry in chain of all nodes. */
-extern struct device_node *of_allnodes;
+extern struct device_node *of_root;
 extern struct device_node *of_chosen;
 extern struct device_node *of_aliases;
 extern struct device_node *of_stdout;
 extern raw_spinlock_t devtree_lock;
 
+#ifdef CONFIG_OF
+static inline bool is_of_node(struct fwnode_handle *fwnode)
+{
+       return fwnode && fwnode->type == FWNODE_OF;
+}
+
+static inline struct device_node *of_node(struct fwnode_handle *fwnode)
+{
+       return fwnode ? container_of(fwnode, struct device_node, fwnode) : NULL;
+}
+
 static inline bool of_have_populated_dt(void)
 {
-       return of_allnodes != NULL;
+       return of_root != NULL;
 }
 
 static inline bool of_node_is_root(const struct device_node *node)
@@ -160,6 +177,7 @@ static inline void of_property_clear_flag(struct property *p, unsigned long flag
        clear_bit(flag, &p->_flags);
 }
 
+extern struct device_node *__of_find_all_nodes(struct device_node *prev);
 extern struct device_node *of_find_all_nodes(struct device_node *prev);
 
 /*
@@ -215,8 +233,9 @@ static inline const char *of_node_full_name(const struct device_node *np)
        return np ? np->full_name : "<no-node>";
 }
 
-#define for_each_of_allnodes(dn) \
-       for (dn = of_allnodes; dn; dn = dn->allnext)
+#define for_each_of_allnodes_from(from, dn) \
+       for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn))
+#define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
 extern struct device_node *of_find_node_by_name(struct device_node *from,
        const char *name);
 extern struct device_node *of_find_node_by_type(struct device_node *from,
@@ -228,7 +247,13 @@ extern struct device_node *of_find_matching_node_and_match(
        const struct of_device_id *matches,
        const struct of_device_id **match);
 
-extern struct device_node *of_find_node_by_path(const char *path);
+extern struct device_node *of_find_node_opts_by_path(const char *path,
+       const char **opts);
+static inline struct device_node *of_find_node_by_path(const char *path)
+{
+       return of_find_node_opts_by_path(path, NULL);
+}
+
 extern struct device_node *of_find_node_by_phandle(phandle handle);
 extern struct device_node *of_get_parent(const struct device_node *node);
 extern struct device_node *of_get_next_parent(struct device_node *node);
@@ -263,6 +288,10 @@ 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_u64_array(const struct device_node *np,
+                                     const char *propname,
+                                     u64 *out_values,
+                                     size_t sz);
 
 extern int of_property_read_string(struct device_node *np,
                                   const char *propname,
@@ -275,7 +304,7 @@ extern int of_property_read_string_helper(struct device_node *np,
                                              const char **out_strs, size_t sz, int index);
 extern int of_device_is_compatible(const struct device_node *device,
                                   const char *);
-extern int of_device_is_available(const struct device_node *device);
+extern bool of_device_is_available(const struct device_node *device);
 extern const void *of_get_property(const struct device_node *node,
                                const char *name,
                                int *lenp);
@@ -317,16 +346,6 @@ extern int of_update_property(struct device_node *np, struct property *newprop);
 #define OF_RECONFIG_REMOVE_PROPERTY    0x0004
 #define OF_RECONFIG_UPDATE_PROPERTY    0x0005
 
-struct of_prop_reconfig {
-       struct device_node      *dn;
-       struct property         *prop;
-       struct property         *old_prop;
-};
-
-extern int of_reconfig_notifier_register(struct notifier_block *);
-extern int of_reconfig_notifier_unregister(struct notifier_block *);
-extern int of_reconfig_notify(unsigned long, void *);
-
 extern int of_attach_node(struct device_node *);
 extern int of_detach_node(struct device_node *);
 
@@ -355,6 +374,16 @@ bool of_console_check(struct device_node *dn, char *name, int index);
 
 #else /* CONFIG_OF */
 
+static inline bool is_of_node(struct fwnode_handle *fwnode)
+{
+       return false;
+}
+
+static inline struct device_node *of_node(struct fwnode_handle *fwnode)
+{
+       return NULL;
+}
+
 static inline const char* of_node_full_name(const struct device_node *np)
 {
        return "<no-node>";
@@ -385,6 +414,12 @@ static inline struct device_node *of_find_node_by_path(const char *path)
        return NULL;
 }
 
+static inline struct device_node *of_find_node_opts_by_path(const char *path,
+       const char **opts)
+{
+       return NULL;
+}
+
 static inline struct device_node *of_get_parent(const struct device_node *node)
 {
        return NULL;
@@ -426,9 +461,9 @@ static inline int of_device_is_compatible(const struct device_node *device,
        return 0;
 }
 
-static inline int of_device_is_available(const struct device_node *device)
+static inline bool of_device_is_available(const struct device_node *device)
 {
-       return 0;
+       return false;
 }
 
 static inline struct property *of_find_property(const struct device_node *np,
@@ -477,6 +512,13 @@ static inline int of_property_read_u32_array(const struct device_node *np,
        return -ENOSYS;
 }
 
+static inline int of_property_read_u64_array(const struct device_node *np,
+                                            const char *propname,
+                                            u64 *out_values, size_t sz)
+{
+       return -ENOSYS;
+}
+
 static inline int of_property_read_string(struct device_node *np,
                                          const char *propname,
                                          const char **out_string)
@@ -760,6 +802,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);
+}
+
 #define of_property_for_each_u32(np, propname, prop, p, u)     \
        for (prop = of_find_property(np, propname, NULL),       \
                p = of_prop_next_u32(prop, NULL, &u);           \
@@ -828,7 +877,7 @@ static inline int of_get_available_child_count(const struct device_node *np)
                 = { .compatible = compat,                              \
                     .data = (fn == (fn_type)NULL) ? fn : fn  }
 #else
-#define _OF_DECLARE(table, name, compat, fn, fn_type)                                  \
+#define _OF_DECLARE(table, name, compat, fn, fn_type)                  \
        static const struct of_device_id __of_table_##name              \
                __attribute__((unused))                                 \
                 = { .compatible = compat,                              \
@@ -879,7 +928,19 @@ struct of_changeset {
        struct list_head entries;
 };
 
+enum of_reconfig_change {
+       OF_RECONFIG_NO_CHANGE = 0,
+       OF_RECONFIG_CHANGE_ADD,
+       OF_RECONFIG_CHANGE_REMOVE,
+};
+
 #ifdef CONFIG_OF_DYNAMIC
+extern int of_reconfig_notifier_register(struct notifier_block *);
+extern int of_reconfig_notifier_unregister(struct notifier_block *);
+extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
+extern int of_reconfig_get_state_change(unsigned long action,
+                                       struct of_reconfig_data *arg);
+
 extern void of_changeset_init(struct of_changeset *ocs);
 extern void of_changeset_destroy(struct of_changeset *ocs);
 extern int of_changeset_apply(struct of_changeset *ocs);
@@ -917,7 +978,26 @@ static inline int of_changeset_update_property(struct of_changeset *ocs,
 {
        return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
 }
-#endif
+#else /* CONFIG_OF_DYNAMIC */
+static inline int of_reconfig_notifier_register(struct notifier_block *nb)
+{
+       return -EINVAL;
+}
+static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
+{
+       return -EINVAL;
+}
+static inline int of_reconfig_notify(unsigned long action,
+                                    struct of_reconfig_data *arg)
+{
+       return -EINVAL;
+}
+static inline int of_reconfig_get_state_change(unsigned long action,
+                                               struct of_reconfig_data *arg)
+{
+       return -EINVAL;
+}
+#endif /* CONFIG_OF_DYNAMIC */
 
 /* CONFIG_OF_RESOLVE api */
 extern int of_resolve_phandles(struct device_node *tree);
@@ -933,4 +1013,34 @@ static inline bool of_device_is_system_power_controller(const struct device_node
        return of_property_read_bool(np, "system-power-controller");
 }
 
+/**
+ * Overlay support
+ */
+
+#ifdef CONFIG_OF_OVERLAY
+
+/* ID based overlays; the API for external users */
+int of_overlay_create(struct device_node *tree);
+int of_overlay_destroy(int id);
+int of_overlay_destroy_all(void);
+
+#else
+
+static inline int of_overlay_create(struct device_node *tree)
+{
+       return -ENOTSUPP;
+}
+
+static inline int of_overlay_destroy(int id)
+{
+       return -ENOTSUPP;
+}
+
+static inline int of_overlay_destroy_all(void)
+{
+       return -ENOTSUPP;
+}
+
+#endif
+
 #endif /* _LINUX_OF_H */