From patchwork Tue Jul 28 13:19:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6885011 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 59895C05AC for ; Tue, 28 Jul 2015 13:26:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6C280206D2 for ; Tue, 28 Jul 2015 13:26:01 +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 7644F206BE for ; Tue, 28 Jul 2015 13:26:00 +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 1ZK4q5-0005xf-K2; Tue, 28 Jul 2015 13:22:37 +0000 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZK4oa-0004v0-8X for linux-arm-kernel@lists.infradead.org; Tue, 28 Jul 2015 13:21:08 +0000 Received: by wicmv11 with SMTP id mv11so179317421wic.0 for ; Tue, 28 Jul 2015 06:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=2Buf0GPiKQ+3Mzqbi0iW1X40rSzPqZx4Qafp6SRPiYg=; b=ry1rqcK4tz1+JrIZVwosH2Jwo5wM5MKWAM3x63AD/00nCGXN5ty4818W9hTgdgHT5Y LjNWaR+BCFNd8d5JKyjBTRxJgC9/pkABFBpGfOLyFcqoVpFf/ghTpC6yAlCTDCiQdwu0 /lsXCDFGYewzloiDUAC0kkFVRh8LO0/xZNBW30KWg593jBQ/fVGE8xLpMh7YH9yYWscP QwLaNfKUfFhMIcNRMIVF4Y0PGz1//DkFibuL8tUFHrgidtd49Bu9BXx/gIF351jm4ZL0 7nZFpg6OYeLdVsqJobTVUx9KP6f5B2/r7Yr33My4YGZRSY08dgqwWwXGCh6nPot3qzwc W/+Q== X-Received: by 10.180.104.167 with SMTP id gf7mr33767123wib.86.1438089643916; Tue, 28 Jul 2015 06:20:43 -0700 (PDT) Received: from cizrna.lan ([109.72.12.179]) by smtp.gmail.com with ESMTPSA id h9sm33265696wjx.20.2015.07.28.06.20.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jul 2015 06:20:42 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v2 06/22] device property: add fwnode_ensure_device() Date: Tue, 28 Jul 2015 15:19:37 +0200 Message-Id: <1438089593-7696-7-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1438089593-7696-1-git-send-email-tomeu.vizoso@collabora.com> References: <1438089593-7696-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150728_062104_726833_C25B87A0 X-CRM114-Status: GOOD ( 19.21 ) X-Spam-Score: -2.4 (--) 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: devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, Arnd Bergmann , Stephen Warren , Greg Kroah-Hartman , Linus Walleij , Dmitry Torokhov , "Rafael J. Wysocki" , Tomeu Vizoso , Javier Martinez Canillas , Mark Brown , Thierry Reding , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Checks if the device associated with this firmware node has been already probed, and probes it if not. It can be used by resource getters to make sure that the requested resource is available, if at all possible. For OF nodes, it finds the platform device that encloses this node and tries to probe it. Signed-off-by: Tomeu Vizoso --- Changes in v2: - Add fwnode_ensure_device() so the mechanism for probing devices on demand is independent of the firmware format. drivers/base/property.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 2 ++ 2 files changed, 60 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index efa74803af30..a63d9bc3d8f7 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -15,8 +15,11 @@ #include #include #include +#include #include +#include "base.h" + /** * device_add_property_set - Add a collection of properties to a device object. * @dev: Device to add properties to. @@ -548,3 +551,58 @@ const char *fwnode_get_name(struct fwnode_handle *fwnode) return NULL; } EXPORT_SYMBOL_GPL(fwnode_get_name); + +/** + * fwnode_ensure_device - probes the device associated to this firmware node + * @fwnode: Firmware node whose device is to be probed + * + * Checks if the device associated with this firmware node has been already + * probed, and probes it if not. It can be used by resource getters to make + * sure that the requested resource is available, if at all possible. + */ +void fwnode_ensure_device(struct fwnode_handle *fwnode) +{ + struct device *dev = NULL; + + /* + * In general, OF nodes don't have a single device associated to them, + * but those directly beneath the root of the tree or that are + * children of simple memory mapped bus nodes do have just one + * platform device. See Documentation/devicetree/usage-model.txt for + * a more extended explanation. + * + * of_platform_device_find() will return such a platform device and + * probing it should cause the target device to be probed as well + * because platform devices are expected to register their children + * when probing. + */ + if (is_of_node(fwnode)) + dev = of_platform_device_find(to_of_node(fwnode)); + else if (is_acpi_node(fwnode)) + dev = acpi_dev_get_device(to_acpi_node(fwnode)); + + if (!dev) { + /* + * Cannot be a warning because some fwnodes will have + * matching data but aren't really supposed to be probed. + */ + pr_debug("Couldn't find device for %s\n", + fwnode_get_name(fwnode)); + return; + } + + /* + * Device is bound or is being probed right now. If we have bad luck + * and the dependency isn't ready when it's needed, deferred probe + * will save us. + */ + if (dev->driver) + return; + + bus_probe_device(dev); + + if (!dev->driver) + pr_warn("Probe failed for %s (%s)\n", + fwnode_get_name(fwnode), dev_name(dev)); +} +EXPORT_SYMBOL_GPL(fwnode_ensure_device); diff --git a/include/linux/property.h b/include/linux/property.h index 826f156f7288..6b99296bcad7 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -168,4 +168,6 @@ void device_add_property_set(struct device *dev, struct property_set *pset); bool device_dma_is_coherent(struct device *dev); +void fwnode_ensure_device(struct fwnode_handle *fwnode); + #endif /* _LINUX_PROPERTY_H_ */