Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2135197imm; Sun, 23 Sep 2018 21:36:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV62XPimvGpRLt6Y7D42DFYKDVQ1O2IJxdBB5ZCk+H6xVeakXuZ8X8iNoMm6HMbXUG2bz2//7 X-Received: by 2002:a63:ed55:: with SMTP id m21-v6mr7904497pgk.147.1537763810950; Sun, 23 Sep 2018 21:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537763810; cv=none; d=google.com; s=arc-20160816; b=mhVoWmYneZsNj5vkgWRaUpzhDwrBwjvP6Pi2W7CafLdGXOD65rRvcM1V0BIe7IMor0 dYEN84NAOS9KlVZ7QnEnNO+peQ79LnAyzImtNHRctYOLbK+PuIy86iguiDYrAT1vW5I+ E8Kd33HJSLpOXHABecyPvxAv9YG1aap2BxKYW+x/ULn5jslsBtlaW8KiiUhcY1nCHjsp XSyxjHD+IqJOodFL4CtcTyhguZzFxx6gSXzOr7WlIBWXeLvasvLP3S9tIw/AwAvpblql 8oypoS6U+IKiLe2UdjjubmIV3Z5cChbc3UQs0HG+MgSZ6KWBwu+nE6Hkbyb4US4ifWvy p4lQ== 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=/HACrf5Tu+AFLWvxevDv+YUccBR9VUVbHvWi9W3Q3SM=; b=ynh1yHg01+q9tvi6iFmTKBIjrUhcCX5+BGlbDYsr0ya29BZBXN2vZE7WSnSUMun8Pt i0RgtGxczEabmmLMmdnI+T8c4tNdynIQjj31X9Cx46/YEhLCV6HkmJGnzHJN8zSUB/lf oUjpR6oTSa48mXAqK0OBVqic5hMELyqe2vNeVsbwvAEl2X6EngVuwyb0s9oi0m1SmlVN uHSRQEo8DLvwTtY+qxFcCplnztoLmphbkIZSD5rfDPIVZvZsRMSPqFcNpkgtsTVW/kTN wYKlhyaLQHWsU3yqB8clcLe9nDeaKeOsgjT2V5YMiDk0XyFhGg/hV1u2gPEbYjV1HxAf TKpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mvista-com.20150623.gappssmtp.com header.s=20150623 header.b=YPBUg3ca; 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 c185-v6si4590190pfg.158.2018.09.23.21.36.24; Sun, 23 Sep 2018 21:36: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; dkim=pass header.i=@mvista-com.20150623.gappssmtp.com header.s=20150623 header.b=YPBUg3ca; 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 S1727405AbeIXKg3 (ORCPT + 99 others); Mon, 24 Sep 2018 06:36:29 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46040 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726158AbeIXKg3 (ORCPT ); Mon, 24 Sep 2018 06:36:29 -0400 Received: by mail-pl1-f195.google.com with SMTP id j8-v6so8532729pll.12 for ; Sun, 23 Sep 2018 21:36:17 -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=/HACrf5Tu+AFLWvxevDv+YUccBR9VUVbHvWi9W3Q3SM=; b=YPBUg3ca8xtoi0h1eE8c6fzRdSFu6zsT6GFUkG6iO6ieUEXrYRlaIDEUJitaeVvvxF z3tyH6xj3P/DjOC1h+gLIqAV4Z8R4RGS09P2wV+V2NgL60E8lqfouTmsbfncQvFDXWh8 i7YvqTvvqYtSiSYJx33BNHOsGU3oGdihGdtYtGtAc4Kldq/IZer224ipKbwIsXDFutYG CVIcuUISReFkAfiWfwJfHxHGYqrKkfnznayxX9Ym1GmEJpK10Xst+pzfdeI2+Do4wHZQ D4KKxm6VqkImXbK9o2mzCA1KC2UhJTpEqMxy50DdHkxYmVy6+0+ZNhgV5ERbed+7HGIe icnQ== 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=/HACrf5Tu+AFLWvxevDv+YUccBR9VUVbHvWi9W3Q3SM=; b=eM0s/CEdqQAaCFtNTRLu8ky1cmlrFkyvSdEIHr5/1uWs6TZfWY8oKfbHp2GvhC+naB ozRHDEMbpxiEKQ1nB0spK+8FhszPVOKN+axI3lhvcziU0JqLw1LRZfkwzLykA2+iqBj0 qt9ax30z92mGfIaWpMUxx/puk/nR9FkrfCj1BoWoE4FrU7ErKDcswb7oVfLLtc1KrMAO FkOtZrd0c2D/opiFwf1qldBfaKuxh24wqEYbFdrkUfHUMXVoZbWfAvX5srzyxS9aRKKt xNZP/hjJgxw3fCvTEd60kajZo5IhqE5WgTfMwqHjdMyfJaAVNFfYRr9hfsn7uLC/w9sT rsPQ== X-Gm-Message-State: ABuFfojNb7jaIxw9oDFkvEEHV3JWf2Q2vTYBoQGnXtxoG5TE9rq31Spf UjZRHdH6UHmus2MoPy1WMlO72A== X-Received: by 2002:a17:902:710e:: with SMTP id a14-v6mr4660629pll.179.1537763777253; Sun, 23 Sep 2018 21:36:17 -0700 (PDT) Received: from mercury.CELSYSJYN.IN ([182.72.92.62]) by smtp.gmail.com with ESMTPSA id d81-v6sm53071725pfj.122.2018.09.23.21.36.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Sep 2018 21:36:16 -0700 (PDT) From: Silesh C V To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, Silesh C V Subject: [PATCH] Driver core: add bus_find_device_by_fwnode Date: Mon, 24 Sep 2018 10:05:55 +0530 Message-Id: <1537763755-28871-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 --- drivers/base/bus.c | 26 ++++++++++++++++++++++++++ include/linux/device.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 8bfd27e..148b198 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,31 @@ 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 *data) +{ + struct fwnode_handle *fwnode = data; + struct device_node *of_node = to_of_node(fwnode); + + if (of_node) + return dev->of_node == of_node; + else + return dev->fwnode == 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