Skip to content

Commit

Permalink
media: ti-vpe: cal: Use of_graph_get_endpoint_by_regs() to parse OF
Browse files Browse the repository at this point in the history
Replace the manual of_get_next_port() and of_get_next_endpoint()
implementations and the corresponding logic in the caller with a call to
of_graph_get_endpoint_by_regs(). This greatly simplifies OF parsing.

Signed-off-by: Laurent Pinchart <[email protected]>
Reviewed-by: Tomi Valkeinen <[email protected]>
Reviewed-by: Benoit Parrot <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
pinchartl authored and sigmaris committed Aug 8, 2020
1 parent 06447a7 commit 73e2336
Showing 1 changed file with 7 additions and 107 deletions.
114 changes: 7 additions & 107 deletions drivers/media/platform/ti-vpe/cal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2014,125 +2014,26 @@ static const struct v4l2_async_notifier_operations cal_async_ops = {
.complete = cal_async_complete,
};

static struct device_node *
of_get_next_port(const struct device_node *parent,
struct device_node *prev)
{
struct device_node *port;

if (!parent)
return NULL;

if (!prev) {
struct device_node *ports;
/*
* It's the first call, we have to find a port subnode
* within this node or within an optional 'ports' node.
*/
ports = of_get_child_by_name(parent, "ports");
if (ports)
parent = ports;

port = of_get_child_by_name(parent, "port");

/* release the 'ports' node */
of_node_put(ports);
} else {
struct device_node *ports;

ports = of_get_parent(prev);
if (!ports)
return NULL;

do {
port = of_get_next_child(ports, prev);
if (!port) {
of_node_put(ports);
return NULL;
}
prev = port;
} while (!of_node_name_eq(port, "port"));
of_node_put(ports);
}

return port;
}

static struct device_node *
of_get_next_endpoint(const struct device_node *parent,
struct device_node *prev)
{
struct device_node *ep;

if (!parent)
return NULL;

do {
ep = of_get_next_child(parent, prev);
if (!ep)
return NULL;
prev = ep;
} while (!of_node_name_eq(ep, "endpoint"));

return ep;
}

static int of_cal_create_instance(struct cal_ctx *ctx, int inst)
{
struct platform_device *pdev = ctx->cal->pdev;
struct device_node *ep_node, *port, *sensor_node, *parent;
struct device_node *ep_node, *sensor_node;
struct v4l2_fwnode_endpoint *endpoint;
struct v4l2_async_subdev *asd;
u32 regval = 0;
int ret, index, lane;
bool found_port = false;

parent = pdev->dev.of_node;
int ret = -EINVAL, lane;

endpoint = &ctx->phy->endpoint;

ep_node = NULL;
port = NULL;
sensor_node = NULL;
ret = -EINVAL;

ctx_dbg(3, ctx, "Scanning Port node for csi2 port: %d\n", inst);
for (index = 0; index < CAL_NUM_CSI2_PORTS; index++) {
port = of_get_next_port(parent, port);
if (!port) {
ctx_dbg(1, ctx, "No port node found for csi2 port:%d\n",
index);
goto cleanup_exit;
}

/* Match the slice number with <REG> */
of_property_read_u32(port, "reg", &regval);
ctx_dbg(3, ctx, "port:%d inst:%d <reg>:%d\n",
index, inst, regval);
if ((regval == inst) && (index == inst)) {
found_port = true;
break;
}
}

if (!found_port) {
ctx_dbg(1, ctx, "No port node matches csi2 port:%d\n",
inst);
goto cleanup_exit;
}

ctx_dbg(3, ctx, "Scanning sub-device for csi2 port: %d\n",
inst);

ep_node = of_get_next_endpoint(port, ep_node);
ctx_dbg(3, ctx, "Getting endpoint for port@%d\n", inst);
ep_node = of_graph_get_endpoint_by_regs(pdev->dev.of_node, inst, 0);
if (!ep_node) {
ctx_dbg(3, ctx, "can't get next endpoint\n");
goto cleanup_exit;
ctx_dbg(3, ctx, "Can't get endpoint\n");
return -EINVAL;
}

sensor_node = of_graph_get_remote_port_parent(ep_node);
if (!sensor_node) {
ctx_dbg(3, ctx, "can't get remote parent\n");
ctx_dbg(3, ctx, "Can't get remote parent\n");
goto cleanup_exit;
}

Expand Down Expand Up @@ -2193,7 +2094,6 @@ static int of_cal_create_instance(struct cal_ctx *ctx, int inst)
cleanup_exit:
of_node_put(sensor_node);
of_node_put(ep_node);
of_node_put(port);

return ret;
}
Expand Down

0 comments on commit 73e2336

Please sign in to comment.