From patchwork Tue Feb 27 07:11:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10244425 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 99C8E602DC for ; Tue, 27 Feb 2018 07:13:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8695C2A26B for ; Tue, 27 Feb 2018 07:13:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B23A2A2E7; Tue, 27 Feb 2018 07:13:49 +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=unavailable 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 0743D2A26B for ; Tue, 27 Feb 2018 07:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752133AbeB0HNe (ORCPT ); Tue, 27 Feb 2018 02:13:34 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:50116 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752129AbeB0HLp (ORCPT ); Tue, 27 Feb 2018 02:11:45 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180227071142euoutp021cac56f4f0325ff87dcce2cea7b829cf~XHTK16-3u2625726257euoutp02a; Tue, 27 Feb 2018 07:11:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180227071142euoutp021cac56f4f0325ff87dcce2cea7b829cf~XHTK16-3u2625726257euoutp02a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1519715502; bh=niI8NxHtr2Sdw2KvDDx5ykwtbBgcg3IOE5GGlFgHFtc=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=LfRHuj/acLERGHXbcaVf+FLhDUbs2SPZ+JuoziXuP5o1aiN1eABPEQztbfHl62dvm wjY0GPHawBHzrmH8oxZ9tmIlKB0uGBq8VXkBs0n55T2GPdkwg8YkplTXz3SnQ6JyIW 782hIPkgeU7c4aM97j+l+PgK9Yk06D6Gu7tKgufE= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180227071142eucas1p23b44b9c1406abc921b70dbd30489e921~XHTKFikWS2509525095eucas1p2f; Tue, 27 Feb 2018 07:11:42 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id A7.7F.10409.DA4059A5; Tue, 27 Feb 2018 07:11:41 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180227071141eucas1p1170216070d70007a07de120a0dc3363a~XHTJaX3oB2996729967eucas1p1R; Tue, 27 Feb 2018 07:11:41 +0000 (GMT) X-AuditID: cbfec7f5-b5fff700000028a9-b3-5a9504ad5319 Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 30.FE.04183.DA4059A5; Tue, 27 Feb 2018 07:11:41 +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 <0P4S00AJMRZD4P00@eusync1.samsung.com>; Tue, 27 Feb 2018 07:11:41 +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: [PATCH v5 5/6] extcon: add possibility to get extcon device by OF node Date: Tue, 27 Feb 2018 08:11:33 +0100 Message-id: <20180227071134.28063-6-a.hajda@samsung.com> X-Mailer: git-send-email 2.16.2 In-reply-to: <20180227071134.28063-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSe0hTURzHO/e1u9HqNiVPKpmDQCW1KOOIEgYVF+mPEkIaWK68zOeUXTX1 D5Mwm0/MV9rDmflIcVlT1ESNzBylNnW+ysJCcDTMB2qiaea89t/n+/t9zvmdczg0LlsgHOkI dTynUSuj5ZSEaOldM3nqiWLF8YJFb/TlxScS3dH+ItGr0kYSjS9bSKTr2a6NrMxTqGAqn0Am 00sRyrxfJUKG6TESmdsfU6jU1IWhypq7ONL3fBOh6vEhDN3t7BEFMGxDeQNgzXm5GPtIW0ay hvpMip3KNmJsU9VtNq+5HrBLhsOXaIXEP4yLjkjkNN5nQiXhw9WhcTqnpNHylDQwezAL0DRk TsFa3YUsIKFlzHMA02e+E0JYArBIrxdlAfGONDo7TwqNGgA3LeuYELYAbG7t2LEoxh1uNn2m bGzPhMC54XbcJuHMIAEH+6w7kh1zGerXGjAbE8xR+N7wdacuZRDsn2ilhHEu8OnAKG5jMeML 35T0U7aNIDNJwYonJbvSOagdaSMEtoNWY/PuWZ2huTCbEBZkA/ixKxMXQhGAJqsZEyw/+M44 RNoYZ/bBgpYHuPAcUqjNkAkKC9f/dOACn4WWRi0l3DkHw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LtXuTdenI9fVznikG/e7dzX7na0Q4n8zOup8SRSf2Sc9RYinOSDTUYi4qTgQA xMXrjlQCAAA= X-CMS-MailID: 20180227071141eucas1p1170216070d70007a07de120a0dc3363a X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180227071141eucas1p1170216070d70007a07de120a0dc3363a X-RootMTR: 20180227071141eucas1p1170216070d70007a07de120a0dc3363a References: <20180227071134.28063-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 --- v5: function renamed to extcon_find_edev_by_node (Andy) 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..47a5ca9eb86d 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_find_edev_by_node - Find 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_find_edev_by_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_find_edev_by_node(node); of_node_put(node); - return ERR_PTR(-EPROBE_DEFER); + return edev; } + #else + +struct extcon_dev *extcon_find_edev_by_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_find_edev_by_node); EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); /** diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 6d94e82c8ad9..7f033b1ea568 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_find_edev_by_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_find_edev_by_node(struct device_node *node) +{ + return ERR_PTR(-ENODEV); +} + static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) {