From patchwork Mon May 25 14:53:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6475351 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 3ABA0C0020 for ; Mon, 25 May 2015 15:03:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B60B203B6 for ; Mon, 25 May 2015 15:03:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8812B20148 for ; Mon, 25 May 2015 15:03:36 +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 1Ywtrf-0006Tz-M6; Mon, 25 May 2015 15:00:27 +0000 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ywtpm-0004a6-GX for linux-arm-kernel@lists.infradead.org; Mon, 25 May 2015 14:58:34 +0000 Received: by wgez8 with SMTP id z8so75031854wge.0 for ; Mon, 25 May 2015 07:58:11 -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=IGnHRWKWQ016iGfbYDN2I+9o9DFoARZ/Ezzp8Ipdbq4=; b=ch6B6M6uTDOwr8TMH9x4j7PjdhzRisT/AJKJ1wND8yf1nO0nhnhCaXNu/z0s5j+o/B M9/TFlHdQRnUNVfuhFfWXJAyRxNWcQavyz0uOQySy1Nl2XiYk1L740qjUSlmYNMXm3FW dK7PMNolr+jQd09ld0iJ/k2jJeXLKD+y40O1PMmjjc2VWKitRu2GRPOVXOFW8XAmY8Yq ruIPKaA3VsMptBAeGBgS+EP+fXnIplqR1UFD+hCQge7JDG7L7ctm9tljYuehlwL4x+ZV pgfeAzKaf8jOwO55ul6cLnDXzs6AsmVHCvU4rl3r18hFXzfTYsI4R+2LhXS9DG2rHr/3 kyCQ== X-Received: by 10.180.91.17 with SMTP id ca17mr1235249wib.9.1432565891616; Mon, 25 May 2015 07:58:11 -0700 (PDT) Received: from cizrna.lan ([109.72.12.80]) by mx.google.com with ESMTPSA id ez19sm12258917wid.19.2015.05.25.07.58.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 May 2015 07:58:10 -0700 (PDT) From: Tomeu Vizoso To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 06/21] of/platform: Add of_platform_device_ensure() Date: Mon, 25 May 2015 16:53:10 +0200 Message-Id: <1432565608-26036-7-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1432565608-26036-1-git-send-email-tomeu.vizoso@collabora.com> References: <1432565608-26036-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150525_075830_774646_2C66A307 X-CRM114-Status: GOOD ( 15.45 ) X-Spam-Score: 0.0 (/) Cc: Mark Rutland , devicetree@vger.kernel.org, Tomeu Vizoso , Dmitry Torokhov , linux-kernel@vger.kernel.org, Rob Herring , =?UTF-8?q?St=C3=A9phane=20Marchesin?= , Thierry Reding , Grant Likely , Alexander Holler X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, 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 This function ensures that the device that encloses the passed device node is registered, and thus probed if the corresponding driver has been registered already. This function can be used by drivers to ensure that a dependency is fulfilled. Signed-off-by: Tomeu Vizoso --- drivers/of/platform.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index a01f57c..cc5d808 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -499,6 +499,57 @@ void of_platform_depopulate(struct device *parent) } EXPORT_SYMBOL_GPL(of_platform_depopulate); +/** + * of_platform_device_ensure - Ensure that device has been registered + * @np: pointer to node to create device for + * + * Ensures that a device has been registered for the given node. + */ +void of_platform_device_ensure(struct device_node *np) +{ + struct device_node *iter, *node = NULL; + int rc; + + /* Nothing to be done here */ + if (of_node_check_flag(np, OF_POPULATED)) + return; + + /* Too early for us to do anything useful */ + if (!platform_bus.kobj.state_initialized) + return; + + /* Find the node of the platform device enclosing this node */ + for (iter = np; + iter && iter->parent; + iter = iter->parent) { + if (of_get_property(iter, "compatible", NULL)) + node = iter; + + /* + * If the requested and requester nodes have a common ancestor + * that is being populated at this moment, register the device + * associated with the child of this ancestor that includes + * the requested node. + */ + if (of_node_check_flag(iter->parent, OF_POPULATED) && + of_match_node(of_default_bus_match_table, iter->parent)) + break; + + if (of_node_is_root(iter->parent)) + break; + } + + if (!node) + return; + + rc = of_platform_bus_create(node, of_default_bus_match_table, NULL, + NULL, true); + if (rc) + pr_debug("%s: creation of platform device failed\n", + np->full_name); +} +EXPORT_SYMBOL_GPL(of_platform_device_ensure); + #ifdef CONFIG_OF_DYNAMIC static int of_platform_notify(struct notifier_block *nb, unsigned long action, void *arg) diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 611a691..df17890 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -73,6 +73,7 @@ extern int of_platform_populate(struct device_node *root, const struct of_dev_auxdata *lookup, struct device *parent); extern void of_platform_depopulate(struct device *parent); +extern void of_platform_device_ensure(struct device_node *np); #else static inline int of_platform_populate(struct device_node *root, const struct of_device_id *matches, @@ -82,6 +83,7 @@ static inline int of_platform_populate(struct device_node *root, return -ENODEV; } static inline void of_platform_depopulate(struct device *parent) { } +static inline void of_platform_device_ensure(struct device_node *np) { } #endif #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)