Skip to content

Commit

Permalink
Merge tag 'devicetree-fixes-for-4.19' of git://git.kernel.org/pub/scm…
Browse files Browse the repository at this point in the history
…/linux/kernel/git/robh/linux

Pull devicetree updates from Rob Herring:
 "A couple of new helper functions in preparation for some tree wide
  clean-ups.

  I'm sending these new helpers now for rc2 in order to simplify the
  dependencies on subsequent cleanups across the tree in 4.20"

* tag 'devicetree-fixes-for-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux:
  of: Add device_type access helper functions
  of: add node name compare helper functions
  of: add helper to lookup compatible child node
  • Loading branch information
torvalds committed Sep 2, 2018
2 parents a3ea991 + 0413bed commit fd6868d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
47 changes: 47 additions & 0 deletions drivers/of/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ DEFINE_MUTEX(of_mutex);
*/
DEFINE_RAW_SPINLOCK(devtree_lock);

bool of_node_name_eq(const struct device_node *np, const char *name)
{
const char *node_name;
size_t len;

if (!np)
return false;

node_name = kbasename(np->full_name);
len = strchrnul(node_name, '@') - node_name;

return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);
}

bool of_node_name_prefix(const struct device_node *np, const char *prefix)
{
if (!np)
return false;

return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0;
}

int of_n_addr_cells(struct device_node *np)
{
u32 cells;
Expand Down Expand Up @@ -719,6 +741,31 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
}
EXPORT_SYMBOL(of_get_next_available_child);

/**
* of_get_compatible_child - Find compatible child node
* @parent: parent node
* @compatible: compatible string
*
* Lookup child node whose compatible property contains the given compatible
* string.
*
* Returns a node pointer with refcount incremented, use of_node_put() on it
* when done; or NULL if not found.
*/
struct device_node *of_get_compatible_child(const struct device_node *parent,
const char *compatible)
{
struct device_node *child;

for_each_child_of_node(parent, child) {
if (of_device_is_compatible(child, compatible))
break;
}

return child;
}
EXPORT_SYMBOL(of_get_compatible_child);

/**
* of_get_child_by_name - Find the child node by name for a given parent
* @node: parent node
Expand Down
33 changes: 33 additions & 0 deletions include/linux/of.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)

extern bool of_node_name_eq(const struct device_node *np, const char *name);
extern bool of_node_name_prefix(const struct device_node *np, const char *prefix);

static inline const char *of_node_full_name(const struct device_node *np)
{
return np ? np->full_name : "<no-node>";
Expand Down Expand Up @@ -290,6 +293,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
extern struct device_node *of_get_next_available_child(
const struct device_node *node, struct device_node *prev);

extern struct device_node *of_get_compatible_child(const struct device_node *parent,
const char *compatible);
extern struct device_node *of_get_child_by_name(const struct device_node *node,
const char *name);

Expand Down Expand Up @@ -561,6 +566,16 @@ static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
return NULL;
}

static inline bool of_node_name_eq(const struct device_node *np, const char *name)
{
return false;
}

static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix)
{
return false;
}

static inline const char* of_node_full_name(const struct device_node *np)
{
return "<no-node>";
Expand Down Expand Up @@ -632,6 +647,12 @@ static inline bool of_have_populated_dt(void)
return false;
}

static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
const char *compatible)
{
return NULL;
}

static inline struct device_node *of_get_child_by_name(
const struct device_node *node,
const char *name)
Expand Down Expand Up @@ -967,6 +988,18 @@ static inline struct device_node *of_find_matching_node(
return of_find_matching_node_and_match(from, matches, NULL);
}

static inline const char *of_node_get_device_type(const struct device_node *np)
{
return of_get_property(np, "type", NULL);
}

static inline bool of_node_is_type(const struct device_node *np, const char *type)
{
const char *match = of_node_get_device_type(np);

return np && match && type && !strcmp(match, type);
}

/**
* of_property_count_u8_elems - Count the number of u8 elements in a property
*
Expand Down

0 comments on commit fd6868d

Please sign in to comment.