Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5989660ybi; Wed, 29 May 2019 00:46:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzA6ppshcHs6iyQQpJdAd0GWrFaaesQK+cERru68jq8puqIyhAUPY+lj/2pS4/EzUMKkAWn X-Received: by 2002:a63:2fc3:: with SMTP id v186mr26847149pgv.107.1559115983379; Wed, 29 May 2019 00:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559115983; cv=none; d=google.com; s=arc-20160816; b=KJbH8oo10L6Ry4qiW20b2WRHpIjX9HO48WQBzS0Szyx4dshIezWcKxJ2AHuZkG4ule pZOt8Knk3vK5EYCLbkfPPBVx8g5l+4/z9ONb0+0wly8sHIL3I5Ez2XUQbqmq0yS78LzH qxAi8CQ0C4piD64PQtDHMupJGUaMzJLrvudozJF/VnxV6ztmgR4DAspKp5WyMOj4Ny5N LvPc00xQQbCpyt6TYLaZqGDMywNbeLj6mZUAWEi2pOoii06GouzbL1aburpt0dljdMqU NfJQVTOAg+UMhBuJptMNWTNgUGfmwJ9jlDJEz6682Z/+caiARqg00DjpfxMCh8cLXar+ GMxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=gWr9Rf44TZBzMRQiEnixbCcXSfQCEJcOCBfF/bH8JY4=; b=AhY3pgpkAoo4dmM/LcQFDbcxNGJFIwKPG7fPkX+zcB+P/U1ZDd5G7AxIdyEaj6zyNe END5kxtUMp/7SYMofArRqMR69h20oSvBlFE5nxH3F1+reMM6kCKQzkYl3kTF9//jFYj6 n3BYu0TBA+4a+lXq7jy1C6/nCy6CJA3twxSXnDxsoJsQP3X2obfMUE6EHuHnt0VAk3q1 2GLFEnLJ1Y8nusvVLA9pznwZwpfOQCSfj5f6k593mvkHMxOewDuezK3au3HuKL1cZYAp b7o4BAS0wHphHE0WZEYj38+0lIyeQjN4HoPuwDFBY3ZmvYQvsJcnc4fAeHWcImK8b4XA KV/w== 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 34si24892925plp.305.2019.05.29.00.46.08; Wed, 29 May 2019 00:46:23 -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 S1727017AbfE2Ho2 (ORCPT + 99 others); Wed, 29 May 2019 03:44:28 -0400 Received: from Mailgw01.mediatek.com ([1.203.163.78]:27133 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726842AbfE2HoW (ORCPT ); Wed, 29 May 2019 03:44:22 -0400 X-UUID: cf43890cc10640748f2aef7fa618f03d-20190529 X-UUID: cf43890cc10640748f2aef7fa618f03d-20190529 Received: from mtkcas36.mediatek.inc [(172.27.4.253)] by mailgw01.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLS) with ESMTP id 1353994933; Wed, 29 May 2019 15:44:17 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by MTKMBS31N1.mediatek.inc (172.27.4.69) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 29 May 2019 15:44:15 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 29 May 2019 15:44:14 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Heikki Krogerus CC: Mark Rutland , Chunfeng Yun , Matthias Brugger , Adam Thomson , Li Jun , Badhri Jagan Sridharan , Hans de Goede , Andy Shevchenko , Min Guo , , , , , , Biju Das , Linus Walleij , Yu Chen Subject: [PATCH v6 06/10] device connection: Add fwnode_connection_find_match() Date: Wed, 29 May 2019 15:43:44 +0800 Message-ID: <1559115828-19146-7-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1559115828-19146-1-git-send-email-chunfeng.yun@mediatek.com> References: <1559115828-19146-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Heikki Krogerus The fwnode_connection_find_match() function is exactly the same as device_connection_find_match(), except it takes struct fwnode_handle as parameter instead of struct device. That allows locating device connections before the device entries have been created. Signed-off-by: Heikki Krogerus --- v6: new patch --- drivers/base/devcon.c | 33 +++++++++++++++++++++++++-------- include/linux/device.h | 10 +++++++--- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c index 04db9ae235e4..8311b70bbca2 100644 --- a/drivers/base/devcon.c +++ b/drivers/base/devcon.c @@ -12,9 +12,6 @@ static DEFINE_MUTEX(devcon_lock); static LIST_HEAD(devcon_list); -typedef void *(*devcon_match_fn_t)(struct device_connection *con, int ep, - void *data); - static void * fwnode_graph_devcon_match(struct fwnode_handle *fwnode, const char *con_id, void *data, devcon_match_fn_t match) @@ -38,6 +35,28 @@ fwnode_graph_devcon_match(struct fwnode_handle *fwnode, const char *con_id, return NULL; } +/** + * fwnode_connection_find_match - Find connection from a device node + * @fwnode: Device node with the connection + * @con_id: Identifier for the connection + * @data: Data for the match function + * @match: Function to check and convert the connection description + * + * Find a connection with unique identifier @con_id between @fwnode and another + * device node. @match will be used to convert the connection description to + * data the caller is expecting to be returned. + */ +void *fwnode_connection_find_match(struct fwnode_handle *fwnode, + const char *con_id, void *data, + devcon_match_fn_t match) +{ + if (!fwnode || !match) + return NULL; + + return fwnode_graph_devcon_match(fwnode, con_id, data, match); +} +EXPORT_SYMBOL_GPL(fwnode_connection_find_match); + /** * device_connection_find_match - Find physical connection to a device * @dev: Device with the connection @@ -61,11 +80,9 @@ 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; - } + ret = fwnode_connection_find_match(fwnode, con_id, data, match); + if (ret) + return ret; mutex_lock(&devcon_lock); diff --git a/include/linux/device.h b/include/linux/device.h index e85264fb6616..9445f068602f 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -772,10 +772,14 @@ struct device_connection { struct list_head list; }; +typedef void *(*devcon_match_fn_t)(struct device_connection *con, int ep, + void *data); + +void *fwnode_connection_find_match(struct fwnode_handle *fwnode, + const char *con_id, void *data, + devcon_match_fn_t match); 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, devcon_match_fn_t match); struct device *device_connection_find(struct device *dev, const char *con_id); -- 2.21.0