From patchwork Wed Dec 2 09:09:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 7743621 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 A949F9F350 for ; Wed, 2 Dec 2015 09:12:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA5A92063E for ; Wed, 2 Dec 2015 09:12:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D368F2063C for ; Wed, 2 Dec 2015 09:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756789AbbLBJM1 (ORCPT ); Wed, 2 Dec 2015 04:12:27 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:12300 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756878AbbLBJMZ (ORCPT ); Wed, 2 Dec 2015 04:12:25 -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 DAB70778; 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:13 +0800 From: Kefeng Wang To: "Rafael J. Wysocki" , Arnd Bergmann CC: Hanjun Guo , , , Kefeng Wang Subject: [RFC PATCH 3/4] ACPI/platform: Introduce helper acpi_dev_find_plat_dev() Date: Wed, 2 Dec 2015 17:09:27 +0800 Message-ID: <1449047368-5768-4-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.0A090201.565EB5B9.005F, 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: 9316aa6fc92689da7a2e8ee5a79b019e 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 Sometimes in a device object, we refer to another device object, mostly in _DSD method, and we need to get platform device with the ACPI device node from the referenced device object. So introduce the helper acpi_dev_find_plat_dev() to do this. Signed-off-by: Kefeng Wang --- drivers/acpi/acpi_platform.c | 25 +++++++++++++++++++++++++ include/linux/acpi.h | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index 296b7a1..2603f9b 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c @@ -121,3 +121,28 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) return pdev; } EXPORT_SYMBOL_GPL(acpi_create_platform_device); + +static int acpi_dev_object_match(struct device *dev, void *data) +{ + return ACPI_COMPANION(dev) == data; +} + +/* + * acpi_find_plat_device - Find the platform_device associated + * with an acpi device + * @adev: Pointer to the acpi device + * + * Returns platform_device pointer, or NULL if not found + */ +struct platform_device *acpi_dev_find_plat_dev(struct acpi_device *adev) +{ + struct device *dev; + + if (!adev) + return NULL; + + dev = bus_find_device(&platform_bus_type, NULL, adev, + acpi_dev_object_match); + return dev ? to_platform_device(dev) : NULL; +} +EXPORT_SYMBOL(acpi_dev_find_plat_dev); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index d76a688..16af22f 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -468,6 +468,7 @@ int acpi_device_modalias(struct device *, char *, int); void acpi_walk_dep_device_list(acpi_handle handle); struct platform_device *acpi_create_platform_device(struct acpi_device *); +struct platform_device *acpi_dev_find_plat_dev(struct acpi_device *adev); #define ACPI_PTR(_ptr) (_ptr) #else /* !CONFIG_ACPI */ @@ -929,6 +930,11 @@ static inline struct fwnode_handle *acpi_get_next_subnode(struct device *dev, return NULL; } +static inline struct platform_device *acpi_dev_find_plat_dev(struct acpi_device *adev) +{ + return NULL; +} + #define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable, validate, data, fn) \ static const void * __acpi_table_##name[] \ __attribute__((unused)) \