From patchwork Thu May 17 12:50:22 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: 136146 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp155171lji; Thu, 17 May 2018 05:50:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqPkhZvZy0Dg3GSCoybAx9eRtvKNrEUoz/HLHF6e1ICSKbuFy6Ykpex3Hog6hQRxCd8qZKT X-Received: by 2002:a63:6aca:: with SMTP id f193-v6mr4037215pgc.244.1526561456496; Thu, 17 May 2018 05:50:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526561456; cv=none; d=google.com; s=arc-20160816; b=bADLWdBhOX7B/eYKqaBRnt0aLI9wD8wCwJHN0PVbNDoqFQkTDyDH+KEvLtr1hAl38/ ZM4r0SFIaU+YMeRDUTn45uv3NAJeQdT0OgOneJf00BC2EuaS6lTZENVc/tZQJ0xBDecA /ZWkR9XlI3BaCeO7GpwlioFTm7kgXDN5Ug+jRisYOcTImyqzWuw39vWFMfyDBRL+haKY KN1HZwc2642qURKtsxmQ6bRlq72toun07CbYxsZ5xpIn7VogsLexGkrB3i25hD3O6rBE QdY5kXGkVyAecSLEItmXjUY0XHaef8APrTiVC5DMQ1hMRoHhr/uvUDfKKVl9VMVijA1e eHLw== 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=w9aHiSfchWfoAbxJo0TNdDNDPwSXQNl7/AAzvXm4Axs=; b=bjROZXNjqGE1ItpdO+/ylI8YHLc9I/sG7efUEdrnBFyAEF+axgXfXCoNe7AhPWVOnA DExVS9dP/UqzYm5WfKK1JCsVFAN0LGR23jLz6iBDOTMX7B3kD/d4tZv1Q/hL/r2kQx/a ovRezlFKgObpkT92zLBj3IuadjSblbCaUbarNoGLgtHwFSa2sEFoDLa0SJmtsDjHoCfm 8EZREcOD6D6vkfKTU8O4ybjIxoVad1HaY4BHy+TEJ/OGbnGELrXkscsgwUw3wvET0Iw9 z7mT7+lZVg5dUfvhhtB8eNnNmUGzUBT0GgCMOaspfkv2+biGvo0PyifR7/XqCpFE71Ae mxtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=NnoTkniX; 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=fail (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 a33-v6si4972897pli.275.2018.05.17.05.50.56; Thu, 17 May 2018 05:50:56 -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=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=NnoTkniX; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751520AbeEQMuz (ORCPT + 5 others); Thu, 17 May 2018 08:50:55 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:34830 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751367AbeEQMuy (ORCPT ); Thu, 17 May 2018 08:50:54 -0400 Received: by mail-wr0-f194.google.com with SMTP id i14-v6so5575113wre.2 for ; Thu, 17 May 2018 05:50:53 -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=p2dm/aHknhBfztC+jyzc2KrXgiR5olVtwBimN2bG6eg=; b=NnoTkniXgvcBlzDJkMLRA9p76n4f4W05aRFvFrMNGIVxS9f5ZrwmdxOt16e35+7Etj PN2R2/2SL+yHzfKtF+ImI7exwhHX26LqyQtOZXOacMOyUi1XHRczwTEYUkXissB8Fi3g R3d25r6dfXpgckYO5yScTLNmWoubMcMdcuNJ4= 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=p2dm/aHknhBfztC+jyzc2KrXgiR5olVtwBimN2bG6eg=; b=EiRXVOLBcRIb6mO1QWm6RH8PsIQ8fKCXqINH9KtgXPkw1cd6Id7sl5IndhR6fhrjh0 6ssm2II6YhK5f0KtL5865w9ao7084rdGqa9KVgsRHtC7DRpLK9AjCdwF7fUkxhaxuZEs jZLvYJNoYvY6NJ5Dh7K1+3YUiEbho4BlTakto7aBqqJPKG7xrQuU/KyMnVoIPnLldVN/ dNFhXph43nrqOo9hew5m9/Fq2H8M0mfe3tnl0qEZA6D3a/1xwu17LdlUnp5C+01/Fb8p jxxzn4Cd4eExERZ5yM2XCfhsq2CNOpYVSsfOmGH904idIM6IIkzLRsFQLmuf9gu1B08E G0gA== X-Gm-Message-State: ALKqPwfvcgI6bMVRHV8LyHRAfbg7imKGuFxPFcz5PQHjfvTly6vGJbmT ZSmezttWOAYUEQlCEyIajkOTHA== X-Received: by 2002:adf:aa94:: with SMTP id h20-v6mr4086665wrc.149.1526561452083; Thu, 17 May 2018 05:50:52 -0700 (PDT) Received: from localhost.localdomain ([2001:8a0:6606:9100:b159:5390:182d:7dce]) by smtp.gmail.com with ESMTPSA id 33-v6sm6077665wrs.5.2018.05.17.05.50.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 May 2018 05:50:51 -0700 (PDT) From: Rui Miguel Silva To: mchehab@kernel.org, sakari.ailus@linux.intel.com, Steve Longerbeam , Philipp Zabel , Rob Herring Cc: linux-media@vger.kernel.org, devel@driverdev.osuosl.org, Shawn Guo , Fabio Estevam , devicetree@vger.kernel.org, Greg Kroah-Hartman , Ryan Harkin , Rui Miguel Silva Subject: [PATCH v4 01/12] media: staging/imx: refactor imx media device probe Date: Thu, 17 May 2018 13:50:22 +0100 Message-Id: <20180517125033.18050-2-rui.silva@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180517125033.18050-1-rui.silva@linaro.org> References: <20180517125033.18050-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. Also introduce a new flag to control the presence of IPU or not (imx6/5 has this but imx7 does not). Signed-off-by: Rui Miguel Silva --- drivers/staging/media/imx/Makefile | 1 + .../staging/media/imx/imx-media-dev-common.c | 102 ++++++++++++++++++ drivers/staging/media/imx/imx-media-dev.c | 89 ++++----------- .../staging/media/imx/imx-media-internal-sd.c | 3 + drivers/staging/media/imx/imx-media-of.c | 6 +- drivers/staging/media/imx/imx-media.h | 18 ++++ 6 files changed, 150 insertions(+), 69 deletions(-) create mode 100644 drivers/staging/media/imx/imx-media-dev-common.c -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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-common.c b/drivers/staging/media/imx/imx-media-dev-common.c new file mode 100644 index 000000000000..7e9613ca5b5f --- /dev/null +++ b/drivers/staging/media/imx/imx-media-dev-common.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL +/* + * V4L2 Media Controller Driver for Freescale common i.MX5/6/7 SOC + * + * Copyright (c) 2018 Linaro Ltd + * Copyright (c) 2016 Mentor Graphics Inc. + */ + +#include +#include +#include "imx-media.h" + +static const struct v4l2_async_notifier_operations imx_media_subdev_ops = { + .bound = imx_media_subdev_bound, + .complete = imx_media_probe_complete, +}; + +static const struct media_device_ops imx_media_md_ops = { + .link_notify = imx_media_link_notify, +}; + +struct imx_media_dev *imx_media_dev_init(struct device *dev, bool ipu_present) +{ + struct imx_media_dev *imxmd; + int ret; + + imxmd = devm_kzalloc(dev, sizeof(*imxmd), GFP_KERNEL); + if (!imxmd) + return ERR_PTR(-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; + + imxmd->ipu_present = ipu_present; + + 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); + + return imxmd; + +cleanup: + media_device_cleanup(&imxmd->md); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(imx_media_dev_init); + +int imx_media_dev_notifier_register(struct imx_media_dev *imxmd) +{ + int ret; + + /* no subdevs? just bail */ + if (imxmd->notifier.num_subdevs == 0) { + v4l2_err(&imxmd->v4l2_dev, "no subdevs\n"); + return -ENODEV; + } + + /* 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); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(imx_media_dev_notifier_register); + +void imx_media_dev_cleanup(struct imx_media_dev *imxmd) +{ + v4l2_device_unregister(&imxmd->v4l2_dev); + media_device_cleanup(&imxmd->md); +} +EXPORT_SYMBOL_GPL(imx_media_dev_cleanup); + +void imx_media_dev_notifier_unregister(struct imx_media_dev *imxmd) +{ + v4l2_async_notifier_cleanup(&imxmd->notifier); +} +EXPORT_SYMBOL_GPL(imx_media_dev_notifier_unregister); diff --git a/drivers/staging/media/imx/imx-media-dev.c b/drivers/staging/media/imx/imx-media-dev.c index 7e7bd1c6c81b..6160070b72fb 100644 --- a/drivers/staging/media/imx/imx-media-dev.c +++ b/drivers/staging/media/imx/imx-media-dev.c @@ -87,6 +87,9 @@ static int imx_media_get_ipu(struct imx_media_dev *imxmd, struct ipu_soc *ipu; int ipu_id; + if (!imxmd->ipu_present) + return 0; + ipu = dev_get_drvdata(csi_sd->dev->parent); if (!ipu) { v4l2_err(&imxmd->v4l2_dev, @@ -107,9 +110,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 +296,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 +320,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 +363,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 +427,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,74 +434,36 @@ 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); + imxmd = imx_media_dev_init(dev, true); + 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 (imxmd->notifier.num_subdevs == 0) { - 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); + 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; } @@ -520,10 +476,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-internal-sd.c b/drivers/staging/media/imx/imx-media-internal-sd.c index 0fdc45dbfb76..2bcdc232369a 100644 --- a/drivers/staging/media/imx/imx-media-internal-sd.c +++ b/drivers/staging/media/imx/imx-media-internal-sd.c @@ -238,6 +238,9 @@ int imx_media_create_internal_links(struct imx_media_dev *imxmd, struct media_pad *pad; int i, j, ret; + if (!imxmd->ipu_present) + return 0; + intsd = find_intsd_by_grp_id(sd->grp_id); if (!intsd) return -ENODEV; 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