From patchwork Fri Aug 10 14:20:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Miguel Silva X-Patchwork-Id: 143929 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp15639ljj; Fri, 10 Aug 2018 07:21:36 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzE+VP55krmU9JNRd3Qk44q07PIvTo6J7w0A+Da+P+OpIyU4VDIeI2BZdKbrTLIAWRiyPgx X-Received: by 2002:a62:51c6:: with SMTP id f189-v6mr7329651pfb.7.1533910896209; Fri, 10 Aug 2018 07:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533910896; cv=none; d=google.com; s=arc-20160816; b=YFAGu/oSWz7crPfQ5PkL+r/mth5Ua4bUc5UgvIDK5BVeHvqUOt6L6d9wtOkyWi7dgE RGW2rhOnu05sGRHWI63+ou80JH6SE/cuVdcJdOImMNpsQnOEDiG6MfBosSovR0BhHYja cGXEORH+ttTBJxEyVLK/DbDl11lB3MsjJd0V1u2H+iP5re/rErCBKzLksK4n5ZM0YBdr 6v47ypsjDNt602iDjUaUTXC3rhn66RfJOQKkzW3iLwjIRiPIGIxV4gRa8KU4Jn2jIZ2k JMOEgyxW7uk0bf7TmgE/1Z1F7jIRl2/18lssa+1VyuyKDXhdZaDA3ggJrpglnLsrGu/h uThQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=U2EN7UKo0a+xPGYmGkcjiE+t3GmnsxdvvNNYhBmyegI=; b=Un7sKqyohXK6QiFFj0pi+XWmRu1IXPAAABGIi8toQT6veg6UK3n1d6pnX5wjw+kbdD uKpPCEBYOpiEtJQWYNZw5qLVTt0WIGry08reNZvX266M2WcbIDHefQEICyAScljw5PX6 hatxCfz7U3eaFn59weLtj73F6nelEpxgBEwvq7dfcS1stICuPREDqV0IKbfS+7BsJz4H qNvs+wpML1M+uESp2e0Y+RoqWMBjgReDv70XzV9Lm2Y7Sd3LMAE86kNLxXioXe0yI+mu sfkX1xD80JuNd6abPdMIDDp2z/0k1yKX5gFdDu52AJUvWRv75SArUbJOK3vOf0yxCbBx AKXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jGFF20Yy; 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 91-v6si7981107ply.405.2018.08.10.07.21.36; Fri, 10 Aug 2018 07:21:36 -0700 (PDT) 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=jGFF20Yy; 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 S1727718AbeHJQvl (ORCPT + 5 others); Fri, 10 Aug 2018 12:51:41 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:54976 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727519AbeHJQvl (ORCPT ); Fri, 10 Aug 2018 12:51:41 -0400 Received: by mail-wm0-f67.google.com with SMTP id c14-v6so2095741wmb.4 for ; Fri, 10 Aug 2018 07:21:33 -0700 (PDT) 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; bh=U2EN7UKo0a+xPGYmGkcjiE+t3GmnsxdvvNNYhBmyegI=; b=jGFF20YyeTS9jwU2REVlXxnvIw6wG0sJfpMawygpuLha2KdbfwM/NH1bBxMz7UBkbX z81zZN+Tu9LhSD2KSNLYDkx+gyiU3fXeVD1pNjrfxEAA2I+tr5nlZ1kJn2o+HOwL0Zhm taGdSRy7oKu8rBn/0zKjmk+aRZaFWimL+70hU= 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=U2EN7UKo0a+xPGYmGkcjiE+t3GmnsxdvvNNYhBmyegI=; b=p5ORpqf5+lzKY7LH1paibJ8g/1aIgPy505yCb8qInVoYVzLckORexe6buoYUoo7bOH pK0CYckQDs7yKPhKV1R9jVZbjSX/+h6ZimKKCkXQceg8aXT2tKVjORDDeeR+n+SYmN4Y OulgcG3eRctAZC9pcjiBnOmB1pwW7qJDm1N6iaTuvxk/vK51yq2+V5kGlz6bzGLiS08u niVLnEO3ZH8B4gTqqHNL2VxWLSBRN+D4khD3ecURmWRyIVezjwiEtEw1Jc57nc2/EcFb J5SpFDToh/o+KsJtxgka7KHk/I9E6qQcCzWigjCjIYg9H+ki0tIdzra4a/WBmSGlJUJF qlTQ== X-Gm-Message-State: AOUpUlEX+8YTljkV9xTZvio7ne2fW0UKuQEVacYBV1m+2uYcM4GyH0R9 qNFwe2Lm8HY9NVfQrBV0VmugVg== X-Received: by 2002:a1c:ec1b:: with SMTP id k27-v6mr1583665wmh.157.1533910893168; Fri, 10 Aug 2018 07:21:33 -0700 (PDT) Received: from arch-late.local (a109-49-46-234.cpe.netcabo.pt. [109.49.46.234]) by smtp.gmail.com with ESMTPSA id b13-v6sm13077578wrn.17.2018.08.10.07.21.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 07:21:32 -0700 (PDT) From: Rui Miguel Silva To: mchehab@kernel.org, sakari.ailus@linux.intel.com, Philipp Zabel , Rob Herring Cc: linux-media@vger.kernel.org, devel@driverdev.osuosl.org, Fabio Estevam , devicetree@vger.kernel.org, Greg Kroah-Hartman , Ryan Harkin , Rui Miguel Silva Subject: [PATCH v7 01/12] media: staging/imx: refactor imx media device probe Date: Fri, 10 Aug 2018 15:20:34 +0100 Message-Id: <20180810142045.27657-2-rui.silva@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180810142045.27657-1-rui.silva@linaro.org> References: <20180810142045.27657-1-rui.silva@linaro.org> 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 | 88 ++++++----------------- drivers/staging/media/imx/imx-media-of.c | 6 +- drivers/staging/media/imx/imx-media.h | 15 ++++ 4 files changed, 40 insertions(+), 70 deletions(-) -- 2.18.0 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 659420ec4b2e..b06c300d12e0 100644 --- a/drivers/staging/media/imx/imx-media-dev.c +++ b/drivers/staging/media/imx/imx-media-dev.c @@ -107,9 +107,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; @@ -293,7 +293,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; @@ -317,11 +317,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. @@ -365,8 +360,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; @@ -429,10 +424,6 @@ 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 int imx_media_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -440,76 +431,38 @@ 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); - strlcpy(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; - strlcpy(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 dev_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 dev_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); - goto del_int; - } + ret = imx_media_dev_notifier_register(imxmd); + if (ret < 0) + goto del_int; return 0; del_int: imx_media_remove_internal_subdevs(imxmd); -notifier_cleanup: - v4l2_async_notifier_cleanup(&imxmd->notifier); - v4l2_device_unregister(&imxmd->v4l2_dev); -cleanup: - media_device_cleanup(&imxmd->md); + +dev_cleanup: + imx_media_dev_cleanup(imxmd); + return ret; } @@ -522,10 +475,9 @@ 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); + imx_media_dev_notifier_unregister(imxmd); media_device_unregister(&imxmd->md); - media_device_cleanup(&imxmd->md); + imx_media_dev_cleanup(imxmd); return 0; } diff --git a/drivers/staging/media/imx/imx-media-of.c b/drivers/staging/media/imx/imx-media-of.c index 1c9175433ba6..a0020cc7b3f3 100644 --- a/drivers/staging/media/imx/imx-media-of.c +++ b/drivers/staging/media/imx/imx-media-of.c @@ -20,7 +20,8 @@ #include