From patchwork Tue May 2 16:54:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9708377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7BC5360385 for ; Tue, 2 May 2017 16:54:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E7E6284DA for ; Tue, 2 May 2017 16:54:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 634AF284E4; Tue, 2 May 2017 16:54:38 +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=-6.9 required=2.0 tests=BAYES_00,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 0E8ED284DA for ; Tue, 2 May 2017 16:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751018AbdEBQyg (ORCPT ); Tue, 2 May 2017 12:54:36 -0400 Received: from smtp-4.sys.kth.se ([130.237.48.193]:54616 "EHLO smtp-4.sys.kth.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750769AbdEBQyf (ORCPT ); Tue, 2 May 2017 12:54:35 -0400 Received: from smtp-4.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-4.sys.kth.se (Postfix) with ESMTP id 68263189; Tue, 2 May 2017 18:54:33 +0200 (CEST) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-4.sys.kth.se ([127.0.0.1]) by smtp-4.sys.kth.se (smtp-4.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id CixYQWI20ljd; Tue, 2 May 2017 18:54:32 +0200 (CEST) X-KTH-Auth: niso [89.233.230.99] X-KTH-mail-from: niklas.soderlund+renesas@ragnatech.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by smtp-4.sys.kth.se (Postfix) with ESMTPSA id F281F9B; Tue, 2 May 2017 18:54:31 +0200 (CEST) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: Sakari Ailus , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: Laurent Pinchart , Kieran Bingham , hverkuil@xs4all.nl, =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH] v4l2-async: add v4l2_async_match() Date: Tue, 2 May 2017 18:54:13 +0200 Message-Id: <20170502165413.7559-1-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.12.2 MIME-Version: 1.0 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 For drivers registering notifiers with more then one subdevices it's difficult to know exactly which one is being bound in each call to the notifiers bound callback. Comparing OF nodes became harder after the introduction of fwnode where the two following comparisons are not equal but where so previous to fwnode. asd.match.fwnode.fwnode == of_fwnode_handle(subdev->dev->of_node) asd.match.fwnode.fwnode == of_fwnode_handle(subdev->of_node) It's also not ideal to directly access the asd.match union without first checking the match_type. So to make it easier for drivers to perform this type of matching export the v4l2 async match helpers with a new symbol v4l2_async_match(). This wold replace the comparisons above with: v4l2_async_match(subdev, &asd) Suggested-by: Kieran Bingham Signed-off-by: Niklas Söderlund --- drivers/media/v4l2-core/v4l2-async.c | 52 +++++++++++++++++++++--------------- include/media/v4l2-async.h | 11 ++++++++ 2 files changed, 41 insertions(+), 22 deletions(-) Depends on '[PATCH v3 0/7] V4L2 fwnode support' and tested on Renesas R-Car H3 and M3-W together with rcar-vin Gen3 patches. diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index cbd919d4edd27e17..c291ffda4d18202b 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -60,6 +60,35 @@ static bool match_custom(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd) return asd->match.custom.match(sd->dev, asd); } +bool v4l2_async_match(struct v4l2_subdev *sd, + struct v4l2_async_subdev *asd) +{ + bool (*match)(struct v4l2_subdev *, struct v4l2_async_subdev *); + + switch (asd->match_type) { + case V4L2_ASYNC_MATCH_CUSTOM: + match = match_custom; + break; + case V4L2_ASYNC_MATCH_DEVNAME: + match = match_devname; + break; + case V4L2_ASYNC_MATCH_I2C: + match = match_i2c; + break; + case V4L2_ASYNC_MATCH_FWNODE: + match = match_fwnode; + break; + default: + /* Cannot happen, unless someone breaks us */ + WARN_ON(true); + return false; + } + + /* match cannot be NULL here */ + return match(sd, asd); +} +EXPORT_SYMBOL(v4l2_async_match); + static LIST_HEAD(subdev_list); static LIST_HEAD(notifier_list); static DEFINE_MUTEX(list_lock); @@ -67,32 +96,11 @@ static DEFINE_MUTEX(list_lock); static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier *notifier, struct v4l2_subdev *sd) { - bool (*match)(struct v4l2_subdev *, struct v4l2_async_subdev *); struct v4l2_async_subdev *asd; list_for_each_entry(asd, ¬ifier->waiting, list) { /* bus_type has been verified valid before */ - switch (asd->match_type) { - case V4L2_ASYNC_MATCH_CUSTOM: - match = match_custom; - break; - case V4L2_ASYNC_MATCH_DEVNAME: - match = match_devname; - break; - case V4L2_ASYNC_MATCH_I2C: - match = match_i2c; - break; - case V4L2_ASYNC_MATCH_FWNODE: - match = match_fwnode; - break; - default: - /* Cannot happen, unless someone breaks us */ - WARN_ON(true); - return NULL; - } - - /* match cannot be NULL here */ - if (match(sd, asd)) + if (v4l2_async_match(sd, asd)) return asd; } diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h index c69d8c8a66d0093a..45677387282919d7 100644 --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h @@ -135,4 +135,15 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd); * @sd: pointer to &struct v4l2_subdev */ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd); + +/** + * v4l2_async_match - match a subdevice with a asynchronous subdevice descriptor + * + * @sd: pointer to &struct v4l2_subdev + * @asd: pointer to &struct v4l2_async_subdev + * + * Return: true if @asd matches @sd else false + */ +bool v4l2_async_match(struct v4l2_subdev *sd, + struct v4l2_async_subdev *asd); #endif