From patchwork Tue Feb 11 16:53:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 24473 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 54764203F3 for ; Tue, 11 Feb 2014 16:54:19 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id m1sf34638192oag.5 for ; Tue, 11 Feb 2014 08:54:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Vg0QT5t8iCmPQZnPIUL2lG4s5n3ME+USadPrb20t7yo=; b=CF/U/ib9GlETfEDB2fuGo12guFyqeDQSpA/6IaE6BAgJm6qGIa8JqiBsoWaTxukjWy +Onfmg2dKtOX5sIvZgWAgM7S1vvw0yjHMCqK0Z8hDv+xmj/JmGuLCylaF5XP0V41PJBi T0ila2ivijoKPfngHwY4tY2kLd2ILeIFmtmo1Oi+Chw3Dsuve/cO4myj/l2AqmzCz283 VhvIRV07MIygmfIlYLAPJ2KVi3OD8oFectJOHP1/gDaWhjKK+7MgalJUiI5H3vYPjTPo 7KI1KfKkdDudM5Wwi7mSMSw/eonIs9nMJWmPG0nO3HfgZ9WNL5au6qs59g6DqllV30A+ igTQ== X-Gm-Message-State: ALoCoQmBgBj1c/y7jSp2QM8Pq7xAWeoLjawlw+5Sd2rc1ttjvecq60sKUP92j1INrbKYjzlVRHg0 X-Received: by 10.50.112.2 with SMTP id im2mr180006igb.6.1392137658107; Tue, 11 Feb 2014 08:54:18 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.37 with SMTP id u34ls2563175qgu.37.gmail; Tue, 11 Feb 2014 08:54:18 -0800 (PST) X-Received: by 10.52.164.137 with SMTP id yq9mr442754vdb.33.1392137657952; Tue, 11 Feb 2014 08:54:17 -0800 (PST) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id uo10si6116046vec.132.2014.02.11.08.54.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Feb 2014 08:54:17 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ij19so5989314vcb.6 for ; Tue, 11 Feb 2014 08:54:17 -0800 (PST) X-Received: by 10.58.170.106 with SMTP id al10mr124033vec.61.1392137657766; Tue, 11 Feb 2014 08:54:17 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp260941vcz; Tue, 11 Feb 2014 08:54:17 -0800 (PST) X-Received: by 10.68.106.130 with SMTP id gu2mr45162691pbb.59.1392137656421; Tue, 11 Feb 2014 08:54:16 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zk9si19556093pac.318.2014.02.11.08.54.15; Tue, 11 Feb 2014 08:54:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752424AbaBKQxu (ORCPT + 27 others); Tue, 11 Feb 2014 11:53:50 -0500 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:20716 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752216AbaBKQxq (ORCPT ); Tue, 11 Feb 2014 11:53:46 -0500 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.45]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 1806314005F; Tue, 11 Feb 2014 10:53:42 -0600 (CST) From: Pawel Moll To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, lm-sensors@lm-sensors.org, arm@kernel.org Cc: Rob Herring , Mark Rutland , Ian Campbell , Kumar Gala , Greg Kroah-Hartman , Mike Turquette , Jean Delvare , Guenter Roeck , Samuel Ortiz , Lee Jones , Arnd Bergmann , Grant Likely , Dmitry Eremin-Solenikov , David Woodhouse , Liam Girdwood , Mark Brown , Pawel Moll Subject: [PATCH 1/3] driver core & of: Mark of_nodes of added device as populated Date: Tue, 11 Feb 2014 16:53:28 +0000 Message-Id: <1392137610-27842-2-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1392137610-27842-1-git-send-email-pawel.moll@arm.com> References: <1392137610-27842-1-git-send-email-pawel.moll@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pawel.moll@arm.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In "Device Tree powered" systems, platform devices are usually massively populated with of_platform_populate() call, executed at some level of initcalls, either by generic architecture or by platform-specific code. There are situations though where certain devices must be created (and bound with drivers) before all the others. This presents small challenge in DT-driven systems, as devices explicitly created in early code would be created again by of_platform_populate(). This patch tries to solve that issue in a generic way, adding a "populated" flag which is set in the device_node structure when a device is being created in the core. Later, of_platform_populate() skips such nodes (and its children) in a similar way to the non-available ones. Signed-off-by: Pawel Moll --- drivers/base/core.c | 4 ++++ drivers/of/device.c | 16 ++++++++++++++++ drivers/of/platform.c | 6 ++++-- include/linux/of.h | 6 ++++++ include/linux/of_device.h | 11 +++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 2b56717..588c9a6 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1088,6 +1088,8 @@ int device_add(struct device *dev) class_intf->add_dev(dev, class_intf); mutex_unlock(&dev->class->p->mutex); } + + of_device_populate(dev); done: put_device(dev); return error; @@ -1190,6 +1192,8 @@ void device_del(struct device *dev) struct device *parent = dev->parent; struct class_interface *class_intf; + of_device_depopulate(dev); + /* Notify clients of device removal. This call must come * before dpm_sysfs_remove(). */ diff --git a/drivers/of/device.c b/drivers/of/device.c index dafb973..3b31144 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -190,3 +190,19 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) return 0; } + +void of_device_populate(struct device *dev) +{ + if ((!dev) || (!dev->of_node)) + return; + + of_node_set_flag(dev->of_node, OF_POPULATED); +} + +void of_device_depopulate(struct device *dev) +{ + if ((!dev) || (!dev->of_node)) + return; + + of_node_clear_flag(dev->of_node, OF_POPULATED); +} diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 404d1da..ad43ee0 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -204,7 +204,8 @@ static struct platform_device *of_platform_device_create_pdata( { struct platform_device *dev; - if (!of_device_is_available(np)) + if (!of_device_is_available(np) || + of_node_check_flag(np, OF_POPULATED)) return NULL; dev = of_device_alloc(np, bus_id, parent); @@ -262,7 +263,8 @@ static struct amba_device *of_amba_device_create(struct device_node *node, pr_debug("Creating amba device %s\n", node->full_name); - if (!of_device_is_available(node)) + if (!of_device_is_available(node) || + of_node_check_flag(node, OF_POPULATED)) return NULL; dev = amba_device_alloc(NULL, 0, 0); diff --git a/include/linux/of.h b/include/linux/of.h index 70c64ba..caf7b8a 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -114,6 +114,11 @@ static inline void of_node_set_flag(struct device_node *n, unsigned long flag) set_bit(flag, &n->_flags); } +static inline void of_node_clear_flag(struct device_node *n, unsigned long flag) +{ + clear_bit(flag, &n->_flags); +} + extern struct device_node *of_find_all_nodes(struct device_node *prev); /* @@ -156,6 +161,7 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size) /* flag descriptions */ #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ #define OF_DETACHED 2 /* node has been detached from the device tree */ +#define OF_POPULATED 3 /* device already created for the node */ #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) diff --git a/include/linux/of_device.h b/include/linux/of_device.h index 8d7dd67..513e598 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -44,6 +44,9 @@ static inline void of_device_node_put(struct device *dev) of_node_put(dev->of_node); } +extern void of_device_populate(struct device *dev); +extern void of_device_depopulate(struct device *dev); + static inline struct device_node *of_cpu_device_node_get(int cpu) { struct device *cpu_dev; @@ -84,6 +87,14 @@ static inline const struct of_device_id *of_match_device( return NULL; } +static inline void of_device_populate(struct device *dev) +{ +} + +static inline void of_device_depopulate(struct device *dev) +{ +} + static inline struct device_node *of_cpu_device_node_get(int cpu) { return NULL;