From patchwork Tue May 10 15:25:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 571434 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC3E5C433F5 for ; Tue, 10 May 2022 15:29:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345576AbiEJPdT (ORCPT ); Tue, 10 May 2022 11:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345705AbiEJPc5 (ORCPT ); Tue, 10 May 2022 11:32:57 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4743F79809 for ; Tue, 10 May 2022 08:25:30 -0700 (PDT) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4DB5EB60; Tue, 10 May 2022 17:25:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652196328; bh=3z38PR6KbUx9EXbjyILJZX6N6y69xADV3INHv2JzQGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lR+9zwNBiEKgNNdn3Znz0UWsPOnuNJ/rp7am5KbmoDk+fnzaNGGGqXVk0UttJIelD fMKIAFjPOXJ0rkeHUlEMATDsrUOhMWUQ6H0hF/QvW+kJN2IZVH71U52D/eaQW3vlqp vqpvaRZLQSEfrvLf/R+BYv4SArV8fenzqCSuLyok= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Rui Miguel Silva , Steve Longerbeam , Philipp Zabel , Jacopo Mondi , Martin Kepplinger , Alexander Stein , Dorota Czaplejewicz , kernel@pengutronix.de Subject: [PATCH v1.1 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe() Date: Tue, 10 May 2022 18:25:18 +0300 Message-Id: <20220510152518.4063-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220510115859.19777-3-laurent.pinchart@ideasonboard.com> References: <20220510115859.19777-3-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- Changes since v1: - Set csi->imxmd earlier in imx7_csi_media_init() - Unregister and cleanup notifier in imx7_csi_media_cleanup() --- drivers/staging/media/imx/imx7-media-csi.c | 74 +++++++++++++--------- 1 file changed, 45 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..3246a5826cb2 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -1175,11 +1175,48 @@ 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_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); +} + +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); + + csi->imxmd = 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; + } + + 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 +1230,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 +1252,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 +1259,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 +1295,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 +1307,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); From patchwork Tue May 10 15:26:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 571672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40BC7C433EF for ; Tue, 10 May 2022 15:29:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345651AbiEJPdY (ORCPT ); Tue, 10 May 2022 11:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345839AbiEJPdG (ORCPT ); Tue, 10 May 2022 11:33:06 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDFE08FD43 for ; Tue, 10 May 2022 08:26:28 -0700 (PDT) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E2B49B60; Tue, 10 May 2022 17:26:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652196386; bh=u4oHCgowD/dbv9QHhq1MuIZ9m5AdxkACQZsDjcALtKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=POJGJyDExRm4RaLi16j96BVRydZfmH1UNziOvf52AT/jCGG22IxjTDxcMXmEZuZLX U9yCihDvVDVvyITlh/1OiphJcxcx5ial7vlbmUpIOGFwTkESAh5qqV6rRqRWjzRay/ 5GhKZRF3rTBFt2/hFln80In/jkZvx+OSscah4R0g= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Rui Miguel Silva , Steve Longerbeam , Philipp Zabel , Jacopo Mondi , Martin Kepplinger , Alexander Stein , Dorota Czaplejewicz , kernel@pengutronix.de, Paul Elder Subject: [PATCH v1.1 06/50] staging: media: imx: imx7-media-csi: Move misc init out of probe() Date: Tue, 10 May 2022 18:26:16 +0300 Message-Id: <20220510152616.4139-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220510115859.19777-7-laurent.pinchart@ideasonboard.com> References: <20220510115859.19777-7-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Paul Elder There is a chunk of miscellaneous initializations related to the CSI subdev and media pads directly in the probe function. Move them into the imx7_csi_media_init() function to clean up the probe function. Signed-off-by: Paul Elder --- Changes since v1: - Fix error handling in imx7_csi_media_init() --- drivers/staging/media/imx/imx7-media-csi.c | 60 ++++++++++++---------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index 9551cf37a1a9..1b801f39f568 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -1342,6 +1342,7 @@ static void imx7_csi_media_cleanup(struct imx7_csi *csi) static int imx7_csi_media_init(struct imx7_csi *csi) { struct imx_media_dev *imxmd; + unsigned int i; int ret; /* add media device */ @@ -1352,19 +1353,44 @@ static int imx7_csi_media_init(struct imx7_csi *csi) csi->imxmd = 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; - } + if (ret < 0 && ret != -ENODEV && ret != -EEXIST) + goto error; + + v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops); + v4l2_set_subdevdata(&csi->sd, csi); + csi->sd.internal_ops = &imx7_csi_internal_ops; + csi->sd.entity.ops = &imx7_csi_entity_ops; + csi->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; + csi->sd.dev = csi->dev; + csi->sd.owner = THIS_MODULE; + csi->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE; + snprintf(csi->sd.name, sizeof(csi->sd.name), "csi"); + + for (i = 0; i < IMX7_CSI_PADS_NUM; i++) + csi->pad[i].flags = (i == IMX7_CSI_PAD_SINK) ? + MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE; + + ret = media_entity_pads_init(&csi->sd.entity, IMX7_CSI_PADS_NUM, + csi->pad); + if (ret) + goto error; + + ret = v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd); + if (ret) + goto error; return 0; + +error: + imx7_csi_media_cleanup(csi); + return ret; } static int imx7_csi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct imx7_csi *csi; - int i, ret; + int ret; csi = devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL); if (!csi) @@ -1410,28 +1436,9 @@ static int imx7_csi_probe(struct platform_device *pdev) if (ret) goto destroy_mutex; - v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops); - v4l2_set_subdevdata(&csi->sd, csi); - csi->sd.internal_ops = &imx7_csi_internal_ops; - csi->sd.entity.ops = &imx7_csi_entity_ops; - csi->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; - csi->sd.dev = &pdev->dev; - csi->sd.owner = THIS_MODULE; - csi->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE; - snprintf(csi->sd.name, sizeof(csi->sd.name), "csi"); - - for (i = 0; i < IMX7_CSI_PADS_NUM; i++) - csi->pad[i].flags = (i == IMX7_CSI_PAD_SINK) ? - MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE; - - ret = media_entity_pads_init(&csi->sd.entity, IMX7_CSI_PADS_NUM, - csi->pad); - if (ret < 0) - goto cleanup; - ret = v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd); if (ret) - goto cleanup; + goto media_cleanup; ret = imx7_csi_async_register(csi); if (ret) @@ -1442,8 +1449,7 @@ static int imx7_csi_probe(struct platform_device *pdev) subdev_notifier_cleanup: v4l2_async_nf_unregister(&csi->notifier); v4l2_async_nf_cleanup(&csi->notifier); - -cleanup: +media_cleanup: imx7_csi_media_cleanup(csi); destroy_mutex: