From patchwork Tue Mar 17 18:07:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11443699 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E83B1874 for ; Tue, 17 Mar 2020 18:07:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47ADD20754 for ; Tue, 17 Mar 2020 18:07:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726789AbgCQSHM (ORCPT ); Tue, 17 Mar 2020 14:07:12 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35336 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726762AbgCQSHM (ORCPT ); Tue, 17 Mar 2020 14:07:12 -0400 Received: from localhost.localdomain (unknown [IPv6:2a02:810a:113f:ad1c:f038:27d4:2beb:6e6b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 8FB1D29430C; Tue, 17 Mar 2020 18:07:10 +0000 (GMT) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, mchehab@kernel.org, laurent.pinchart@ideasonboard.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org Subject: [PATCH v3 2/2] media: staging: rkisp1: replace the call to v4l2_async_notifier_parse_fwnode_endpoints_by_port Date: Tue, 17 Mar 2020 19:07:01 +0100 Message-Id: <20200317180701.6035-3-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200317180701.6035-1-dafna.hirschfeld@collabora.com> References: <20200317180701.6035-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org don't call 'v4l2_async_notifier_parse_fwnode_endpoints_by_port' in order to register async subdevices. Instead call 'v4l2_fwnode_endpoint_parse' to parse the remote endpoints and then register each async subdev with 'v4l2_async_notifier_add_fwnode_remote_subdev' Also remove the relevant item in the TODO file Signed-off-by: Dafna Hirschfeld Acked-by: Helen Koike --- changes since v1: in the function rkisp1_subdev_notifier: 1. move the test 'if (next_id == 0)' outside of the while loop 2. remove the 'end' label. The changes are due to Helen Koike's comments changes since v2: in the function rkisp1_subdev_notifier: 1. remove a newline between a call to fwnode_graph_get_endpoint_by_id to the test of its ret value 2. define 'next_id' as 'unsigned int' instead of 'int' 3. rename 'parallel_bus_flags' to 'mbus_flags' and set it to vep.bus.mipi_csi2.flags instead of 0 (this follows previous patch of the series) 4. when no remote sensor is found, log it with dev_dbg instead of dev_warn drivers/staging/media/rkisp1/TODO | 3 - drivers/staging/media/rkisp1/rkisp1-dev.c | 90 +++++++++++++---------- 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/drivers/staging/media/rkisp1/TODO b/drivers/staging/media/rkisp1/TODO index 0aa9877dd64a..1aa3bb9fd6cb 100644 --- a/drivers/staging/media/rkisp1/TODO +++ b/drivers/staging/media/rkisp1/TODO @@ -1,6 +1,3 @@ -* Don't use v4l2_async_notifier_parse_fwnode_endpoints_by_port(). -e.g. isp_parse_of_endpoints in drivers/media/platform/omap3isp/isp.c -cio2_parse_firmware in drivers/media/pci/intel/ipu3/ipu3-cio2.c. * Fix pad format size for statistics and parameters entities. * Use threaded interrupt for rkisp1_stats_isr(), remove work queue. * Fix checkpatch errors. diff --git a/drivers/staging/media/rkisp1/rkisp1-dev.c b/drivers/staging/media/rkisp1/rkisp1-dev.c index fcd2a3a4cc78..2eedabab4044 100644 --- a/drivers/staging/media/rkisp1/rkisp1-dev.c +++ b/drivers/staging/media/rkisp1/rkisp1-dev.c @@ -233,33 +233,6 @@ static int rkisp1_subdev_notifier_complete(struct v4l2_async_notifier *notifier) return 0; } -static int rkisp1_fwnode_parse(struct device *dev, - struct v4l2_fwnode_endpoint *vep, - struct v4l2_async_subdev *asd) -{ - struct rkisp1_sensor_async *s_asd = - container_of(asd, struct rkisp1_sensor_async, asd); - - if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) { - dev_err(dev, "Only CSI2 bus type is currently supported\n"); - return -EINVAL; - } - - if (vep->base.port != 0) { - dev_err(dev, "The ISP has only port 0\n"); - return -EINVAL; - } - - s_asd->mbus_type = vep->bus_type; - s_asd->mbus_flags = vep->bus.mipi_csi2.flags; - s_asd->lanes = vep->bus.mipi_csi2.num_data_lanes; - - if (s_asd->lanes < 1 || s_asd->lanes > 4) - return -EINVAL; - - return 0; -} - static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops = { .bound = rkisp1_subdev_notifier_bound, .unbind = rkisp1_subdev_notifier_unbind, @@ -269,23 +242,66 @@ static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops = static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1) { struct v4l2_async_notifier *ntf = &rkisp1->notifier; - struct device *dev = rkisp1->dev; + unsigned int next_id = 0; int ret; v4l2_async_notifier_init(ntf); - ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(dev, ntf, - sizeof(struct rkisp1_sensor_async), - 0, rkisp1_fwnode_parse); - if (ret) - return ret; + while (1) { + struct v4l2_fwnode_endpoint vep = { + .bus_type = V4L2_MBUS_CSI2_DPHY + }; + struct rkisp1_sensor_async *rk_asd = NULL; + struct fwnode_handle *ep; - if (list_empty(&ntf->asd_list)) - return -ENODEV; + ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(rkisp1->dev), + 0, next_id, FWNODE_GRAPH_ENDPOINT_NEXT); + if (!ep) + break; - ntf->ops = &rkisp1_subdev_notifier_ops; + ret = v4l2_fwnode_endpoint_parse(ep, &vep); + if (ret) + goto err_parse; - return v4l2_async_notifier_register(&rkisp1->v4l2_dev, ntf); + rk_asd = kzalloc(sizeof(*rk_asd), GFP_KERNEL); + if (!rk_asd) { + ret = -ENOMEM; + goto err_parse; + } + + rk_asd->mbus_type = vep.bus_type; + rk_asd->mbus_flags = vep.bus.mipi_csi2.flags; + rk_asd->lanes = vep.bus.mipi_csi2.num_data_lanes; + + ret = v4l2_async_notifier_add_fwnode_remote_subdev(ntf, ep, + &rk_asd->asd); + if (ret) + goto err_parse; + + dev_dbg(rkisp1->dev, "registered ep id %d with %d lanes\n", + vep.base.id, rk_asd->lanes); + + next_id = vep.base.id + 1; + + fwnode_handle_put(ep); + + continue; +err_parse: + fwnode_handle_put(ep); + kfree(rk_asd); + v4l2_async_notifier_cleanup(ntf); + return ret; + } + + if (next_id == 0) + dev_dbg(rkisp1->dev, "no remote subdevice found\n"); + ntf->ops = &rkisp1_subdev_notifier_ops; + ret = v4l2_async_notifier_register(&rkisp1->v4l2_dev, ntf); + if (ret) { + v4l2_async_notifier_cleanup(ntf); + return ret; + } + return 0; } /* ----------------------------------------------------------------------------