From patchwork Wed Jan 31 13:44:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10194027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 29B6A60380 for ; Wed, 31 Jan 2018 13:45:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17767285ED for ; Wed, 31 Jan 2018 13:45:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BD9828630; Wed, 31 Jan 2018 13:45:48 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 90FE2285ED for ; Wed, 31 Jan 2018 13:45:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752329AbeAaNpq (ORCPT ); Wed, 31 Jan 2018 08:45:46 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:33891 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752858AbeAaNpE (ORCPT ); Wed, 31 Jan 2018 08:45:04 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180131134501euoutp02e6b88c141d7ba016f2383121d54d2aa6~O6P3yAyNF1413014130euoutp02r; Wed, 31 Jan 2018 13:45:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180131134501euoutp02e6b88c141d7ba016f2383121d54d2aa6~O6P3yAyNF1413014130euoutp02r DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1517406301; bh=irRwjRkUy2Pli+9oCWa+FK8iTwBsQxWlyNDaRIGCX2Q=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=tv3k24+CB3aDazJYJM+CUGS8C/6bUKdpTg49aJ1QpajxL/g3cPxATPi3grE6CUNVK 3+4bfe/I57tvYBnw12xBtDOGSsWFTh5r/Rym2Fosx8if+bIjbm3/xwueE08+VSF6+4 sM6jA4yyeUw5SJnlEyl97TupKhx/X+dj7a09wzXI= Received: from eusmges4.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180131134500eucas1p2f425a730a6e6743bd33d1abae57aee99~O6P2pgTNn1565115651eucas1p2U; Wed, 31 Jan 2018 13:45:00 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges4.samsung.com (EUCPMTA) with SMTP id E5.60.30163.C58C17A5; Wed, 31 Jan 2018 13:45:00 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180131134459eucas1p15c0dd76f5173816b949e72cde93c0a6c~O6P1uhGUA2975129751eucas1p1c; Wed, 31 Jan 2018 13:44:59 +0000 (GMT) X-AuditID: cbfec7f4-f790c6d0000075d3-a1-5a71c85c4d58 Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 40.83.18832.B58C17A5; Wed, 31 Jan 2018 13:44:59 +0000 (GMT) Received: from AMDC2768.DIGITAL.local ([106.120.43.17]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P3F00KEJA6V2O00@eusync1.samsung.com>; Wed, 31 Jan 2018 13:44:59 +0000 (GMT) From: Andrzej Hajda To: devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS) Cc: Andrzej Hajda , Bartlomiej Zolnierkiewicz , Marek Szyprowski , dri-devel@lists.freedesktop.org, Inki Dae , Rob Herring , Mark Rutland , Krzysztof Kozlowski , Chanwoo Choi , Archit Taneja , Laurent Pinchart , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-usb@vger.kernel.org Subject: [RFC PATCH v2 4/5] extcon: add possibility to get extcon device by OF node Date: Wed, 31 Jan 2018 14:44:34 +0100 Message-id: <20180131134435.12216-5-a.hajda@samsung.com> X-Mailer: git-send-email 2.15.1 In-reply-to: <20180131134435.12216-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSbUhTURzGO9t9m215uYqd1IomfihKE/xwrIyEPlx6gQwNHEaOdlHxbe46 URESU5mv6TLTJvm+TCxzioZp0DRnaM2lKEkpISgpmU4rK7Pc7vz2+z//5+F/HjiUmPmNeVPx yWmcJlmZKCfcsJ7hX9YT0SOpipOzNhmaefoOR7m6rzjqrO7A0fTGIo7qhna0ye/fCKSfK8eQ 1fqMRIUVzSQyzU/haKKvlkDV1pci1GjMF6MnQ59I1DJtE6H8gSHyHM22P2wH7ERZqYg16Gpw 1tRWSLBzxRYR29V8iy3rbgPsuunQFUrhdkbFJcanc5rAszFucQuTa4R63TtjwY7nAItXEZBQ kA6G/V/ukQJ7wfHZDqIIuFEM3QLgysycSBjWAWysK8Z3E136QVJYGAFcrZlzLhj6H4C1nayD Cfoo/Nv1gXCwJ30drrzvEzsCYnocg+OjS857HnQkrLytwxyM0f5wzPjHGZDRCJa0mUTCtcOw vDvX6ZHQIXC2td/5PkgvEtC60ioWTOfhg9xNVwkPuGTpdrEvLNS9EgmBYgDtd0ZIYagEcHu1 2pU+DQctNmcHMb0P6nvu7+jUji6DugJGsLBwoiqPEDgM3v1ocPU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TwxU2zu1W8R DOU8rFM4J8/uDVx06nV++gO7aVfmle5WOGX0QvHPvAdLdA9nMv23rGduY7+vfVn6aqUSS3FG oqEWc1FxIgCvIZkeYQIAAA== X-CMS-MailID: 20180131134459eucas1p15c0dd76f5173816b949e72cde93c0a6c X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180131134459eucas1p15c0dd76f5173816b949e72cde93c0a6c X-RootMTR: 20180131134459eucas1p15c0dd76f5173816b949e72cde93c0a6c References: <20180131134435.12216-1-a.hajda@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since extcon property is not allowed in DT, extcon subsystem requires another way to get extcon device. Lets try the simplest approach - get edev by of_node. Signed-off-by: Andrzej Hajda Acked-by: Chanwoo Choi --- v2: changed label to follow local convention (Chanwoo) --- drivers/extcon/extcon.c | 44 ++++++++++++++++++++++++++++++++++---------- include/linux/extcon.h | 6 ++++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index cb38c2747684..c4972c4cb3bd 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -1336,6 +1336,28 @@ void extcon_dev_unregister(struct extcon_dev *edev) EXPORT_SYMBOL_GPL(extcon_dev_unregister); #ifdef CONFIG_OF + +/* + * extcon_get_edev_by_of_node - Get the extcon device from devicetree. + * @node : OF node identyfying edev + * + * Return the pointer of extcon device if success or ERR_PTR(err) if fail. + */ +struct extcon_dev *extcon_get_edev_by_of_node(struct device_node *node) +{ + struct extcon_dev *edev; + + mutex_lock(&extcon_dev_list_lock); + list_for_each_entry(edev, &extcon_dev_list, entry) + if (edev->dev.parent && edev->dev.parent->of_node == node) + goto out; + edev = ERR_PTR(-EPROBE_DEFER); +out: + mutex_unlock(&extcon_dev_list_lock); + + return edev; +} + /* * extcon_get_edev_by_phandle - Get the extcon device from devicetree. * @dev : the instance to the given device @@ -1363,25 +1385,27 @@ struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) return ERR_PTR(-ENODEV); } - mutex_lock(&extcon_dev_list_lock); - list_for_each_entry(edev, &extcon_dev_list, entry) { - if (edev->dev.parent && edev->dev.parent->of_node == node) { - mutex_unlock(&extcon_dev_list_lock); - of_node_put(node); - return edev; - } - } - mutex_unlock(&extcon_dev_list_lock); + edev = extcon_get_edev_by_of_node(node); of_node_put(node); - return ERR_PTR(-EPROBE_DEFER); + return edev; } + #else + +struct extcon_dev *extcon_get_edev_by_of_node(struct device_node *node) +{ + return ERR_PTR(-ENOSYS); +} + struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) { return ERR_PTR(-ENOSYS); } + #endif /* CONFIG_OF */ + +EXPORT_SYMBOL_GPL(extcon_get_edev_by_of_node); EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); /** diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 6d94e82c8ad9..b47e0c7f01fe 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -230,6 +230,7 @@ extern void devm_extcon_unregister_notifier_all(struct device *dev, * Following APIs get the extcon_dev from devicetree or by through extcon name. */ extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name); +extern struct extcon_dev *extcon_get_edev_by_of_node(struct device_node *node); extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index); @@ -283,6 +284,11 @@ static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) return ERR_PTR(-ENODEV); } +static inline struct extcon_dev *extcon_get_edev_by_of_node(struct device_node *node) +{ + return ERR_PTR(-ENODEV); +} + static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) {