From patchwork Sun May 31 22:24:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 6516911 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2D918C0020 for ; Sun, 31 May 2015 22:26:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3A750205C1 for ; Sun, 31 May 2015 22:26:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B98420397 for ; Sun, 31 May 2015 22:26:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752104AbbEaWZs (ORCPT ); Sun, 31 May 2015 18:25:48 -0400 Received: from nblzone-211-213.nblnetworks.fi ([83.145.211.213]:37421 "EHLO hillosipuli.retiisi.org.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751272AbbEaWZr (ORCPT ); Sun, 31 May 2015 18:25:47 -0400 Received: from lanttu.localdomain (lanttu-e.localdomain [192.168.1.64]) by hillosipuli.retiisi.org.uk (Postfix) with ESMTP id F404760098; Mon, 1 Jun 2015 01:25:39 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, linux-leds@vger.kernel.org, j.anaszewski@samsung.com, cooloney@gmail.com, s.nawrocki@samsung.com, mchehab@osg.samsung.com, g.liakhovetski@gmx.de Subject: [PATCH v1.1 1/5] v4l: async: Add a pointer to of_node to struct v4l2_subdev, match it Date: Mon, 1 Jun 2015 01:24:39 +0300 Message-Id: <1433111079-22457-1-git-send-email-sakari.ailus@iki.fi> X-Mailer: git-send-email 2.1.4 In-Reply-To: <4071589.mUaJIGvIJX@avalon> References: <4071589.mUaJIGvIJX@avalon> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP V4L2 async sub-devices are currently matched (OF case) based on the struct device_node pointer in struct device. LED devices may have more than one LED, and in that case the OF node to match is not directly the device's node, but a LED's node. Signed-off-by: Laurent Pinchart Signed-off-by: Sakari Ailus Acked-by: Laurent Pinchart --- since v1: - Move conditional setting of struct v4l2_subdev.of_node from v4l2_device_register_subdev() to v4l2_async_register_subdev. - Remove the check for NULL struct v4l2_subdev.of_node from match_of() as it's no longer needed. - Unconditionally state in the struct v4l2_subdev.of_node field comment that the field contains (a pointer to) the sub-device's of_node. drivers/media/v4l2-core/v4l2-async.c | 34 ++++++++++++++++++++++------------ include/media/v4l2-subdev.h | 2 ++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 85a6a34..b0badac 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -22,10 +22,10 @@ #include #include -static bool match_i2c(struct device *dev, struct v4l2_async_subdev *asd) +static bool match_i2c(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd) { #if IS_ENABLED(CONFIG_I2C) - struct i2c_client *client = i2c_verify_client(dev); + struct i2c_client *client = i2c_verify_client(sd->dev); return client && asd->match.i2c.adapter_id == client->adapter->nr && asd->match.i2c.address == client->addr; @@ -34,14 +34,24 @@ static bool match_i2c(struct device *dev, struct v4l2_async_subdev *asd) #endif } -static bool match_devname(struct device *dev, struct v4l2_async_subdev *asd) +static bool match_devname(struct v4l2_subdev *sd, + struct v4l2_async_subdev *asd) { - return !strcmp(asd->match.device_name.name, dev_name(dev)); + return !strcmp(asd->match.device_name.name, dev_name(sd->dev)); } -static bool match_of(struct device *dev, struct v4l2_async_subdev *asd) +static bool match_of(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd) { - return dev->of_node == asd->match.of.node; + return sd->of_node == asd->match.of.node; +} + +static bool match_custom(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd) +{ + if (!asd->match.custom.match) + /* Match always */ + return true; + + return asd->match.custom.match(sd->dev, asd); } static LIST_HEAD(subdev_list); @@ -51,17 +61,14 @@ 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; - bool (*match)(struct device *, struct v4l2_async_subdev *); 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 = asd->match.custom.match; - if (!match) - /* Match always */ - return asd; + match = match_custom; break; case V4L2_ASYNC_MATCH_DEVNAME: match = match_devname; @@ -79,7 +86,7 @@ static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier * } /* match cannot be NULL here */ - if (match(sd->dev, asd)) + if (match(sd, asd)) return asd; } @@ -266,6 +273,9 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd) { struct v4l2_async_notifier *notifier; + if (!sd->of_node && sd->dev) + sd->of_node = sd->dev->of_node; + mutex_lock(&list_lock); INIT_LIST_HEAD(&sd->async_list); diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 8f5da73..8a17c24 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -603,6 +603,8 @@ struct v4l2_subdev { struct video_device *devnode; /* pointer to the physical device, if any */ struct device *dev; + /* A device_node of the subdev, usually the same as dev->of_node. */ + struct device_node *of_node; /* Links this subdev to a global subdev_list or @notifier->done list. */ struct list_head async_list; /* Pointer to respective struct v4l2_async_subdev. */