From patchwork Wed Feb 6 10:25:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Miguel Silva X-Patchwork-Id: 157590 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6240446jaa; Wed, 6 Feb 2019 02:25:52 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia7pvJNdZpGtk5N37/yGcJNfGyJyiL2bpht11497HuLdTfuLTZGFZuJa2DTx6ZdPbLkBx4+ X-Received: by 2002:aa7:8759:: with SMTP id g25mr724771pfo.248.1549448752726; Wed, 06 Feb 2019 02:25:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549448752; cv=none; d=google.com; s=arc-20160816; b=P9ZG7k0Bl/WY4Z1VSIoyhf63nONMh5p3HqA3ObeL7MVhNy0cg2rGup1843CaHmSaVw rxQa1Rg8OEyLMMC/547qt936Te9b7DC6l/JEdwC56s6NFolUWOBWdlsQ2oFtu7T0kWPe TTh7yEQU9J/qMLMwIAPdZ6Y15+bBZ0KOP2o3XaqAbfIyZNKcsz1HTgalP/wFS4qbZfSK b1sdudAOv3oQaK7b/d4xuByyT81wGWVs1ii+fizjZwMDaGOauRdjzvzZgnBNPER7Unz/ wmZxJWmpo2kM6Vbfbf32Gf8AcuHKDcY0RoJXURaZ8dKqTzeiB2ImpIFbfVonH21150iH w9aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P/gzA+CFvac5Yo9z/sb+N633t3yMqNwQHaNZtBPv8po=; b=u7ufMLWMGbOI8lKhI4gwN3zJ6/DJazBdofgqOzzyHyYysYSJCy94DXn6J2AumroZTE 0fyfIms+o/tpnrndiP/gT9WSImxaCwxL/QrQyF7AeBPeq+Xov7+rEbVkWjVMqzdWzoDA hm7nF63FTSJBzJlYCmVabAhyP+DCRuq0Rsc7fIu0/BgOSUXn3LemNY04OhCeJ7Hqz6z5 B5TiFB7pejH7IaQ+HG9CXCYdb7n/q2EJfXz2ipSlJ6tQkf6oj2cpDHR5pre3/+NOpYOQ g03KFI/wKZ/ZY2NEDpGt/vpGJslrAh6axKI2I81M3T6eysqoLBRoq9dHvgCpwiIIH0Ui roLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZTRE1Mh5; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si5512986pll.219.2019.02.06.02.25.52; Wed, 06 Feb 2019 02:25:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZTRE1Mh5; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729248AbfBFKZv (ORCPT + 7 others); Wed, 6 Feb 2019 05:25:51 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42948 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729264AbfBFKZv (ORCPT ); Wed, 6 Feb 2019 05:25:51 -0500 Received: by mail-wr1-f65.google.com with SMTP id q18so6873554wrx.9 for ; Wed, 06 Feb 2019 02:25:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P/gzA+CFvac5Yo9z/sb+N633t3yMqNwQHaNZtBPv8po=; b=ZTRE1Mh5o1npZAeM9dOxYkcz/sq5Z77WY+M1R60bR9Wav75LYewsWEPUtHCBsZMBjY h2skCGnkq4y/D3fAx+/aUrIourQaS7PjOp6fyUnxS2/3NtNbr4NP3PJtQVTrO7uoNc7T 0tbDYnbBUZ3TVwEY0YBF9HdEN4SifQtGnNo8n20CUMyx0N7ZduD4JTRLMucpNAyPFdZG bqmKnl6qJYcdre7Blom8FpumaeWz1Jnc7rPtkIhFLuBHKvtdjE+BLqQ44le9YFdsQO55 fkM2zV4DcNjeKI8B3oAhJaKTX23pqhUMq8ks4pbrKAy2XlXAmxzDygmaqi3vC9EW0+fm b08g== 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:mime-version:content-transfer-encoding; bh=P/gzA+CFvac5Yo9z/sb+N633t3yMqNwQHaNZtBPv8po=; b=RqJKnYWYhf/b3RjBlaVNCNQPxWRIR7CsxrTQOsZq1Z+fHsrXFz0z61ivj6mVfQ0GHf qmzASJ+kcp4rxVjubgKMomDqzaT8kDNvnvvmi1WolJjvYhjff/qyPGMPQQIHRJDxv6W3 QU4fx4JsPWI+ha3ujx4d4N4lbzj5JpNma+qNQ1LBmikydJoifdYmX036aXJc+XDfvtnF hILrDd7r18bRlqQqTIjdE7FRRrfcow9c8uMXfnYoDEEprPOVHJhD6C0/Yn+auGgag2pF kjQoG4GumWcHo04j/8X+0zJkNrkeXYq0eigxYzwwFVyohRdh/Xvm7Ip2f01PdjqDEzs+ n4tw== X-Gm-Message-State: AHQUAuYHPNw/1KCrMdZTQ4CXarRmNYTWKWus5PGkYaOkf48HNsBrkFTc +JutDw3J9C6B0blYPwn5Cjx7DQ== X-Received: by 2002:adf:fbc7:: with SMTP id d7mr7038600wrs.275.1549448749618; Wed, 06 Feb 2019 02:25:49 -0800 (PST) Received: from arch-late.local (a109-49-46-234.cpe.netcabo.pt. [109.49.46.234]) by smtp.gmail.com with ESMTPSA id i192sm18149631wmg.7.2019.02.06.02.25.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 02:25:49 -0800 (PST) From: Rui Miguel Silva To: sakari.ailus@linux.intel.com, Steve Longerbeam , Hans Verkuil , Philipp Zabel Cc: linux-media@vger.kernel.org, devel@driverdev.osuosl.org, devicetree@vger.kernel.org, Greg Kroah-Hartman , Rui Miguel Silva Subject: [PATCH v13 01/13] media: staging/imx: refactor imx media device probe Date: Wed, 6 Feb 2019 10:25:10 +0000 Message-Id: <20190206102522.29212-2-rui.silva@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190206102522.29212-1-rui.silva@linaro.org> References: <20190206102522.29212-1-rui.silva@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Refactor and move media device initialization code to a new common module, so it can be used by other devices, this will allow for example a near to introduce imx7 CSI driver, to use this media device. Signed-off-by: Rui Miguel Silva --- drivers/staging/media/imx/Makefile | 1 + drivers/staging/media/imx/imx-media-dev.c | 86 +++++------------------ drivers/staging/media/imx/imx-media-of.c | 6 +- drivers/staging/media/imx/imx-media.h | 14 ++++ 4 files changed, 37 insertions(+), 70 deletions(-) -- 2.20.1 diff --git a/drivers/staging/media/imx/Makefile b/drivers/staging/media/imx/Makefile index 698a4210316e..a30b3033f9a3 100644 --- a/drivers/staging/media/imx/Makefile +++ b/drivers/staging/media/imx/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 imx-media-objs := imx-media-dev.o imx-media-internal-sd.o imx-media-of.o +imx-media-objs += imx-media-dev-common.o imx-media-common-objs := imx-media-utils.o imx-media-fim.o imx-media-ic-objs := imx-ic-common.o imx-ic-prp.o imx-ic-prpencvf.o diff --git a/drivers/staging/media/imx/imx-media-dev.c b/drivers/staging/media/imx/imx-media-dev.c index 25e916562c66..c42bddd78906 100644 --- a/drivers/staging/media/imx/imx-media-dev.c +++ b/drivers/staging/media/imx/imx-media-dev.c @@ -116,9 +116,9 @@ static int imx_media_get_ipu(struct imx_media_dev *imxmd, } /* async subdev bound notifier */ -static int imx_media_subdev_bound(struct v4l2_async_notifier *notifier, - struct v4l2_subdev *sd, - struct v4l2_async_subdev *asd) +int imx_media_subdev_bound(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *sd, + struct v4l2_async_subdev *asd) { struct imx_media_dev *imxmd = notifier2dev(notifier); int ret = 0; @@ -302,7 +302,7 @@ static int imx_media_create_pad_vdev_lists(struct imx_media_dev *imxmd) } /* async subdev complete notifier */ -static int imx_media_probe_complete(struct v4l2_async_notifier *notifier) +int imx_media_probe_complete(struct v4l2_async_notifier *notifier) { struct imx_media_dev *imxmd = notifier2dev(notifier); int ret; @@ -326,11 +326,6 @@ static int imx_media_probe_complete(struct v4l2_async_notifier *notifier) return media_device_register(&imxmd->md); } -static const struct v4l2_async_notifier_operations imx_media_subdev_ops = { - .bound = imx_media_subdev_bound, - .complete = imx_media_probe_complete, -}; - /* * adds controls to a video device from an entity subdevice. * Continues upstream from the entity's sink pads. @@ -374,8 +369,8 @@ static int imx_media_inherit_controls(struct imx_media_dev *imxmd, return ret; } -static int imx_media_link_notify(struct media_link *link, u32 flags, - unsigned int notification) +int imx_media_link_notify(struct media_link *link, u32 flags, + unsigned int notification) { struct media_entity *source = link->source->entity; struct imx_media_pad_vdev *pad_vdev; @@ -438,13 +433,8 @@ static int imx_media_link_notify(struct media_link *link, u32 flags, return ret; } -static const struct media_device_ops imx_media_md_ops = { - .link_notify = imx_media_link_notify, -}; - -static void imx_media_notify(struct v4l2_subdev *sd, - unsigned int notification, - void *arg) +void imx_media_notify(struct v4l2_subdev *sd, unsigned int notification, + void *arg) { struct media_entity *entity = &sd->entity; int i; @@ -472,77 +462,37 @@ static int imx_media_probe(struct platform_device *pdev) struct imx_media_dev *imxmd; int ret; - imxmd = devm_kzalloc(dev, sizeof(*imxmd), GFP_KERNEL); - if (!imxmd) - return -ENOMEM; - - dev_set_drvdata(dev, imxmd); - - strscpy(imxmd->md.model, "imx-media", sizeof(imxmd->md.model)); - imxmd->md.ops = &imx_media_md_ops; - imxmd->md.dev = dev; - - mutex_init(&imxmd->mutex); - - imxmd->v4l2_dev.mdev = &imxmd->md; - imxmd->v4l2_dev.notify = imx_media_notify; - strscpy(imxmd->v4l2_dev.name, "imx-media", - sizeof(imxmd->v4l2_dev.name)); - - media_device_init(&imxmd->md); - - ret = v4l2_device_register(dev, &imxmd->v4l2_dev); - if (ret < 0) { - v4l2_err(&imxmd->v4l2_dev, - "Failed to register v4l2_device: %d\n", ret); - goto cleanup; - } - - dev_set_drvdata(imxmd->v4l2_dev.dev, imxmd); - - INIT_LIST_HEAD(&imxmd->vdev_list); - - v4l2_async_notifier_init(&imxmd->notifier); + imxmd = imx_media_dev_init(dev); + if (IS_ERR(imxmd)) + return PTR_ERR(imxmd); ret = imx_media_add_of_subdevs(imxmd, node); if (ret) { v4l2_err(&imxmd->v4l2_dev, "add_of_subdevs failed with %d\n", ret); - goto notifier_cleanup; + goto cleanup; } ret = imx_media_add_internal_subdevs(imxmd); if (ret) { v4l2_err(&imxmd->v4l2_dev, "add_internal_subdevs failed with %d\n", ret); - goto notifier_cleanup; - } - - /* no subdevs? just bail */ - if (list_empty(&imxmd->notifier.asd_list)) { - ret = -ENODEV; - goto notifier_cleanup; + goto cleanup; } - /* prepare the async subdev notifier and register it */ - imxmd->notifier.ops = &imx_media_subdev_ops; - ret = v4l2_async_notifier_register(&imxmd->v4l2_dev, - &imxmd->notifier); - if (ret) { - v4l2_err(&imxmd->v4l2_dev, - "v4l2_async_notifier_register failed with %d\n", ret); + ret = imx_media_dev_notifier_register(imxmd); + if (ret) goto del_int; - } return 0; del_int: imx_media_remove_internal_subdevs(imxmd); -notifier_cleanup: +cleanup: v4l2_async_notifier_cleanup(&imxmd->notifier); v4l2_device_unregister(&imxmd->v4l2_dev); -cleanup: media_device_cleanup(&imxmd->md); + return ret; } @@ -556,8 +506,8 @@ static int imx_media_remove(struct platform_device *pdev) v4l2_async_notifier_unregister(&imxmd->notifier); imx_media_remove_internal_subdevs(imxmd); v4l2_async_notifier_cleanup(&imxmd->notifier); - v4l2_device_unregister(&imxmd->v4l2_dev); media_device_unregister(&imxmd->md); + v4l2_device_unregister(&imxmd->v4l2_dev); media_device_cleanup(&imxmd->md); return 0; diff --git a/drivers/staging/media/imx/imx-media-of.c b/drivers/staging/media/imx/imx-media-of.c index a01327f6e045..03446335ac03 100644 --- a/drivers/staging/media/imx/imx-media-of.c +++ b/drivers/staging/media/imx/imx-media-of.c @@ -20,7 +20,8 @@ #include