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: 7743661 Return-Path: X-Original-To: patchwork-linux-arm@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 8E1C39F350 for ; Wed, 2 Dec 2015 09:14:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BE8F320494 for ; Wed, 2 Dec 2015 09:14:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5DBC20445 for ; Wed, 2 Dec 2015 09:14:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1a43T1-0003Uv-4t; Wed, 02 Dec 2015 09:12:51 +0000 Received: from szxga01-in.huawei.com ([58.251.152.64]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a43SV-00033C-Ao for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2015 09:12:21 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151202_011220_060404_912F75B9 X-CRM114-Status: GOOD ( 11.07 ) X-Spam-Score: -4.2 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-acpi@vger.kernel.org, Kefeng Wang , Hanjun Guo , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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)) \