From patchwork Fri Feb 7 16:53:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Francois Moine X-Patchwork-Id: 3607071 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 843EF9F2D6 for ; Fri, 7 Feb 2014 17:31:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A5DB92011E for ; Fri, 7 Feb 2014 17:31:12 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (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 975E520114 for ; Fri, 7 Feb 2014 17:31:11 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WBpGE-000621-Uq; Fri, 07 Feb 2014 17:30:43 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WBp7P-0001Om-1A; Fri, 07 Feb 2014 17:21:35 +0000 Received: from smtp5-g21.free.fr ([2a01:e0c:1:1599::14]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WBp7L-0001ML-Sm for linux-arm-kernel@lists.infradead.org; Fri, 07 Feb 2014 17:21:32 +0000 Received: from localhost (unknown [IPv6:2a01:e35:2f5c:9de0:212:bfff:fe1e:9ce4]) by smtp5-g21.free.fr (Postfix) with ESMTP id 9DE84D4812F; Fri, 7 Feb 2014 18:21:00 +0100 (CET) X-Mailbox-Line: From 9f8bbe28b00160cab2cedffa3f8fb42121035964 Mon Sep 17 00:00:00 2001 Message-Id: <9f8bbe28b00160cab2cedffa3f8fb42121035964.1391792986.git.moinejf@free.fr> In-Reply-To: References: From: Jean-Francois Moine Date: Fri, 7 Feb 2014 17:53:27 +0100 Subject: [PATCH v3 2/2] drivers/base: declare phandle DT nodes as components To: Russell King , devel@driverdev.osuosl.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140207_122132_508408_91921C0A X-CRM114-Status: GOOD ( 14.58 ) X-Spam-Score: -1.9 (-) Cc: alsa-devel@alsa-project.org, Daniel Vetter , Takashi Iwai , Greg Kroah-Hartman , dri-devel@lists.freedesktop.org, Sascha Hauer , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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.7 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_MED, 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 At system startup time, some devices depends on the availability of some other devices before starting. The infrastructure for componentised subsystems permits to handle this dependence, each driver defining its own role. This patch does an automatic creation of the lowest components in case of DT. This permits simple devices to be part of complex componentised subsystems without any specific code. When created from DT, the device dependence is generally indicated by phandle: a device which is pointed to by a phandle must be started before the pointing device(s). So, at device register time, the devices which are pointed to by a phandle are declared as components, except when they declared themselves as such in their probe function. Signed-off-by: Jean-Francois Moine --- drivers/base/component.c | 12 ++++++++++++ drivers/base/core.c | 18 ++++++++++++++++++ include/linux/of.h | 2 ++ 3 files changed, 32 insertions(+) diff --git a/drivers/base/component.c b/drivers/base/component.c index 0a39d7a..3cab26b 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -17,6 +17,7 @@ #include #include #include +#include struct master { struct list_head node; @@ -336,6 +337,7 @@ EXPORT_SYMBOL_GPL(component_bind_all); int component_add(struct device *dev, const struct component_ops *ops) { struct component *component; + struct device_node *np; int ret; component = kzalloc(sizeof(*component), GFP_KERNEL); @@ -356,6 +358,11 @@ int component_add(struct device *dev, const struct component_ops *ops) kfree(component); } + + np = dev->of_node; + if (np) + np->_flags |= OF_DEV_COMPONENT; + mutex_unlock(&component_mutex); return ret < 0 ? ret : 0; @@ -365,6 +372,7 @@ EXPORT_SYMBOL_GPL(component_add); void component_del(struct device *dev, const struct component_ops *ops) { struct component *c, *component = NULL; + struct device_node *np; mutex_lock(&component_mutex); list_for_each_entry(c, &component_list, node) @@ -377,6 +385,10 @@ void component_del(struct device *dev, const struct component_ops *ops) if (component && component->master) take_down_master(component->master); + np = dev->of_node; + if (np) + np->_flags &= ~OF_DEV_COMPONENT; + mutex_unlock(&component_mutex); WARN_ON(!component); diff --git a/drivers/base/core.c b/drivers/base/core.c index 2b56717..0517b91 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" @@ -980,6 +981,7 @@ int device_add(struct device *dev) struct device *parent = NULL; struct kobject *kobj; struct class_interface *class_intf; + struct device_node *np; int error = -EINVAL; dev = get_device(dev); @@ -1088,6 +1090,15 @@ int device_add(struct device *dev) class_intf->add_dev(dev, class_intf); mutex_unlock(&dev->class->p->mutex); } + + /* if DT-created device referenced by phandle, create a component */ + np = dev->of_node; + if (np && np->phandle && + !(np->_flags & OF_DEV_COMPONENT)) { + component_add(dev, NULL); + np->_flags |= OF_DEV_IMPLICIT_COMPONENT; + } + done: put_device(dev); return error; @@ -1189,10 +1200,17 @@ void device_del(struct device *dev) { struct device *parent = dev->parent; struct class_interface *class_intf; + struct device_node *np; /* Notify clients of device removal. This call must come * before dpm_sysfs_remove(). */ + np = dev->of_node; + if (np && (np->_flags & OF_DEV_COMPONENT)) { + component_del(dev, NULL); + np->_flags &= ~OF_DEV_IMPLICIT_COMPONENT; + } + if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_DEL_DEVICE, dev); diff --git a/include/linux/of.h b/include/linux/of.h index 70c64ba..40f1c34 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -59,6 +59,8 @@ struct device_node { struct proc_dir_entry *pde; /* this node's proc directory */ struct kref kref; unsigned long _flags; +#define OF_DEV_COMPONENT 1 +#define OF_DEV_IMPLICIT_COMPONENT 2 void *data; #if defined(CONFIG_SPARC) const char *path_component_name;