From patchwork Sat Sep 29 19:54:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10620969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B07FC15A6 for ; Sat, 29 Sep 2018 19:54:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A069A29BE1 for ; Sat, 29 Sep 2018 19:54:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94C5029C2A; Sat, 29 Sep 2018 19:54:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3484229BE1 for ; Sat, 29 Sep 2018 19:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727723AbeI3CYR (ORCPT ); Sat, 29 Sep 2018 22:24:17 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38051 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726999AbeI3CYQ (ORCPT ); Sat, 29 Sep 2018 22:24:16 -0400 Received: by mail-pg1-f194.google.com with SMTP id r77-v6so6772377pgr.5; Sat, 29 Sep 2018 12:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vhmN50C9sktsUnQ0DqCK715HpG76rwFyWm3Q6vCbPtY=; b=mO3FyjyYptjEAJ++6jXEHZN5VdartMJnHMu3KHKwOYVc4SBx4ELpPDcLOxgVowrXvE mowgSPf/sMuaEiXe2VBBSjETuEwvCf3r4aWcQiwpv976z1mVckU6DREGYTx+7dMJYmTI ePKdUT0KxC0G+gI8hAQVsGfrnGrjQhh5D7YvNhA80TSLOoO+kj3qg8dOFQtQ2R8D8v7p CzdFe9FS/cccpX8Ij/0zxkhBolUoCyb3vyLbU8X4Gw2YPOIGwtllOfK+8DO5+jB20AkK kc/vPirqe9gmkrFOZLXaUkFo9nOj5RhJSTI0T6Vi1kSsPrVvAwwZxibh8sauqZwaaVRD IsaA== 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=vhmN50C9sktsUnQ0DqCK715HpG76rwFyWm3Q6vCbPtY=; b=L02x+fZpWd+SAF0aQkifYJDsYKSiX+z2s0Pe+V+c8C/SuarKeiN6K9LNvKFOqT3NBM gI/DTnZ9Dg1ZKE6n5quVJc3ILy7HX2W6jbOESCaHZsrOsKgfi+iM55Sk6ICZ2eUVVjsI gCRMnXafj7ovKgQV5eRvtJA4UJ7UnM1ICTZ7xXTCMkocf39Kf9bdirk7Q7Ip/a9Gt0iS Gl7HujfCrbZHWL4g3W9jM4RTUOmse1ls6wI+wh0chhP2gzYCE+3ZEWd+J7kxC2pc3mR4 09loCjU/l5xJVR//G5CrtxFk99o4Yn8oXtAewnwq32aXQ93ZtkKgIdYHoibZ5NArTjxM 3SQw== X-Gm-Message-State: ABuFfogt2+I7S0zYo8GqeoGkbXeLp7pfEUqXAnEHzP59WHscfzCzsW5/ H8SPekLvCNKg7s3wOeph2mU22lFV X-Google-Smtp-Source: ACcGV60zRyZPccSUNHc1UCET1WgAxAMrI78O/PKIzcqJQmspSyx4lGHKfceliUBtCzF/vHbRJkDluA== X-Received: by 2002:a63:1c1b:: with SMTP id c27-v6mr3906619pgc.351.1538250873709; Sat, 29 Sep 2018 12:54:33 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:32 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Mauro Carvalho Chehab , Sakari Ailus , Hans Verkuil , =?utf-8?q?Niklas_S=C3=B6derlund?= , Sebastian Reichel , Jacopo Mondi , Tomasz Figa , linux-kernel@vger.kernel.org (open list) Subject: [RESEND PATCH v7 01/17] media: v4l2-fwnode: ignore endpoints that have no remote port parent Date: Sat, 29 Sep 2018 12:54:04 -0700 Message-Id: <20180929195420.28579-2-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Documentation/devicetree/bindings/media/video-interfaces.txt states that the 'remote-endpoint' property is optional. So v4l2_async_notifier_fwnode_parse_endpoint() should not return error if the endpoint has no remote port parent. Just ignore the endpoint, skip adding an asd to the notifier and return 0. __v4l2_async_notifier_parse_fwnode_endpoints() will then continue parsing the remaining port endpoints of the device. Signed-off-by: Steve Longerbeam Acked-by: Hans Verkuil --- Changes since v6: - none Changes since v5: - none Changes since v4: - none Changes since v3: - none Changes since v2: - none Changes since v1: - don't pass an empty endpoint to the parse_endpoint callback, v4l2_async_notifier_fwnode_parse_endpoint() now just ignores them and returns success. The current users of v4l2_async_notifier_parse_fwnode_endpoints() (omap3isp, rcar-vin, intel-ipu3) no longer need modification. --- drivers/media/v4l2-core/v4l2-fwnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c index 169bdbb1f61a..0b8c736b1606 100644 --- a/drivers/media/v4l2-core/v4l2-fwnode.c +++ b/drivers/media/v4l2-core/v4l2-fwnode.c @@ -367,7 +367,7 @@ static int v4l2_async_notifier_fwnode_parse_endpoint( fwnode_graph_get_remote_port_parent(endpoint); if (!asd->match.fwnode) { dev_warn(dev, "bad remote port parent\n"); - ret = -EINVAL; + ret = -ENOTCONN; goto out_err; } From patchwork Sat Sep 29 19:54:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10621003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D9BA415A6 for ; Sat, 29 Sep 2018 19:56:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C81E629C1F for ; Sat, 29 Sep 2018 19:56:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB9EA29C52; Sat, 29 Sep 2018 19:56:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 414B529C1F for ; Sat, 29 Sep 2018 19:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727883AbeI3CYU (ORCPT ); Sat, 29 Sep 2018 22:24:20 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37249 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726999AbeI3CYU (ORCPT ); Sat, 29 Sep 2018 22:24:20 -0400 Received: by mail-pf1-f194.google.com with SMTP id x26-v6so6506254pfn.4; Sat, 29 Sep 2018 12:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BfzJnIzqNRTgDaERy8jcbXwneJrpDpJvjf2jAJbgtxI=; b=oO+MexWPsemsxRyUTBAGV18JtTpYL1yOH+WXfwlAR9ZceiFxg3i9WDx7L4aXQxs9PF 3V6ohO/kuB0XE+UP4TWb70rLOIaZYklrqpXufnux7QEt3yI0bXJ89W9Wo78qFu4IqUAq cKE65azi+zIRLffSycbsw/RA4bfYx8QukZPvwiSLv1p3TL+Z45uNjGm4MNBqeG6IN91K Pg2XHLVqvPmKml9X5ySX8Jr1rMAn8sIZ8fX6cRBsIxhouxbqPx4j0YyWWJR/hhMZYl3O EcualMemuKBG0MbEBVUvq8NaaRtrK4zi5uzaa0xkRhZcRkC2Om+RxUokuapNxG71hE8n FhEQ== 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=BfzJnIzqNRTgDaERy8jcbXwneJrpDpJvjf2jAJbgtxI=; b=BEi8BoeKnvWhc/ZpZgiffIEBN3G3QLzg4hMaB/gOSMlYUJRrFnv+E1cNs1x8rtRWKg F8Emj19ZQwFL0v4Om+/zsLCzLeCHDB8BgQXBHqkOXn23RXNYIbEUg0qnfz+9MTZ+r7F9 jk5iYSzaH5rhkC6hW2yTf0HNVBKa2v4Jd2oz5+GYXaTpaUumGeKOegQliF3NKuvOjkNm EKELO+NPOnQpiWbLq170tIxfgb/Hp8qR8a8FnkfmW+qPBwmqS89CKL1a1JhzxZdRl6v0 1D+OdNe6lWt8J8S2eH6bmNd8MkEySVYumNka7eCNX2PReEKptrS9vBwsFw8GfF/gOf1W +vkg== X-Gm-Message-State: ABuFfogG2xbfvYlYAy0EYFtP1iMZDRQKQdg427HxTqfild381NvV7jUP +D5GSiSKHUs05+gc7o9qVj9i6brK X-Google-Smtp-Source: ACcGV61QAQR25h/NJeYqLsXtUHRWt7joCscny7hMuJRET/Vsw+bC2qbMc8vTp6+cLVM+kPnaRnmo+Q== X-Received: by 2002:a17:902:780d:: with SMTP id p13-v6mr4204037pll.96.1538250876846; Sat, 29 Sep 2018 12:54:36 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:35 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Mauro Carvalho Chehab , =?utf-8?q?Niklas_S=C3=B6derlund?= , Sakari Ailus , Sebastian Reichel , Hans Verkuil , linux-kernel@vger.kernel.org (open list) Subject: [RESEND PATCH v7 02/17] media: v4l2: async: Allow searching for asd of any type Date: Sat, 29 Sep 2018 12:54:05 -0700 Message-Id: <20180929195420.28579-3-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Generalize v4l2_async_notifier_fwnode_has_async_subdev() to allow searching for any type of async subdev, not just fwnodes. Rename to v4l2_async_notifier_has_async_subdev() and pass it an asd pointer. Signed-off-by: Steve Longerbeam --- Changes since v6: - elaborate on comment for asd_equal(), suggested by Mauro Chehab. - whitespace checkpatch fixes, suggested by Mauro. - made an error message more clear in __v4l2_async_notifier_register(), suggested by Mauro. Changes since v5: - none Changes since v4: - none Changes since v3: - removed TODO to support asd compare with CUSTOM match type in asd_equal(). Changes since v2: - code optimization in asd_equal(), and remove unneeded braces, suggested by Sakari Ailus. Changes since v1: - none --- drivers/media/v4l2-core/v4l2-async.c | 77 +++++++++++++++++----------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 2b08d03b251d..f09d354b96a0 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -124,6 +124,31 @@ static struct v4l2_async_subdev *v4l2_async_find_match( return NULL; } +/* Compare two async sub-device descriptors for equivalence */ +static bool asd_equal(struct v4l2_async_subdev *asd_x, + struct v4l2_async_subdev *asd_y) +{ + if (asd_x->match_type != asd_y->match_type) + return false; + + switch (asd_x->match_type) { + case V4L2_ASYNC_MATCH_DEVNAME: + return strcmp(asd_x->match.device_name, + asd_y->match.device_name) == 0; + case V4L2_ASYNC_MATCH_I2C: + return asd_x->match.i2c.adapter_id == + asd_y->match.i2c.adapter_id && + asd_x->match.i2c.address == + asd_y->match.i2c.address; + case V4L2_ASYNC_MATCH_FWNODE: + return asd_x->match.fwnode == asd_y->match.fwnode; + default: + break; + } + + return false; +} + /* Find the sub-device notifier registered by a sub-device driver. */ static struct v4l2_async_notifier *v4l2_async_find_subdev_notifier( struct v4l2_subdev *sd) @@ -308,29 +333,23 @@ static void v4l2_async_notifier_unbind_all_subdevs( notifier->parent = NULL; } -/* See if an fwnode can be found in a notifier's lists. */ -static bool __v4l2_async_notifier_fwnode_has_async_subdev( - struct v4l2_async_notifier *notifier, struct fwnode_handle *fwnode) +/* See if an async sub-device can be found in a notifier's lists. */ +static bool +__v4l2_async_notifier_has_async_subdev(struct v4l2_async_notifier *notifier, + struct v4l2_async_subdev *asd) { - struct v4l2_async_subdev *asd; + struct v4l2_async_subdev *asd_y; struct v4l2_subdev *sd; - list_for_each_entry(asd, ¬ifier->waiting, list) { - if (asd->match_type != V4L2_ASYNC_MATCH_FWNODE) - continue; - - if (asd->match.fwnode == fwnode) + list_for_each_entry(asd_y, ¬ifier->waiting, list) + if (asd_equal(asd, asd_y)) return true; - } list_for_each_entry(sd, ¬ifier->done, async_list) { if (WARN_ON(!sd->asd)) continue; - if (sd->asd->match_type != V4L2_ASYNC_MATCH_FWNODE) - continue; - - if (sd->asd->match.fwnode == fwnode) + if (asd_equal(asd, sd->asd)) return true; } @@ -338,32 +357,29 @@ static bool __v4l2_async_notifier_fwnode_has_async_subdev( } /* - * Find out whether an async sub-device was set up for an fwnode already or + * Find out whether an async sub-device was set up already or * whether it exists in a given notifier before @this_index. */ -static bool v4l2_async_notifier_fwnode_has_async_subdev( - struct v4l2_async_notifier *notifier, struct fwnode_handle *fwnode, - unsigned int this_index) +static bool +v4l2_async_notifier_has_async_subdev(struct v4l2_async_notifier *notifier, + struct v4l2_async_subdev *asd, + unsigned int this_index) { unsigned int j; lockdep_assert_held(&list_lock); - /* Check that an fwnode is not being added more than once. */ + /* Check that an asd is not being added more than once. */ for (j = 0; j < this_index; j++) { - struct v4l2_async_subdev *asd = notifier->subdevs[this_index]; - struct v4l2_async_subdev *other_asd = notifier->subdevs[j]; + struct v4l2_async_subdev *asd_y = notifier->subdevs[j]; - if (other_asd->match_type == V4L2_ASYNC_MATCH_FWNODE && - asd->match.fwnode == - other_asd->match.fwnode) + if (asd_equal(asd, asd_y)) return true; } - /* Check than an fwnode did not exist in other notifiers. */ + /* Check that an asd does not exist in other notifiers. */ list_for_each_entry(notifier, ¬ifier_list, list) - if (__v4l2_async_notifier_fwnode_has_async_subdev( - notifier, fwnode)) + if (__v4l2_async_notifier_has_async_subdev(notifier, asd)) return true; return false; @@ -392,12 +408,11 @@ static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier) case V4L2_ASYNC_MATCH_CUSTOM: case V4L2_ASYNC_MATCH_DEVNAME: case V4L2_ASYNC_MATCH_I2C: - break; case V4L2_ASYNC_MATCH_FWNODE: - if (v4l2_async_notifier_fwnode_has_async_subdev( - notifier, asd->match.fwnode, i)) { + if (v4l2_async_notifier_has_async_subdev(notifier, + asd, i)) { dev_err(dev, - "fwnode has already been registered or in notifier's subdev list\n"); + "subdev descriptor already listed in this or other notifiers\n"); ret = -EEXIST; goto err_unlock; } From patchwork Sat Sep 29 19:54:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10621001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E143216B1 for ; Sat, 29 Sep 2018 19:56:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D15EA29B5B for ; Sat, 29 Sep 2018 19:56:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C58B129C52; Sat, 29 Sep 2018 19:56:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02A4C29B5B for ; Sat, 29 Sep 2018 19:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728087AbeI3CYX (ORCPT ); Sat, 29 Sep 2018 22:24:23 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38056 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726999AbeI3CYX (ORCPT ); Sat, 29 Sep 2018 22:24:23 -0400 Received: by mail-pg1-f193.google.com with SMTP id r77-v6so6772461pgr.5; Sat, 29 Sep 2018 12:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SdColWhuoxh5iOQR8lDZAZXzz1nID/+dREPu5z8xj0s=; b=NtZTLKz6cnSXC9xoISjpe/sOuiZTEgs63IB78hP+Ih1zETBGHqmYgYW7vyHr3/yquT w/xD+Uvtv7A9XatS0+bi3CZJ8pZtTZ8ATir2AMUXH54tUSg4LkjmQXf+WeC8I84WrmtN VCzHITX6Enm0oNmQihrHIZ65GbZy9F47me3mY+RAmF0ophrLk/Ppz6rqaQPTz41nJl7c XRF4r8cPnVRl9oP1gDxfb+gYnojJp065eeF5G5N1CiIzFDKW/DA7I9PIGLfXHNYOSimb dvDiEgpBlZDovpBd+Nny25WBjAlLgazuWiow9T/fi4msVsALpr63WxJuuHCfA5B5XS6h 4Ytg== 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=SdColWhuoxh5iOQR8lDZAZXzz1nID/+dREPu5z8xj0s=; b=a6kxUpiy4IMUogF/34jEBGpxYrJkHYwACtiyPyCPgElUcWG0XtMPgL2oW/OrhXqujJ DPDFVXY1o6PetJJwgJWhhRgJIjiqIpqrSr0RorA7bHMQcA+Q/DXPj3f5fxYfuDb44T7V 9T6Qt4PluvSv4xQ7LDfZGLzCKrq9ctBtY94IU6gVl5wRXPNvr+87gWwNvmzIxCBBTDTN BBR5beMdUVUnwUrvp8L+Td0vTb+D1Epx8ee7XkCjWOra8YNOn9CjWyPoUA0txbKf05hy 0RneJZ02xn3a3VfOA2Ry8/Xg9pFvjaPW9IS+9yzXLElESWhwkQjDD+6tp3ubZzZ9sb2l B0Pw== X-Gm-Message-State: ABuFfoh3ArevEIuJ6v5HUYLrteI69pN+IPh3O4ylOAO+igR7o8njR+Oc KMFhzdrldehiyf4Ks+N20VRrBbaB X-Google-Smtp-Source: ACcGV63ERvXB41MM62Cb4UV6nj5gu4QaXipdiwm3e+9o+X45WqztHqh1kbwi/t1Tu88AMHkJNOoP+g== X-Received: by 2002:a63:1624:: with SMTP id w36-v6mr4000697pgl.409.1538250879996; Sat, 29 Sep 2018 12:54:39 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:39 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Mauro Carvalho Chehab , =?utf-8?q?Niklas_S=C3=B6derlund?= , Sakari Ailus , Hans Verkuil , Sebastian Reichel , linux-kernel@vger.kernel.org (open list) Subject: [RESEND PATCH v7 03/17] media: v4l2: async: Add v4l2_async_notifier_add_subdev Date: Sat, 29 Sep 2018 12:54:06 -0700 Message-Id: <20180929195420.28579-4-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks that no other equivalent asd's have already been added to this notifier's asd list, or to other registered notifier's waiting or done lists, and increments num_subdevs. v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs array, otherwise it would have to re-allocate the array every time the function was called. In place of the subdevs array, the function adds the newly allocated asd to a new master asd_list. The function will return error with a WARN() if it is ever called with the subdevs array allocated. Drivers are now required to call a v4l2_async_notifier_init(), before the first call to v4l2_async_notifier_add_subdev(), in order to initialize the asd_list. In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(), and v4l2_async_notifier_cleanup(), maintain backward compatibility with the subdevs array, by alternatively operate on the subdevs array or a non-empty notifier->asd_list. Signed-off-by: Steve Longerbeam --- Changes since v6: - add "already listed asd" message from __v4l2_async_notifier_register() to v4l2_async_notifier_asd_valid() as a debug message. Changes since v5: - export v4l2_async_notifier_init() which must be called by drivers. Suggested by Sakari Ailus. Changes since v4: - none Changes since v3: - init notifier lists after the sanity checks. Changes since v2: - add a NULL asd pointer check to v4l2_async_notifier_asd_valid(). Changes since v1: - none --- drivers/media/v4l2-core/v4l2-async.c | 191 +++++++++++++++++++++------ include/media/v4l2-async.h | 34 ++++- 2 files changed, 182 insertions(+), 43 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index f09d354b96a0..7925875d09b7 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -365,16 +365,26 @@ v4l2_async_notifier_has_async_subdev(struct v4l2_async_notifier *notifier, struct v4l2_async_subdev *asd, unsigned int this_index) { + struct v4l2_async_subdev *asd_y; unsigned int j; lockdep_assert_held(&list_lock); /* Check that an asd is not being added more than once. */ - for (j = 0; j < this_index; j++) { - struct v4l2_async_subdev *asd_y = notifier->subdevs[j]; - - if (asd_equal(asd, asd_y)) - return true; + if (notifier->subdevs) { + for (j = 0; j < this_index; j++) { + asd_y = notifier->subdevs[j]; + if (asd_equal(asd, asd_y)) + return true; + } + } else { + j = 0; + list_for_each_entry(asd_y, ¬ifier->asd_list, asd_list) { + if (j++ >= this_index) + break; + if (asd_equal(asd, asd_y)) + return true; + } } /* Check that an asd does not exist in other notifiers. */ @@ -385,10 +395,48 @@ v4l2_async_notifier_has_async_subdev(struct v4l2_async_notifier *notifier, return false; } -static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier) +static int v4l2_async_notifier_asd_valid(struct v4l2_async_notifier *notifier, + struct v4l2_async_subdev *asd, + unsigned int this_index) { struct device *dev = notifier->v4l2_dev ? notifier->v4l2_dev->dev : NULL; + + if (!asd) + return -EINVAL; + + switch (asd->match_type) { + case V4L2_ASYNC_MATCH_CUSTOM: + case V4L2_ASYNC_MATCH_DEVNAME: + case V4L2_ASYNC_MATCH_I2C: + case V4L2_ASYNC_MATCH_FWNODE: + if (v4l2_async_notifier_has_async_subdev(notifier, asd, + this_index)) { + dev_dbg(dev, "subdev descriptor already listed in this or other notifiers\n"); + return -EEXIST; + } + break; + default: + dev_err(dev, "Invalid match type %u on %p\n", + asd->match_type, asd); + return -EINVAL; + } + + return 0; +} + +void v4l2_async_notifier_init(struct v4l2_async_notifier *notifier) +{ + mutex_lock(&list_lock); + + INIT_LIST_HEAD(¬ifier->asd_list); + + mutex_unlock(&list_lock); +} +EXPORT_SYMBOL(v4l2_async_notifier_init); + +static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier) +{ struct v4l2_async_subdev *asd; int ret; int i; @@ -401,29 +449,25 @@ static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier) mutex_lock(&list_lock); - for (i = 0; i < notifier->num_subdevs; i++) { - asd = notifier->subdevs[i]; + if (notifier->subdevs) { + for (i = 0; i < notifier->num_subdevs; i++) { + asd = notifier->subdevs[i]; - switch (asd->match_type) { - case V4L2_ASYNC_MATCH_CUSTOM: - case V4L2_ASYNC_MATCH_DEVNAME: - case V4L2_ASYNC_MATCH_I2C: - case V4L2_ASYNC_MATCH_FWNODE: - if (v4l2_async_notifier_has_async_subdev(notifier, - asd, i)) { - dev_err(dev, - "subdev descriptor already listed in this or other notifiers\n"); - ret = -EEXIST; + ret = v4l2_async_notifier_asd_valid(notifier, asd, i); + if (ret) goto err_unlock; - } - break; - default: - dev_err(dev, "Invalid match type %u on %p\n", - asd->match_type, asd); - ret = -EINVAL; - goto err_unlock; + + list_add_tail(&asd->list, ¬ifier->waiting); + } + } else { + i = 0; + list_for_each_entry(asd, ¬ifier->asd_list, asd_list) { + ret = v4l2_async_notifier_asd_valid(notifier, asd, i++); + if (ret) + goto err_unlock; + + list_add_tail(&asd->list, ¬ifier->waiting); } - list_add_tail(&asd->list, ¬ifier->waiting); } ret = v4l2_async_notifier_try_all_subdevs(notifier); @@ -513,36 +557,99 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier) } EXPORT_SYMBOL(v4l2_async_notifier_unregister); -void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier) +static void __v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier) { + struct v4l2_async_subdev *asd, *tmp; unsigned int i; - if (!notifier || !notifier->max_subdevs) + if (!notifier) return; - for (i = 0; i < notifier->num_subdevs; i++) { - struct v4l2_async_subdev *asd = notifier->subdevs[i]; + if (notifier->subdevs) { + if (!notifier->max_subdevs) + return; - switch (asd->match_type) { - case V4L2_ASYNC_MATCH_FWNODE: - fwnode_handle_put(asd->match.fwnode); - break; - default: - WARN_ON_ONCE(true); - break; + for (i = 0; i < notifier->num_subdevs; i++) { + asd = notifier->subdevs[i]; + + switch (asd->match_type) { + case V4L2_ASYNC_MATCH_FWNODE: + fwnode_handle_put(asd->match.fwnode); + break; + default: + break; + } + + kfree(asd); } - kfree(asd); + notifier->max_subdevs = 0; + kvfree(notifier->subdevs); + notifier->subdevs = NULL; + } else { + list_for_each_entry_safe(asd, tmp, + ¬ifier->asd_list, asd_list) { + switch (asd->match_type) { + case V4L2_ASYNC_MATCH_FWNODE: + fwnode_handle_put(asd->match.fwnode); + break; + default: + break; + } + + list_del(&asd->asd_list); + kfree(asd); + } } - notifier->max_subdevs = 0; notifier->num_subdevs = 0; +} + +void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier) +{ + mutex_lock(&list_lock); + + __v4l2_async_notifier_cleanup(notifier); - kvfree(notifier->subdevs); - notifier->subdevs = NULL; + mutex_unlock(&list_lock); } EXPORT_SYMBOL_GPL(v4l2_async_notifier_cleanup); +int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier, + struct v4l2_async_subdev *asd) +{ + int ret; + + mutex_lock(&list_lock); + + if (notifier->num_subdevs >= V4L2_MAX_SUBDEVS) { + ret = -EINVAL; + goto unlock; + } + + /* + * If caller uses this function, it cannot also allocate and + * place asd's in the notifier->subdevs array. + */ + if (WARN_ON(notifier->subdevs)) { + ret = -EINVAL; + goto unlock; + } + + ret = v4l2_async_notifier_asd_valid(notifier, asd, + notifier->num_subdevs); + if (ret) + goto unlock; + + list_add_tail(&asd->asd_list, ¬ifier->asd_list); + notifier->num_subdevs++; + +unlock: + mutex_unlock(&list_lock); + return ret; +} +EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_subdev); + int v4l2_async_register_subdev(struct v4l2_subdev *sd) { struct v4l2_async_notifier *subdev_notifier; @@ -616,7 +723,7 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd) mutex_lock(&list_lock); __v4l2_async_notifier_unregister(sd->subdev_notifier); - v4l2_async_notifier_cleanup(sd->subdev_notifier); + __v4l2_async_notifier_cleanup(sd->subdev_notifier); kfree(sd->subdev_notifier); sd->subdev_notifier = NULL; diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h index 1592d323c577..ab4d7acb7960 100644 --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h @@ -73,6 +73,8 @@ enum v4l2_async_match_type { * @match.custom.priv: * Driver-specific private struct with match parameters * to be used if %V4L2_ASYNC_MATCH_CUSTOM. + * @asd_list: used to add struct v4l2_async_subdev objects to the + * master notifier @asd_list * @list: used to link struct v4l2_async_subdev objects, waiting to be * probed, to a notifier->waiting list * @@ -98,6 +100,7 @@ struct v4l2_async_subdev { /* v4l2-async core private: not to be used by drivers */ struct list_head list; + struct list_head asd_list; }; /** @@ -127,6 +130,7 @@ struct v4l2_async_notifier_operations { * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise * @sd: sub-device that registered the notifier, NULL otherwise * @parent: parent notifier + * @asd_list: master list of struct v4l2_async_subdev, replaces @subdevs * @waiting: list of struct v4l2_async_subdev, waiting for their drivers * @done: list of struct v4l2_subdev, already probed * @list: member in a global list of notifiers @@ -139,11 +143,37 @@ struct v4l2_async_notifier { struct v4l2_device *v4l2_dev; struct v4l2_subdev *sd; struct v4l2_async_notifier *parent; + struct list_head asd_list; struct list_head waiting; struct list_head done; struct list_head list; }; +/** + * v4l2_async_notifier_init - Initialize a notifier. + * + * @notifier: pointer to &struct v4l2_async_notifier + * + * This function initializes the notifier @asd_list. It must be called + * before the first call to @v4l2_async_notifier_add_subdev. + */ +void v4l2_async_notifier_init(struct v4l2_async_notifier *notifier); + +/** + * v4l2_async_notifier_add_subdev - Add an async subdev to the + * notifier's master asd list. + * + * @notifier: pointer to &struct v4l2_async_notifier + * @asd: pointer to &struct v4l2_async_subdev + * + * This can be used before registering a notifier to add an + * asd to the notifiers @asd_list. If the caller uses this + * method to compose an asd list, it must never allocate + * or place asd's in the @subdevs array. + */ +int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier, + struct v4l2_async_subdev *asd); + /** * v4l2_async_notifier_register - registers a subdevice asynchronous notifier * @@ -177,7 +207,9 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier); * Release memory resources related to a notifier, including the async * sub-devices allocated for the purposes of the notifier but not the notifier * itself. The user is responsible for calling this function to clean up the - * notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints or + * notifier after calling + * @v4l2_async_notifier_add_subdev, + * @v4l2_async_notifier_parse_fwnode_endpoints or * @v4l2_fwnode_reference_parse_sensor_common. * * There is no harm from calling v4l2_async_notifier_cleanup in other From patchwork Sat Sep 29 19:54:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10620999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 670BA16B1 for ; Sat, 29 Sep 2018 19:56:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56AE429B5B for ; Sat, 29 Sep 2018 19:56:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4ADC929C1F; Sat, 29 Sep 2018 19:56:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B38E229B5B for ; Sat, 29 Sep 2018 19:56:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728081AbeI3CY1 (ORCPT ); Sat, 29 Sep 2018 22:24:27 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40110 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726999AbeI3CY0 (ORCPT ); Sat, 29 Sep 2018 22:24:26 -0400 Received: by mail-pg1-f196.google.com with SMTP id n31-v6so6757243pgm.7; Sat, 29 Sep 2018 12:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2luOFW4gD3OoNRwvZ0xx/PGqhozNn2/M7xAvPq7b+cQ=; b=X0FQV2Zb8X8dHvpmucTjko79bwuLlGcysnLye3QOLkPkNnPaiZIcP7HBZ3l6qY1a9B 2H1xRuzvjdGBlHjk4rqDbXSC8/fnv99+R6CPE/hXEeurL7dgbHzLQ/ZKu/dgV7s4raaN LrqEc+wNljRcBA3+CPKQp9dmBj/7M8cpms7HGB/SDNiYt0mGFzSxllnsj0Im6HiWaXsA PF8B7sWa6GkqoZwp3UI7R28iqCe0jrimwo5IP7UTJClkeibzUl4XBO94pcB4hIK+3/oh 0RTl02b8lWhrGc5Pv9W0z3Oah52G8NmoA2FNUioruIRkI9T2ZmTpe6osdnxvMqHhtkRG tgIg== 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=2luOFW4gD3OoNRwvZ0xx/PGqhozNn2/M7xAvPq7b+cQ=; b=c/HfidKHMrw/DSl3oyOi9NzDenT4WfEDMaOvJYXfQRWUOupZ9p23RF+6rhNCBB/rZA 3iz17CAN0gk2kFrW93fusW+jhhv3IdSjKxPU9LeRtcgf/IThkMRqX9Gz6xXMddw05oR4 b27lLgnvDs+0gQfHYRf+YvBgH8GADSTiUuuQXyIpCrB+kvOnnDFtG56KOxMg1lVNXwp5 T5up5YdPh5McXC8DwRcfuLWodorBLP4Ad2sa2iZRr+JcmkYgenhyklokoAl7ncW+B6lb 50TFKjJvLIcT090NzJKJPQgHqrMkmshS5WPof4qwTKcmT6GAf04ELe2ukQj8EL7G5g9O PlUg== X-Gm-Message-State: ABuFfoisKQaVvQcrSF2MyGTA6xjp75MISqOa7xy6RX/n0PJq/mm+cjGb ajxQGxIASX0Peccr41yCksdoq6Se X-Google-Smtp-Source: ACcGV62h2fT0LKzjLMOWylGinuezac8HwkPQ+qdlK3DR5WQ3P1cbIL7B+lSHC9a44f05NZJ4eXjySw== X-Received: by 2002:a17:902:108a:: with SMTP id c10-v6mr4400396pla.272.1538250883145; Sat, 29 Sep 2018 12:54:43 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:42 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Mauro Carvalho Chehab , =?utf-8?q?Niklas_S=C3=B6derlund?= , Sakari Ailus , Sebastian Reichel , Hans Verkuil , linux-kernel@vger.kernel.org (open list) Subject: [RESEND PATCH v7 04/17] media: v4l2: async: Add convenience functions to allocate and add asd's Date: Sat, 29 Sep 2018 12:54:07 -0700 Message-Id: <20180929195420.28579-5-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add these convenience functions, which allocate an asd of match type fwnode, i2c, or device-name, of size asd_struct_size, and then adds them to the notifier asd_list. Signed-off-by: Steve Longerbeam --- drivers/media/v4l2-core/v4l2-async.c | 76 ++++++++++++++++++++++++++++ include/media/v4l2-async.h | 62 +++++++++++++++++++++++ 2 files changed, 138 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 7925875d09b7..196573f4ec48 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -650,6 +650,82 @@ int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier, } EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_subdev); +struct v4l2_async_subdev * +v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier, + struct fwnode_handle *fwnode, + unsigned int asd_struct_size) +{ + struct v4l2_async_subdev *asd; + int ret; + + asd = kzalloc(asd_struct_size, GFP_KERNEL); + if (!asd) + return ERR_PTR(-ENOMEM); + + asd->match_type = V4L2_ASYNC_MATCH_FWNODE; + asd->match.fwnode = fwnode; + + ret = v4l2_async_notifier_add_subdev(notifier, asd); + if (ret) { + kfree(asd); + return ERR_PTR(ret); + } + + return asd; +} +EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_subdev); + +struct v4l2_async_subdev * +v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier, + int adapter_id, unsigned short address, + unsigned int asd_struct_size) +{ + struct v4l2_async_subdev *asd; + int ret; + + asd = kzalloc(asd_struct_size, GFP_KERNEL); + if (!asd) + return ERR_PTR(-ENOMEM); + + asd->match_type = V4L2_ASYNC_MATCH_I2C; + asd->match.i2c.adapter_id = adapter_id; + asd->match.i2c.address = address; + + ret = v4l2_async_notifier_add_subdev(notifier, asd); + if (ret) { + kfree(asd); + return ERR_PTR(ret); + } + + return asd; +} +EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_i2c_subdev); + +struct v4l2_async_subdev * +v4l2_async_notifier_add_devname_subdev(struct v4l2_async_notifier *notifier, + const char *device_name, + unsigned int asd_struct_size) +{ + struct v4l2_async_subdev *asd; + int ret; + + asd = kzalloc(asd_struct_size, GFP_KERNEL); + if (!asd) + return ERR_PTR(-ENOMEM); + + asd->match_type = V4L2_ASYNC_MATCH_DEVNAME; + asd->match.device_name = device_name; + + ret = v4l2_async_notifier_add_subdev(notifier, asd); + if (ret) { + kfree(asd); + return ERR_PTR(ret); + } + + return asd; +} +EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_devname_subdev); + int v4l2_async_register_subdev(struct v4l2_subdev *sd) { struct v4l2_async_notifier *subdev_notifier; diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h index ab4d7acb7960..3489e4ccb29b 100644 --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h @@ -174,6 +174,68 @@ void v4l2_async_notifier_init(struct v4l2_async_notifier *notifier); int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier, struct v4l2_async_subdev *asd); +/** + * v4l2_async_notifier_add_fwnode_subdev - Allocate and add a fwnode async + * subdev to the notifier's master asd_list. + * + * @notifier: pointer to &struct v4l2_async_notifier + * @fwnode: fwnode handle of the sub-device to be matched + * @asd_struct_size: size of the driver's async sub-device struct, including + * sizeof(struct v4l2_async_subdev). The &struct + * v4l2_async_subdev shall be the first member of + * the driver's async sub-device struct, i.e. both + * begin at the same memory address. + * + * This can be used before registering a notifier to add a + * fwnode-matched asd to the notifiers master asd_list. If the caller + * uses this method to compose an asd list, it must never allocate + * or place asd's in the @subdevs array. + */ +struct v4l2_async_subdev * +v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier, + struct fwnode_handle *fwnode, + unsigned int asd_struct_size); + +/** + * v4l2_async_notifier_add_i2c_subdev - Allocate and add an i2c async + * subdev to the notifier's master asd_list. + * + * @notifier: pointer to &struct v4l2_async_notifier + * @adapter_id: I2C adapter ID to be matched + * @address: I2C address of sub-device to be matched + * @asd_struct_size: size of the driver's async sub-device struct, including + * sizeof(struct v4l2_async_subdev). The &struct + * v4l2_async_subdev shall be the first member of + * the driver's async sub-device struct, i.e. both + * begin at the same memory address. + * + * Same as above but for I2C matched sub-devices. + */ +struct v4l2_async_subdev * +v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier, + int adapter_id, unsigned short address, + unsigned int asd_struct_size); + +/** + * v4l2_async_notifier_add_devname_subdev - Allocate and add a device-name + * async subdev to the notifier's master asd_list. + * + * @notifier: pointer to &struct v4l2_async_notifier + * @device_name: device name string to be matched + * @asd_struct_size: size of the driver's async sub-device struct, including + * sizeof(struct v4l2_async_subdev). The &struct + * v4l2_async_subdev shall be the first member of + * the driver's async sub-device struct, i.e. both + * begin at the same memory address. + * + * Same as above but for device-name matched sub-devices. + */ +struct v4l2_async_subdev * +v4l2_async_notifier_add_devname_subdev(struct v4l2_async_notifier *notifier, + const char *device_name, + unsigned int asd_struct_size); + + /** * v4l2_async_notifier_register - registers a subdevice asynchronous notifier * From patchwork Sat Sep 29 19:54:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10620997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2181715A6 for ; Sat, 29 Sep 2018 19:56:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10A2329B5B for ; Sat, 29 Sep 2018 19:56:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 042AD29C1F; Sat, 29 Sep 2018 19:56:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C04029B5B for ; Sat, 29 Sep 2018 19:56:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728219AbeI3CYc (ORCPT ); Sat, 29 Sep 2018 22:24:32 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35911 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726999AbeI3CYc (ORCPT ); Sat, 29 Sep 2018 22:24:32 -0400 Received: by mail-pg1-f194.google.com with SMTP id f18-v6so3257209pgv.3; Sat, 29 Sep 2018 12:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=g6+ikUOI7jx8njeSwjuicq4h9f38aNc/QaFT1TTPVpE=; b=sf4aveudY9jD0s8b+ekbmR4UHhXcDO3tYDzXyrQHqYeFqDe9vMvYbKDTwlT87HfDLT 2yVeznCd46SaClx/TNU+m0lRnQMwPa0OgMfb3NCxD9WTnaUD9CwSWXUCTE31CLasCnJB /P9NSD1JcPiKCDS3UNYL+si+IXJo+txcVz32ykkcERy4wV9A79TkKBCUgI3COMv/ZU/h dhtGQAbhQENfinv+iAUfiv52TpNYrltHT2c52SGnkG8hTnZGNlRe/AhkJT5xSguMOtQf JOM7kk6L3NihLjn0ocdljhusyZf91hLfdBE1uF5QwGS1MHbc4omHULUVtIqad1nRJ2I8 uL+A== 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=g6+ikUOI7jx8njeSwjuicq4h9f38aNc/QaFT1TTPVpE=; b=tFvcPg35WGjZedsfRuH37kuRRMEAo96Z8UMeW6OWV7wJTjGprNQKqBi4vpAoXP4MW2 8Iwc7gGXCZukliJAj9IGWdaaUZcUqzzMZo+mSwbzAfeEN1Gmro6pS2BoN3LHrm4jFjWj tEiQGkXbeF5/R9044PTMv1a3kP1AfnJFEFIxWqHt3L8sVQufWpd4UbaepxmUZrlcXz5h twZGp6sgaLOL6KIk3KUt4PkLbeXeOZE3RuP/APZi+dxxaf0mHDg4VU9b8kQAA7bZGrkG HaQHHYYnNE/Uk0YIktrHtYBxFRZ81ftHHMkuZDfOHTS474bXpYPuOYgvggxEY931ri/q mrFQ== X-Gm-Message-State: ABuFfojKDFNdS3HBw58jmleLZ1aTyBqBeizaagbPb/k7Xwy/HlqXspr7 j5ecDFC0xgq5kyyy3NLGhU0E5ek0 X-Google-Smtp-Source: ACcGV61ve8e6UAoz6URQb4NF1s4A7wtj+ma/WR/Ui2z8/wABeu5+8pK8jU0gDe3x9/a8C28V8BV9XQ== X-Received: by 2002:a62:2fc1:: with SMTP id v184-v6mr4312159pfv.115.1538250888218; Sat, 29 Sep 2018 12:54:48 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:47 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Yong Zhi , Sakari Ailus , Bingbu Cao , Tian Shu Qiu , Jian Xu Zheng , Mauro Carvalho Chehab , Laurent Pinchart , =?utf-8?q?Niklas_S?= =?utf-8?q?=C3=B6derlund?= , Sebastian Reichel , Hans Verkuil , Tomasz Figa , Jacopo Mondi , linux-kernel@vger.kernel.org (open list), linux-renesas-soc@vger.kernel.org (open list:MEDIA DRIVERS FOR RENESAS - VIN) Subject: [RESEND PATCH v7 05/17] media: v4l2-fwnode: Switch to v4l2_async_notifier_add_subdev Date: Sat, 29 Sep 2018 12:54:08 -0700 Message-Id: <20180929195420.28579-6-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The fwnode endpoint and reference parsing functions in v4l2-fwnode.c are modified to make use of v4l2_async_notifier_add_subdev(). As a result the notifier->subdevs array is no longer allocated or re-allocated, and by extension the max_subdevs value is also no longer needed. Callers of the fwnode endpoint and reference parsing functions must now first initialize the notifier with a call to v4l2_async_notifier_init(). This includes the function v4l2_async_register_subdev_sensor_common(), and the intel-ipu3, omap3isp, and rcar-vin drivers. Since the notifier->subdevs array is no longer allocated in the fwnode endpoint and reference parsing functions, the callers of those functions must never reference that array, since it is now NULL. Of the drivers that make use of the fwnode/ref parsing, only the intel-ipu3 driver references the ->subdevs[] array, (in the notifier completion callback), so that driver has been modified to iterate through the notifier->asd_list instead. Signed-off-by: Steve Longerbeam --- Changes since v6: - none Changes since v5: - drivers must now initialize the notifier. Suggested by Sakari Ailus. --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 12 +- drivers/media/platform/omap3isp/isp.c | 1 + drivers/media/platform/rcar-vin/rcar-core.c | 4 + drivers/media/v4l2-core/v4l2-async.c | 4 - drivers/media/v4l2-core/v4l2-fwnode.c | 132 +++++--------------- include/media/v4l2-async.h | 2 - include/media/v4l2-fwnode.h | 22 ++-- 7 files changed, 52 insertions(+), 125 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 08cf4bf00941..d7926c31388f 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -1433,13 +1433,13 @@ static int cio2_notifier_complete(struct v4l2_async_notifier *notifier) struct cio2_device *cio2 = container_of(notifier, struct cio2_device, notifier); struct sensor_async_subdev *s_asd; + struct v4l2_async_subdev *asd; struct cio2_queue *q; - unsigned int i, pad; + unsigned int pad; int ret; - for (i = 0; i < notifier->num_subdevs; i++) { - s_asd = container_of(cio2->notifier.subdevs[i], - struct sensor_async_subdev, asd); + list_for_each_entry(asd, &cio2->notifier.asd_list, asd_list) { + s_asd = container_of(asd, struct sensor_async_subdev, asd); q = &cio2->queue[s_asd->csi2.port]; for (pad = 0; pad < q->sensor->entity.num_pads; pad++) @@ -1461,7 +1461,7 @@ static int cio2_notifier_complete(struct v4l2_async_notifier *notifier) if (ret) { dev_err(&cio2->pci_dev->dev, "failed to create link for %s\n", - cio2->queue[i].sensor->name); + q->sensor->name); return ret; } } @@ -1497,6 +1497,8 @@ static int cio2_notifier_init(struct cio2_device *cio2) { int ret; + v4l2_async_notifier_init(&cio2->notifier); + ret = v4l2_async_notifier_parse_fwnode_endpoints( &cio2->pci_dev->dev, &cio2->notifier, sizeof(struct sensor_async_subdev), diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c index 93f032a39470..f5dde8774399 100644 --- a/drivers/media/platform/omap3isp/isp.c +++ b/drivers/media/platform/omap3isp/isp.c @@ -2220,6 +2220,7 @@ static int isp_probe(struct platform_device *pdev) mutex_init(&isp->isp_mutex); spin_lock_init(&isp->stat_lock); + v4l2_async_notifier_init(&isp->notifier); ret = v4l2_async_notifier_parse_fwnode_endpoints( &pdev->dev, &isp->notifier, sizeof(struct isp_async_subdev), diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 5dd16af3625c..1402b1ea1de1 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -611,6 +611,8 @@ static int rvin_parallel_init(struct rvin_dev *vin) { int ret; + v4l2_async_notifier_init(&vin->notifier); + ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port( vin->dev, &vin->notifier, sizeof(struct rvin_parallel_entity), 0, rvin_parallel_parse_v4l2); @@ -803,6 +805,8 @@ static int rvin_mc_parse_of_graph(struct rvin_dev *vin) return 0; } + v4l2_async_notifier_init(&vin->group->notifier); + /* * Have all VIN's look for CSI-2 subdevices. Some subdevices will * overlap but the parser function can handle it, so each subdevice diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 196573f4ec48..b0eb31efcbfe 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -566,9 +566,6 @@ static void __v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier) return; if (notifier->subdevs) { - if (!notifier->max_subdevs) - return; - for (i = 0; i < notifier->num_subdevs; i++) { asd = notifier->subdevs[i]; @@ -583,7 +580,6 @@ static void __v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier) kfree(asd); } - notifier->max_subdevs = 0; kvfree(notifier->subdevs); notifier->subdevs = NULL; } else { diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c index 0b8c736b1606..88383d3d5974 100644 --- a/drivers/media/v4l2-core/v4l2-fwnode.c +++ b/drivers/media/v4l2-core/v4l2-fwnode.c @@ -320,33 +320,6 @@ void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link) } EXPORT_SYMBOL_GPL(v4l2_fwnode_put_link); -static int v4l2_async_notifier_realloc(struct v4l2_async_notifier *notifier, - unsigned int max_subdevs) -{ - struct v4l2_async_subdev **subdevs; - - if (max_subdevs <= notifier->max_subdevs) - return 0; - - subdevs = kvmalloc_array( - max_subdevs, sizeof(*notifier->subdevs), - GFP_KERNEL | __GFP_ZERO); - if (!subdevs) - return -ENOMEM; - - if (notifier->subdevs) { - memcpy(subdevs, notifier->subdevs, - sizeof(*subdevs) * notifier->num_subdevs); - - kvfree(notifier->subdevs); - } - - notifier->subdevs = subdevs; - notifier->max_subdevs = max_subdevs; - - return 0; -} - static int v4l2_async_notifier_fwnode_parse_endpoint( struct device *dev, struct v4l2_async_notifier *notifier, struct fwnode_handle *endpoint, unsigned int asd_struct_size, @@ -391,8 +364,13 @@ static int v4l2_async_notifier_fwnode_parse_endpoint( if (ret < 0) goto out_err; - notifier->subdevs[notifier->num_subdevs] = asd; - notifier->num_subdevs++; + ret = v4l2_async_notifier_add_subdev(notifier, asd); + if (ret < 0) { + /* not an error if asd already exists */ + if (ret == -EEXIST) + ret = 0; + goto out_err; + } return 0; @@ -411,46 +389,11 @@ static int __v4l2_async_notifier_parse_fwnode_endpoints( struct v4l2_async_subdev *asd)) { struct fwnode_handle *fwnode; - unsigned int max_subdevs = notifier->max_subdevs; - int ret; + int ret = 0; if (WARN_ON(asd_struct_size < sizeof(struct v4l2_async_subdev))) return -EINVAL; - for (fwnode = NULL; (fwnode = fwnode_graph_get_next_endpoint( - dev_fwnode(dev), fwnode)); ) { - struct fwnode_handle *dev_fwnode; - bool is_available; - - dev_fwnode = fwnode_graph_get_port_parent(fwnode); - is_available = fwnode_device_is_available(dev_fwnode); - fwnode_handle_put(dev_fwnode); - if (!is_available) - continue; - - if (has_port) { - struct fwnode_endpoint ep; - - ret = fwnode_graph_parse_endpoint(fwnode, &ep); - if (ret) { - fwnode_handle_put(fwnode); - return ret; - } - - if (ep.port != port) - continue; - } - max_subdevs++; - } - - /* No subdevs to add? Return here. */ - if (max_subdevs == notifier->max_subdevs) - return 0; - - ret = v4l2_async_notifier_realloc(notifier, max_subdevs); - if (ret) - return ret; - for (fwnode = NULL; (fwnode = fwnode_graph_get_next_endpoint( dev_fwnode(dev), fwnode)); ) { struct fwnode_handle *dev_fwnode; @@ -473,11 +416,6 @@ static int __v4l2_async_notifier_parse_fwnode_endpoints( continue; } - if (WARN_ON(notifier->num_subdevs >= notifier->max_subdevs)) { - ret = -EINVAL; - break; - } - ret = v4l2_async_notifier_fwnode_parse_endpoint( dev, notifier, fwnode, asd_struct_size, parse_endpoint); if (ret < 0) @@ -548,31 +486,23 @@ static int v4l2_fwnode_reference_parse( if (ret != -ENOENT && ret != -ENODATA) return ret; - ret = v4l2_async_notifier_realloc(notifier, - notifier->num_subdevs + index); - if (ret) - return ret; - for (index = 0; !fwnode_property_get_reference_args( dev_fwnode(dev), prop, NULL, 0, index, &args); index++) { struct v4l2_async_subdev *asd; - if (WARN_ON(notifier->num_subdevs >= notifier->max_subdevs)) { - ret = -EINVAL; - goto error; - } + asd = v4l2_async_notifier_add_fwnode_subdev( + notifier, args.fwnode, sizeof(*asd)); + if (IS_ERR(asd)) { + ret = PTR_ERR(asd); + /* not an error if asd already exists */ + if (ret == -EEXIST) { + fwnode_handle_put(args.fwnode); + continue; + } - asd = kzalloc(sizeof(*asd), GFP_KERNEL); - if (!asd) { - ret = -ENOMEM; goto error; } - - notifier->subdevs[notifier->num_subdevs] = asd; - asd->match.fwnode = args.fwnode; - asd->match_type = V4L2_ASYNC_MATCH_FWNODE; - notifier->num_subdevs++; } return 0; @@ -843,31 +773,23 @@ static int v4l2_fwnode_reference_parse_int_props( index++; } while (1); - ret = v4l2_async_notifier_realloc(notifier, - notifier->num_subdevs + index); - if (ret) - return -ENOMEM; - for (index = 0; !IS_ERR((fwnode = v4l2_fwnode_reference_get_int_prop( dev_fwnode(dev), prop, index, props, nprops))); index++) { struct v4l2_async_subdev *asd; - if (WARN_ON(notifier->num_subdevs >= notifier->max_subdevs)) { - ret = -EINVAL; - goto error; - } + asd = v4l2_async_notifier_add_fwnode_subdev(notifier, fwnode, + sizeof(*asd)); + if (IS_ERR(asd)) { + ret = PTR_ERR(asd); + /* not an error if asd already exists */ + if (ret == -EEXIST) { + fwnode_handle_put(fwnode); + continue; + } - asd = kzalloc(sizeof(struct v4l2_async_subdev), GFP_KERNEL); - if (!asd) { - ret = -ENOMEM; goto error; } - - notifier->subdevs[notifier->num_subdevs] = asd; - asd->match.fwnode = fwnode; - asd->match_type = V4L2_ASYNC_MATCH_FWNODE; - notifier->num_subdevs++; } return PTR_ERR(fwnode) == -ENOENT ? 0 : PTR_ERR(fwnode); @@ -924,6 +846,8 @@ int v4l2_async_register_subdev_sensor_common(struct v4l2_subdev *sd) if (!notifier) return -ENOMEM; + v4l2_async_notifier_init(notifier); + ret = v4l2_async_notifier_parse_fwnode_sensor_common(sd->dev, notifier); if (ret < 0) diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h index 3489e4ccb29b..16b1e2b097c1 100644 --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h @@ -125,7 +125,6 @@ struct v4l2_async_notifier_operations { * * @ops: notifier operations * @num_subdevs: number of subdevices used in the subdevs array - * @max_subdevs: number of subdevices allocated in the subdevs array * @subdevs: array of pointers to subdevice descriptors * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise * @sd: sub-device that registered the notifier, NULL otherwise @@ -138,7 +137,6 @@ struct v4l2_async_notifier_operations { struct v4l2_async_notifier { const struct v4l2_async_notifier_operations *ops; unsigned int num_subdevs; - unsigned int max_subdevs; struct v4l2_async_subdev **subdevs; struct v4l2_device *v4l2_dev; struct v4l2_subdev *sd; diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h index 9cccab618b98..ea7a8b247e19 100644 --- a/include/media/v4l2-fwnode.h +++ b/include/media/v4l2-fwnode.h @@ -247,7 +247,7 @@ typedef int (*parse_endpoint_func)(struct device *dev, * endpoint. Optional. * * Parse the fwnode endpoints of the @dev device and populate the async sub- - * devices array of the notifier. The @parse_endpoint callback function is + * devices list in the notifier. The @parse_endpoint callback function is * called for each endpoint with the corresponding async sub-device pointer to * let the caller initialize the driver-specific part of the async sub-device * structure. @@ -258,10 +258,11 @@ typedef int (*parse_endpoint_func)(struct device *dev, * This function may not be called on a registered notifier and may be called on * a notifier only once. * - * Do not change the notifier's subdevs array, take references to the subdevs - * array itself or change the notifier's num_subdevs field. This is because this - * function allocates and reallocates the subdevs array based on parsing - * endpoints. + * Do not allocate the notifier's subdevs array, or change the notifier's + * num_subdevs field. This is because this function uses + * @v4l2_async_notifier_add_subdev to populate the notifier's asd_list, + * which is in-place-of the subdevs array which must remain unallocated + * and unused. * * The &struct v4l2_fwnode_endpoint passed to the callback function * @parse_endpoint is released once the function is finished. If there is a need @@ -303,7 +304,7 @@ int v4l2_async_notifier_parse_fwnode_endpoints( * devices). In this case the driver must know which ports to parse. * * Parse the fwnode endpoints of the @dev device on a given @port and populate - * the async sub-devices array of the notifier. The @parse_endpoint callback + * the async sub-devices list of the notifier. The @parse_endpoint callback * function is called for each endpoint with the corresponding async sub-device * pointer to let the caller initialize the driver-specific part of the async * sub-device structure. @@ -314,10 +315,11 @@ int v4l2_async_notifier_parse_fwnode_endpoints( * This function may not be called on a registered notifier and may be called on * a notifier only once per port. * - * Do not change the notifier's subdevs array, take references to the subdevs - * array itself or change the notifier's num_subdevs field. This is because this - * function allocates and reallocates the subdevs array based on parsing - * endpoints. + * Do not allocate the notifier's subdevs array, or change the notifier's + * num_subdevs field. This is because this function uses + * @v4l2_async_notifier_add_subdev to populate the notifier's asd_list, + * which is in-place-of the subdevs array which must remain unallocated + * and unused. * * The &struct v4l2_fwnode_endpoint passed to the callback function * @parse_endpoint is released once the function is finished. If there is a need From patchwork Sat Sep 29 19:54:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10620993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D567216B1 for ; Sat, 29 Sep 2018 19:56:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C509D29B5B for ; Sat, 29 Sep 2018 19:56:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8EA829C1F; Sat, 29 Sep 2018 19:56:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13D9129B5B for ; Sat, 29 Sep 2018 19:56:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728322AbeI3CYg (ORCPT ); Sat, 29 Sep 2018 22:24:36 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41531 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726999AbeI3CYf (ORCPT ); Sat, 29 Sep 2018 22:24:35 -0400 Received: by mail-pg1-f195.google.com with SMTP id z3-v6so6753967pgv.8; Sat, 29 Sep 2018 12:54:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3w5nZy1rTmDq9OehC3BiAguPc8U344n6mmQ65gzZ79w=; b=Og4qDv99O9igXtw7Czo9aR4NjaNrj/oqgDWLKtv5Jk7OfghH5fqUriNOuFjdf/1TAy Xcjso+dt3k3wXcgPbHBvHYjepbcOt1NB2xlcnWGwNVptQL0Yu1UUFLxHFs2NOQOrV4KK B82s4KzRhSf3p0B9oHQ7EZyApDHRceHvK7vuCFvu28by13IRJbFV6D3YUX3FD6m2rB0w cOf/put399Fr66wTUuyOQY3yvAqMis2Szd+RYhHTLgHvQTQVhwAR4vhXD+DmCbgL3mCK b2Jl2lJuT9kzDqpAkPhc2JyD97rFEj+SI0orOXDf9T3QZpj2+EqR0S705rKObaAZSacr xA4Q== 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=3w5nZy1rTmDq9OehC3BiAguPc8U344n6mmQ65gzZ79w=; b=lxT50Y5Of+YDMXO/fpWhvhz1m4xcUXJUvd/doOqnv0T6wKRS6KXf0Qe3V8efhlJ9xU NhJU9cjjptQN6bKtdZQaXpXsevNJWItM2akQ0SpHCBG72Z01/Jk06jGsziIiIq1GM50y x07ybx5o5DyfVGWRjXiKyzA2Jup/LRoFZL72kthRNWP8MoKtYAropqLAgT6AdEb3HfQZ j3WHpNsXyTWFmqlMzTSixB2Gk3JNgWZmCOwA43SL6/o+gUlQxB5x+4xvbyoRA8jcBFni UKRT527hx/Fo3w8dFPBBkezYy9KLMLhJyqxFsz9nPbMeliioe5bR8C87tg87UdptlC09 C8Aw== X-Gm-Message-State: ABuFfoh0v0Qlk+ExpBb+ubfz8n/iRK6XEfzPWnh8cOP4hTk9XldvnBg2 DqV6zbhcT/SWNo9wohZ726trXxYW X-Google-Smtp-Source: ACcGV61aYjDvfIv3heaqnIc1Qn2KQ5n97L3K+eWPfWu6VPR82g8hFnccclCeJquPfMZMFLIvRuNXUw== X-Received: by 2002:a62:438f:: with SMTP id l15-v6mr4377622pfi.196.1538250891552; Sat, 29 Sep 2018 12:54:51 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:50 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Mauro Carvalho Chehab , Sakari Ailus , Hans Verkuil , =?utf-8?q?Niklas_S=C3=B6derlund?= , Sebastian Reichel , Tomasz Figa , Jacopo Mondi , linux-kernel@vger.kernel.org (open list) Subject: [RESEND PATCH v7 06/17] media: v4l2-fwnode: Add a convenience function for registering subdevs with notifiers Date: Sat, 29 Sep 2018 12:54:09 -0700 Message-Id: <20180929195420.28579-7-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds v4l2_async_register_fwnode_subdev(), which is a convenience function for parsing a sub-device's fwnode port endpoints for connected remote sub-devices, registering a sub-device notifier, and then registering the sub-device itself. Signed-off-by: Steve Longerbeam --- Changes since v6: - none Changes since v5: - add call to v4l2_async_notifier_init(). Changes since v4: - none Changes since v3: - remove support for port sub-devices, such sub-devices will have to role their own. Changes since v2: - fix error-out path in v4l2_async_register_fwnode_subdev() that forgot to put device. Changes since v1: - add #include to v4l2-fwnode.h for 'struct v4l2_subdev' declaration. --- drivers/media/v4l2-core/v4l2-fwnode.c | 64 +++++++++++++++++++++++++++ include/media/v4l2-fwnode.h | 38 ++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c index 88383d3d5974..be75d9900667 100644 --- a/drivers/media/v4l2-core/v4l2-fwnode.c +++ b/drivers/media/v4l2-core/v4l2-fwnode.c @@ -876,6 +876,70 @@ int v4l2_async_register_subdev_sensor_common(struct v4l2_subdev *sd) } EXPORT_SYMBOL_GPL(v4l2_async_register_subdev_sensor_common); +int v4l2_async_register_fwnode_subdev( + struct v4l2_subdev *sd, size_t asd_struct_size, + unsigned int *ports, unsigned int num_ports, + int (*parse_endpoint)(struct device *dev, + struct v4l2_fwnode_endpoint *vep, + struct v4l2_async_subdev *asd)) +{ + struct v4l2_async_notifier *notifier; + struct device *dev = sd->dev; + struct fwnode_handle *fwnode; + int ret; + + if (WARN_ON(!dev)) + return -ENODEV; + + fwnode = dev_fwnode(dev); + if (!fwnode_device_is_available(fwnode)) + return -ENODEV; + + notifier = kzalloc(sizeof(*notifier), GFP_KERNEL); + if (!notifier) + return -ENOMEM; + + v4l2_async_notifier_init(notifier); + + if (!ports) { + ret = v4l2_async_notifier_parse_fwnode_endpoints( + dev, notifier, asd_struct_size, parse_endpoint); + if (ret < 0) + goto out_cleanup; + } else { + unsigned int i; + + for (i = 0; i < num_ports; i++) { + ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port( + dev, notifier, asd_struct_size, + ports[i], parse_endpoint); + if (ret < 0) + goto out_cleanup; + } + } + + ret = v4l2_async_subdev_notifier_register(sd, notifier); + if (ret < 0) + goto out_cleanup; + + ret = v4l2_async_register_subdev(sd); + if (ret < 0) + goto out_unregister; + + sd->subdev_notifier = notifier; + + return 0; + +out_unregister: + v4l2_async_notifier_unregister(notifier); +out_cleanup: + v4l2_async_notifier_cleanup(notifier); + kfree(notifier); + + return ret; +} +EXPORT_SYMBOL_GPL(v4l2_async_register_fwnode_subdev); + MODULE_LICENSE("GPL"); MODULE_AUTHOR("Sakari Ailus "); MODULE_AUTHOR("Sylwester Nawrocki "); diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h index ea7a8b247e19..031ebb069dcb 100644 --- a/include/media/v4l2-fwnode.h +++ b/include/media/v4l2-fwnode.h @@ -23,6 +23,7 @@ #include #include +#include struct fwnode_handle; struct v4l2_async_notifier; @@ -360,4 +361,41 @@ int v4l2_async_notifier_parse_fwnode_endpoints_by_port( int v4l2_async_notifier_parse_fwnode_sensor_common( struct device *dev, struct v4l2_async_notifier *notifier); +/** + * v4l2_async_register_fwnode_subdev - registers a sub-device to the + * asynchronous sub-device framework + * and parses fwnode endpoints + * + * @sd: pointer to struct &v4l2_subdev + * @asd_struct_size: size of the driver's async sub-device struct, including + * sizeof(struct v4l2_async_subdev). The &struct + * v4l2_async_subdev shall be the first member of + * the driver's async sub-device struct, i.e. both + * begin at the same memory address. + * @ports: array of port id's to parse for fwnode endpoints. If NULL, will + * parse all ports owned by the sub-device. + * @num_ports: number of ports in @ports array. Ignored if @ports is NULL. + * @parse_endpoint: Driver's callback function called on each V4L2 fwnode + * endpoint. Optional. + * + * This function is just like v4l2_async_register_subdev() with the + * exception that calling it will also allocate a notifier for the + * sub-device, parse the sub-device's firmware node endpoints using + * v4l2_async_notifier_parse_fwnode_endpoints() or + * v4l2_async_notifier_parse_fwnode_endpoints_by_port(), and + * registers the sub-device notifier. The sub-device is similarly + * unregistered by calling v4l2_async_unregister_subdev(). + * + * While registered, the subdev module is marked as in-use. + * + * An error is returned if the module is no longer loaded on any attempts + * to register it. + */ +int v4l2_async_register_fwnode_subdev( + struct v4l2_subdev *sd, size_t asd_struct_size, + unsigned int *ports, unsigned int num_ports, + int (*parse_endpoint)(struct device *dev, + struct v4l2_fwnode_endpoint *vep, + struct v4l2_async_subdev *asd)); + #endif /* _V4L2_FWNODE_H */ From patchwork Sat Sep 29 19:54:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10620991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 39A1716B1 for ; Sat, 29 Sep 2018 19:56:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29BCB29B5B for ; Sat, 29 Sep 2018 19:56:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D9F929C1F; Sat, 29 Sep 2018 19:56:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB23329B5B for ; Sat, 29 Sep 2018 19:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728363AbeI3CYi (ORCPT ); Sat, 29 Sep 2018 22:24:38 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41876 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728361AbeI3CYi (ORCPT ); Sat, 29 Sep 2018 22:24:38 -0400 Received: by mail-pf1-f194.google.com with SMTP id m77-v6so6495726pfi.8; Sat, 29 Sep 2018 12:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gaWEwfdxCeE5LcfSqhDthv1uikrxw4vxlpf1btQOKr0=; b=Ha/G46BsYW1kebfdiOqa28uu7diyuojYfXPAF0TDMp1tmfQfKnln1pOkBeJ5eV+yoX LXtMWH/lbBcHpEcuKzuaIMiutsnJbynyxnL6q9YvSnJLNwPi0TWdapdYjRIZyw5b0c79 9Poek9DUa/NPdoaQ5aFTQRPplEtLcltX7CS8xWQielB3l4toYvrUdY+CMaqjDapppj9K gx/ds26A4V7grHl1ikg6/KDxcYWYsygBq/A5fheOyJXdUe9rR392D35E+kWseHwIOqXy pU0N6Y1nJViGis/c6c3xzYw0S+ef6jnTD3bLQXjFjWiLNKalrMhjlEw8s2JtfN+9iYTO 8+Sw== 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=gaWEwfdxCeE5LcfSqhDthv1uikrxw4vxlpf1btQOKr0=; b=XvSwrgaj3vmKYVswjhGnQbC5oOnOYV+Sp54nHhWHFwJEG2q72EtY35BV3U750SCOVN GOOKAbtBHDydPwpolFDw498dsyoyO+XpmPHSYyCnh867uNjASkpFYY4BbxNTl63yGUDI OmJSQZqRJ5zva+cnLI/dokg5rgsEWnDd1N/N14E1A8NC7o7t0hGxcA5MajTBxYMeUv3F GiW6A1Gnc7jprHuyufGdZitrpmIzGbs3HmtTn1nPdCH6E/XskOxV+/hnRyP0FKbB3Zt0 xNFHXIacrGek2a48/Lm7aMQLuBxwDMX1ucJ+WWnmbD4bJ+6rsKRNskGcyHlcHopZ0xtL PX2A== X-Gm-Message-State: ABuFfohO9/v4gIXy7yTJTIvYPnVTmYqDnNgjuHVHLkbtP4BhohfytjOF W3qibCJ1SnsjQNULysPJc9/pOFBM X-Google-Smtp-Source: ACcGV62qfkERD9fSfHJbF95y/XABo14tdgbEPsPE1dHCk9ra3bO7dmBh6FSKCCCPoYKfqhQVQ3YJ5Q== X-Received: by 2002:aa7:8594:: with SMTP id w20-v6mr4319242pfn.77.1538250894800; Sat, 29 Sep 2018 12:54:54 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:53 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Mauro Carvalho Chehab , Philipp Zabel , Hans Verkuil , Laurent Pinchart , Arnd Bergmann , Geert Uytterhoeven , Jacob Chen , Neil Armstrong , linux-kernel@vger.kernel.org (open list) Subject: [RESEND PATCH v7 07/17] media: platform: video-mux: Register a subdev notifier Date: Sat, 29 Sep 2018 12:54:10 -0700 Message-Id: <20180929195420.28579-8-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Parse neighbor remote devices on the video muxes input ports, add them to a subdev notifier, and register the subdev notifier for the video mux, by calling v4l2_async_register_fwnode_subdev(). Signed-off-by: Steve Longerbeam --- Changes since v6: - none Changes since v5: - add missing select V4L2_FWNODE to Kconfig for VIDEO_MUX Changes since v4: - none Changes since v3: - pass num_pads - 1 (num_input_pads) to video_mux_async_register(). Changes since v2: - none Changes since v1: - add #include for kcalloc() declaration. --- drivers/media/platform/Kconfig | 1 + drivers/media/platform/video-mux.c | 36 +++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index f6275874ec9e..0edacfb01f3a 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -58,6 +58,7 @@ config VIDEO_MUX select MULTIPLEXER depends on VIDEO_V4L2 && OF && VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER select REGMAP + select V4L2_FWNODE help This driver provides support for N:1 video bus multiplexers. diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c index 61a9bf716a05..c33900e3c23e 100644 --- a/drivers/media/platform/video-mux.c +++ b/drivers/media/platform/video-mux.c @@ -21,8 +21,10 @@ #include #include #include +#include #include #include +#include #include struct video_mux { @@ -316,6 +318,38 @@ static const struct v4l2_subdev_ops video_mux_subdev_ops = { .video = &video_mux_subdev_video_ops, }; +static int video_mux_parse_endpoint(struct device *dev, + struct v4l2_fwnode_endpoint *vep, + struct v4l2_async_subdev *asd) +{ + /* + * it's not an error if remote is missing on a video-mux + * input port, return -ENOTCONN to skip this endpoint with + * no error. + */ + return fwnode_device_is_available(asd->match.fwnode) ? 0 : -ENOTCONN; +} + +static int video_mux_async_register(struct video_mux *vmux, + unsigned int num_input_pads) +{ + unsigned int i, *ports; + int ret; + + ports = kcalloc(num_input_pads, sizeof(*ports), GFP_KERNEL); + if (!ports) + return -ENOMEM; + for (i = 0; i < num_input_pads; i++) + ports[i] = i; + + ret = v4l2_async_register_fwnode_subdev( + &vmux->subdev, sizeof(struct v4l2_async_subdev), + ports, num_input_pads, video_mux_parse_endpoint); + + kfree(ports); + return ret; +} + static int video_mux_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -383,7 +417,7 @@ static int video_mux_probe(struct platform_device *pdev) vmux->subdev.entity.ops = &video_mux_ops; - return v4l2_async_register_subdev(&vmux->subdev); + return video_mux_async_register(vmux, num_pads - 1); } static int video_mux_remove(struct platform_device *pdev) From patchwork Sat Sep 29 19:54:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10620989 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C41715A6 for ; Sat, 29 Sep 2018 19:55:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BD8629B5B for ; Sat, 29 Sep 2018 19:55:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FB1A29C1F; Sat, 29 Sep 2018 19:55:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2E0829B5B for ; Sat, 29 Sep 2018 19:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727799AbeI3CYk (ORCPT ); Sat, 29 Sep 2018 22:24:40 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44716 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728361AbeI3CYj (ORCPT ); Sat, 29 Sep 2018 22:24:39 -0400 Received: by mail-pg1-f196.google.com with SMTP id g2-v6so6748073pgu.11; Sat, 29 Sep 2018 12:54:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ek7aMvAhww7wXIT36gN37Bk4zsXEvCBRyTYVNW5/+Jc=; b=dr5bTV0RVtaI4ClLrVtb0fBZUq4d7Ss3bWGHFBVpdYDafLO8KoKuUqEoFqcBtQdITG OtL40G5dQ4n9ce3Me42SJAZt6fPp5Dc8Gvm8KJ0Z8E5DvxpoNNiiNvQjCyuzDVT70M+0 17X91BEh8KnY+6Ikd0XUrnfI9STeuWjY94yyDIjgfmB8WUJ2JwVzvUOMMzO2NQMVEvwl 7oaMTIGCpkD/hcXH0hj6pvcIiM5DQooJZrlln1v93qd2yWgPPnPgOJoKKIfkEKCDWSXE dgz4LqSXAzhvncHfHHSxI8kEGzQPla/LMf0N5O+nsXCodUJbWzDH0YhmT7hP3YEtfLyS IF1g== 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=ek7aMvAhww7wXIT36gN37Bk4zsXEvCBRyTYVNW5/+Jc=; b=OhYGzlJ6TCEDk8TkPGT88ZA6ZVHIcD1koV6MfHraXuo6qJJL/Ez1ste4tobwc/Zoxz NQvSyo0YuKYAUJNOlaFuVp1t+/39UBhSNHM81LO51rJ9h9aTpSI/9SYA9XkYJKjwC5Ho gVnemBioTbd2PNmtZHhVL4jtkUcRBZwO2TASdczrH8H3od+57gh2cDyObrMOWeWPGTLo 2YF2uIncxp8oTx7rUb9QQASiH6JD+F8CewQB8orq3zo2DT6HzX1FW/ErDi5sMmGsKRz7 dT9rWcj6j3DX2La0808NWzcSuOuOXvLYISYVGR1O3Fu8QLSq7K8yZ3fIW8wBrR5FKeG7 4frQ== X-Gm-Message-State: ABuFfoiMCVC2CjZJ9TtP/7SROOyLWODKCgTM2t6hkzX8mx6sxZkEizJa q5v9VZn3kGluvmspN/bSJTuDi5k+ X-Google-Smtp-Source: ACcGV60J2VDHi/BOcGSV7AmQNW//nPcQaF2Z0hJt/C34ZNdd1rMTnlruUwNU0OaQr92mJT4f9Md4mw== X-Received: by 2002:a62:898d:: with SMTP id n13-v6mr4315103pfk.57.1538250896631; Sat, 29 Sep 2018 12:54:56 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:55 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman , devel@driverdev.osuosl.org (open list:STAGING SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [RESEND PATCH v7 08/17] media: imx: csi: Register a subdev notifier Date: Sat, 29 Sep 2018 12:54:11 -0700 Message-Id: <20180929195420.28579-9-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Parse neighbor remote devices on the CSI port, and add them to a subdev notifier, by calling v4l2_async_notifier_parse_fwnode_endpoints_by_port() using the CSI's port id. And register the subdev notifier for the CSI. Signed-off-by: Steve Longerbeam --- Changes since v6: - none Changes since v5: - add call to v4l2_async_notifier_init(). Changes since v4: - none Changes since v3: - v4l2_async_register_fwnode_subdev() no longer supports parsing port sub-devices, so call v4l2_async_notifier_parse_fwnode_endpoints_by_port() directly. --- drivers/staging/media/imx/imx-media-csi.c | 57 ++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index 4acdd7ae612b..bca13846ce6d 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -1783,6 +1783,61 @@ static const struct v4l2_subdev_internal_ops csi_internal_ops = { .unregistered = csi_unregistered, }; +static int imx_csi_parse_endpoint(struct device *dev, + struct v4l2_fwnode_endpoint *vep, + struct v4l2_async_subdev *asd) +{ + return fwnode_device_is_available(asd->match.fwnode) ? 0 : -EINVAL; +} + +static int imx_csi_async_register(struct csi_priv *priv) +{ + struct v4l2_async_notifier *notifier; + struct fwnode_handle *fwnode; + unsigned int port; + int ret; + + notifier = kzalloc(sizeof(*notifier), GFP_KERNEL); + if (!notifier) + return -ENOMEM; + + v4l2_async_notifier_init(notifier); + + fwnode = dev_fwnode(priv->dev); + + /* get this CSI's port id */ + ret = fwnode_property_read_u32(fwnode, "reg", &port); + if (ret < 0) + goto out_free; + + ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port( + priv->dev->parent, notifier, sizeof(struct v4l2_async_subdev), + port, imx_csi_parse_endpoint); + if (ret < 0) + goto out_cleanup; + + ret = v4l2_async_subdev_notifier_register(&priv->sd, notifier); + if (ret < 0) + goto out_cleanup; + + ret = v4l2_async_register_subdev(&priv->sd); + if (ret < 0) + goto out_unregister; + + priv->sd.subdev_notifier = notifier; + + return 0; + +out_unregister: + v4l2_async_notifier_unregister(notifier); +out_cleanup: + v4l2_async_notifier_cleanup(notifier); +out_free: + kfree(notifier); + + return ret; +} + static int imx_csi_probe(struct platform_device *pdev) { struct ipu_client_platformdata *pdata; @@ -1852,7 +1907,7 @@ static int imx_csi_probe(struct platform_device *pdev) goto free; } - ret = v4l2_async_register_subdev(&priv->sd); + ret = imx_csi_async_register(priv); if (ret) goto free; From patchwork Sat Sep 29 19:54:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10620987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A20BD16B1 for ; Sat, 29 Sep 2018 19:55:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9143329B5B for ; Sat, 29 Sep 2018 19:55:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85D6729C1F; Sat, 29 Sep 2018 19:55:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2505929B5B for ; Sat, 29 Sep 2018 19:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728455AbeI3CYm (ORCPT ); Sat, 29 Sep 2018 22:24:42 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35923 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728015AbeI3CYl (ORCPT ); Sat, 29 Sep 2018 22:24:41 -0400 Received: by mail-pg1-f195.google.com with SMTP id f18-v6so3257353pgv.3; Sat, 29 Sep 2018 12:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sVp5a2nWozC6KcAR667nDInnw3w1AXgzDlQwp5Coil8=; b=KNcwqRtdtmoxhyptGVVnwq/3pMLJqvLrubhvPCKqa5oaBc7RIYH6ERVb1KFIITjRIA i7hgG3nbPnBIwFAlv2Epm2VJfcNafKQE7NKJUnGC+NxDOpFnDDTWgBL2Rw1h2EcQn50w XZoX33JgFgBfL1LdVF0xp5puuhk9L7v5mC45P9qkp8yWtGyMC2Aq4VqXBqedW0htgUoG ToLFoGUAsO/0GgN8cNopqIZ4OBffTTi/z1SmZlBGKlbFjOBrzJsNi0d0RGJivqFpFJAA RO4dWVO0LwjXouqidyIu5dFN/snyUfEaplUm8XWzekiwy4ujxh3p5F7VErloSx6AcLJ1 ph9w== 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=sVp5a2nWozC6KcAR667nDInnw3w1AXgzDlQwp5Coil8=; b=j2ydDWEwwaOK0cPujpprfgsrJu2aVOuLr0R6rzjHWz/vV3CEdUD1a0TTTU5r84rMMk KHI7ExDlMlOkcJh1iE7adPYVPtPSTxfhbjPDS1Z7gx1cNk6rJGaAxXC3NJcM8Eil0K8I Pg8Ol/HXRJRonXSwqD3jSgh3LnsCe+t/Z6b+wdM5yUa3ZJ0hvkTTRiIyuzOs7bY4xnCJ xJb/SvJBgbaY5M9leJG/JXk0EHkaffGChaDJCtDOrbMVUxcqhq2N5fvISQQvOkPPWzBQ lQtHtwyeXmGZnShcvr+IqcWqDkGKf7ZM9oA5etng++TNBwJHq3gqvx4E+yhVkl4ttbbx agRg== X-Gm-Message-State: ABuFfojiA/YiZ3TEVVaXqDKECAqfRAfZ4t/M3N+dQ4XjFGGoiucfDdHA PxvjrPnqtYRorldtU53UPSX3nv/e X-Google-Smtp-Source: ACcGV62gErIkI1/s09bQuObWZpk8dAO73/I9SdIz304zhwgrXRbOb06UTddg5lihbwwbMPNtu7F6zw== X-Received: by 2002:a17:902:4281:: with SMTP id h1-v6mr4487112pld.134.1538250898399; Sat, 29 Sep 2018 12:54:58 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:57 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman , devel@driverdev.osuosl.org (open list:STAGING SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [RESEND PATCH v7 09/17] media: imx: mipi csi-2: Register a subdev notifier Date: Sat, 29 Sep 2018 12:54:12 -0700 Message-Id: <20180929195420.28579-10-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Parse neighbor remote devices on the MIPI CSI-2 input port, add them to a subdev notifier, and register the subdev notifier for the MIPI CSI-2 receiver, by calling v4l2_async_register_fwnode_subdev(). csi2_parse_endpoints() is modified to be the parse_endpoint callback. Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx6-mipi-csi2.c | 31 ++++++++++------------ 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c index 7b457a4b7df5..d60a52cfc69c 100644 --- a/drivers/staging/media/imx/imx6-mipi-csi2.c +++ b/drivers/staging/media/imx/imx6-mipi-csi2.c @@ -551,35 +551,34 @@ static const struct v4l2_subdev_internal_ops csi2_internal_ops = { .registered = csi2_registered, }; -static int csi2_parse_endpoints(struct csi2_dev *csi2) +static int csi2_parse_endpoint(struct device *dev, + struct v4l2_fwnode_endpoint *vep, + struct v4l2_async_subdev *asd) { - struct device_node *node = csi2->dev->of_node; - struct device_node *epnode; - struct v4l2_fwnode_endpoint ep; + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct csi2_dev *csi2 = sd_to_dev(sd); - epnode = of_graph_get_endpoint_by_regs(node, 0, -1); - if (!epnode) { - v4l2_err(&csi2->sd, "failed to get sink endpoint node\n"); + if (!fwnode_device_is_available(asd->match.fwnode)) { + v4l2_err(&csi2->sd, "remote is not available\n"); return -EINVAL; } - v4l2_fwnode_endpoint_parse(of_fwnode_handle(epnode), &ep); - of_node_put(epnode); - - if (ep.bus_type != V4L2_MBUS_CSI2) { + if (vep->bus_type != V4L2_MBUS_CSI2) { v4l2_err(&csi2->sd, "invalid bus type, must be MIPI CSI2\n"); return -EINVAL; } - csi2->bus = ep.bus.mipi_csi2; + csi2->bus = vep->bus.mipi_csi2; dev_dbg(csi2->dev, "data lanes: %d\n", csi2->bus.num_data_lanes); dev_dbg(csi2->dev, "flags: 0x%08x\n", csi2->bus.flags); + return 0; } static int csi2_probe(struct platform_device *pdev) { + unsigned int sink_port = 0; struct csi2_dev *csi2; struct resource *res; int ret; @@ -601,10 +600,6 @@ static int csi2_probe(struct platform_device *pdev) csi2->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; csi2->sd.grp_id = IMX_MEDIA_GRP_ID_CSI2; - ret = csi2_parse_endpoints(csi2); - if (ret) - return ret; - csi2->pllref_clk = devm_clk_get(&pdev->dev, "ref"); if (IS_ERR(csi2->pllref_clk)) { v4l2_err(&csi2->sd, "failed to get pll reference clock\n"); @@ -654,7 +649,9 @@ static int csi2_probe(struct platform_device *pdev) platform_set_drvdata(pdev, &csi2->sd); - ret = v4l2_async_register_subdev(&csi2->sd); + ret = v4l2_async_register_fwnode_subdev( + &csi2->sd, sizeof(struct v4l2_async_subdev), + &sink_port, 1, csi2_parse_endpoint); if (ret) goto dphy_off; From patchwork Sat Sep 29 19:54:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10620983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D00A15A6 for ; Sat, 29 Sep 2018 19:55:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D38029BE1 for ; Sat, 29 Sep 2018 19:55:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11B3A29C40; Sat, 29 Sep 2018 19:55:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E9C529BE1 for ; Sat, 29 Sep 2018 19:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728497AbeI3CYn (ORCPT ); Sat, 29 Sep 2018 22:24:43 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35724 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728015AbeI3CYn (ORCPT ); Sat, 29 Sep 2018 22:24:43 -0400 Received: by mail-pf1-f194.google.com with SMTP id p12-v6so6517850pfh.2; Sat, 29 Sep 2018 12:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gFvXkTztOIIjYdRfaWKAifhvc9l1yE2CQD4pWZVMgK0=; b=XmYROIcMT86iOZPrHDAMyls8PEgnubW8x7RdMDmhqSfIB3BEsigASgFWoZjajKQiko kvd3+R62mGLUqdX/a9LK5M65JjMG8GuFCjIHe4Ka5GDhWm8qIlztw+Tnpd1O2LUBXKrP 9bNagM89aISjoQ+MtIeu7fSzE6XSu4+vaLVLRW2xNFxnhcOVvcyFDsSn7Qd3anumo73h tqtKKyArKAIl1Y3ujWX9Sw8uspdzvapJYL6+RbIP08xIMu/1Dqfp4f3eTR4f2d5QqSFe DVTFYSTTGJMMASuh8xIH1LexKe1T+ehurSoJ1OSL0orjaYa+CPKX58fNbdjBr1BjbLsN lMQQ== 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=gFvXkTztOIIjYdRfaWKAifhvc9l1yE2CQD4pWZVMgK0=; b=AKceqSUsHhvCu5pUnGaAs/+ubtli79VfdHwZYPSe2ASIUYBkfr7/87/6AGgmugXI00 yt/8V4Li4hNBREXu+XqCeILTNToPccZWZFpGIOeaeHNneqoZJIqGpLzuPxPOiXWaO5zI Ak3ksNYVlXrO00RKVh5Bums49y1Z+IbbOyf7s3kxVqW/E7UBFuWg5Be5ySMZHuyIGJng MdESU5McTf0RUrG8fpUCmLba52sUivyOUr485g3j8Ft+sCj1po14PsP0V+lLU7Wb2ah9 G8ivAgNPMkK0QKZkXQj8XTEuDkHY8fxolxCene866BpS716mIIGlxiBnSKkIX1sIbr9G cbRQ== X-Gm-Message-State: ABuFfojP8Dv801Cpf31X/3r1DHnZeBk5oflRSb5mxe1vieKd0AJubMNM cTLtsrSYNJMyjL5pAXutgkkJp99G X-Google-Smtp-Source: ACcGV62e8eC7NCTeq27lhfveXZ10FBKisMqSmmqJuT9THNq/GG/X45e2nuWRstf8AyEdu9ruKwP/PQ== X-Received: by 2002:a63:f14a:: with SMTP id o10-v6mr3944100pgk.339.1538250900024; Sat, 29 Sep 2018 12:55:00 -0700 (PDT) Received: from mappy.world.mentorg.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.gmail.com with ESMTPSA id b126-v6sm18371946pga.49.2018.09.29.12.54.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 12:54:59 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman , devel@driverdev.osuosl.org (open list:STAGING SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [RESEND PATCH v7 10/17] media: staging/imx: of: Remove recursive graph walk Date: Sat, 29 Sep 2018 12:54:13 -0700 Message-Id: <20180929195420.28579-11-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929195420.28579-1-slongerbeam@gmail.com> References: <20180929195420.28579-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After moving to subdev notifiers, it's no longer necessary to recursively walk the OF graph, because the subdev notifiers will discover and add devices from the graph for us. So the recursive of_parse_subdev() function is gone, replaced with of_add_csi() which adds only the CSI port fwnodes to the imx-media root notifier. Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-media-of.c | 106 ++--------------------- 1 file changed, 8 insertions(+), 98 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-of.c b/drivers/staging/media/imx/imx-media-of.c index acde372c6795..1c9175433ba6 100644 --- a/drivers/staging/media/imx/imx-media-of.c +++ b/drivers/staging/media/imx/imx-media-of.c @@ -20,74 +20,19 @@ #include