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: 9281377 X-Patchwork-Delegate: bhelgaas@google.com 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 7B8F6607FD for ; Mon, 15 Aug 2016 15:27:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CCFB28D26 for ; Mon, 15 Aug 2016 15:27:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 615B028D2A; Mon, 15 Aug 2016 15:27:13 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06A1328D26 for ; Mon, 15 Aug 2016 15:27:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753265AbcHOPYD (ORCPT ); Mon, 15 Aug 2016 11:24:03 -0400 Received: from foss.arm.com ([217.140.101.70]:41194 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752961AbcHOPYB (ORCPT ); Mon, 15 Aug 2016 11:24:01 -0400 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 Cc: Lorenzo Pieralisi , Greg Kroah-Hartman , "Rafael J. Wysocki" , Will Deacon , Marc Zyngier , Robin Murphy , Joerg Roedel , Tomasz Nowicki , Hanjun Guo , Jon Masters , Sinan Kaya , Nate Watterson , Dennis Chen , linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.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> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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,