From patchwork Mon Sep 28 23:54:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Anholt X-Patchwork-Id: 7281591 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A09FD9F40A for ; Mon, 28 Sep 2015 23:54:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D34EB20702 for ; Mon, 28 Sep 2015 23:54:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 225B320709 for ; Mon, 28 Sep 2015 23:54:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4AA0D6EA77; Mon, 28 Sep 2015 16:54:27 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from annarchy.freedesktop.org (annarchy.freedesktop.org [131.252.210.176]) by gabe.freedesktop.org (Postfix) with ESMTP id 06F966EA73; Mon, 28 Sep 2015 16:54:26 -0700 (PDT) Received: from eliezer.anholt.net (annarchy.freedesktop.org [127.0.0.1]) by annarchy.freedesktop.org (Postfix) with ESMTP id EB59B1818F; Mon, 28 Sep 2015 16:54:25 -0700 (PDT) Received: by eliezer.anholt.net (Postfix, from userid 1000) id 48D1FF0053B; Mon, 28 Sep 2015 16:54:09 -0700 (PDT) From: Eric Anholt To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] component: Make a "match_add all devices matching my drivers" helper. Date: Mon, 28 Sep 2015 16:54:08 -0700 Message-Id: <1443484449-31868-1-git-send-email-eric@anholt.net> X-Mailer: git-send-email 2.1.4 Cc: Greg Kroah-Hartman , Seung-Woo Kim , linux-kernel@vger.kernel.org, Kyungmin Park X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 The body of the loop is taken from the exynos driver. It appears to also be useful in msm, and I've used it in vc4. Signed-off-by: Eric Anholt Reviewed-by: Gustavo Padovan --- This is separated from converting exynos to use it, to let it land separately and not have to sync between trees. drivers/base/component.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/component.h | 5 +++++ 2 files changed, 45 insertions(+) diff --git a/drivers/base/component.c b/drivers/base/component.c index f748430..08167a3 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -16,6 +16,7 @@ #include #include #include +#include #include struct component_match { @@ -283,6 +284,45 @@ void component_match_add(struct device *dev, struct component_match **matchptr, } EXPORT_SYMBOL(component_match_add); +static int compare_dev(struct device *dev, void *data) +{ + return dev == (struct device *)data; +} + +/** + * component_match_add_platform_drivers - For each driver passed in, + * finds each device that probed with it and adds it as a component + * driver to the match list. + * @dev: master device for the components + * @match: pointer to the match structure pointer. For the first + * component_match_add(), this should be a pointer to a NULL + * pointer, which will get filled in by the call. + * @drivers: array of platform drivers whose devices should all be + * added to the match + * @count: number of platform drivers to match + */ +void component_match_add_platform_drivers(struct device *dev, + struct component_match **match, + struct platform_driver *const *drivers, + int count) +{ + int i; + + for (i = 0; i < count; i++) { + struct device_driver *drv = &drivers[i]->driver; + struct device *p = NULL, *d; + + while ((d = bus_find_device(&platform_bus_type, p, drv, + (void *)platform_bus_type.match))) { + put_device(p); + component_match_add(dev, match, compare_dev, d); + p = d; + } + put_device(p); + } +} +EXPORT_SYMBOL_GPL(component_match_add_platform_drivers); + int component_master_add_with_match(struct device *dev, const struct component_master_ops *ops, struct component_match *match) diff --git a/include/linux/component.h b/include/linux/component.h index c00dcc3..2d74420 100644 --- a/include/linux/component.h +++ b/include/linux/component.h @@ -2,6 +2,7 @@ #define COMPONENT_H struct device; +struct platform_driver; struct component_ops { int (*bind)(struct device *, struct device *, void *); @@ -35,5 +36,9 @@ int component_master_add_with_match(struct device *, const struct component_master_ops *, struct component_match *); void component_match_add(struct device *, struct component_match **, int (*compare)(struct device *, void *), void *compare_data); +void component_match_add_platform_drivers(struct device *dev, + struct component_match **match, + struct platform_driver *const *drivers, + int count); #endif