From patchwork Wed Feb 6 15:13:16 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: 157630 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6524866jaa; Wed, 6 Feb 2019 07:13:40 -0800 (PST) X-Google-Smtp-Source: AHgI3IaElXUTix01PXZXUOfxp6HmZtn23ZFirfFaY4PWUs/wjRiy709elG1Pj6rLaqHTQQvuGkF8 X-Received: by 2002:a17:902:129:: with SMTP id 38mr11245277plb.140.1549466020537; Wed, 06 Feb 2019 07:13:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549466020; cv=none; d=google.com; s=arc-20160816; b=fuhIsULT4ESgPX7IXqMWLuaUUcwCq+wYfPktP6x1sZ7Al/MNqNPUCVTdbJ7EhKL/nZ Yjc1JqLAVdYwZYb6Q2XZuU0isa+w8rHAdEIP3/TA1mIZj/tx+h5Ue+srrjsY0GN8hX4C GzhRGziALkx6Ud145stEGjwv/GuXG/1VIe8pxCayOgDA271Ih9sJorJG9WgddhvWl0PZ orCZIEhMOnYEYeK7o3el7x5wR0QR5XW3XYNuCNnGZ/gupTwoH0/VpnZ5skGy4MY5JhcQ GB02qFRH13Z/7WtY9XET8mmw+TfhXOthJ+3lkvewJo+b15q+G6gt4b2haIBez4HufUZe JCRw== 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=/eTPAy0wTxfYa7EWri5SAsnIE8WsNQNqmAc7vqXUujY=; b=jM1euxJEDbZZ3zV7Bdkywa69j2BFq2uWAPf08jzztNFH9NV2iifkJ76s+2TG3LU5Kv Kt2AuiGMKoS1cv3kv5lzyOrzRftEHIHtbNI7QgZOyvAmL9XEzYR4FW9/HjgnPxxAnS9b UbKzj5HFTz+yZd1bmSt8U5RV7cpknveLMAqfq2zBIbbPUZHuEoh3COIxVOFbh+058MEE QOLqAtitGx/qJGYoTflLb5DPY7bu041CPJhBthJ9uJgu+W4p9Q0GZlN0C6R6IQS6OfhE Wiy/KOH2uQFuv9Y5Mpivmb1WAC/+VfcCF2VP2DCxF3hTAoKLYMGTLoKKCwcjLBtpExVq kSwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i4IyNCDi; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-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 e4si6111576pgk.127.2019.02.06.07.13.40; Wed, 06 Feb 2019 07:13:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-media-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=i4IyNCDi; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-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 S1731141AbfBFPNj (ORCPT + 4 others); Wed, 6 Feb 2019 10:13:39 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37264 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731137AbfBFPNj (ORCPT ); Wed, 6 Feb 2019 10:13:39 -0500 Received: by mail-wr1-f65.google.com with SMTP id c8so1152151wrs.4 for ; Wed, 06 Feb 2019 07:13:37 -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=/eTPAy0wTxfYa7EWri5SAsnIE8WsNQNqmAc7vqXUujY=; b=i4IyNCDik1mNYTUPJd9BBxJSW5kOaGpbRRuZrkeyqf1v+DDFFam1/fvPvgqNB3x+CI C3Tq4MwJprWqrMY2owYDh7/tcPry/OFiuItnTpMVeotAgFLID21CW8IhAq26pCI+Tsv4 Oa/5OUQkCUeK+x5XgJjHrB83yPerGs0aI+G6Q9e5H8pgrROnNcgoh5tWYG1Ogosrsh6Q MYoLSkQMBBwBaCwX5zfOwgr57UhKdEv0yB2tKCgEPH1jZD5aNqHpuAiPVDoHILogXqvY WMIsmm3HCHlnkBJOD8TwO1EGFZKurgSnvZLSE4Rgmr5f4cc0YpPQr2zS9PoecKXnTiXv 1tRQ== 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=/eTPAy0wTxfYa7EWri5SAsnIE8WsNQNqmAc7vqXUujY=; b=I0JmY9onXq+0ODygOXTmrZd5+/rq7B7FvBRP4O5Oj2gtYiMuz7IylZAAz+hfbx7JVn qoI7mEo5PhwFHU1qiQ/IVXhlueesV5NjGd99OasXHWsmN0MTstn5zAOQ7LsxgVeD0EHN vR/FDZatDpDSfKwEi2MmowlMOOhFfT52nqVho8/y8fdqUbRu8gbdWX6VD5gHtxQSboTF mVqn2PN1JnR4MWN+1wfORTBPNXxzNStte10HQABV54Xe70N/9GgLT47LaN6IviyksUoJ QKoGZ3Ija266hAN5oY+lnfZIBl+e67cVWu2tw1FsoU8gnj66uduSV95aCjL8O1/CnyPe BP0Q== X-Gm-Message-State: AHQUAubUNl6LTUp1JxuP6QUVBHJJsllqlFYoFQs14QbPIf8D8wrT3+9E VVNboJZLrGlARl9uXy7j7j1FeA== X-Received: by 2002:a5d:6850:: with SMTP id o16mr8611583wrw.123.1549466016470; Wed, 06 Feb 2019 07:13:36 -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 f22sm11207836wmj.26.2019.02.06.07.13.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 07:13:35 -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 v14 01/13] media: staging/imx: refactor imx media device probe Date: Wed, 6 Feb 2019 15:13:16 +0000 Message-Id: <20190206151328.21629-2-rui.silva@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190206151328.21629-1-rui.silva@linaro.org> References: <20190206151328.21629-1-rui.silva@linaro.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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 + .../staging/media/imx/imx-media-dev-common.c | 90 +++++++++++++++++++ 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 +++ 5 files changed, 127 insertions(+), 70 deletions(-) create mode 100644 drivers/staging/media/imx/imx-media-dev-common.c -- 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-common.c b/drivers/staging/media/imx/imx-media-dev-common.c new file mode 100644 index 000000000000..28bcb31cf6ca --- /dev/null +++ b/drivers/staging/media/imx/imx-media-dev-common.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL +/* + * V4L2 Media Controller Driver for Freescale common i.MX5/6/7 SOC + * + * Copyright (c) 2019 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) +{ + 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; + + mutex_init(&imxmd->mutex); + + imxmd->v4l2_dev.mdev = &imxmd->md; + imxmd->v4l2_dev.notify = imx_media_notify; + 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); + + 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 (list_empty(&imxmd->notifier.asd_list)) { + 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); 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