From patchwork Fri Aug 23 07:57:16 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: 11110897 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C60BF13B1 for ; Fri, 23 Aug 2019 07:59:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A49BC233A0 for ; Fri, 23 Aug 2019 07:59:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HOJuXe59" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A49BC233A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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=cFVmPEW22Yx1Dg2fFGGdZLiPWhl2c0RptYfWA+16SZE=; b=HOJuXe59aHZXIX tMvPTv9DUmOLQspumF5uV09dJYpcpE+6arUqBKPexQ2xNbWcAhXZW0c2njgPXDKnahijnIhGrag07 uLyGFIwmPDzIU2TQYBOD5lgaCc0zhdBWfd/u7p70GrfiLrnOIfHrhnt7TZ8GoZmBhk9St0V4JqBHl ydqQV6nabJ69YgwcWl3K8UfddtPOLzcbeG1QuRAfIEyXR39JBkYRjPCplV1deeioev21CEvYpsa6R A11tHAVLxiMIe10ai8NUieHFvdfvj44EttYVAjfaTMoBvYfU6WE2SktVEFNZ2D990o7TW0MzINcQD rcHOR3fe0jXsw9WyKNig==; 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 1i14U1-0008L3-7l; Fri, 23 Aug 2019 07:59:41 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i14S7-0006Rs-JH; Fri, 23 Aug 2019 07:57:45 +0000 X-UUID: 40ee06a37d0c4769b8d5ff174f2edcbe-20190822 X-UUID: 40ee06a37d0c4769b8d5ff174f2edcbe-20190822 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1966783382; Thu, 22 Aug 2019 23:57:33 -0800 Received: from MTKMBS31N1.mediatek.inc (172.27.4.69) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 23 Aug 2019 00:57:32 -0700 Received: from mtkcas09.mediatek.inc (172.21.101.178) by MTKMBS31N1.mediatek.inc (172.27.4.69) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 23 Aug 2019 15:57:30 +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; Fri, 23 Aug 2019 15:57:28 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Biju Das Subject: [PATCH next v10 06/11] device connection: Add fwnode_connection_find_match() Date: Fri, 23 Aug 2019 15:57:16 +0800 Message-ID: <1566547041-20804-7-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1566547041-20804-1-git-send-email-chunfeng.yun@mediatek.com> References: <1566547041-20804-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 4A9DB8FB0F0616EC04C996C91B87A7BAF13F1658CD144D9402BA1363662C80B92000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190823_005743_665756_63198774 X-CRM114-Status: GOOD ( 12.70 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-arm-kernel@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 , Heikki Krogerus , Badhri Jagan Sridharan , Linus Walleij , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, 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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 Signed-off-by: Chunfeng Yun --- v10: revert changes of v9 v9: replace signed-off-by by suggested-by Heikki v8: no changes 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 1d488dc5dd0c..14e2178e09f8 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 8ae3f4b47293..93626476c9ae 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1009,10 +1009,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);