All of lore.kernel.org
 help / color / mirror / Atom feed
From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH RFC 26/46] drivers/base: provide an infrastructure for componentised subsystems
Date: Fri, 10 Jan 2014 23:23:37 +0000	[thread overview]
Message-ID: <20140110232336.GI15937@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20140110204259.GC10235@kroah.com>

On Fri, Jan 10, 2014 at 12:42:59PM -0800, Greg Kroah-Hartman wrote:
> On Fri, Jan 10, 2014 at 07:30:21PM +0100, Robert Schwebel wrote:
> > On Fri, Jan 10, 2014 at 07:35:30AM -0800, Greg Kroah-Hartman wrote:
> > > > I'll sort out a new set of patches today, along with a branch to pull if
> > > > you wish to take them that way.
> > > 
> > > It's too late for 3.14, as my tree is now closed for that because 3.13
> > > should be out this weekend.  But I'll be glad to queue them up after
> > > 3.14-rc1 is out.
> > 
> > Didnt' Linus say there would be an -rc8?
> 
> Ah, you are right, nevermind then :)
> 
> Russell, if you want to send me just the driver core patch, I can take
> that now and get that into 3.14 so that you don't have any cross-tree
> dependancies on the rest of this patch series.

Thanks, here it is.  Only change from the previously posted one is a
few checkpatch cleanups.

8<===
From: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH] drivers/base: provide an infrastructure for componentised
 subsystems

Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem.  However, firmware tends to
describe the individual devices and the connections between them.

Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.

We do this in DT by providing a "superdevice" node which specifies
the components, eg:

	imx-drm {
		compatible = "fsl,drm";
		crtcs = <&ipu1>;
		connectors = <&hdmi>;
	};

The superdevice is declared into the component support, along with the
subcomponents.  The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present.  At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.

When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
 drivers/base/Makefile     |   2 +-
 drivers/base/component.c  | 382 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/component.h |  32 ++++
 3 files changed, 415 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/component.c
 create mode 100644 include/linux/component.h

diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 94e8a80e87f8..870ecfd503af 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -1,6 +1,6 @@
 # Makefile for the Linux device tree
 
-obj-y			:= core.o bus.o dd.o syscore.o \
+obj-y			:= component.o core.o bus.o dd.o syscore.o \
 			   driver.o class.o platform.o \
 			   cpu.o firmware.o init.o map.o devres.o \
 			   attribute_container.o transport_class.o \
diff --git a/drivers/base/component.c b/drivers/base/component.c
new file mode 100644
index 000000000000..c53efe6c6d8e
--- /dev/null
+++ b/drivers/base/component.c
@@ -0,0 +1,382 @@
+/*
+ * Componentized device handling.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This is work in progress.  We gather up the component devices into a list,
+ * and bind them when instructed.  At the moment, we're specific to the DRM
+ * subsystem, and only handles one master device, but this doesn't have to be
+ * the case.
+ */
+#include <linux/component.h>
+#include <linux/device.h>
+#include <linux/kref.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+
+struct master {
+	struct list_head node;
+	struct list_head components;
+	bool bound;
+
+	const struct component_master_ops *ops;
+	struct device *dev;
+};
+
+struct component {
+	struct list_head node;
+	struct list_head master_node;
+	struct master *master;
+	bool bound;
+
+	const struct component_ops *ops;
+	struct device *dev;
+};
+
+static DEFINE_MUTEX(component_mutex);
+static LIST_HEAD(component_list);
+static LIST_HEAD(masters);
+
+static struct master *__master_find(struct device *dev,
+	const struct component_master_ops *ops)
+{
+	struct master *m;
+
+	list_for_each_entry(m, &masters, node)
+		if (m->dev == dev && (!ops || m->ops == ops))
+			return m;
+
+	return NULL;
+}
+
+/* Attach an unattached component to a master. */
+static void component_attach_master(struct master *master, struct component *c)
+{
+	c->master = master;
+
+	list_add_tail(&c->master_node, &master->components);
+}
+
+/* Detach a component from a master. */
+static void component_detach_master(struct master *master, struct component *c)
+{
+	list_del(&c->master_node);
+
+	c->master = NULL;
+}
+
+int component_master_add_child(struct master *master,
+	int (*compare)(struct device *, void *), void *compare_data)
+{
+	struct component *c;
+	int ret = -ENXIO;
+
+	list_for_each_entry(c, &component_list, node) {
+		if (c->master)
+			continue;
+
+		if (compare(c->dev, compare_data)) {
+			component_attach_master(master, c);
+			ret = 0;
+			break;
+		}
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(component_master_add_child);
+
+/* Detach all attached components from this master */
+static void master_remove_components(struct master *master)
+{
+	while (!list_empty(&master->components)) {
+		struct component *c = list_first_entry(&master->components,
+					struct component, master_node);
+
+		WARN_ON(c->master != master);
+
+		component_detach_master(master, c);
+	}
+}
+
+/*
+ * Try to bring up a master.  If component is NULL, we're interested in
+ * this master, otherwise it's a component which must be present to try
+ * and bring up the master.
+ *
+ * Returns 1 for successful bringup, 0 if not ready, or -ve errno.
+ */
+static int try_to_bring_up_master(struct master *master,
+	struct component *component)
+{
+	int ret = 0;
+
+	if (!master->bound) {
+		/*
+		 * Search the list of components, looking for components that
+		 * belong to this master, and attach them to the master.
+		 */
+		if (master->ops->add_components(master->dev, master)) {
+			/* Failed to find all components */
+			master_remove_components(master);
+			ret = 0;
+			goto out;
+		}
+
+		if (component && component->master != master) {
+			master_remove_components(master);
+			ret = 0;
+			goto out;
+		}
+
+		/* Found all components */
+		ret = master->ops->bind(master->dev);
+		if (ret < 0) {
+			master_remove_components(master);
+			goto out;
+		}
+
+		master->bound = true;
+		ret = 1;
+	}
+out:
+
+	return ret;
+}
+
+static int try_to_bring_up_masters(struct component *component)
+{
+	struct master *m;
+	int ret = 0;
+
+	list_for_each_entry(m, &masters, node) {
+		ret = try_to_bring_up_master(m, component);
+		if (ret != 0)
+			break;
+	}
+
+	return ret;
+}
+
+static void take_down_master(struct master *master)
+{
+	if (master->bound) {
+		master->ops->unbind(master->dev);
+		master->bound = false;
+	}
+
+	master_remove_components(master);
+}
+
+int component_master_add(struct device *dev,
+	const struct component_master_ops *ops)
+{
+	struct master *master;
+	int ret;
+
+	master = kzalloc(sizeof(*master), GFP_KERNEL);
+	if (!master)
+		return -ENOMEM;
+
+	master->dev = dev;
+	master->ops = ops;
+	INIT_LIST_HEAD(&master->components);
+
+	/* Add to the list of available masters. */
+	mutex_lock(&component_mutex);
+	list_add(&master->node, &masters);
+
+	ret = try_to_bring_up_master(master, NULL);
+
+	if (ret < 0) {
+		/* Delete off the list if we weren't successful */
+		list_del(&master->node);
+		kfree(master);
+	}
+	mutex_unlock(&component_mutex);
+
+	return ret < 0 ? ret : 0;
+}
+EXPORT_SYMBOL_GPL(component_master_add);
+
+void component_master_del(struct device *dev,
+	const struct component_master_ops *ops)
+{
+	struct master *master;
+
+	mutex_lock(&component_mutex);
+	master = __master_find(dev, ops);
+	if (master) {
+		take_down_master(master);
+
+		list_del(&master->node);
+		kfree(master);
+	}
+	mutex_unlock(&component_mutex);
+}
+EXPORT_SYMBOL_GPL(component_master_del);
+
+static void component_unbind(struct component *component,
+	struct master *master, void *data)
+{
+	WARN_ON(!component->bound);
+
+	component->ops->unbind(component->dev, master->dev, data);
+	component->bound = false;
+
+	/* Release all resources claimed in the binding of this component */
+	devres_release_group(component->dev, component);
+}
+
+void component_unbind_all(struct device *master_dev, void *data)
+{
+	struct master *master;
+	struct component *c;
+
+	WARN_ON(!mutex_is_locked(&component_mutex));
+
+	master = __master_find(master_dev, NULL);
+	if (!master)
+		return;
+
+	list_for_each_entry_reverse(c, &master->components, master_node)
+		component_unbind(c, master, data);
+}
+EXPORT_SYMBOL_GPL(component_unbind_all);
+
+static int component_bind(struct component *component, struct master *master,
+	void *data)
+{
+	int ret;
+
+	/*
+	 * Each component initialises inside its own devres group.
+	 * This allows us to roll-back a failed component without
+	 * affecting anything else.
+	 */
+	if (!devres_open_group(master->dev, NULL, GFP_KERNEL))
+		return -ENOMEM;
+
+	/*
+	 * Also open a group for the device itself: this allows us
+	 * to release the resources claimed against the sub-device
+	 * at the appropriate moment.
+	 */
+	if (!devres_open_group(component->dev, component, GFP_KERNEL)) {
+		devres_release_group(master->dev, NULL);
+		return -ENOMEM;
+	}
+
+	dev_dbg(master->dev, "binding %s (ops %ps)\n",
+		dev_name(component->dev), component->ops);
+
+	ret = component->ops->bind(component->dev, master->dev, data);
+	if (!ret) {
+		component->bound = true;
+
+		/*
+		 * Close the component device's group so that resources
+		 * allocated in the binding are encapsulated for removal
+		 * at unbind.  Remove the group on the DRM device as we
+		 * can clean those resources up independently.
+		 */
+		devres_close_group(component->dev, NULL);
+		devres_remove_group(master->dev, NULL);
+
+		dev_info(master->dev, "bound %s (ops %ps)\n",
+			 dev_name(component->dev), component->ops);
+	} else {
+		devres_release_group(component->dev, NULL);
+		devres_release_group(master->dev, NULL);
+
+		dev_err(master->dev, "failed to bind %s (ops %ps): %d\n",
+			dev_name(component->dev), component->ops, ret);
+	}
+
+	return ret;
+}
+
+int component_bind_all(struct device *master_dev, void *data)
+{
+	struct master *master;
+	struct component *c;
+	int ret = 0;
+
+	WARN_ON(!mutex_is_locked(&component_mutex));
+
+	master = __master_find(master_dev, NULL);
+	if (!master)
+		return -EINVAL;
+
+	list_for_each_entry(c, &master->components, master_node) {
+		ret = component_bind(c, master, data);
+		if (ret)
+			break;
+	}
+
+	if (ret != 0) {
+		list_for_each_entry_continue_reverse(c, &master->components,
+						     master_node)
+			component_unbind(c, master, data);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(component_bind_all);
+
+int component_add(struct device *dev, const struct component_ops *ops)
+{
+	struct component *component;
+	int ret;
+
+	component = kzalloc(sizeof(*component), GFP_KERNEL);
+	if (!component)
+		return -ENOMEM;
+
+	component->ops = ops;
+	component->dev = dev;
+
+	dev_dbg(dev, "adding component (ops %ps)\n", ops);
+
+	mutex_lock(&component_mutex);
+	list_add_tail(&component->node, &component_list);
+
+	ret = try_to_bring_up_masters(component);
+	if (ret < 0) {
+		list_del(&component->node);
+
+		kfree(component);
+	}
+	mutex_unlock(&component_mutex);
+
+	return ret < 0 ? ret : 0;
+}
+EXPORT_SYMBOL_GPL(component_add);
+
+void component_del(struct device *dev, const struct component_ops *ops)
+{
+	struct component *c, *component = NULL;
+
+	mutex_lock(&component_mutex);
+	list_for_each_entry(c, &component_list, node)
+		if (c->dev == dev && c->ops == ops) {
+			list_del(&c->node);
+			component = c;
+			break;
+		}
+
+	if (component && component->master)
+		take_down_master(component->master);
+
+	mutex_unlock(&component_mutex);
+
+	WARN_ON(!component);
+	kfree(component);
+}
+EXPORT_SYMBOL_GPL(component_del);
+
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/component.h b/include/linux/component.h
new file mode 100644
index 000000000000..68870182ca1e
--- /dev/null
+++ b/include/linux/component.h
@@ -0,0 +1,32 @@
+#ifndef COMPONENT_H
+#define COMPONENT_H
+
+struct device;
+
+struct component_ops {
+	int (*bind)(struct device *, struct device *, void *);
+	void (*unbind)(struct device *, struct device *, void *);
+};
+
+int component_add(struct device *, const struct component_ops *);
+void component_del(struct device *, const struct component_ops *);
+
+int component_bind_all(struct device *, void *);
+void component_unbind_all(struct device *, void *);
+
+struct master;
+
+struct component_master_ops {
+	int (*add_components)(struct device *, struct master *);
+	int (*bind)(struct device *);
+	void (*unbind)(struct device *);
+};
+
+int component_master_add(struct device *, const struct component_master_ops *);
+void component_master_del(struct device *,
+	const struct component_master_ops *);
+
+int component_master_add_child(struct master *master,
+	int (*compare)(struct device *, void *), void *compare_data);
+
+#endif
-- 
1.8.3.1


-- 
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".

WARNING: multiple messages have this Message-ID (diff)
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devel@driverdev.osuosl.org, David Airlie <airlied@linux.ie>,
	Robert Schwebel <r.schwebel@pengutronix.de>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	dri-devel@lists.freedesktop.org,
	Sascha Hauer <kernel@pengutronix.de>,
	Shawn Guo <shawn.guo@linaro.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH RFC 26/46] drivers/base: provide an infrastructure for componentised subsystems
Date: Fri, 10 Jan 2014 23:23:37 +0000	[thread overview]
Message-ID: <20140110232336.GI15937@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20140110204259.GC10235@kroah.com>

On Fri, Jan 10, 2014 at 12:42:59PM -0800, Greg Kroah-Hartman wrote:
> On Fri, Jan 10, 2014 at 07:30:21PM +0100, Robert Schwebel wrote:
> > On Fri, Jan 10, 2014 at 07:35:30AM -0800, Greg Kroah-Hartman wrote:
> > > > I'll sort out a new set of patches today, along with a branch to pull if
> > > > you wish to take them that way.
> > > 
> > > It's too late for 3.14, as my tree is now closed for that because 3.13
> > > should be out this weekend.  But I'll be glad to queue them up after
> > > 3.14-rc1 is out.
> > 
> > Didnt' Linus say there would be an -rc8?
> 
> Ah, you are right, nevermind then :)
> 
> Russell, if you want to send me just the driver core patch, I can take
> that now and get that into 3.14 so that you don't have any cross-tree
> dependancies on the rest of this patch series.

Thanks, here it is.  Only change from the previously posted one is a
few checkpatch cleanups.

8<===
From: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH] drivers/base: provide an infrastructure for componentised
 subsystems

Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem.  However, firmware tends to
describe the individual devices and the connections between them.

Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.

We do this in DT by providing a "superdevice" node which specifies
the components, eg:

	imx-drm {
		compatible = "fsl,drm";
		crtcs = <&ipu1>;
		connectors = <&hdmi>;
	};

The superdevice is declared into the component support, along with the
subcomponents.  The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present.  At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.

When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
 drivers/base/Makefile     |   2 +-
 drivers/base/component.c  | 382 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/component.h |  32 ++++
 3 files changed, 415 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/component.c
 create mode 100644 include/linux/component.h

diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 94e8a80e87f8..870ecfd503af 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -1,6 +1,6 @@
 # Makefile for the Linux device tree
 
-obj-y			:= core.o bus.o dd.o syscore.o \
+obj-y			:= component.o core.o bus.o dd.o syscore.o \
 			   driver.o class.o platform.o \
 			   cpu.o firmware.o init.o map.o devres.o \
 			   attribute_container.o transport_class.o \
diff --git a/drivers/base/component.c b/drivers/base/component.c
new file mode 100644
index 000000000000..c53efe6c6d8e
--- /dev/null
+++ b/drivers/base/component.c
@@ -0,0 +1,382 @@
+/*
+ * Componentized device handling.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This is work in progress.  We gather up the component devices into a list,
+ * and bind them when instructed.  At the moment, we're specific to the DRM
+ * subsystem, and only handles one master device, but this doesn't have to be
+ * the case.
+ */
+#include <linux/component.h>
+#include <linux/device.h>
+#include <linux/kref.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+
+struct master {
+	struct list_head node;
+	struct list_head components;
+	bool bound;
+
+	const struct component_master_ops *ops;
+	struct device *dev;
+};
+
+struct component {
+	struct list_head node;
+	struct list_head master_node;
+	struct master *master;
+	bool bound;
+
+	const struct component_ops *ops;
+	struct device *dev;
+};
+
+static DEFINE_MUTEX(component_mutex);
+static LIST_HEAD(component_list);
+static LIST_HEAD(masters);
+
+static struct master *__master_find(struct device *dev,
+	const struct component_master_ops *ops)
+{
+	struct master *m;
+
+	list_for_each_entry(m, &masters, node)
+		if (m->dev == dev && (!ops || m->ops == ops))
+			return m;
+
+	return NULL;
+}
+
+/* Attach an unattached component to a master. */
+static void component_attach_master(struct master *master, struct component *c)
+{
+	c->master = master;
+
+	list_add_tail(&c->master_node, &master->components);
+}
+
+/* Detach a component from a master. */
+static void component_detach_master(struct master *master, struct component *c)
+{
+	list_del(&c->master_node);
+
+	c->master = NULL;
+}
+
+int component_master_add_child(struct master *master,
+	int (*compare)(struct device *, void *), void *compare_data)
+{
+	struct component *c;
+	int ret = -ENXIO;
+
+	list_for_each_entry(c, &component_list, node) {
+		if (c->master)
+			continue;
+
+		if (compare(c->dev, compare_data)) {
+			component_attach_master(master, c);
+			ret = 0;
+			break;
+		}
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(component_master_add_child);
+
+/* Detach all attached components from this master */
+static void master_remove_components(struct master *master)
+{
+	while (!list_empty(&master->components)) {
+		struct component *c = list_first_entry(&master->components,
+					struct component, master_node);
+
+		WARN_ON(c->master != master);
+
+		component_detach_master(master, c);
+	}
+}
+
+/*
+ * Try to bring up a master.  If component is NULL, we're interested in
+ * this master, otherwise it's a component which must be present to try
+ * and bring up the master.
+ *
+ * Returns 1 for successful bringup, 0 if not ready, or -ve errno.
+ */
+static int try_to_bring_up_master(struct master *master,
+	struct component *component)
+{
+	int ret = 0;
+
+	if (!master->bound) {
+		/*
+		 * Search the list of components, looking for components that
+		 * belong to this master, and attach them to the master.
+		 */
+		if (master->ops->add_components(master->dev, master)) {
+			/* Failed to find all components */
+			master_remove_components(master);
+			ret = 0;
+			goto out;
+		}
+
+		if (component && component->master != master) {
+			master_remove_components(master);
+			ret = 0;
+			goto out;
+		}
+
+		/* Found all components */
+		ret = master->ops->bind(master->dev);
+		if (ret < 0) {
+			master_remove_components(master);
+			goto out;
+		}
+
+		master->bound = true;
+		ret = 1;
+	}
+out:
+
+	return ret;
+}
+
+static int try_to_bring_up_masters(struct component *component)
+{
+	struct master *m;
+	int ret = 0;
+
+	list_for_each_entry(m, &masters, node) {
+		ret = try_to_bring_up_master(m, component);
+		if (ret != 0)
+			break;
+	}
+
+	return ret;
+}
+
+static void take_down_master(struct master *master)
+{
+	if (master->bound) {
+		master->ops->unbind(master->dev);
+		master->bound = false;
+	}
+
+	master_remove_components(master);
+}
+
+int component_master_add(struct device *dev,
+	const struct component_master_ops *ops)
+{
+	struct master *master;
+	int ret;
+
+	master = kzalloc(sizeof(*master), GFP_KERNEL);
+	if (!master)
+		return -ENOMEM;
+
+	master->dev = dev;
+	master->ops = ops;
+	INIT_LIST_HEAD(&master->components);
+
+	/* Add to the list of available masters. */
+	mutex_lock(&component_mutex);
+	list_add(&master->node, &masters);
+
+	ret = try_to_bring_up_master(master, NULL);
+
+	if (ret < 0) {
+		/* Delete off the list if we weren't successful */
+		list_del(&master->node);
+		kfree(master);
+	}
+	mutex_unlock(&component_mutex);
+
+	return ret < 0 ? ret : 0;
+}
+EXPORT_SYMBOL_GPL(component_master_add);
+
+void component_master_del(struct device *dev,
+	const struct component_master_ops *ops)
+{
+	struct master *master;
+
+	mutex_lock(&component_mutex);
+	master = __master_find(dev, ops);
+	if (master) {
+		take_down_master(master);
+
+		list_del(&master->node);
+		kfree(master);
+	}
+	mutex_unlock(&component_mutex);
+}
+EXPORT_SYMBOL_GPL(component_master_del);
+
+static void component_unbind(struct component *component,
+	struct master *master, void *data)
+{
+	WARN_ON(!component->bound);
+
+	component->ops->unbind(component->dev, master->dev, data);
+	component->bound = false;
+
+	/* Release all resources claimed in the binding of this component */
+	devres_release_group(component->dev, component);
+}
+
+void component_unbind_all(struct device *master_dev, void *data)
+{
+	struct master *master;
+	struct component *c;
+
+	WARN_ON(!mutex_is_locked(&component_mutex));
+
+	master = __master_find(master_dev, NULL);
+	if (!master)
+		return;
+
+	list_for_each_entry_reverse(c, &master->components, master_node)
+		component_unbind(c, master, data);
+}
+EXPORT_SYMBOL_GPL(component_unbind_all);
+
+static int component_bind(struct component *component, struct master *master,
+	void *data)
+{
+	int ret;
+
+	/*
+	 * Each component initialises inside its own devres group.
+	 * This allows us to roll-back a failed component without
+	 * affecting anything else.
+	 */
+	if (!devres_open_group(master->dev, NULL, GFP_KERNEL))
+		return -ENOMEM;
+
+	/*
+	 * Also open a group for the device itself: this allows us
+	 * to release the resources claimed against the sub-device
+	 * at the appropriate moment.
+	 */
+	if (!devres_open_group(component->dev, component, GFP_KERNEL)) {
+		devres_release_group(master->dev, NULL);
+		return -ENOMEM;
+	}
+
+	dev_dbg(master->dev, "binding %s (ops %ps)\n",
+		dev_name(component->dev), component->ops);
+
+	ret = component->ops->bind(component->dev, master->dev, data);
+	if (!ret) {
+		component->bound = true;
+
+		/*
+		 * Close the component device's group so that resources
+		 * allocated in the binding are encapsulated for removal
+		 * at unbind.  Remove the group on the DRM device as we
+		 * can clean those resources up independently.
+		 */
+		devres_close_group(component->dev, NULL);
+		devres_remove_group(master->dev, NULL);
+
+		dev_info(master->dev, "bound %s (ops %ps)\n",
+			 dev_name(component->dev), component->ops);
+	} else {
+		devres_release_group(component->dev, NULL);
+		devres_release_group(master->dev, NULL);
+
+		dev_err(master->dev, "failed to bind %s (ops %ps): %d\n",
+			dev_name(component->dev), component->ops, ret);
+	}
+
+	return ret;
+}
+
+int component_bind_all(struct device *master_dev, void *data)
+{
+	struct master *master;
+	struct component *c;
+	int ret = 0;
+
+	WARN_ON(!mutex_is_locked(&component_mutex));
+
+	master = __master_find(master_dev, NULL);
+	if (!master)
+		return -EINVAL;
+
+	list_for_each_entry(c, &master->components, master_node) {
+		ret = component_bind(c, master, data);
+		if (ret)
+			break;
+	}
+
+	if (ret != 0) {
+		list_for_each_entry_continue_reverse(c, &master->components,
+						     master_node)
+			component_unbind(c, master, data);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(component_bind_all);
+
+int component_add(struct device *dev, const struct component_ops *ops)
+{
+	struct component *component;
+	int ret;
+
+	component = kzalloc(sizeof(*component), GFP_KERNEL);
+	if (!component)
+		return -ENOMEM;
+
+	component->ops = ops;
+	component->dev = dev;
+
+	dev_dbg(dev, "adding component (ops %ps)\n", ops);
+
+	mutex_lock(&component_mutex);
+	list_add_tail(&component->node, &component_list);
+
+	ret = try_to_bring_up_masters(component);
+	if (ret < 0) {
+		list_del(&component->node);
+
+		kfree(component);
+	}
+	mutex_unlock(&component_mutex);
+
+	return ret < 0 ? ret : 0;
+}
+EXPORT_SYMBOL_GPL(component_add);
+
+void component_del(struct device *dev, const struct component_ops *ops)
+{
+	struct component *c, *component = NULL;
+
+	mutex_lock(&component_mutex);
+	list_for_each_entry(c, &component_list, node)
+		if (c->dev == dev && c->ops == ops) {
+			list_del(&c->node);
+			component = c;
+			break;
+		}
+
+	if (component && component->master)
+		take_down_master(component->master);
+
+	mutex_unlock(&component_mutex);
+
+	WARN_ON(!component);
+	kfree(component);
+}
+EXPORT_SYMBOL_GPL(component_del);
+
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/component.h b/include/linux/component.h
new file mode 100644
index 000000000000..68870182ca1e
--- /dev/null
+++ b/include/linux/component.h
@@ -0,0 +1,32 @@
+#ifndef COMPONENT_H
+#define COMPONENT_H
+
+struct device;
+
+struct component_ops {
+	int (*bind)(struct device *, struct device *, void *);
+	void (*unbind)(struct device *, struct device *, void *);
+};
+
+int component_add(struct device *, const struct component_ops *);
+void component_del(struct device *, const struct component_ops *);
+
+int component_bind_all(struct device *, void *);
+void component_unbind_all(struct device *, void *);
+
+struct master;
+
+struct component_master_ops {
+	int (*add_components)(struct device *, struct master *);
+	int (*bind)(struct device *);
+	void (*unbind)(struct device *);
+};
+
+int component_master_add(struct device *, const struct component_master_ops *);
+void component_master_del(struct device *,
+	const struct component_master_ops *);
+
+int component_master_add_child(struct master *master,
+	int (*compare)(struct device *, void *), void *compare_data);
+
+#endif
-- 
1.8.3.1


-- 
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".

  reply	other threads:[~2014-01-10 23:23 UTC|newest]

Thread overview: 219+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-02 21:25 [PATCH RFC 00/46] Preview of imx-drm cleanup series Russell King - ARM Linux
2014-01-02 21:25 ` Russell King - ARM Linux
2014-01-02 21:25 ` [PATCH RFC 01/46] imx-drm: imx-drm-core: use the crtc drm device for vblank Russell King
2014-01-02 21:25   ` Russell King
2014-01-02 21:25 ` [PATCH RFC 02/46] imx-drm: imx-drm-core: avoid going the long route round for drm_device Russell King
2014-01-02 21:25   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 03/46] imx-drm: imx-drm-core: merge imx_drm_crtc_register() into imx_drm_add_crtc() Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 04/46] imx-drm: ipu-v3: more inteligent DI clock selection Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 05/46] imx-drm: ipu-v3: don't use clk_round_rate() before clk_set_rate() Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 06/46] imx-drm: ipu-v3: more clocking fixes Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 07/46] imx-drm: Add mx6 hdmi transmitter support Russell King
2014-01-02 21:34   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 08/46] imx-drm: add imx6 DT configuration for HDMI Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 09/46] imx-drm: update and fix imx6 DT descriptions for v3 HDMI driver Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 10/46] imx-drm: imx-hdmi: fix PLL lock wait Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 11/46] imx-drm: imx-hdmi: fix pixel clock Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 12/46] imx-drm: imx-hdmi: fix wrong comment Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 13/46] imx-drm: imx-hdmi: get rid of pointless fb_reg Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:26 ` [PATCH RFC 14/46] imx-drm: imx-hdmi: get rid of clk manipulations in imx_hdmi_fb_registered() Russell King
2014-01-02 21:26   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 15/46] imx-drm: imx-hdmi: minor cleanups Russell King
2014-01-02 21:27   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 16/46] imx-drm: imx-hdmi: convert HDMI clock settings to tabular form Russell King
2014-01-02 21:27   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 17/46] imx-drm: imx-hdmi: clean up setting CSC registers Russell King
2014-01-02 21:27   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 18/46] imx-drm: imx-hdmi: provide register modification function Russell King
2014-01-02 21:27   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 19/46] imx-drm: imx-hdmi: clean up setting of vp_conf Russell King
2014-01-02 21:27   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 20/46] imx-drm: imx-hdmi: fix CTS/N setup at init time Russell King
2014-01-02 21:27   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 21/46] drm: provide a helper for the encoder possible_crtcs mask Russell King
2014-01-02 21:27   ` Russell King
2014-01-03 16:05   ` David Herrmann
2014-01-03 16:05     ` David Herrmann
2014-01-03 16:13     ` Russell King - ARM Linux
2014-01-03 16:13       ` Russell King - ARM Linux
2014-01-03 16:26       ` David Herrmann
2014-01-03 16:26         ` David Herrmann
2014-01-03 16:29         ` Russell King - ARM Linux
2014-01-03 16:29           ` Russell King - ARM Linux
2014-01-02 21:27 ` [PATCH RFC 22/46] imx-drm: imx-drm-core: sanitise imx_drm_encoder_get_mux_id() Russell King
2014-01-02 21:27   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 23/46] imx-drm: imx-drm-core: use array instead of list for CRTCs Russell King
2014-01-02 21:27   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 24/46] imx-drm: provide common connector mode validation function Russell King
2014-01-02 21:27   ` Russell King
2014-01-07  6:38   ` Shawn Guo
2014-01-07  6:38     ` Shawn Guo
2014-01-08 21:25     ` Russell King - ARM Linux
2014-01-08 21:25       ` Russell King - ARM Linux
2014-01-02 21:27 ` [PATCH RFC 25/46] imx-drm: simplify setup of panel format Russell King
2014-01-02 21:27   ` Russell King
2014-01-02 21:27 ` [PATCH RFC 26/46] drivers/base: provide an infrastructure for componentised subsystems Russell King
2014-01-02 21:27   ` Russell King
2014-01-03  3:10   ` Greg Kroah-Hartman
2014-01-03  3:10     ` Greg Kroah-Hartman
2014-01-03 11:00     ` Russell King - ARM Linux
2014-01-03 11:00       ` Russell King - ARM Linux
2014-01-03 11:58       ` Rafael J. Wysocki
2014-01-03 11:58         ` Rafael J. Wysocki
2014-01-03 12:18         ` Russell King - ARM Linux
2014-01-03 12:18           ` Russell King - ARM Linux
2014-01-03 13:24           ` Rafael J. Wysocki
2014-01-03 13:24             ` Rafael J. Wysocki
2014-01-03 14:14             ` Russell King - ARM Linux
2014-01-03 14:14               ` Russell King - ARM Linux
2014-01-10 14:54     ` Russell King - ARM Linux
2014-01-10 14:54       ` Russell King - ARM Linux
2014-01-10 15:07       ` Greg Kroah-Hartman
2014-01-10 15:07         ` Greg Kroah-Hartman
2014-01-10 15:11         ` Russell King - ARM Linux
2014-01-10 15:11           ` Russell King - ARM Linux
2014-01-10 15:35           ` Greg Kroah-Hartman
2014-01-10 15:35             ` Greg Kroah-Hartman
2014-01-10 16:04             ` Russell King - ARM Linux
2014-01-10 16:04               ` Russell King - ARM Linux
2014-01-10 18:30             ` Robert Schwebel
2014-01-10 18:30               ` Robert Schwebel
2014-01-10 20:42               ` Greg Kroah-Hartman
2014-01-10 20:42                 ` Greg Kroah-Hartman
2014-01-10 23:23                 ` Russell King - ARM Linux [this message]
2014-01-10 23:23                   ` Russell King - ARM Linux
2014-01-11 11:31                   ` Robert Schwebel
2014-01-11 11:31                     ` Robert Schwebel
2014-01-11 11:40                     ` Russell King - ARM Linux
2014-01-11 11:40                       ` Russell King - ARM Linux
2014-01-13  8:34                       ` Philipp Zabel
2014-01-13  8:34                         ` Philipp Zabel
2014-01-07 20:18   ` Sean Paul
2014-01-07 20:18     ` Sean Paul
2014-01-08 21:36     ` Russell King - ARM Linux
2014-01-08 21:36       ` Russell King - ARM Linux
2014-01-08 22:39       ` Sean Paul
2014-01-08 22:39         ` Sean Paul
2014-01-09  7:40         ` Sascha Hauer
2014-01-09  7:40           ` Sascha Hauer
2014-02-07  9:04   ` Daniel Vetter
2014-02-07  9:04     ` Daniel Vetter
2014-02-07  9:04     ` Daniel Vetter
2014-02-07  9:46     ` Russell King - ARM Linux
2014-02-07  9:46       ` Russell King - ARM Linux
2014-02-07 11:57       ` Jean-Francois Moine
2014-02-07 11:57         ` Jean-Francois Moine
2014-02-07 11:57         ` Jean-Francois Moine
2014-02-07 12:28         ` Russell King - ARM Linux
2014-02-07 12:28           ` Russell King - ARM Linux
2014-02-07 12:28           ` Russell King - ARM Linux
2014-02-26 21:00   ` Guennadi Liakhovetski
2014-02-26 21:00     ` Guennadi Liakhovetski
2014-02-26 21:00     ` Guennadi Liakhovetski
2014-02-26 22:19     ` Russell King - ARM Linux
2014-02-26 22:19       ` Russell King - ARM Linux
2014-02-26 22:19       ` Russell King - ARM Linux
2014-03-06 11:46       ` Guennadi Liakhovetski
2014-03-06 11:46         ` Guennadi Liakhovetski
2014-03-06 23:24       ` Laurent Pinchart
2014-03-06 23:24         ` Laurent Pinchart
2014-03-06 23:24         ` Laurent Pinchart
2014-03-19 17:22         ` Laurent Pinchart
2014-03-19 17:22           ` Laurent Pinchart
2014-03-19 17:22           ` Laurent Pinchart
2014-03-19 17:27           ` Russell King - ARM Linux
2014-03-19 17:27             ` Russell King - ARM Linux
2014-03-19 17:27             ` Russell King - ARM Linux
2014-03-21 12:34         ` Russell King - ARM Linux
2014-03-21 12:34           ` Russell King - ARM Linux
2014-03-21 12:34           ` Russell King - ARM Linux
2014-01-02 21:28 ` [PATCH RFC 27/46] imx-drm: convert to componentised device support Russell King
2014-01-02 21:28   ` Russell King
2014-01-03 16:48   ` Philipp Zabel
2014-01-03 16:48     ` Philipp Zabel
2014-01-03 17:07     ` Russell King - ARM Linux
2014-01-03 17:07       ` Russell King - ARM Linux
2014-01-03 17:26       ` Philipp Zabel
2014-01-03 17:26         ` Philipp Zabel
2014-01-03 17:38         ` Russell King - ARM Linux
2014-01-03 17:38           ` Russell King - ARM Linux
2014-01-03 19:14         ` Eric Nelson
2014-01-03 19:14           ` Eric Nelson
2014-01-06 17:41           ` Philipp Zabel
2014-01-06 17:41             ` Philipp Zabel
2014-01-06 17:46             ` Russell King - ARM Linux
2014-01-06 17:46               ` Russell King - ARM Linux
2014-01-07  2:31               ` Eric Nelson
2014-01-07  2:31                 ` Eric Nelson
2014-01-07 11:29                 ` Philipp Zabel
2014-01-07 11:29                   ` Philipp Zabel
2014-01-07 15:30                   ` Eric Nelson
2014-01-07 15:30                     ` Eric Nelson
2014-01-07 16:29                     ` Philipp Zabel
2014-01-07 16:29                       ` Philipp Zabel
2014-01-08 21:40                       ` Russell King - ARM Linux
2014-01-08 21:40                         ` Russell King - ARM Linux
2014-01-07  8:59   ` Shawn Guo
2014-01-07  8:59     ` Shawn Guo
2014-01-08 21:32     ` Russell King - ARM Linux
2014-01-08 21:32       ` Russell King - ARM Linux
2014-01-09 15:25       ` Shawn Guo
2014-01-09 15:25         ` Shawn Guo
2014-01-09 15:33         ` Russell King - ARM Linux
2014-01-09 15:33           ` Russell King - ARM Linux
2014-01-02 21:28 ` [PATCH RFC 28/46] imx-drm: imx-hdmi: convert to a component device Russell King
2014-01-02 21:28   ` Russell King
2014-01-02 21:28 ` [PATCH RFC 29/46] imx-drm: delay publishing sysfs connector entries Russell King
2014-01-02 21:28   ` Russell King
2014-01-02 21:28 ` [PATCH RFC 30/46] imx-drm: remove separate imx-fbdev Russell King
2014-01-02 21:28   ` Russell King
2014-01-07  6:49   ` Shawn Guo
2014-01-07  6:49     ` Shawn Guo
2014-01-08 21:27     ` Russell King - ARM Linux
2014-01-08 21:27       ` Russell King - ARM Linux
2014-01-02 21:28 ` [PATCH RFC 31/46] imx-drm: remove imx-fb.c Russell King
2014-01-02 21:28   ` Russell King
2014-01-02 21:28 ` [PATCH RFC 32/46] imx-drm: use supplied drm_device where possible Russell King
2014-01-02 21:28   ` Russell King
2014-01-02 21:28 ` [PATCH RFC 33/46] imx-drm: imx-drm-core: provide helper function to parse possible crtcs Russell King
2014-01-02 21:28   ` Russell King
2014-01-02 21:28 ` [PATCH RFC 34/46] imx-drm: imx-drm-core: provide common connector and encoder cleanup functions Russell King
2014-01-02 21:28   ` Russell King
2014-01-02 21:28 ` [PATCH RFC 35/46] imx-drm: parallel-display,imx-tve,imx-ldb: initialise drm components directly Russell King
2014-01-02 21:28   ` Russell King
2014-01-02 21:28 ` [PATCH RFC 36/46] imx-drm: imx-hdmi: " Russell King
2014-01-02 21:28   ` Russell King
2014-01-02 21:28 ` [PATCH RFC 37/46] imx-drm: imx-drm-core: remove imx_drm_connector and imx_drm_encoder code Russell King
2014-01-02 21:28   ` Russell King
2014-01-02 21:29 ` [PATCH RFC 38/46] imx-drm: imx-drm-core: get rid of drm_mode_group_init_legacy_group() Russell King
2014-01-02 21:29   ` Russell King
2014-01-02 21:29 ` [PATCH RFC 39/46] imx-drm: imx-drm-core: kill off mutex Russell King
2014-01-02 21:29   ` Russell King
2014-01-02 21:29 ` [PATCH RFC 40/46] imx-drm: imx-drm-core: move allocation of imxdrm device to driver load function Russell King
2014-01-02 21:29   ` Russell King
2014-01-02 21:29 ` [PATCH RFC 41/46] imx-drm: imx-drm-core: various cleanups Russell King
2014-01-02 21:29   ` Russell King
2014-01-02 21:29 ` [PATCH RFC 42/46] imx-drm: imx-drm-core: add core hotplug connector support Russell King
2014-01-02 21:29   ` Russell King
2014-01-02 21:29 ` [PATCH RFC 43/46] imx-drm: imx-hdmi: add hotplug support to HDMI component Russell King
2014-01-02 21:29   ` Russell King
2014-01-02 21:29 ` [PATCH RFC 44/46] imx-drm: dw-hdmi-audio: add audio driver Russell King
2014-01-02 21:29   ` Russell King
2014-01-02 21:29 ` [PATCH RFC 45/46] imx-drm: dw-hdmi-audio: parse ELD from HDMI driver Russell King
2014-01-02 21:29   ` Russell King
2014-01-02 21:29 ` [PATCH RFC 46/46] imx-drm: pass an IPU ID to crtc and core (needs work) Russell King
2014-01-02 21:29   ` Russell King
2014-01-07  6:33 ` [PATCH RFC 00/46] Preview of imx-drm cleanup series Shawn Guo
2014-01-07  6:33   ` Shawn Guo
2014-01-09 13:17   ` Russell King - ARM Linux
2014-01-09 13:17     ` Russell King - ARM Linux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140110232336.GI15937@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.