From f0baa0d6681355442173af43d82575d923958adc Mon Sep 17 00:00:00 2001 From: Marcel Ziswiler Date: Fri, 11 Sep 2020 16:04:07 +0200 Subject: media: mxc mipi csi: fix device tree node order dependency Explicitly get endpoint 1 being the sensor one as using overlays may reverse node order in the final device tree blob. Signed-off-by: Marcel Ziswiler Conflicts: drivers/media/platform/mxc/capture/mxc_mipi_csi.c Signed-off-by: Oleksandr Suvorov (cherry picked from commit ad9b05bd70583805170e27ba98015502fe5517e0) Upstream-status: Inappropriate [NXP downstream camera stack] --- drivers/media/platform/mxc/capture/mxc_mipi_csi.c | 66 ++++++++++++----------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/drivers/media/platform/mxc/capture/mxc_mipi_csi.c b/drivers/media/platform/mxc/capture/mxc_mipi_csi.c index db9101f573cc..ed0b0177b67f 100644 --- a/drivers/media/platform/mxc/capture/mxc_mipi_csi.c +++ b/drivers/media/platform/mxc/capture/mxc_mipi_csi.c @@ -953,9 +953,13 @@ static int mipi_csis_parse_dt(struct platform_device *pdev, &state->max_num_lanes)) return -EINVAL; - node = of_graph_get_next_endpoint(node, NULL); + /* + * Explicitly get endpoint 1 being the sensor one as using overlays may + * reverse node order in the final device tree blob. + */ + node = of_graph_get_endpoint_by_regs(node, 0, 1); if (!node) { - dev_err(&pdev->dev, "No port node at %s\n", + dev_err(&pdev->dev, "No port/endpoint 1 sensor node at %s\n", pdev->dev.of_node->full_name); return -EINVAL; } @@ -987,45 +991,45 @@ static const struct v4l2_async_notifier_operations mxc_mipi_csi_subdev_ops = { static int mipi_csis_subdev_host(struct csi_state *state) { struct device_node *parent = state->dev->of_node; - struct device_node *node, *port, *rem; + struct device_node *node, *rem; struct v4l2_async_subdev *asd; int ret; v4l2_async_notifier_init(&state->subdev_notifier); - /* Attach sensors linked to csi receivers */ - for_each_available_child_of_node(parent, node) { - if (of_node_cmp(node->name, "port")) - continue; - - /* The csi node can have only port subnode. */ - port = of_get_next_child(node, NULL); - if (!port) - continue; - rem = of_graph_get_remote_port_parent(port); - of_node_put(port); - if (rem == NULL) { - v4l2_info(&state->v4l2_dev, - "Remote device at %s not found\n", - port->full_name); - return -1; - } + /* + * Explicitly get endpoint 1 being the sensor one as using overlays may + * reverse node order in the final device tree blob. + */ + node = of_graph_get_endpoint_by_regs(parent, 0, 1); + if (node == NULL) { + v4l2_info(&state->v4l2_dev, + "Port at %s not found\n", + parent->full_name); + return -1; + } - state->fwnode = of_fwnode_handle(rem); - asd = v4l2_async_notifier_add_fwnode_subdev( - &state->subdev_notifier, - state->fwnode, - struct v4l2_async_subdev); - if (IS_ERR(asd)) { - of_node_put(rem); - dev_err(state->dev, "failed to add subdev to a notifier\n"); - return PTR_ERR(asd); - } + rem = of_graph_get_remote_port_parent(node); + of_node_put(node); + if (rem == NULL) { + v4l2_info(&state->v4l2_dev, + "Remote device at %s not found\n", + node->full_name); + return -1; + } + state->fwnode = of_fwnode_handle(rem); + asd = v4l2_async_notifier_add_fwnode_subdev( + &state->subdev_notifier, + state->fwnode, + struct v4l2_async_subdev); + if (IS_ERR(asd)) { of_node_put(rem); - break; + dev_err(state->dev, "failed to add subdev to a notifier\n"); + return PTR_ERR(asd); } + of_node_put(rem); state->subdev_notifier.v4l2_dev = &state->v4l2_dev; state->subdev_notifier.ops = &mxc_mipi_csi_subdev_ops; -- cgit v1.2.3