From patchwork Wed Dec 2 09:09:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 7743631 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 299BD9F39D for ; Wed, 2 Dec 2015 09:12:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4382020638 for ; Wed, 2 Dec 2015 09:12:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CBEBD20640 for ; Wed, 2 Dec 2015 09:12:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756945AbbLBJMa (ORCPT ); Wed, 2 Dec 2015 04:12:30 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:12367 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756878AbbLBJM3 (ORCPT ); Wed, 2 Dec 2015 04:12:29 -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 DAB70782; Wed, 02 Dec 2015 17:11:21 +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:11 +0800 From: Kefeng Wang To: "Rafael J. Wysocki" , Arnd Bergmann CC: Hanjun Guo , , , Kefeng Wang Subject: [RFC PATCH 1/4] acpi: property: Introduce helper acpi_dev_get_reference_device() Date: Wed, 2 Dec 2015 17:09:25 +0800 Message-ID: <1449047368-5768-2-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.0A090205.565EB5B9.01E3, 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: b434dbcd798e723ccd6ebae6747540f1 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 Like of_parse_phandle() helper function to read and parse a phandle property and return a pointer to the resulting device_node, introduce helper function acpi_dev_get_reference_device() to read and parse a device properties(used in _DSD method) and return a pointer to the resulting acpi_device. Signed-off-by: Kefeng Wang --- drivers/acpi/property.c | 23 +++++++++++++++++++++++ include/linux/acpi.h | 7 +++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 88f4306..e2e7754 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -398,6 +398,29 @@ int acpi_dev_get_property(struct acpi_device *adev, const char *name, } EXPORT_SYMBOL_GPL(acpi_dev_get_property); +/** + * acpi_dev_get_reference_device - return the acpi_device referenced + * @adev: ACPI device to get the property from. + * @name: Name of the property. + * @index: Index of the reference to return + * + * Returns referenced ACPI device pointer, or NULL if not found + */ +struct acpi_device *acpi_dev_get_reference_device(struct acpi_device *adev, + const char *name, size_t index) +{ + struct acpi_reference_args args; + int ret; + + ret = acpi_node_get_property_reference(acpi_fwnode_handle(adev), name, index, &args); + + if (ret) + return NULL; + + return args.adev; +} +EXPORT_SYMBOL(acpi_dev_get_reference_device); + static struct acpi_device_data *acpi_device_data_of_node(struct fwnode_handle *fwnode) { if (fwnode->type == FWNODE_ACPI) { diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 93811dc..d76a688 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -793,6 +793,8 @@ struct acpi_reference_args { #ifdef CONFIG_ACPI int acpi_dev_get_property(struct acpi_device *adev, const char *name, acpi_object_type type, const union acpi_object **obj); +struct acpi_device *acpi_dev_get_reference_device(struct acpi_device *adev, + const char *name, size_t index); int acpi_node_get_property_reference(struct fwnode_handle *fwnode, const char *name, size_t index, struct acpi_reference_args *args); @@ -870,6 +872,11 @@ static inline int acpi_dev_get_property(struct acpi_device *adev, { return -ENXIO; } +static inline struct acpi_device *acpi_dev_get_reference_device(struct acpi_device *adev, + const char *name, size_t index) +{ + return NULL; +} static inline int acpi_node_get_property_reference(struct fwnode_handle *fwnode, const char *name, const char *cells_name,