From patchwork Tue Jun 11 08:44:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 10986269 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 EBA2A13AF for ; Tue, 11 Jun 2019 08:49:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7A8328708 for ; Tue, 11 Jun 2019 08:49:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9FAA28718; Tue, 11 Jun 2019 08:49:18 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 635D728708 for ; Tue, 11 Jun 2019 08:49:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pv0+Ctq+wvxKmdnalVwDaELP2gIg/Ij7vOBykLsNppA=; b=d12E3rNa0quCxX mOUaImQ3qHD3No27ucOMUDbnlVRWn+aiAyVm0QK1YlnGDS2J5xg6WXrvT7rel8h3qemNssEJ7+q23 DdAv7YjRJzRgMsNPk19QBBmP7LmrgSiPm/Yf5yQ/jyEWeCPuf0RN5oOc10GAlvNsiabPuqBrwQylD jEMZh7j0LQxtQCr421OToQ0DEEr9dS1KKCDKYI/5gm2hNmdiSOovhkOh5FfnO3gQLYUYyOPYA9hUw RMFO9+DgyM92QckE4U/oeBlWATgYU3/DY0Xr7ViSl4bmiylmfdCsWK8jC0xcuhEa0XQ43eieBEHnT 0ub8Uo4tFt8JDaXJBPfA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hacSy-0005Eh-Ba; Tue, 11 Jun 2019 08:49:16 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hacPI-0002VV-80; Tue, 11 Jun 2019 08:45:30 +0000 X-UUID: f8ef3cdcb0e04b728fc93eadc2962874-20190611 X-UUID: f8ef3cdcb0e04b728fc93eadc2962874-20190611 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1902411500; Tue, 11 Jun 2019 00:45:19 -0800 Received: from MTKMBS31N2.mediatek.inc (172.27.4.87) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 11 Jun 2019 01:45:17 -0700 Received: from mtkcas09.mediatek.inc (172.21.101.178) by MTKMBS31N2.mediatek.inc (172.27.4.87) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 11 Jun 2019 16:45:14 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 11 Jun 2019 16:45:12 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Heikki Krogerus Subject: [PATCH v7 06/10] device connection: Add fwnode_connection_find_match() Date: Tue, 11 Jun 2019 16:44:36 +0800 Message-ID: <1560242680-23844-7-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1560242680-23844-1-git-send-email-chunfeng.yun@mediatek.com> References: <1560242680-23844-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190611_014528_412388_650BD77E X-CRM114-Status: GOOD ( 13.43 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Hans de Goede , Felipe Balbi , Badhri Jagan Sridharan , Linus Walleij , linux-usb@vger.kernel.org, Yu Chen , linux-kernel@vger.kernel.org, Biju Das , Matthias Brugger , Andy Shevchenko , linux-mediatek@lists.infradead.org, Min Guo , Chunfeng Yun , Nagarjuna Kristam , Adam Thomson , linux-arm-kernel@lists.infradead.org, Li Jun Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Chunfeng Yun --- v7: rebased on Rafael's tree [1] (after rc4), provided by Heikki [1] https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/log/?h=linux-next v6: new patch --- drivers/base/devcon.c | 43 ++++++++++++++++++++++++++++++------------ include/linux/device.h | 10 +++++++--- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c index f7035fc12b92..5bf9537bd738 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) @@ -60,6 +57,34 @@ fwnode_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) +{ + void *ret; + + if (!fwnode || !match) + return NULL; + + ret = fwnode_graph_devcon_match(fwnode, con_id, data, match); + if (ret) + return ret; + + return fwnode_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 @@ -83,15 +108,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_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 5489a759e1c5..3d3081387937 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);