From patchwork Wed Oct 24 15:05:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10654757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23BFA13A4 for ; Wed, 24 Oct 2018 15:05:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFC9F1FFB1 for ; Wed, 24 Oct 2018 15:05:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3FBF2A953; Wed, 24 Oct 2018 15:05:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76E981FFB1 for ; Wed, 24 Oct 2018 15:05:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727313AbeJXXeG (ORCPT ); Wed, 24 Oct 2018 19:34:06 -0400 Received: from mga12.intel.com ([192.55.52.136]:34388 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726497AbeJXXeF (ORCPT ); Wed, 24 Oct 2018 19:34:05 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Oct 2018 08:05:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,420,1534834800"; d="scan'208";a="102104730" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 24 Oct 2018 08:05:36 -0700 From: Heikki Krogerus To: Heiko Stuebner Cc: Guenter Roeck , Hans de Goede , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 5/5] drivers core: Find device connections also from device graphs Date: Wed, 24 Oct 2018 18:05:25 +0300 Message-Id: <20181024150525.11552-6-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181024150525.11552-1-heikki.krogerus@linux.intel.com> References: <20181024150525.11552-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If connections between devices are described in OF graph or ACPI device graph, we can find them by using the fwnode_graph_*() functions. Signed-off-by: Heikki Krogerus --- drivers/base/devcon.c | 48 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c index d427e806cd73..9c446ef84dd1 100644 --- a/drivers/base/devcon.c +++ b/drivers/base/devcon.c @@ -7,10 +7,45 @@ */ #include +#include static DEFINE_MUTEX(devcon_lock); static LIST_HEAD(devcon_list); +static void * +fwnode_graph_devcon_match(struct fwnode_handle *fwnode, + const char *con_id, void *data, + void *(*match)(struct device_connection *con, + int ep, void *data)) +{ + struct device_connection con = { .id = con_id }; + struct fwnode_handle *ep; + const char *val; + void *ret; + int err; + + fwnode_graph_for_each_endpoint(fwnode, ep) { + con.fwnode = fwnode_graph_get_remote_port_parent(ep); + + if (con_id) { + err = fwnode_property_read_string(con.fwnode, "name", + &val); + if (err || strcmp(con_id, val)) { + fwnode_handle_put(con.fwnode); + continue; + } + } + + ret = match(&con, -1, data); + fwnode_handle_put(con.fwnode); + if (ret) { + fwnode_handle_put(ep); + return ret; + } + } + return NULL; +} + /** * device_connection_find_match - Find physical connection to a device * @dev: Device with the connection @@ -23,10 +58,11 @@ static LIST_HEAD(devcon_list); * caller is expecting to be returned. */ void *device_connection_find_match(struct device *dev, const char *con_id, - void *data, - void *(*match)(struct device_connection *con, - int ep, void *data)) + void *data, + void *(*match)(struct device_connection *con, + int ep, void *data)) { + struct fwnode_handle *fwnode = dev_fwnode(dev); const char *devname = dev_name(dev); struct device_connection *con; void *ret = NULL; @@ -35,6 +71,12 @@ void *device_connection_find_match(struct device *dev, const char *con_id, if (!match) return NULL; + if (fwnode) { + ret = fwnode_graph_devcon_match(fwnode, con_id, data, match); + if (ret) + return ret; + } + mutex_lock(&devcon_lock); list_for_each_entry(con, &devcon_list, list) {