From patchwork Tue Mar 3 23:42:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 210754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BA87C3F2D7 for ; Tue, 3 Mar 2020 23:43:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 11D862072D for ; Tue, 3 Mar 2020 23:43:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rK+ilurY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728367AbgCCXnJ (ORCPT ); Tue, 3 Mar 2020 18:43:09 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:34422 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727429AbgCCXnJ (ORCPT ); Tue, 3 Mar 2020 18:43:09 -0500 Received: by mail-pj1-f65.google.com with SMTP id f2so1741949pjq.1 for ; Tue, 03 Mar 2020 15:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WldNcB0ZUA0C59QCiXBTJolDLh/hIPr21BH76I/kQ7w=; b=rK+ilurYTS4QXIMl2Auhh3YRLUyZuHvy2RJp4hDUJ7tFNlr7rVcvnPY2M5VTw3oFlI m+glKgc4RNh1xMq+4Au06SSInC7Azs/qparoYonPaqmgnEMzcAiygKkKwcnWCRYtHSH7 UFu6y3jifftx1IhrsBH0ysmIyf0jUlhe4ii3JWxxwRe1KI+dF5yMecn9QdWLmRK8dVW9 bT2uv0PyCy61rmlZ96ecnH+xPCruJpXKJI5WC22TqY3LX7r81AEY8nWt7gX5LbPWFRWP KPsnpfVQqBsWz5X+zu1hNPpjBcyUrWSC08bQtAIHkcdJHWr98F38BRXN51MJ/8V30W2h 8dQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WldNcB0ZUA0C59QCiXBTJolDLh/hIPr21BH76I/kQ7w=; b=cdDpWj4rOb8SIVm1Agq346VXzDxKeknto0hTw/KZIpxVev5IQJtXjCjCchWbyxDP7s TrBwpI8ioGmHJC8zmobiFryvN4muhMPwui/Zg/JRoWbr2n777sJh8bB2cHBdlyuX+1I5 shdbFl2FPz8eQlTCiiL50RexMCAy+Z5OPE3pE2HthACUoZrBhIxG3Y3Il57HG7RxEwHU A8BSh0fFD3mjcWRlVYA9h+NTCL4XcHpzqwG9Vrpr4uZeRm0WvwV0R1l9XFDh3PNmR0tl ZL4pS5GQALNy7XmXKNkzsXVKz4cWjHHdJjonom8+rMjEt0ImL/F66ba3tM1Hb5RrvXOg YPUA== X-Gm-Message-State: ANhLgQ3wcFXiWYLGq9z1FOLdxjNQeWSfgcLkolevYk5SaVKw7nHeuvI4 WiyVOf5LrX7W2m34R0oTy3NVWLMtV/A= X-Google-Smtp-Source: ADFU+vsnhd0rxsOU4JcKZRKdtpxxMNk6q8qNC6NWUKfhvmo8KqSKiQvbs3PpJdaiQRHJn0Kjiw2+hQ== X-Received: by 2002:a17:90a:d103:: with SMTP id l3mr17666pju.91.1583278988125; Tue, 03 Mar 2020 15:43:08 -0800 (PST) Received: from mappy.sklembedded.com ([2605:e000:d445:6a00:8145:3904:f092:dd35]) by smtp.gmail.com with ESMTPSA id q66sm23540009pgq.50.2020.03.03.15.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:43:07 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Subject: [PATCH v4 01/17] media: entity: Pass entity to get_fwnode_pad operation Date: Tue, 3 Mar 2020 15:42:40 -0800 Message-Id: <20200303234256.8928-2-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303234256.8928-1-slongerbeam@gmail.com> References: <20200303234256.8928-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a missing pointer to the entity in the media_entity operation get_fwnode_pad. There are no implementers of this op yet, but a future entity that does so will almost certainly need a reference to itself to carry out the work. Fixes: ae45cd5efc120 ("[media] media: entity: Add get_fwnode_pad entity operation") Signed-off-by: Steve Longerbeam --- drivers/media/mc/mc-entity.c | 2 +- include/media/media-entity.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c index 211279c5fd77..12b45e669bcc 100644 --- a/drivers/media/mc/mc-entity.c +++ b/drivers/media/mc/mc-entity.c @@ -386,7 +386,7 @@ int media_entity_get_fwnode_pad(struct media_entity *entity, if (ret) return ret; - ret = entity->ops->get_fwnode_pad(&endpoint); + ret = entity->ops->get_fwnode_pad(entity, &endpoint); if (ret < 0) return ret; diff --git a/include/media/media-entity.h b/include/media/media-entity.h index 8cb2c504a05c..cde80ad029b7 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -212,7 +212,8 @@ struct media_pad { * mutex held. */ struct media_entity_operations { - int (*get_fwnode_pad)(struct fwnode_endpoint *endpoint); + int (*get_fwnode_pad)(struct media_entity *entity, + struct fwnode_endpoint *endpoint); int (*link_setup)(struct media_entity *entity, const struct media_pad *local, const struct media_pad *remote, u32 flags); From patchwork Tue Mar 3 23:42:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 210753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8602C3F2C6 for ; Tue, 3 Mar 2020 23:43:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7DE952072D for ; Tue, 3 Mar 2020 23:43:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OOBOylkb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728389AbgCCXnO (ORCPT ); Tue, 3 Mar 2020 18:43:14 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40398 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727429AbgCCXnN (ORCPT ); Tue, 3 Mar 2020 18:43:13 -0500 Received: by mail-pg1-f194.google.com with SMTP id t24so57035pgj.7 for ; Tue, 03 Mar 2020 15:43:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ayKqejKOnrvGn3Gt6KUwE9Eg6tbKPqBovfizospOrd0=; b=OOBOylkbTY76ulbBqhazf07EkfIFRkMiFdCxWzSBqvcxpI/vQ+Nbkwzov7mqeuLZXd emMoZQo7+NiWQJsGxu8jl6Oim2MAo2kGrPb6L70A7b58IctqZKMCnNhMOXMX3c5070J4 L9Vo4OUSWjMJGqkCw0dzozVmgZ6w7Z+M1OFX9yfPYfFPp1Bd4KnvgIdLnrNp5j8CHHNj sYL6NfPWo+f9eNR2BPV/6F1ZsrSRLi4HrUJx65b4VyMgTXlrnYIctCdpX18KOfaY/LKp E4bMEhkgo0bx2S60pKc/VSlWhOUAHS0/Xip+6EzTM8ebqtdzOn9KBWb6I4UWoG3mpl4C QuXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ayKqejKOnrvGn3Gt6KUwE9Eg6tbKPqBovfizospOrd0=; b=t6hs0JRcYWxsqQV2hDCxhtVv8/wx63ManquyQG5omhL5hxu8FoRadCCkSKsZPhwpjq bqBpD1q+IJrH9BNs63VPYig+VbDv2W7CpAl07V4kB3+bIEyUBeOii1IPmOyWsjFPDzyp 8pXg0SL4AH/O2nV0GlJgvg8t4hopBpAPQKb8Y5hdkcZFxb7pqS/+MuOGOER0VYHyI0dW o2sxV3HUJ/x82mW6VrwTb6zlwTQpRzG7hjTzj6nF3KyVO2f1taISNnYPBhJk3VgaPsui ZrJBn2t8oHK6g5q6q2vqQ9f9KHtTyE++dyG6VOMSIgscRpbXmTtsrtIUGLBMvRxYErZ5 yCag== X-Gm-Message-State: ANhLgQ3CqZQcUse49y0jt1P58AYPlXlKL7JjcN2SEbXAbdapUiTv8OA1 vIp/jbuzIGDe0yA3YUEMFoIItPre9fQ= X-Google-Smtp-Source: ADFU+vu1IFdWOhwJZwGNrZW7TpR6lqcWisNnwMk8kU/NVMCNFg8IQr7kBkIuAf1OZF+3OEdz0S2+Dw== X-Received: by 2002:aa7:8755:: with SMTP id g21mr221318pfo.36.1583278991742; Tue, 03 Mar 2020 15:43:11 -0800 (PST) Received: from mappy.sklembedded.com ([2605:e000:d445:6a00:8145:3904:f092:dd35]) by smtp.gmail.com with ESMTPSA id q66sm23540009pgq.50.2020.03.03.15.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:43:11 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Subject: [PATCH v4 03/17] media: imx: Parse information from firmware without using callbacks Date: Tue, 3 Mar 2020 15:42:42 -0800 Message-Id: <20200303234256.8928-4-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303234256.8928-1-slongerbeam@gmail.com> References: <20200303234256.8928-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Instead of using the convenience functions v4l2_async_notifier_parse_fwnode_endpoints*() or v4l2_async_register_fwnode_subdev(), parse the input endpoints and set up the async sub-devices without using callbacks. The drivers know which ports it must parse and how to handle unconnected remotes, so it makes the code simpler to transfer control of endpoint parsing to the driver. Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-media-csi.c | 78 +++++++++---------- drivers/staging/media/imx/imx6-mipi-csi2.c | 70 ++++++++++++----- drivers/staging/media/imx/imx7-media-csi.c | 53 ++++++++++--- drivers/staging/media/imx/imx7-mipi-csis.c | 91 +++++++++++++++------- 4 files changed, 192 insertions(+), 100 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index b60ed4f22f6d..f409fca88dcf 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -58,6 +58,8 @@ struct csi_priv { struct ipu_soc *ipu; struct v4l2_subdev sd; struct media_pad pad[CSI_NUM_PADS]; + struct v4l2_async_notifier notifier; + /* the video device at IDMAC output pad */ struct imx_media_video_dev *vdev; struct imx_media_fim *fim; @@ -1864,59 +1866,49 @@ static const struct v4l2_subdev_internal_ops csi_internal_ops = { .unregistered = csi_unregistered, }; -static int imx_csi_parse_endpoint(struct device *dev, - struct v4l2_fwnode_endpoint *vep, - struct v4l2_async_subdev *asd) -{ - return fwnode_device_is_available(asd->match.fwnode) ? 0 : -ENOTCONN; -} - static int imx_csi_async_register(struct csi_priv *priv) { - struct v4l2_async_notifier *notifier; - struct fwnode_handle *fwnode; + struct v4l2_async_subdev *asd = NULL; + struct fwnode_handle *ep; unsigned int port; int ret; - notifier = kzalloc(sizeof(*notifier), GFP_KERNEL); - if (!notifier) - return -ENOMEM; - - v4l2_async_notifier_init(notifier); - - fwnode = dev_fwnode(priv->dev); + v4l2_async_notifier_init(&priv->notifier); /* get this CSI's port id */ - ret = fwnode_property_read_u32(fwnode, "reg", &port); - if (ret < 0) - goto out_free; - - ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port( - priv->dev->parent, notifier, sizeof(struct v4l2_async_subdev), - port, imx_csi_parse_endpoint); + ret = fwnode_property_read_u32(dev_fwnode(priv->dev), "reg", &port); if (ret < 0) - goto out_cleanup; + return ret; - ret = v4l2_async_subdev_notifier_register(&priv->sd, notifier); - if (ret < 0) - goto out_cleanup; + ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(priv->dev->parent), + port, 0, + FWNODE_GRAPH_ENDPOINT_NEXT); + if (ep) { + asd = kzalloc(sizeof(*asd), GFP_KERNEL); + if (!asd) { + fwnode_handle_put(ep); + return -ENOMEM; + } - ret = v4l2_async_register_subdev(&priv->sd); - if (ret < 0) - goto out_unregister; + ret = v4l2_async_notifier_add_fwnode_remote_subdev( + &priv->notifier, ep, asd); - priv->sd.subdev_notifier = notifier; + fwnode_handle_put(ep); - return 0; + if (ret) { + kfree(asd); + /* OK if asd already exists */ + if (ret != -EEXIST) + return ret; + } + } -out_unregister: - v4l2_async_notifier_unregister(notifier); -out_cleanup: - v4l2_async_notifier_cleanup(notifier); -out_free: - kfree(notifier); + ret = v4l2_async_subdev_notifier_register(&priv->sd, + &priv->notifier); + if (ret) + return ret; - return ret; + return v4l2_async_register_subdev(&priv->sd); } static int imx_csi_probe(struct platform_device *pdev) @@ -1996,9 +1988,13 @@ static int imx_csi_probe(struct platform_device *pdev) ret = imx_csi_async_register(priv); if (ret) - goto free; + goto cleanup; return 0; + +cleanup: + v4l2_async_notifier_unregister(&priv->notifier); + v4l2_async_notifier_cleanup(&priv->notifier); free: v4l2_ctrl_handler_free(&priv->ctrl_hdlr); mutex_destroy(&priv->lock); @@ -2012,6 +2008,8 @@ static int imx_csi_remove(struct platform_device *pdev) v4l2_ctrl_handler_free(&priv->ctrl_hdlr); mutex_destroy(&priv->lock); + v4l2_async_notifier_unregister(&priv->notifier); + v4l2_async_notifier_cleanup(&priv->notifier); v4l2_async_unregister_subdev(sd); media_entity_cleanup(&sd->entity); diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c index cd3dd6e33ef0..fdd763587e6c 100644 --- a/drivers/staging/media/imx/imx6-mipi-csi2.c +++ b/drivers/staging/media/imx/imx6-mipi-csi2.c @@ -35,6 +35,7 @@ struct csi2_dev { struct device *dev; struct v4l2_subdev sd; + struct v4l2_async_notifier notifier; struct media_pad pad[CSI2_NUM_PADS]; struct clk *dphy_clk; struct clk *pllref_clk; @@ -530,34 +531,59 @@ static const struct v4l2_subdev_internal_ops csi2_internal_ops = { .registered = csi2_registered, }; -static int csi2_parse_endpoint(struct device *dev, - struct v4l2_fwnode_endpoint *vep, - struct v4l2_async_subdev *asd) +static int csi2_async_register(struct csi2_dev *csi2) { - struct v4l2_subdev *sd = dev_get_drvdata(dev); - struct csi2_dev *csi2 = sd_to_dev(sd); + struct v4l2_fwnode_endpoint vep = { + .bus_type = V4L2_MBUS_CSI2_DPHY, + }; + struct v4l2_async_subdev *asd = NULL; + struct fwnode_handle *ep; + int ret; - if (!fwnode_device_is_available(asd->match.fwnode)) { - v4l2_err(&csi2->sd, "remote is not available\n"); - return -EINVAL; - } + v4l2_async_notifier_init(&csi2->notifier); - if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) { - v4l2_err(&csi2->sd, "invalid bus type, must be MIPI CSI2\n"); - return -EINVAL; - } + ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(csi2->dev), 0, 0, + FWNODE_GRAPH_ENDPOINT_NEXT); + if (!ep) + return -ENOTCONN; + + ret = v4l2_fwnode_endpoint_parse(ep, &vep); + if (ret) + goto err_parse; - csi2->bus = vep->bus.mipi_csi2; + csi2->bus = vep.bus.mipi_csi2; dev_dbg(csi2->dev, "data lanes: %d\n", csi2->bus.num_data_lanes); dev_dbg(csi2->dev, "flags: 0x%08x\n", csi2->bus.flags); - return 0; + asd = kzalloc(sizeof(*asd), GFP_KERNEL); + if (!asd) { + ret = -ENOMEM; + goto err_parse; + } + + ret = v4l2_async_notifier_add_fwnode_remote_subdev( + &csi2->notifier, ep, asd); + if (ret) + goto err_parse; + + fwnode_handle_put(ep); + + ret = v4l2_async_subdev_notifier_register(&csi2->sd, + &csi2->notifier); + if (ret) + return ret; + + return v4l2_async_register_subdev(&csi2->sd); + +err_parse: + fwnode_handle_put(ep); + kfree(asd); + return ret; } static int csi2_probe(struct platform_device *pdev) { - unsigned int sink_port = 0; struct csi2_dev *csi2; struct resource *res; int i, ret; @@ -636,15 +662,15 @@ static int csi2_probe(struct platform_device *pdev) platform_set_drvdata(pdev, &csi2->sd); - ret = v4l2_async_register_fwnode_subdev( - &csi2->sd, sizeof(struct v4l2_async_subdev), - &sink_port, 1, csi2_parse_endpoint); + ret = csi2_async_register(csi2); if (ret) - goto dphy_off; + goto clean_notifier; return 0; -dphy_off: +clean_notifier: + v4l2_async_notifier_unregister(&csi2->notifier); + v4l2_async_notifier_cleanup(&csi2->notifier); clk_disable_unprepare(csi2->dphy_clk); pllref_off: clk_disable_unprepare(csi2->pllref_clk); @@ -658,6 +684,8 @@ static int csi2_remove(struct platform_device *pdev) struct v4l2_subdev *sd = platform_get_drvdata(pdev); struct csi2_dev *csi2 = sd_to_dev(sd); + v4l2_async_notifier_unregister(&csi2->notifier); + v4l2_async_notifier_cleanup(&csi2->notifier); v4l2_async_unregister_subdev(sd); clk_disable_unprepare(csi2->dphy_clk); clk_disable_unprepare(csi2->pllref_clk); diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index db30e2c70f2f..776eb42ae5c8 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -155,6 +155,7 @@ struct imx7_csi { struct device *dev; struct v4l2_subdev sd; + struct v4l2_async_notifier notifier; struct imx_media_video_dev *vdev; struct imx_media_dev *imxmd; struct media_pad pad[IMX7_CSI_PADS_NUM]; @@ -1179,11 +1180,41 @@ static const struct v4l2_subdev_internal_ops imx7_csi_internal_ops = { .unregistered = imx7_csi_unregistered, }; -static int imx7_csi_parse_endpoint(struct device *dev, - struct v4l2_fwnode_endpoint *vep, - struct v4l2_async_subdev *asd) +static int imx7_csi_async_register(struct imx7_csi *csi) { - return fwnode_device_is_available(asd->match.fwnode) ? 0 : -EINVAL; + struct v4l2_async_subdev *asd = NULL; + struct fwnode_handle *ep; + int ret; + + v4l2_async_notifier_init(&csi->notifier); + + ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(csi->dev), 0, 0, + FWNODE_GRAPH_ENDPOINT_NEXT); + if (ep) { + asd = kzalloc(sizeof(*asd), GFP_KERNEL); + if (!asd) { + fwnode_handle_put(ep); + return -ENOMEM; + } + + ret = v4l2_async_notifier_add_fwnode_remote_subdev( + &csi->notifier, ep, asd); + + fwnode_handle_put(ep); + + if (ret) { + kfree(asd); + /* OK if asd already exists */ + if (ret != -EEXIST) + return ret; + } + } + + ret = v4l2_async_subdev_notifier_register(&csi->sd, &csi->notifier); + if (ret) + return ret; + + return v4l2_async_register_subdev(&csi->sd); } static int imx7_csi_probe(struct platform_device *pdev) @@ -1266,19 +1297,21 @@ static int imx7_csi_probe(struct platform_device *pdev) if (ret < 0) goto free; - ret = v4l2_async_register_fwnode_subdev(&csi->sd, - sizeof(struct v4l2_async_subdev), - NULL, 0, - imx7_csi_parse_endpoint); + ret = imx7_csi_async_register(csi); if (ret) - goto free; + goto subdev_notifier_cleanup; return 0; +subdev_notifier_cleanup: + v4l2_async_notifier_unregister(&csi->notifier); + v4l2_async_notifier_cleanup(&csi->notifier); + free: v4l2_ctrl_handler_free(&csi->ctrl_hdlr); cleanup: + v4l2_async_notifier_unregister(&imxmd->notifier); v4l2_async_notifier_cleanup(&imxmd->notifier); v4l2_device_unregister(&imxmd->v4l2_dev); media_device_unregister(&imxmd->md); @@ -1303,6 +1336,8 @@ static int imx7_csi_remove(struct platform_device *pdev) v4l2_device_unregister(&imxmd->v4l2_dev); media_device_cleanup(&imxmd->md); + v4l2_async_notifier_unregister(&csi->notifier); + v4l2_async_notifier_cleanup(&csi->notifier); v4l2_async_unregister_subdev(sd); v4l2_ctrl_handler_free(&csi->ctrl_hdlr); diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c index 383abecb3bec..7e872d8f51e0 100644 --- a/drivers/staging/media/imx/imx7-mipi-csis.c +++ b/drivers/staging/media/imx/imx7-mipi-csis.c @@ -223,6 +223,7 @@ struct csi_state { struct device *dev; struct media_pad pads[CSIS_PADS_NUM]; struct v4l2_subdev mipi_sd; + struct v4l2_async_notifier notifier; struct v4l2_subdev *src_sd; u8 index; @@ -827,33 +828,11 @@ static int mipi_csis_parse_dt(struct platform_device *pdev, static int mipi_csis_pm_resume(struct device *dev, bool runtime); -static int mipi_csis_parse_endpoint(struct device *dev, - struct v4l2_fwnode_endpoint *ep, - struct v4l2_async_subdev *asd) -{ - struct v4l2_subdev *mipi_sd = dev_get_drvdata(dev); - struct csi_state *state = mipi_sd_to_csis_state(mipi_sd); - - if (ep->bus_type != V4L2_MBUS_CSI2_DPHY) { - dev_err(dev, "invalid bus type, must be MIPI CSI2\n"); - return -EINVAL; - } - - state->bus = ep->bus.mipi_csi2; - - dev_dbg(state->dev, "data lanes: %d\n", state->bus.num_data_lanes); - dev_dbg(state->dev, "flags: 0x%08x\n", state->bus.flags); - - return 0; -} - static int mipi_csis_subdev_init(struct v4l2_subdev *mipi_sd, struct platform_device *pdev, const struct v4l2_subdev_ops *ops) { struct csi_state *state = mipi_sd_to_csis_state(mipi_sd); - unsigned int sink_port = 0; - int ret; v4l2_subdev_init(mipi_sd, ops); mipi_sd->owner = THIS_MODULE; @@ -878,17 +857,58 @@ static int mipi_csis_subdev_init(struct v4l2_subdev *mipi_sd, state->pads[CSIS_PAD_SINK].flags = MEDIA_PAD_FL_SINK; state->pads[CSIS_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE; - ret = media_entity_pads_init(&mipi_sd->entity, CSIS_PADS_NUM, - state->pads); + return media_entity_pads_init(&mipi_sd->entity, CSIS_PADS_NUM, + state->pads); +} + +static int mipi_csis_async_register(struct csi_state *state) +{ + struct v4l2_fwnode_endpoint vep = { + .bus_type = V4L2_MBUS_CSI2_DPHY, + }; + struct v4l2_async_subdev *asd = NULL; + struct fwnode_handle *ep; + int ret; + + v4l2_async_notifier_init(&state->notifier); + + ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(state->dev), 0, 0, + FWNODE_GRAPH_ENDPOINT_NEXT); + if (!ep) + return -ENOTCONN; + + ret = v4l2_fwnode_endpoint_parse(ep, &vep); + if (ret) + goto err_parse; + + state->bus = vep.bus.mipi_csi2; + + dev_dbg(state->dev, "data lanes: %d\n", state->bus.num_data_lanes); + dev_dbg(state->dev, "flags: 0x%08x\n", state->bus.flags); + + asd = kzalloc(sizeof(*asd), GFP_KERNEL); + if (!asd) { + ret = -ENOMEM; + goto err_parse; + } + + ret = v4l2_async_notifier_add_fwnode_remote_subdev( + &state->notifier, ep, asd); + if (ret) + goto err_parse; + + fwnode_handle_put(ep); + + ret = v4l2_async_subdev_notifier_register(&state->mipi_sd, + &state->notifier); if (ret) return ret; - ret = v4l2_async_register_fwnode_subdev(mipi_sd, - sizeof(struct v4l2_async_subdev), - &sink_port, 1, - mipi_csis_parse_endpoint); - if (ret < 0) - dev_err(&pdev->dev, "async fwnode register failed: %d\n", ret); + return v4l2_async_register_subdev(&state->mipi_sd); + +err_parse: + fwnode_handle_put(ep); + kfree(asd); return ret; } @@ -995,6 +1015,12 @@ static int mipi_csis_probe(struct platform_device *pdev) if (ret < 0) goto disable_clock; + ret = mipi_csis_async_register(state); + if (ret < 0) { + dev_err(&pdev->dev, "async register failed: %d\n", ret); + goto cleanup; + } + memcpy(state->events, mipi_csis_events, sizeof(state->events)); mipi_csis_debugfs_init(state); @@ -1013,7 +1039,10 @@ static int mipi_csis_probe(struct platform_device *pdev) unregister_all: mipi_csis_debugfs_exit(state); +cleanup: media_entity_cleanup(&state->mipi_sd.entity); + v4l2_async_notifier_unregister(&state->notifier); + v4l2_async_notifier_cleanup(&state->notifier); v4l2_async_unregister_subdev(&state->mipi_sd); disable_clock: mipi_csis_clk_disable(state); @@ -1101,6 +1130,8 @@ static int mipi_csis_remove(struct platform_device *pdev) struct csi_state *state = mipi_sd_to_csis_state(mipi_sd); mipi_csis_debugfs_exit(state); + v4l2_async_notifier_unregister(&state->notifier); + v4l2_async_notifier_cleanup(&state->notifier); v4l2_async_unregister_subdev(&state->mipi_sd); pm_runtime_disable(&pdev->dev); From patchwork Tue Mar 3 23:42:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 210752 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35A3DC3F2D1 for ; Tue, 3 Mar 2020 23:43:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B42420842 for ; Tue, 3 Mar 2020 23:43:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YWcJKSqM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728397AbgCCXnR (ORCPT ); Tue, 3 Mar 2020 18:43:17 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43932 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727429AbgCCXnR (ORCPT ); Tue, 3 Mar 2020 18:43:17 -0500 Received: by mail-pf1-f193.google.com with SMTP id c144so81061pfb.10 for ; Tue, 03 Mar 2020 15:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8uhfqYqnydZFe8c9SbO7P/6+8io27mcAmYqcApQItKE=; b=YWcJKSqMuR5iSKKeX5rX0zHZbWyopfB+tKQZi9Qw2mm36NKZiaxS3xyzVxPZJGnSFa o80uWzcMGRXyOoShIiFNE3UiewfTsxzD7AV5TBPS+TsyvDrBoTXJHdkpz49cr5V0HWet X+vT58P0teBmi6TSGrVYVzD4XxkXD+822yKAIJJZc/kihX96KAFdKZb3tVG2vpG13yh+ Vp57oCwkQ6MvnfFIP9c/weoHXrn207rGVJTTBInfl6VXPUA2ZnKLNMTTstaWFxHi06qJ Q2CV6nOEN+ajaGdHOmiyq8YfrdeccM1mtCkwiiskNpn8dg+nAmtEQfjwZ17S0lWY2nKJ Nosg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8uhfqYqnydZFe8c9SbO7P/6+8io27mcAmYqcApQItKE=; b=QuzQZ1UBgZatM4pVMxkLQ+ckIEi5TjYN04ikfMNEpVD1qszSjNzckYyHyLkBDd//D5 yd1o2piuRMcAHpxOBFE3oLn7ns1dNkD4UxBNusoFuQT+8Q6UuDFcNCvgraapnSCQbkrW JboziQJVwNK2h0gkqmpAyGsYK5kvnhhxyGdYKM+Wvr/DhLGD01dm0D52S3t/hY8oCTfv Yle8cnUpMz3tpDDKW9UT65Wz392A1bGNKFX8NXacu4nw5fIxIW0liaghhshaBavH4Eae E6cru6nQF/WaqyqrzUm9vN7YHnb2NRd2TXuM+V3EPB7oLeQ+uOV/xRCyD8L+2xckDie0 Mtew== X-Gm-Message-State: ANhLgQ2tccKoBUxuFv/dJ4gAjS/rXrbD0LY+y9wNGo01g9NxlMfJvVbl GFpPmQ8jC9dK6c0oySp2akAYM4YlBKs= X-Google-Smtp-Source: ADFU+vvZYT+0vD48JPOzvXHS9JKakN2x81mCVEkguqA9F+dhZEglwW7piTABrFI0VFBAqPwUIfgTWA== X-Received: by 2002:a62:ae13:: with SMTP id q19mr201439pff.244.1583278995510; Tue, 03 Mar 2020 15:43:15 -0800 (PST) Received: from mappy.sklembedded.com ([2605:e000:d445:6a00:8145:3904:f092:dd35]) by smtp.gmail.com with ESMTPSA id q66sm23540009pgq.50.2020.03.03.15.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:43:15 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Subject: [PATCH v4 05/17] media: imx: csi: Implement get_fwnode_pad op Date: Tue, 3 Mar 2020 15:42:44 -0800 Message-Id: <20200303234256.8928-6-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303234256.8928-1-slongerbeam@gmail.com> References: <20200303234256.8928-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The CSI does not have a 1:1 relationship between fwnode port numbers and pad indexes. In fact the CSI fwnode device is itself a port which is the sink, containing only a single fwnode endpoint. Implement media_entity operation get_fwnode_pad to first verify the given endpoint is the CSI's sink endpoint, and if so return the CSI sink pad index. Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-media-csi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index f409fca88dcf..35f2512ed2a9 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -1827,9 +1827,32 @@ static void csi_unregistered(struct v4l2_subdev *sd) ipu_csi_put(priv->csi); } +/* + * The CSI has only one fwnode endpoint, at the sink pad. Verify the + * endpoint belongs to us, and return CSI_SINK_PAD. + */ +static int csi_get_fwnode_pad(struct media_entity *entity, + struct fwnode_endpoint *endpoint) +{ + struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); + struct csi_priv *priv = v4l2_get_subdevdata(sd); + struct fwnode_handle *csi_port = dev_fwnode(priv->dev); + struct fwnode_handle *csi_ep; + int ret; + + csi_ep = fwnode_get_next_child_node(csi_port, NULL); + + ret = endpoint->local_fwnode == csi_ep ? CSI_SINK_PAD : -ENXIO; + + fwnode_handle_put(csi_ep); + + return ret; +} + static const struct media_entity_operations csi_entity_ops = { .link_setup = csi_link_setup, .link_validate = v4l2_subdev_link_validate, + .get_fwnode_pad = csi_get_fwnode_pad, }; static const struct v4l2_subdev_core_ops csi_core_ops = { From patchwork Tue Mar 3 23:42:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 210751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E61BFC3F2C6 for ; Tue, 3 Mar 2020 23:43:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6C5E2072D for ; Tue, 3 Mar 2020 23:43:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FbUt9xm1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728433AbgCCXnW (ORCPT ); Tue, 3 Mar 2020 18:43:22 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:42211 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728415AbgCCXnW (ORCPT ); Tue, 3 Mar 2020 18:43:22 -0500 Received: by mail-pl1-f196.google.com with SMTP id u3so128503plr.9 for ; Tue, 03 Mar 2020 15:43:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UmulW+gVzwrZmHWvKjh1tlSb5HuC+mxLHVPgwHlIe0I=; b=FbUt9xm1rkh1RyWcoAnoZqbdnmx7j4FohzExpZm30pdljQLLX6BzuiwiYrlKQLd3En ZRaAxL4JZzNGE405RxJWSWlM+vtUUzrs8Jdid0LeZFEnbBMRFo2GtkjsLYGweieP5Rcv hkJCl1bNkGpI1aq4WlUHE6iTc3L6J9qgQdkrR9qnXUkbLs7RfUrxT/UtN0Ct2+OaCoWH x9W6KVr8AmtsPebrKeJa9jiM7twqWu8pZR/dG0xQn8MNRYIz0yDYzBhpaz7ez9wguoI+ WX634bZ8oxXmGKGkQB8I2K3m8c/swxIfjDEKTAFcuN7+zYLvuiUY8ZcEokKeLFlTzwOJ dsmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UmulW+gVzwrZmHWvKjh1tlSb5HuC+mxLHVPgwHlIe0I=; b=LA+qByGAyq7WEuM5gipYgDO+f7TvtBcVAHZVdoKPd/EE7hgd8qw5lVEzmPGuHw7Wir p9NuM4993wEm+cuWM+ajYT5v+/zLy4lsLRakUVN0WxQ4rwML085pVF6Pdkzo3b8c71zp EKQ8Op2R9KGajAWl/P0QT9j/TX3FxDx2f4UJfzK7wuEkMopMW/okH58X96DTDievojfN 1Kv7R0RUPFBROFciYsg8s0GL5zsjYLsmUiiQIL90yjIPRHgJZ2pDH31yKlllqLQ8PXZ9 SHxmthGbIRN3Kio746izQlmwCMdktW+3BYuLe2pptVsdv/9dAWQhD7wP4xsoOcCAYwtZ 6XbA== X-Gm-Message-State: ANhLgQ3OdKA9D/iQvoaRhzMffm2JjxJyaAosetKYBcY+nL3uPnvRUDFo 1aHRyIG3MveQHZbU6FGA/iS3D5kM/Bw= X-Google-Smtp-Source: ADFU+vuB8/nxsVHa1juMm7SqRFBY9fZmTHCnMaxkVQIVyY6jUMLGmMo6bxF60Nd94sqRrBAUvL2eGw== X-Received: by 2002:a17:902:123:: with SMTP id 32mr381607plb.38.1583278999571; Tue, 03 Mar 2020 15:43:19 -0800 (PST) Received: from mappy.sklembedded.com ([2605:e000:d445:6a00:8145:3904:f092:dd35]) by smtp.gmail.com with ESMTPSA id q66sm23540009pgq.50.2020.03.03.15.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:43:19 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Subject: [PATCH v4 07/17] media: video-mux: Implement get_fwnode_pad op Date: Tue, 3 Mar 2020 15:42:46 -0800 Message-Id: <20200303234256.8928-8-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303234256.8928-1-slongerbeam@gmail.com> References: <20200303234256.8928-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Implement get_fwnode_pad operation. If the endpoint is owned by the video mux, return the endpoint's port number. The video mux maps fwnode port numbers and pad indexes 1:1. Signed-off-by: Steve Longerbeam --- drivers/media/platform/video-mux.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c index 7b6c96a29aa5..f446ada82176 100644 --- a/drivers/media/platform/video-mux.c +++ b/drivers/media/platform/video-mux.c @@ -94,9 +94,38 @@ static int video_mux_link_setup(struct media_entity *entity, return ret; } +static int video_mux_get_fwnode_pad(struct media_entity *entity, + struct fwnode_endpoint *endpoint) +{ + struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); + struct video_mux *vmux = v4l2_subdev_to_video_mux(sd); + struct fwnode_handle *vmux_fwnode = dev_fwnode(vmux->subdev.dev); + struct fwnode_handle *vmux_ep; + + /* + * If the endpoint is one of ours, return the endpoint's port + * number. This device maps port numbers and pad indexes 1:1. + */ + fwnode_graph_for_each_endpoint(vmux_fwnode, vmux_ep) { + if (endpoint->local_fwnode == vmux_ep) { + struct fwnode_endpoint fwep; + int ret; + + ret = fwnode_graph_parse_endpoint(vmux_ep, &fwep); + + fwnode_handle_put(vmux_ep); + + return ret ? ret : fwep.port; + } + } + + return -ENXIO; +} + static const struct media_entity_operations video_mux_ops = { .link_setup = video_mux_link_setup, .link_validate = v4l2_subdev_link_validate, + .get_fwnode_pad = video_mux_get_fwnode_pad, }; static int video_mux_s_stream(struct v4l2_subdev *sd, int enable) From patchwork Tue Mar 3 23:42:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 210750 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 213A4C3F2C6 for ; Tue, 3 Mar 2020 23:43:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E726820842 for ; Tue, 3 Mar 2020 23:43:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RQnyTS1G" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728445AbgCCXnY (ORCPT ); Tue, 3 Mar 2020 18:43:24 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:44653 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728427AbgCCXnY (ORCPT ); Tue, 3 Mar 2020 18:43:24 -0500 Received: by mail-pg1-f194.google.com with SMTP id a14so48116pgb.11 for ; Tue, 03 Mar 2020 15:43:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=k6owUehipygcgAwE4Me8A8yJ7y3IgmI/s2YT+RYiWrU=; b=RQnyTS1GVHyM/wqenjZEcEphz5ki44UCxuB7xvFLnSSlm+E+CCKGBPXXPSuqyJMSgp cbdyE3YnZsbXfdpAez13hXgLKilYuMnWnfaffHhwvDaFeP+5H/x1cmpDCHM8G4QDr6xS ZbFw7i0P3PS+nMgeKbSwTJqWY/0emSLf+tBdGbqrNIVjL20B02j8DXhZ1x54GQYVYQ07 ROYmcrCDc2jWwSiBgE+qvn5DoXtgkMwbCUW56mlOmot7ez0NqEVGIk518TSZFqDNkRm5 0fzS5KYwwaUL0lNvcSQ4PFMXpuqixBU2WNX8zngHRsHyEIJJJ1QU/xIcziBHRqAI4FaF IFgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=k6owUehipygcgAwE4Me8A8yJ7y3IgmI/s2YT+RYiWrU=; b=ZILmavwulaWLPsbvgNTVGx5H5QuztN3gd9E5/si7Q0LRNn325F7EbwX4b3iS5iDj+k 2hBvfwR3E+9/pAnqVIsYTyHyOqLCSvF8nZPrsAzE9JOX1JNEHZDm2EHyWs2Jj1DgZ4KP uHhJnB1SFni9qbfmoPmUhZz7vfD5L0tHI9Zw4L79rvp3+EireBvDqj6YW79l3IMv1DjZ WpLLjgwM10MTgD4jYqnItxt5odQHGcdqiPTcBawOnyF3+QV5lxfNTFSo33IucOI2G57G DX3tVEW3Ye+Lvi9CaBxlcgHWLKWZl8M0uPb5HZdhKHToDnARpi7HH/FKjyJj9pWCStTw A/tQ== X-Gm-Message-State: ANhLgQ2hVpjno1JOpVnehIimxmSLMr65aNxYN4wdG3ewKTg7YZMg/ju9 T3y85ICACnQoxkw87dsBAY41z2ApEgc= X-Google-Smtp-Source: ADFU+vuRm0jjviy7TdxZFlUv1X1b4torFfy4MgusLE8b9kJcAEs1+hORa8zIReIgnlMwtoLFOHDgwQ== X-Received: by 2002:a63:a741:: with SMTP id w1mr6386585pgo.131.1583279002573; Tue, 03 Mar 2020 15:43:22 -0800 (PST) Received: from mappy.sklembedded.com ([2605:e000:d445:6a00:8145:3904:f092:dd35]) by smtp.gmail.com with ESMTPSA id q66sm23540009pgq.50.2020.03.03.15.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:43:22 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Subject: [PATCH v4 09/17] media: video-mux: Create media links in bound notifier Date: Tue, 3 Mar 2020 15:42:48 -0800 Message-Id: <20200303234256.8928-10-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303234256.8928-1-slongerbeam@gmail.com> References: <20200303234256.8928-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Implement a notifier bound op to register media links from the remote sub-device's source pad(s) to the video-mux sink pad(s). Signed-off-by: Steve Longerbeam --- Changes in v3: - this version does the work inline. The previous version called a media_create_fwnode_links() which is removed in v3. --- drivers/media/platform/video-mux.c | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c index f446ada82176..3991b1ea671c 100644 --- a/drivers/media/platform/video-mux.c +++ b/drivers/media/platform/video-mux.c @@ -36,6 +36,12 @@ static const struct v4l2_mbus_framefmt video_mux_format_mbus_default = { .field = V4L2_FIELD_NONE, }; +static inline struct video_mux * +notifier_to_video_mux(struct v4l2_async_notifier *n) +{ + return container_of(n, struct video_mux, notifier); +} + static inline struct video_mux *v4l2_subdev_to_video_mux(struct v4l2_subdev *sd) { return container_of(sd, struct video_mux, subdev); @@ -360,6 +366,90 @@ static const struct v4l2_subdev_ops video_mux_subdev_ops = { .video = &video_mux_subdev_video_ops, }; +static int video_mux_notify_bound(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *sd, + struct v4l2_async_subdev *asd) +{ + struct video_mux *vmux = notifier_to_video_mux(notifier); + struct fwnode_handle *vmux_fwnode = dev_fwnode(vmux->subdev.dev); + struct fwnode_handle *sd_fwnode = dev_fwnode(sd->dev); + struct fwnode_handle *vmux_ep; + + fwnode_graph_for_each_endpoint(vmux_fwnode, vmux_ep) { + struct fwnode_handle *remote_ep, *sd_ep; + struct media_pad *src_pad, *sink_pad; + struct fwnode_endpoint fwep; + int src_idx, sink_idx, ret; + bool remote_ep_belongs; + + ret = fwnode_graph_parse_endpoint(vmux_ep, &fwep); + if (ret) + continue; + + /* only create links to the vmux sink pads */ + if (fwep.port >= vmux->subdev.entity.num_pads - 1) + continue; + + sink_idx = fwep.port; + sink_pad = &vmux->subdev.entity.pads[sink_idx]; + + remote_ep = fwnode_graph_get_remote_endpoint(vmux_ep); + if (!remote_ep) + continue; + + /* + * verify that this remote endpoint is owned by the + * sd, in case the sd does not check for that in its + * .get_fwnode_pad operation or does not implement it. + */ + remote_ep_belongs = false; + fwnode_graph_for_each_endpoint(sd_fwnode, sd_ep) { + if (sd_ep == remote_ep) { + remote_ep_belongs = true; + fwnode_handle_put(sd_ep); + break; + } + } + if (!remote_ep_belongs) + continue; + + src_idx = media_entity_get_fwnode_pad(&sd->entity, remote_ep, + MEDIA_PAD_FL_SOURCE); + fwnode_handle_put(remote_ep); + + if (src_idx < 0) + continue; + + src_pad = &sd->entity.pads[src_idx]; + + /* skip this link if it already exists */ + if (media_entity_find_link(src_pad, sink_pad)) + continue; + + ret = media_create_pad_link(&sd->entity, src_idx, + &vmux->subdev.entity, + sink_idx, 0); + if (ret) { + dev_err(vmux->subdev.dev, + "%s:%d -> %s:%d failed with %d\n", + sd->entity.name, src_idx, + vmux->subdev.entity.name, sink_idx, ret); + fwnode_handle_put(vmux_ep); + return ret; + } + + dev_dbg(vmux->subdev.dev, "%s:%d -> %s:%d\n", + sd->entity.name, src_idx, + vmux->subdev.entity.name, sink_idx); + } + + return 0; +} + +static const struct v4l2_async_notifier_operations video_mux_notify_ops = { + .bound = video_mux_notify_bound, +}; + static int video_mux_async_register(struct video_mux *vmux, unsigned int num_input_pads) { @@ -397,6 +487,8 @@ static int video_mux_async_register(struct video_mux *vmux, } } + vmux->notifier.ops = &video_mux_notify_ops; + ret = v4l2_async_subdev_notifier_register(&vmux->subdev, &vmux->notifier); if (ret) From patchwork Tue Mar 3 23:42:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 210749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A577C3F2D7 for ; Tue, 3 Mar 2020 23:43:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 415BE20848 for ; Tue, 3 Mar 2020 23:43:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QwZeBa7U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728457AbgCCXn2 (ORCPT ); Tue, 3 Mar 2020 18:43:28 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40422 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728427AbgCCXn2 (ORCPT ); Tue, 3 Mar 2020 18:43:28 -0500 Received: by mail-pf1-f193.google.com with SMTP id l184so2315817pfl.7 for ; Tue, 03 Mar 2020 15:43:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u90FNeV7YRWX/ZiCG1LHsUcgglvWvd+1ge0hhU/zuqo=; b=QwZeBa7UMT7kP3/NkVSjucIxMf50WJupqQZpfxysjlOU2DKp1BeZrfkqONBpmtrqPo H649RLXAGAgbbsNDSgpjTG3h+wTRj+jlFYShxPr5LJyh74Xna3Wi8meHFsHq0ewlJXMY gnmM6rjOJ4Q4riHJRGvqItvnolx/g2L/8C4k6dgO2Bl3+JvhjAtIDi6Vpf8VOUJN93+b mSRgnDNKptQBHWP1Tc+PfQzdYW+6H7JVcJccUqaeXBDGvJHvJf3+2IILi/e8Nj3Lfe32 iP1xk7w4j7AR7zjMdgNzu6yTkfyuADMJPcO4jC+UafvHEoYs6FxeaY7Vu1JrDFzlXKKd ZDZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u90FNeV7YRWX/ZiCG1LHsUcgglvWvd+1ge0hhU/zuqo=; b=kXdw1gW/x+kDRHkuWRHL2JSx3OfkfJdDJVYqJ3DrmUIfzcLn7XKUgzPC6T3S5PE9cq N9y13KVISr5yfYiV29htW0lWo4/dxA5E56yGiImiM8gtk4KWv5n1Vu71DWlmcv5ih5/j JWQdW3vb3s87aPCrYop7VNIOYAJ1dnpIU2SXVPz0/gOWYA8nURSf23tTbU2Q/KxQs851 aiboa5MAV27kFgCCKBazc4X1SIfOUzegD1XrW/gBzFOOBKdtq5oJLzT9YuXghRLdQbzM 91wXVf+4yz5mSsFtOWL3//uEoTwyHdM1iH2uodYX54t8awnccn6z1yJWRu0ocnRY4dxK GQTg== X-Gm-Message-State: ANhLgQ2WQAecLnOOgTeFhIOtCE+ywgsVRoxBHa9OHnzhiAKn+yHXuoys WctLiqNIhcpT2FiKdyFYhT8q/DDpGUk= X-Google-Smtp-Source: ADFU+vudvLnY6xwduNuIVNM9PHoO9dNADomuWMN8mF+xcws1psN1qZUhz/q4DnZyHwwihe6Fy2exKg== X-Received: by 2002:a63:445:: with SMTP id 66mr950644pge.351.1583279006027; Tue, 03 Mar 2020 15:43:26 -0800 (PST) Received: from mappy.sklembedded.com ([2605:e000:d445:6a00:8145:3904:f092:dd35]) by smtp.gmail.com with ESMTPSA id q66sm23540009pgq.50.2020.03.03.15.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:43:25 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Subject: [PATCH v4 11/17] media: imx7: mipi csis: Create media links in bound notifier Date: Tue, 3 Mar 2020 15:42:50 -0800 Message-Id: <20200303234256.8928-12-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303234256.8928-1-slongerbeam@gmail.com> References: <20200303234256.8928-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Implement a notifier bound op to register media links from the remote sub-device's source pad(s) to the mipi csi-2 receiver sink pad. Signed-off-by: Steve Longerbeam --- Changes in v3: - call a local imx-media utility imx_media_create_fwnode_pad_link(). Changes in v2: - Move notifier_to_csis_state() next to mipi_sd_to_csis_state(), remove unnecessary inline, and rename to mipi_notifier_to_csis_state(). Suggested by Rui Silva. --- drivers/staging/media/imx/imx7-mipi-csis.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c index 7e872d8f51e0..363545127047 100644 --- a/drivers/staging/media/imx/imx7-mipi-csis.c +++ b/drivers/staging/media/imx/imx7-mipi-csis.c @@ -317,6 +317,12 @@ static int mipi_csis_dump_regs(struct csi_state *state) return 0; } +static struct csi_state * +mipi_notifier_to_csis_state(struct v4l2_async_notifier *n) +{ + return container_of(n, struct csi_state, notifier); +} + static struct csi_state *mipi_sd_to_csis_state(struct v4l2_subdev *sdev) { return container_of(sdev, struct csi_state, mipi_sd); @@ -828,6 +834,20 @@ static int mipi_csis_parse_dt(struct platform_device *pdev, static int mipi_csis_pm_resume(struct device *dev, bool runtime); +static int mipi_csis_notify_bound(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *sd, + struct v4l2_async_subdev *asd) +{ + struct csi_state *state = mipi_notifier_to_csis_state(notifier); + struct media_pad *sink = &state->mipi_sd.entity.pads[CSIS_PAD_SINK]; + + return imx_media_create_fwnode_pad_link(sd, sink); +} + +static const struct v4l2_async_notifier_operations mipi_csis_notify_ops = { + .bound = mipi_csis_notify_bound, +}; + static int mipi_csis_subdev_init(struct v4l2_subdev *mipi_sd, struct platform_device *pdev, const struct v4l2_subdev_ops *ops) @@ -899,6 +919,8 @@ static int mipi_csis_async_register(struct csi_state *state) fwnode_handle_put(ep); + state->notifier.ops = &mipi_csis_notify_ops; + ret = v4l2_async_subdev_notifier_register(&state->mipi_sd, &state->notifier); if (ret) From patchwork Tue Mar 3 23:42:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 210748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74E1AC3F2C6 for ; Tue, 3 Mar 2020 23:43:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 472032072D for ; Tue, 3 Mar 2020 23:43:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KolG0wp/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728467AbgCCXna (ORCPT ); Tue, 3 Mar 2020 18:43:30 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33757 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728107AbgCCXna (ORCPT ); Tue, 3 Mar 2020 18:43:30 -0500 Received: by mail-pf1-f195.google.com with SMTP id n7so2329450pfn.0 for ; Tue, 03 Mar 2020 15:43:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I/weKw8gqSMHerG7+ZtB0jaPIbMs+J6LkbgWE8zyS2o=; b=KolG0wp/nlZeZAto3wnTI8CtRNn86MNCy+CseiHgX+F39EPJue519oEz+MN/43A8+N RWVWIvrZlmA5Xtu6104ZweJnz2bQuXzTlsunDUTsFxCzrj8OWwZjy4yUomTiLCv1Nn8x Xk9RZyKjAJZ3pdckHpsTtpGSPZsxyc1djdS54B1jc9to0aDZn5ZgHQjQDvU+3Svajj2J d1dml8HLr/TBUbuC4kjpftXwiWXroR/qTlKvaqD8VLoTsQfJhLcBG3OTIA1+4CFMpSS+ JCFOahxdRafVKdXzUUG1cTH1lm5pJ5R53rIT0BZSMKjFIK27TPGxyVqgP61O/rFVHKmc cLQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=I/weKw8gqSMHerG7+ZtB0jaPIbMs+J6LkbgWE8zyS2o=; b=D1FKead7HQAgN4+BH8xNoNl301tydh2VfNBmi9F98ygMBOrxy9aSDN8HS6L3X7xK5T Y7F1RevG3okoqWOAn/G2q/roQAIh9sifUyglA4phY0+j0MEzG6mCJRVP3bQO5WsuyyZQ ParRlrRZ6KhOIW23eUFSCGnS452JuWLyhlZE012GagAvX98q2/9OEaGV5/37Oj7QqUKZ wkWepDohNhYZyi4wOniEeoJDzPbS4b8HoiOfr7VZAE68e1EZ/XX038ZxsE9Pl4byUiLh xZ6OshaK50J1bvgDGQmcfAy5tqB0sqJ+B6jTum+5FHadl5/nj6JPju8E0Uqpg+ikLlKD XQLA== X-Gm-Message-State: ANhLgQ23J8iOFmslKbilX8/W0ADWYjKJ1yRKWIPK3iUEJHNyt2BCtPMz +3YtUv0kJVMhcA58gfdD3RE9CO2apOY= X-Google-Smtp-Source: ADFU+vuqMzyPVjNJsQntTY/2xt5idxopQleSvlethhNFKbopw1FGQ6D7e91X7dIyVyM/mKwAQ0DdJg== X-Received: by 2002:a63:d18:: with SMTP id c24mr6306470pgl.218.1583279009437; Tue, 03 Mar 2020 15:43:29 -0800 (PST) Received: from mappy.sklembedded.com ([2605:e000:d445:6a00:8145:3904:f092:dd35]) by smtp.gmail.com with ESMTPSA id q66sm23540009pgq.50.2020.03.03.15.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:43:29 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Subject: [PATCH v4 13/17] media: imx: csi: Create media links in bound notifier Date: Tue, 3 Mar 2020 15:42:52 -0800 Message-Id: <20200303234256.8928-14-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303234256.8928-1-slongerbeam@gmail.com> References: <20200303234256.8928-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Implement a notifier bound op to register media links from the remote sub-device's source pad(s) to the CSI sink pad. Signed-off-by: Steve Longerbeam --- Changes in v3: - call a local imx-media utility imx_media_create_fwnode_pad_link(). --- drivers/staging/media/imx/imx-media-csi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index 35f2512ed2a9..59ab1cf72841 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -120,6 +120,11 @@ static inline struct csi_priv *sd_to_dev(struct v4l2_subdev *sdev) return container_of(sdev, struct csi_priv, sd); } +static inline struct csi_priv *notifier_to_dev(struct v4l2_async_notifier *n) +{ + return container_of(n, struct csi_priv, notifier); +} + static inline bool is_parallel_bus(struct v4l2_fwnode_endpoint *ep) { return ep->bus_type != V4L2_MBUS_CSI2_DPHY; @@ -1889,6 +1894,20 @@ static const struct v4l2_subdev_internal_ops csi_internal_ops = { .unregistered = csi_unregistered, }; +static int imx_csi_notify_bound(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *sd, + struct v4l2_async_subdev *asd) +{ + struct csi_priv *priv = notifier_to_dev(notifier); + struct media_pad *sink = &priv->sd.entity.pads[CSI_SINK_PAD]; + + return imx_media_create_fwnode_pad_link(sd, sink); +} + +static const struct v4l2_async_notifier_operations csi_notify_ops = { + .bound = imx_csi_notify_bound, +}; + static int imx_csi_async_register(struct csi_priv *priv) { struct v4l2_async_subdev *asd = NULL; @@ -1926,6 +1945,8 @@ static int imx_csi_async_register(struct csi_priv *priv) } } + priv->notifier.ops = &csi_notify_ops; + ret = v4l2_async_subdev_notifier_register(&priv->sd, &priv->notifier); if (ret) From patchwork Tue Mar 3 23:42:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 210747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FC1EC3F2C6 for ; Tue, 3 Mar 2020 23:43:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF8F920848 for ; Tue, 3 Mar 2020 23:43:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VLyyd0kl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728483AbgCCXne (ORCPT ); Tue, 3 Mar 2020 18:43:34 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34372 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728107AbgCCXne (ORCPT ); Tue, 3 Mar 2020 18:43:34 -0500 Received: by mail-pl1-f195.google.com with SMTP id j7so145837plt.1 for ; Tue, 03 Mar 2020 15:43:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bHkoLoAopDh/1dv+BwgYSSiMTnq6CBi7MdRZKVUgkME=; b=VLyyd0kltz8/fc8No5wm7uzRRNrmuW1r+LIzH/OFX0K5JU16Cbf5B93EJYquAyVsSJ X4ccJ7ntuPQ0LAkFGpjh5PZhCvAMnoTmW7GHrxd4d/7HP5fWrv0hLA+0MlNpSF5VRAFG qxixjroFhUFH+p92qjm9OkppDR0/BPX3moo7OGsDExkVNYZhEU9kYnj91AC8KyFrMTKh ax3ueRDhjLkVx39709cncNn5wsoqH6Evbr3wcK0JFmuKwmm67ekW55V+eua9icv/CTLn IsszwxFRzdVpcLJfzaon5JMui5MoCZUFD8AteK0QbpFsw2GoKPX5skHfGNoH9yEEghjf kcDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bHkoLoAopDh/1dv+BwgYSSiMTnq6CBi7MdRZKVUgkME=; b=oGj5e1OwJuiKz8kok8orCKPdfEDNF6sVSkqC8BdH8ZdGHidXr3zQ83NVLeWh5WD5ZU sQYAfN8kePoks5AMFZ++Hcmm1bQNlgjsMO3Oi331og2b/wMu2vZGLdxFqXnqs3NaO+kp XlEzz35o3wxT50AWJHtN0XDpP/zSBkUXbWCGTKXn7lnQg0TGPWcaSOE4/ucT3X5N21ut cAM9nnQiARxj6rjDWiKq/4X/nW6eMR7obtMOtxGsa7rUMkQ5OxNDDpVyL03E4RJTVv+p I6lErOXkHfITnA6ze6NlJvrEf4BxTzfOBDMmloWf5VY9TGz6fxwOEbfgoXxWqj+2iEka 9N2g== X-Gm-Message-State: ANhLgQ1KdF114Wo+4m+F7cnTST4nMwHhuIhYz7fv3CsahCcv15zmDm+3 KdkSLxuTMU3kApj6iMkHHgqI9Q95V0Y= X-Google-Smtp-Source: ADFU+vva5TJRM298r9Ngg/vKz7OuF4kS+gb8YGZy2V1PcEwnZV6MlZOK1wBX+O/bMHDwfPuupEQwCw== X-Received: by 2002:a17:902:bf08:: with SMTP id bi8mr312864plb.305.1583279012653; Tue, 03 Mar 2020 15:43:32 -0800 (PST) Received: from mappy.sklembedded.com ([2605:e000:d445:6a00:8145:3904:f092:dd35]) by smtp.gmail.com with ESMTPSA id q66sm23540009pgq.50.2020.03.03.15.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:43:32 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Subject: [PATCH v4 15/17] media: imx: Create missing links from CSI-2 receiver Date: Tue, 3 Mar 2020 15:42:54 -0800 Message-Id: <20200303234256.8928-16-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303234256.8928-1-slongerbeam@gmail.com> References: <20200303234256.8928-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The entities external to the i.MX6 IPU and i.MX7 now create the links to their fwnode-endpoint connected entities in their notifier bound callbacks. Which means imx_media_create_of_links() and imx_media_create_csi_of_links() are no longer needed and are removed. However there is still one case in which imx-media needs to create fwnode-endpoint based links at probe completion. The v4l2-async framework does not allow multiple subdevice notifiers to contain a duplicate subdevice in their asd_list. Only the first subdev notifier that discovers and adds that one subdevice to its asd_list will receive a bound callback for it. Other subdevices that also have firmware endpoint connections to this duplicate subdevice will not have it in their asd_list, and thus will never receive a bound callback for it. In the case of imx-media, the one duplicate subdevice in question is the i.MX6 MIPI CSI-2 receiver. Until there is a solution to that problem, rewrite imx_media_create_links() to add the missing links from the CSI-2 receiver to the CSIs and CSI muxes. The function is renamed imx_media_create_csi2_links(). Signed-off-by: Steve Longerbeam --- Changes in v3: - call a local imx-media utility imx_media_create_fwnode_pad_links(). Changes in v2: - this is a rewrite of v1 "media: imx: Use media_create_fwnode_links for external links", which only adds the missing CSI-2 receiver links. --- .../staging/media/imx/imx-media-dev-common.c | 46 +++---- drivers/staging/media/imx/imx-media-of.c | 114 ------------------ drivers/staging/media/imx/imx-media.h | 4 - 3 files changed, 17 insertions(+), 147 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-dev-common.c b/drivers/staging/media/imx/imx-media-dev-common.c index 66b505f7e8df..f7ad3cbbeec2 100644 --- a/drivers/staging/media/imx/imx-media-dev-common.c +++ b/drivers/staging/media/imx/imx-media-dev-common.c @@ -30,41 +30,31 @@ static int imx_media_subdev_bound(struct v4l2_async_notifier *notifier, } /* - * Create the media links for all subdevs that registered. + * Create the missing media links from the CSI-2 receiver. * Called after all async subdevs have bound. */ -static int imx_media_create_links(struct v4l2_async_notifier *notifier) +static void imx_media_create_csi2_links(struct imx_media_dev *imxmd) { - struct imx_media_dev *imxmd = notifier2dev(notifier); - struct v4l2_subdev *sd; + struct v4l2_subdev *sd, *csi2 = NULL; list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) { - switch (sd->grp_id) { - case IMX_MEDIA_GRP_ID_IPU_VDIC: - case IMX_MEDIA_GRP_ID_IPU_IC_PRP: - case IMX_MEDIA_GRP_ID_IPU_IC_PRPENC: - case IMX_MEDIA_GRP_ID_IPU_IC_PRPVF: - /* - * links have already been created for the - * sync-registered subdevs. - */ - break; - case IMX_MEDIA_GRP_ID_IPU_CSI0: - case IMX_MEDIA_GRP_ID_IPU_CSI1: - case IMX_MEDIA_GRP_ID_CSI: - imx_media_create_csi_of_links(imxmd, sd); - break; - default: - /* - * if this subdev has fwnode links, create media - * links for them. - */ - imx_media_create_of_links(imxmd, sd); + if (sd->grp_id == IMX_MEDIA_GRP_ID_CSI2) { + csi2 = sd; break; } } + if (!csi2) + return; - return 0; + list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) { + /* skip if not a CSI or a video mux */ + if (!(sd->grp_id & IMX_MEDIA_GRP_ID_IPU_CSI) && + !(sd->grp_id & IMX_MEDIA_GRP_ID_CSI) && + sd->entity.function != MEDIA_ENT_F_VID_MUX) + continue; + + imx_media_create_fwnode_pad_links(csi2, sd); + } } /* @@ -196,9 +186,7 @@ int imx_media_probe_complete(struct v4l2_async_notifier *notifier) mutex_lock(&imxmd->mutex); - ret = imx_media_create_links(notifier); - if (ret) - goto unlock; + imx_media_create_csi2_links(imxmd); ret = imx_media_create_pad_vdev_lists(imxmd); if (ret) diff --git a/drivers/staging/media/imx/imx-media-of.c b/drivers/staging/media/imx/imx-media-of.c index 2d3efd2a6dde..82e13e972e23 100644 --- a/drivers/staging/media/imx/imx-media-of.c +++ b/drivers/staging/media/imx/imx-media-of.c @@ -74,117 +74,3 @@ int imx_media_add_of_subdevs(struct imx_media_dev *imxmd, return ret; } EXPORT_SYMBOL_GPL(imx_media_add_of_subdevs); - -/* - * Create a single media link to/from sd using a fwnode link. - * - * NOTE: this function assumes an OF port node is equivalent to - * a media pad (port id equal to media pad index), and that an - * OF endpoint node is equivalent to a media link. - */ -static int create_of_link(struct imx_media_dev *imxmd, - struct v4l2_subdev *sd, - struct v4l2_fwnode_link *link) -{ - struct v4l2_subdev *remote, *src, *sink; - int src_pad, sink_pad; - - if (link->local_port >= sd->entity.num_pads) - return -EINVAL; - - remote = imx_media_find_subdev_by_fwnode(imxmd, link->remote_node); - if (!remote) - return 0; - - if (sd->entity.pads[link->local_port].flags & MEDIA_PAD_FL_SINK) { - src = remote; - src_pad = link->remote_port; - sink = sd; - sink_pad = link->local_port; - } else { - src = sd; - src_pad = link->local_port; - sink = remote; - sink_pad = link->remote_port; - } - - /* make sure link doesn't already exist before creating */ - if (media_entity_find_link(&src->entity.pads[src_pad], - &sink->entity.pads[sink_pad])) - return 0; - - v4l2_info(sd->v4l2_dev, "%s:%d -> %s:%d\n", - src->name, src_pad, sink->name, sink_pad); - - return media_create_pad_link(&src->entity, src_pad, - &sink->entity, sink_pad, 0); -} - -/* - * Create media links to/from sd using its device-tree endpoints. - */ -int imx_media_create_of_links(struct imx_media_dev *imxmd, - struct v4l2_subdev *sd) -{ - struct v4l2_fwnode_link link; - struct device_node *ep; - int ret; - - for_each_endpoint_of_node(sd->dev->of_node, ep) { - ret = v4l2_fwnode_parse_link(of_fwnode_handle(ep), &link); - if (ret) - continue; - - ret = create_of_link(imxmd, sd, &link); - v4l2_fwnode_put_link(&link); - if (ret) - return ret; - } - - return 0; -} -EXPORT_SYMBOL_GPL(imx_media_create_of_links); - -/* - * Create media links to the given CSI subdevice's sink pads, - * using its device-tree endpoints. - */ -int imx_media_create_csi_of_links(struct imx_media_dev *imxmd, - struct v4l2_subdev *csi) -{ - struct device_node *csi_np = csi->dev->of_node; - struct device_node *ep; - - for_each_child_of_node(csi_np, ep) { - struct fwnode_handle *fwnode, *csi_ep; - struct v4l2_fwnode_link link; - int ret; - - memset(&link, 0, sizeof(link)); - - link.local_node = of_fwnode_handle(csi_np); - link.local_port = CSI_SINK_PAD; - - csi_ep = of_fwnode_handle(ep); - - fwnode = fwnode_graph_get_remote_endpoint(csi_ep); - if (!fwnode) - continue; - - fwnode = fwnode_get_parent(fwnode); - fwnode_property_read_u32(fwnode, "reg", &link.remote_port); - fwnode = fwnode_get_next_parent(fwnode); - if (is_of_node(fwnode) && - of_node_name_eq(to_of_node(fwnode), "ports")) - fwnode = fwnode_get_next_parent(fwnode); - link.remote_node = fwnode; - - ret = create_of_link(imxmd, csi, &link); - fwnode_handle_put(link.remote_node); - if (ret) - return ret; - } - - return 0; -} -EXPORT_SYMBOL_GPL(imx_media_create_csi_of_links); diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index 5f23d852122f..5271b84bea9a 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -248,10 +248,6 @@ void imx_media_unregister_ipu_internal_subdevs(struct imx_media_dev *imxmd); /* imx-media-of.c */ int imx_media_add_of_subdevs(struct imx_media_dev *dev, struct device_node *np); -int imx_media_create_of_links(struct imx_media_dev *imxmd, - struct v4l2_subdev *sd); -int imx_media_create_csi_of_links(struct imx_media_dev *imxmd, - struct v4l2_subdev *csi); int imx_media_of_add_csi(struct imx_media_dev *imxmd, struct device_node *csi_np); From patchwork Tue Mar 3 23:42:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 210746 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 684C5C3F2D1 for ; Tue, 3 Mar 2020 23:43:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D0252072D for ; Tue, 3 Mar 2020 23:43:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nx+iRQ9r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728500AbgCCXnh (ORCPT ); Tue, 3 Mar 2020 18:43:37 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36202 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728494AbgCCXnh (ORCPT ); Tue, 3 Mar 2020 18:43:37 -0500 Received: by mail-pf1-f194.google.com with SMTP id i13so2325186pfe.3 for ; Tue, 03 Mar 2020 15:43:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AS+AHCuMQWIyLmWzD2RHQ/sZnkJFO9p0vLnea6pI0u8=; b=nx+iRQ9rlI/UN8xYS4H2lgIfb7SwrIUVzaIj6QFmCJ44w5wVtFapFsZYhvHhnjQS4L Q+IENjrnYfJUs8Ue1Szh1hQDSksOngWvI+jgTEz+ztT/So0aY9EBJe7GxC+bbyAP1nv2 BhIrS6tGLC5WVXRkYsmdCxHGcEF88C/hffNTyUy4I5DALDvSdweC3yvdxxgUUuA6UU1Y KK84k8flEhs2iHekB90IwCw6QgMwSsQvvQqxKdf3I9kt2GxqofPs7XAjNgLGUW6/ygf2 ncmY90srO+Rwud1c4/nNtOBTIAYtfaFvyK51xYT5let7aQ/cati0WqWlYLgk+x7Namhb FuRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AS+AHCuMQWIyLmWzD2RHQ/sZnkJFO9p0vLnea6pI0u8=; b=E8kiyk+azbztIOPEL+k5mtApXWxMKgRH9i+uTWBMQtGPrAhSzkQENI5CcYd/PeE8/Y ct3ojzxNp37Huy+Jexyao4QOdecsWpGaByKvMBR2GzYtMomXww+z5vCIYRXWUKA5/7KD aeNEnHIGiRsTa+T0T8x1QQXu34BPgsqw9VjD67ZW47fNTVFwYWvSNlsYXyHiRuoEwWiW MXMaLQOb0Ao0Gw8vZm6vMlu7R9hm1LsjAWoZxFPbn8JAEQfSsCIoz7RxS8sHYzq22v6l krKD/+lt1BYkO36JjbYKPKFpFR5MoVHkWZ3E5D3RQiUmtFV9+xHCpnWX5msuojnE3hVa rf+w== X-Gm-Message-State: ANhLgQ3/wuSP496s1U/cxZ1lZdmRiwPI3dmyM2MkFYwksN8h6mGRr26Y w1lNGO8qsqw41XGEWlJixvIoaopzAMg= X-Google-Smtp-Source: ADFU+vt8YPvn85p+KvVGysds4MYZkP2OT0DYvBlkIydwUd2Ki9GXRwVyLjW/7MsdRJ+I2F40y3b7rA== X-Received: by 2002:aa7:947b:: with SMTP id t27mr201118pfq.212.1583279016089; Tue, 03 Mar 2020 15:43:36 -0800 (PST) Received: from mappy.sklembedded.com ([2605:e000:d445:6a00:8145:3904:f092:dd35]) by smtp.gmail.com with ESMTPSA id q66sm23540009pgq.50.2020.03.03.15.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:43:35 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Subject: [PATCH v4 17/17] media: imx: TODO: Remove media link creation todos Date: Tue, 3 Mar 2020 15:42:56 -0800 Message-Id: <20200303234256.8928-18-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303234256.8928-1-slongerbeam@gmail.com> References: <20200303234256.8928-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Remove the TODO items regarding media link creation, these issues are resolved by moving media link creation to individual entity bound callbacks and the implementation of the get_fwnode_pad operation. Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/TODO | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/drivers/staging/media/imx/TODO b/drivers/staging/media/imx/TODO index 6f29b5ca5324..a371cdedcdb0 100644 --- a/drivers/staging/media/imx/TODO +++ b/drivers/staging/media/imx/TODO @@ -17,35 +17,6 @@ decided whether this feature is useful enough to make it generally available by exporting to v4l2-core. -- After all async subdevices have been bound, v4l2_fwnode_parse_link() - is used to form the media links between the devices discovered in - the OF graph. - - While this approach allows support for arbitrary OF graphs, there - are some assumptions for this to work: - - 1. If a port owned by a device in the graph has endpoint nodes, the - port is treated as a media pad. - - This presents problems for devices that don't make this port = pad - assumption. Examples are SMIAPP compatible cameras which define only - a single output port node, but which define multiple pads owned - by multiple subdevices (pixel-array, binner, scaler). Or video - decoders (entity function MEDIA_ENT_F_ATV_DECODER), which also define - only a single output port node, but define multiple pads for video, - VBI, and audio out. - - A workaround at present is to set the port reg properties to - correspond to the media pad index that the port represents. A - possible long-term solution is to implement a subdev API that - maps a port id to a media pad index. - - 2. Every endpoint of a port owned by a device in the graph is treated - as a media link. - - Which means a port must not contain mixed-use endpoints, they - must all refer to media links between V4L2 subdevices. - - i.MX7: all of the above, since it uses the imx media core - i.MX7: use Frame Interval Monitor