1
0
Fork 0

of: Add of-graph helpers to loop over endpoints and find ports by id

This series converts of_graph_get_next_endpoint to decrement the refcount of
 the passed prev parameter. This allows to add a for_each_endpoint_of_node
 helper macro to loop over all endpoints in a device tree node.
 The of_graph_get_port_by_id function is added to retrieve a port by its known
 port id (contained in the reg property) from the device tree.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJU9Vn9AAoJEFDCiBxwnmDriPMP/2Bzx7kYdRkTFICqGsITHcUf
 pjMEf7htHdg+lFn6jBYtLW42NqZMX+kI1BIpd6RzEjKxAhbp0tr7FVwn0Kds2rQw
 6ikwtZsd6oBR61Xv0sZWMwNbfn2MUcl7M9k+Sh6kDUBph5IEMZ5F+n8dRYHhA+MH
 rs9PGTH2DmRE1HXvWBjsE8QVgfia4WRp5OipDkOxNhCpkbzU4XqbVoBh/6BmJ54R
 Dxq3srM479CyRY3o4+KT4ajhS7g4aU7WTQMxIXtU0cLcYMvfkcHoYwNBw+bjSn3s
 eYfjpw96XHhS4abVzo8QziN1oNV/i/Y4wpqIOKwY5TnA+Gt+sEnFXjGHa331QdpL
 WdisAQg/6MFPlR4D7gkBWEjoeeMn4FkyiFSHntYclywOxv/Cbc/l1cOyPkS3zxIa
 v6KH7zu5J83sICx8TlZv0YLnES1GtixCuWukaKzyLiAXqHVGullkBvUauQwRrtEW
 73CjIGpCTQMY5xmt/8V8JFi1HQLbDBRlHkX2WOzcrByLLgiGaUeKRvjYcYtaBm7q
 Q25E10lnW3cGf+kljlPfc3NVxgtQUGaQKsx+wzICnz6h+0gdEzsTcAWB3Qp891jX
 q+RSqEsT93oSAhPxJYQGvEu4wPfmOrh7QvProwj8mR1Jp6TyvgGi9pOtHU+YwOz+
 EZD+c6mhdOfuWgD8GqT/
 =jtB3
 -----END PGP SIGNATURE-----

Merge tag 'of-graph-for-4.0' of git://git.pengutronix.de/git/pza/linux into for-next

Pull of-graph helpers from Philipp Zabel:
of: Add of-graph helpers to loop over endpoints and find ports by id

This series converts of_graph_get_next_endpoint to decrement the refcount of
the passed prev parameter. This allows to add a for_each_endpoint_of_node
helper macro to loop over all endpoints in a device tree node.
The of_graph_get_port_by_id function is added to retrieve a port by its known
port id (contained in the reg property) from the device tree.
wifi-calibration
Rob Herring 2015-03-25 00:41:08 -05:00
commit 8147e2e8f1
8 changed files with 61 additions and 48 deletions

View File

@ -52,15 +52,6 @@ of_coresight_get_endpoint_device(struct device_node *endpoint)
endpoint, of_dev_node_match);
}
static struct device_node *of_get_coresight_endpoint(
const struct device_node *parent, struct device_node *prev)
{
struct device_node *node = of_graph_get_next_endpoint(parent, prev);
of_node_put(prev);
return node;
}
static void of_coresight_get_ports(struct device_node *node,
int *nr_inport, int *nr_outport)
{
@ -68,7 +59,7 @@ static void of_coresight_get_ports(struct device_node *node,
int in = 0, out = 0;
do {
ep = of_get_coresight_endpoint(node, ep);
ep = of_graph_get_next_endpoint(node, ep);
if (!ep)
break;
@ -140,7 +131,7 @@ struct coresight_platform_data *of_get_coresight_platform_data(
/* Iterate through each port to discover topology */
do {
/* Get a handle on a port */
ep = of_get_coresight_endpoint(node, ep);
ep = of_graph_get_next_endpoint(node, ep);
if (!ep)
break;

View File

@ -431,15 +431,6 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,
}
EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of);
static struct device_node *imx_drm_of_get_next_endpoint(
const struct device_node *parent, struct device_node *prev)
{
struct device_node *node = of_graph_get_next_endpoint(parent, prev);
of_node_put(prev);
return node;
}
/*
* @node: device tree node containing encoder input ports
* @encoder: drm_encoder
@ -457,7 +448,7 @@ int imx_drm_encoder_get_mux_id(struct device_node *node,
return -EINVAL;
do {
ep = imx_drm_of_get_next_endpoint(node, ep);
ep = of_graph_get_next_endpoint(node, ep);
if (!ep)
break;

View File

@ -206,7 +206,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
enum rcar_du_encoder_type enc_type = RCAR_DU_ENCODER_NONE;
struct device_node *connector = NULL;
struct device_node *encoder = NULL;
struct device_node *prev = NULL;
struct device_node *ep_node = NULL;
struct device_node *entity_ep_node;
struct device_node *entity;
int ret;
@ -225,11 +225,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
entity_ep_node = of_parse_phandle(ep->local_node, "remote-endpoint", 0);
while (1) {
struct device_node *ep_node;
ep_node = of_graph_get_next_endpoint(entity, prev);
of_node_put(prev);
prev = ep_node;
ep_node = of_graph_get_next_endpoint(entity, ep_node);
if (!ep_node)
break;
@ -300,7 +296,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
{
struct device_node *np = rcdu->dev->of_node;
struct device_node *prev = NULL;
struct device_node *ep_node = NULL;
unsigned int num_encoders = 0;
/*
@ -308,15 +304,12 @@ static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
* pipeline.
*/
while (1) {
struct device_node *ep_node;
enum rcar_du_output output;
struct of_endpoint ep;
unsigned int i;
int ret;
ep_node = of_graph_get_next_endpoint(np, prev);
of_node_put(prev);
prev = ep_node;
ep_node = of_graph_get_next_endpoint(np, ep_node);
if (ep_node == NULL)
break;

View File

@ -2504,7 +2504,6 @@ vpfe_get_pdata(struct platform_device *pdev)
GFP_KERNEL);
pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_OF;
pdata->asd[i]->match.of.node = rem;
of_node_put(endpoint);
of_node_put(rem);
}

View File

@ -1694,7 +1694,6 @@ static void scan_of_host(struct soc_camera_host *ici)
if (!i)
soc_of_bind(ici, epn, ren->parent);
of_node_put(epn);
of_node_put(ren);
if (i) {
@ -1702,6 +1701,8 @@ static void scan_of_host(struct soc_camera_host *ici)
break;
}
}
of_node_put(epn);
}
#else

View File

@ -2082,14 +2082,45 @@ int of_graph_parse_endpoint(const struct device_node *node,
}
EXPORT_SYMBOL(of_graph_parse_endpoint);
/**
* of_graph_get_port_by_id() - get the port matching a given id
* @parent: pointer to the parent device node
* @id: id of the port
*
* Return: A 'port' node pointer with refcount incremented. The caller
* has to use of_node_put() on it when done.
*/
struct device_node *of_graph_get_port_by_id(struct device_node *parent, u32 id)
{
struct device_node *node, *port;
node = of_get_child_by_name(parent, "ports");
if (node)
parent = node;
for_each_child_of_node(parent, port) {
u32 port_id = 0;
if (of_node_cmp(port->name, "port") != 0)
continue;
of_property_read_u32(port, "reg", &port_id);
if (id == port_id)
break;
}
of_node_put(node);
return port;
}
EXPORT_SYMBOL(of_graph_get_port_by_id);
/**
* of_graph_get_next_endpoint() - get next endpoint node
* @parent: pointer to the parent device node
* @prev: previous endpoint node, or NULL to get first
*
* Return: An 'endpoint' node pointer with refcount incremented. Refcount
* of the passed @prev node is not decremented, the caller have to use
* of_node_put() on it when done.
* of the passed @prev node is decremented.
*/
struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
struct device_node *prev)
@ -2125,12 +2156,6 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n",
__func__, prev->full_name))
return NULL;
/*
* Avoid dropping prev node refcount to 0 when getting the next
* child below.
*/
of_node_get(prev);
}
while (1) {

View File

@ -164,20 +164,15 @@ static void __init omapdss_walk_device(struct device_node *node, bool root)
pn = of_graph_get_remote_port_parent(n);
if (!pn) {
of_node_put(n);
if (!pn)
continue;
}
if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
of_node_put(pn);
of_node_put(n);
continue;
}
omapdss_walk_device(pn, false);
of_node_put(n);
}
}

View File

@ -26,9 +26,21 @@ struct of_endpoint {
const struct device_node *local_node;
};
/**
* for_each_endpoint_of_node - iterate over every endpoint in a device node
* @parent: parent device node containing ports and endpoints
* @child: loop variable pointing to the current endpoint node
*
* When breaking out of the loop, of_node_put(child) has to be called manually.
*/
#define for_each_endpoint_of_node(parent, child) \
for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \
child = of_graph_get_next_endpoint(parent, child))
#ifdef CONFIG_OF
int of_graph_parse_endpoint(const struct device_node *node,
struct of_endpoint *endpoint);
struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id);
struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
struct device_node *previous);
struct device_node *of_graph_get_remote_port_parent(
@ -42,6 +54,12 @@ static inline int of_graph_parse_endpoint(const struct device_node *node,
return -ENOSYS;
}
static inline struct device_node *of_graph_get_port_by_id(
struct device_node *node, u32 id)
{
return NULL;
}
static inline struct device_node *of_graph_get_next_endpoint(
const struct device_node *parent,
struct device_node *previous)