From patchwork Wed Nov 21 11:15:47 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: 151657 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1790019ljp; Wed, 21 Nov 2018 03:16:30 -0800 (PST) X-Google-Smtp-Source: AJdET5f0MACzUgrRWP+kC/4I0l3MHZ4ER5U67n2HEj0ZqNLIGw2Pp33+kF+FMpCKcceYftVOp7t6 X-Received: by 2002:a62:2781:: with SMTP id n123mr6464277pfn.138.1542798990710; Wed, 21 Nov 2018 03:16:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542798990; cv=none; d=google.com; s=arc-20160816; b=aUT52O/NoSJuv9x3XsfpaG9k/Qp22dO/yOZfCBA39UeCsulg+sZm097HxQs0Jt0EAK iZFthADKtos4zYn/JilLZtjCrpAiumrhVMftE7DwHllyfitwx7xbqsqO6Adnd3gWBpUZ 1eRRCeQFW3sO/npykbDTtMX2Lz3Rx7ToVPQYo6zyf7erFPzIPAr+B6Owt+562wZCW+w1 l9RSJxAvEKJ15c/diwe1gKc8zQck31MjN5J9s2WG0kPaCROQv+FpjHeWPYOgTrNx3M26 +zXbxqoY/rk5NignuZ5dkHrmKU7nYQoqexH+ODbbF0rB45Sb1iGWU36AAPJZle9/gwHL wqlA== 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=EL6C5Zd0xjiByu70BJaMCQ+IIB2yuqxKaUeCRdSD298=; b=ABU/1DfsqTEh+emX8nxZ5JQwAfMQW5JEmsyDDuuFYN+bJMvl5+KDxO5pLkrek4dXuk DPytiYO8p1IHdMMSQPCLhsarhUZHtgccNGGh5IdjTQj9WGmPnweQCk/QQn1cVd9Ia6xJ FIfAFSQTYWnynSgxiQFsVurpkywY6Bmp7sFbo4pOedEHWWNh3ZDc6O0cJcODmvVebwTI dcPzl5s5N8B3L7dWkHLZpAs8EOA/Y1o15aproCGneLlNH4sd9voscMJByTSdPsSN5Nxd 1sqeC1dzdly+vN+1Qh1c1pxSE0+BCAhz8cYF2BTqyzizSuh+RRyUsyX4639ww/N00jQI bCKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cQRLN6WF; 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 n3si9574252pfn.285.2018.11.21.03.16.30; Wed, 21 Nov 2018 03:16:30 -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=cQRLN6WF; 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 S1727486AbeKUVu2 (ORCPT + 6 others); Wed, 21 Nov 2018 16:50:28 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44327 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728045AbeKUVu2 (ORCPT ); Wed, 21 Nov 2018 16:50:28 -0500 Received: by mail-wr1-f65.google.com with SMTP id z5so951486wrt.11 for ; Wed, 21 Nov 2018 03:16:27 -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=EL6C5Zd0xjiByu70BJaMCQ+IIB2yuqxKaUeCRdSD298=; b=cQRLN6WFu/6K9ea2WaBbczqc6RhN2Pa0jPdLFF5vG+hEzhM6efumMiWCf2MerTU1JI G6a6gj6Gi5dzuhajzTx7+f/lONGDPGtlTCvdlAZfhdE8TohBb5jQv2SWvf1r0WaKe1GD KQiIjLwSuM3Od6QBRBpKNVVR9BT5TwDKkHmiQ= 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=EL6C5Zd0xjiByu70BJaMCQ+IIB2yuqxKaUeCRdSD298=; b=qYl28bgghQ5e1APImr9RTweQdLgVismgc/yLDkqqwn9zJqgtwTVoyM6DStFXwwa7pX /kAhxG0mU8MGoJ2LlOdSLs7adnIQ0wFCWfJmrwaLlTfYpmBlkA2VQJCAhIjOhQf2l/cg NIJM2fVVoPSSa8uYh/g3VLBT43ZUayLwj3zaYLUE+6pp1vUbVvIDcYtYQeqvXLm+HMaN 1TsvZb7dUQe8dK1sX6apcNwj0rn+l/5YtPAz+v9+vn5J+wUJSxSim3YpHp/uz2uv7Fnh 4EQlAnBkqQeNN4nhCrYmSReIQhDeTKyyvESlmZLjciyMV4/EMYr8c7T4CClftz5A/nkL 5qAg== X-Gm-Message-State: AA+aEWYPAZ9GVF3OGTU1V6JbgVI0l0kT+rspLjC5mxaizZRo8Y/YwgRX LK6iEaEHYx/9F9GEYgLkhhAzTw== X-Received: by 2002:adf:fe8f:: with SMTP id l15mr5148011wrr.313.1542798987000; Wed, 21 Nov 2018 03:16:27 -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 a125-v6sm771526wmf.8.2018.11.21.03.16.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Nov 2018 03:16:26 -0800 (PST) From: Rui Miguel Silva To: sakari.ailus@linux.intel.com, Philipp Zabel Cc: linux-media@vger.kernel.org, devel@driverdev.osuosl.org, devicetree@vger.kernel.org, Greg Kroah-Hartman , Rui Miguel Silva Subject: [PATCH v8 01/12] media: staging/imx: refactor imx media device probe Date: Wed, 21 Nov 2018 11:15:47 +0000 Message-Id: <20181121111558.10838-2-rui.silva@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181121111558.10838-1-rui.silva@linaro.org> References: <20181121111558.10838-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 | 88 +++++------------------ drivers/staging/media/imx/imx-media-of.c | 6 +- drivers/staging/media/imx/imx-media.h | 15 ++++ 4 files changed, 39 insertions(+), 71 deletions(-) -- 2.19.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 4b344a4a3706..21f65af5c738 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,10 +433,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; @@ -449,76 +440,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); - - 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; - 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 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); + ret = imx_media_dev_notifier_register(imxmd); + if (ret) 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; } @@ -531,10 +482,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 b2e840f96c50..c77d97874d06 100644 --- a/drivers/staging/media/imx/imx-media-of.c +++ b/drivers/staging/media/imx/imx-media-of.c @@ -20,7 +20,8 @@ #include