From patchwork Tue May 10 11:50:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15842 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8EDF9C326C for ; Tue, 10 May 2022 11:52:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2FA306564F; Tue, 10 May 2022 13:52:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652183521; bh=biy0GTT1QoP72aKYu5WMI/a8pkSOFL+DXgOcxXmEqYk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=VY+k/Q/jnDhzxsIfztw2kBhVowzRYa4xGxQJwYpenByxin0jPT5GnkP7IOVAgv44x h0euTW46m9BAvLZSRlfvrzIM0cDDZz9DMoZN92wDc7waznIjTzErdfpP9hCvPmlZDt B5jVmC+ZHoUd2X8uZRsPHxGCZ0zXefUGOkbCUZA3vjnnTaNvfcPwihnOWMlTtf/i61 CSfc7AVNcpp7FYfI9a/EOzXxy3kbrzK3ufUGpFc7FRn2Pzvs9F8HhYtPgPtr9QvlGg HE8+8vc/nBm/6Ek3C0Mm3D+cjxLIZeHN9RD1O42MBBdV8t4guJ+Gxw5vaLdaDdfUE1 592uwBnWMGecA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8223F65648 for ; Tue, 10 May 2022 13:51:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OFIx9Vtb"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 900EFB9A; Tue, 10 May 2022 13:51:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652183518; bh=biy0GTT1QoP72aKYu5WMI/a8pkSOFL+DXgOcxXmEqYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OFIx9VtbfZpvK4FYMar2dLCOnuZ3X+X/6aqhonL4sDKXhr7sfbwQwC1p75ugYV7R8 9YDA7n0GXLHgkWtUckcGO2Cq1Oh+W/FmZl7l//DcsCHdLJg2Tjlz3Vs5OtrNOLaCqA 0dllezY6TwqMZfVZjY6maCTIaWmKD+gB13nFV5RI= To: libcamera-devel@lists.libcamera.org Date: Tue, 10 May 2022 14:50:59 +0300 Message-Id: <20220510115147.19360-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220510115147.19360-1-laurent.pinchart@ideasonboard.com> References: <20220510115147.19360-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Martin Kepplinger , kernel@pengutronix.de, Dorota Czaplejewicz , Alexander Stein , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Prepare for the decoupling of the imx7-media-csi driver from the IPUv3-based drivers by moving the imx_media_dev handling from probe() function to separate functions. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx7-media-csi.c | 71 +++++++++++++--------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index 893620e8fc03..d7c65b8bb3c9 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -1175,11 +1175,45 @@ static int imx7_csi_async_register(struct imx7_csi *csi) return v4l2_async_register_subdev(&csi->sd); } +static void imx7_csi_media_cleanup(struct imx7_csi *csi) +{ + struct imx_media_dev *imxmd = csi->imxmd; + + v4l2_device_unregister(&imxmd->v4l2_dev); + media_device_unregister(&imxmd->md); + media_device_cleanup(&imxmd->md); +} + +static int imx7_csi_media_init(struct imx7_csi *csi) +{ + struct imx_media_dev *imxmd; + int ret; + + /* add media device */ + imxmd = imx_media_dev_init(csi->dev, NULL); + if (IS_ERR(imxmd)) + return PTR_ERR(imxmd); + + ret = imx_media_of_add_csi(imxmd, csi->dev->of_node); + if (ret < 0 && ret != -ENODEV && ret != -EEXIST) { + imx7_csi_media_cleanup(csi); + return ret; + } + + ret = imx_media_dev_notifier_register(imxmd, NULL); + if (ret < 0) { + imx7_csi_media_cleanup(csi); + return ret; + } + + csi->imxmd = imxmd; + + return 0; +} + static int imx7_csi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *node = dev->of_node; - struct imx_media_dev *imxmd; struct imx7_csi *csi; int i, ret; @@ -1193,6 +1227,7 @@ static int imx7_csi_probe(struct platform_device *pdev) spin_lock_init(&csi->irqlock); mutex_init(&csi->lock); + /* Acquire resources and install interrupt handler. */ csi->mclk = devm_clk_get(&pdev->dev, "mclk"); if (IS_ERR(csi->mclk)) { ret = PTR_ERR(csi->mclk); @@ -1214,7 +1249,6 @@ static int imx7_csi_probe(struct platform_device *pdev) csi->model = (enum imx_csi_model)(uintptr_t)of_device_get_match_data(&pdev->dev); - /* install interrupt handler */ ret = devm_request_irq(dev, csi->irq, imx7_csi_irq_handler, 0, "csi", (void *)csi); if (ret < 0) { @@ -1222,22 +1256,11 @@ static int imx7_csi_probe(struct platform_device *pdev) goto destroy_mutex; } - /* add media device */ - imxmd = imx_media_dev_init(dev, NULL); - if (IS_ERR(imxmd)) { - ret = PTR_ERR(imxmd); + /* Initialize all the media device infrastructure. */ + ret = imx7_csi_media_init(csi); + if (ret) goto destroy_mutex; - } - ret = imx_media_of_add_csi(imxmd, node); - if (ret < 0 && ret != -ENODEV && ret != -EEXIST) - goto cleanup; - - ret = imx_media_dev_notifier_register(imxmd, NULL); - if (ret < 0) - goto cleanup; - - csi->imxmd = imxmd; v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops); v4l2_set_subdevdata(&csi->sd, csi); csi->sd.internal_ops = &imx7_csi_internal_ops; @@ -1269,11 +1292,7 @@ static int imx7_csi_probe(struct platform_device *pdev) v4l2_async_nf_cleanup(&csi->notifier); cleanup: - v4l2_async_nf_unregister(&imxmd->notifier); - v4l2_async_nf_cleanup(&imxmd->notifier); - v4l2_device_unregister(&imxmd->v4l2_dev); - media_device_unregister(&imxmd->md); - media_device_cleanup(&imxmd->md); + imx7_csi_media_cleanup(csi); destroy_mutex: mutex_destroy(&csi->lock); @@ -1285,14 +1304,8 @@ static int imx7_csi_remove(struct platform_device *pdev) { struct v4l2_subdev *sd = platform_get_drvdata(pdev); struct imx7_csi *csi = v4l2_get_subdevdata(sd); - struct imx_media_dev *imxmd = csi->imxmd; - v4l2_async_nf_unregister(&imxmd->notifier); - v4l2_async_nf_cleanup(&imxmd->notifier); - - media_device_unregister(&imxmd->md); - v4l2_device_unregister(&imxmd->v4l2_dev); - media_device_cleanup(&imxmd->md); + imx7_csi_media_cleanup(csi); v4l2_async_nf_unregister(&csi->notifier); v4l2_async_nf_cleanup(&csi->notifier);