From patchwork Mon Aug 15 15:23:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 9281395 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 203EB607FD for ; Mon, 15 Aug 2016 15:27:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 110CA28D26 for ; Mon, 15 Aug 2016 15:27:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04AF428D2A; Mon, 15 Aug 2016 15:27:44 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id A75ED28D26 for ; Mon, 15 Aug 2016 15:27:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZJmK-0007tU-9x; Mon, 15 Aug 2016 15:26:16 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZJkZ-0005W2-DU for linux-arm-kernel@lists.infradead.org; Mon, 15 Aug 2016 15:24:31 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C14C2BBD; Mon, 15 Aug 2016 08:25:32 -0700 (PDT) Received: from red-moon.cambridge.arm.com (red-moon.cambridge.arm.com [10.1.206.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F18D83F32C; Mon, 15 Aug 2016 08:23:57 -0700 (PDT) From: Lorenzo Pieralisi To: iommu@lists.linux-foundation.org Subject: [PATCH v4 05/15] drivers: platform: add fwnode base platform devices retrieval Date: Mon, 15 Aug 2016 16:23:30 +0100 Message-Id: <1471274620-20754-6-git-send-email-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1471274620-20754-1-git-send-email-lorenzo.pieralisi@arm.com> References: <1471274620-20754-1-git-send-email-lorenzo.pieralisi@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160815_082427_779501_F7D295E4 X-CRM114-Status: UNSURE ( 9.84 ) X-CRM114-Notice: Please train this message. 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-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Joerg Roedel , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Will Deacon , Sinan Kaya , linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, Dennis Chen , Hanjun Guo , Tomasz Nowicki , Nate Watterson , Robin Murphy , Jon Masters MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The platform device kernel API does not provide functions to retrieve a platform device through the corresponding struct device fwnode pointer. Implement the fwnode platform_device look-up in drivers core code by using the bus_find_device() API and a corresponding matching function. The OF equivalent (eg of_find_device_by_node()) will reuse the newly introduced function when OF code will take care of setting up the device->fwnode value that is currently left dangling for platform devices instantiated out of device tree nodes. Signed-off-by: Lorenzo Pieralisi Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Reviewed-by: Hanjun Guo --- drivers/base/platform.c | 23 +++++++++++++++++++++++ include/linux/platform_device.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 6482d47..3ef150d 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -760,6 +760,29 @@ err_out: } EXPORT_SYMBOL_GPL(__platform_create_bundle); +static int fwnode_dev_match(struct device *dev, void *data) +{ + return dev->fwnode == data; +} + +/** + * platform_find_device_by_fwnode() - Find the platform_device associated + * with a fwnode + * @fwnode: Pointer to firmware node + * + * Returns platform_device pointer, or NULL if not found + */ +struct platform_device * +platform_find_device_by_fwnode(struct fwnode_handle *fwnode) +{ + struct device *dev; + + dev = bus_find_device(&platform_bus_type, NULL, fwnode, + fwnode_dev_match); + return dev ? to_platform_device(dev) : NULL; +} +EXPORT_SYMBOL(platform_find_device_by_fwnode); + /** * __platform_register_drivers - register an array of platform drivers * @drivers: an array of drivers to register diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 98c2a7c..01a3eb2 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -276,6 +276,9 @@ extern struct platform_device *__platform_create_bundle( struct resource *res, unsigned int n_res, const void *data, size_t size, struct module *module); +extern struct platform_device * +platform_find_device_by_fwnode(struct fwnode_handle *fwnode); + int __platform_register_drivers(struct platform_driver * const *drivers, unsigned int count, struct module *owner); void platform_unregister_drivers(struct platform_driver * const *drivers,