Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4662022imm; Tue, 9 Oct 2018 03:18:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV62gss9gFVqOR8WW/hRn1rKKUR6KNrS9OmQTYSURS9EqVfAqiodBpxKf4RYx94UNbsJOn88b X-Received: by 2002:a62:1906:: with SMTP id 6-v6mr30078243pfz.9.1539080332393; Tue, 09 Oct 2018 03:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539080332; cv=none; d=google.com; s=arc-20160816; b=kGoy7xo66cqUJL7eQdHnHknmdT1M4gRW34LZzyRl6gzPEeBzSCc+NzO5OhFJ6NWfWg gwp0Dx1QKhCGQnPe4xU95xVjsfljgicIEVPabcDlnDsgF41S/CCApa4bu6nVGSzPxyvz jMRTnbngwgOyZJRM+rEVsrLk9InVs+imZiIw8Cosk+kYn/+ZlbxhTMCjXjfMAk3ZBDya Piano6di/b+cNEn4BFV0EN1JNa01VNPylIfVQRwBGKGnWNgHiDiDLZU12jg7hW4eD3Kf Q/BX4QEACWV4vYc0bqqVn4O6rM5TgGRezMdOIC4xP8f0k82LZNmx94SRwAYLB5c7qdIz drog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=I+XobssBceHNES2QCYGPphH3TI/xahn3VphKv1PaJ08=; b=mFfI5LLJbwECPwSA6NBBQZ/TaynLy0E5qqr471GKIiuECDeCU0CHet7ps5J/q/wxyM wc+I+/D/xXofQ2Y71736vB48iwf+zaMnt5OaghAT8Ux+VevWyMzy/KmxSWoI7CU66xIu uwlVoTjAbufu7iYmW345tj1Ps6dUl+WEiGC7G1kKHYSAwGxQp8SwDldcmihUwtwHpNLB dUT6x5FugHfrRhDm6wEURS++eNM6cgoCs8TxfNXnv5re5d/h85P7jHCNB/a70jvU6x+S 2agU/y0ecTDwTMRGckxIwZ/8F7l6NK6y0PAlL/OYSzmhSYUK95B04NDr+MBJBzckTc6V ADPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mvista-com.20150623.gappssmtp.com header.s=20150623 header.b=kqqN+8V5; 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 k20-v6si19732139pgb.115.2018.10.09.03.18.36; Tue, 09 Oct 2018 03:18:52 -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; dkim=pass header.i=@mvista-com.20150623.gappssmtp.com header.s=20150623 header.b=kqqN+8V5; 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 S1726525AbeJIRe0 (ORCPT + 99 others); Tue, 9 Oct 2018 13:34:26 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46295 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725892AbeJIReZ (ORCPT ); Tue, 9 Oct 2018 13:34:25 -0400 Received: by mail-pf1-f196.google.com with SMTP id r64-v6so590814pfb.13 for ; Tue, 09 Oct 2018 03:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mvista-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=I+XobssBceHNES2QCYGPphH3TI/xahn3VphKv1PaJ08=; b=kqqN+8V5DmD2G67Qmj/ItzHVG5l/lMtKvreNGNnhVmjNFMrH/8lFPPVTZVQHumLAle yiyB4rLkx1ZFnkw4xmCYB2xSWWBQ+6VEbUmarj0CY1gkHPgiKSlLfj24+eSKXPpucB3w YBCEa4/7ts8ETb4YzB3ik5U93Jpz4AM0D51MnJp47tV7kXigAymIvH8ZkmL8xokx8Gjq GcW8d8WSYBRqI47W6WoKAspcZsrzDq/Fj0vocE1jU9bL+uo9n1EeTRqnugID6CdH2phw VuJTWFklzW44F06kptF+tuiuom4g9wnulGGik0AOBEtUcSswNRvdFlvTOF/XXtPpX6Wr syJA== 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; bh=I+XobssBceHNES2QCYGPphH3TI/xahn3VphKv1PaJ08=; b=rAJ7/sA9KILpvPIu575qkLo82uc4QITWyYRlBnbljoZG4XxLXgY8GnAiVYQnxerDY9 /wnYXatHqnRyOsxnWuMh+6gZooLvoPgZYm7KojygJan6yc2FrZb/EvtgpuGVTqeWCZZW wy5snxwv05k8XLmnM8obudDCQuw3/76Ho0Xe1r14c7/w0MB2QLOpeM5OeIfy3dOpSx6p BJkBUzsCE0xV3/043EUxSENdGrjvOplLeFyRU6F1DSEGiANqzzLbLgOToHkMRtpXskvd jUfjJNoiZZPuqp9C556zhndsdVKMwhTUUVP1yXgYe+mxV3q0VDt/aUENAGv704t21VRA xWiA== X-Gm-Message-State: ABuFfoh08cMqo7a+DGXRRHTeZPQDW7lm5BLYaRu+i9oEXtkSr+ZP7Hwq Xn+Kf24/mNZ26wApIUZRiUXbFA== X-Received: by 2002:a62:20d8:: with SMTP id m85-v6mr29277521pfj.152.1539080292835; Tue, 09 Oct 2018 03:18:12 -0700 (PDT) Received: from mercury.mvista.com ([182.72.92.62]) by smtp.gmail.com with ESMTPSA id z22-v6sm20854472pgv.24.2018.10.09.03.18.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 03:18:11 -0700 (PDT) From: Silesh C V To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-spi@vger.kernel.org, Mathieu Poirier , Wolfram Sang , Lijun Ou , "Wei Hu(Xavier)" , Yisen Zhuang , Salil Mehta , Srinivas Kandagatla , Andrew Lunn , Florian Fainelli , Rob Herring , Frank Rowand , Mark Brown , "David S. Miller" , Silesh C V Subject: [PATCH v3 1/2] Driver core: add bus_find_device_by_fwnode Date: Tue, 9 Oct 2018 15:47:24 +0530 Message-Id: <1539080245-25818-1-git-send-email-svellattu@mvista.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some drivers need to find the device on a bus having a specific firmware node. Currently, such drivers have their own implementations to do this. Provide a helper similar to bus_find_device_by_name so that each driver does not have to reinvent this. Signed-off-by: Silesh C V --- Changes since v2: - make use of dev_fwnode in match_fwnode. drivers/base/bus.c | 20 ++++++++++++++++++++ include/linux/device.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 8bfd27e..a2f39db 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" @@ -373,6 +374,25 @@ struct device *bus_find_device_by_name(struct bus_type *bus, } EXPORT_SYMBOL_GPL(bus_find_device_by_name); +static int match_fwnode(struct device *dev, void *fwnode) +{ + return dev_fwnode(dev) == fwnode; +} + +/** + * bus_find_device_by_fwnode - device iterator for locating a particular device + * having a specific firmware node + * @bus: bus type + * @start: Device to begin with + * @fwnode: firmware node of the device to match + */ +struct device *bus_find_device_by_fwnode(struct bus_type *bus, struct device *start, + struct fwnode_handle *fwnode) +{ + return bus_find_device(bus, start, (void *)fwnode, match_fwnode); +} +EXPORT_SYMBOL_GPL(bus_find_device_by_fwnode); + /** * subsys_find_device_by_id - find a device with a specific enumeration number * @subsys: subsystem diff --git a/include/linux/device.h b/include/linux/device.h index 8f88254..09384f6 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -171,6 +171,9 @@ struct device *bus_find_device(struct bus_type *bus, struct device *start, struct device *bus_find_device_by_name(struct bus_type *bus, struct device *start, const char *name); +struct device *bus_find_device_by_fwnode(struct bus_type *bus, + struct device *start, + struct fwnode_handle *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, -- 1.9.1