From patchwork Wed Dec 2 09:09:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 7743601 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3919FBEEE1 for ; Wed, 2 Dec 2015 09:12:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4C5E12063E for ; Wed, 2 Dec 2015 09:12:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A73F920638 for ; Wed, 2 Dec 2015 09:12:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756913AbbLBJMY (ORCPT ); Wed, 2 Dec 2015 04:12:24 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:12225 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755503AbbLBJMV (ORCPT ); Wed, 2 Dec 2015 04:12:21 -0500 Received: from 172.24.1.49 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.49]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DAB70780; Wed, 02 Dec 2015 17:11:20 +0800 (CST) Received: from localhost (10.177.19.180) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Wed, 2 Dec 2015 17:11:12 +0800 From: Kefeng Wang To: "Rafael J. Wysocki" , Arnd Bergmann CC: Hanjun Guo , , , Kefeng Wang Subject: [RFC PATCH 2/4] device property: Introduce helper device_get_reference_node() Date: Wed, 2 Dec 2015 17:09:26 +0800 Message-ID: <1449047368-5768-3-git-send-email-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1449047368-5768-1-git-send-email-wangkefeng.wang@huawei.com> References: <1449047368-5768-1-git-send-email-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.180] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090203.565EB5B9.00A1, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 618c7576b76454b134af3d970bfa7155 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With of_parse_phandle() and acpi_dev_get_reference_device(), we can introduce a universal helper device_get_reference_node() to read and parse a device property and return a pointer to the resulting firmware node. Signed-off-by: Kefeng Wang --- drivers/base/property.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 6 ++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 1325ff2..6517140 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -568,6 +568,46 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev, EXPORT_SYMBOL_GPL(device_get_next_child_node); /** + * fwnode_get_reference_node - Find the firmware node referenced + * @fwnode: Firmware node to get the property from. + * @propname: Name of the property + * @index: Index of the reference + * + * Returns referenced fwnode handler pointer, or an NULL if not found + */ +struct fwnode_handle *fwnode_get_reference_node(struct fwnode_handle *fwnode, + const char *propname, int index) +{ + if (is_of_node(fwnode)) { + struct device_node *np; + np = of_parse_phandle(to_of_node(fwnode), propname, index); + return np ? &np->fwnode : NULL; + } else if (is_acpi_node(fwnode)) { + struct acpi_device *adev; + adev = acpi_dev_get_reference_device(to_acpi_device_node(fwnode), + propname, index); + return adev ? acpi_fwnode_handle(adev) : NULL; + } + return NULL; +} +EXPORT_SYMBOL_GPL(fwnode_get_reference_node); + +/** + * dev_get_reference_node - Find the firmware node referenced + * @dev: Device to get the property from. + * @propname: Name of the property + * @index: Index of the reference + * + * Returns referenced fwnode handler pointer, or an NULL if not found + */ +struct fwnode_handle *device_get_reference_node(struct device *dev, + const char *propname, int index) +{ + return fwnode_get_reference_node(dev_fwnode(dev), propname, index); +} +EXPORT_SYMBOL_GPL(device_get_reference_node); + +/** * fwnode_handle_put - Drop reference to a device node * @fwnode: Pointer to the device node to drop the reference to. * diff --git a/include/linux/property.h b/include/linux/property.h index 0a3705a..d77e6a2 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -70,6 +70,12 @@ int fwnode_property_read_string(struct fwnode_handle *fwnode, int fwnode_property_match_string(struct fwnode_handle *fwnode, const char *propname, const char *string); +struct fwnode_handle *fwnode_get_reference_node(struct fwnode_handle *fwnode, + const char *propname, int index); + +struct fwnode_handle *device_get_reference_node(struct device *dev, + const char *propname, int index); + struct fwnode_handle *device_get_next_child_node(struct device *dev, struct fwnode_handle *child);