From patchwork Mon Jun 3 15:49:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 165656 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4647709ili; Mon, 3 Jun 2019 08:54:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGTt944Lhf/PqgAMIqe3II00cwwzz5slYMgMGX4aKOVtohi74TQSkGwODnAzbupS4REjk9 X-Received: by 2002:a17:90a:e17:: with SMTP id v23mr30271479pje.139.1559577290117; Mon, 03 Jun 2019 08:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559577290; cv=none; d=google.com; s=arc-20160816; b=q2kTGLJIObPVbd5j2KgTIEdzDaD61QKzbztrtJLrj7k7YpkZ0RR+9YK/dBbEaO645R 3VFXmQeQeAtQlCoD6frG3LnniIgVAlE1jUeyNbq60Grf4C820AFetcd9iTOE652GkfWR YCoE8PROJXo57W8hzdzVcThaCI4ZLcDKOF2pvHJBndtB62FdYpIL8FV7L2mjCr3B2HZt VYPahxi4+czo+WYqg3DULsvSj/xXgUqdBaxv03s/Yy5HXBTZbwEs/pK+EMdTWwRek89t V4GiPhSjNm068YOk76Dr4rq6h5Qr3g/RNx9OT/UaZ9epqcMV17BAfaTqIUVnHI+45HQa 8cRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=LP2RjXruQcI9RvjW+DmrRgZc+4tZ5qnmCkmUTMriLP0=; b=KNc6SeX9FTGa9U9/Snacv7ky54RS9vNFjJVcCXz2KrKaLIDwyDrZZ5hiUBHzonW89y 3UUhM8DO7DP28Nz11e0CeVxCg1RkfR47jC3SImuNBCNiFGOlr+SOpWx/pp0zoQc/uRLS FavYZzvEWkX3hUEpKChlHn2KUGT8NnZKZJbAw6QBIYyvkWAt1tzHxqePsTur3sLTj322 HrvkZ2uFTp+JTxwb41j3Ib2FFi4i2EyNyMQPuvWxmJDo2a2+0SaqluIuN44PQ2pFisJA dnoVp5rLVPm3v7+yZYPlWONObil2wwLgjkZsk5vGr/54SHgCaN0iFecSF0CUR6rHnByP xKIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w17si7474704pjn.21.2019.06.03.08.54.49; Mon, 03 Jun 2019 08:54:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729734AbfFCPys (ORCPT + 30 others); Mon, 3 Jun 2019 11:54:48 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:53654 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728731AbfFCPvT (ORCPT ); Mon, 3 Jun 2019 11:51:19 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 90E4B15AB; Mon, 3 Jun 2019 08:51:18 -0700 (PDT) Received: from en101.cambridge.arm.com (en101.cambridge.arm.com [10.1.196.93]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 817F83F246; Mon, 3 Jun 2019 08:51:17 -0700 (PDT) From: Suzuki K Poulose To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, suzuki.poulose@arm.com, Ulf Hansson Subject: [RFC PATCH 13/57] drivers: Add generic helper for matching device by fwnode Date: Mon, 3 Jun 2019 16:49:39 +0100 Message-Id: <1559577023-558-14-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559577023-558-1-git-send-email-suzuki.poulose@arm.com> References: <1559577023-558-1-git-send-email-suzuki.poulose@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of spilling the match function to check the device fwnode everywhere, let us add a generic helper which can be reused by all. Also adds a wrapper for bus_find_device to find a device by fwnode. Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Ulf Hansson Signed-off-by: Suzuki K Poulose --- drivers/base/core.c | 6 ++++++ include/linux/device.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+) -- 2.7.4 diff --git a/drivers/base/core.c b/drivers/base/core.c index d20699c..141c4f8 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3334,3 +3334,9 @@ int device_match_of_node(struct device *dev, void *np) return dev->of_node == np; } EXPORT_SYMBOL_GPL(device_match_of_node); + +int device_match_fwnode(struct device *dev, void *fwnode) +{ + return dev_fwnode(dev) == fwnode; +} +EXPORT_SYMBOL_GPL(device_match_fwnode); diff --git a/include/linux/device.h b/include/linux/device.h index fe16be4..54be931 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -164,6 +164,7 @@ struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); void subsys_dev_iter_exit(struct subsys_dev_iter *iter); int device_match_of_node(struct device *dev, void *np); +int device_match_fwnode(struct device *dev, void *fwnode); int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, int (*fn)(struct device *dev, void *data)); @@ -188,6 +189,20 @@ static inline struct device *bus_find_device_by_of_node(struct bus_type *bus, return bus_find_device(bus, start, np, device_match_of_node); } +/** + * bus_find_device_by_fwnode : device iterator for locating a particular device + * matching the fwnode. + * @bus: bus type + * @start: Device to begin with + * @fwnode: fwnode of the device to match. + */ +static inline struct device *bus_find_device_by_fwnode(struct bus_type *bus, + struct device *start, + struct fwnode_handle *fwnode) +{ + return bus_find_device(bus, start, fwnode, device_match_fwnode); +} + struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, struct device *hint); int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,