Skip to content

Commit

Permalink
Merge branch 'robherring/for-next' from git://sources.calxeda.com/ker…
Browse files Browse the repository at this point in the history
…nel/linux.git

Signed-off-by: Grant Likely <[email protected]>
  • Loading branch information
glikely committed Feb 8, 2013
2 parents 12514aa + eb7ccb8 commit d2f4ec1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Documentation/devicetree/bindings/vendor-prefixes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bosch Bosch Sensortec GmbH
brcm Broadcom Corporation
cavium Cavium, Inc.
chrp Common Hardware Reference Platform
cirrus Cirrus Logic, Inc.
cortina Cortina Systems, Inc.
dallas Maxim Integrated Products (formerly Dallas Semiconductor)
denx Denx Software Engineering
Expand Down Expand Up @@ -42,6 +43,7 @@ powervr PowerVR (deprecated, use img)
qcom Qualcomm, Inc.
ramtron Ramtron International
realtek Realtek Semiconductor Corp.
renesas Renesas Electronics Corporation
samsung Samsung Semiconductor
sbs Smart Battery System
schindler Schindler
Expand All @@ -52,6 +54,7 @@ snps Synopsys, Inc.
st STMicroelectronics
stericsson ST-Ericsson
ti Texas Instruments
toshiba Toshiba Corporation
via VIA Technologies, Inc.
wlf Wolfson Microelectronics
wm Wondermedia Technologies, Inc.
Expand Down
95 changes: 73 additions & 22 deletions drivers/of/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,33 @@ void of_node_put(struct device_node *node)
EXPORT_SYMBOL(of_node_put);
#endif /* CONFIG_OF_DYNAMIC */

struct property *of_find_property(const struct device_node *np,
const char *name,
int *lenp)
static struct property *__of_find_property(const struct device_node *np,
const char *name, int *lenp)
{
struct property *pp;

if (!np)
return NULL;

read_lock(&devtree_lock);
for (pp = np->properties; pp; pp = pp->next) {
if (of_prop_cmp(pp->name, name) == 0) {
if (lenp)
*lenp = pp->length;
break;
}
}

return pp;
}

struct property *of_find_property(const struct device_node *np,
const char *name,
int *lenp)
{
struct property *pp;

read_lock(&devtree_lock);
pp = __of_find_property(np, name, lenp);
read_unlock(&devtree_lock);

return pp;
Expand Down Expand Up @@ -193,12 +203,24 @@ struct device_node *of_find_all_nodes(struct device_node *prev)
}
EXPORT_SYMBOL(of_find_all_nodes);

/*
* Find a property with a given name for a given node
* and return the value.
*/
static const void *__of_get_property(const struct device_node *np,
const char *name, int *lenp)
{
struct property *pp = __of_find_property(np, name, lenp);

return pp ? pp->value : NULL;
}

/*
* Find a property with a given name for a given node
* and return the value.
*/
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp)
int *lenp)
{
struct property *pp = of_find_property(np, name, lenp);

Expand All @@ -209,13 +231,13 @@ EXPORT_SYMBOL(of_get_property);
/** Checks if the given "compat" string matches one of the strings in
* the device's "compatible" property
*/
int of_device_is_compatible(const struct device_node *device,
const char *compat)
static int __of_device_is_compatible(const struct device_node *device,
const char *compat)
{
const char* cp;
int cplen, l;

cp = of_get_property(device, "compatible", &cplen);
cp = __of_get_property(device, "compatible", &cplen);
if (cp == NULL)
return 0;
while (cplen > 0) {
Expand All @@ -228,6 +250,20 @@ int of_device_is_compatible(const struct device_node *device,

return 0;
}

/** Checks if the given "compat" string matches one of the strings in
* the device's "compatible" property
*/
int of_device_is_compatible(const struct device_node *device,
const char *compat)
{
int res;

read_lock(&devtree_lock);
res = __of_device_is_compatible(device, compat);
read_unlock(&devtree_lock);
return res;
}
EXPORT_SYMBOL(of_device_is_compatible);

/**
Expand Down Expand Up @@ -501,7 +537,8 @@ struct device_node *of_find_compatible_node(struct device_node *from,
if (type
&& !(np->type && (of_node_cmp(np->type, type) == 0)))
continue;
if (of_device_is_compatible(np, compatible) && of_node_get(np))
if (__of_device_is_compatible(np, compatible) &&
of_node_get(np))
break;
}
of_node_put(from);
Expand Down Expand Up @@ -545,15 +582,9 @@ struct device_node *of_find_node_with_property(struct device_node *from,
}
EXPORT_SYMBOL(of_find_node_with_property);

/**
* of_match_node - Tell if an device_node has a matching of_match structure
* @matches: array of of device match structures to search in
* @node: the of device structure to match against
*
* Low level utility function used by device matching.
*/
const struct of_device_id *of_match_node(const struct of_device_id *matches,
const struct device_node *node)
static
const struct of_device_id *__of_match_node(const struct of_device_id *matches,
const struct device_node *node)
{
if (!matches)
return NULL;
Expand All @@ -567,14 +598,32 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
match &= node->type
&& !strcmp(matches->type, node->type);
if (matches->compatible[0])
match &= of_device_is_compatible(node,
matches->compatible);
match &= __of_device_is_compatible(node,
matches->compatible);
if (match)
return matches;
matches++;
}
return NULL;
}

/**
* of_match_node - Tell if an device_node has a matching of_match structure
* @matches: array of of device match structures to search in
* @node: the of device structure to match against
*
* Low level utility function used by device matching.
*/
const struct of_device_id *of_match_node(const struct of_device_id *matches,
const struct device_node *node)
{
const struct of_device_id *match;

read_lock(&devtree_lock);
match = __of_match_node(matches, node);
read_unlock(&devtree_lock);
return match;
}
EXPORT_SYMBOL(of_match_node);

/**
Expand All @@ -595,16 +644,18 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from,
const struct of_device_id **match)
{
struct device_node *np;
const struct of_device_id *m;

if (match)
*match = NULL;

read_lock(&devtree_lock);
np = from ? from->allnext : of_allnodes;
for (; np; np = np->allnext) {
if (of_match_node(matches, np) && of_node_get(np)) {
m = __of_match_node(matches, np);
if (m && of_node_get(np)) {
if (match)
*match = matches;
*match = m;
break;
}
}
Expand Down

0 comments on commit d2f4ec1

Please sign in to comment.